From 63ad0912c313edc38b577f1737b1e635d23ffd2a Mon Sep 17 00:00:00 2001 From: gfawcett Date: Fri, 6 Aug 2010 02:25:44 +0000 Subject: [PATCH] Added Site.end_term attribute, for modelling multi-term course offerings. Replaced 'term' with ('start_term', 'end_term'); 'term' is now a read-only alias for 'start_term'. Most sites will have the same value for their start- and end-terms. git-svn-id: svn://svn.open-ils.org/ILS-Contrib/servres/trunk@950 6d9bc8c9-1ec2-4278-b937-99fde70a366f --- conifer/syrup/models.py | 21 ++++++++++++++++++--- conifer/templates/edit_site.xhtml | 3 ++- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/conifer/syrup/models.py b/conifer/syrup/models.py index 07dbffa..afa4cc6 100644 --- a/conifer/syrup/models.py +++ b/conifer/syrup/models.py @@ -195,7 +195,8 @@ class Config(m.Model): class Site(BaseModel): """A a list of materials for one (or more) course offering(s).""" course = m.ForeignKey(Course) - term = m.ForeignKey(Term) + start_term = m.ForeignKey(Term, related_name='start_term') + end_term = m.ForeignKey(Term, related_name='end_term') owner = m.ForeignKey(User) service_desk = m.ForeignKey(ServiceDesk) @@ -207,11 +208,25 @@ class Site(BaseModel): ('MEMBR', _('Accessible to course-site members')), ('CLOSE', _('Accessible only to course-site owners'))]) + @property + def term(self): + """ + Returns the start term (typically the term thought of as 'the' term of + the site). + + Whenever possible, use the explicit 'start_term' attribute rather than + the 'term' property. + """ + return self.start_term + class Meta: - unique_together = (('course', 'term', 'owner')) - ordering = ['-term__start', 'course__code', 'owner__last_name'] + unique_together = (('course', 'start_term', 'owner')) + ordering = ['-start_term__start', 'course__code', 'owner__last_name'] def save(self, *args, **kwargs): + # Assert that the term-order is logical. + assert self.start_term.start <= self.end_term.start, \ + 'The end-term cannot begin before the start-term.' # Ensure there is always an internal Group. super(Site, self).save(*args, **kwargs) internal, just_created = Group.objects.get_or_create( diff --git a/conifer/templates/edit_site.xhtml b/conifer/templates/edit_site.xhtml index ba75178..829741b 100644 --- a/conifer/templates/edit_site.xhtml +++ b/conifer/templates/edit_site.xhtml @@ -34,7 +34,8 @@ else: ${field_row(form.owner)} - ${field_row(form.term)} + ${field_row(form.start_term)} + ${field_row(form.end_term)} ${field_row(form.course)} ${field_row(form.service_desk)} -- 2.11.0