[open-ils-commits] r906 - in servres/trunk/conifer: integration syrup syrup/views templates (gfawcett)

svn at svn.open-ils.org svn at svn.open-ils.org
Wed Jul 14 20:53:41 EDT 2010


Author: gfawcett
Date: 2010-07-14 20:53:40 -0400 (Wed, 14 Jul 2010)
New Revision: 906

Added:
   servres/trunk/conifer/integration/_hooksystem.py
   servres/trunk/conifer/integration/hooks.py
Modified:
   servres/trunk/conifer/syrup/models.py
   servres/trunk/conifer/syrup/urls.py
   servres/trunk/conifer/syrup/views/__init__.py
   servres/trunk/conifer/syrup/views/courses.py
   servres/trunk/conifer/templates/my_courses.xhtml
   servres/trunk/conifer/templates/tabbar.xhtml
Log:
minor UI tweaks; introduced hook system for miscellaneous customizations.

The hook system is experimental; as the name suggests, it's a
mechanism for declaring and implementing hooks into various parts of
the application. Currently, I've just added one hook for determining
which users should be entitled to create new ReadingLists. We'll see
how it plays out.

Added: servres/trunk/conifer/integration/_hooksystem.py
===================================================================
--- servres/trunk/conifer/integration/_hooksystem.py	                        (rev 0)
+++ servres/trunk/conifer/integration/_hooksystem.py	2010-07-15 00:53:40 UTC (rev 906)
@@ -0,0 +1,36 @@
+# TODO: decide whether or not to use this!
+
+import warnings
+
+__all__ = ['hook', 'callhook', 'callhook_required', 'gethook']
+
+__HOOKS = {}
+
+def __register_hook(name, func):
+    assert isinstance(name, basestring)
+    assert callable(func)
+    if name in __HOOKS:
+        warnings.warn('redefining hook %r (%r)' % (name, func))
+    __HOOKS[name] = func
+    return func
+
+def hook(*args):
+    if isinstance(args[0], basestring):
+        return lambda f: __register_hook(args[0], f)
+    else:
+        f = args[0]
+        return __register_hook(f.__name__, f)
+
+def gethook(name, default=None):
+    return __HOOKS.get(name, default)
+
+def callhook_required(name, *args, **kwargs):
+    f = __HOOKS.get(name)
+    assert f, 'implementation for hook %r required but not found' % name
+    return f(*args, **kwargs)
+
+def callhook(name, *args, **kwargs):
+    f = __HOOKS.get(name)
+    if f:
+        return f(*args, **kwargs)
+

Added: servres/trunk/conifer/integration/hooks.py
===================================================================
--- servres/trunk/conifer/integration/hooks.py	                        (rev 0)
+++ servres/trunk/conifer/integration/hooks.py	2010-07-15 00:53:40 UTC (rev 906)
@@ -0,0 +1,8 @@
+from conifer.integration._hooksystem import *
+
+#----------------------------------------------------------------------
+# Your hooks go here.
+
+# @hook
+# def can_create_reading_lists(user):
+#     ...

Modified: servres/trunk/conifer/syrup/models.py
===================================================================
--- servres/trunk/conifer/syrup/models.py	2010-07-15 00:53:35 UTC (rev 905)
+++ servres/trunk/conifer/syrup/models.py	2010-07-15 00:53:40 UTC (rev 906)
@@ -8,8 +8,8 @@
 import random
 from django.utils import simplejson
 from conifer.middleware import genshi_locals
-
 # campus and library integration
+from conifer.integration._hooksystem import *
 from django.conf import settings
 campus = settings.CAMPUS_INTEGRATION
 # TODO: fixme, not sure if conifer.custom is a good parent.
@@ -42,9 +42,13 @@
 # candidate).
 
 class UserExtensionMixin(object):
-    def courses(self):
-        return Course.objects.filter(member__user=self.id)
+    def reading_lists(self):
+        return ReadingList.objects.filter(group__membership__user=self.id)
 
+    def can_create_reading_lists(self):
+        return self.is_staff or \
+            bool(callhook('can_create_reading_lists', self))
+
     @classmethod
     def active_instructors(cls):
         """Return a queryset of all active instructors."""
@@ -52,6 +56,8 @@
         return cls.objects.filter(membership__role='INSTR', is_active=True) \
             .order_by('-last_name','-first_name').distinct()
 
+
+
 for k,v in [(k,v) for k,v in UserExtensionMixin.__dict__.items() \
                 if not k.startswith('_')]:
     setattr(User, k, v)
@@ -65,6 +71,7 @@
 
     # When we add email notices for new items, this is how we'll set
     # the preference, and how far back we'll need to look.
+
     wants_email_notices = m.BooleanField(default=False)
     last_email_notice   = m.DateTimeField(
         default=datetime.now, blank=True, null=True)
@@ -290,7 +297,8 @@
     # external_id) is unique forall external_id != NULL.
 
     reading_list = m.ForeignKey(ReadingList)
-    external_id = m.CharField(default=None, null=True, blank=True,
+    external_id = m.CharField(null=True, blank=True,
+                              db_index=True,
                               max_length=2048)
 
     def __unicode__(self):

Modified: servres/trunk/conifer/syrup/urls.py
===================================================================
--- servres/trunk/conifer/syrup/urls.py	2010-07-15 00:53:35 UTC (rev 905)
+++ servres/trunk/conifer/syrup/urls.py	2010-07-15 00:53:40 UTC (rev 906)
@@ -47,7 +47,6 @@
     (r'^admin/desks/' + GENERIC_REGEX, 'admin_desks'),
     (r'^admin/courses/' + GENERIC_REGEX, 'admin_courses'),
     (r'^admin/depts/' + GENERIC_REGEX, 'admin_depts'),
-    (r'^admin/news/' + GENERIC_REGEX, 'admin_news'),
     (r'^admin/config/' + GENERIC_REGEX, 'admin_configs'),
     (r'^admin/targets/' + GENERIC_REGEX, 'admin_targets'),
 

Modified: servres/trunk/conifer/syrup/views/__init__.py
===================================================================
--- servres/trunk/conifer/syrup/views/__init__.py	2010-07-15 00:53:35 UTC (rev 905)
+++ servres/trunk/conifer/syrup/views/__init__.py	2010-07-15 00:53:40 UTC (rev 906)
@@ -1,3 +1,4 @@
+from conifer.integration import hooks
 from general import *
 from courses import *
 from items import *

Modified: servres/trunk/conifer/syrup/views/courses.py
===================================================================
--- servres/trunk/conifer/syrup/views/courses.py	2010-07-15 00:53:35 UTC (rev 905)
+++ servres/trunk/conifer/syrup/views/courses.py	2010-07-15 00:53:40 UTC (rev 906)
@@ -38,7 +38,7 @@
     
 @login_required
 def add_new_course(request):
-    if not request.user.has_perm('add_course'):
+    if not request.user.can_create_reading_lists():
         return _access_denied(_('You are not allowed to create course sites.'))
     return _add_or_edit_course(request)
 

Modified: servres/trunk/conifer/templates/my_courses.xhtml
===================================================================
--- servres/trunk/conifer/templates/my_courses.xhtml	2010-07-15 00:53:35 UTC (rev 905)
+++ servres/trunk/conifer/templates/my_courses.xhtml	2010-07-15 00:53:40 UTC (rev 906)
@@ -1,5 +1,5 @@
 <?python
-title = _('My Courses')
+title = _('My Reserves')
 ?>
 <html xmlns="http://www.w3.org/1999/xhtml"
       xmlns:xi="http://www.w3.org/2001/XInclude"
@@ -12,18 +12,18 @@
   <h1>${title}</h1>
   <?python
     if user.is_authenticated():
-        my_courses = user.courses()
+        my_courses = user.reading_lists()
     else:
         my_courses = []
   ?>
-  <p py:if="not my_courses">You are not part of any courses at this time.</p>
+  <p py:if="not my_courses">You are not part of any course reserves at this time.</p>
   <p py:for="course in my_courses" style="font-size: large;">
     <a href="${course.id}/">${course.list_display()}</a>
   </p>
   <div class="gap"/>
   <div class="itemadd">
-  <p py:if="user.has_perm('add_course')"><a href="new/">Create a new course site</a></p>
-  <p><a href="invitation/">Join a course using an Invitation Code</a></p>
+  <p py:if="user.can_create_reading_lists()"><a href="new/">Create a new course reserves list</a></p>
+  <p><a href="invitation/">Join a reserves list using an Invitation Code</a></p>
   </div>
 </body>
 </html>

Modified: servres/trunk/conifer/templates/tabbar.xhtml
===================================================================
--- servres/trunk/conifer/templates/tabbar.xhtml	2010-07-15 00:53:35 UTC (rev 905)
+++ servres/trunk/conifer/templates/tabbar.xhtml	2010-07-15 00:53:40 UTC (rev 906)
@@ -7,9 +7,9 @@
     use one for now
 -->
 <ul id="tabbar">
-  <li><a href="${ROOT}/">Home</a></li>
+  <!-- <li><a href="${ROOT}/">Home</a></li> -->
   <li><a href="${ROOT}/browse/">Browse</a></li>
-  <li class="active"><a href="${ROOT}/course/">My Courses</a></li>
+  <li class="active"><a href="${ROOT}/course/">My Reserves</a></li>
   <div py:strip="True"
        py:if="request.user.is_staff">
     <li><a href="${ROOT}/admin/">Admin Options</a></li>



More information about the open-ils-commits mailing list