diff --git a/biscuit/apps/schild_nrw/util.py b/biscuit/apps/schild_nrw/util.py index daa52805ef0ab3ffab17a1e566062030acd34937..0a9bb36de34e2af831bc56b567a8c7dd3ded46a3 100644 --- a/biscuit/apps/schild_nrw/util.py +++ b/biscuit/apps/schild_nrw/util.py @@ -1,15 +1,17 @@ -from biscuit.core.models import Person - from collections import OrderedDict +from typing import Any, ByteIO, Dict, Optional, Union -from biscuit.core.util import messages +from django.http import HttpRequest from django.utils.translation import gettext as _ import pandas import phonenumbers +from biscuit.core.models import Person +from biscuit.core.util import messages + -def schild_import_csv_single(request, csv, cols, converters): +def schild_import_csv_single(request: HttpRequest, csv: Union[ByteIO, str], cols: Dict[str, Any], converters: Dict[str, Callable[[Optional[str]], Any]]) -> None: persons = pandas.read_csv(csv, sep=';', names=cols.keys(), dtype=cols, usecols=lambda k: not k.startswith('_'), keep_default_na=False, converters=converters, parse_dates=['date_of_birth'], quotechar='"', encoding='utf-8-sig', true_values=['+', 'Ja'], false_values=['-', 'Nein']) @@ -37,7 +39,7 @@ def schild_import_csv_single(request, csv, cols, converters): 'Some persons failed to be imported.')) -def schild_import_csv(request, teachers_csv, students_csv, guardians_csv): +def schild_import_csv(request: HttpRequest, teachers_csv: Union[ByteIO, str], students_csv: Union[ByteIO, str], guardians_csv: Union[ByteIO, str]) -> None: csv_converters = {'phone_number': lambda v: phonenumbers.parse(v, 'DE') if v else '', 'mobile_number': lambda v: phonenumbers.parse(v, 'DE') if v else '', 'sex': lambda v: 'f' if v == 'w' else v} diff --git a/biscuit/apps/schild_nrw/views.py b/biscuit/apps/schild_nrw/views.py index f68f23a132a12477d972205fcef8532c8b3bf74c..9f59b10b33b99b322004efdc1078b039eeaaee8a 100644 --- a/biscuit/apps/schild_nrw/views.py +++ b/biscuit/apps/schild_nrw/views.py @@ -2,6 +2,7 @@ import io from django.contrib import messages from django.contrib.auth.decorators import login_required +from django.http import HttpRequest, HttpResponse from django.shortcuts import render from .forms import SchILDNRWUploadForm @@ -12,7 +13,7 @@ from biscuit.core.decorators import admin_required @login_required @admin_required -def schild_import(request): +def schild_import(request: HttpRequest) -> HttpResponse: context = {} upload_form = SchILDNRWUploadForm()