Allow pages to be marked as NSFW

This commit is contained in:
Rodolphe Breard 2018-06-02 16:03:13 +02:00
parent b444fe8c49
commit bfe37bedea
3 changed files with 26 additions and 0 deletions

View file

@ -0,0 +1,18 @@
# Generated by Django 2.0.6 on 2018-06-02 13:55
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('pages', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='page',
name='is_nsfw',
field=models.BooleanField(default=False),
),
]

View file

@ -6,6 +6,7 @@ import markdown
class Page(models.Model): class Page(models.Model):
slug = models.CharField(max_length=200, unique=True) slug = models.CharField(max_length=200, unique=True)
default = models.BooleanField(default=False) default = models.BooleanField(default=False)
is_nsfw = models.BooleanField(default=False)
def __str__(self): def __str__(self):
return self.slug return self.slug

View file

@ -2,6 +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 .models import Page, PageContent from .models import Page, PageContent
@ -15,6 +16,12 @@ class PageView(generic.DetailView):
context_object_name = 'page' context_object_name = 'page'
template_name = 'pages/page.html' template_name = 'pages/page.html'
def dispatch(self, request, *args, **kwargs):
if not nsfw.is_nsfw_allowed(request):
if self.get_object().page.is_nsfw:
return nsfw.redirect(request)
return super().dispatch(request, *args, **kwargs)
def get_object(self): def get_object(self):
obj = PageContent.objects.filter( obj = PageContent.objects.filter(
language=get_language(), language=get_language(),