Link to earliest available copy
authorArt Rhyno <art632000@yahoo.ca>
Mon, 14 Apr 2014 00:07:15 +0000 (20:07 -0400)
committerArt Rhyno <art632000@yahoo.ca>
Mon, 14 Apr 2014 00:07:15 +0000 (20:07 -0400)
Making syrup more multipart aware opened the door to
linking from the summary page to the full display
of a random copy. The summary page is set to always
show when the next available copy is due and it can
be jarring to see a different due time on the full
display. This should hopefully take care of that
scenario.

Signed-off-by: Art Rhyno <art632000@yahoo.ca>
conifer/integration/evergreen_site.py
conifer/syrup/models.py
conifer/templates/components/site.xhtml
conifer/templates/item/item_metadata.xhtml

index 002cd90..b1d3bb1 100644 (file)
@@ -183,6 +183,8 @@ class EvergreenIntegration(object):
         idlist = make_obj_string(ids)
         return self._item_status(item.bib_id, item.barcode, bclist, idlist)
 
+    #in general, you want to cache this for a few minutes
+    #but bump this value to 0 or something low for debugging
     CACHE_TIME = 300
 
     @memoize(timeout=CACHE_TIME)
@@ -307,13 +309,13 @@ class EvergreenIntegration(object):
             due_callno = callno
             due_callsuffix = callsuffix
              
-            if (avail == 0 or bringfw) and copy.circs and len(copy.circs) > 0:
+            if copy.circs and len(copy.circs) > 0:
                 if len(dueinfo) == 0 or bringfw:
                     earlydue = duetime
                     due,due_callno,due_callprefix,due_callsuffix = get_dueinfo(callprefix,callsuffix,callno,
-                        earliestdue,attachtest,voltest,sort_callno,bringfw,dueinfo)
+                        earlydue,attachtest,voltest,sort_callno,bringfw,dueinfo)
 
-                if duetime < earlydue and not bringfw:
+                if (earlydue is None or duetime < earlydue) and not bringfw:
                    earlydue = duetime
                    due = time.strftime(self.DUE_FORMAT,earliestdue)
 
@@ -379,7 +381,7 @@ class EvergreenIntegration(object):
                     
         #pull together status information
         def sort_out_status(barcode, sort_vol, counts, version, sort_lib, sort_desk, sort_avail, 
-            sort_callno, sort_dueinfo, sort_circmod, sort_allcalls, sort_alldues, prefix, suffix, 
+            sort_callno, sort_dueid, sort_dueinfo, sort_circmod, sort_allcalls, sort_alldues, prefix, suffix, 
             bcs,ids):
 
             vol = sort_vol
@@ -391,6 +393,7 @@ class EvergreenIntegration(object):
             circmod = sort_circmod
             allcalls = sort_allcalls
             alldues = sort_alldues
+            dueid = sort_dueid
 
             try:
                 if loc in self.RESERVES_DESK_NAME:
@@ -430,12 +433,21 @@ class EvergreenIntegration(object):
                     # we want to identify the copy that will be returned first if
                     # all are checked out
                     for copy in copies:
+                        #this condition should only ever be true when a multipart is in full display
+                        #in that case, the most available copy should be selected
+                        if len(ids) == 1:
+                            if ids[0][0] == '':
+                                avail = 1 
                         if copy.part_label:
                             #print "callno", callno
                             #print "sort_callno", sort_callno
+
                             callno = sort_callno + " " + copy.part_label
                             if copy.part_sort in copy_parts and len(copy_parts) > 0:
-                                allcalls[len(allcalls) - 1] = [callno,READY,copy.syrup_id,copy.part_label]
+                                #leave alone if locked - otherwise mark as ready
+                                if allcalls[len(allcalls) - 1][1] != LOCKED:
+                                    allcalls[len(allcalls) - 1] = [callno,READY,copy.syrup_id,copy.part_label]
+                                    
                             else:
                                 allcalls.append([callno,READY,copy.syrup_id,copy.part_label])
                             copy_parts.append(copy.part_sort)
@@ -452,6 +464,8 @@ class EvergreenIntegration(object):
                             #remove offset info, %z is flakey for some reason
                             rawdate = rawdate[:-5]
                             duetime = time.strptime(rawdate, self.TIME_FORMAT)
+                        elif len(allcalls) == 0:
+                            dueid = [copy.syrup_id,LOCKED]
 
                         #get due information - lots of extra pieces needed for embedded parts
                         dueinfo,callprefix,callno,callsuffix = deal_with_dues(duetime,avail,bringfw,copy,
@@ -460,15 +474,22 @@ class EvergreenIntegration(object):
                         alldisplay = callno + ' (Available)'
 
                         if copy.circs and isinstance(copy.circs, list):
-                            if len(allcalls) > 0 and (earliestdue is None or duetime < earliestdue):
+                            if (earliestdue is None or duetime < earliestdue):
+                                #print "SETTING earliest to", duetime
                                 earliestdue = duetime
-                            alldisplay = '%s (DUE: %s)' % (callno,time.strftime(self.DUE_FORMAT,duetime))
+                                dueinfo = time.strftime(self.DUE_FORMAT,earliestdue)
+                                #will want the link to be to the earliest item if not multipart
+                                if len(allcalls) == 0 and dueid[1] != LOCKED:
+                                    dueid = [copy.syrup_id,DUE]
+
+                            alldisplay = '%s (DUE: %s)' % (callno,time.strftime(self.DUE_FORMAT,earliestdue))
 
                             if len(allcalls) > 0:
                                 if allcalls[len(allcalls) - 1][1] != LOCKED:
                                     allcalls[len(allcalls) - 1] = [alldisplay,DUE,copy.syrup_id,copy.part_label]
-                                    avail -= 1
-                            else:
+                                    if avail >= 1:
+                                        avail -= 1
+                            elif avail >= 1:
                                 avail -= 1
                                
                         elif len(allcalls) > 0:
@@ -483,7 +504,7 @@ class EvergreenIntegration(object):
                 print "*** print_exc:"
                 traceback.print_exc()
         
-            return (vol, lib, desk, avail, callno, dueinfo, circmod, allcalls, alldues)
+            return (vol, lib, desk, avail, callno, dueid, dueinfo, circmod, allcalls, alldues)
 
         #get lists of barcodes and ids
         bcs = make_obj_list(bclist)
@@ -496,6 +517,7 @@ class EvergreenIntegration(object):
         assert self.RESERVES_DESK_NAME, 'No RESERVES_DESK_NAME specified!'
 
         lib = desk = avail = vol = anystatus_here = 0
+        dueid = ['',READY]
         dueinfo = ''
         callno  = ''
         circmod = ''
@@ -518,17 +540,17 @@ class EvergreenIntegration(object):
                     prefix += ' '
                 if len(suffix) > 0:
                     suffix = ' ' + suffix
-                vol, lib, desk, avail, callno, dueinfo, circmod, allcalls, alldues = sort_out_status(barcode, vol, counts, 
-                    version, lib, desk, avail, callno, dueinfo, circmod, allcalls, alldues, prefix, suffix, bcs,ids)
+                vol, lib, desk, avail, callno, dueid, dueinfo, circmod, allcalls, alldues = sort_out_status(barcode, vol, counts, 
+                    version, lib, desk, avail, callno, dueid, dueinfo, circmod, allcalls, alldues, prefix, suffix, bcs,ids)
         else:
             for org, callno, loc, stats in counts:
-                vol, lib, desk, avail, callno, dueinfo, circmod, allcalls, alldues = sort_out_status(barcode, vol, counts, 
-                    version, lib, desk, avail, callno, dueinfo, circmod, allcalls, alldues, bcs,ids)
+                vol, lib, desk, avail, callno, dueid, dueinfo, circmod, allcalls, alldues = sort_out_status(barcode, vol, counts, 
+                    version, lib, desk, avail, callno, dueid, dueinfo, circmod, allcalls, alldues, bcs,ids)
             
         if len(allcalls) > 0:
             cpname = 'volumes'
 
-        return (cpname, lib, desk, avail, callno, dueinfo, circmod, allcalls, alldues)
+        return (cpname, lib, desk, avail, callno, dueid[0], dueinfo, circmod, allcalls, alldues)
 
 
 
index 680bcff..db818b2 100644 (file)
@@ -925,7 +925,7 @@ class Item(BaseModel):
         if not stat:
             return (False, 'Status information not available.')
         else:
-            cpname, lib, desk, avail, callno, dueinfo, circmod, allcalls, alldues = stat
+            cpname, lib, desk, avail, callno, dueid, dueinfo, circmod, allcalls, alldues = stat
             return (avail > 0,
                     '%d of %d %s available at reserves desk; %d total copies in library system' % 
                     (avail, desk, cpname, lib))
index f52bfa8..9e31b3e 100644 (file)
@@ -39,7 +39,7 @@ searchtext = _('search this site...')
        stat = callhook('item_status', item, bcs, ids) if (item.item_type == 'PHYS') else None
        valid = stat is not None
       ?>
-      <span py:if="valid" py:with="(_cpname, _lib, _desk, _avail, _callno, _dueinfo, _circmod, _allcalls, _alldues) = stat">
+      <span py:if="valid" py:with="(_cpname, _lib, _desk, _avail, _callno, _dueid, _dueinfo, _circmod, _allcalls, _alldues) = stat">
       <div class="availability" py:if="item.item_type == 'PHYS'">
        <a href="${item.item_url()}">
        <div class="${_avail &gt; 0 and 'available' or 'unavailable'}"
@@ -70,7 +70,7 @@ searchtext = _('search this site...')
                 <span py:if="k==0" class="unavailable">${j}</span>
                 <span py:if="k &gt; 0">Ask for: <span class="standout">${j}</span></span>
          </div>
-          <div py:if="_dueinfo">NEXT DUE: ${_dueinfo}</div>
+          <div py:if="_avail == 0 and _dueinfo">NEXT DUE: ${_dueinfo}</div>
          </div>
                  
          <div py:if="not valid" class="unavailable">
@@ -109,13 +109,6 @@ searchtext = _('search this site...')
       <div class="availability avail_nonphys" py:if="item.item_type != 'PHYS'">
       </div>
       <div class="mainline ${item.item_type=='HEADING' and 'headingmainline' or ''}">
-       <span py:if="item.item_type=='ELEC' and not downloads_allowed">
-         <img title="Sorry, this document is not available to you."
-              src="${ROOT}/static/tango/lock.png"/></span>
-         <a py:if="len(_allcalls) == 0 or (edit and user.is_staff)" href="${item.item_url()}" class="mainlink"
-            py:strip="item.item_type=='ELEC' and not downloads_allowed">${item}</a> 
-       <span py:if="item.suppress_item">[additional copy - not displayed]</span>
-        <span py:if="len(_allcalls) &gt; 0 and not (edit and user.is_staff)">
         <?python
             site_url = item.item_url()
             #get base of url without item number
@@ -135,6 +128,17 @@ searchtext = _('search this site...')
                 elif len(m) > 0 or len(display_calls) == 0:
                     display_calls.append([site_url + str(l),item,part])
         ?>
+       <span py:if="item.item_type=='ELEC' and not downloads_allowed">
+         <img title="Sorry, this document is not available to you."
+              src="${ROOT}/static/tango/lock.png"/></span>
+          <span py:if="len(_allcalls) == 0 or (edit and user.is_staff)">
+          <a py:if="not _dueid" href="${item.item_url()}" class="mainlink"
+             py:strip="item.item_type=='ELEC' and not downloads_allowed">${item}</a> 
+          <a py:if="_dueid" href="${site_url}${_dueid}" class="mainlink"
+             py:strip="item.item_type=='ELEC' and not downloads_allowed">${item}</a> 
+          </span>
+       <span py:if="item.suppress_item">[additional copy - not displayed]</span>
+        <span py:if="len(_allcalls) &gt; 0 and not (edit and user.is_staff)">
          <div py:for="i,j,k in display_calls"> 
                <a href="${i}" class="mainlink">${j}${k}</a>
          </div>
index b8e7eac..1d4e429 100644 (file)
@@ -63,7 +63,7 @@ callnum = item.call_number()
         stat = callhook('item_status', item) if (item.item_type == 'PHYS') else None
         valid = stat is not None
       ?>
-      <tr py:if="valid" py:with="(_cpname, _lib, _desk, _avail, _callno, _dueinfo, _circmod, _allcalls, _alldues) = stat"
+      <tr py:if="valid" py:with="(_cpname, _lib, _desk, _avail, _callno, _dueid, _dueinfo, _circmod, _allcalls, _alldues) = stat"
              title="${_avail} of ${_desk} copies available at reserves desk; ${_lib} total copies in library system">
          <th>Call Number(s) (take to the counter)</th>
           <td>