add new project
This commit is contained in:
parent
487a8b5ed2
commit
6ed7b6a96b
@ -7,6 +7,7 @@ from posts.serializer import NoticeSerializer
|
|||||||
from django.http import JsonResponse
|
from django.http import JsonResponse
|
||||||
from rest_framework.parsers import JSONParser
|
from rest_framework.parsers import JSONParser
|
||||||
from django.views.decorators.csrf import csrf_exempt
|
from django.views.decorators.csrf import csrf_exempt
|
||||||
|
from django_eventstream import send_event
|
||||||
|
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
|
|
||||||
@ -27,12 +28,13 @@ 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'],
|
new_Notice = 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_end=form.cleaned_data['end'])
|
pub_end=form.cleaned_data['end'])
|
||||||
newNotice.save()
|
new_Notice.save()
|
||||||
#return redirect('index')
|
send_event('notice', 'message', new_Notice.id)
|
||||||
|
return redirect('index')
|
||||||
context = {'form': NoticeForm()}
|
context = {'form': NoticeForm()}
|
||||||
return render(request, 'posts/edit.html', context)
|
return render(request, 'posts/edit.html', context)
|
||||||
|
|
||||||
@ -41,6 +43,7 @@ def delete(request, deleteId=None):
|
|||||||
if deleteId != None:
|
if deleteId != None:
|
||||||
delNotice = Notice.objects.get(id=deleteId)
|
delNotice = Notice.objects.get(id=deleteId)
|
||||||
if delNotice != None:
|
if delNotice != None:
|
||||||
|
send_event('notice', 'message', delNotice.id)
|
||||||
delNotice.delete()
|
delNotice.delete()
|
||||||
return redirect('index')
|
return redirect('index')
|
||||||
|
|
||||||
|
@ -1,12 +1,17 @@
|
|||||||
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
|
{% load static %}
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
|
<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">
|
<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">
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<title>{% block title %} Platzhalter {% endblock %}</title>
|
<title>{% block title %} Platzhalter {% endblock %}</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
|
|
||||||
{% block content %} Platzhalter {% endblock %}
|
{% block content %} Platzhalter {% endblock %}
|
||||||
|
|
||||||
<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>
|
||||||
|
@ -1,34 +1,22 @@
|
|||||||
{% extends 'base.html' %}
|
{% extends "base.html" %}
|
||||||
|
{% block title %}Index.html{% endblock %}
|
||||||
{% block title %}
|
|
||||||
Index
|
|
||||||
{% endblock %}
|
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
<script>
|
||||||
|
var es = new ReconnectingEventSource('/events/');
|
||||||
|
es.addEventListener('message', function (e) {
|
||||||
|
console.log(e.data);
|
||||||
|
location.reload();
|
||||||
|
}, false);
|
||||||
|
</script>
|
||||||
|
|
||||||
<nav class="navbar navbar-default">
|
<form method="post">
|
||||||
<div class="container-fluid">
|
{% for n in notices %}
|
||||||
<div class="navbar-header">
|
<div>
|
||||||
<a class="navbar-brand" href="https://www.th-nuernberg.de/fakultaeten/efi/">Efi</a>
|
<p>Titel: {{ n.notice_title }}</p>
|
||||||
<a class="navbar-brand" href="https://www.google.de">Google</a>
|
<p>Text: {{ n.notice_text }}</p>
|
||||||
<a class="navbar-brand" href="/posts">Home</a>
|
<p><a href="{% url 'delete' deleteId=n.id %}" class="btn btn-danger" >Löschen</a></p>
|
||||||
</div>
|
</div>
|
||||||
<ul class="nav navbar-nav">
|
{% endfor %}
|
||||||
<li class="active"><a href="#">Home</a></li>
|
<p><a href="{% url 'new' %}" class="btn btn-info" role="button">Neue Nachricht</a></p>
|
||||||
<li><a href="/posts">Page 1</a></li>
|
</form>
|
||||||
<li><a href="">Page 2</a></li>
|
{% endblock %}
|
||||||
<li><a href="h">Page 3</a></li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
</nav>
|
|
||||||
|
|
||||||
|
|
||||||
<div class="container">
|
|
||||||
<div class="jumbotron">
|
|
||||||
<h1>Jumbotron Test</h1>
|
|
||||||
<p>My Jumbotron test</p>
|
|
||||||
</div>
|
|
||||||
<p>This is some text.</p>
|
|
||||||
<p>This is another text.</p>
|
|
||||||
</div>
|
|
||||||
{% endblock %}
|
|
Loading…
x
Reference in New Issue
Block a user