diff --git a/MEIM_Lsg/urls.py b/MEIM_Lsg/urls.py index 335a9cc..73c97f0 100644 --- a/MEIM_Lsg/urls.py +++ b/MEIM_Lsg/urls.py @@ -19,6 +19,7 @@ from . import views urlpatterns = [ path('admin/', admin.site.urls), - path('', views.index, name='posts'), - path('posts/', include('posts.urls'), name='posts') + path('', views.index), + path('posts/', include('posts.urls')), + path('accounts/', include('django.contrib.auth.urls')) ] diff --git a/posts/views.py b/posts/views.py index acceee4..b56ffa9 100644 --- a/posts/views.py +++ b/posts/views.py @@ -3,7 +3,8 @@ from datetime import timedelta from django.utils import timezone from posts.models import Notice 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. @@ -21,6 +22,7 @@ def home(request, value=""): } return render(request, 'index.html', context) +@login_required def new(request): if request.method == "POST": form = NoticeForm(request.POST) @@ -34,6 +36,7 @@ def new(request): context = {'form': NoticeForm()} return render(request, 'edit.html', context) +@staff_member_required def delete(request, value): notice = Notice.objects.get(id = value) notice.delete() diff --git a/templates/base.html b/templates/base.html index 72189cd..87f4ef0 100644 --- a/templates/base.html +++ b/templates/base.html @@ -17,7 +17,7 @@ {% block content %} {% endblock %} diff --git a/templates/index.html b/templates/index.html index c724584..505392b 100644 --- a/templates/index.html +++ b/templates/index.html @@ -7,8 +7,12 @@

{{ notice.notice_title }}

{{notice.notice_text}}

-

Nachricht löschen

+ {% if user.is_staff %} +

Nachricht löschen

+ {% endif %}
{% endfor %} -

Neue Nachricht

+ {% if user.is_authenticated %} +

Neue Nachricht

+ {% endif %} {% endblock content %} \ No newline at end of file diff --git a/templates/registration/login.html b/templates/registration/login.html new file mode 100644 index 0000000..4e8221b --- /dev/null +++ b/templates/registration/login.html @@ -0,0 +1,12 @@ +{% extends 'base.html' %} +{% block title %} Login {% endblock %} +{% block content %} +
+ {% csrf_token %} + Benutzername: {{ form.username }} +
Passwort: {{ form.password }}
+ + +
+
+{% endblock %} \ No newline at end of file