Allow pages to be marked as NSFW
This commit is contained in:
parent
b444fe8c49
commit
bfe37bedea
3 changed files with 26 additions and 0 deletions
18
pages/migrations/0002_page_is_nsfw.py
Normal file
18
pages/migrations/0002_page_is_nsfw.py
Normal 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),
|
||||
),
|
||||
]
|
|
@ -6,6 +6,7 @@ import markdown
|
|||
class Page(models.Model):
|
||||
slug = models.CharField(max_length=200, unique=True)
|
||||
default = models.BooleanField(default=False)
|
||||
is_nsfw = models.BooleanField(default=False)
|
||||
|
||||
def __str__(self):
|
||||
return self.slug
|
||||
|
|
|
@ -2,6 +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 .models import Page, PageContent
|
||||
|
||||
|
||||
|
@ -15,6 +16,12 @@ class PageView(generic.DetailView):
|
|||
context_object_name = 'page'
|
||||
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):
|
||||
obj = PageContent.objects.filter(
|
||||
language=get_language(),
|
||||
|
|
Loading…
Reference in a new issue