diff --git a/news/settings.py b/news/settings.py index 052c148..afa4e56 100755 --- a/news/settings.py +++ b/news/settings.py @@ -105,7 +105,7 @@ AUTH_PASSWORD_VALIDATORS = [ # Internationalization # https://docs.djangoproject.com/en/2.2/topics/i18n/ -LANGUAGE_CODE = 'en-us' +LANGUAGE_CODE = 'de-de' TIME_ZONE = 'UTC' diff --git a/news/urls.py b/news/urls.py index bf1c417..ec1ce9d 100755 --- a/news/urls.py +++ b/news/urls.py @@ -1,9 +1,15 @@ from django.contrib import admin from django.urls import path, include + + + + urlpatterns = [ path('posts/', include('posts.urls')), path('admin/', admin.site.urls), + + ] diff --git a/posts/forms.py b/posts/forms.py new file mode 100644 index 0000000..b34b80b --- /dev/null +++ b/posts/forms.py @@ -0,0 +1,13 @@ +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/posts/urls.py b/posts/urls.py index 306c8bc..ffc2ada 100755 --- a/posts/urls.py +++ b/posts/urls.py @@ -2,5 +2,7 @@ from django.urls import path from . import views urlpatterns = [ - path('', views.index, name='index') + path('', views.index, name='index'), + path('new', views.new, name='new'), + path('delete/', views.delete, name='delete'), ] \ No newline at end of file diff --git a/posts/views.py b/posts/views.py index bc19589..36f14c7 100755 --- a/posts/views.py +++ b/posts/views.py @@ -1,13 +1,34 @@ -from django.shortcuts import render +from django.shortcuts import render, redirect from .models import Notice from django.utils import timezone +from .forms import NoticeForm +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, 'posts/edit.html', context) -def index (request): + +def index(request): notices = Notice.objects.all() notices = notices.filter(pub_start__lte=timezone.now()) notices = notices.filter(pub_end__gte=timezone.now()) - context = { "notices" : notices } + context = {"notices": notices} return render(request, 'posts/index.html', context) +def delete(request, deleteId=None): + if deleteId !=None: + delNotice = Notice.objects.get(id=deleteId) + if delNotice != None: + delNotice.delete() + return redirect('index') + diff --git a/templates/base.html b/templates/base.html index 38bc0bb..9c1f600 100755 --- a/templates/base.html +++ b/templates/base.html @@ -19,4 +19,6 @@ {% block navigation %} Platzhalter {% endblock %} {% block content %} Platzhalter {% endblock %} - \ No newline at end of file + + + diff --git a/templates/posts/edit.html b/templates/posts/edit.html new file mode 100644 index 0000000..f3988b1 --- /dev/null +++ b/templates/posts/edit.html @@ -0,0 +1,26 @@ +{% extends 'base.html' %} + + +{% block title %} + News +{% endblock %} + + +{% block content %} + +
+ +

Neue Nachricht

+
+ {% csrf_token %} + {{ form.as_p }} + +
+
+ + + +{% endblock %} + + + diff --git a/templates/posts/index.html b/templates/posts/index.html index 7aa2146..74cd076 100755 --- a/templates/posts/index.html +++ b/templates/posts/index.html @@ -11,40 +11,26 @@ {% for notice in notices %}

{{ notice.notice_title }}

{{ notice.notice_text }}

- {% endfor %} + +

Neue Nachricht

+ + + + +

+ Meldung loeschen

+ {% endfor %} + + + + + + + + + {% endblock %} - - - - - - Navbar Example - - - - -

.navbar .navbar-expand-sm

- - - - - - - - - -

Index der Polls-Applikation