Commit aa9da133 authored by Behr, Svenja's avatar Behr, Svenja
Browse files

- Unnötigen Status entfernt für Binary Felder

parent 99b7e3f1
......@@ -12,7 +12,6 @@ from django.utils.text import slugify
BLOG_STATE_HIDE_FROM_LIST = 1
BLOG_STATE_CAN_HAVE_COMMENTS = 2
BLOG_STATE_USER_ONLY = 4
BLOG_STATE_CAN_HAVE_COMMENTS_AND_USER_ONLY = 6
def unique_identifier():
......@@ -54,6 +53,10 @@ class Blog(models.Model):
""" Returns true or false if this blog is open for comments """
return self.status & BLOG_STATE_CAN_HAVE_COMMENTS == BLOG_STATE_CAN_HAVE_COMMENTS
def needs_authentication(self):
""" Returns true if this blog needs authentication to be viewed"""
return self.status & BLOG_STATE_USER_ONLY == BLOG_STATE_USER_ONLY
def get_absolute_url(self):
# Slugify the combination of role and company_name as these may contain
# whitespace or other characters that are not permitted in urls.
......@@ -61,13 +64,6 @@ class Blog(models.Model):
# "blog-detail" refers to url, key word argument
return reverse("blog-detail", kwargs={'slug': slug})
def needs_authentication(self):
"""Returns true if this blog needs authentication to be viewed"""
if self.status & BLOG_STATE_USER_ONLY == BLOG_STATE_USER_ONLY or self.status & BLOG_STATE_CAN_HAVE_COMMENTS_AND_USER_ONLY == BLOG_STATE_CAN_HAVE_COMMENTS_AND_USER_ONLY:
return True
else:
return False
class Comment(models.Model):
""" Comment class
......
......@@ -6,7 +6,6 @@ from django.urls import reverse_lazy
from itertools import chain
from random import shuffle
from django.contrib.auth import authenticate, login, logout
from .forms import CommentForm
......@@ -18,15 +17,13 @@ def get_all_blogs(request):
Will exclude those which should be hidden in this list (e.g. impress)
Authenticated user get articles with status 4 and 6 extra.
"""
if request.user.is_authenticated:
# Exclude those with status hidden from the overall list, but show everything else
query = f'status & {BLOG_STATE_HIDE_FROM_LIST} <> {BLOG_STATE_HIDE_FROM_LIST}'
else:
# Exclude those with status hidden from the overall list and the user only blogs
query = f'status & {BLOG_STATE_HIDE_FROM_LIST}<>{BLOG_STATE_HIDE_FROM_LIST}' \
f' AND status & {BLOG_STATE_USER_ONLY}<>{BLOG_STATE_USER_ONLY}' \
f' AND status & {BLOG_STATE_CAN_HAVE_COMMENTS_AND_USER_ONLY}' \
f'<>{BLOG_STATE_CAN_HAVE_COMMENTS_AND_USER_ONLY}'
# Exclude those with status hidden from the overall list, but show everything else
query = f'status & {BLOG_STATE_HIDE_FROM_LIST} <> {BLOG_STATE_HIDE_FROM_LIST}'
# if not logged in, exclude the user only entries as well
if not request.user.is_authenticated:
query += f' AND status & {BLOG_STATE_USER_ONLY} <> {BLOG_STATE_USER_ONLY}'
blogs = Blog.objects.extra(where=[query]).order_by('-created')
return blogs
......@@ -120,7 +117,8 @@ def user_login(request):
else:
# Throw Error if credentials are wrong
return render(request, 'blog/login.html', {'error_message': 'Falscher Username und / oder Passwort.', 'blogs': blogs})
return render(request, 'blog/login.html',
{'error_message': 'Falscher Username und / oder Passwort.', 'blogs': blogs})
else:
# No POST data -> then show the page again
return render(request, 'blog/login.html', {'blogs': blogs})
......@@ -130,4 +128,4 @@ def user_logout(request):
"""User logout
"""
logout(request)
return redirect(reverse_lazy('blog:all_blogs'))
\ No newline at end of file
return redirect(reverse_lazy('blog:all_blogs'))
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment