diff --git a/fanik/__init__.py b/fanik/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/fanik/admin.py b/fanik/admin.py new file mode 100644 index 00000000..8c38f3f3 --- /dev/null +++ b/fanik/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/fanik/apps.py b/fanik/apps.py new file mode 100644 index 00000000..1ddc3fc1 --- /dev/null +++ b/fanik/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class FanikConfig(AppConfig): + name = 'fanik' diff --git a/fanik/middleware.py b/fanik/middleware.py new file mode 100644 index 00000000..cf819ef9 --- /dev/null +++ b/fanik/middleware.py @@ -0,0 +1,31 @@ +from random import choices +from django.shortcuts import render + +def fanik_middleware(get_response): + # Mapování uživatelských jmen na blbý kecy (+ váhy), obsah odkazu ap. + config = { + 'fanik': { + 'kecy': [ + (r'

Co je web?

– 8. 11. 2021

', 10), + (r'

Mě to nezajímá.

– 8. 11. 2021

', 5), + ], + 'link': r'Svůj postoj jsem přehodnotil', + }, + } + + def middleware(request): + if request.user.is_authenticated: + username = request.user.username + if username in config: + kecy = config[username]['kecy'] + vahy = [x[1] for x in kecy] + kec = choices([x[0] for x in kecy], weights=vahy, k=1)[0] + template_name = 'universal.html' + context = {} + context['raw_html'] = kec + config[username]['link'] + return render(request,template_name,context) + + # Ve všech ostatních případech vrátíme výsledek původního dotazu + return get_response(request) + + return middleware diff --git a/fanik/migrations/__init__.py b/fanik/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/fanik/models.py b/fanik/models.py new file mode 100644 index 00000000..71a83623 --- /dev/null +++ b/fanik/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/fanik/tests.py b/fanik/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/fanik/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/fanik/views.py b/fanik/views.py new file mode 100644 index 00000000..91ea44a2 --- /dev/null +++ b/fanik/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/mamweb/settings_common.py b/mamweb/settings_common.py index 3c850245..b8b1dcc6 100644 --- a/mamweb/settings_common.py +++ b/mamweb/settings_common.py @@ -65,6 +65,7 @@ MIDDLEWARE = ( 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', 'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware', + 'fanik.middleware.fanik_middleware', ) TEMPLATES = [