Compare commits

...
3 Commits
Author SHA1 Message Date
pouanideumassse68079 c97f4b9c7f Praktikum8 2019-12-10 15:33:46 +01:00
pouanideumassse68079 d3fc3d5e39 Praktikum8 2019-12-03 16:29:45 +01:00
pouanideumassse68079 10d2dabced Praktikum8 2019-12-03 16:27:31 +01:00
12 changed files with 118 additions and 1 deletions

No files matched your search

+4
View File
@@ -0,0 +1,4 @@
db.sqlite3
bin/*
venv/*
lib/*
BIN
View File
Binary file not shown.
View File
Whitespace-only changes.
+5
View File
@@ -39,6 +39,9 @@ INSTALLED_APPS = [
'django.contrib.staticfiles',
'posts',
'rest_framework',
'channels',
'django_eventstream',
]
MIDDLEWARE = [
@@ -49,6 +52,7 @@ MIDDLEWARE = [
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django_grip.GripMiddleware'
]
ROOT_URLCONF = 'news1.urls'
@@ -71,6 +75,7 @@ TEMPLATES = [
]
WSGI_APPLICATION = 'news1.wsgi.application'
ASGI_APPLICATION = 'news1.routing.application'
# Database
+12
View File
@@ -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)
+24
View File
@@ -0,0 +1,24 @@
# Generated by Django 2.2.7 on 2019-11-12 12:46
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Notice',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('notice_title', models.CharField(max_length=80)),
('notice_text', models.CharField(max_length=400)),
('pub_start', models.DateTimeField()),
('pub_end', models.DateTimeField()),
],
),
]
+7
View File
@@ -0,0 +1,7 @@
from rest_framework import serializers
from .models import Notice
class NoticeSerializer(serializers.ModelSerializer):
class Meta:
model = Notice
fields = ('id' , 'notice_title','notice_text', 'pub_start', 'pub_end')
+11
View 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 %}
+26
View File
@@ -0,0 +1,26 @@
{% extends 'base.html'%}
{% block content %}
<div class="container">
{% for notice in notices %}
<h3> {{ notice.notice_title }}</h3>
<p> {{ notice.notice_text }}</p>
<p><a href="{% url 'delete' deleteId=notice.id%}" class="btn btn-danger">Meldung löschen</a></p>
<hr>
{% endfor %}
<p><a href="{% url 'new' %}" class="btn btn-info" role="button">Neue Nachricht</a></p>
<p><a href="{% url 'logout' %}" class="btn btn-warning">Abmelden</a></p>
</div>
<script>
var es = new ReconnectingEventSource('/events/');
es.addEventListener('message',function(e) {
console.log(e.data); location.reload();false
})
</script>
{% endblock %}
+3
View File
@@ -1,6 +1,7 @@
from django.contrib.auth.decorators import login_required
from django.shortcuts import render, redirect
from django.views.decorators.csrf import csrf_exempt
from django_eventstream import send_event
from rest_framework.parsers import JSONParser
from posts.forms import NoticeForm
@@ -27,6 +28,7 @@ def new(request):
pub_start=form.cleaned_data['start'],
pub_end=form.cleaned_data['end'])
newNotice.save()
send_event('notice', 'message', newNotice.id)
return redirect('index')
context = {'form': NoticeForm()}
return render(request, 'posts/edit.html', context)
@@ -36,6 +38,7 @@ def delete(request, deleteId=None):
delNotice= Notice.objects.get(id=deleteId)
if delNotice!= None:
delNotice.delete()
send_event('notice', 'message', deleteId)
return redirect('index')
@csrf_exempt
def notice_list(request):
+4 -1
View File
@@ -1,6 +1,9 @@
<!DOCTYPE html>
<html lang="fr">
<head>
{% load static %}
<script src="{% static 'django_eventstream/eventsource.min.js' %}"></script>
<script src="{% static 'django_eventstream/reconnecting-eventsource.js' %}"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
@@ -60,4 +63,4 @@
</section>
<footer>&copy; posts news1</footer>
</body>
</html>
</html>
+22
View File
@@ -0,0 +1,22 @@
{% extends 'base.html' %}
{% block title %}
{% if user.is_authenticated %}
<p><a href="{% url 'logout' %}?next=/posts"
class="btn btn-warning">Abmelden</a></p>
{% endif %}
Login
{% endblock %}
{% block content %}
<form method="post" action="{% url 'login' %}">
{% csrf_token %}
Benutzername: {{ form.username }} <br>
Passwort: {{ form.password }} <br>
<button type="submit" class="btn btn-default">Anmelden</button>
<input type="hidden" name="next" value="{{ next }}"/>
</form>
{% endblock %}