From 17b8d977d5fe7d20e9c644f25f2dbad9a2cdbf26 Mon Sep 17 00:00:00 2001 From: Guillaume Pellerin Date: Mon, 10 Dec 2018 01:04:01 +0100 Subject: [PATCH] Add conferences to seminars view --- teleforma/context_processors.py | 34 +++++++++++++++++++ .../templates/teleforma/course_media.html | 2 +- teleforma/templates/teleforma/seminars.html | 12 +++++++ teleforma/views/pro.py | 7 +++- 4 files changed, 53 insertions(+), 2 deletions(-) diff --git a/teleforma/context_processors.py b/teleforma/context_processors.py index bab539b5..2d6fe5d8 100644 --- a/teleforma/context_processors.py +++ b/teleforma/context_processors.py @@ -183,6 +183,40 @@ def all_seminars(request, progress_order=False, date_order=False): return {'all_seminars': seminars} +def all_conferences(request, progress_order=False, date_order=False): + conferences = [] + now = datetime.datetime.now() + + if isinstance(request, User): + user = request + else: + user = request.user + + if not user.is_authenticated(): + return {} + + professor = user.professor.all() + auditor = user.auditor.all() + + if professor: + conferences = [] + professor = user.professor.get() + courses = professor.courses.all() + + for course in courses: + for conference in course.conference.filter(expiry_date__gte=now): + conferences.append(conference) + + elif auditor and not (user.is_staff or user.is_superuser): + auditor = user.auditor.get() + conferences = auditor.conferences.filter(status=2, expiry_date__gte=now) + + elif user.is_staff or user.is_superuser: + conferences = Conference.objects.filter(Q(expiry_date__gte=now) | Q(expiry_date=None)) + + return conferences + + def total_progress(request): """return the user progress of all seminars in percent""" diff --git a/teleforma/templates/teleforma/course_media.html b/teleforma/templates/teleforma/course_media.html index 7393173c..170ed70c 100644 --- a/teleforma/templates/teleforma/course_media.html +++ b/teleforma/templates/teleforma/course_media.html @@ -1,4 +1,4 @@ -{% extends "teleforma/course_detail.html" %} +{% extends "teleforma/seminars.html" %} {% load telemeta_utils %} {% load teleforma_tags %} {% load i18n %} diff --git a/teleforma/templates/teleforma/seminars.html b/teleforma/templates/teleforma/seminars.html index b1e204c0..51d86b11 100644 --- a/teleforma/templates/teleforma/seminars.html +++ b/teleforma/templates/teleforma/seminars.html @@ -53,6 +53,18 @@ $(function() { +

playlists{% trans "My conferences" %}

+
+ +
+ + {% block submodules %} {% endblock submodules %} diff --git a/teleforma/views/pro.py b/teleforma/views/pro.py index 15903d3e..4bd69923 100644 --- a/teleforma/views/pro.py +++ b/teleforma/views/pro.py @@ -315,6 +315,11 @@ class SeminarsView(ListView): def get_queryset(self): return all_seminars(self.request, date_order=True)['all_seminars'][:10] + def get_context_data(self, **kwargs): + context = super(SeminarsView, self).get_context_data(**kwargs) + context['conferences'] = all_conferences(self.request) + return context + class AnswerView(SeminarAccessMixin, SeminarRevisionMixin, FormView): @@ -499,7 +504,7 @@ class AnswersView(ListView): a = _('answer') v = _('validated') subject = '%s : %s - %s %s' % (seminar.title, a, str(context['rank']), v) - + mess = Message(sender=sender, recipient=user, subject=subject[:511], body=text) mess.moderation_status = 'a' mess.save() -- 2.39.5