From bffd8fae7cf2d71d34e31c21302f9e11ca9ad135 Mon Sep 17 00:00:00 2001 From: gfawcett Date: Tue, 21 Apr 2009 23:46:30 +0000 Subject: [PATCH] ensure that new items always appear at the end of their heading. git-svn-id: svn://svn.open-ils.org/ILS-Contrib/servres/trunk@378 6d9bc8c9-1ec2-4278-b937-99fde70a366f --- conifer/syrup/views/items.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/conifer/syrup/views/items.py b/conifer/syrup/views/items.py index 53d9162..d984241 100644 --- a/conifer/syrup/views/items.py +++ b/conifer/syrup/views/items.py @@ -43,11 +43,17 @@ def item_add(request, course_id, item_id): 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 @@ def item_add(request, course_id, item_id): item = models.Item( course=course, item_type='HEADING', + sort_order = next_order, parent_heading=parent_item, title=title, ) @@ -104,6 +111,7 @@ def item_add(request, course_id, item_id): course=course, item_type='URL', parent_heading=parent_item, + sort_order = next_order, title=title, url = url) item.save() @@ -119,6 +127,7 @@ def item_add(request, course_id, item_id): course=course, item_type='ELEC', parent_heading=parent_item, + sort_order = next_order, title=title, fileobj_mimetype = upload.content_type, ) @@ -141,10 +150,18 @@ def item_add_cat_search(request, course_id, item_id): 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 @@ def item_add_cat_search(request, course_id, item_id): 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() -- 2.11.0