Pra. 9
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
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
|
||||
|
||||
urpatterns = [
|
||||
re_path(r'events/',
|
||||
AuthMiddlewareStack(URLRouter(django_eventstream.routing.urlpatterns)),
|
||||
{'channels': ['notice']}),
|
||||
|
||||
re_path(r'', AsgiHandler),
|
||||
|
||||
|
||||
|
||||
|
||||
]
|
||||
|
||||
application = ProtocolTypeRouter({
|
||||
'http' : URLRouter(urpatterns)
|
||||
|
||||
})
|
||||
+4
-2
@@ -7,6 +7,7 @@ from .models import Notice
|
||||
from .serializers import NoticeSerializer
|
||||
from rest_framework.parsers import JSONParser
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
from django_eventstream import send_event
|
||||
|
||||
|
||||
|
||||
@@ -19,11 +20,12 @@ def new(request):
|
||||
if request.method == "POST":
|
||||
form = NoticeForm(request.POST)
|
||||
if form.is_valid():
|
||||
newNotice = Notice(notice_title=form.cleaned_data['title'],
|
||||
new_notice = 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()
|
||||
new_notice.save()
|
||||
send_event('notice', 'message', new_notice.id)
|
||||
return redirect('index')
|
||||
context = {'form': NoticeForm()}
|
||||
return render(request, 'posts/edit.html', context)
|
||||
|
||||
Reference in New Issue
Block a user