From 3631ec3c5b37a6f50d82e531e5280036e249c80e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=C3=A1=C5=A1=20Havelka?= Date: Mon, 31 Jul 2023 17:23:06 +0200 Subject: [PATCH] =?UTF-8?q?AESOP=20p=C5=99estal=20b=C3=BDti=20aktu=C3=A1ln?= =?UTF-8?q?=C3=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 5 +- aesop/__init__.py | 3 - aesop/apps.py | 8 --- aesop/migrations/__init__.py | 0 aesop/ovvpfile.py | 30 --------- aesop/urls.py | 27 -------- aesop/utils.py | 16 ----- aesop/views.py | 101 ------------------------------ mamweb/settings_common.py | 1 - mamweb/urls.py | 4 -- seminar/models/personalni.py | 30 +-------- setup/nginx/mam-test.ks.matfyz.cz | 7 --- setup/nginx/mam.mff.cuni.cz | 6 -- 13 files changed, 2 insertions(+), 236 deletions(-) delete mode 100644 aesop/__init__.py delete mode 100644 aesop/apps.py delete mode 100644 aesop/migrations/__init__.py delete mode 100644 aesop/ovvpfile.py delete mode 100644 aesop/urls.py delete mode 100644 aesop/utils.py delete mode 100644 aesop/views.py diff --git a/.gitignore b/.gitignore index d3a2a533..3ef14e2a 100644 --- a/.gitignore +++ b/.gitignore @@ -25,9 +25,6 @@ TODO # .htpasswd kvůli přihlášení .htpasswd -# .htpasswd pro AESOPa -/.htpasswd-aesop - # reversion kvůli historii objektů v reversion **/reversion @@ -36,4 +33,4 @@ TODO # dokumentace docs/_build -docs/modules \ No newline at end of file +docs/modules diff --git a/aesop/__init__.py b/aesop/__init__.py deleted file mode 100644 index 440e1492..00000000 --- a/aesop/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -""" -Obsahuje vše, co se týká aesopu (exportu, který po nás vyžaduje OPMK). -""" \ No newline at end of file diff --git a/aesop/apps.py b/aesop/apps.py deleted file mode 100644 index 4e8b4787..00000000 --- a/aesop/apps.py +++ /dev/null @@ -1,8 +0,0 @@ -""" -Soubor sloužící k pojmenování a jiným nastavením djangovské aplikace. -""" -from django.apps import AppConfig - - -class AesopConfig(AppConfig): - name = 'aesop' diff --git a/aesop/migrations/__init__.py b/aesop/migrations/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/aesop/ovvpfile.py b/aesop/ovvpfile.py deleted file mode 100644 index 4d58af35..00000000 --- a/aesop/ovvpfile.py +++ /dev/null @@ -1,30 +0,0 @@ -from django.http import HttpResponse -from django.utils.encoding import force_text - - -class OvvpFile: - def __init__(self): - # { header: value, ... } - self.headers = {} - # [ 'column-name', ... ] - self.columns = [] - # [ { column: value, ...}, ...] - self.rows = [] - - def to_lines(self): - # header - for hk in sorted(self.headers.keys()): - yield f'{hk}\t{self.headers[hk]}\n' - yield '\n' - # columns - yield '\t'.join(self.columns) + '\n' - # rows - for r in self.rows: - yield '\t'.join([force_text(r[c]) for c in self.columns]) + '\n' - - def to_string(self): - return ''.join(self.to_lines()) - - # Pozn: tohle je ta jediná funkce, která se reálně používá… - def to_HttpResponse(self): - return HttpResponse(self.to_string(), content_type='text/plain; charset=utf-8') diff --git a/aesop/urls.py b/aesop/urls.py deleted file mode 100644 index 946a873b..00000000 --- a/aesop/urls.py +++ /dev/null @@ -1,27 +0,0 @@ -""" -Soubor sloužící jako „router“, tj. zde se definují url adresy a na co ukazují: - -- ``aesop-export/mam-rocnik-.csv`` (seminar_export_rocnik) :class:`~aesop.views.ExportRocnikView` -- ``aesop-export/mam-sous-.csv`` (seminar_export_sous) :class:`~aesop.views.ExportSousView` -- ``aesop-export/index.csv`` (seminar_export_index) :class:`~aesop.views.ExportIndexView` -""" -from django.urls import path -from aesop import views - -urlpatterns = [ - path( - 'aesop-export/mam-rocnik-.csv', - views.ExportRocnikView.as_view(), - name='seminar_export_rocnik' - ), - path( - 'aesop-export/mam-sous-.csv', - views.ExportSousView.as_view(), - name='seminar_export_sous' - ), - path( - 'aesop-export/index.csv', - views.ExportIndexView.as_view(), - name='seminar_export_index' - ), -] diff --git a/aesop/utils.py b/aesop/utils.py deleted file mode 100644 index 3ea62dce..00000000 --- a/aesop/utils.py +++ /dev/null @@ -1,16 +0,0 @@ -import datetime - -from django.utils.encoding import force_text - -from aesop.ovvpfile import OvvpFile - - -def default_ovvpfile(event, rocnik): - of = OvvpFile() - of.headers['version'] = '1' - of.headers['event'] = event - of.headers['year'] = force_text(rocnik.prvni_rok) - of.headers['date'] = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") - of.headers['id-scope'] = 'mam' - of.headers['id-generation'] = '1' - return of diff --git a/aesop/views.py b/aesop/views.py deleted file mode 100644 index 4d1748b7..00000000 --- a/aesop/views.py +++ /dev/null @@ -1,101 +0,0 @@ -""" -Soubor sloužící k deklaraci jednotlivých „views“ (nejčastěji funkce beroucí request -a vracející :func:`django.shortcuts.render` respektive nějakou response, nebo -třídy většinou rozšiřující nějakou třídu z :mod:`django.views.generic`) -""" -import django -from django.shortcuts import get_object_or_404 -from django.http import HttpResponse -from django.urls import reverse -from django.views import generic -from django.utils.encoding import force_text - -from .utils import default_ovvpfile -from seminar.models import Rocnik, Soustredeni -from vysledkovky import utils -from seminar.utils import aktivniResitele - -class ExportIndexView(generic.View): - def get(self, request): - ls = [] - for r in Rocnik.objects.filter(exportovat = True): - url = reverse('seminar_export_rocnik', kwargs={'prvni_rok': r.prvni_rok}) - ls.append(url.split('/')[-1]) - for s in Soustredeni.objects.filter(exportovat = True): - url = reverse('seminar_export_sous', kwargs={'datum_zacatku': s.datum_zacatku.isoformat()}) - ls.append(url.split('/')[-1]) - - return HttpResponse('\n'.join(ls) + '\n', content_type='text/plain; charset=utf-8') - - -class ExportSousView(generic.View): - - def get(self, request, datum_zacatku=None): - try: - dz = django.utils.dateparse.parse_date(datum_zacatku) - except: - dz = None - if dz is None: - raise django.http.Http404() - - s = get_object_or_404(Soustredeni, datum_zacatku=dz, exportovat=True) - - akce = {Soustredeni.TYP_JARNI: 'MaM.sous.jaro', - Soustredeni.TYP_PODZIMNI: 'MaM.sous.podzim', - Soustredeni.TYP_VIKEND: 'MaM.vikend', - }[s.typ] - - of = default_ovvpfile(akce, s.rocnik) - of.headers['x-event-begin'] = s.datum_zacatku.isoformat() - of.headers['x-event-end'] = s.datum_konce.isoformat() - of.headers['x-event-location'] = s.misto - of.headers['comment'] = u'MaM-Web export ucastniku soustredeni v {x-event-location} od {x-event-begin} do {x-event-end}'.format(**of.headers) - of.columns = ['id', 'name', 'surname', 'gender', 'email', 'end-year', 'school', 'school-name'] - - for u in s.ucastnici.all(): - of.rows.append(u.export_row()) - - return of.to_HttpResponse() - -# POZOR! Předělání na nový model neotestováno v reálu (ale zase jen drobné změny) -class ExportRocnikView(generic.View): - - def get(self, request, prvni_rok=None): - try: - pr = int(prvni_rok) - except: - pr = None - if pr is None: - raise django.http.Http404() - - rocnik = get_object_or_404(Rocnik, prvni_rok=pr, exportovat=True) - cislo = rocnik.posledni_zverejnena_vysledkovka_cislo() - resitele = aktivniResitele(cislo, True) - slovnik_body = utils.secti_body_za_rocnik(cislo, resitele, False) - setrizeni_resitele, body = utils.setrid_resitele_a_body(slovnik_body) - - of = default_ovvpfile('MaM.rocnik', rocnik) - of.headers['comment'] = u'MaM-Web export aktivnich resitelu rocniku {rocnik} do cisla {cislo}'.format(rocnik=rocnik, cislo=cislo) - of.columns = ['id', 'name', 'surname', 'gender', 'born', 'email', 'end-year', - 'street', 'town', 'postcode', 'country', 'spam-flag', 'spam-date', - 'school', 'school-name', 'points', 'rank',] - - resitele_slovnik = {} - for r in resitele: - resitele_slovnik[r.id] = r - - # počítání pořadí řešitelů - posledni_body = 100000 - posledni_poradi = 0 - for i in range(len(setrizeni_resitele)): - rd = resitele_slovnik[setrizeni_resitele[i]].export_row() - - if posledni_body > body[i]: - posledni_body = body[i] - posledni_poradi = i + 1 - rd['rank'] = posledni_poradi - rd['points'] = body[i] - - of.rows.append(rd) - - return of.to_HttpResponse() diff --git a/mamweb/settings_common.py b/mamweb/settings_common.py index 03724d3d..37c7205c 100644 --- a/mamweb/settings_common.py +++ b/mamweb/settings_common.py @@ -144,7 +144,6 @@ INSTALLED_APPS = ( 'various', 'various.autentizace', 'api', - 'aesop', 'odevzdavatko', 'vysledkovky', 'personalni', diff --git a/mamweb/urls.py b/mamweb/urls.py index 0855b6b6..680ab621 100644 --- a/mamweb/urls.py +++ b/mamweb/urls.py @@ -12,7 +12,6 @@ Soubor sloužící jako základní „router“, tj. zde se includují veškeré - :mod:`various.autentizace.urls` - :mod:`api.urls` - :mod:`treenode.urls` -- :mod:`aesop.urls` - ``comments_dj/`` :mod:`django_comments.urls` """ from django.urls import path, include @@ -59,9 +58,6 @@ urlpatterns = [ # treenode (ma vlastni podadresare) path('', include('treenode.urls')), - # Aesop (ma vlastni podadresare) - path('', include('aesop.urls')), - # Comments (interni i verejne) path('comments_dj/', include('django_comments.urls')), diff --git a/seminar/models/personalni.py b/seminar/models/personalni.py index 61313e87..ce7e51ea 100644 --- a/seminar/models/personalni.py +++ b/seminar/models/personalni.py @@ -115,14 +115,10 @@ class Osoba(SeminarModelBase): u.save() super().save() -# -# Mělo by být částečně vytaženo z Aesopa -# viz https://ovvp.mff.cuni.cz/wiki/aesop/export-skol. -# @reversion.register(ignore_duplicates=True) class Skola(SeminarModelBase): - + # Mělo by být částečně vytaženo z Aesopa class Meta: db_table = 'seminar_skoly' verbose_name = 'Škola' @@ -243,30 +239,6 @@ class Resitel(SeminarModelBase): poznamka = models.TextField('neveřejná poznámka', blank=True, help_text='Neveřejná poznámka k řešiteli (plain text)') - - def export_row(self): - "Slovnik pro pouziti v AESOP exportu" - return { - 'id': self.id, - 'name': self.osoba.jmeno, - 'surname': self.osoba.prijmeni, - 'gender': 'M' if self.osoba.pohlavi_muz else 'F', - 'born': self.osoba.datum_narozeni.isoformat() if self.osoba.datum_narozeni else '', - 'email': self.osoba.email, - 'end-year': self.rok_maturity or '', - - 'street': self.osoba.ulice, - 'town': self.osoba.mesto, - 'postcode': self.osoba.psc, - 'country': self.osoba.stat, - - 'spam-flag': 'Y' if self.osoba.datum_souhlasu_zasilani else '', - 'spam-date': self.osoba.datum_souhlasu_zasilani.isoformat() if self.osoba.datum_souhlasu_zasilani else '', - - 'school': self.skola.aesop_id if self.skola else '', - 'school-name': str(self.skola) if self.skola else 'Skola neni znama', - } - def rocnik(self, rocnik): """Vrati skolni rocnik resitele pro zadany Rocnik. Vraci '' pro neznamy rok maturity resitele, Z* pro ekvivalent ZŠ.""" diff --git a/setup/nginx/mam-test.ks.matfyz.cz b/setup/nginx/mam-test.ks.matfyz.cz index 46f9b2ec..27e90979 100644 --- a/setup/nginx/mam-test.ks.matfyz.cz +++ b/setup/nginx/mam-test.ks.matfyz.cz @@ -32,13 +32,6 @@ server { location /media/ { root /akce/mam/www/mamweb-test/; } - - location /aesop-export/ { - auth_basic "AESOP API"; - auth_basic_user_file /akce/mam/www/mamweb-test/.htpasswd-aesop; - try_files $uri @mamweb_test; - } - location / { try_files $uri @mamweb_test; } diff --git a/setup/nginx/mam.mff.cuni.cz b/setup/nginx/mam.mff.cuni.cz index 99292a67..b213fb2a 100644 --- a/setup/nginx/mam.mff.cuni.cz +++ b/setup/nginx/mam.mff.cuni.cz @@ -26,12 +26,6 @@ server { client_max_body_size 50M; - location /aesop-export/ { - auth_basic "AESOP API"; - auth_basic_user_file /akce/mam/www/mamweb-prod/.htpasswd-aesop; - try_files $uri @mamweb_prod; - } - location /static/ { root /akce/mam/www/mamweb-prod/; }