From: Guillaume Pellerin Date: Fri, 17 Jun 2022 13:55:33 +0000 (+0200) Subject: add Conference.notified and a prototyped command to update the X-Git-Tag: 2.7.1~45^2~1 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=c18188390ec56db4ae7829cd980e45f060c9b2b7;p=teleforma.git add Conference.notified and a prototyped command to update the Conference status --- diff --git a/teleforma/management/commands/teleforma-publish-notify-conferences.py b/teleforma/management/commands/teleforma-publish-notify-conferences.py new file mode 100644 index 00000000..86103ff7 --- /dev/null +++ b/teleforma/management/commands/teleforma-publish-notify-conferences.py @@ -0,0 +1,47 @@ +# -*- coding: utf-8 -*- + +from optparse import make_option +from django.conf import settings +from django.core.management.base import BaseCommand, CommandError +from django.contrib.auth.models import User +from django.template.defaultfilters import slugify +from teleforma.models import * +import logging +import os +from copy import deepcopy + +class Logger: + """A logging object""" + + def __init__(self, file): + self.logger = logging.getLogger('myapp') + self.hdlr = logging.FileHandler(file) + self.formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s') + self.hdlr.setFormatter(self.formatter) + self.logger.addHandler(self.hdlr) + self.logger.setLevel(logging.INFO) + + +class Command(BaseCommand): + help = """Publish conferences and notify users when \ + conference.date_publish is equal or greater \ + than current date """ + + def handle(self, *args, **options): + conferences = Conference.objects.filter(notified=False, + date_publish__lte=datetime.datetime.now()) + + for conference in conferences: + conference.status = 3 + conference.save() + + students = Student.objects.filter(period=conference.period) + for student in students: + courses = get_courses(student.user, period=conference.period) + for course in courses: + if conference.course == course['course'] and \ + conference.course_type in course['types']: + notify(student.user, conference) + + conference.notified = True + conference.save() \ No newline at end of file diff --git a/teleforma/models/core.py b/teleforma/models/core.py index 18a7e8c1..07821464 100755 --- a/teleforma/models/core.py +++ b/teleforma/models/core.py @@ -396,6 +396,7 @@ class Conference(models.Model): streaming = models.BooleanField(_('streaming'), default=True) web_class_group = models.ForeignKey('WebClassGroup', related_name='conferences', verbose_name=_('web class group'), blank=True, null=True, on_delete=models.SET_NULL) + notified = models.BooleanField(_('notified')) @property def description(self):