Compare commits
No commits in common. "85576f05cca8b3b05e1c405b39f62518bcd45749" and "06bcbd1d4fc39bafcf5901ae912ffc7aca0ea94f" have entirely different histories.
85576f05cc
...
06bcbd1d4f
@ -1,18 +0,0 @@
|
|||||||
from channels.routing import ProtocolTypeRouter, URLRouter
|
|
||||||
from django.urls import re_path
|
|
||||||
from channels.routing import URLRouter
|
|
||||||
from channels.http import AsgiHandler
|
|
||||||
from channels.auth import AuthMiddlewareStack
|
|
||||||
import django_eventstream
|
|
||||||
|
|
||||||
urlpatterns = [
|
|
||||||
#idz lt. URL ein Eventstream auszuliefern
|
|
||||||
re_path(r'^events/',
|
|
||||||
AuthMiddlewareStack(URLRouter(django_eventstream.routing.urlpatterns)),
|
|
||||||
{'channels': ['notice']}),
|
|
||||||
#bei allen anderen Anfragen werden die Standart-Router verwendet
|
|
||||||
re_path(r'', AsgiHandler),
|
|
||||||
]
|
|
||||||
application = ProtocolTypeRouter({
|
|
||||||
'http': URLRouter(urlpatterns)
|
|
||||||
})
|
|
@ -38,9 +38,6 @@ INSTALLED_APPS = [
|
|||||||
'django.contrib.sessions',
|
'django.contrib.sessions',
|
||||||
'django.contrib.messages',
|
'django.contrib.messages',
|
||||||
'django.contrib.staticfiles',
|
'django.contrib.staticfiles',
|
||||||
'rest_framework',
|
|
||||||
'channels',
|
|
||||||
'django_eventstream',
|
|
||||||
]
|
]
|
||||||
|
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
@ -51,9 +48,6 @@ MIDDLEWARE = [
|
|||||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||||
'django.contrib.messages.middleware.MessageMiddleware',
|
'django.contrib.messages.middleware.MessageMiddleware',
|
||||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||||
'django_grip.GripMiddleware',
|
|
||||||
'django.middleware.security.SecurityMiddleware',
|
|
||||||
|
|
||||||
]
|
]
|
||||||
|
|
||||||
ROOT_URLCONF = 'PR.urls'
|
ROOT_URLCONF = 'PR.urls'
|
||||||
@ -76,7 +70,7 @@ TEMPLATES = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
WSGI_APPLICATION = 'PR.wsgi.application'
|
WSGI_APPLICATION = 'PR.wsgi.application'
|
||||||
ASGI_APPLICATION = 'PR.routing.application'
|
|
||||||
|
|
||||||
# Database
|
# Database
|
||||||
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases
|
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases
|
||||||
|
@ -1,24 +0,0 @@
|
|||||||
# Generated by Django 2.2.7 on 2019-11-30 16:27
|
|
||||||
|
|
||||||
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()),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
]
|
|
@ -6,5 +6,3 @@ class Notice(models.Model):
|
|||||||
notice_text = models.CharField(max_length=400)
|
notice_text = models.CharField(max_length=400)
|
||||||
pub_start = models.DateTimeField()
|
pub_start = models.DateTimeField()
|
||||||
pub_end = models.DateTimeField()
|
pub_end = models.DateTimeField()
|
||||||
|
|
||||||
#neues model python migration
|
|
@ -1,7 +0,0 @@
|
|||||||
from rest_framework import serializers
|
|
||||||
from .models import Notice
|
|
||||||
|
|
||||||
class NoticeSerializer(serializers.ModelSerializer):
|
|
||||||
class Meta:
|
|
||||||
model = Notice
|
|
||||||
fields = ('id', 'notice_title', 'pub_start', 'pub_end')
|
|
@ -19,18 +19,13 @@ from django.urls import path
|
|||||||
from polls import views
|
from polls import views
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('', views.index , name='index'),
|
#path('', views.index , name='index'),
|
||||||
path('new', views.new, name='new'),
|
path('new', views.new, name='new'),
|
||||||
#path('index',views.index, name='index'),
|
#path('index',views.index, name='index'),
|
||||||
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),
|
||||||
path('delete/<int:deleteId>', views.delete, name ='delete'),
|
path('delete/<int:deleteId>', views.delete, name ='delete')
|
||||||
#url(r'^new', views.new, name='new'),
|
#url(r'^new', views.new, name='new'),
|
||||||
path('notices/', views.notice_list),
|
|
||||||
path('notices/<int:id>/', views.notice_detail),
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
]
|
]
|
||||||
|
@ -1,30 +1,9 @@
|
|||||||
|
from django.http import HttpResponse
|
||||||
from django.shortcuts import render,redirect
|
from django.shortcuts import render,redirect
|
||||||
from .models import Notice
|
from .models import Notice
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
#Pr8
|
|
||||||
from django.views.decorators.csrf import csrf_exempt
|
|
||||||
from django.http import HttpResponse,JsonResponse
|
|
||||||
from polls.forms import NoticeForm
|
from polls.forms import NoticeForm
|
||||||
from polls.models import Notice
|
|
||||||
from polls.serializers import NoticeSerializer
|
|
||||||
from rest_framework.parsers import JSONParser
|
|
||||||
#XXXX
|
|
||||||
from django.contrib.admin.views.decorators import staff_member_required
|
|
||||||
from django.contrib.auth.decorators import login_required
|
|
||||||
from django.http import HttpResponse, JsonResponse
|
|
||||||
from django.shortcuts import render, redirect
|
|
||||||
from django.utils import timezone
|
|
||||||
from django.views.decorators.csrf import csrf_exempt
|
|
||||||
from django_eventstream import send_event
|
|
||||||
from rest_framework.parsers import JSONParser
|
|
||||||
|
|
||||||
from polls.forms import NoticeForm
|
|
||||||
from polls.models import Notice
|
|
||||||
|
|
||||||
# Create your views here.
|
|
||||||
from polls.serializers import NoticeSerializer
|
|
||||||
|
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
logger = None
|
logger = None
|
||||||
@ -49,25 +28,21 @@ def index(request):
|
|||||||
#context = {"notices" : notices}
|
#context = {"notices" : notices}
|
||||||
return render(request, 'polls/notice.html',{"notices" : notices})
|
return render(request, 'polls/notice.html',{"notices" : notices})
|
||||||
|
|
||||||
|
#def new(request):
|
||||||
#login_required
|
# return render(request, 'polls/edit.html')
|
||||||
def new(request):
|
def new(request):
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
form = NoticeForm(request.POST)
|
form = NoticeForm(request.POST)
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
newNotice = Notice(notice_title=form.cleaned_data['title'],
|
newNotice = Notice(notice_title=form.cleaned_data['title'],
|
||||||
notice_text=form.cleaned_data['text'],
|
notice_text=form.cleaned_data['text'],
|
||||||
#pub_start=form.cleaned_data['start'],
|
pub_start=form.cleaned_data['start'],
|
||||||
pub_start= timezone.now(),
|
|
||||||
pub_end=form.cleaned_data['end'])
|
pub_end=form.cleaned_data['end'])
|
||||||
newNotice.save()
|
newNotice.save()
|
||||||
#Absetzen eines Events
|
|
||||||
send_event('notice', 'message', newNotice.id)
|
|
||||||
return redirect('index')
|
return redirect('index')
|
||||||
context = {'form': NoticeForm()}
|
context = {'form': NoticeForm()}
|
||||||
return render(request, 'polls/edit.html', context)
|
return render(request, 'polls/edit.html', context)
|
||||||
|
|
||||||
#staff_member_required
|
|
||||||
def delete(request, deleteId = None):
|
def delete(request, deleteId = None):
|
||||||
if deleteId != None:
|
if deleteId != None:
|
||||||
delNotice = Notice.objects.get(id=deleteId)
|
delNotice = Notice.objects.get(id=deleteId)
|
||||||
@ -80,42 +55,3 @@ def welcome_seite(request):
|
|||||||
|
|
||||||
def about_seite(request):
|
def about_seite(request):
|
||||||
return render(request, 'polls/about.html')
|
return render(request, 'polls/about.html')
|
||||||
|
|
||||||
#csrf_exempt
|
|
||||||
def notice_list (request):
|
|
||||||
if request.method == 'GET':
|
|
||||||
notices = Notice.objects.all()
|
|
||||||
serializer = NoticeSerializer(notices, many=True)
|
|
||||||
return JsonResponse(serializer.data, safe=False)
|
|
||||||
|
|
||||||
elif request.method == 'POST':
|
|
||||||
data = JSONParser().parser(request)
|
|
||||||
serializer = NoticeSerializer(data=data)
|
|
||||||
if serializer.is_valid():
|
|
||||||
serializer.save()
|
|
||||||
return JsonResponse(serializer.data, status=201)
|
|
||||||
return JsonResponse(serializer.errors, status=400)
|
|
||||||
|
|
||||||
#csrf_exempt
|
|
||||||
def notice_detail(request, id):
|
|
||||||
try:
|
|
||||||
notice = Notice.objects.get(id =id)
|
|
||||||
except Notice.DoesNotExist:
|
|
||||||
return HttpResponse(status=404)
|
|
||||||
|
|
||||||
if request.method == 'GET':
|
|
||||||
serializer = NoticeSerializer(notice)
|
|
||||||
return JsonResponse(serializer.data)
|
|
||||||
|
|
||||||
elif request.method == 'PUT':
|
|
||||||
data = JSONParser().parse(request)
|
|
||||||
serializer = NoticeSerializer(notice, data=data)
|
|
||||||
if serializer.is_valid():
|
|
||||||
serializer.save()
|
|
||||||
return JsonResponse(serializer.data)
|
|
||||||
return JsonResponse(serializer.errors, status=400)
|
|
||||||
|
|
||||||
elif request.method == 'DELETE':
|
|
||||||
notice.delete()
|
|
||||||
return HttpResponse(status=204)
|
|
||||||
|
|
||||||
|
@ -4,10 +4,6 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="de">
|
<html lang="de">
|
||||||
<head>
|
<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="/media/css/style.css" />#}
|
{# <link rel="stylesheet" href="/media/css/style.css" />#}
|
||||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
|
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
@ -1,10 +1,6 @@
|
|||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
<script>
|
|
||||||
var es = new ReconnectingEventSource('/events/');
|
|
||||||
es.addEventListener('message', function (e) {console.log(e.data);location.reload();}, false);
|
|
||||||
</script>
|
|
||||||
<h2>Seite Infos</h2>
|
<h2>Seite Infos</h2>
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user