2013-09-15 12:29:56 +02:00
|
|
|
from datetime import datetime
|
2019-01-05 11:27:15 +01:00
|
|
|
from django.shortcuts import render, redirect
|
|
|
|
from simpleforum.models import Message
|
2013-09-15 12:29:56 +02:00
|
|
|
|
|
|
|
|
2019-01-05 11:27:15 +01:00
|
|
|
def message_view(request):
|
2013-09-15 12:29:56 +02:00
|
|
|
if request.method == 'POST':
|
|
|
|
if 'titel' in request.POST and 'text' in request.POST:
|
|
|
|
titel = request.POST.get('titel')
|
2019-01-05 11:27:15 +01:00
|
|
|
text = request.POST.get('text')
|
|
|
|
|
2013-09-15 12:29:56 +02:00
|
|
|
if len(titel) > 0 and len(text) > 0:
|
2019-01-05 11:27:15 +01:00
|
|
|
Message.objects.create(titel=titel, text=text, author=request.user, creation_time=datetime.now())
|
|
|
|
|
|
|
|
return redirect(message_view)
|
|
|
|
|
2013-09-15 12:29:56 +02:00
|
|
|
context = dict()
|
2019-01-05 11:27:15 +01:00
|
|
|
|
2013-09-15 12:29:56 +02:00
|
|
|
if request.method == 'GET':
|
|
|
|
if 'month' in request.GET and 'year' in request.GET:
|
2019-01-05 11:27:15 +01:00
|
|
|
year = int(request.GET['year'])
|
|
|
|
month = int(request.GET['month'])
|
|
|
|
until_date = datetime(year, month + 1, 1)
|
|
|
|
from_date = datetime(year, month, 1)
|
2013-09-15 12:29:56 +02:00
|
|
|
context['archiveMode'] = True
|
2019-01-05 11:27:15 +01:00
|
|
|
context['year'] = year
|
2013-09-15 12:29:56 +02:00
|
|
|
context['month'] = month
|
2019-01-05 11:27:15 +01:00
|
|
|
context['messages'] = Message.objects.filter(creation_time__lt=until_date).filter(
|
|
|
|
creation_time__gte=from_date).order_by('-creation_time')
|
2013-09-15 12:29:56 +02:00
|
|
|
else:
|
2019-01-05 11:27:15 +01:00
|
|
|
context['messages'] = Message.objects.order_by('-creation_time')[:20]
|
2013-09-15 12:29:56 +02:00
|
|
|
context['archiveMode'] = False
|
2013-10-03 11:27:06 +02:00
|
|
|
|
2019-01-05 11:27:15 +01:00
|
|
|
return render(request, 'simpleforum/simpleforum.html', context)
|