Copy-paste items between sites.
authorgfawcett <gfawcett@6d9bc8c9-1ec2-4278-b937-99fde70a366f>
Thu, 14 Apr 2011 00:51:23 +0000 (00:51 +0000)
committergfawcett <gfawcett@6d9bc8c9-1ec2-4278-b937-99fde70a366f>
Thu, 14 Apr 2011 00:51:23 +0000 (00:51 +0000)
git-svn-id: svn://svn.open-ils.org/ILS-Contrib/servres/trunk@1355 6d9bc8c9-1ec2-4278-b937-99fde70a366f

conifer/syrup/urls.py
conifer/syrup/views/sites.py
conifer/templates/site_confirm_paste.xhtml [new file with mode: 0644]
conifer/templates/site_confirm_paste_undo.xhtml [new file with mode: 0644]
conifer/templates/site_detail.xhtml

index 0ec6dfd..ae8cad9 100644 (file)
@@ -66,4 +66,8 @@ urlpatterns = patterns('conifer.syrup.views',
 #     (r'^admin/terms/(?P<term_id>\d+)/delete$', 'admin_term_delete'),
 #     (r'^admin/terms/$', 'admin_term'),
     (r'^unapi/$', 'unapi'),
+
+    (r'^site/(?P<site_id>\d+)/copy_from/$', 'site_clipboard_copy_from'),
+    (r'^site/(?P<site_id>\d+)/paste_to/$', 'site_clipboard_paste_to'),
+    (r'^site/(?P<site_id>\d+)/paste_undo/$', 'site_clipboard_paste_undo'),
 )
index 7af9c35..7ba283f 100644 (file)
@@ -223,3 +223,49 @@ def site_fuzzy_user_lookup(request):
     return HttpResponse(simplejson.dumps(resp),
                         content_type='application/json')
 
+
+def site_clipboard_copy_from(request, site_id):
+    site = get_object_or_404(models.Site, pk=site_id)
+    request.session['copy_source'] = site_id
+    return simple_message(_('Ready to copy.'),
+                          _('This site has been marked as the copying source. Visit the new site, '
+                            'and click "Paste to Here," to copy this site\'s materials into the new site.'))
+
+def site_clipboard_paste_to(request, site_id):
+    source_id = request.session['copy_source']
+    source_site = get_object_or_404(models.Site, pk=source_id)
+    site = get_object_or_404(models.Site, pk=site_id)
+    if request.method != 'POST':
+        return g.render('site_confirm_paste.xhtml', **locals())
+
+    item_map = {}
+
+    def process_item(parent, (item, subitems)):
+        dct = dict((k,v) for k,v in item.__dict__.items() if not k.startswith('_'))
+        old_id = dct['id']
+        del dct['id']
+        dct['parent_heading_id'] = parent.id if parent else None
+        newitem = models.Item.objects.create(**dct)
+        newitem.site = site
+        newitem.save()
+        item_map[old_id] = newitem.id
+        for sub in subitems:
+            process_item(newitem, sub)
+
+    for branch in source_site.item_tree():
+        process_item(None, branch)
+    request.session['last_paste'] = (source_site.id, site.id, item_map.values())
+    return HttpResponseRedirect('../')
+
+def site_clipboard_paste_undo(request, site_id):
+    site = get_object_or_404(models.Site, pk=site_id)
+    source_id, _site_id, item_list = request.session.get('last_paste', (0,0,0))
+    if _site_id != site.id:     # should never happen
+        return HttpResponseRedirect('../')
+    source_site = get_object_or_404(models.Site, pk=source_id)
+    if request.method != 'POST':
+        return g.render('site_confirm_paste_undo.xhtml', **locals())
+    for item_id in item_list:
+        site.item_set.get(pk=item_id).delete()
+    del request.session['last_paste']
+    return HttpResponseRedirect('../')
diff --git a/conifer/templates/site_confirm_paste.xhtml b/conifer/templates/site_confirm_paste.xhtml
new file mode 100644 (file)
index 0000000..8c55114
--- /dev/null
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+<?python
+title = _('Paste into this site?') 
+?>
+<html xmlns="http://www.w3.org/1999/xhtml"
+      xmlns:xi="http://www.w3.org/2001/XInclude"
+      xmlns:py="http://genshi.edgewall.org/">
+  <xi:include href="master.xhtml"/>
+  <xi:include href="components/site.xhtml"/>
+  <head>
+    <title>${title}</title>
+  </head>
+  <body>
+    <h2>${title}</h2>
+    <p>Please confirm that you want to paste the materials into this site.</p>
+    <table class="metadata_table">
+      <tr><th>Source:</th><td><a href="${source_site.site_url()}">${source_site}</a></td></tr>
+      <tr><th>Destination:</th><td>${site}</td></tr>
+      <tr><th>Items:</th><td>
+      ${show_tree(source_site.item_tree())}
+      </td></tr>
+    </table>
+    <form action="." method="POST">
+      <p>
+       <input type="submit" value="Paste the materials"/>
+       ${go_back_link()}
+      </p>
+    </form>
+  </body>
+</html>
\ No newline at end of file
diff --git a/conifer/templates/site_confirm_paste_undo.xhtml b/conifer/templates/site_confirm_paste_undo.xhtml
new file mode 100644 (file)
index 0000000..89b1194
--- /dev/null
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="utf-8"?>
+<?python
+title = _('Undo last paste?') 
+?>
+<html xmlns="http://www.w3.org/1999/xhtml"
+      xmlns:xi="http://www.w3.org/2001/XInclude"
+      xmlns:py="http://genshi.edgewall.org/">
+  <xi:include href="master.xhtml"/>
+  <xi:include href="components/site.xhtml"/>
+  <head>
+    <title>${title}</title>
+  </head>
+  <body>
+    <h2>${title}</h2>
+    <p>Please confirm that you want to <b>remove</b> the materials that you last pasted into this site.</p>
+    <table class="metadata_table">
+      <tr><th>Source:</th><td><a href="${source_site.site_url()}">${source_site}</a></td></tr>
+      <tr><th>Destination:</th><td>${site}</td></tr>
+      <tr><th>Items:</th><td>
+      <div py:for="item in sorted([site.item_set.get(pk=n) for n in item_list], key=lambda i: i.title)">
+      ${show_tree([(item, [])])}
+      </div>
+      </td></tr>
+    </table>
+    <form action="." method="POST">
+      <p>
+       <input type="submit" value="Remove the pasted materials"/>
+       ${go_back_link()}
+      </p>
+    </form>
+  </body>
+</html>
\ No newline at end of file
index 612e9ad..5142a45 100644 (file)
@@ -34,9 +34,18 @@ is_joinable = site.is_joinable_by(request.user)
       <div py:if="is_editor" id="feeds" class="little_action_panel">
        <a href="${site.site_url()}feeds/">Feeds</a>
       </div>
+      <div py:if="is_editor" id="copy_from" class="little_action_panel">
+       <a href="${site.site_url()}copy_from/">Copy from here</a>
+      </div>
+      <div py:if="is_editor and request.session.get('copy_source')" id="paste_to" class="little_action_panel">
+       <a href="${site.site_url()}paste_to/">Paste to here</a>
+      </div>
+      <div py:if="is_editor and request.session.get('last_paste', (0,0,0))[1] == site.id" 
+          id="paste_undo" class="little_action_panel">
+       <a href="${site.site_url()}paste_undo/">Undo last paste</a>
+      </div>
+
     </div>
     <div py:if="is_editor">${add_subs()}</div>
-
-
   </body>
 </html>