[open-ils-commits] r101 - in servres/trunk/conifer: static syrup templates templates/components

svn at svn.open-ils.org svn at svn.open-ils.org
Sat Jan 10 21:18:32 EST 2009


Author: gfawcett
Date: 2009-01-10 21:18:31 -0500 (Sat, 10 Jan 2009)
New Revision: 101

Added:
   servres/trunk/conifer/templates/item_add.xhtml
Modified:
   servres/trunk/conifer/static/main.css
   servres/trunk/conifer/syrup/models.py
   servres/trunk/conifer/syrup/urls.py
   servres/trunk/conifer/syrup/views.py
   servres/trunk/conifer/templates/components/item.xhtml
   servres/trunk/conifer/templates/course_detail.xhtml
   servres/trunk/conifer/templates/item_heading_detail.xhtml
   servres/trunk/conifer/templates/item_metadata.xhtml
   servres/trunk/conifer/templates/search_results.xhtml
Log:
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.


Modified: servres/trunk/conifer/static/main.css
===================================================================
--- servres/trunk/conifer/static/main.css	2009-01-11 02:11:40 UTC (rev 100)
+++ servres/trunk/conifer/static/main.css	2009-01-11 02:18:31 UTC (rev 101)
@@ -76,9 +76,10 @@
 }
 .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 @@
 
 .newsitem { 
     max-width: 600;
-}
\ No newline at end of file
+}
+
+.nestedtitle h2 { margin-top: 8; }
\ No newline at end of file

Modified: servres/trunk/conifer/syrup/models.py
===================================================================
--- servres/trunk/conifer/syrup/models.py	2009-01-11 02:11:40 UTC (rev 100)
+++ servres/trunk/conifer/syrup/models.py	2009-01-11 02:18:31 UTC (rev 101)
@@ -305,6 +305,15 @@
     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):

Modified: servres/trunk/conifer/syrup/urls.py
===================================================================
--- servres/trunk/conifer/syrup/urls.py	2009-01-11 02:11:40 UTC (rev 100)
+++ servres/trunk/conifer/syrup/urls.py	2009-01-11 02:18:31 UTC (rev 101)
@@ -19,4 +19,5 @@
     (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
 )

Modified: servres/trunk/conifer/syrup/views.py
===================================================================
--- servres/trunk/conifer/syrup/views.py	2009-01-11 02:11:40 UTC (rev 100)
+++ servres/trunk/conifer/syrup/views.py	2009-01-11 02:18:31 UTC (rev 101)
@@ -8,8 +8,9 @@
 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_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,

Modified: servres/trunk/conifer/templates/components/item.xhtml
===================================================================
--- servres/trunk/conifer/templates/components/item.xhtml	2009-01-11 02:11:40 UTC (rev 100)
+++ servres/trunk/conifer/templates/components/item.xhtml	2009-01-11 02:18:31 UTC (rev 101)
@@ -4,7 +4,7 @@
       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">
@@ -16,4 +16,11 @@
     </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> &bull; </span>
+<h2>${item.title}</h2>
+  </div>
 </html>

Modified: servres/trunk/conifer/templates/course_detail.xhtml
===================================================================
--- servres/trunk/conifer/templates/course_detail.xhtml	2009-01-11 02:11:40 UTC (rev 100)
+++ servres/trunk/conifer/templates/course_detail.xhtml	2009-01-11 02:18:31 UTC (rev 101)
@@ -11,12 +11,12 @@
     <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>

Added: servres/trunk/conifer/templates/item_add.xhtml
===================================================================
--- servres/trunk/conifer/templates/item_add.xhtml	                        (rev 0)
+++ servres/trunk/conifer/templates/item_add.xhtml	2009-01-11 02:18:31 UTC (rev 101)
@@ -0,0 +1,28 @@
+<!-- 
+     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>

Modified: servres/trunk/conifer/templates/item_heading_detail.xhtml
===================================================================
--- servres/trunk/conifer/templates/item_heading_detail.xhtml	2009-01-11 02:11:40 UTC (rev 100)
+++ servres/trunk/conifer/templates/item_heading_detail.xhtml	2009-01-11 02:18:31 UTC (rev 101)
@@ -13,12 +13,15 @@
     <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>

Modified: servres/trunk/conifer/templates/item_metadata.xhtml
===================================================================
--- servres/trunk/conifer/templates/item_metadata.xhtml	2009-01-11 02:11:40 UTC (rev 100)
+++ servres/trunk/conifer/templates/item_metadata.xhtml	2009-01-11 02:18:31 UTC (rev 101)
@@ -1,22 +1,28 @@
 <?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>

Modified: servres/trunk/conifer/templates/search_results.xhtml
===================================================================
--- servres/trunk/conifer/templates/search_results.xhtml	2009-01-11 02:11:40 UTC (rev 100)
+++ servres/trunk/conifer/templates/search_results.xhtml	2009-01-11 02:18:31 UTC (rev 101)
@@ -72,7 +72,7 @@
   
     <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)}
 



More information about the open-ils-commits mailing list