From 5a4aa2bf8ceb6f49a79ccf1b777e7f1178e1d4b7 Mon Sep 17 00:00:00 2001 From: Guillaume Pellerin Date: Thu, 19 Dec 2013 17:44:19 +0100 Subject: [PATCH] add periods --- teleforma/management/commands/teleforma-copy-seminars.py | 9 +++++++-- teleforma/models/core.py | 5 ++++- teleforma/models/pro.py | 5 ++++- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/teleforma/management/commands/teleforma-copy-seminars.py b/teleforma/management/commands/teleforma-copy-seminars.py index cef1b19b..df1ee1fa 100644 --- a/teleforma/management/commands/teleforma-copy-seminars.py +++ b/teleforma/management/commands/teleforma-copy-seminars.py @@ -23,6 +23,8 @@ class Command(BaseCommand): def handle(self, *args, **kwargs): to_year = int(args[-1]) from_year = int(args[-2]) + to_period = Period.objects.get_or_create(name=str(to_year)) + from_period = Period.objects.get_or_create(name=str(from_year)) for seminar in Seminar.objects.all(): if seminar.expiry_date: @@ -39,16 +41,19 @@ class Command(BaseCommand): source = getattr(seminar, field.attname) destination = getattr(clone, field.attname) for item in source.all(): + item.period = from_period + item.save() item_clone = item.clone() item_clone.readers = [] + item_clone.period = to_period item_clone.save() destination.remove(item) destination.add(item_clone) - print ("documents and medias cloned and assigned:", clone) + print ("cloned and assigned:", item_clone) questions = seminar.question.all() for question in questions: question_clone = question.clone() question_clone.seminar = clone question.save() - print ("updated:", question) + print ("cloned and assigned:", question) diff --git a/teleforma/models/core.py b/teleforma/models/core.py index 3878dbec..f5816d4e 100755 --- a/teleforma/models/core.py +++ b/teleforma/models/core.py @@ -395,6 +395,8 @@ class Document(MediaBase): def __unicode__(self): strings = [] + if self.period: + strings.append(self.period) if self.course: strings.append(self.course.code) if self.course_type.all(): @@ -450,7 +452,8 @@ class Media(MediaBase): def __unicode__(self): strings = [] - + if self.period: + strings.append(self.period) if self.course and self.course_type: strings.append(self.course.code + ' ' + self.course_type.name) elif self.course: diff --git a/teleforma/models/pro.py b/teleforma/models/pro.py index 62a70a77..6ecf4b6e 100755 --- a/teleforma/models/pro.py +++ b/teleforma/models/pro.py @@ -104,7 +104,10 @@ class Seminar(ClonableMixin, Displayable): objects = DisplayableManager() def __unicode__(self): - return ' - '.join([self.course.title, str(self.rank), self.title]) + if self.publish_date: + return ' - '.join([self.publish_date.year, self.course.title, str(self.rank), self.title]) + else: + return ' - '.join([self.course.title, str(self.rank), self.title]) @property def pretty_title(self): -- 2.39.5