From: Guillaume Pellerin Date: Mon, 29 May 2023 14:53:51 +0000 (+0200) Subject: add full data pull commnd with periods X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=19ec9ec01832d279c3f4f83547489843aa1b50e5;p=teleforma.git add full data pull commnd with periods --- diff --git a/teleforma/management/commands/teleforma-pull.py b/teleforma/management/commands/teleforma-pull.py new file mode 100644 index 00000000..33057f7c --- /dev/null +++ b/teleforma/management/commands/teleforma-pull.py @@ -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() + diff --git a/teleforma/views/core.py b/teleforma/views/core.py index 58c2a783..4849c90c 100644 --- a/teleforma/views/core.py +++ b/teleforma/views/core.py @@ -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):