From 1a9f9ca23b7e83c0e34543f93158e68c14429c0d Mon Sep 17 00:00:00 2001 From: Rodolphe Breard Date: Sun, 3 Jun 2018 23:48:21 +0200 Subject: [PATCH] Move the nsfw functions into a real module --- khaganat/settings.py | 1 + khaganat/static/khaganat/css/khaganat.css | 51 +------- khaganat/templates/khaganat/base.html | 5 +- khaganat/urls.py | 1 + logs/templates/logs/entries.html | 4 +- logs/views.py | 9 +- neluser/locale/en/LC_MESSAGES/django.po | 78 +++--------- neluser/locale/fr/LC_MESSAGES/django.po | 120 ++++++++---------- neluser/urls.py | 6 - nsfw/__init__.py | 0 nsfw/admin.py | 3 + nsfw/apps.py | 5 + nsfw/locale/en/LC_MESSAGES/django.po | 57 +++++++++ nsfw/locale/fr/LC_MESSAGES/django.po | 62 +++++++++ nsfw/migrations/__init__.py | 0 nsfw/models.py | 3 + .../templates/nsfw/alert.html | 10 +- .../templates/nsfw/disabled_alert.html | 2 +- nsfw/templates/nsfw/redirect_page.html | 8 ++ nsfw/tests.py | 3 + nsfw/urls.py | 10 ++ neluser/nsfw.py => nsfw/views.py | 32 ++++- pages/views.py | 2 +- 23 files changed, 271 insertions(+), 201 deletions(-) create mode 100644 nsfw/__init__.py create mode 100644 nsfw/admin.py create mode 100644 nsfw/apps.py create mode 100644 nsfw/locale/en/LC_MESSAGES/django.po create mode 100644 nsfw/locale/fr/LC_MESSAGES/django.po create mode 100644 nsfw/migrations/__init__.py create mode 100644 nsfw/models.py rename neluser/templates/neluser/nsfw.html => nsfw/templates/nsfw/alert.html (85%) rename neluser/templates/neluser/nsfw_message.html => nsfw/templates/nsfw/disabled_alert.html (51%) create mode 100644 nsfw/templates/nsfw/redirect_page.html create mode 100644 nsfw/tests.py create mode 100644 nsfw/urls.py rename neluser/nsfw.py => nsfw/views.py (68%) diff --git a/khaganat/settings.py b/khaganat/settings.py index 6dbae12..cd8a030 100644 --- a/khaganat/settings.py +++ b/khaganat/settings.py @@ -46,6 +46,7 @@ INSTALLED_APPS = [ 'pages.apps.PagesConfig', 'navbar.apps.NavbarConfig', 'logs.apps.LogsConfig', + 'nsfw.apps.NsfwConfig', 'npb.apps.NpbConfig', 'bulma', ] diff --git a/khaganat/static/khaganat/css/khaganat.css b/khaganat/static/khaganat/css/khaganat.css index a5ed946..9c26a6b 100644 --- a/khaganat/static/khaganat/css/khaganat.css +++ b/khaganat/static/khaganat/css/khaganat.css @@ -1,50 +1,3 @@ -html,body { - background: url("/static/khaganat/images/website_khaganat_bg_v7.jpg") no-repeat center fixed; - font-family: "Verdana","Arial","Helvetica",sans-serif; - color: #222; -} - -#mainNav { - padding-top: 0; - padding-bottom: 0; - background-color: #efeded; - opacity: 0.8; -} - -#page-footer { - text-align: center; -} - -#messages { - margin-top: 10px; -} - -.tooltip-inner { - background-color: #efeded; - color: #222; -} - -.tooltip.bs-tooltip-auto[x-placement^=right] .arrow::before, .tooltip.bs-tooltip-right .arrow::before { - border-right-color: #efeded; -} - -.content-bloc { - margin: 10px; - padding: 10px; - background-color: #efeded; - opacity: 0.8; - border-radius: 1.4em; -} - -.log-nick { - font-weight: bold; - color: #6300A6; -} - -.log-content { -} - -.log-action { - font-style: italic; - color: #9073FF; +#messagesContainer { + margin-bottom: 20px; } diff --git a/khaganat/templates/khaganat/base.html b/khaganat/templates/khaganat/base.html index c72d20d..e247461 100644 --- a/khaganat/templates/khaganat/base.html +++ b/khaganat/templates/khaganat/base.html @@ -6,8 +6,7 @@ - - + {% block headers %}{% endblock %} Khaganat - {% block title %}{% endblock %} @@ -15,7 +14,7 @@ {% navbar %}
{% if messages %} -
+
{% for message in messages %}
diff --git a/khaganat/urls.py b/khaganat/urls.py index 57dcd4c..fa402aa 100644 --- a/khaganat/urls.py +++ b/khaganat/urls.py @@ -30,4 +30,5 @@ urlpatterns += i18n_patterns( path('page/', include('pages.urls')), path('paste/', include('npb.urls', namespace='npb')), path('logs/', include('logs.urls')), + path('nsfw/', include('nsfw.urls')), ) diff --git a/logs/templates/logs/entries.html b/logs/templates/logs/entries.html index 9342235..138491c 100644 --- a/logs/templates/logs/entries.html +++ b/logs/templates/logs/entries.html @@ -53,7 +53,7 @@
{% endif %} - {% if entries %} + {% if entries and not filter_nsfw %} {% for entry in entries %} @@ -70,6 +70,8 @@ {% endfor %}
+ {% elif entries %} + {% include "nsfw/alert.html" with next_url=current_url %} {% endif %}
diff --git a/logs/views.py b/logs/views.py index 687b50c..7e9f6ce 100644 --- a/logs/views.py +++ b/logs/views.py @@ -6,7 +6,7 @@ from django.views import generic from django.conf import settings from django.urls import reverse from django.http import Http404 -from neluser import nsfw +from nsfw import views as nsfw from .models import Source, Entry from .forms import SearchForm from utils import is_link_legit @@ -67,6 +67,7 @@ def search_view(request): class EntriesView(generic.ListView): template_name = 'logs/entries.html' context_object_name = 'entries' + filter_nsfw = False def is_nsfw(self): for e in self.get_queryset(): @@ -78,9 +79,9 @@ class EntriesView(generic.ListView): def dispatch(self, request, *args, **kwargs): if self.is_nsfw(): if not nsfw.is_nsfw_allowed(request): - return nsfw.redirect(request) + self.filter_nsfw = True else: - nsfw.alert(request) + nsfw.alert(request, request.get_full_path()) return super().dispatch(request, *args, **kwargs) def get_date(self): @@ -155,6 +156,8 @@ class EntriesView(generic.ListView): context['current_source'] = self.get_source() context['dates'] = self.get_dates(context['current_source']) context['current_date'] = self.get_date() + context['filter_nsfw'] = self.filter_nsfw + context['current_url'] = self.request.get_full_path() return context def get_queryset(self): diff --git a/neluser/locale/en/LC_MESSAGES/django.po b/neluser/locale/en/LC_MESSAGES/django.po index ccf90f0..bbe87df 100644 --- a/neluser/locale/en/LC_MESSAGES/django.po +++ b/neluser/locale/en/LC_MESSAGES/django.po @@ -2,7 +2,7 @@ msgid "" msgstr "" "Project-Id-Version: 1.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2018-06-02 21:36+0200\n" +"POT-Creation-Date: 2018-06-03 23:12+0200\n" "PO-Revision-Date: 2018-02-04 01:03+0100\n" "Last-Translator: Khaganat \n" "Language-Team: Khaganat \n" @@ -54,19 +54,17 @@ msgstr "" msgid "users" msgstr "" -#: templates/neluser/activate_done.html:4 templates/neluser/login.html:13 -#: templates/neluser/register.html:4 templates/neluser/register.html:11 -#: templates/neluser/register_done.html:4 +#: templates/neluser/activate_done.html:4 templates/neluser/login.html:15 +#: templates/neluser/register.html:5 templates/neluser/register.html:13 msgid "register" msgstr "" -#: templates/neluser/activate_done.html:9 +#: templates/neluser/activate_done.html:8 msgid "account_activated" msgstr "Your account has been activated." -#: templates/neluser/activate_done.html:10 templates/neluser/login.html:4 -#: templates/neluser/login.html:12 -#: templates/neluser/password_reset_done.html:10 +#: templates/neluser/activate_done.html:9 templates/neluser/login.html:5 +#: templates/neluser/login.html:13 templates/neluser/password_reset_done.html:9 msgid "login" msgstr "" @@ -106,62 +104,18 @@ msgstr "" msgid "forgotten_password" msgstr "forgotten password" -#: templates/neluser/nsfw.html:4 templates/neluser/nsfw.html:8 -msgid "NSFW content" -msgstr "" - -#: templates/neluser/nsfw.html:9 -msgid "" -"The content you were about to see is flagged as sensitive and therefore " -"cannot be seen while the safe mode is activated." -msgstr "" - -#: templates/neluser/nsfw.html:11 -msgid "Go back home" -msgstr "" - -#: templates/neluser/nsfw.html:12 -msgid "Permanently disable safe mode" -msgstr "" - -#: templates/neluser/nsfw.html:14 -msgid "Or disable safe mode for:" -msgstr "" - -#: templates/neluser/nsfw.html:15 -msgid "5 minutes" -msgstr "" - -#: templates/neluser/nsfw.html:16 -msgid "1 hour" -msgstr "" - -#: templates/neluser/nsfw.html:17 -msgid "1 day" -msgstr "" - -#: templates/neluser/nsfw_message.html:2 -msgid "" -"This page contains sensitive content which is displayed because you disabled " -"the safe mode." -msgstr "" - -#: templates/neluser/nsfw_message.html:3 -msgid "Enable safe mode" -msgstr "" - -#: templates/neluser/password_reset.html:4 -#: templates/neluser/password_reset_confirm.html:4 +#: templates/neluser/password_reset.html:5 +#: templates/neluser/password_reset_confirm.html:5 #: templates/neluser/password_reset_done.html:4 #: templates/neluser/password_reset_email_sent.html:4 msgid "password_reset" msgstr "password reset" -#: templates/neluser/password_reset.html:11 +#: templates/neluser/password_reset.html:12 msgid "reset_my_password" msgstr "reset my password" -#: templates/neluser/password_reset_confirm.html:9 +#: templates/neluser/password_reset_confirm.html:5 msgid "set_new_password" msgstr "Please set a new password" @@ -173,7 +127,7 @@ msgstr "change my password" msgid "reset_password_invalid_link" msgstr "Sorry, we are unable to reset your password." -#: templates/neluser/password_reset_done.html:9 +#: templates/neluser/password_reset_done.html:8 msgid "password_reset_success" msgstr "Your password has been changed." @@ -196,21 +150,25 @@ msgstr "" "An email has been sent to your address. Please follow the link given in this " "email to reset your password." +#: templates/neluser/password_reset_email_sent.html:9 +msgid "Go back home" +msgstr "" + #: templates/neluser/password_reset_email_subject.txt:2 #, python-format msgid "Password reset on %(site_name)s" msgstr "" -#: templates/neluser/register_done.html:9 +#: templates/neluser/register_done.html:4 msgid "almost_there" msgstr "Almost there…" -#: templates/neluser/register_done.html:10 +#: templates/neluser/register_done.html:8 msgid "activate_your_account" msgstr "" "You now need to activate your account. Please click on the link that has " "been sent to your email address." -#: templates/neluser/register_done.html:11 +#: templates/neluser/register_done.html:9 msgid "take_me_home" msgstr "Take me home" diff --git a/neluser/locale/fr/LC_MESSAGES/django.po b/neluser/locale/fr/LC_MESSAGES/django.po index 859b8bc..e95ebd6 100644 --- a/neluser/locale/fr/LC_MESSAGES/django.po +++ b/neluser/locale/fr/LC_MESSAGES/django.po @@ -2,7 +2,7 @@ msgid "" msgstr "" "Project-Id-Version: 1.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2018-06-02 21:36+0200\n" +"POT-Creation-Date: 2018-06-03 23:12+0200\n" "PO-Revision-Date: 2018-02-04 01:03+0100\n" "Last-Translator: Khaganat \n" "Language-Team: Khaganat \n" @@ -56,19 +56,17 @@ msgstr "utilisateur" msgid "users" msgstr "utilisateurs" -#: templates/neluser/activate_done.html:4 templates/neluser/login.html:13 -#: templates/neluser/register.html:4 templates/neluser/register.html:11 -#: templates/neluser/register_done.html:4 +#: templates/neluser/activate_done.html:4 templates/neluser/login.html:15 +#: templates/neluser/register.html:5 templates/neluser/register.html:13 msgid "register" msgstr "inscription" -#: templates/neluser/activate_done.html:9 +#: templates/neluser/activate_done.html:8 msgid "account_activated" msgstr "compte activé" -#: templates/neluser/activate_done.html:10 templates/neluser/login.html:4 -#: templates/neluser/login.html:12 -#: templates/neluser/password_reset_done.html:10 +#: templates/neluser/activate_done.html:9 templates/neluser/login.html:5 +#: templates/neluser/login.html:13 templates/neluser/password_reset_done.html:9 msgid "login" msgstr "connexion" @@ -108,67 +106,18 @@ msgstr "Activation de compte sur %(site_name)s" msgid "forgotten_password" msgstr "mot de passe oublié" -#: templates/neluser/nsfw.html:4 templates/neluser/nsfw.html:8 -msgid "NSFW content" -msgstr "Contenu sensible" - -#: templates/neluser/nsfw.html:9 -msgid "" -"The content you were about to see is flagged as sensitive and therefore " -"cannot be seen while the safe mode is activated." -msgstr "" -"Le contenu que vous vous apprêtiez à consulter est indiqué comme pouvant " -"choquer la sensibilité et ne peut donc pas être affiché tant que la " -"navigation filtrée est activée." - -#: templates/neluser/nsfw.html:11 -msgid "Go back home" -msgstr "Retourner à l'accueil" - -#: templates/neluser/nsfw.html:12 -msgid "Permanently disable safe mode" -msgstr "Définitivement désactiver la navigation filtrée" - -#: templates/neluser/nsfw.html:14 -msgid "Or disable safe mode for:" -msgstr "Ou désactiver la navigation filtrée pour :" - -#: templates/neluser/nsfw.html:15 -msgid "5 minutes" -msgstr "5 minutes" - -#: templates/neluser/nsfw.html:16 -msgid "1 hour" -msgstr "1 heure" - -#: templates/neluser/nsfw.html:17 -msgid "1 day" -msgstr "1 jour" - -#: templates/neluser/nsfw_message.html:2 -msgid "" -"This page contains sensitive content which is displayed because you disabled " -"the safe mode." -msgstr "" -"Cette page contient du contenu indiqué comme pouvant heurter la sensibilité. " -"Ce contenu est affiché car vous avez désactivé la navigation filtrée." - -#: templates/neluser/nsfw_message.html:3 -msgid "Enable safe mode" -msgstr "Activer la navigation filtrée" - -#: templates/neluser/password_reset.html:4 -#: templates/neluser/password_reset_confirm.html:4 +#: templates/neluser/password_reset.html:5 +#: templates/neluser/password_reset_confirm.html:5 #: templates/neluser/password_reset_done.html:4 #: templates/neluser/password_reset_email_sent.html:4 msgid "password_reset" msgstr "réinitialisation du mot de passe" -#: templates/neluser/password_reset.html:11 +#: templates/neluser/password_reset.html:12 msgid "reset_my_password" msgstr "réinitialiser mon mot de passe" -#: templates/neluser/password_reset_confirm.html:9 +#: templates/neluser/password_reset_confirm.html:5 msgid "set_new_password" msgstr "Veuillez indiquer un nouveau mot de passe" @@ -180,7 +129,7 @@ msgstr "Modifier mon mot de passe" msgid "reset_password_invalid_link" msgstr "Désolé, nous ne sommes pas en mesure de modifier votre mot de passe." -#: templates/neluser/password_reset_done.html:9 +#: templates/neluser/password_reset_done.html:8 msgid "password_reset_success" msgstr "Votre mot de passe a été modifié." @@ -206,21 +155,62 @@ msgstr "" "Un message a été envoyé sur votre messagerie électronique. Veuillez suivre " "le lien donné dans ce message afin de réinitialiser votre mot de passe." +#: templates/neluser/password_reset_email_sent.html:9 +msgid "Go back home" +msgstr "Retourner à l'accueil" + #: templates/neluser/password_reset_email_subject.txt:2 #, python-format msgid "Password reset on %(site_name)s" msgstr "Réinitialisation du mot de passe sur %(site_name)s" -#: templates/neluser/register_done.html:9 +#: templates/neluser/register_done.html:4 msgid "almost_there" msgstr "Vous y êtes presque…" -#: templates/neluser/register_done.html:10 +#: templates/neluser/register_done.html:8 msgid "activate_your_account" msgstr "" "Vous devez maintenant activer votre compte. Veuillez cliquer sur le lien qui " "vient d'être envoyé sur votre adresse électronique." -#: templates/neluser/register_done.html:11 +#: templates/neluser/register_done.html:9 msgid "take_me_home" msgstr "Retour à l'accueil" + +#~ msgid "NSFW content" +#~ msgstr "Contenu sensible" + +#~ msgid "" +#~ "The content you were about to see is flagged as sensitive and therefore " +#~ "cannot be seen while the safe mode is activated." +#~ msgstr "" +#~ "Le contenu que vous vous apprêtiez à consulter est indiqué comme pouvant " +#~ "choquer la sensibilité et ne peut donc pas être affiché tant que la " +#~ "navigation filtrée est activée." + +#~ msgid "Permanently disable safe mode" +#~ msgstr "Définitivement désactiver la navigation filtrée" + +#~ msgid "Or disable safe mode for:" +#~ msgstr "Ou désactiver la navigation filtrée pour :" + +#~ msgid "5 minutes" +#~ msgstr "5 minutes" + +#~ msgid "1 hour" +#~ msgstr "1 heure" + +#~ msgid "1 day" +#~ msgstr "1 jour" + +#~ msgid "" +#~ "This page contains sensitive content which is displayed because you " +#~ "disabled the safe mode." +#~ msgstr "" +#~ "Cette page contient du contenu indiqué comme pouvant heurter la " +#~ "sensibilité. Ce contenu est affiché car vous avez désactivé la navigation " +#~ "filtrée." + +#~ msgid "Enable safe mode" +#~ msgstr "Activer la navigation filtrée" diff --git a/neluser/urls.py b/neluser/urls.py index 1022245..c53989e 100644 --- a/neluser/urls.py +++ b/neluser/urls.py @@ -1,7 +1,6 @@ from django.contrib.auth import views as auth_views from django.urls import reverse_lazy, path from . import views -from . import nsfw urlpatterns = [ @@ -62,9 +61,4 @@ urlpatterns = [ ), name='password_reset_complete' ), - - # NSFW - path('nsfw/', nsfw.warn_view, name='nsfw'), - path('nsfw/enable//', nsfw.enable_view, name='enable_nsfw'), - path('nsfw/disable/', nsfw.disable_view, name='disable_nsfw'), ] diff --git a/nsfw/__init__.py b/nsfw/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/nsfw/admin.py b/nsfw/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/nsfw/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/nsfw/apps.py b/nsfw/apps.py new file mode 100644 index 0000000..c973d41 --- /dev/null +++ b/nsfw/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class NsfwConfig(AppConfig): + name = 'nsfw' diff --git a/nsfw/locale/en/LC_MESSAGES/django.po b/nsfw/locale/en/LC_MESSAGES/django.po new file mode 100644 index 0000000..427b789 --- /dev/null +++ b/nsfw/locale/en/LC_MESSAGES/django.po @@ -0,0 +1,57 @@ +msgid "" +msgstr "" +"Project-Id-Version: 1.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2018-06-03 23:12+0200\n" +"PO-Revision-Date: 2018-06-03 23:12+0200\n" +"Last-Translator: Khaganat \n" +"Language-Team: Khaganat \n" +"Language: en\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" + +#: templates/nsfw/alert.html:3 templates/nsfw/redirect_page.html:4 +msgid "NSFW content" +msgstr "" + +#: templates/nsfw/alert.html:6 +msgid "" +"The content you were about to see is flagged as sensitive and therefore " +"cannot be seen while the safe mode is activated." +msgstr "" + +#: templates/nsfw/alert.html:9 +msgid "Go back home" +msgstr "" + +#: templates/nsfw/alert.html:10 +msgid "Permanently disable safe mode" +msgstr "" + +#: templates/nsfw/alert.html:13 +msgid "Or disable safe mode for:" +msgstr "" + +#: templates/nsfw/alert.html:14 +msgid "5 minutes" +msgstr "" + +#: templates/nsfw/alert.html:15 +msgid "1 hour" +msgstr "" + +#: templates/nsfw/alert.html:16 +msgid "1 day" +msgstr "" + +#: templates/nsfw/disabled_alert.html:2 +msgid "" +"This page contains sensitive content which is displayed because you disabled " +"the safe mode." +msgstr "" + +#: templates/nsfw/disabled_alert.html:3 +msgid "Enable safe mode" +msgstr "" diff --git a/nsfw/locale/fr/LC_MESSAGES/django.po b/nsfw/locale/fr/LC_MESSAGES/django.po new file mode 100644 index 0000000..2a71ac2 --- /dev/null +++ b/nsfw/locale/fr/LC_MESSAGES/django.po @@ -0,0 +1,62 @@ +msgid "" +msgstr "" +"Project-Id-Version: 1.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2018-06-03 23:12+0200\n" +"PO-Revision-Date: 2018-06-03 23:12+0200\n" +"Last-Translator: Khaganat \n" +"Language-Team: Khaganat \n" +"Language: fr\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=2; plural=(n > 1);\n" + +#: templates/nsfw/alert.html:3 templates/nsfw/redirect_page.html:4 +msgid "NSFW content" +msgstr "Contenu sensible" + +#: templates/nsfw/alert.html:6 +msgid "" +"The content you were about to see is flagged as sensitive and therefore " +"cannot be seen while the safe mode is activated." +msgstr "" +"Le contenu que vous vous apprêtiez à consulter est indiqué comme pouvant " +"choquer la sensibilité et ne peut donc pas être affiché tant que la " +"navigation filtrée est activée." + +#: templates/nsfw/alert.html:9 +msgid "Go back home" +msgstr "Retourner à l'accueil" + +#: templates/nsfw/alert.html:10 +msgid "Permanently disable safe mode" +msgstr "Définitivement désactiver la navigation filtrée" + +#: templates/nsfw/alert.html:13 +msgid "Or disable safe mode for:" +msgstr "Ou désactiver la navigation filtrée pour :" + +#: templates/nsfw/alert.html:14 +msgid "5 minutes" +msgstr "5 minutes" + +#: templates/nsfw/alert.html:15 +msgid "1 hour" +msgstr "1 heure" + +#: templates/nsfw/alert.html:16 +msgid "1 day" +msgstr "1 jour" + +#: templates/nsfw/disabled_alert.html:2 +msgid "" +"This page contains sensitive content which is displayed because you disabled " +"the safe mode." +msgstr "" +"Cette page contient du contenu indiqué comme pouvant heurter la sensibilité. " +"Ce contenu est affiché car vous avez désactivé la navigation filtrée." + +#: templates/nsfw/disabled_alert.html:3 +msgid "Enable safe mode" +msgstr "Activer la navigation filtrée" diff --git a/nsfw/migrations/__init__.py b/nsfw/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/nsfw/models.py b/nsfw/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/nsfw/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/neluser/templates/neluser/nsfw.html b/nsfw/templates/nsfw/alert.html similarity index 85% rename from neluser/templates/neluser/nsfw.html rename to nsfw/templates/nsfw/alert.html index 9a2c504..109f507 100644 --- a/neluser/templates/neluser/nsfw.html +++ b/nsfw/templates/nsfw/alert.html @@ -1,9 +1,4 @@ -{% extends "khaganat/base.html" %} {% load i18n %} - -{% block title %}{% trans "NSFW content" %}{% endblock %} - -{% block content %} -{% endblock %} diff --git a/neluser/templates/neluser/nsfw_message.html b/nsfw/templates/nsfw/disabled_alert.html similarity index 51% rename from neluser/templates/neluser/nsfw_message.html rename to nsfw/templates/nsfw/disabled_alert.html index ca90f97..87ebad4 100644 --- a/neluser/templates/neluser/nsfw_message.html +++ b/nsfw/templates/nsfw/disabled_alert.html @@ -1,3 +1,3 @@ {% load i18n %} {% trans "This page contains sensitive content which is displayed because you disabled the safe mode." %}
-{% trans "Enable safe mode" %} +{% trans "Enable safe mode" %} diff --git a/nsfw/templates/nsfw/redirect_page.html b/nsfw/templates/nsfw/redirect_page.html new file mode 100644 index 0000000..0b0ba20 --- /dev/null +++ b/nsfw/templates/nsfw/redirect_page.html @@ -0,0 +1,8 @@ +{% extends "khaganat/base.html" %} +{% load i18n %} + +{% block title %}{% trans "NSFW content" %}{% endblock %} + +{% block content %} +{% include "nsfw/alert.html" %} +{% endblock %} diff --git a/nsfw/tests.py b/nsfw/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/nsfw/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/nsfw/urls.py b/nsfw/urls.py new file mode 100644 index 0000000..50dfc51 --- /dev/null +++ b/nsfw/urls.py @@ -0,0 +1,10 @@ +from django.contrib.auth import views as auth_views +from django.urls import reverse_lazy, path +from . import views + + +urlpatterns = [ + path('', views.warn_view, name='nsfw'), + path('enable//', views.enable_view, name='enable_nsfw'), + path('disable/', views.disable_view, name='disable_nsfw'), +] diff --git a/neluser/nsfw.py b/nsfw/views.py similarity index 68% rename from neluser/nsfw.py rename to nsfw/views.py index ed27827..d9fc3a9 100644 --- a/neluser/nsfw.py +++ b/nsfw/views.py @@ -21,7 +21,9 @@ def disable_view(request): if isinstance(request.user, NelUser): request.user.nsfw_allowed = False request.user.save() - next_url = reverse('index') + next_url = QueryDict(request.META.get('QUERY_STRING')).get('next') + if not is_link_legit(next_url): + next_url = reverse('index') response = HttpResponseRedirect(next_url) response.delete_cookie(settings.KHAGANAT_NSFW_NAME) return response @@ -32,9 +34,9 @@ def enable_view(request, max_age): max_age = int(max_age) or None except ValueError: max_age = None - next_url = QueryDict(request.META.get('QUERY_STRING')).get('next') or '/' + next_url = QueryDict(request.META.get('QUERY_STRING')).get('next') if not is_link_legit(next_url): - next_url = '/' + next_url = reverse('index') response = HttpResponseRedirect(next_url) if isinstance(request.user, NelUser) and not max_age: request.user.nsfw_allowed = True @@ -52,11 +54,26 @@ def warn_view(request): next_url = QueryDict(request.META.get('QUERY_STRING')).get('next') or '/' if not is_link_legit(next_url): next_url = '/' + prev_url = QueryDict(request.META.get('QUERY_STRING')).get('prev') + if not is_link_legit(prev_url): + prev_url = None context = { + 'prev_url': prev_url, + 'go_home': True, 'next_url': next_url, 'is_authenticated': request.user.is_authenticated, } - return render(request, 'neluser/nsfw.html', context=context) + return render(request, 'nsfw/redirect_page.html', context=context) + + +def warn_msg(request, next_url=None): + context = { + 'prev_url': None, + 'go_home': False, + 'next_url': next_url, + 'is_authenticated': request.user.is_authenticated, + } + return render_to_string(request, 'nsfw/redirect_page.html', context=context) def redirect(request): @@ -66,6 +83,9 @@ def redirect(request): ) return HttpResponseRedirect(dest) -def alert(request): - msg = render_to_string('neluser/nsfw_message.html') +def alert(request, next_url=None): + context = { + 'next_url': next_url, + } + msg = render_to_string('nsfw/disabled_alert.html', context=context) messages.info(request, msg, extra_tags='safe') diff --git a/pages/views.py b/pages/views.py index c04af03..54b3024 100644 --- a/pages/views.py +++ b/pages/views.py @@ -2,7 +2,7 @@ from django.http import HttpResponseRedirect, Http404 from django.utils.translation import get_language from django.views import generic from django.urls import reverse -from neluser import nsfw +from nsfw import views as nsfw from .models import Page, PageContent