From d73f5f3c048ba966f90e60237026a326cc9be470 Mon Sep 17 00:00:00 2001 From: gfawcett Date: Thu, 14 Apr 2011 00:51:23 +0000 Subject: [PATCH] Copy-paste items between sites. git-svn-id: svn://svn.open-ils.org/ILS-Contrib/servres/trunk@1355 6d9bc8c9-1ec2-4278-b937-99fde70a366f --- conifer/syrup/urls.py | 4 +++ conifer/syrup/views/sites.py | 46 +++++++++++++++++++++++++ conifer/templates/site_confirm_paste.xhtml | 30 ++++++++++++++++ conifer/templates/site_confirm_paste_undo.xhtml | 32 +++++++++++++++++ conifer/templates/site_detail.xhtml | 13 +++++-- 5 files changed, 123 insertions(+), 2 deletions(-) create mode 100644 conifer/templates/site_confirm_paste.xhtml create mode 100644 conifer/templates/site_confirm_paste_undo.xhtml diff --git a/conifer/syrup/urls.py b/conifer/syrup/urls.py index 0ec6dfd..ae8cad9 100644 --- a/conifer/syrup/urls.py +++ b/conifer/syrup/urls.py @@ -66,4 +66,8 @@ urlpatterns = patterns('conifer.syrup.views', # (r'^admin/terms/(?P\d+)/delete$', 'admin_term_delete'), # (r'^admin/terms/$', 'admin_term'), (r'^unapi/$', 'unapi'), + + (r'^site/(?P\d+)/copy_from/$', 'site_clipboard_copy_from'), + (r'^site/(?P\d+)/paste_to/$', 'site_clipboard_paste_to'), + (r'^site/(?P\d+)/paste_undo/$', 'site_clipboard_paste_undo'), ) diff --git a/conifer/syrup/views/sites.py b/conifer/syrup/views/sites.py index 7af9c35..7ba283f 100644 --- a/conifer/syrup/views/sites.py +++ b/conifer/syrup/views/sites.py @@ -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 index 0000000..8c55114 --- /dev/null +++ b/conifer/templates/site_confirm_paste.xhtml @@ -0,0 +1,30 @@ + + + + + + + ${title} + + +

${title}

+

Please confirm that you want to paste the materials into this site.

+ + + + + +
+

+ + ${go_back_link()} +

+
+ + \ 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 index 0000000..89b1194 --- /dev/null +++ b/conifer/templates/site_confirm_paste_undo.xhtml @@ -0,0 +1,32 @@ + + + + + + + ${title} + + +

${title}

+

Please confirm that you want to remove the materials that you last pasted into this site.

+ + + + + +
+

+ + ${go_back_link()} +

+
+ + \ No newline at end of file diff --git a/conifer/templates/site_detail.xhtml b/conifer/templates/site_detail.xhtml index 612e9ad..5142a45 100644 --- a/conifer/templates/site_detail.xhtml +++ b/conifer/templates/site_detail.xhtml @@ -34,9 +34,18 @@ is_joinable = site.is_joinable_by(request.user) + + + +
${add_subs()}
- - -- 2.11.0