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

svn at svn.open-ils.org svn at svn.open-ils.org
Sat Jan 10 23:04:18 EST 2009


Author: gfawcett
Date: 2009-01-10 23:04:16 -0500 (Sat, 10 Jan 2009)
New Revision: 103

Modified:
   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
Log:
Basic UI support for adding URL items.

Will need some refactoring.


Modified: servres/trunk/conifer/syrup/views.py
===================================================================
--- servres/trunk/conifer/syrup/views.py	2009-01-11 04:01:41 UTC (rev 102)
+++ servres/trunk/conifer/syrup/views.py	2009-01-11 04:04:16 UTC (rev 103)
@@ -167,30 +167,50 @@
     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,

Modified: servres/trunk/conifer/templates/components/item.xhtml
===================================================================
--- servres/trunk/conifer/templates/components/item.xhtml	2009-01-11 04:01:41 UTC (rev 102)
+++ servres/trunk/conifer/templates/components/item.xhtml	2009-01-11 04:04:16 UTC (rev 103)
@@ -21,6 +21,17 @@
        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>
+    <h2>${item.title}</h2>
   </div>
+
+  <ul py:def="add_subs(parent=None)">
+    <li>Add a new item...</li>
+    <ul py:with="prefix = (not parent) and 'item/0/' or ''">
+      <li><a href="${prefix}add?item_type=HEADING">Add subheading</a></li>
+      <li><a href="${prefix}add?item_type=URL">Add URL</a></li>
+      <li><a href="${prefix}add?item_type=ELEC">Add Electronic Document</a></li>
+      <li><a href="${prefix}add?item_type=PHYS">Add Physical Book/Document</a></li>
+    </ul>
+  </ul>
+  
 </html>

Modified: servres/trunk/conifer/templates/course_detail.xhtml
===================================================================
--- servres/trunk/conifer/templates/course_detail.xhtml	2009-01-11 04:01:41 UTC (rev 102)
+++ servres/trunk/conifer/templates/course_detail.xhtml	2009-01-11 04:04:16 UTC (rev 103)
@@ -17,6 +17,6 @@
       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>
+    ${add_subs()}
   </body>
 </html>

Modified: servres/trunk/conifer/templates/item_heading_detail.xhtml
===================================================================
--- servres/trunk/conifer/templates/item_heading_detail.xhtml	2009-01-11 04:01:41 UTC (rev 102)
+++ servres/trunk/conifer/templates/item_heading_detail.xhtml	2009-01-11 04:04:16 UTC (rev 103)
@@ -22,6 +22,6 @@
     <!--   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>
+    ${add_subs(item)}
   </body>
 </html>



More information about the open-ils-commits mailing list