From 4f8e98096e6b20d56fcbf55271bcee382d75b08f Mon Sep 17 00:00:00 2001 From: "Tomas \"Jethro\" Pokorny" Date: Wed, 13 Nov 2019 22:14:49 +0100 Subject: [PATCH] Prihlaska | logovani do souboru + bugfixy --- mamweb/settings_common.py | 22 +++++++++++++++++++--- mamweb/settings_prod.py | 2 ++ mamweb/settings_test.py | 2 ++ seminar/forms.py | 2 ++ seminar/views.py | 20 +++++--------------- 5 files changed, 30 insertions(+), 18 deletions(-) diff --git a/mamweb/settings_common.py b/mamweb/settings_common.py index 7bdd6abf..62cd7fe7 100644 --- a/mamweb/settings_common.py +++ b/mamweb/settings_common.py @@ -218,10 +218,14 @@ LOGGING = { 'handlers': ['console'], 'level': 'DEBUG', }, - 'seminar.prihlaska':{ + 'seminar.prihlaska.form':{ 'handlers': ['console','registration_logfile'], 'level': 'INFO' }, + 'seminar.prihlaska.problem':{ + 'handlers': ['console','mail_registration','registration_error_log'], + 'level': 'INFO' + }, # Catch-all logger '': { @@ -244,12 +248,24 @@ LOGGING = { 'class': 'django.utils.log.AdminEmailHandler', 'formatter': 'verbose', }, + 'mail_registraion': { + 'level': 'WARN', + 'class': 'django.utils.log.AdminEmailHandler', + 'formatter': 'verbose', + }, 'registration_logfile':{ 'level': 'INFO', 'class': 'logging.FileHandler', - 'filename': 'registration.log', + # filename declared in specific configuration files 'formatter': 'verbose', - } + }, + 'registration_error_log':{ + 'level': 'INFO', + 'class': 'logging.FileHandler', + # filename declared in specific configuration files + 'formatter': 'verbose', + }, + }, } diff --git a/mamweb/settings_prod.py b/mamweb/settings_prod.py index 918fd4b2..1c223842 100644 --- a/mamweb/settings_prod.py +++ b/mamweb/settings_prod.py @@ -61,6 +61,8 @@ CSRF_COOKIE_SECURE = True LOGGING['loggers']['']['handlers'] = ['console', 'mail_admins'] LOGGING['loggers']['django']['handlers'] = ['console', 'mail_admins'] +LOGGING['handlers']['registration_logfile']['filename'] = '/home/mam-web/logs/prod/registration.log' +LOGGING['handlers']['registration_error_log']['filename'] = '/home/mam-web/logs/prod/registration_errors.log' # E-MAIL NOTIFICATIONS diff --git a/mamweb/settings_test.py b/mamweb/settings_test.py index 9f971f45..2d85f2f5 100644 --- a/mamweb/settings_test.py +++ b/mamweb/settings_test.py @@ -65,3 +65,5 @@ CSRF_COOKIE_SECURE = True LOGGING['loggers']['']['handlers'] = ['console', 'mail_admins'] LOGGING['loggers']['django']['handlers'] = ['console', 'mail_admins'] +LOGGING['handlers']['registration_logfile']['filename'] = '/home/mam-web/logs/test/registration.log' +LOGGING['handlers']['registration_error_log']['filename'] = '/home/mam-web/logs/test/registration_errors.log' diff --git a/seminar/forms.py b/seminar/forms.py index f05b18e2..42d3c2d7 100644 --- a/seminar/forms.py +++ b/seminar/forms.py @@ -86,6 +86,7 @@ class PrihlaskaForm(forms.Form): except ObjectDoesNotExist: pass + return username def clean_email(self): err_logger = logging.getLogger('seminar.prihlaska.problem') @@ -98,6 +99,7 @@ class PrihlaskaForm(forms.Form): except ObjectDoesNotExist: pass + return email def clean(self): diff --git a/seminar/views.py b/seminar/views.py index a320307e..2d442eb9 100644 --- a/seminar/views.py +++ b/seminar/views.py @@ -1026,24 +1026,16 @@ def logoutView(request): return render(request, 'seminar/login.html', {'form': form}) -def prihlaska_log_gdpr_safe(logger, gdpr_logger, msg, form_data): - msg = "{}, form_hash:{}".format(msg,hash(form_data)) - logger.warn(msg) - gdpr_logger.warn(msg+", form:{}".format(form_data)) - - def prihlaskaView(request): - generic_logger = logging.getLogger('seminar.prihlaska') err_logger = logging.getLogger('seminar.prihlaska.problem') form_logger = logging.getLogger('seminar.prihlaska.form') if request.method == 'POST': form = PrihlaskaForm(request.POST) - # TODO vyresit, co se bude v jakych situacich zobrazovat if form.is_valid(): - generic_logger.info("Form valid") fcd = form.cleaned_data - form_hash = hash(fcd) - form_logger.info(fcd,form_hash=form_hash) + form_hash = hash(frozenset(fcd.items())) + fcd["hash"] = form_hash + form_logger.info(fcd) with transaction.atomic(): u = User.objects.create_user( @@ -1072,8 +1064,7 @@ def prihlaskaView(request): o.stat = fcd['stat'] else: # Unknown country - log it - msg = "Unknown country {}".format(fcd['stat_text']) - err_logger.warn(msg,form_hash=form_hash) + err_logger.warn("Unknown country {}. Form hash:{}".format(fcd['stat_text'],form_hash)) o.save() o.user = u @@ -1090,8 +1081,7 @@ def prihlaskaView(request): r.skola = fcd['skola'] else: # Unknown school - log it - msg = "Unknown school {}, {}".format(fcd['skola_nazev'],fcd['skola_adresa']) - err_logger.warn(msg,form_hash=form_hash) + err_logger.warn("Unknown school {}, {}. Form hash:{}".format(fcd['skola_nazev'],fcd['skola_adresa'],form_hash)) r.save()