Browse Source

Update for home use

master
Lukas Weber 3 years ago
parent
commit
f2845486df
5 changed files with 44 additions and 7 deletions
  1. 1
    1
      posts/urls.py
  2. 10
    4
      posts/views.py
  3. 11
    2
      templates/posts/index.html
  4. 21
    0
      templates/registration/login.html
  5. 1
    0
      webengdjango/urls.py

+ 1
- 1
posts/urls.py View File

@@ -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')
]

+ 10
- 4
posts/views.py View File

@@ -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')

+ 11
- 2
templates/posts/index.html View File

@@ -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
- 0
templates/registration/login.html View 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 %}

+ 1
- 0
webengdjango/urls.py View File

@@ -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…
Cancel
Save