# Internationalization | # Internationalization | ||||
# https://docs.djangoproject.com/en/2.1/topics/i18n/ | # https://docs.djangoproject.com/en/2.1/topics/i18n/ | ||||
LANGUAGE_CODE = 'en-us' | |||||
LANGUAGE_CODE = 'de-de' | |||||
TIME_ZONE = 'UTC' | TIME_ZONE = 'UTC' | ||||
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) |
from . import views | from . import views | ||||
urlpatterns = [ | urlpatterns = [ | ||||
url(r'^$', views.index, name='index'), | url(r'^$', views.index, name='index'), | ||||
url('new', views.new, name='new'), | |||||
] | ] |
from django.http import HttpResponse | from django.http import HttpResponse | ||||
from django.shortcuts import render | |||||
from django.shortcuts import render, redirect | |||||
import time | import time | ||||
from polls.forms import NoticeForm | |||||
from django.utils import timezone | from django.utils import timezone | ||||
from datetime import timedelta | from datetime import timedelta | ||||
from polls.models import Notice | from polls.models import Notice | ||||
# print(n.notice_title) | # print(n.notice_title) | ||||
return render(request, 'polls/index.html', context) | 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. | # Create your views here. |
{% extends 'base.html' %} | |||||
{% block title %} | |||||
edit | |||||
{% endblock %} | |||||
{% block content %} | |||||
<h1>Neue Nachricht</h1> | |||||
<form method="POST"> | |||||
{% csrf_token %} | |||||
{{ form.as_p }} | |||||
<button type="submit" class="save btn btn-default">Speichern</button> | |||||
</form> | |||||
{% endblock %} | |||||
Index | Index | ||||
{% endblock %} | {% endblock %} | ||||
{% block content %} | {% block content %} | ||||
<div class="jumbotron jumbotron-fluid"> | <div class="jumbotron jumbotron-fluid"> | ||||
<div class="container"> | <div class="container"> | ||||
<h1>Index der Polls-Applikation</h1> | <h1>Index der Polls-Applikation</h1> | ||||
{% for post in posts %} | {% for post in posts %} | ||||
<p>{{ post.notice_title }}</p> | |||||
<p>{{ post.notice_text }}</p> | |||||
<p>{{ post.notice_title }} {{ post.notice_text }} | |||||
<a class="btn btn-info" role="button">delete message</a></p> | |||||
{% endfor %} | {% endfor %} | ||||
</div> | </div> | ||||
</div> | </div> | ||||
<p><a href="{% url 'new' %}" class="btn btn-info" role="button">Neue Nachricht</a></p> | |||||
{% endblock %} | {% endblock %} | ||||