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

svn at svn.open-ils.org svn at svn.open-ils.org
Sun Jan 11 18:44:32 EST 2009


Author: gfawcett
Date: 2009-01-11 18:44:27 -0500 (Sun, 11 Jan 2009)
New Revision: 108

Added:
   servres/trunk/conifer/static/tango/x-office-address-book.png
Modified:
   servres/trunk/conifer/static/main.css
   servres/trunk/conifer/syrup/models.py
   servres/trunk/conifer/syrup/views.py
   servres/trunk/conifer/templates/components/item.xhtml
   servres/trunk/conifer/templates/item_heading_detail.xhtml
Log:
basic access-controls on adding/editing items; added phys-item icon.

Only instructors and proxy-instructors can add items. We hide
edit-links if user isn't an editor.

The physical item icon could be improved.


Modified: servres/trunk/conifer/static/main.css
===================================================================
--- servres/trunk/conifer/static/main.css	2009-01-11 22:29:03 UTC (rev 107)
+++ servres/trunk/conifer/static/main.css	2009-01-11 23:44:27 UTC (rev 108)
@@ -127,7 +127,13 @@
     margin-top: 4;
 }
 
+.itemtree li.item_PHYS { 
+    /* fixme: need a better icon */
+    list-style-image: url(tango/x-office-address-book.png);
+    margin-top: 4;
+}
 
+
 .instructors {
   border: 1px solid #ccc;
   float: left;

Added: servres/trunk/conifer/static/tango/x-office-address-book.png
===================================================================
--- servres/trunk/conifer/static/tango/x-office-address-book.png	                        (rev 0)
+++ servres/trunk/conifer/static/tango/x-office-address-book.png	2009-01-11 23:44:27 UTC (rev 108)
@@ -0,0 +1,16 @@
+‰PNG
+
+   
+IHDR         óÿa   bKGD ÿ ÿ ÿ ½§“   	pHYs     šœ   tIMEÕ
+*(¹dºÊ   5tEXtComment (c) 2004 Jakub Steiner
+
+Created with The GIMPÙ‹o  =IDAT8Ë•“MOSA†Ÿ™Þ¹÷öƒ¶`?PjbLŒ1&Æhü
+š`ܘâÂ…Á¤,Lü„=‘Ÿ`â„
+0V´T¡ -·íííôŽ‹b¡ÂBO2›™9ϼï9gÀTqa˜áßc~ñÕô,€˜*.̍H=óâùC<_ãµ:ZSóÚ H) Ç™
+? ^YæÙ½"©ìäK˜yüèA†FvƒÙTŒò>ÊCå=T«M¨"x£Z™ù‘8u •¤¶·ôÚpGààÐ#s¡Þ$]ªP»2JˆaùmR¥
+]‘81'è{± \W†–ß;_*ÔDzD‚¹Õ-ŒüºV ùmÆóDíÎ ÀvlÂnØ߇íBŽÌZ‰z!GâÇ>ÚµQM€wŸ|:jƒ+1$€­æT¡
+F¤îb"稉ŽÚgÚ!„€9!Ä]TÃÇê½n+’Û?©_Î÷ø$-œDŽ’Ü,S»zu@ˆ[nIñdn¯7{ ƒ¹) L6M½­I~ßE5ZtmEõæĹÕS`@)‹t:ßÑä‡ã$£\ëëJ
+hüà5Z¼Y~‹%
+¡é-­
+B
+lA ºÝ¯åj˜oÉÏëë O-€«[Ü¿ïíy!¥¤)Òlìr{üwÅX ‡^ƒ‰Ü…Â¥3‰âT×6wέÁüûÍêŒn5Ýj ]W¡;zÀð„î†LÞɘ¥•ª8Ý79U\˜ýÏïÌâ«iðs»ÛÙj¾lÿ    IEND®B`‚
\ No newline at end of file

Modified: servres/trunk/conifer/syrup/models.py
===================================================================
--- servres/trunk/conifer/syrup/models.py	2009-01-11 22:29:03 UTC (rev 107)
+++ servres/trunk/conifer/syrup/models.py	2009-01-11 23:44:27 UTC (rev 108)
@@ -165,6 +165,14 @@
         walk(subtree, out)
         return out
 
+    def can_edit(self, user):
+        if user.is_anonymous():
+            return False
+        try:
+            mbr = Member.objects.get(course=self, user=user)
+        except Member.DoesNotExist:
+            return False
+        return mbr.role in (u'INSTR', u'PROXY')
 
 class Member(m.Model):
     course = m.ForeignKey(Course)

Modified: servres/trunk/conifer/syrup/views.py
===================================================================
--- servres/trunk/conifer/syrup/views.py	2009-01-11 22:29:03 UTC (rev 107)
+++ servres/trunk/conifer/syrup/views.py	2009-01-11 23:44:27 UTC (rev 108)
@@ -1,4 +1,5 @@
 from django.http import HttpResponse, HttpResponseRedirect
+from django.http import HttpResponseForbidden
 from django.core.paginator import Paginator
 from django.shortcuts import get_object_or_404
 from django.contrib.auth.decorators import login_required
@@ -138,6 +139,7 @@
         return g.render('item_metadata.xhtml', course=item.course,
                         item=item)
 
+ at login_required
 def item_edit(request, course_id, item_id):
     """Edit an item."""
     # For now, just pop to the Admin interface.
@@ -152,7 +154,7 @@
     return g.render('item_heading_detail.xhtml', item=item)
 
 
-
+ at login_required
 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
@@ -164,6 +166,10 @@
         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
+
+    if not course.can_edit(user):
+        return HttpResponseForbidden('not an editor') # fixme, prettier msg?
+
     item_type = request.GET.get('item_type')
     assert item_type, 'No item_type parameter was provided.'
 
@@ -175,6 +181,7 @@
                         **locals())
     else:
         # fixme, this will need refactoring. But not yet.
+        author = request.user.get_full_name() or request.user.username
         if item_type == 'HEADING':
             title = request.POST.get('title', '').strip()
             if not title:
@@ -186,7 +193,7 @@
                     item_type='HEADING',
                     parent_heading=parent_item,
                     title=title,
-                    author=request.user.get_full_name() or request.user.username,
+                    author=author,
                     activation_date=datetime.now(),
                     last_modified=datetime.now())
                 item.save()
@@ -203,7 +210,7 @@
                     item_type='URL',
                     parent_heading=parent_item,
                     title=title,
-                    author=request.user.get_full_name() or request.user.username,
+                    author=author,
                     activation_date=datetime.now(),
                     last_modified=datetime.now(),
                     url = url)

Modified: servres/trunk/conifer/templates/components/item.xhtml
===================================================================
--- servres/trunk/conifer/templates/components/item.xhtml	2009-01-11 22:29:03 UTC (rev 107)
+++ servres/trunk/conifer/templates/components/item.xhtml	2009-01-11 23:44:27 UTC (rev 108)
@@ -10,7 +10,7 @@
       <span py:if="item.needs_meta_link()" class="metalink">
 	[<a href="${item_url(item)}meta/">about</a>]
       </span>
-      <span class="editlinks">
+      <span class="editlinks" py:if="edit">
 	[<a href="${item_url(item)}edit/">edit</a>]
       </span>
       ${show_tree(subs)}

Modified: servres/trunk/conifer/templates/item_heading_detail.xhtml
===================================================================
--- servres/trunk/conifer/templates/item_heading_detail.xhtml	2009-01-11 22:29:03 UTC (rev 107)
+++ servres/trunk/conifer/templates/item_heading_detail.xhtml	2009-01-11 23:44:27 UTC (rev 108)
@@ -2,6 +2,7 @@
 course = item.course
 title = item.title
 course_title = '%s: %s (%s)' % (course.code, course.title, course.term)
+is_editor = course.can_edit(request.user)
 item_tree = course.item_tree(subtree=item)
 ?>
 <html xmlns="http://www.w3.org/1999/xhtml"
@@ -21,7 +22,7 @@
     <!-- <p py:if="not item_tree"> -->
     <!--   There are no items associated in this subheading. -->
     <!-- </p> -->
-    ${show_tree(item_tree)}
-    ${add_subs(item)}
+    ${show_tree(item_tree, edit=is_editor)}
+    <div py:if="is_editor">${add_subs(item)}</div>
   </body>
 </html>



More information about the open-ils-commits mailing list