From: gfawcett Date: Mon, 9 Mar 2009 23:49:36 +0000 (+0000) Subject: fixed bugs in add/drop sections; was leaving broken section identifiers behind. X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=9740dcb10183b7a8d55b2fa7bbfed5178139e3bf;p=Syrup.git fixed bugs in add/drop sections; was leaving broken section identifiers behind. git-svn-id: svn://svn.open-ils.org/ILS-Contrib/servres/trunk@162 6d9bc8c9-1ec2-4278-b937-99fde70a366f --- diff --git a/conifer/syrup/models.py b/conifer/syrup/models.py index 44646c9..0b55722 100644 --- a/conifer/syrup/models.py +++ b/conifer/syrup/models.py @@ -265,11 +265,13 @@ class Course(m.Model): return set(inner()) def add_sections(self, *sections): + assert all(len(s)==3 for s in sections), repr(sections) current = self.sections() sections = set(sections).union(current) self.enrol_codes = _merge_sections(sections) def drop_sections(self, *sections): + assert all(len(s)==3 for s in sections), repr(sections) current = self.sections() sections = current - set(sections) self.enrol_codes = _merge_sections(sections) diff --git a/conifer/syrup/views.py b/conifer/syrup/views.py index 0ec2aeb..3e73dd7 100644 --- a/conifer/syrup/views.py +++ b/conifer/syrup/views.py @@ -363,17 +363,19 @@ def edit_course_permissions(request, course_id): if new_sec: course.add_sections(new_sec) # remove the sections to be dropped - to_remove = [models.section_decode_safe(name.rsplit('_',1)[1]) \ - for name in POST \ - if name.startswith('remove_section_')] - course.drop_sections(*to_remove) + to_remove = [models.section_decode_safe(name.rsplit('_',1)[1]) \ + for name in POST \ + if name.startswith('remove_section_')] + course.drop_sections(*to_remove) student_names = models.course_sections.students_in(*course.sections()) for name in student_names: user = models.maybe_initialize_user(name) if user: - mbr = models.Member.objects.create(course=course, user=user, - role='STUDT', provided=True) - mbr.save() + if not models.Member.objects.filter(course=course, user=user): + mbr = models.Member.objects.create( + course=course, user=user, + role='STUDT', provided=True) + mbr.save() else: pass course.save() diff --git a/conifer/templates/edit_course_permissions.xhtml b/conifer/templates/edit_course_permissions.xhtml index a921da7..f06f6e6 100644 --- a/conifer/templates/edit_course_permissions.xhtml +++ b/conifer/templates/edit_course_permissions.xhtml @@ -86,7 +86,7 @@ instructors = [m for m in models.Member.objects.filter(course=course) if m.role

Add section: