From 63cd008a0fe89b394032ba71899a1a14ba2ff8d6 Mon Sep 17 00:00:00 2001 From: gfawcett Date: Sun, 11 Jan 2009 02:18:31 +0000 Subject: [PATCH] UI support for adding subheadings. It's a start. No other types of item can be added yet. Subheadings can be nested arbitrarily deep. Note, there are no access controls yet! Also tweaked search-results so that results link to the found items. git-svn-id: svn://svn.open-ils.org/ILS-Contrib/servres/trunk@101 6d9bc8c9-1ec2-4278-b937-99fde70a366f --- conifer/static/main.css | 7 +++-- conifer/syrup/models.py | 9 ++++++ conifer/syrup/urls.py | 1 + conifer/syrup/views.py | 44 ++++++++++++++++++++++++++++- conifer/templates/components/item.xhtml | 9 +++++- conifer/templates/course_detail.xhtml | 4 +-- conifer/templates/item_add.xhtml | 28 ++++++++++++++++++ conifer/templates/item_heading_detail.xhtml | 15 ++++++---- conifer/templates/item_metadata.xhtml | 22 +++++++++------ conifer/templates/search_results.xhtml | 2 +- 10 files changed, 120 insertions(+), 21 deletions(-) create mode 100644 conifer/templates/item_add.xhtml diff --git a/conifer/static/main.css b/conifer/static/main.css index b56585b..e1b6fa1 100644 --- a/conifer/static/main.css +++ b/conifer/static/main.css @@ -76,9 +76,10 @@ a:hover { text-decoration: underline; } } .pagetable thead th { font-size: smaller; text-align: left; padding: 2 8; } +.itemtree li { width: 400; } .metalinks { padding-left: 12; color: gray; } .metalinks a { color: navy; } -.metalinks { position: absolute; left: 300; } +.metalinks { position: absolute; left: 500; } .instructors { border: 1px solid #ccc; @@ -108,4 +109,6 @@ p.todo, div.todo { background-color: #fdd; padding: 6; margin: 12; border-left: .newsitem { max-width: 600; -} \ No newline at end of file +} + +.nestedtitle h2 { margin-top: 8; } \ No newline at end of file diff --git a/conifer/syrup/models.py b/conifer/syrup/models.py index 95e99fa..329a726 100644 --- a/conifer/syrup/models.py +++ b/conifer/syrup/models.py @@ -305,6 +305,15 @@ class Item(m.Model): def __unicode__(self): return self.title + def hierarchy(self): + """Return a list of items; the first is the topmost ancestor + of this item in the heading hierarchy; the last is the current + item. + """ + if self.parent_heading is None: + return [self] + else: + return self.parent_heading.hierarchy() + [self] #------------------------------------------------------------ class NewsItem(m.Model): diff --git a/conifer/syrup/urls.py b/conifer/syrup/urls.py index 0d4dbbe..cd95c76 100644 --- a/conifer/syrup/urls.py +++ b/conifer/syrup/urls.py @@ -19,4 +19,5 @@ urlpatterns = patterns('conifer.syrup.views', (ITEM_PREFIX + r'$', 'item_detail'), (ITEM_PREFIX + r'meta/$', 'item_metadata'), (ITEM_PREFIX + r'edit/$', 'item_edit'), + (ITEM_PREFIX + r'add/$', 'item_add'), # for adding sub-things ) diff --git a/conifer/syrup/views.py b/conifer/syrup/views.py index 91c9285..86f3b80 100644 --- a/conifer/syrup/views.py +++ b/conifer/syrup/views.py @@ -8,7 +8,8 @@ import re from conifer.syrup import models from django.contrib.auth.models import User from django.db.models import Q - +from datetime import datetime +from genshi_namespace import item_url, course_url #------------------------------------------------------------ # Authentication @@ -149,6 +150,47 @@ def _heading_url(request, item): def _heading_detail(request, item): """Display a heading. Show the subitems for this heading.""" return g.render('item_heading_detail.xhtml', item=item) + + + +def item_add(request, course_id, item_id): + # The item-id is the id for the parent-heading item. Zero represents + # 'top-level', i.e. the new item should have no heading. For any other + # number, we must check that the parent item is of the Heading type. + if item_id=='0': + parent_item = None + course = get_object_or_404(models.Course, pk=course_id) + else: + parent_item = get_object_or_404(models.Item, pk=item_id, course__id=course_id) + assert parent_item.item_type == 'HEADING', 'Can only add items to headings!' + course = parent_item.course + 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.' + + if request.method == 'GET': + return g.render('item_add.xhtml', **locals()) + else: + title = request.POST.get('title', '').strip() + if not title: + return HttpResponseRedirect(request.get_full_path()) + 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 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 d1e8ffe..d759568 100644 --- a/conifer/templates/components/item.xhtml +++ b/conifer/templates/components/item.xhtml @@ -4,7 +4,7 @@ py:strip=""> -