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

urlpatterns = [ urlpatterns = [
path('edit', views.new, name='new'), path('edit', views.new, name='new'),
path('', views.index, name = 'index'), 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

from django.shortcuts import render, redirect, HttpResponse from django.shortcuts import render, redirect, HttpResponse
from django.utils import timezone 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 .forms import NoticeForm
from .models import Notice from .models import Notice
context = { "notices": notices } context = { "notices": notices }
return render(request, 'posts/index.html', context) return render(request, 'posts/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)
context = {'form': NoticeForm()} context = {'form': NoticeForm()}
return render(request, 'posts/edit.html', context) 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

{% endblock %} {% endblock %}


{% block body %} {% 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> <div>
{% for notice in notices %} {% for notice in notices %}
<h3> {{ notice.notice_title }}</h3> <h3> {{ notice.notice_title }}</h3>
<p> {{ notice.notice_text }}</p> <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 %} {% endfor %}
</div> </div>
<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>

+ 21
- 0
templates/registration/login.html View File

{% 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

urlpatterns = [ urlpatterns = [
path('posts/', include('posts.urls')), path('posts/', include('posts.urls')),
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
path('accounts/', include('django.contrib.auth.urls'))
] ]

Loading…
Cancel
Save