]> git.parisson.com Git - teleforma.git/commitdiff
Optimising course/period views feature/optim-dec2021
authorGael Le Mignot <gael@pilotsystems.net>
Fri, 7 Jan 2022 07:58:36 +0000 (08:58 +0100)
committerGael Le Mignot <gael@pilotsystems.net>
Fri, 7 Jan 2022 07:58:36 +0000 (08:58 +0100)
.gitignore
teleforma/management/commands/teleforma-exam-message-bug.py
teleforma/migrations/0015_auto_20211210_1411.py [new file with mode: 0644]
teleforma/models/core.py
teleforma/templates/teleforma/inc/conference_list.html
teleforma/templates/teleforma/inc/document_list.html
teleforma/templates/teleforma/inc/media_list.html
teleforma/templatetags/teleforma_tags.py

index 3094971909b3f7009eca4c656f5a500aa34e407f..98893fff578b6656cfaa135a00a3339460edf46b 100644 (file)
@@ -30,3 +30,5 @@ pip-log.txt
 #python venv
 py_env
 prod.env
+
+README_pilot.rst
\ No newline at end of file
index 277ade2f1ae53e71099a4914d4423902b7d17439..eba7247d7378abf0170132196d178cf4278e747d 100644 (file)
@@ -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 (file)
index 0000000..e07b8de
--- /dev/null
@@ -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'),
+        ),
+    ]
index bdeb4c194710ca408b890191dd662c3077028a85..58538a9889c92b50351818ef147a0b70f86bfbd4 100755 (executable)
@@ -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):
index 6659ba24adf67dd5384ea5ad9b84c5f7d3d45ef1..0d3ed8195aa02b2e4b524a0be4ed3f94e567ea81 100644 (file)
@@ -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 %}
 <div class="course_content content_video">
 <div class="course_subtitle">
     <h3><img src="/static/teleforma/images/item_title.png" width="10px" alt="" /> {% trans "Live conferences"%}</h3>
 </div>
     <table class="listing" width="100%">
     <tbody>
-       {% for conference in conferences|from_period:period %}
+       {% for conference in conferences %}
         {% for stream in conference.livestream.all %}
          {% if stream.stream_type == 'webm' %}
             <tr>
@@ -50,4 +51,3 @@
     </table>
 </div>
 {% endif %}
-{% endwith %}
index ba933bdc334107adf59b297f036f080edf41fa2b..7e32f765a20e7d69e9b06988f1c929d60b45664f 100644 (file)
@@ -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 %}
 <div class="course_content">
 <div class="course_subtitle">
 <h3><img src="/static/teleforma/images/item_title.png" width="10px" alt="" /> {% trans "Documents"%}</h3>
 </div>
 
-{% 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 %}
 <span class="doc_type_title">{{ doc_type }}</span>
 <table class="listing" width="100%">
     <tbody>
-        {% 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 %}
         <tr>
-        <td {% if forloop.first %}class="border-top"{% endif %} width="60%">{% if doc.file %}<a href="{% url 'teleforma-document-view' doc.id %}" target="_blank" title="{% trans "View" %}"><img src="/static//teleforma/images/application-msword.png" style="vertical-align:middle" alt="" />{% endif %} {{ doc.title }}{% if doc.file %}</a>{% endif %}</td>
+        <td {% if forloop.first %}class="border-top"{% endif %} width="60%">{% if doc.file %}<a href="{{ docurl }}" target="_blank" title="{% trans "View" %}"><img src="/static//teleforma/images/application-msword.png" style="vertical-align:middle" alt="" />{% endif %} {{ doc.title }}{% if doc.file %}</a>{% endif %}</td>
         <td {% if forloop.first %}class="border-top"{% endif %} width="35%">{{ doc.date_added }}</td>
-        <td {% if forloop.first %}class="border-top"{% endif %} width="5%" align="center">{% if doc.file %}<a href="{% url 'teleforma-document-download' doc.id %}"><img src="/static/teleforma/images/download.png" style="vertical-align:middle" alt="" title="{% trans "Download" %}" /></a>{% endif %}</td>
+        <td {% if forloop.first %}class="border-top"{% endif %} width="5%" align="center">{% if doc.file %}<a href="{{ docurl }}"><img src="/static/teleforma/images/download.png" style="vertical-align:middle" alt="" title="{% trans "Download" %}" /></a>{% endif %}</td>
         </tr>
     {% endfor %}
     </tbody>
 </table>
 {% endif %}
 {% endfor %}
-{% endwith %}
 
 </div>
 
index fe490b7351b132295a3aedc9377c44c59f462ff1..9b8c27fedf41d5be063c9defdc9c981c85472154 100644 (file)
@@ -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 %}
 <div class="course_content content_video">
 <div class="course_subtitle">
     <h3><img src="/static/teleforma/images/item_title.png" width="10px" alt="" /> {% trans "Conférences en différé" %}</h3>
 </div>
     <table class="listing" width="100%">
     <tbody>
-        {% 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' %}
             <tr>
             <td {% if forloop.first %}class="border-top"{% endif %} width="230px" style="vertical-align:middle">
@@ -58,7 +59,6 @@
             </td>
             </tr>
           {% endif %}
-         {% endif %}
         {% endfor %}
     </tbody>
     </table>
index dcf316cc7c1aa6eafde202760a7c0197a2652c48..ebff8e41928a49b902ad97c058c4c8bb62752411 100644 (file)
@@ -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)