diff --git a/djp/djp/settings.py b/djp/djp/settings.py index a126dd8..c6bf341 100644 --- a/djp/djp/settings.py +++ b/djp/djp/settings.py @@ -107,7 +107,7 @@ AUTH_PASSWORD_VALIDATORS = [ # Internationalization # https://docs.djangoproject.com/en/2.1/topics/i18n/ -LANGUAGE_CODE = 'en-us' +LANGUAGE_CODE = 'de-de' TIME_ZONE = 'UTC' diff --git a/djp/polls/forms.py b/djp/polls/forms.py new file mode 100644 index 0000000..9335b00 --- /dev/null +++ b/djp/polls/forms.py @@ -0,0 +1,9 @@ +from django import forms +import datetime + +class NoticeForm(forms.Form): + date_formats = ['%d.%m.%Y', '%d.%m.%y'] + title = forms.CharField(label='Titel', max_length=80) + text = forms.CharField(label='Text', max_length=400) + start = forms.DateField(label='Von', input_formats=date_formats, initial=datetime.date.today) + end = forms.DateField(label='Bis', input_formats=date_formats, initial=datetime.date.today) diff --git a/djp/polls/urls.py b/djp/polls/urls.py index a3780aa..7f95bad 100644 --- a/djp/polls/urls.py +++ b/djp/polls/urls.py @@ -2,6 +2,8 @@ from django.conf.urls import url from . import views + urlpatterns = [ url(r'^$', views.index, name='index'), + url('new', views.new, name='new'), ] diff --git a/djp/polls/views.py b/djp/polls/views.py index e12075e..ea88691 100644 --- a/djp/polls/views.py +++ b/djp/polls/views.py @@ -1,6 +1,7 @@ from django.http import HttpResponse -from django.shortcuts import render +from django.shortcuts import render, redirect import time +from polls.forms import NoticeForm from django.utils import timezone from datetime import timedelta from polls.models import Notice @@ -14,4 +15,13 @@ def index(request): # print(n.notice_title) return render(request, 'polls/index.html', context) +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, 'polls/edit.html', context) # Create your views here. diff --git a/djp/templates/polls/edit.html b/djp/templates/polls/edit.html new file mode 100644 index 0000000..5648c3e --- /dev/null +++ b/djp/templates/polls/edit.html @@ -0,0 +1,20 @@ +{% extends 'base.html' %} + +{% block title %} +edit +{% endblock %} + + +{% block content %} +

Neue Nachricht

+
+ {% csrf_token %} + {{ form.as_p }} + +
+{% endblock %} + + + + + diff --git a/djp/templates/polls/index.html b/djp/templates/polls/index.html index 394293d..2e3dbcd 100644 --- a/djp/templates/polls/index.html +++ b/djp/templates/polls/index.html @@ -4,15 +4,21 @@ Index {% endblock %} + {% block content %}

Index der Polls-Applikation

{% for post in posts %} -

{{ post.notice_title }}

-

{{ post.notice_text }}

+

{{ post.notice_title }} {{ post.notice_text }} + delete message

+ {% endfor %}
+

Neue Nachricht

+ {% endblock %} + +