}
.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;
.newsitem {
max-width: 600;
-}
\ No newline at end of file
+}
+
+.nestedtitle h2 { margin-top: 8; }
\ No newline at end of file
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):
(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
)
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
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,
py:strip="">
<!-- !show_tree: display a tree of items in a hierarchical style. -->
- <ul py:def="show_tree(tree)" py:if="tree">
+ <ul py:def="show_tree(tree)" py:if="tree" class="itemtree">
<li py:for="item, subs in tree">
<a href="/syrup/course/${item.course_id}/item/${item.id}/">${item}</a>
<span class="metalinks">
</li>
</ul>
+ <div py:def="nested_title(item)"
+ py:with="hier=item.hierarchy()[:-1]; lastnum=len(hier)"
+ class="nestedtitle">
+ <span py:for="n, x in enumerate(hier)"
+ style="margin-left: ${n}em;"><a href="${item_url(x)}">${x.title}</a> • </span>
+<h2>${item.title}</h2>
+ </div>
</html>
<title>${title}</title>
</head>
<body>
+ <p class="deptident">${course.department}</p>
<h1>${title}</h1>
- <p>${course.department}</p>
- <h2>Reserve Items</h2>
<p py:if="not item_tree">
There are no items associated with this course yet.
</p>
${show_tree(course.item_tree())}
+ <ul class="action"><li><a href="item/0/add?item_type=HEADING">Add subheading</a></li></ul>
</body>
</html>
--- /dev/null
+<!--
+ fixme, this is heading-specific. Should accommodate other types of item too.
+-->
+<?python
+title = 'Add a new subheading'
+course_title = '%s: %s (%s)' % (course.code, course.title, course.term)
+?>
+<html xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:xi="http://www.w3.org/2001/XInclude"
+ xmlns:py="http://genshi.edgewall.org/">
+ <xi:include href="master.xhtml"/>
+ <head>
+ <title>${title}</title>
+ </head>
+ <body>
+ <div class="courseident">
+ <div>${course.department}</div>
+ <h1><a href="${course_url(course)}">${course_title}</a></h1>
+ <h2>${title}</h2>
+ <form action=".?item_type=${item_type}" method="POST">
+ <table>
+ <tr><th>Heading</th><td><input type="text" name="title"/></td></tr>
+ </table>
+ <p><input type="submit" value="Create heading"/></p>
+ </form>
+ </div>
+</body>
+</html>
<title>${title}</title>
</head>
<body>
- <h1>${title}</h1>
- <p><a href="${course_url(course)}">${course_title}</a></p>
- <p>${course.department}</p>
- <p py:if="not item_tree">
- There are no items associated in this subheading.
- </p>
+ <div class="courseident">
+ <div>${course.department}</div>
+ <h1><a href="${course_url(course)}">${course_title}</a></h1>
+ </div>
+ ${nested_title(item)}
+ <!-- <p py:if="not item_tree"> -->
+ <!-- There are no items associated in this subheading. -->
+ <!-- </p> -->
${show_tree(item_tree)}
+ <ul class="action"><li><a href="add?item_type=HEADING">Add subheading</a></li></ul>
</body>
</html>
<?python
-course_title = '%s: %s (%s)' % (course.title, course.title, course.term)
+course_title = '%s: %s (%s)' % (course.code, course.title, course.term)
+hier = item.hierarchy()[:-1]
title = item.title
?>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns:py="http://genshi.edgewall.org/">
<xi:include href="master.xhtml"/>
+ <xi:include href="components/item.xhtml"/>
<head>
<title>${title}</title>
</head>
<body>
- <h1>${title}</h1>
- <p><a href="${course_url(course)}">${course_title}</a></p>
- <p>${course.department}</p>
+ <div class="courseident">
+ <div>${course.department}</div>
+ <h1><a href="${course_url(course)}">${course_title}</a></h1>
+ </div>
+ ${nested_title(item)}
- <p>Title: ${item.title}</p>
- <p>Type: ${item.item_type}</p>
- <p>Author: ${item.author}</p>
- <p py:if="item.url">URL: <a href="${item.url}">${item.url}</a></p>
+ <table>
+ <tr><th>Title</th><td>${item.title}</td></tr>
+ <tr><th>Type</th><td>${item.item_type}</td></tr>
+ <tr><th>Author</th><td>${item.author}</td></tr>
+ <tr py:if="item.url"><th>URL</th><td><a href="${item.url}">${item.url}</a></td></tr>
+ </table>
</body>
</html>
<span py:def="pagerow(item)">
<td>${Markup(item.author_hl(norm_query))}</td>
- <td>${Markup(item.title_hl(norm_query))}</td>
+ <td><a href="${item_url(item)}">${Markup(item.title_hl(norm_query))}</a></td>
</span>
${pagetable(paginator, count, pagerow, pageheader)}