Solution of 07
This commit is contained in:
parent
b4ac907a6a
commit
5d99369516
@ -19,6 +19,7 @@ from . import views
|
|||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('admin/', admin.site.urls),
|
path('admin/', admin.site.urls),
|
||||||
path('', views.index, name='posts'),
|
path('', views.index),
|
||||||
path('posts/', include('posts.urls'), name='posts')
|
path('posts/', include('posts.urls')),
|
||||||
|
path('accounts/', include('django.contrib.auth.urls'))
|
||||||
]
|
]
|
||||||
|
@ -3,7 +3,8 @@ from datetime import timedelta
|
|||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from posts.models import Notice
|
from posts.models import Notice
|
||||||
from posts.forms import NoticeForm
|
from posts.forms import NoticeForm
|
||||||
from django.http import HttpResponse
|
from django.contrib.auth.decorators import login_required
|
||||||
|
from django.contrib.admin.views.decorators import staff_member_required
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
|
|
||||||
|
|
||||||
@ -21,6 +22,7 @@ def home(request, value=""):
|
|||||||
}
|
}
|
||||||
return render(request, 'index.html', context)
|
return render(request, 'index.html', context)
|
||||||
|
|
||||||
|
@login_required
|
||||||
def new(request):
|
def new(request):
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
form = NoticeForm(request.POST)
|
form = NoticeForm(request.POST)
|
||||||
@ -34,6 +36,7 @@ def new(request):
|
|||||||
context = {'form': NoticeForm()}
|
context = {'form': NoticeForm()}
|
||||||
return render(request, 'edit.html', context)
|
return render(request, 'edit.html', context)
|
||||||
|
|
||||||
|
@staff_member_required
|
||||||
def delete(request, value):
|
def delete(request, value):
|
||||||
notice = Notice.objects.get(id = value)
|
notice = Notice.objects.get(id = value)
|
||||||
notice.delete()
|
notice.delete()
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
<span class="navbar-toggler-icon"></span>
|
<span class="navbar-toggler-icon"></span>
|
||||||
</button>
|
</button>
|
||||||
<div class="collapse navbar-collapse" id="navbarNav">
|
<div class="collapse navbar-collapse" id="navbarNav">
|
||||||
<ul class="navbar-nav">
|
<ul class="navbar-nav mr-auto mt-2 mt-lg-0">
|
||||||
<li class="nav-item active">
|
<li class="nav-item active">
|
||||||
<a class="nav-link" href="/posts">Posts</a>
|
<a class="nav-link" href="/posts">Posts</a>
|
||||||
</li>
|
</li>
|
||||||
@ -28,6 +28,18 @@
|
|||||||
<a class="nav-link" href="https://www.google.com/">Google</a>
|
<a class="nav-link" href="https://www.google.com/">Google</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
<ul class="navbar-nav">
|
||||||
|
{% if request.user.is_authenticated %}
|
||||||
|
<span class="navbar-text"> Willkommen {{ request.user.username }}! </span>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="{% url 'logout' %}?next=/posts">Abmelden</a>
|
||||||
|
</li>
|
||||||
|
{% else %}
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="{% url 'login' %}?next=/posts">Anmelden</a>
|
||||||
|
</li>
|
||||||
|
{% endif %}
|
||||||
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
{% block content %} {% endblock %}
|
{% block content %} {% endblock %}
|
||||||
|
@ -7,8 +7,12 @@
|
|||||||
<div class="jumbotron">
|
<div class="jumbotron">
|
||||||
<h1 class="display-6">{{ notice.notice_title }}</h1>
|
<h1 class="display-6">{{ notice.notice_title }}</h1>
|
||||||
<p class="lead">{{notice.notice_text}}</p>
|
<p class="lead">{{notice.notice_text}}</p>
|
||||||
|
{% if user.is_staff %}
|
||||||
<p><a href="{% url 'delete' notice.id %}" class="btn btn-info" role="button">Nachricht löschen</a></p>
|
<p><a href="{% url 'delete' notice.id %}" class="btn btn-info" role="button">Nachricht löschen</a></p>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
{% if user.is_authenticated %}
|
||||||
<p><a href="{% url 'new' %}" class="btn btn-info" role="button">Neue Nachricht</a></p>
|
<p><a href="{% url 'new' %}" class="btn btn-info" role="button">Neue Nachricht</a></p>
|
||||||
|
{% endif %}
|
||||||
{% endblock content %}
|
{% endblock content %}
|
12
templates/registration/login.html
Normal file
12
templates/registration/login.html
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
{% extends 'base.html' %}
|
||||||
|
{% block title %} Login {% endblock %}
|
||||||
|
{% block content %}
|
||||||
|
<div class="container"><form method="post" action="{% url 'login' %}">
|
||||||
|
{% csrf_token %}
|
||||||
|
Benutzername: {{ form.username }}
|
||||||
|
<br>Passwort: {{ form.password }} <br>
|
||||||
|
<button type="submit" class="btn btn-default">Anmelden</button>
|
||||||
|
<input type="hidden" name="next" value="{{ next }}" />
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
Loading…
x
Reference in New Issue
Block a user