From 06bcbd1d4fc39bafcf5901ae912ffc7aca0ea94f Mon Sep 17 00:00:00 2001 From: Laura Date: Tue, 3 Dec 2019 14:36:59 +0100 Subject: [PATCH] PR7 --- PR/settings.py | 3 +- manage.py | 1 + polls/forms.py | 12 +++ polls/models.py | 7 +- polls/urls.py | 15 ++- polls/views.py | 56 +++++++++- templates/base.html | 203 ++++++++---------------------------- templates/polls/about.html | 8 ++ templates/polls/edit.html | 11 ++ templates/polls/index.html | 25 +++-- templates/polls/notice.html | 20 ++++ 11 files changed, 184 insertions(+), 177 deletions(-) create mode 100644 polls/forms.py create mode 100644 templates/polls/about.html create mode 100644 templates/polls/edit.html create mode 100644 templates/polls/notice.html diff --git a/PR/settings.py b/PR/settings.py index 1a5a7de..1b941c0 100644 --- a/PR/settings.py +++ b/PR/settings.py @@ -31,6 +31,7 @@ ALLOWED_HOSTS = [] # Application definition INSTALLED_APPS = [ + 'polls.apps.PollsConfig', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', @@ -106,7 +107,7 @@ AUTH_PASSWORD_VALIDATORS = [ LANGUAGE_CODE = 'de-de' -TIME_ZONE = 'Europe/Berlin' +TIME_ZONE = 'UTC' USE_I18N = True diff --git a/manage.py b/manage.py index b8a8b56..37609f6 100644 --- a/manage.py +++ b/manage.py @@ -19,3 +19,4 @@ def main(): if __name__ == '__main__': main() + diff --git a/polls/forms.py b/polls/forms.py new file mode 100644 index 0000000..3ed0d67 --- /dev/null +++ b/polls/forms.py @@ -0,0 +1,12 @@ +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) \ No newline at end of file diff --git a/polls/models.py b/polls/models.py index 71a8362..b6f4ac5 100644 --- a/polls/models.py +++ b/polls/models.py @@ -1,3 +1,8 @@ from django.db import models - # Create your models here. + +class Notice(models.Model): + notice_title = models.CharField(max_length=80) + notice_text = models.CharField(max_length=400) + pub_start = models.DateTimeField() + pub_end = models.DateTimeField() \ No newline at end of file diff --git a/polls/urls.py b/polls/urls.py index 8576843..d8844b8 100644 --- a/polls/urls.py +++ b/polls/urls.py @@ -14,11 +14,18 @@ Including another URLconf 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ - +from django.conf.urls import url from django.urls import path -from . import views +from polls import views urlpatterns = [ - path('', views.index , name='index'), - + #path('', views.index , name='index'), + path('new', views.new, name='new'), + #path('index',views.index, name='index'), + path('notice',views.index, name = 'index'), + path('welcome', views.welcome_seite), + path('home', views.welcome_seite), + path('about', views.about_seite), + path('delete/', views.delete, name ='delete') + #url(r'^new', views.new, name='new'), ] diff --git a/polls/views.py b/polls/views.py index c080567..49b7edd 100644 --- a/polls/views.py +++ b/polls/views.py @@ -1,5 +1,57 @@ +from django.http import HttpResponse +from django.shortcuts import render,redirect +from .models import Notice +from django.utils import timezone +import logging +from polls.forms import NoticeForm -from django.shortcuts import render # Create your views here. +logger = None +def initLogger(): + global logger + if logger == None: + logger = logging.getLogger('django.db.backends') + logger.setLevel(logging.DEBUG) + logger.addHandler(logging.StreamHandler()) + +def delate(request, deleteId=None): + if deleteId !=None: + delNotice = Notice.objects.get(id=deleteId) + if delNotice != None: + delNotice.delete() + return redirect ('index') + def index(request): - return render(request, 'polls/index.html') \ No newline at end of file + notices = Notice.objects.all() + notices = notices.filter(pub_start__lte=timezone.now()) + notices = notices.filter(pub_end__gte=timezone.now()) + #context = {"notices" : notices} + return render(request, 'polls/notice.html',{"notices" : notices}) + +#def new(request): + # return render(request, 'polls/edit.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, 'polls/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') + +def welcome_seite(request): + return render(request, 'polls/index.html') + +def about_seite(request): + return render(request, 'polls/about.html') \ No newline at end of file diff --git a/templates/base.html b/templates/base.html index cb987f2..4c9a251 100644 --- a/templates/base.html +++ b/templates/base.html @@ -1,169 +1,48 @@ - - - - HTML FlexBox Template - Two columns, left menu - - - - - - - - - - - - - + + + +{# #} + + + + + + + + + + {% block title %}First Django PR{% endblock %} - -
- -
-
-

1. Main Content

-

Ueberschrift 1

-

-üüüüü -

-

- TEXT1.1 -

-

Ueberschrift2

-

- TEXT2 -

-
-
- -
-

3. Additional Stuff

-

Stichpunkte:

-
    -
  • X
  • -
  • X
  • -
  • X
  • -
  • X
  • -
-
- -
- + +
+ {% block content %}{% endblock %} +
+
© Danke
diff --git a/templates/polls/about.html b/templates/polls/about.html new file mode 100644 index 0000000..f89aca9 --- /dev/null +++ b/templates/polls/about.html @@ -0,0 +1,8 @@ +{% extends "base.html" %} +{% block content %} + +

Seite Infos

+

+ 123 test Eugen +

+{% endblock %}ml> \ No newline at end of file diff --git a/templates/polls/edit.html b/templates/polls/edit.html new file mode 100644 index 0000000..904520e --- /dev/null +++ b/templates/polls/edit.html @@ -0,0 +1,11 @@ +{% extends 'base.html' %} +{% block content %} + +

Neue Nachricht

+
+ {% csrf_token %} + {{ form.as_p }} + +
+ +{% endblock %} \ No newline at end of file diff --git a/templates/polls/index.html b/templates/polls/index.html index 479517a..65f2d2f 100644 --- a/templates/polls/index.html +++ b/templates/polls/index.html @@ -1,9 +1,20 @@ -{% extends 'base.html' %} - -{% block titel%} -Index-von Test -{% endblock %} - +{% extends "base.html" %} {% block content %} -

123 TEST

+ +

Seite Infos

+ + + +
+
+ {% for notice in notices %} +
{{ notice.notice_title }}
+

{{ notice.notice_text |linebreaks }}

+

Nachricht Löschen

+ {% endfor %} +

Neue Nachricht

+
+
+ + {% endblock %} \ No newline at end of file diff --git a/templates/polls/notice.html b/templates/polls/notice.html new file mode 100644 index 0000000..578a7a6 --- /dev/null +++ b/templates/polls/notice.html @@ -0,0 +1,20 @@ +{% extends "base.html" %} +{% block content %} + +

Seite Infos

+ + + +
+
+ {% for notice in notices %} +
{{ notice.notice_title }}
+

{{ notice.notice_text |linebreaks }}

+

Nachricht Löschen

+ {% endfor %} +

Neue Nachricht

+
+
+ + +{% endblock %} \ No newline at end of file