12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- from django.shortcuts import render, redirect
- from datetime import timedelta
- from django.utils import timezone
- from posts.models import Notice
- from posts.forms import NoticeForm
- from django.contrib.auth.decorators import login_required
- from django.contrib.admin.views.decorators import staff_member_required
- # Create your views here.
-
-
- #Titel und die Texte aller Meldungen, deren Veröffentlichungsdatum vor und der Endedatum nach dem aktuellen Datum liegt.
- def home(request, value=""):
- now = timezone.now()
- notices = Notice.objects.all()
- display_notices = list()
- for notice in notices:
- if notice.pub_start < now and notice.pub_end > now:
- display_notices.append(notice)
- context = {
- "title": "Beboop",
- "notices": display_notices
- }
- return render(request, 'index.html', context)
-
- @login_required
- def new(request):
- if request.method == "POST":
- form = NoticeForm(request.POST)
- if form.is_valid():
- newNotice = Notice(notice_title=form.cleaned_data['title'],
- notice_text=form.cleaned_data['text'],
- pub_start=form.cleaned_data['start'],
- pub_end=form.cleaned_data['end'])
- newNotice.save()
- return redirect('index')
- context = {'form': NoticeForm()}
- return render(request, 'edit.html', context)
-
- @staff_member_required
- def delete(request, value):
- notice = Notice.objects.get(id = value)
- notice.delete()
- return redirect('index')
|