[open-ils-commits] r378 - servres/trunk/conifer/syrup/views (gfawcett)

svn at svn.open-ils.org svn at svn.open-ils.org
Tue Apr 21 19:46:31 EDT 2009


Author: gfawcett
Date: 2009-04-21 19:46:30 -0400 (Tue, 21 Apr 2009)
New Revision: 378

Modified:
   servres/trunk/conifer/syrup/views/items.py
Log:
ensure that new items always appear at the end of their heading.


Modified: servres/trunk/conifer/syrup/views/items.py
===================================================================
--- servres/trunk/conifer/syrup/views/items.py	2009-04-21 23:17:41 UTC (rev 377)
+++ servres/trunk/conifer/syrup/views/items.py	2009-04-21 23:46:30 UTC (rev 378)
@@ -43,11 +43,17 @@
     if parent_item_id=='0':
         parent_item = None
         course = get_object_or_404(models.Course, pk=course_id)
+        siblings = course.item_set.filter(parent_heading=None)
     else:
         parent_item = get_object_or_404(models.Item, pk=parent_item_id, course__id=course_id)
         assert parent_item.item_type == 'HEADING', _('You can only add items to headings!')
         course = parent_item.course
+        siblings = course.item_set.filter(parent_heading=parent_item)
 
+    try:
+        next_order = 1 + max(i.sort_order for i in siblings)
+    except:
+        next_order = 0
     if not course.can_edit(request.user):
         return _access_denied(_('You are not an editor.'))
 
@@ -87,6 +93,7 @@
                 item = models.Item(
                     course=course,
                     item_type='HEADING',
+                    sort_order = next_order,
                     parent_heading=parent_item,
                     title=title,
                     )
@@ -104,6 +111,7 @@
                     course=course,
                     item_type='URL',
                     parent_heading=parent_item,
+                    sort_order = next_order,
                     title=title,
                     url = url)
                 item.save()
@@ -119,6 +127,7 @@
                 course=course,
                 item_type='ELEC',
                 parent_heading=parent_item,
+                sort_order = next_order,
                 title=title,
                 fileobj_mimetype = upload.content_type,
                 )
@@ -141,10 +150,18 @@
     if parent_item_id=='0':
         parent_item = None
         course = get_object_or_404(models.Course, pk=course_id)
+        siblings = course.item_set.filter(parent_heading=None)
     else:
         parent_item = get_object_or_404(models.Item, pk=parent_item_id, course__id=course_id)
         assert parent_item.item_type == 'HEADING', _('You can only add items to headings!')
         course = parent_item.course
+        siblings = course.item_set.filter(parent_heading=parent_item)
+
+    try:
+        next_order = 1 + max(i.sort_order for i in siblings)
+    except:
+        next_order = 0
+
     #----------
 
     if request.method != 'POST':
@@ -180,6 +197,7 @@
         dublin = marcxml_dictionary_to_dc(pickitem)
 
         item = course.item_set.create(parent_heading=parent_item,
+                                      sort_order=next_order,
                                       title=dublin.get('dc:title','Untitled'),
                                       item_type='PHYS')
         item.save()



More information about the open-ils-commits mailing list