Solutions for MEIM
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

views.py 1.4KB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
12345678910111213141516171819202122232425262728293031323334353637383940
  1. from django.shortcuts import render, redirect
  2. from datetime import timedelta
  3. from django.utils import timezone
  4. from posts.models import Notice
  5. from posts.forms import NoticeForm
  6. from django.http import HttpResponse
  7. # Create your views here.
  8. #Titel und die Texte aller Meldungen, deren Veröffentlichungsdatum vor und der Endedatum nach dem aktuellen Datum liegt.
  9. def home(request, value=""):
  10. now = timezone.now()
  11. notices = Notice.objects.all()
  12. display_notices = list()
  13. for notice in notices:
  14. if notice.pub_start < now and notice.pub_end > now:
  15. display_notices.append(notice)
  16. context = {
  17. "title": "Beboop",
  18. "notices": display_notices
  19. }
  20. return render(request, 'index.html', context)
  21. def new(request):
  22. if request.method == "POST":
  23. form = NoticeForm(request.POST)
  24. if form.is_valid():
  25. newNotice = Notice(notice_title=form.cleaned_data['title'],
  26. notice_text=form.cleaned_data['text'],
  27. pub_start=form.cleaned_data['start'],
  28. pub_end=form.cleaned_data['end'])
  29. newNotice.save()
  30. return redirect('index')
  31. context = {'form': NoticeForm()}
  32. return render(request, 'edit.html', context)
  33. def delete(request, value):
  34. notice = Notice.objects.get(id = value)
  35. notice.delete()
  36. return redirect('index')