fixed bugs in add/drop sections; was leaving broken section identifiers behind.
authorgfawcett <gfawcett@6d9bc8c9-1ec2-4278-b937-99fde70a366f>
Mon, 9 Mar 2009 23:49:36 +0000 (23:49 +0000)
committergfawcett <gfawcett@6d9bc8c9-1ec2-4278-b937-99fde70a366f>
Mon, 9 Mar 2009 23:49:36 +0000 (23:49 +0000)
git-svn-id: svn://svn.open-ils.org/ILS-Contrib/servres/trunk@162 6d9bc8c9-1ec2-4278-b937-99fde70a366f

conifer/syrup/models.py
conifer/syrup/views.py
conifer/templates/edit_course_permissions.xhtml

index 44646c9..0b55722 100644 (file)
@@ -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)
index 0ec2aeb..3e73dd7 100644 (file)
@@ -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()
index a921da7..f06f6e6 100644 (file)
@@ -86,7 +86,7 @@ instructors = [m for m in models.Member.objects.filter(course=course) if m.role
       </table>
       <p>Add section: 
       <select name="add_section">
-       <option>--------</option>
+       <option value="">--------</option>
        <optgroup py:for="label, sections in ((_('My Courses'), my_sections), (_('%s in term %s') % (course.code, course.term), ct_sections))"
                  label="${label}" py:if="sections">
          <option py:for="(term, code, sec) in sections"