[open-ils-commits] r1355 - in servres/trunk/conifer: syrup syrup/views templates (gfawcett)

svn at svn.open-ils.org svn at svn.open-ils.org
Wed Apr 13 20:51:25 EDT 2011


Author: gfawcett
Date: 2011-04-13 20:51:23 -0400 (Wed, 13 Apr 2011)
New Revision: 1355

Added:
   servres/trunk/conifer/templates/site_confirm_paste.xhtml
   servres/trunk/conifer/templates/site_confirm_paste_undo.xhtml
Modified:
   servres/trunk/conifer/syrup/urls.py
   servres/trunk/conifer/syrup/views/sites.py
   servres/trunk/conifer/templates/site_detail.xhtml
Log:
Copy-paste items between sites.

Modified: servres/trunk/conifer/syrup/urls.py
===================================================================
--- servres/trunk/conifer/syrup/urls.py	2011-04-14 00:02:01 UTC (rev 1354)
+++ servres/trunk/conifer/syrup/urls.py	2011-04-14 00:51:23 UTC (rev 1355)
@@ -66,4 +66,8 @@
 #     (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'),
 )

Modified: servres/trunk/conifer/syrup/views/sites.py
===================================================================
--- servres/trunk/conifer/syrup/views/sites.py	2011-04-14 00:02:01 UTC (rev 1354)
+++ servres/trunk/conifer/syrup/views/sites.py	2011-04-14 00:51:23 UTC (rev 1355)
@@ -223,3 +223,49 @@
     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('../')

Added: servres/trunk/conifer/templates/site_confirm_paste.xhtml
===================================================================
--- servres/trunk/conifer/templates/site_confirm_paste.xhtml	                        (rev 0)
+++ servres/trunk/conifer/templates/site_confirm_paste.xhtml	2011-04-14 00:51:23 UTC (rev 1355)
@@ -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

Added: servres/trunk/conifer/templates/site_confirm_paste_undo.xhtml
===================================================================
--- servres/trunk/conifer/templates/site_confirm_paste_undo.xhtml	                        (rev 0)
+++ servres/trunk/conifer/templates/site_confirm_paste_undo.xhtml	2011-04-14 00:51:23 UTC (rev 1355)
@@ -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

Modified: servres/trunk/conifer/templates/site_detail.xhtml
===================================================================
--- servres/trunk/conifer/templates/site_detail.xhtml	2011-04-14 00:02:01 UTC (rev 1354)
+++ servres/trunk/conifer/templates/site_detail.xhtml	2011-04-14 00:51:23 UTC (rev 1355)
@@ -34,9 +34,18 @@
       <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>



More information about the open-ils-commits mailing list