Update for home use
This commit is contained in:
parent
72c6a3762d
commit
f2845486df
@ -4,5 +4,5 @@ from . import views
|
||||
urlpatterns = [
|
||||
path('edit', views.new, name='new'),
|
||||
path('', views.index, name = 'index'),
|
||||
path('delete/int:id/', views.delete, name ='delete')
|
||||
path('delete/<int:deleteId>/', views.delete, name ='delete')
|
||||
]
|
@ -1,5 +1,7 @@
|
||||
from django.shortcuts import render, redirect, HttpResponse
|
||||
from django.utils import timezone
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.contrib.admin.views.decorators import staff_member_required
|
||||
|
||||
from .forms import NoticeForm
|
||||
from .models import Notice
|
||||
@ -12,6 +14,7 @@ def index(request):
|
||||
context = { "notices": notices }
|
||||
return render(request, 'posts/index.html', context)
|
||||
|
||||
@login_required
|
||||
def new(request):
|
||||
if request.method == "POST":
|
||||
form = NoticeForm(request.POST)
|
||||
@ -25,7 +28,10 @@ def new(request):
|
||||
context = {'form': NoticeForm()}
|
||||
return render(request, 'posts/edit.html', context)
|
||||
|
||||
|
||||
def delete(request):
|
||||
notices = Notice.objects.all()
|
||||
notices.filter()
|
||||
@staff_member_required
|
||||
def delete(request, deleteId=None):
|
||||
if deleteId != None:
|
||||
delNotice = Notice.objects.get(id=deleteId)
|
||||
if delNotice != None:
|
||||
delNotice.delete(())
|
||||
return redirect('index')
|
@ -5,12 +5,21 @@
|
||||
{% endblock %}
|
||||
|
||||
{% block body %}
|
||||
|
||||
<div>
|
||||
{% if user.is_authenticated %}
|
||||
<p><a href="{% url 'logout' %}?next=/posts" class="btn btn-warning">Abmelden</a></p>
|
||||
{% endif %}
|
||||
{% if not user.is_authenticated %}
|
||||
<p><a href="{% url 'login' %}?next=/posts" class="btn btn-warning">Anmelden</a></p>
|
||||
{% endif %}
|
||||
</div>
|
||||
<div>
|
||||
{% for notice in notices %}
|
||||
<h3> {{ notice.notice_title }}</h3>
|
||||
<p> {{ notice.notice_text }}</p>
|
||||
<p><a class="btn btn-info" role="button"> href={% url 'delete' id=n %} Löschen </a></p>
|
||||
{% if user.is_staff %}
|
||||
<p><a href="{% url 'delete' deleteId=notice.id %}" class="btn btn-danger"> Meldung löschen </a></p>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</div>
|
||||
<p><a href="{% url 'new' %}" class="btn btn-info" role="button">Neue Nachricht</a></p>
|
||||
|
21
templates/registration/login.html
Normal file
21
templates/registration/login.html
Normal file
@ -0,0 +1,21 @@
|
||||
{% extends 'base.html' %}
|
||||
|
||||
{% block title %}
|
||||
Login
|
||||
{% endblock %}
|
||||
|
||||
{% block body %}
|
||||
|
||||
<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 %}
|
@ -19,4 +19,5 @@ from django.urls import path, include
|
||||
urlpatterns = [
|
||||
path('posts/', include('posts.urls')),
|
||||
path('admin/', admin.site.urls),
|
||||
path('accounts/', include('django.contrib.auth.urls'))
|
||||
]
|
||||
|
Loading…
x
Reference in New Issue
Block a user