Permalink
Browse files

Added teaching assistants

  • Loading branch information...
1 parent f186411 commit c5b2df44d540a2cf0540ccdc2bd87d3582a2f1bc @emperorcezar emperorcezar committed Apr 5, 2012
Showing with 29 additions and 9 deletions.
  1. +11 −5 apps/courses/admin.py
  2. +4 −2 apps/courses/models.py
  3. +11 −1 apps/courses/tests.py
  4. +3 −1 apps/courses/views.py
View
16 apps/courses/admin.py
@@ -5,6 +5,7 @@
from django.forms import ModelForm
from django.forms import ModelMultipleChoiceField
from django.contrib.admin.widgets import FilteredSelectMultiple
+from django.utils.translation import ugettext as _
from permission_backend_nonrel.models import UserPermissionList
from courses.models import Course, Semester, Assignment, AssignmentSubmission, Resource
@@ -13,19 +14,24 @@
class CourseAdminForm(ModelForm):
faculty = ModelMultipleChoiceField(queryset = User.objects.none(),
required = False,
- widget = FilteredSelectMultiple("Faculty", False) )
+ widget = FilteredSelectMultiple(_("Faculty"), False) )
+
+ teaching_assistants = ModelMultipleChoiceField(queryset = User.objects.all(),
+ required = False,
+ widget = FilteredSelectMultiple(_("Teaching Assistants"), False) )
+
members = ModelMultipleChoiceField(queryset = User.objects.none(),
required = False,
- widget = FilteredSelectMultiple("Faculty", False) )
+ widget = FilteredSelectMultiple(_("Faculty"), False) )
def __init__(self,*args,**kwargs):
super (CourseAdminForm,self ).__init__(*args,**kwargs)
- faculty_group = Group.objects.get_or_create(name = 'Faculty')[0]
+ faculty_group = Group.objects.get_or_create(name = _('Faculty'))[0]
faculty_list = UserPermissionList.objects.filter(group_fk_list = faculty_group.pk)
self.fields['faculty'].queryset = User.objects.filter(pk__in = [faculty.user.pk for faculty in faculty_list])
- student_group = Group.objects.get_or_create(name = 'Student')[0]
+ student_group = Group.objects.get_or_create(name = _('Student'))[0]
student_list = UserPermissionList.objects.filter(group_fk_list = student_group.pk)
self.fields['members'].queryset = User.objects.filter(pk__in = [student.user.pk for student in student_list])
if self.instance.id:
@@ -38,7 +44,7 @@ def __init__(self,*args,**kwargs):
class Meta:
model = Course
- exclude = ('faculty', 'members')
+ exclude = ('faculty', 'members', 'teaching_assistants')
class CourseAdmin(admin.ModelAdmin):
list_filter = ('semester',)
View
6 apps/courses/models.py
@@ -2,6 +2,7 @@
from django.db import models
from django.conf import settings
from django.contrib.auth.models import Group, User
+from django.utils.translation import ugettext as _
from djangotoolbox import fields
from tinymce import models as tinymce_models
@@ -33,9 +34,10 @@ class Course(models.Model):
number = models.CharField(max_length = 10)
description = tinymce_models.HTMLField()
semester = models.ForeignKey(Semester)
- faculty = fields.ListField(ForeignKey(User, related_name = 'faculty'))
+ faculty = fields.ListField(ForeignKey(User, related_name = _('Faculty')))
+ teaching_assistants = fields.ListField(ForeignKey(User, related_name = _('Teaching Assistants')))
private = models.BooleanField(default=False, blank=True)
- members = fields.ListField(ForeignKey(User, related_name = 'members'))
+ members = fields.ListField(ForeignKey(User, related_name = _('Members')))
schedule = recurrence.fields.RecurrenceField()
credits = models.DecimalField(max_digits = 3, decimal_places = 1, default = '3.0')
campus = models.CharField(max_length = 200,
View
12 apps/courses/tests.py
@@ -122,9 +122,19 @@ def test_access(self):
response = self.c.get(reverse('courses:overview', args = [self.course.id]))
self.assertEquals(response.status_code, 200)
self.course.faculty.remove(self.user)
- self.course.private = False
self.course.save()
+ # Test TA
+ self.course.teaching_assistants.append(self.user)
+ self.course.save()
+ response = self.c.get(reverse('courses:overview', args = [self.course.id]))
+ self.assertEquals(response.status_code, 200)
+ self.course.teaching_assistants.remove(self.user)
+ self.course.save()
+
+ self.course.private = False
+ self.course.save()
+
class AssignmentTest(test_utils.AuthenticatedTest):
def setUp(self):
super(AssignmentTest, self).setUp()
View
4 apps/courses/views.py
@@ -1,4 +1,6 @@
import datetime
+import itertools
+
from django import forms
from django.core.urlresolvers import reverse
from django.shortcuts import get_object_or_404
@@ -34,7 +36,7 @@ def dispatch(self, request, *args, **kwargs):
course = self.get_object()
if course.private:
- if request.user not in course.faculty and request.user not in course.members:
+ if request.user not in itertools.chain(course.faculty, course.members, course.teaching_assistants):
raise exceptions.PermissionDenied
return super(CourseOverview, self).dispatch(request, *args, **kwargs)

0 comments on commit c5b2df4

Please sign in to comment.