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)
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
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:
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,
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))
<?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"
<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>