Aufgabe7
This commit is contained in:
parent
04beb1c854
commit
a17626b3db
BIN
news1/db.sqlite3
BIN
news1/db.sqlite3
Binary file not shown.
@ -105,7 +105,7 @@ AUTH_PASSWORD_VALIDATORS = [
|
|||||||
# Internationalization
|
# Internationalization
|
||||||
# https://docs.djangoproject.com/en/2.2/topics/i18n/
|
# https://docs.djangoproject.com/en/2.2/topics/i18n/
|
||||||
|
|
||||||
LANGUAGE_CODE = 'en-us'
|
LANGUAGE_CODE = 'de-de'
|
||||||
|
|
||||||
TIME_ZONE = 'UTC'
|
TIME_ZONE = 'UTC'
|
||||||
|
|
||||||
|
13
news1/posts/forms.py
Normal file
13
news1/posts/forms.py
Normal file
@ -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)
|
@ -2,5 +2,7 @@ from django.urls import path
|
|||||||
from . import views
|
from . import views
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('', views.index, name='index')
|
path('', views.index, name='index'),
|
||||||
|
path('new', views.new, name='new'),
|
||||||
|
path('delete/<int:deleteId>', views.delete, name='delete'),
|
||||||
]
|
]
|
@ -1,9 +1,34 @@
|
|||||||
from django.shortcuts import render
|
from django.shortcuts import render, redirect
|
||||||
|
|
||||||
|
from posts.forms import NoticeForm
|
||||||
from .models import Notice
|
from .models import Notice
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
from django.http import HttpResponse
|
||||||
|
|
||||||
def index(request):
|
def index(request):
|
||||||
notices = Notice.objects.all()
|
notices = Notice.objects.all()
|
||||||
notices = notices.filter(pub_start__lte=timezone.now())
|
notices = notices.filter(pub_start__lte=timezone.now())
|
||||||
notices = notices.filter(pub_end__gte=timezone.now())
|
notices = notices.filter(pub_end__gte=timezone.now())
|
||||||
context = {'notices': notices}
|
context = {'notices': notices}
|
||||||
return render(request, 'posts/Notice.html', context)
|
return render(request, 'posts/Notice.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, 'posts/edit.html', context)
|
||||||
|
|
||||||
|
def delete(request, deleteId=None):
|
||||||
|
if deleteId != None:
|
||||||
|
delNotice = Notice.objects.get(id=deleteId)
|
||||||
|
if delNotice != None:
|
||||||
|
delNotice.delete()
|
||||||
|
return redirect('index')
|
@ -9,9 +9,15 @@
|
|||||||
<div class="container">
|
<div class="container">
|
||||||
|
|
||||||
{% for notice in notices %}
|
{% for notice in notices %}
|
||||||
<h3>{{ notice.notice_title }}</h3>}}
|
<h3>{{ notice.notice_title }}</h3>
|
||||||
<P> {{ notice.notice_text }}<p>
|
<P> {{ notice.notice_text }}<p>
|
||||||
|
<P><a href="{% url 'delete' deleteId=notice.id %}" class="btn btn-danger">
|
||||||
|
Meldung löschen</a></P>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
<p><a href="{% url 'new' %} "class="btn btn-info" role="button">Neue Nachricht</a></p>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</div>}
|
</div>}
|
||||||
|
|
||||||
|
18
news1/templates/posts/edit.html
Normal file
18
news1/templates/posts/edit.html
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
{% extends 'posts/base.html'%}
|
||||||
|
|
||||||
|
{% block title %}
|
||||||
|
News
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="container">
|
||||||
|
<h1>Neue Nachricht</h1>
|
||||||
|
<form method="POST">
|
||||||
|
{% csrf_token %}
|
||||||
|
{{ form.as_p }}
|
||||||
|
<button type="submit" class="save btn btn-default">Speichern</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
Loading…
x
Reference in New Issue
Block a user