Commit 50610ea2 authored by Behr, Svenja's avatar Behr, Svenja
Browse files

- Unnötige Importe entfernt

- Magic Number in Konstante
- CamelCase ersetzt
parent aa9da133
from time import timezone
import uuid
from ckeditor.fields import RichTextField
from ckeditor_uploader.fields import RichTextUploadingField
from django.db import models
from datetime import datetime
......@@ -15,6 +13,8 @@ BLOG_STATE_USER_ONLY = 4
def unique_identifier():
""" Creates a new unique identifier.
Must be wrapped in a function, or else it is always the same."""
return uuid.uuid4()
......
......@@ -11,6 +11,8 @@ from django.contrib.auth import authenticate, login, logout
from .forms import CommentForm
from .models import *
# How many of the blogs should stay the same?
NEWEST_BLOGS_AT_BEGINNING = 3
def get_all_blogs(request):
""" Get all blog articles.
......@@ -34,14 +36,13 @@ def all_blogs(request):
""" Show all blog articles in an overview list.
Will exclude those which should be hidden in this list (e.g. impress)
"""
# Exclude those with status hidden from the overall list
query = f'status & {BLOG_STATE_HIDE_FROM_LIST} <> {BLOG_STATE_HIDE_FROM_LIST}'
allblogs = get_all_blogs(request)
# split into subqueries, turn into lists for shuffling, then being chained
if allblogs.count() > 3:
last_three_blogs = allblogs[:3]
all_blogs_except_last_three_in_random_order = list(allblogs[3:])
if allblogs.count() > NEWEST_BLOGS_AT_BEGINNING:
last_three_blogs = allblogs[:NEWEST_BLOGS_AT_BEGINNING]
all_blogs_except_last_three_in_random_order = list(allblogs[NEWEST_BLOGS_AT_BEGINNING:])
shuffle(all_blogs_except_last_three_in_random_order)
allblogs = chain(last_three_blogs, all_blogs_except_last_three_in_random_order)
......@@ -55,12 +56,12 @@ def detail(request, slug):
"""
blogs = get_all_blogs(request)
blogResult = Blog.objects.filter(slug=slug)
blog_result = Blog.objects.filter(slug=slug)
if blogResult.count() == 0:
if blog_result.count() == 0:
raise Http404("Url does not exist")
blog = blogResult.first()
blog = blog_result.first()
# Check if the Blog needs authentication
if blog.needs_authentication():
......
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