From: Gael Le Mignot Date: Fri, 7 Jan 2022 07:58:36 +0000 (+0100) Subject: Optimising course/period views X-Git-Tag: 2.5.1~18^2^2 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=70498c72b254b5759c68617f6a1962a9a50e0275;p=teleforma.git Optimising course/period views --- diff --git a/.gitignore b/.gitignore index 30949719..98893fff 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,5 @@ pip-log.txt #python venv py_env prod.env + +README_pilot.rst \ No newline at end of file diff --git a/teleforma/management/commands/teleforma-exam-message-bug.py b/teleforma/management/commands/teleforma-exam-message-bug.py index 277ade2f..eba7247d 100644 --- a/teleforma/management/commands/teleforma-exam-message-bug.py +++ b/teleforma/management/commands/teleforma-exam-message-bug.py @@ -1,15 +1,10 @@ -from optparse import make_option from django.conf import settings -from django.core.management.base import BaseCommand, CommandError +from django.core.management.base import BaseCommand from django.contrib.auth.models import User -from django.template.defaultfilters import slugify from django.utils import translation from django.conf import settings from teleforma.exam.models import * -import logging -import codecs -import time, os class Command(BaseCommand): @@ -21,13 +16,13 @@ class Command(BaseCommand): site = Site.objects.all()[0] subject = 'Erreur dans la transmission de votre copie' scripts = Script.objects.filter(file='scripts/2014/07/22/home') - print scripts.count() + print(scripts.count()) for script in scripts: script.reject() context = {'script': script, 'site': site} text = render_to_string('exam/messages/script_fix.txt', context) - print text + print(text) mess = Message(sender=sender, recipient=script.author, subject=subject[:119], body=text) mess.moderation_status = 'a' mess.save() diff --git a/teleforma/migrations/0015_auto_20211210_1411.py b/teleforma/migrations/0015_auto_20211210_1411.py new file mode 100644 index 00000000..e07b8de4 --- /dev/null +++ b/teleforma/migrations/0015_auto_20211210_1411.py @@ -0,0 +1,25 @@ +# Generated by Django 3.2.3 on 2021-12-10 14:11 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('teleforma', '0014_alter_profile_user'), + ] + + operations = [ + migrations.AddIndex( + model_name='conference', + index=models.Index(fields=['course', 'course_type', 'period', 'streaming', '-date_begin'], name='teleforma_c_course__5d8618_idx'), + ), + migrations.AddIndex( + model_name='document', + index=models.Index(fields=['course', 'is_published', '-date_added'], name='teleforma_d_course__b0ecc5_idx'), + ), + migrations.AddIndex( + model_name='media', + index=models.Index(fields=['course', 'course_type', 'period', 'is_published', '-date_modified'], name='teleforma_m_course__19f376_idx'), + ), + ] diff --git a/teleforma/models/core.py b/teleforma/models/core.py index bdeb4c19..58538a98 100755 --- a/teleforma/models/core.py +++ b/teleforma/models/core.py @@ -530,6 +530,9 @@ class Conference(models.Model): verbose_name = _('conference') ordering = ['-date_begin'] + indexes = [ + models.Index(fields=['course', 'course_type', 'period', 'streaming', '-date_begin' ]), + ] class StreamingServer(models.Model): @@ -700,6 +703,9 @@ class Document(MediaBase): class Meta(MetaCore): db_table = app_label + '_' + 'document' ordering = ['-date_added'] + indexes = [ + models.Index(fields=['course', 'is_published', '-date_added' ]), + ] class DocumentSimple(MediaBase): @@ -834,6 +840,9 @@ class Media(MediaBase): class Meta(MetaCore): db_table = app_label + '_' + 'media' ordering = ['-date_modified', '-conference__session',] + indexes = [ + models.Index(fields=['course', 'course_type', 'period', 'is_published', '-date_modified' ]), + ] class NamePaginator(object): diff --git a/teleforma/templates/teleforma/inc/conference_list.html b/teleforma/templates/teleforma/inc/conference_list.html index 6659ba24..0d3ed819 100644 --- a/teleforma/templates/teleforma/inc/conference_list.html +++ b/teleforma/templates/teleforma/inc/conference_list.html @@ -1,15 +1,16 @@ {% load teleforma_tags %} {% load i18n %} -{% with course.conference.all|from_course_type:type|streaming_only as conferences %} -{% if conferences|from_period:period %} +{% course_conferences as conference %} + +{% if conferences %}

{% trans "Live conferences"%}

- {% for conference in conferences|from_period:period %} + {% for conference in conferences %} {% for stream in conference.livestream.all %} {% if stream.stream_type == 'webm' %} @@ -50,4 +51,3 @@
{% endif %} -{% endwith %} diff --git a/teleforma/templates/teleforma/inc/document_list.html b/teleforma/templates/teleforma/inc/document_list.html index ba933bdc..7e32f765 100644 --- a/teleforma/templates/teleforma/inc/document_list.html +++ b/teleforma/templates/teleforma/inc/document_list.html @@ -1,30 +1,31 @@ {% load teleforma_tags %} {% load i18n %} -{% if course.document.all|from_course_type:type|from_period:period|published %} +{% course_docs_by_type as documents %} + +{% if documents %}

{% trans "Documents"%}

-{% with course.document.all as docs %} -{% for doc_type in doc_types %} -{% if docs|from_course_type:type|from_doc_type:doc_type|from_period:period and not type_counter > 2 %} +{% for doc_type, docs in documents %} +{% if docs and not type_counter > 2 %} {{ doc_type }} - {% for doc in docs|from_course_type:type|from_doc_type:doc_type|from_period:period|published %} + {% for doc in docs %} + {% url 'teleforma-document-view' doc.id as docurl %} - + - + {% endfor %}
{% if doc.file %}{% endif %} {{ doc.title }}{% if doc.file %}{% endif %}{% if doc.file %}{% endif %} {{ doc.title }}{% if doc.file %}{% endif %} {{ doc.date_added }}{% if doc.file %}{% endif %}{% if doc.file %}{% endif %}
{% endif %} {% endfor %} -{% endwith %}
diff --git a/teleforma/templates/teleforma/inc/media_list.html b/teleforma/templates/teleforma/inc/media_list.html index fe490b73..9b8c27fe 100644 --- a/teleforma/templates/teleforma/inc/media_list.html +++ b/teleforma/templates/teleforma/inc/media_list.html @@ -2,15 +2,16 @@ {% load thumbnail %} {% load i18n %} -{% if course.media.all|from_course_type:type|from_period:period %} +{% course_media as all_media %} + +{% if all_media %}

{% trans "Conférences en différé" %}

- {% for media in course.media.all|from_course_type:type|from_period:period %} - {% if media.is_published or user.is_staff and not list_view %} + {% for media in all_media %} {% if media.type == 'webm' or media.type == 'mp4' %} {% endif %} - {% endif %} {% endfor %}
@@ -58,7 +59,6 @@
diff --git a/teleforma/templatetags/teleforma_tags.py b/teleforma/templatetags/teleforma_tags.py index dcf316cc..ebff8e41 100644 --- a/teleforma/templatetags/teleforma_tags.py +++ b/teleforma/templatetags/teleforma_tags.py @@ -54,6 +54,8 @@ from ..models.core import Document, Professor from ..models.crfpa import IEJ, Course, NewsItem, Training from ..views import get_courses +from collections import defaultdict + register = template.Library() # more translations for template variables @@ -439,3 +441,37 @@ def chat_room(context, period=None, course=None): 'user_id': context.request.user.id } } + + +@register.simple_tag(takes_context=True) +def course_docs_by_type(context): + course = context['course'] + docs = course.document.filter(is_published=True, + periods__in=(context['period'],), + course_type=context['type']) + res = [] + by_types = defaultdict(list) + for doc in docs: + by_types[doc.type].append(doc) + for doc_type in context['doc_types']: + docs = by_types[doc_type] + if docs: + res.append((doc_type, docs)) + return res + +@register.simple_tag(takes_context=True) +def course_conferences(context): + course = context['course'] + confs = course.conference.filter(streaming=True, + period=context['period'], + course_type=context['type']) + return list(confs) + +@register.simple_tag(takes_context=True) +def course_media(context): + course = context['course'] + media = course.media.filter(period=context['period'], + course_type=context['type']) + if not context['user'].is_staff or context['list_view']: + media = media.filter(is_published = True) + return list(media)