From 40911915dd6ee627c6d49849ccef4bbb58af25fc Mon Sep 17 00:00:00 2001 From: gfawcett Date: Wed, 25 Mar 2009 02:52:37 +0000 Subject: [PATCH] added item-reordering for subheading-contents as well. git-svn-id: svn://svn.open-ils.org/ILS-Contrib/servres/trunk@216 6d9bc8c9-1ec2-4278-b937-99fde70a366f --- conifer/syrup/urls.py | 1 + conifer/syrup/views.py | 20 ++++++++++++++------ conifer/templates/components/course.xhtml | 15 +++++++++++++++ conifer/templates/course_detail.xhtml | 13 +------------ conifer/templates/item_heading_detail.xhtml | 1 + 5 files changed, 32 insertions(+), 18 deletions(-) diff --git a/conifer/syrup/urls.py b/conifer/syrup/urls.py index aa9a4f9..5453b52 100644 --- a/conifer/syrup/urls.py +++ b/conifer/syrup/urls.py @@ -45,6 +45,7 @@ urlpatterns = patterns('conifer.syrup.views', (r'^admin/news/' + GENERIC_REGEX, 'admin_news'), (r'^admin/targets/' + GENERIC_REGEX, 'admin_targets'), (r'^course/(?P\d+)/reseq$', 'course_reseq'), + (ITEM_PREFIX + r'reseq', 'item_heading_reseq'), # (r'^admin/terms/(?P\d+)/$', 'admin_term_edit'), # (r'^admin/terms/(?P\d+)/delete$', 'admin_term_delete'), # (r'^admin/terms/$', 'admin_term'), diff --git a/conifer/syrup/views.py b/conifer/syrup/views.py index bd8820a..ac79998 100644 --- a/conifer/syrup/views.py +++ b/conifer/syrup/views.py @@ -1124,16 +1124,13 @@ def course_feeds(request, course_id, feed_type): #------------------------------------------------------------ # resequencing items -@instructors_only -def course_reseq(request, course_id): - course = get_object_or_404(models.Course, pk=course_id) +def _reseq(request, course, parent_heading): new_order = request.POST['new_order'].split(',') # new_order is now a list like this: ['item_3', 'item_8', 'item_1', ...]. # get at the ints. new_order = [int(n.split('_')[1]) for n in new_order] print >> sys.stderr, new_order - # we are at top level, so parent-heading is null. - the_items = list(course.item_set.filter(parent_heading=None).order_by('sort_order')) + the_items = list(course.item_set.filter(parent_heading=parent_heading).order_by('sort_order')) # sort the items by position in new_order the_items.sort(key=lambda item: new_order.index(item.id)) for newnum, item in enumerate(the_items): @@ -1141,4 +1138,15 @@ def course_reseq(request, course_id): item.save() return HttpResponse("'ok'"); -# fixme, need to implement for subheading reordering too. +@instructors_only +def course_reseq(request, course_id): + course = get_object_or_404(models.Course, pk=course_id) + parent_heading = None + return _reseq(request, course, parent_heading) + +@instructors_only +def item_heading_reseq(request, course_id, item_id): + course = get_object_or_404(models.Course, pk=course_id) + item = get_object_or_404(models.Item, pk=item_id, course__id=course_id) + parent_heading = item + return _reseq(request, course, parent_heading) diff --git a/conifer/templates/components/course.xhtml b/conifer/templates/components/course.xhtml index 78bcc40..80cf5f1 100644 --- a/conifer/templates/components/course.xhtml +++ b/conifer/templates/components/course.xhtml @@ -92,4 +92,19 @@ searchtext = _('search this course...') + +
+ +
+ Save Ordering + Reorder Items + The new ordering has been saved. +
Drag the items around. Then click Save Ordering, above.
+
+
+ + diff --git a/conifer/templates/course_detail.xhtml b/conifer/templates/course_detail.xhtml index 1fe6967..081ed5b 100644 --- a/conifer/templates/course_detail.xhtml +++ b/conifer/templates/course_detail.xhtml @@ -20,21 +20,10 @@ is_editor = course.can_edit(request.user) - - + ${item_reorder_panel()} ${show_tree(item_tree, edit=is_editor)} -
${add_subs()}
-
- Save Ordering - Reorder Items - The new ordering has been saved. -
Drag the items around. Then click Save Ordering, above.
-
diff --git a/conifer/templates/item_heading_detail.xhtml b/conifer/templates/item_heading_detail.xhtml index 789df89..e90bf26 100644 --- a/conifer/templates/item_heading_detail.xhtml +++ b/conifer/templates/item_heading_detail.xhtml @@ -20,6 +20,7 @@ item_tree = course.item_tree(subtree=item)

There are no items in this section.

+ ${item_reorder_panel()} ${show_tree(item_tree, edit=is_editor)}
${add_subs(item)}
-- 2.11.0