Commit 2fe2eff1 authored by Falk, Dennis Nikolas's avatar Falk, Dennis Nikolas
Browse files

Settings.py local Einstellung auf 'de-de' gesetzt. Navbar überarbeitet und...

Settings.py local Einstellung auf 'de-de' gesetzt. Navbar überarbeitet und Artikel Archiv hinzugefügt. Status 4 und 6 für angemeldete User verwendet.
parent ac6a3686
......@@ -11,6 +11,8 @@ 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
# Create your models here.
......
......@@ -28,9 +28,11 @@
Blog Archiv
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
{% for blog in blogs %}
<a class="dropdown-item" href="{{ blog.slug }}">{{ blog.created }}: <strong>{{ blog.title }}</strong></a>
{% endfor %}
</div>
</li>
</ul>
......
......@@ -11,18 +11,31 @@ from .models import *
from django.views.generic import DetailView
def get_all_blogs(request):
""" Get all blog articles.
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:
query = f'status & {BLOG_STATE_HIDE_FROM_LIST} <> {BLOG_STATE_HIDE_FROM_LIST}'
else:
# Exclude those with status hidden from the overall list
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}'
blogs = Blog.objects.extra(where=[query]).order_by('created')
return blogs
# Create your views here.
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}'
if request.user.is_authenticated:
blogs = Blog.objects.order_by('created')
else:
blogs = Blog.objects.extra(where=[query]).order_by('created')
blogs = get_all_blogs(request)
return render(request, 'blog/all_blogs.html', {'blogs': blogs})
......@@ -31,6 +44,9 @@ def detail(request, slug):
""" Shows one complete article, based on the slug (url)
If comments are allowed, they will be shown as well (uses an extended template)
"""
blogs = get_all_blogs(request)
blogResult = Blog.objects.filter(slug=slug)
print(blogResult)
if blogResult.count() == 0:
......@@ -44,9 +60,9 @@ def detail(request, slug):
form = CommentForm(initial={'related_blog': blog.id})
# render with comments
return render(request, 'blog/detail_with_comments.html',
{'blog': blog, 'comments': comments, 'comment_form': form})
{'blog': blog, 'comments': comments, 'comment_form': form, 'blogs': blogs})
return render(request, 'blog/detail.html', {'blog': blog})
return render(request, 'blog/detail.html', {'blog': blog, 'blogs': blogs})
def save_comment(request):
......@@ -71,6 +87,9 @@ def save_comment(request):
def user_login(request):
blogs = get_all_blogs(request)
if request.method == 'POST':
# Process the POST Data
username = request.POST['username']
......@@ -79,17 +98,16 @@ def user_login(request):
user = authenticate(username=username, password=password)
if user is not None:
login(request, user)
blogs = Blog.objects.order_by('created')
return render(request, 'blog/all_blogs.html', {'blogs': blogs})
return redirect(reverse_lazy('blog:all_blogs'))
else:
# Throw Error if credentials are wrong
return render(request, 'blog/login.html', {'error_message': 'Falscher Username und / oder Passwort.'})
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')
return render(request, 'blog/login.html', {'blogs': blogs})
def user_logout(request):
logout(request)
return all_blogs(request)
\ No newline at end of file
return redirect(reverse_lazy('blog:all_blogs'))
\ No newline at end of file
......@@ -109,7 +109,7 @@ AUTH_PASSWORD_VALIDATORS = [
# Internationalization
# https://docs.djangoproject.com/en/3.0/topics/i18n/
LANGUAGE_CODE = 'en-us'
LANGUAGE_CODE = 'de-de'
TIME_ZONE = 'UTC'
......
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