praktikum Aufgabe7
This commit is contained in:
parent
dcb4c6c41e
commit
dd08dc74f6
@ -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,6 +13,7 @@ Including another URLconf
|
|||||||
1. Import the include() function: from django.urls import include, path
|
1. Import the include() function: from django.urls import include, path
|
||||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||||
"""
|
"""
|
||||||
|
from django.conf.urls import url
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.urls import path,include
|
from django.urls import path,include
|
||||||
from posts import views
|
from posts import views
|
||||||
@ -20,4 +21,5 @@ from posts import views
|
|||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('posts/', include('posts.urls')),
|
path('posts/', include('posts.urls')),
|
||||||
path('admin/', admin.site.urls),
|
path('admin/', admin.site.urls),
|
||||||
|
|
||||||
]
|
]
|
||||||
|
16
posts/forms.py
Normal file
16
posts/forms.py
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
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)
|
11
posts/templates/posts/edit.html
Normal file
11
posts/templates/posts/edit.html
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
{% 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 %}
|
@ -3,14 +3,18 @@
|
|||||||
|
|
||||||
<h2>Seite Infos</h2>
|
<h2>Seite Infos</h2>
|
||||||
|
|
||||||
{% for notice in allnotice %}
|
|
||||||
|
|
||||||
<div class="notice">
|
|
||||||
<h3>{{ notice.notice_title }}</h3>
|
|
||||||
<h3>{{ notice.notice_text |linebreaks }}</h3>
|
|
||||||
</div>
|
|
||||||
{% empty %}
|
|
||||||
|
|
||||||
|
<div class="card w-100">
|
||||||
|
<div class="card-body">
|
||||||
|
{% for notice in allnotice %}
|
||||||
|
<h5 class="card-title">{{ notice.notice_title }}</h5>
|
||||||
|
<p class="card-text">{{ notice.notice_text |linebreaks }}</p>
|
||||||
|
<p><a href="{% url 'delete' deleteId=notice.id%}" class="btn btn-danger">Nachricht Löschen</a></p>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
<p><a href="{% url 'new' %}" class="btn btn-info" role="button">Neue Nachricht</a></p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
@ -1,3 +1,4 @@
|
|||||||
|
from django.conf.urls import url
|
||||||
from django.urls import path
|
from django.urls import path
|
||||||
from posts import views
|
from posts import views
|
||||||
|
|
||||||
@ -5,5 +6,7 @@ urlpatterns = [
|
|||||||
path('notice', views.index, name='index'),
|
path('notice', views.index, name='index'),
|
||||||
path('welcome', views.welcome_seite),
|
path('welcome', views.welcome_seite),
|
||||||
path('home', views.welcome_seite),
|
path('home', views.welcome_seite),
|
||||||
path('about', views.about_seite)
|
path('about', views.about_seite),
|
||||||
|
url(r'^new', views.new, name='new'),
|
||||||
|
path('delete/<int:deleteId>', views.delete, name ='delete')
|
||||||
]
|
]
|
@ -1,5 +1,8 @@
|
|||||||
from django.shortcuts import render
|
from django.http import HttpResponse
|
||||||
|
from django.shortcuts import render, redirect
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
||||||
|
from posts.forms import NoticeForm
|
||||||
from posts.models import Notice
|
from posts.models import Notice
|
||||||
|
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
@ -13,4 +16,25 @@ def welcome_seite(request):
|
|||||||
return render(request, 'posts/index.html')
|
return render(request, 'posts/index.html')
|
||||||
|
|
||||||
def about_seite(request):
|
def about_seite(request):
|
||||||
return render(request, 'posts/about.html')
|
return render(request, 'posts/about.html')
|
||||||
|
|
||||||
|
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')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user