praktikum 7

This commit is contained in:
khaloufam70043 2019-11-26 15:32:42 +01:00
parent e016462c9f
commit 55c9032946
4315 changed files with 67 additions and 39 deletions

0
.idea/misc.xml generated Normal file → Executable file
View File

0
.idea/modules.xml generated Normal file → Executable file
View File

0
.idea/news.iml generated Normal file → Executable file
View File

0
.idea/vcs.xml generated Normal file → Executable file
View File

BIN
db.sqlite3 Normal file → Executable file

Binary file not shown.

View File

@ -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'

14
posts/forms.py Normal file
View File

@ -0,0 +1,14 @@
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)

View File

@ -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/<int:deleteId>', views.delete, name='delete'),
]

View File

@ -1,8 +1,7 @@
from django.shortcuts import render
from .models import Notice
from django.utils import timezone
from .forms import NoticeForm
def index(request):
notices = Notice.objects.all()
@ -11,3 +10,23 @@ def index (request):
context = {"notices": notices}
return render(request, 'posts/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, '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')

17
templates/posts/edit.html Normal file
View File

@ -0,0 +1,17 @@
{% extends '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 %}

View File

@ -11,40 +11,16 @@
{% for notice in notices %}
<h3>{{ notice.notice_title }}</h3>
<p>{{ notice.notice_text }}</p>
<p><a href="{% url 'new' %}" class="btn btn-info" role="button">Neue Nachricht</a></p>
<p><a href= "{% url 'delete' deleteId=notice.id %}" class="btn btn-danger">
Meldung loeschen</a></p>
{% endfor %}
</div>
{% endblock %}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Navbar Example</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
</head>
<body>
<h4>.navbar .navbar-expand-sm</h4>
<!-- A horizontal navbar that becomes vertical on small screens -->
<nav class="navbar navbar-expand-sm bg-dark">
<!-- Links -->
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="http://th-nuernberg.de">efi-homepage</a>
</li>
<li class="nav-item">
<a class="nav-link" href="http://google.de">Google</a>
</li>
</ul>
</nav>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
</body>
</html>
<h1> Index der Polls-Applikation</h1>

0
venv/bin/activate Normal file → Executable file
View File

0
venv/bin/activate.csh Normal file → Executable file
View File

0
venv/bin/activate.fish Normal file → Executable file
View File

0
venv/lib/python3.7/site-packages/django/__init__.py Normal file → Executable file
View File

0
venv/lib/python3.7/site-packages/django/__main__.py Normal file → Executable file
View File

View File

0
venv/lib/python3.7/site-packages/django/apps/config.py Normal file → Executable file
View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

View File

Some files were not shown because too many files have changed in this diff Show More