Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Behr, Svenja
Django_Blog
Commits
b904b9b7
Commit
b904b9b7
authored
Jun 23, 2020
by
Falk, Dennis Nikolas
Browse files
all_blogs Ansicht angepasst. Wenn ein User eingeloggt ist, dann werden alle Blog-Artikel angezeigt.
parent
bd18941f
Changes
1
Hide whitespace changes
Inline
Side-by-side
blog/views.py
View file @
b904b9b7
...
...
@@ -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'
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment