Move the nsfw functions into a real module

This commit is contained in:
Rodolphe Breard 2018-06-03 23:48:21 +02:00
parent b0b8f30580
commit 1a9f9ca23b
23 changed files with 271 additions and 201 deletions

View file

@ -46,6 +46,7 @@ INSTALLED_APPS = [
'pages.apps.PagesConfig', 'pages.apps.PagesConfig',
'navbar.apps.NavbarConfig', 'navbar.apps.NavbarConfig',
'logs.apps.LogsConfig', 'logs.apps.LogsConfig',
'nsfw.apps.NsfwConfig',
'npb.apps.NpbConfig', 'npb.apps.NpbConfig',
'bulma', 'bulma',
] ]

View file

@ -1,50 +1,3 @@
html,body { #messagesContainer {
background: url("/static/khaganat/images/website_khaganat_bg_v7.jpg") no-repeat center fixed; margin-bottom: 20px;
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;
} }

View file

@ -6,8 +6,7 @@
<link rel="stylesheet" href="{% static 'bulma/css/font-awesome.min.css' %}"> <link rel="stylesheet" href="{% static 'bulma/css/font-awesome.min.css' %}">
<link rel="stylesheet" href="{% static 'bulma/css/style.css' %}"> <link rel="stylesheet" href="{% static 'bulma/css/style.css' %}">
<link rel="shortcut icon" href="{% static "khaganat/images/favicon.ico" %}"> <link rel="shortcut icon" href="{% static "khaganat/images/favicon.ico" %}">
<!-- <link rel="stylesheet" href="{% static "khaganat/css/khaganat.css" %}" /> --> <link rel="stylesheet" href="{% static "khaganat/css/khaganat.css" %}">
<script defer src="{% static "khaganat/js/khaganat.js" %}"></script>
{% block headers %}{% endblock %} {% block headers %}{% endblock %}
<title>Khaganat - {% block title %}{% endblock %}</title> <title>Khaganat - {% block title %}{% endblock %}</title>
</head> </head>
@ -15,7 +14,7 @@
{% navbar %} {% navbar %}
<section class="section"> <section class="section">
{% if messages %} {% if messages %}
<div class="container"> <div class="container" id="messagesContainer">
{% for message in messages %} {% for message in messages %}
<article class="message{% if message.level == DEFAULT_MESSAGE_LEVELS.ERROR %} is-danger{% elif message.level == DEFAULT_MESSAGE_LEVELS.WARNING %} is-warning{% elif message.level == DEFAULT_MESSAGE_LEVELS.SUCCESS %} is-success{% elif message.level == DEFAULT_MESSAGE_LEVELS.INFO %} is-info{% endif %}"> <article class="message{% if message.level == DEFAULT_MESSAGE_LEVELS.ERROR %} is-danger{% elif message.level == DEFAULT_MESSAGE_LEVELS.WARNING %} is-warning{% elif message.level == DEFAULT_MESSAGE_LEVELS.SUCCESS %} is-success{% elif message.level == DEFAULT_MESSAGE_LEVELS.INFO %} is-info{% endif %}">
<div class="message-body"> <div class="message-body">

View file

@ -30,4 +30,5 @@ urlpatterns += i18n_patterns(
path('page/', include('pages.urls')), path('page/', include('pages.urls')),
path('paste/', include('npb.urls', namespace='npb')), path('paste/', include('npb.urls', namespace='npb')),
path('logs/', include('logs.urls')), path('logs/', include('logs.urls')),
path('nsfw/', include('nsfw.urls')),
) )

View file

@ -53,7 +53,7 @@
</ul> </ul>
</div> </div>
{% endif %} {% endif %}
{% if entries %} {% if entries and not filter_nsfw %}
<table class="table is-narrow is-striped"> <table class="table is-narrow is-striped">
<tbody> <tbody>
{% for entry in entries %} {% for entry in entries %}
@ -70,6 +70,8 @@
{% endfor %} {% endfor %}
</tbody> </tbody>
</table> </table>
{% elif entries %}
{% include "nsfw/alert.html" with next_url=current_url %}
{% endif %} {% endif %}
</div> </div>
</div> </div>

View file

@ -6,7 +6,7 @@ from django.views import generic
from django.conf import settings from django.conf import settings
from django.urls import reverse from django.urls import reverse
from django.http import Http404 from django.http import Http404
from neluser import nsfw from nsfw import views as nsfw
from .models import Source, Entry from .models import Source, Entry
from .forms import SearchForm from .forms import SearchForm
from utils import is_link_legit from utils import is_link_legit
@ -67,6 +67,7 @@ def search_view(request):
class EntriesView(generic.ListView): class EntriesView(generic.ListView):
template_name = 'logs/entries.html' template_name = 'logs/entries.html'
context_object_name = 'entries' context_object_name = 'entries'
filter_nsfw = False
def is_nsfw(self): def is_nsfw(self):
for e in self.get_queryset(): for e in self.get_queryset():
@ -78,9 +79,9 @@ class EntriesView(generic.ListView):
def dispatch(self, request, *args, **kwargs): def dispatch(self, request, *args, **kwargs):
if self.is_nsfw(): if self.is_nsfw():
if not nsfw.is_nsfw_allowed(request): if not nsfw.is_nsfw_allowed(request):
return nsfw.redirect(request) self.filter_nsfw = True
else: else:
nsfw.alert(request) nsfw.alert(request, request.get_full_path())
return super().dispatch(request, *args, **kwargs) return super().dispatch(request, *args, **kwargs)
def get_date(self): def get_date(self):
@ -155,6 +156,8 @@ class EntriesView(generic.ListView):
context['current_source'] = self.get_source() context['current_source'] = self.get_source()
context['dates'] = self.get_dates(context['current_source']) context['dates'] = self.get_dates(context['current_source'])
context['current_date'] = self.get_date() context['current_date'] = self.get_date()
context['filter_nsfw'] = self.filter_nsfw
context['current_url'] = self.request.get_full_path()
return context return context
def get_queryset(self): def get_queryset(self):

View file

@ -2,7 +2,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: 1.0\n" "Project-Id-Version: 1.0\n"
"Report-Msgid-Bugs-To: \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" "PO-Revision-Date: 2018-02-04 01:03+0100\n"
"Last-Translator: Khaganat <assoc@khaganat.net>\n" "Last-Translator: Khaganat <assoc@khaganat.net>\n"
"Language-Team: Khaganat <assoc@khaganat.net>\n" "Language-Team: Khaganat <assoc@khaganat.net>\n"
@ -54,19 +54,17 @@ msgstr ""
msgid "users" msgid "users"
msgstr "" msgstr ""
#: templates/neluser/activate_done.html:4 templates/neluser/login.html:13 #: templates/neluser/activate_done.html:4 templates/neluser/login.html:15
#: templates/neluser/register.html:4 templates/neluser/register.html:11 #: templates/neluser/register.html:5 templates/neluser/register.html:13
#: templates/neluser/register_done.html:4
msgid "register" msgid "register"
msgstr "" msgstr ""
#: templates/neluser/activate_done.html:9 #: templates/neluser/activate_done.html:8
msgid "account_activated" msgid "account_activated"
msgstr "Your account has been activated." msgstr "Your account has been activated."
#: templates/neluser/activate_done.html:10 templates/neluser/login.html:4 #: templates/neluser/activate_done.html:9 templates/neluser/login.html:5
#: templates/neluser/login.html:12 #: templates/neluser/login.html:13 templates/neluser/password_reset_done.html:9
#: templates/neluser/password_reset_done.html:10
msgid "login" msgid "login"
msgstr "" msgstr ""
@ -106,62 +104,18 @@ msgstr ""
msgid "forgotten_password" msgid "forgotten_password"
msgstr "forgotten password" msgstr "forgotten password"
#: templates/neluser/nsfw.html:4 templates/neluser/nsfw.html:8 #: templates/neluser/password_reset.html:5
msgid "NSFW content" #: templates/neluser/password_reset_confirm.html:5
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_done.html:4 #: templates/neluser/password_reset_done.html:4
#: templates/neluser/password_reset_email_sent.html:4 #: templates/neluser/password_reset_email_sent.html:4
msgid "password_reset" msgid "password_reset"
msgstr "password reset" msgstr "password reset"
#: templates/neluser/password_reset.html:11 #: templates/neluser/password_reset.html:12
msgid "reset_my_password" msgid "reset_my_password"
msgstr "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" msgid "set_new_password"
msgstr "Please set a new password" msgstr "Please set a new password"
@ -173,7 +127,7 @@ msgstr "change my password"
msgid "reset_password_invalid_link" msgid "reset_password_invalid_link"
msgstr "Sorry, we are unable to reset your password." 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" msgid "password_reset_success"
msgstr "Your password has been changed." 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 " "An email has been sent to your address. Please follow the link given in this "
"email to reset your password." "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 #: templates/neluser/password_reset_email_subject.txt:2
#, python-format #, python-format
msgid "Password reset on %(site_name)s" msgid "Password reset on %(site_name)s"
msgstr "" msgstr ""
#: templates/neluser/register_done.html:9 #: templates/neluser/register_done.html:4
msgid "almost_there" msgid "almost_there"
msgstr "Almost there…" msgstr "Almost there…"
#: templates/neluser/register_done.html:10 #: templates/neluser/register_done.html:8
msgid "activate_your_account" msgid "activate_your_account"
msgstr "" msgstr ""
"You now need to activate your account. Please click on the link that has " "You now need to activate your account. Please click on the link that has "
"been sent to your email address." "been sent to your email address."
#: templates/neluser/register_done.html:11 #: templates/neluser/register_done.html:9
msgid "take_me_home" msgid "take_me_home"
msgstr "Take me home" msgstr "Take me home"

View file

@ -2,7 +2,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: 1.0\n" "Project-Id-Version: 1.0\n"
"Report-Msgid-Bugs-To: \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" "PO-Revision-Date: 2018-02-04 01:03+0100\n"
"Last-Translator: Khaganat <assoc@khaganat.net>\n" "Last-Translator: Khaganat <assoc@khaganat.net>\n"
"Language-Team: Khaganat <assoc@khaganat.net>\n" "Language-Team: Khaganat <assoc@khaganat.net>\n"
@ -56,19 +56,17 @@ msgstr "utilisateur"
msgid "users" msgid "users"
msgstr "utilisateurs" msgstr "utilisateurs"
#: templates/neluser/activate_done.html:4 templates/neluser/login.html:13 #: templates/neluser/activate_done.html:4 templates/neluser/login.html:15
#: templates/neluser/register.html:4 templates/neluser/register.html:11 #: templates/neluser/register.html:5 templates/neluser/register.html:13
#: templates/neluser/register_done.html:4
msgid "register" msgid "register"
msgstr "inscription" msgstr "inscription"
#: templates/neluser/activate_done.html:9 #: templates/neluser/activate_done.html:8
msgid "account_activated" msgid "account_activated"
msgstr "compte activé" msgstr "compte activé"
#: templates/neluser/activate_done.html:10 templates/neluser/login.html:4 #: templates/neluser/activate_done.html:9 templates/neluser/login.html:5
#: templates/neluser/login.html:12 #: templates/neluser/login.html:13 templates/neluser/password_reset_done.html:9
#: templates/neluser/password_reset_done.html:10
msgid "login" msgid "login"
msgstr "connexion" msgstr "connexion"
@ -108,67 +106,18 @@ msgstr "Activation de compte sur %(site_name)s"
msgid "forgotten_password" msgid "forgotten_password"
msgstr "mot de passe oublié" msgstr "mot de passe oublié"
#: templates/neluser/nsfw.html:4 templates/neluser/nsfw.html:8 #: templates/neluser/password_reset.html:5
msgid "NSFW content" #: templates/neluser/password_reset_confirm.html:5
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_done.html:4 #: templates/neluser/password_reset_done.html:4
#: templates/neluser/password_reset_email_sent.html:4 #: templates/neluser/password_reset_email_sent.html:4
msgid "password_reset" msgid "password_reset"
msgstr "réinitialisation du mot de passe" msgstr "réinitialisation du mot de passe"
#: templates/neluser/password_reset.html:11 #: templates/neluser/password_reset.html:12
msgid "reset_my_password" msgid "reset_my_password"
msgstr "réinitialiser mon mot de passe" 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" msgid "set_new_password"
msgstr "Veuillez indiquer un nouveau mot de passe" msgstr "Veuillez indiquer un nouveau mot de passe"
@ -180,7 +129,7 @@ msgstr "Modifier mon mot de passe"
msgid "reset_password_invalid_link" msgid "reset_password_invalid_link"
msgstr "Désolé, nous ne sommes pas en mesure de modifier votre mot de passe." 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" msgid "password_reset_success"
msgstr "Votre mot de passe a été modifié." msgstr "Votre mot de passe a été modifié."
@ -206,21 +155,62 @@ msgstr ""
"Un message a été envoyé sur votre messagerie électronique. Veuillez suivre " "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." "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 #: templates/neluser/password_reset_email_subject.txt:2
#, python-format #, python-format
msgid "Password reset on %(site_name)s" msgid "Password reset on %(site_name)s"
msgstr "Réinitialisation du mot de passe sur %(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" msgid "almost_there"
msgstr "Vous y êtes presque…" msgstr "Vous y êtes presque…"
#: templates/neluser/register_done.html:10 #: templates/neluser/register_done.html:8
msgid "activate_your_account" msgid "activate_your_account"
msgstr "" msgstr ""
"Vous devez maintenant activer votre compte. Veuillez cliquer sur le lien qui " "Vous devez maintenant activer votre compte. Veuillez cliquer sur le lien qui "
"vient d'être envoyé sur votre adresse électronique." "vient d'être envoyé sur votre adresse électronique."
#: templates/neluser/register_done.html:11 #: templates/neluser/register_done.html:9
msgid "take_me_home" msgid "take_me_home"
msgstr "Retour à l'accueil" 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"

View file

@ -1,7 +1,6 @@
from django.contrib.auth import views as auth_views from django.contrib.auth import views as auth_views
from django.urls import reverse_lazy, path from django.urls import reverse_lazy, path
from . import views from . import views
from . import nsfw
urlpatterns = [ urlpatterns = [
@ -62,9 +61,4 @@ urlpatterns = [
), ),
name='password_reset_complete' name='password_reset_complete'
), ),
# NSFW
path('nsfw/', nsfw.warn_view, name='nsfw'),
path('nsfw/enable/<max_age>/', nsfw.enable_view, name='enable_nsfw'),
path('nsfw/disable/', nsfw.disable_view, name='disable_nsfw'),
] ]

0
nsfw/__init__.py Normal file
View file

3
nsfw/admin.py Normal file
View file

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

5
nsfw/apps.py Normal file
View file

@ -0,0 +1,5 @@
from django.apps import AppConfig
class NsfwConfig(AppConfig):
name = 'nsfw'

View file

@ -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 <assoc@khaganat.net>\n"
"Language-Team: Khaganat <assoc@khaganat.net>\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 ""

View file

@ -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 <assoc@khaganat.net>\n"
"Language-Team: Khaganat <assoc@khaganat.net>\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"

View file

3
nsfw/models.py Normal file
View file

@ -0,0 +1,3 @@
from django.db import models
# Create your models here.

View file

@ -1,9 +1,4 @@
{% extends "khaganat/base.html" %}
{% load i18n %} {% load i18n %}
{% block title %}{% trans "NSFW content" %}{% endblock %}
{% block content %}
<article class="message is-warning"> <article class="message is-warning">
<div class="message-header"> <div class="message-header">
<p>{% trans "NSFW content" %}</p> <p>{% trans "NSFW content" %}</p>
@ -12,7 +7,11 @@
<p>{% trans "The content you were about to see is flagged as sensitive and therefore cannot be seen while the safe mode is activated." %}</p> <p>{% trans "The content you were about to see is flagged as sensitive and therefore cannot be seen while the safe mode is activated." %}</p>
<div> <div>
<p> <p>
{% if prev_url %}
<a class="button is-link" href="{{ prev_url }}" role="button">{% trans "Go back" %}</a>
{% elif go_home %}
<a class="button is-link" href="{% url "index" %}" role="button">{% trans "Go back home" %}</a> <a class="button is-link" href="{% url "index" %}" role="button">{% trans "Go back home" %}</a>
{% endif %}
<a class="button is-danger" href="{% url "enable_nsfw" "0" %}?next={{ next_url }}" role="button">{% trans "Permanently disable safe mode" %}</a> <a class="button is-danger" href="{% url "enable_nsfw" "0" %}?next={{ next_url }}" role="button">{% trans "Permanently disable safe mode" %}</a>
</p> </p>
<p> <p>
@ -24,4 +23,3 @@
</div> </div>
</div> </div>
</article> </article>
{% endblock %}

View file

@ -1,3 +1,3 @@
{% load i18n %} {% load i18n %}
{% trans "This page contains sensitive content which is displayed because you disabled the safe mode." %}<br> {% trans "This page contains sensitive content which is displayed because you disabled the safe mode." %}<br>
<a href="{% url 'disable_nsfw' %}">{% trans "Enable safe mode" %}</a> <a href="{% url 'disable_nsfw' %}{% if next_url %}?next={{ next_url }}{% endif %}">{% trans "Enable safe mode" %}</a>

View file

@ -0,0 +1,8 @@
{% extends "khaganat/base.html" %}
{% load i18n %}
{% block title %}{% trans "NSFW content" %}{% endblock %}
{% block content %}
{% include "nsfw/alert.html" %}
{% endblock %}

3
nsfw/tests.py Normal file
View file

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

10
nsfw/urls.py Normal file
View file

@ -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/<max_age>/', views.enable_view, name='enable_nsfw'),
path('disable/', views.disable_view, name='disable_nsfw'),
]

View file

@ -21,6 +21,8 @@ def disable_view(request):
if isinstance(request.user, NelUser): if isinstance(request.user, NelUser):
request.user.nsfw_allowed = False request.user.nsfw_allowed = False
request.user.save() request.user.save()
next_url = QueryDict(request.META.get('QUERY_STRING')).get('next')
if not is_link_legit(next_url):
next_url = reverse('index') next_url = reverse('index')
response = HttpResponseRedirect(next_url) response = HttpResponseRedirect(next_url)
response.delete_cookie(settings.KHAGANAT_NSFW_NAME) response.delete_cookie(settings.KHAGANAT_NSFW_NAME)
@ -32,9 +34,9 @@ def enable_view(request, max_age):
max_age = int(max_age) or None max_age = int(max_age) or None
except ValueError: except ValueError:
max_age = None 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): if not is_link_legit(next_url):
next_url = '/' next_url = reverse('index')
response = HttpResponseRedirect(next_url) response = HttpResponseRedirect(next_url)
if isinstance(request.user, NelUser) and not max_age: if isinstance(request.user, NelUser) and not max_age:
request.user.nsfw_allowed = True request.user.nsfw_allowed = True
@ -52,11 +54,26 @@ def warn_view(request):
next_url = QueryDict(request.META.get('QUERY_STRING')).get('next') or '/' next_url = QueryDict(request.META.get('QUERY_STRING')).get('next') or '/'
if not is_link_legit(next_url): if not is_link_legit(next_url):
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 = { context = {
'prev_url': prev_url,
'go_home': True,
'next_url': next_url, 'next_url': next_url,
'is_authenticated': request.user.is_authenticated, '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): def redirect(request):
@ -66,6 +83,9 @@ def redirect(request):
) )
return HttpResponseRedirect(dest) return HttpResponseRedirect(dest)
def alert(request): def alert(request, next_url=None):
msg = render_to_string('neluser/nsfw_message.html') context = {
'next_url': next_url,
}
msg = render_to_string('nsfw/disabled_alert.html', context=context)
messages.info(request, msg, extra_tags='safe') messages.info(request, msg, extra_tags='safe')

View file

@ -2,7 +2,7 @@ from django.http import HttpResponseRedirect, Http404
from django.utils.translation import get_language from django.utils.translation import get_language
from django.views import generic from django.views import generic
from django.urls import reverse from django.urls import reverse
from neluser import nsfw from nsfw import views as nsfw
from .models import Page, PageContent from .models import Page, PageContent