cleanup of UserProfile model. Redefinition of active_instructors. updated Browse...
authorgfawcett <gfawcett@6d9bc8c9-1ec2-4278-b937-99fde70a366f>
Fri, 20 Mar 2009 01:48:30 +0000 (01:48 +0000)
committergfawcett <gfawcett@6d9bc8c9-1ec2-4278-b937-99fde70a366f>
Fri, 20 Mar 2009 01:48:30 +0000 (01:48 +0000)
git-svn-id: svn://svn.open-ils.org/ILS-Contrib/servres/trunk@206 6d9bc8c9-1ec2-4278-b937-99fde70a366f

conifer/syrup/models.py
conifer/syrup/views.py
conifer/templates/courses.xhtml
conifer/templates/instructors.xhtml

index 1f8e199..cb01746 100644 (file)
@@ -48,6 +48,13 @@ class UserExtensionHack(object):
     def courses(self):
         return Course.objects.filter(member__user=self.id)
 
+    @classmethod
+    def active_instructors(cls):
+        """Return a queryset of all active instructors."""
+        # We are using the Django is_active flag to model activeness.
+        return cls.objects.filter(member__role='INSTR', is_active=True) \
+            .order_by('-last_name','-first_name')
+    
 for k,v in [(k,v) for k,v in UserExtensionHack.__dict__.items() \
                 if not k.startswith('_')]:
     setattr(User, k, v)
@@ -59,26 +66,10 @@ class UserProfile(m.Model):
     home_address = m.TextField(blank=True)
     ils_userid   = m.TextField("Alternate userid in the ILS, if any",
                                max_length=50, blank=True)
-    access_level = m.CharField(max_length=5, blank=True, null=True,
-                               default=None,
-                               choices=(('CUST', _('custodian')),
-                                        ('STAFF', _('staff')),
-                                        ('ADMIN', _('system administrator'))))
-    instructor = m.BooleanField(default=False)
-    proxy = m.BooleanField(default=False)
-    # n.b. Django's User has an active flag, maybe we should use that?
-    active = m.BooleanField(default=True) 
 
     def __unicode__(self):
         return 'UserProfile(%s)' % self.user
 
-    @classmethod
-    def active_instructors(cls):
-        """Return a queryset of all active instructors."""
-        return cls.objects.filter(instructor=True) \
-            .select_related('user').filter(user__is_active=True) \
-            .order_by('-user__last_name','-user__first_name')
-
 #----------------------------------------------------------------------
 # Initializing an external user account
 
index 5688c01..6df874b 100644 (file)
@@ -198,7 +198,7 @@ def instructors(request):
     count = int(request.GET.get('count', 5))
     action = request.GET.get('action', 'browse')
     if action == 'join':
-        paginator = Paginator(models.UserProfile.active_instructors(), count)
+        paginator = Paginator(models.User.active_instructors(), count)
     elif action == 'drop':
         paginator = Paginator(models.Course.objects.all(), count) # fixme, what filter?
     else:
@@ -241,8 +241,8 @@ def browse_courses(request, browse_option=''):
     count = int(request.GET.get('count', 5))
 
     if browse_option == 'instructors':
-        paginator = Paginator(models.UserProfile.active_instructors().
-            order_by('user__last_name'), count)
+        paginator = Paginator(models.User.active_instructors(),
+                              count)
 
         return g.render('instructors.xhtml', paginator=paginator,
             page_num=page_num,
@@ -275,21 +275,21 @@ def instructor_detail(request, instructor_id):
     i am not sure this is the best way to go from instructor
     to course
     '''
-    members = models.Member.objects.get(user__id=instructor_id, 
-        role='INSTR')
-    paginator = Paginator(models.Course.objects.
-        filter(member__id=members.id).
-        order_by('title'), count)
+    courses = models.Course.objects.filter(member__user=instructor_id,
+                                           member__role='INSTR')
+    paginator = Paginator(courses.order_by('title'), count)
 
     '''
     no concept of active right now, maybe suppressed is a better
     description anyway?
     '''
         # filter(active=True).order_by('title'), count)
-
-    return g.render('courses.xhtml', paginator=paginator,
-            page_num=page_num,
-            count=count)
+    instructor = models.User.objects.get(pk=instructor_id)
+    return g.render('courses.xhtml', 
+                    custom_title=_('Courses taught by %s') % instructor.get_full_name(),
+                    paginator=paginator,
+                    page_num=page_num,
+                    count=count)
 
 def department_detail(request, department_id):
     page_num = int(request.GET.get('page', 1))
index 838d69d..7b9c41a 100644 (file)
@@ -1,5 +1,5 @@
 <?python
-title = _('Courses')
+title = defined('custom_title') and custom_title or _('Courses')
 ?>
 <html xmlns="http://www.w3.org/1999/xhtml"
       xmlns:xi="http://www.w3.org/2001/XInclude"
index 411f205..28ff97b 100644 (file)
@@ -18,8 +18,8 @@ title = _('Instructors')
   <tr py:def="pageheader()">
     <th>Name</th>
   </tr>
-  <span py:def="pagerow(item)">
-    <td><a href="${instructor_url(item.user)}">${item.user.last_name}, ${item.user.first_name}</a></td>
+  <span py:def="pagerow(user)">
+    <td><a href="${instructor_url(user)}">${user.last_name}, ${user.first_name}</a></td>
   </span>
   ${pagetable(paginator, count, pagerow, pageheader)}
 </body>