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

all_blogs Ansicht angepasst. Wenn ein User eingeloggt ist, dann werden alle Blog-Artikel angezeigt.

parent bd18941f
......@@ -18,7 +18,11 @@ def all_blogs(request):
"""
# Exclude those with status hidden from the overall list
query = f'status & {BLOG_STATE_HIDE_FROM_LIST} <> {BLOG_STATE_HIDE_FROM_LIST}'
blogs = Blog.objects.extra(where=[query]).order_by('created')
if request.user.is_authenticated:
blogs = Blog.objects.order_by('created')
else:
blogs = Blog.objects.extra(where=[query]).order_by('created')
return render(request, 'blog/all_blogs.html', {'blogs': blogs})
......@@ -68,22 +72,21 @@ def save_comment(request):
def user_login(request):
if request.method == 'POST':
# Process the request if posted data are available
# Process the POST Data
username = request.POST['username']
password = request.POST['password']
# Check username and password combination if correct
# Check username and password
user = authenticate(username=username, password=password)
if user is not None:
# Save session as cookie to login the user
login(request, user)
# Success, now let's login the user.
# return render(request, 'blog/all_blogs.html', {'blogs': blogs})
return all_blogs(request)
blogs = Blog.objects.order_by('created')
return render(request, 'blog/all_blogs.html', {'blogs': blogs})
else:
# Incorrect credentials, let's throw an error to the screen.
# Throw Error if credentials are wrong
return render(request, 'blog/login.html', {'error_message': 'Falscher Username und / oder Passwort.'})
else:
# No post data availabe, let's just show the page to the user.
# No POST data -> then show the page again
return render(request, 'blog/login.html')
......
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