]> git.parisson.com Git - teleforma.git/commitdiff
add full data pull commnd with periods
authorGuillaume Pellerin <guillaume.pellerin@ircam.fr>
Mon, 29 May 2023 14:53:51 +0000 (16:53 +0200)
committerGuillaume Pellerin <guillaume.pellerin@ircam.fr>
Mon, 29 May 2023 14:53:51 +0000 (16:53 +0200)
teleforma/management/commands/teleforma-pull.py [new file with mode: 0644]
teleforma/views/core.py

diff --git a/teleforma/management/commands/teleforma-pull.py b/teleforma/management/commands/teleforma-pull.py
new file mode 100644 (file)
index 0000000..33057f7
--- /dev/null
@@ -0,0 +1,29 @@
+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 telemeta.models import *
+from telemeta.util.unaccent import unaccent
+from teleforma.models import *
+from teleforma.views import *
+import logging
+import codecs
+
+class Command(BaseCommand):
+    help = "pull teleforma conferences, periods and professors from a telecaster master servers"
+    admin_email = 'webmaster@parisson.com'
+    args = "Pre-Barreau"
+
+    def handle(self, *args, **options):
+        organization_name = args[-1]
+
+        view = PeriodAccessMixin()
+        view.pull(organization_name)
+
+        view = CourseListView()
+        view.pull(organization_name)
+
+        view = ProfessorListView()
+        view.pull()
+
index 58c2a783e29e1dbf2a25184e9b1e7532f138716f..4849c90caa87ac3b3cf0082a3987f35387fc2803 100644 (file)
@@ -207,6 +207,29 @@ class PeriodAccessMixin(View):
         department = Department.objects.get(id=department_id)
         return [period.name for period in Period.objects.filter(department=department)]
 
+    def pull(request, organization_name):
+        organization = Organization.objects.get(name=organization_name)
+        departments = Department.objects.filter(organization=organization)
+        periods_new = []
+
+        for department in departments:
+            url = 'https://' + department.domain + '/json/'
+            s = ServiceProxy(url)
+            remote_list = s.teleforma.get_period_list(department.name)
+            if remote_list['result']:
+                for period_dict in remote_list['result']:
+                    if period_dict["is_open"] == "true":
+                        period, c = Period.objects.get_or_create(
+                                        name=period_dict['name'],
+                                        department=department)
+                        period_new.append(period)
+                        print(period)
+
+        # cleanup
+        for period in Period.objects.all():
+            if not period in period_new:
+                period.delete()
+
 
 class CourseAccessMixin(PeriodAccessMixin):