Initial support for batching updates to revert course
authorArt Rhyno <art632000@yahoo.ca>
Wed, 22 Jun 2011 03:58:49 +0000 (23:58 -0400)
committerArt Rhyno <art632000@yahoo.ca>
Wed, 22 Jun 2011 03:58:49 +0000 (23:58 -0400)
materials for a course site.

Signed-off-by: Art Rhyno <art632000@yahoo.ca>
conifer/syrup/urls.py
conifer/syrup/views/sites.py
conifer/templates/components/site.xhtml
conifer/templates/revert_confirm.xhtml [new file with mode: 0644]
conifer/templates/site_detail.xhtml

index 9a2594c..49d2b64 100644 (file)
@@ -68,6 +68,8 @@ urlpatterns = patterns('conifer.syrup.views',
 #     (r'^admin/terms/$', 'admin_term'),
     (r'^unapi/$', 'unapi'),
 
+    (r'^site/(?P<site_id>\d+)/revert_parms/$', 'site_revert_parms'),
+
     (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 bc4af67..2f92ba2 100644 (file)
@@ -1,5 +1,11 @@
 from _common import *
 from search  import *
+from conifer.libsystems.evergreen.support import initialize, E1
+from conifer.plumbing.hooksystem          import *
+from django.conf                          import settings
+if hasattr(settings, 'OPENSRF_STAFF_USERID'): # TODO: we need an explicit 'we do updates' flag
+    from conifer.libsystems.evergreen import opensrf
+
 
 #-----------------------------------------------------------------------------
 # Creating a new site
@@ -257,6 +263,39 @@ def site_fuzzy_user_lookup(request):
                         content_type='application/json')
 
 
+def _revert_parms(request, source_site):
+    cnt = 0
+    def revert_item(parent, (item, subitems)):
+        update_status = False
+        if hasattr(settings, 'OPENSRF_STAFF_USERID'): 
+            update_status = True
+            dct = dict((k,v) for k,v in item.__dict__.items() if not k.startswith('_'))
+            dct['parent_heading_id'] = parent.id if parent else None
+            barcode = dct['barcode']
+            orig_call = dct['orig_callno']
+            orig_desk = dct['circ_desk']
+            orig_modifier = dct['circ_modifier']
+
+            if barcode and orig_call and orig_desk and orig_modifier:
+                update_status = opensrf.ils_item_update(barcode, orig_call,
+                                    orig_modifier, orig_desk)
+        if update_status:
+            for sub in subitems:
+                revert_item(parent, sub)
+        else:
+            return simple_message(_('Unable to update'),
+                _('Sorry, unable to finish updates, %d processed' % cnt))
+
+    for branch in source_site.item_tree():
+        revert_item(None, branch)
+
+def site_revert_parms(request, site_id):
+    site = get_object_or_404(models.Site, pk=site_id)
+    if request.method != 'POST':
+        return g.render('revert_confirm.xhtml', **locals())
+    _revert_parms(request, site)
+    return HttpResponseRedirect('../')
+
 def site_clipboard_copy_from(request, site_id):
     site = get_object_or_404(models.Site, pk=site_id)
     request.session['copy_source'] = site_id
index d4ac24a..df15e54 100644 (file)
@@ -111,6 +111,12 @@ searchtext = _('search this site...')
                <span py:if="item.published">(${item.published}).</span>
                <span py:if="item.source_title"><i>${item.source_title}.</i></span>
                <span py:if="item.volume or item.issue"><i>${item.volume}</i>(${item.issue}), ${item.pages}.</span>
+                 <div py:if="edit">
+            <span><i>Source: </i></span>
+                   <span py:if="item.circ_modifier">${item.circ_modifier}, </span>
+                   <span py:if="item.orig_callno">${item.orig_callno}, </span>
+                   <span py:if="item.circ_desk">desk - ${item.circ_desk}</span>
+                 </div>
       </div>
       <div class="forbidden_notice" py:if="forbidden">Awaiting copyright clearance: Not available to students.</div>
          <div>
diff --git a/conifer/templates/revert_confirm.xhtml b/conifer/templates/revert_confirm.xhtml
new file mode 100644 (file)
index 0000000..54d6d65
--- /dev/null
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+<?python
+title = _('Revert parameters for 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 update the catalogue with the parameters 
+    stored with the course materials.</p>
+    <table class="metadata_table">
+      <tr><th>Source:</th><td><a href="${site.site_url()}">${site}</a></td></tr>
+      <tr><th>Items:</th><td>
+      ${show_tree(site.item_tree(), edit=True)}
+      </td></tr>
+    </table>
+    <form action="." method="POST">
+      <p>
+       <input type="submit" value="Revert these materials"/>
+       ${go_back_link()}
+      </p>
+    </form>
+  </body>
+</html>
index cf498e6..f402dc4 100644 (file)
@@ -31,6 +31,7 @@ is_joinable = site.is_joinable_by(request.user)
       <div py:if="is_editor" id="edit_site" class="little_action_panel">
        <div><a href="${site.site_url()}edit/">Setup</a></div>
        <div><a href="${site.site_url()}edit/permission/">Permissions</a></div>
+       <div><a href="${site.site_url()}revert_parms/">Revert Parameters</a></div>
       </div>
       <div py:if="is_joinable">
        <a href="${site.site_url()}join/">Join this site</a>