From: gfawcett Date: Sun, 11 Jan 2009 04:04:16 +0000 (+0000) Subject: Basic UI support for adding URL items. X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=1e8ff51803275520fc491d6746e6d0a2e4d70f3b;p=Syrup.git Basic UI support for adding URL items. Will need some refactoring. git-svn-id: svn://svn.open-ils.org/ILS-Contrib/servres/trunk@103 6d9bc8c9-1ec2-4278-b937-99fde70a366f --- diff --git a/conifer/syrup/views.py b/conifer/syrup/views.py index 43a92a4..3ee61b9 100644 --- a/conifer/syrup/views.py +++ b/conifer/syrup/views.py @@ -167,30 +167,50 @@ def item_add(request, course_id, item_id): item_type = request.GET.get('item_type') assert item_type, 'No item_type parameter was provided.' - # for the moment, only HEADINGs can be added. - assert item_type == 'HEADING', 'Sorry, only HEADINGs can be added right now.' + # for the moment, only HEADINGs and URLs can be added. + assert item_type in ('HEADING', 'URL'), 'Sorry, only HEADINGs and URLs can be added right now.' if request.method == 'GET': - return g.render('item_add_heading.xhtml', **locals()) + return g.render('item_add_%s.xhtml' % item_type.lower(), + **locals()) else: - title = request.POST.get('title', '').strip() - if not title: - return HttpResponseRedirect(request.get_full_path()) + # fixme, this will need refactoring. But not yet. + if item_type == 'HEADING': + title = request.POST.get('title', '').strip() + if not title: + # fixme, better error handling. + return HttpResponseRedirect(request.get_full_path()) + else: + item = models.Item( + course=course, + item_type='HEADING', + parent_heading=parent_item, + title=title, + author=request.user.get_full_name(), + activation_date=datetime.now(), + last_modified=datetime.now()) + item.save() + return HttpResponseRedirect(item_url(item)) + elif item_type == 'URL': + title = request.POST.get('title', '').strip() + url = request.POST.get('url', '').strip() + if not (title or url): + # fixme, better error handling. + return HttpResponseRedirect(request.get_full_path()) + else: + item = models.Item( + course=course, + item_type='URL', + parent_heading=parent_item, + title=title, + author=request.user.get_full_name(), + activation_date=datetime.now(), + last_modified=datetime.now(), + url = url) + item.save() + return HttpResponseRedirect(item_url(item) + 'meta/') else: - # rubber hits road. - item = models.Item( - course=course, - item_type='HEADING', - parent_heading=parent_item, - title=title, - author=request.user.get_full_name(), - activation_date=datetime.now(), - last_modified=datetime.now()) - item.save() - return HttpResponseRedirect(item_url(item)) - - - raise NotImplementedError + raise NotImplementedError def normalize_query(query_string, findterms=re.compile(r'"([^"]+)"|(\S+)').findall, diff --git a/conifer/templates/components/item.xhtml b/conifer/templates/components/item.xhtml index d759568..8771778 100644 --- a/conifer/templates/components/item.xhtml +++ b/conifer/templates/components/item.xhtml @@ -21,6 +21,17 @@ class="nestedtitle"> ${x.title} -

${item.title}

+

${item.title}

+ + + diff --git a/conifer/templates/course_detail.xhtml b/conifer/templates/course_detail.xhtml index d97f652..4410d6e 100644 --- a/conifer/templates/course_detail.xhtml +++ b/conifer/templates/course_detail.xhtml @@ -17,6 +17,6 @@ item_tree = course.item_tree() There are no items associated with this course yet.

${show_tree(course.item_tree())} - + ${add_subs()} diff --git a/conifer/templates/item_heading_detail.xhtml b/conifer/templates/item_heading_detail.xhtml index 4f27a6b..d2312e4 100644 --- a/conifer/templates/item_heading_detail.xhtml +++ b/conifer/templates/item_heading_detail.xhtml @@ -22,6 +22,6 @@ item_tree = course.item_tree(subtree=item) ${show_tree(item_tree)} - + ${add_subs(item)}