Compare commits
No commits in common. "6ef1c46b6bf7e0035dc280d3072883ed2908ecec" and "fb4f003f39a671bd703f4e9887c73fa5f4c5f145" have entirely different histories.
6ef1c46b6b
...
fb4f003f39
@ -1,17 +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 = [
|
|
||||||
re_path(r'^events/',
|
|
||||||
AuthMiddlewareStack(URLRouter(django_eventstream.routing.urlpatterns)),
|
|
||||||
{'channels': ['notice']}),
|
|
||||||
re_path(r'', AsgiHandler),
|
|
||||||
]
|
|
||||||
|
|
||||||
application = ProtocolTypeRouter({
|
|
||||||
'http': URLRouter(urlpatterns),
|
|
||||||
})
|
|
@ -39,8 +39,6 @@ INSTALLED_APPS = [
|
|||||||
'django.contrib.sessions',
|
'django.contrib.sessions',
|
||||||
'django.contrib.messages',
|
'django.contrib.messages',
|
||||||
'django.contrib.staticfiles',
|
'django.contrib.staticfiles',
|
||||||
'channels',
|
|
||||||
'django_eventstream',
|
|
||||||
]
|
]
|
||||||
|
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
@ -51,8 +49,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 = 'news.urls'
|
ROOT_URLCONF = 'news.urls'
|
||||||
@ -76,7 +72,6 @@ TEMPLATES = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
WSGI_APPLICATION = 'news.wsgi.application'
|
WSGI_APPLICATION = 'news.wsgi.application'
|
||||||
ASGI_APPLICATION = 'news.routing.application'
|
|
||||||
|
|
||||||
|
|
||||||
# Database
|
# Database
|
||||||
|
@ -10,20 +10,4 @@ class NoticeForm(forms.Form):
|
|||||||
initial=datetime.date.today)
|
initial=datetime.date.today)
|
||||||
end = forms.DateField(label='Bis',
|
end = forms.DateField(label='Bis',
|
||||||
input_formats=date_formats,
|
input_formats=date_formats,
|
||||||
initial=datetime.datetime.today() + datetime.timedelta(days=1))
|
initial=datetime.date.today)
|
||||||
|
|
||||||
class EditNoticeForm(forms.Form):
|
|
||||||
def __init__(self, *args, **kwargs):
|
|
||||||
self.title = forms.CharField(label='Titel',
|
|
||||||
max_length=80,
|
|
||||||
initial=kwargs.pop('notice_title'))
|
|
||||||
self.text = forms.CharField(label='Text',
|
|
||||||
max_length=400,
|
|
||||||
initial=kwargs.pop('notice_text'))
|
|
||||||
self.start = forms.DateField(label='Von',
|
|
||||||
initial=kwargs.pop('notice.pub_start'),
|
|
||||||
input_formats=NoticeForm.date_formats)
|
|
||||||
self.end = forms.DateField(label='Bis',
|
|
||||||
initial=kwargs.pop('pub_end'),
|
|
||||||
input_formats=NoticeForm.date_formats)
|
|
||||||
super(EditNoticeForm, self).__init__(*args, **kwargs)
|
|
||||||
|
@ -5,7 +5,6 @@ urlpatterns = [
|
|||||||
path('', views.index, name='posts'),
|
path('', views.index, name='posts'),
|
||||||
path('new', views.new, name='new'),
|
path('new', views.new, name='new'),
|
||||||
path('delete/<int:deleteId>', views.delete, name='delete'),
|
path('delete/<int:deleteId>', views.delete, name='delete'),
|
||||||
path('edit/<int:editId>', views.edit, name='edit'),
|
|
||||||
|
|
||||||
path('notices/', views.notice_list),
|
path('notices/', views.notice_list),
|
||||||
path('notices/<int:id>/', views.notice_detail),
|
path('notices/<int:id>/', views.notice_detail),
|
||||||
|
@ -5,13 +5,12 @@ from django.http import HttpResponse, JsonResponse
|
|||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.views.decorators.csrf import csrf_exempt
|
from django.views.decorators.csrf import csrf_exempt
|
||||||
from django_eventstream import send_event
|
|
||||||
|
|
||||||
from rest_framework.renderers import JSONRenderer
|
from rest_framework.renderers import JSONRenderer
|
||||||
from rest_framework.parsers import JSONParser
|
from rest_framework.parsers import JSONParser
|
||||||
|
|
||||||
from .models import Notice
|
from .models import Notice
|
||||||
from .forms import NoticeForm, EditNoticeForm
|
from .forms import NoticeForm
|
||||||
from .serializers import NoticeSerializer
|
from .serializers import NoticeSerializer
|
||||||
|
|
||||||
logger = None
|
logger = None
|
||||||
@ -36,7 +35,6 @@ def index(request):
|
|||||||
}
|
}
|
||||||
return render(request, 'posts/index.html', context)
|
return render(request, 'posts/index.html', context)
|
||||||
|
|
||||||
#@login_required
|
|
||||||
def new(request):
|
def new(request):
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
form = NoticeForm(request.POST)
|
form = NoticeForm(request.POST)
|
||||||
@ -46,7 +44,6 @@ def new(request):
|
|||||||
pub_start=form.cleaned_data['start'],
|
pub_start=form.cleaned_data['start'],
|
||||||
pub_end=form.cleaned_data['end'])
|
pub_end=form.cleaned_data['end'])
|
||||||
newNotice.save()
|
newNotice.save()
|
||||||
send_event('notice', 'message', newNotice.id)
|
|
||||||
return redirect('posts')
|
return redirect('posts')
|
||||||
|
|
||||||
context = {'form' : NoticeForm()}
|
context = {'form' : NoticeForm()}
|
||||||
@ -61,38 +58,9 @@ def delete(request, deleteId=None):
|
|||||||
if delNotice:
|
if delNotice:
|
||||||
delNotice.delete()
|
delNotice.delete()
|
||||||
message = "Notice has been deleted."
|
message = "Notice has been deleted."
|
||||||
send_event('notice', 'message', "Notice has been deleted.")
|
|
||||||
return redirect('posts')
|
return redirect('posts')
|
||||||
|
|
||||||
|
|
||||||
def edit(request, editId=None):
|
|
||||||
init_loger(__name__)
|
|
||||||
logger.debug(editId)
|
|
||||||
logger.debug(request.method)
|
|
||||||
editNotice = None
|
|
||||||
if editId:
|
|
||||||
editNotice = Notice.objects.get(id=editId)
|
|
||||||
logger.debug(editNotice)
|
|
||||||
if editNotice:
|
|
||||||
form = EditNoticeForm(editNotice)
|
|
||||||
#form.title = editNotice.notice_title
|
|
||||||
#form.notice_to_form(editNotice)
|
|
||||||
logger.info(form)
|
|
||||||
#if form.is_valid():
|
|
||||||
# return HttpResponse(status=204)
|
|
||||||
context = {'form' : form}
|
|
||||||
return render(request, 'posts/edit.html', context)
|
|
||||||
|
|
||||||
"""
|
|
||||||
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()
|
|
||||||
send_event('notice', 'message', newNotice.id)
|
|
||||||
return redirect('posts')
|
|
||||||
"""
|
|
||||||
|
|
||||||
@csrf_exempt
|
@csrf_exempt
|
||||||
def notice_list(request):
|
def notice_list(request):
|
||||||
if request.method == 'GET':
|
if request.method == 'GET':
|
||||||
|
@ -7,11 +7,6 @@
|
|||||||
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
|
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
|
||||||
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
|
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
|
||||||
|
|
||||||
{% load static %}
|
|
||||||
<script src="{% static 'django_eventstream/eventsource.min.js' %}"></script>
|
|
||||||
<script src="{% static 'django_eventstream/reconnecting-eventsource.js' %}"></script>
|
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
{% include 'navbar.html' %}
|
{% include 'navbar.html' %}
|
||||||
|
@ -5,12 +5,6 @@ Index
|
|||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
<script>
|
|
||||||
var es = new ReconnectingEventSource('/events/');
|
|
||||||
es.addEventListener('message', function (e) {console.log(e.data); location.reload();});
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<div class=container>
|
<div class=container>
|
||||||
<h1 class="display-4">Your Posts</h1>
|
<h1 class="display-4">Your Posts</h1>
|
||||||
|
|
||||||
@ -19,10 +13,7 @@ Index
|
|||||||
<div class="jumbotron">
|
<div class="jumbotron">
|
||||||
<h3>{{ notice.notice_title }}</h3>
|
<h3>{{ notice.notice_title }}</h3>
|
||||||
<p>{{ notice.notice_text }}</p>
|
<p>{{ notice.notice_text }}</p>
|
||||||
<p>
|
<p><a href="{% url 'delete' deleteId=notice.id %}" class="btn btn-danger" role="button">Delete</a></p>
|
||||||
<a href="{% url 'delete' deleteId=notice.id %}" class="btn btn-danger" role="button">Delete</a>
|
|
||||||
<a href="{% url 'edit' editId=notice.id %}" class="btn btn-info" role="button">Edit</a>
|
|
||||||
</p>
|
|
||||||
{% if message %}
|
{% if message %}
|
||||||
<script>
|
<script>
|
||||||
alert('{{ message }}');
|
alert('{{ message }}');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user