Skip to content
Snippets Groups Projects
Verified Commit ef77ee70 authored by Jonathan Weth's avatar Jonathan Weth :keyboard:
Browse files

Add some new import tasks with different term ranges

Close #8
parent 172171d6
No related branches found
No related tags found
1 merge request!29Resolve "Register different import tasks/methods"
Pipeline #3146 passed
from django.core.management.base import BaseCommand
from ...tasks import untis_import_mysql
from ...tasks import untis_import_mysql_current_term
class Command(BaseCommand):
def handle(self, *args, **options):
untis_import_mysql()
untis_import_mysql_current_term()
from django.core.management.base import BaseCommand
from ...tasks import untis_import_mysql_current_term, untis_import_mysql_all_terms
class Command(BaseCommand):
def handle(self, *args, **options):
untis_import_mysql_all_terms()
from django.core.management.base import BaseCommand
from ...tasks import untis_import_mysql_current_future_terms
class Command(BaseCommand):
def handle(self, *args, **options):
untis_import_mysql_current_future_terms()
from django.core.management.base import BaseCommand
from ...tasks import untis_import_mysql_current_next_term
class Command(BaseCommand):
def handle(self, *args, **options):
untis_import_mysql_current_next_term()
from django.core.management.base import BaseCommand
from ...tasks import untis_import_mysql_future_terms
class Command(BaseCommand):
def handle(self, *args, **options):
untis_import_mysql_future_terms()
from aleksis.apps.untis.util.mysql.importers.terms import (
get_terms_for_date,
get_future_terms_for_date,
)
from aleksis.core.util.core_helpers import celery_optional
from .util.mysql.main import untis_import_mysql as _untis_import_mysql
@celery_optional
def untis_import_mysql():
"""Celery task for import of UNTIS data from MySQL."""
def untis_import_mysql_current_term():
"""Celery task for import of UNTIS data from MySQL (current term)."""
terms = get_terms_for_date()
_untis_import_mysql(terms)
@celery_optional
def untis_import_mysql_future_terms():
"""Celery task for import of UNTIS data from MySQL (all future terms)."""
terms = get_future_terms_for_date()
_untis_import_mysql(terms)
@celery_optional
def untis_import_mysql_all_terms():
"""Celery task for import of UNTIS data from MySQL (all terms in DB)."""
_untis_import_mysql()
@celery_optional
def untis_import_mysql_current_next_term():
"""Celery task for import of UNTIS data from MySQL (current and next term)."""
terms = get_terms_for_date()
future_terms = get_future_terms_for_date()
if future_terms.exists():
terms = terms.union(future_terms[0:1])
_untis_import_mysql(terms)
@celery_optional
def untis_import_mysql_current_future_terms():
"""Celery task for import of UNTIS data from MySQL (current and future terms)."""
terms = get_terms_for_date()
future_terms = get_future_terms_for_date()
terms = terms.union(future_terms)
_untis_import_mysql(terms)
......@@ -31,6 +31,20 @@ def get_terms_for_date(for_date: Optional[date] = None) -> QuerySet:
return qs
def get_future_terms_for_date(for_date: Optional[date] = None) -> QuerySet:
"""Get all furture terms (after the current term)."""
if not for_date:
for_date = timezone.now().date()
qs = run_using(mysql_models.Terms.objects).filter(
datefrom__gt=date_to_untis_date(for_date),
)
return qs
logger = logging.getLogger(__name__)
......
from aleksis.apps.untis.util.mysql.importers.terms import import_terms, get_terms_for_date
from aleksis.apps.untis.util.mysql.util import TQDM_DEFAULTS
from typing import Optional
from django.db import transaction
from django.db.models import QuerySet
from tqdm import tqdm
......@@ -28,9 +29,8 @@ from .importers.substitutions import import_substitutions
@transaction.atomic
def untis_import_mysql():
def untis_import_mysql(terms: Optional[QuerySet] = None):
# School terms and validity ranges
terms = get_terms_for_date()
validity_ref = import_terms(terms)
for validity_range in tqdm(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment