Compare commits

..
7 Commits
Author SHA1 Message Date
colovicam63900 5a7e242875 Pra. 9 2019-12-10 15:21:44 +01:00
colovicam63900 7bb3690afe praktikum sieben bearbeitung 2019-12-03 15:17:37 +01:00
colovicam63900 5376f0e654 praktikum Sieben bearbeitung 2019-11-26 15:30:55 +01:00
colovicam63900 a67575f713 praktikum Sechs bearbeitung 2019-11-26 14:20:45 +01:00
herrerahuezoul67409 1b4eb2d70f first commit 2019-11-26 14:06:02 +01:00
herrerahuezoul67409 c86cae2216 praktikum6 2019-11-19 15:31:28 +01:00
herrerahuezoul67409 73437a9a7a praktikum Sechs bearbeitung 2019-11-19 15:28:55 +01:00
40 changed files with 353 additions and 50 deletions
Executable
+90
View File
@@ -0,0 +1,90 @@
### OSX ###
.DS_Store
.AppleDouble
.LSOverride
# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear on external disk
.Spotlight-V100
.Trashes
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
# C extensions
*.so
# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.cache
nosetests.xml
coverage.xml
# Translations
*.mo
*.pot
# Sphinx documentation
docs/_build/
# PyBuilder
target/
### Django ###
*.log
*.pot
*.pyc
**__pycache__/
local_settings.py
.env
**/db.sqlite3
# PyCharm
**/.idea/
Generated Regular → Executable
+1 -1
View File
@@ -3,5 +3,5 @@
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7 (news)" project-jdk-type="Python SDK" />
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7 (Django)" project-jdk-type="Python SDK" />
</project>
Generated Regular → Executable
View File
Generated Regular → Executable
+1 -1
View File
@@ -16,7 +16,7 @@
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="jdk" jdkName="Python 3.7 (Django)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="TemplatesService">
Generated Regular → Executable
View File
BIN
View File
Binary file not shown.
Regular → Executable
View File
Regular → Executable
+10 -1
View File
@@ -37,6 +37,10 @@ INSTALLED_APPS = [
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'posts.apps.PostsConfig',
'rest_framework',
'channels',
'django_eventstream',
]
MIDDLEWARE = [
@@ -47,6 +51,8 @@ MIDDLEWARE = [
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django_grip.GripMiddleware',
'django.middleware.security.SecurityMiddleware',
]
ROOT_URLCONF = 'news.urls'
@@ -104,7 +110,7 @@ AUTH_PASSWORD_VALIDATORS = [
# Internationalization
# https://docs.djangoproject.com/en/2.2/topics/i18n/
LANGUAGE_CODE = 'en-us'
LANGUAGE_CODE = 'de-de'
TIME_ZONE = 'UTC'
@@ -119,3 +125,6 @@ USE_TZ = True
# https://docs.djangoproject.com/en/2.2/howto/static-files/
STATIC_URL = '/static/'
WSGI_APPLICATION = 'posts.wsgi.application'
ASGI_APPLICATION = 'posts.routing.application'
Regular → Executable
+6
View File
@@ -1,9 +1,15 @@
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('posts/', include('posts.urls')),
path('admin/', admin.site.urls),
]
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
Regular → Executable
View File
+13
View File
@@ -0,0 +1,13 @@
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-19 13:28
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()),
],
),
]
Regular → Executable
View File
Regular → Executable
+5
View File
@@ -1,3 +1,8 @@
from django.db import models
# Create your models here.
class Notice(models.Model):
notice_title = models.CharField(max_length=80)
notice_text = models.CharField(max_length=400)
pub_start = models.DateTimeField()
pub_end = models.DateTimeField()
+23
View File
@@ -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)
})
+9
View File
@@ -0,0 +1,9 @@
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')
Regular → Executable
View File
Regular → Executable
+5 -1
View File
@@ -2,5 +2,9 @@ from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name='index')
path('', views.index, name='index'),
path('new', views.new, name='new'),
path('delete/<int:deleteId>', views.delete, name='delete'),
path('notices/', views.notice_list),
path('notices/<int:id>/', views.notice_detail),
]
Regular → Executable
+81 -3
View File
@@ -1,6 +1,84 @@
from django.shortcuts import render
from django.shortcuts import render, redirect
from django.utils import timezone
from .forms import NoticeForm
from django.http import JsonResponse, HttpResponse
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
def index (request):
return render(request, 'posts/index.html')
def new(request):
if request.method == "POST":
form = NoticeForm(request.POST)
if form.is_valid():
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'])
new_notice.save()
send_event('notice', 'message', new_notice.id)
return redirect('index')
context = {'form': NoticeForm()}
return render(request, 'posts/edit.html', context)
def index(request):
notices = Notice.objects.all()
notices = notices.filter(pub_start__lte=timezone.now())
notices = notices.filter(pub_end__gte=timezone.now())
context = {"notices": notices}
return render(request, 'posts/index.html', context)
def delete(request, deleteId=None):
if deleteId !=None:
delNotice = Notice.objects.get(id=deleteId)
if delNotice != None:
delNotice.delete()
return redirect('index')
@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().parse(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
View File
@@ -0,0 +1,4 @@
channels
django-eventstream
Regular → Executable
+13 -1
View File
@@ -14,9 +14,21 @@
<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>
<body>
{% block navigation %} Platzhalter {% endblock %}
{% block content %} Platzhalter {% endblock %}
</body>
</html>
</html>
+26
View File
@@ -0,0 +1,26 @@
{% extends 'base.html' %}
{% block title %}
News
{% endblock %}
{% block content %}
<div class="container">
<h1>Neue Nachricht</h1>
<form method="POST">
{% csrf_token %}
{{ form.as_p }}
<button type="submit" class="save btn btn-default">Speichern</button>
</form>
</div>
{% endblock %}
Regular → Executable
+29 -29
View File
@@ -1,40 +1,40 @@
{% extends 'base.html' %}
{% block title %}
Index
News
{% endblock %}
{% block content %}
<script>
var es = new ReconnectingEventSource('/events/');
es.addEventListener('message', function (e) {console.log(e.data);location.reload();}, false);
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Navbar Example</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
</head>
<body>
<h4>.navbar .navbar-expand-sm</h4>
</script>
<!-- A horizontal navbar that becomes vertical on small screens -->
<nav class="navbar navbar-expand-sm bg-dark">
<!-- Links -->
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="http://th-nuernberg.de">efi-homepage</a>
</li>
<li class="nav-item">
<a class="nav-link" href="http://google.de">Google</a>
</li>
</ul>
</nav>
<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 loeschen</a></p>
{% endfor %}
<p><a href="{% url 'new' %}" class="btn btn-info" role="button">Neue Nachricht</a></p>
</div>
{% endblock %}
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
</body>
</html>
<h1> Index der Polls-Applikation</h1>
{% endblock %}
+1 -1
View File
@@ -37,7 +37,7 @@ deactivate () {
# unset irrelevant variables
deactivate nondestructive
VIRTUAL_ENV="/Users/colovicam63900/Desktop/mysite/venv"
VIRTUAL_ENV="/Users/herrerahuezoul67409/PycharmProjects/Django/venv"
export VIRTUAL_ENV
_OLD_VIRTUAL_PATH="$PATH"
+1 -1
View File
@@ -8,7 +8,7 @@ alias deactivate 'test $?_OLD_VIRTUAL_PATH != 0 && setenv PATH "$_OLD_VIRTUAL_PA
# Unset irrelevant variables.
deactivate nondestructive
setenv VIRTUAL_ENV "/Users/colovicam63900/Desktop/mysite/venv"
setenv VIRTUAL_ENV "/Users/herrerahuezoul67409/PycharmProjects/Django/venv"
set _OLD_VIRTUAL_PATH="$PATH"
setenv PATH "$VIRTUAL_ENV/bin:$PATH"
+1 -1
View File
@@ -29,7 +29,7 @@ end
# unset irrelevant variables
deactivate nondestructive
set -gx VIRTUAL_ENV "/Users/colovicam63900/Desktop/mysite/venv"
set -gx VIRTUAL_ENV "/Users/herrerahuezoul67409/PycharmProjects/Django/venv"
set -gx _OLD_VIRTUAL_PATH $PATH
set -gx PATH "$VIRTUAL_ENV/bin" $PATH
+1 -1
View File
@@ -1,4 +1,4 @@
#!/Users/colovicam63900/Desktop/mysite/venv/bin/python
#!/Users/herrerahuezoul67409/PycharmProjects/Django/venv/bin/python
# -*- coding: utf-8 -*-
import re
+1 -1
View File
@@ -1,4 +1,4 @@
#!/Users/colovicam63900/Desktop/mysite/venv/bin/python
#!/Users/herrerahuezoul67409/PycharmProjects/Django/venv/bin/python
from django.core import management
if __name__ == "__main__":
+1 -1
View File
@@ -1,4 +1,4 @@
#!/Users/colovicam63900/Desktop/mysite/venv/bin/python
#!/Users/herrerahuezoul67409/PycharmProjects/Django/venv/bin/python
# EASY-INSTALL-ENTRY-SCRIPT: 'setuptools==39.1.0','console_scripts','easy_install'
__requires__ = 'setuptools==39.1.0'
import re
+1 -1
View File
@@ -1,4 +1,4 @@
#!/Users/colovicam63900/Desktop/mysite/venv/bin/python
#!/Users/herrerahuezoul67409/PycharmProjects/Django/venv/bin/python
# EASY-INSTALL-ENTRY-SCRIPT: 'setuptools==39.1.0','console_scripts','easy_install-3.7'
__requires__ = 'setuptools==39.1.0'
import re
+1 -1
View File
@@ -1,4 +1,4 @@
#!/Users/colovicam63900/Desktop/mysite/venv/bin/python
#!/Users/herrerahuezoul67409/PycharmProjects/Django/venv/bin/python
# EASY-INSTALL-ENTRY-SCRIPT: 'pip==10.0.1','console_scripts','pip'
__requires__ = 'pip==10.0.1'
import re
+1 -1
View File
@@ -1,4 +1,4 @@
#!/Users/colovicam63900/Desktop/mysite/venv/bin/python
#!/Users/herrerahuezoul67409/PycharmProjects/Django/venv/bin/python
# EASY-INSTALL-ENTRY-SCRIPT: 'pip==10.0.1','console_scripts','pip3'
__requires__ = 'pip==10.0.1'
import re
+1 -1
View File
@@ -1,4 +1,4 @@
#!/Users/colovicam63900/Desktop/mysite/venv/bin/python
#!/Users/herrerahuezoul67409/PycharmProjects/Django/venv/bin/python
# EASY-INSTALL-ENTRY-SCRIPT: 'pip==10.0.1','console_scripts','pip3.7'
__requires__ = 'pip==10.0.1'
import re
+1 -1
View File
@@ -1,4 +1,4 @@
#!/Users/colovicam63900/Desktop/mysite/venv/bin/python
#!/Users/herrerahuezoul67409/PycharmProjects/Django/venv/bin/python
# -*- coding: utf-8 -*-
import re
@@ -26,7 +26,7 @@ sqlparse-0.3.0.dist-info/WHEEL,sha256=HX-v9-noUkyUoxyZ1PMSuS7auUxDAR4VBdoYLqD0xw
sqlparse-0.3.0.dist-info/entry_points.txt,sha256=S2WxhPln7zXybKRE73ekBicXHh7_BX-KYGFZZaGGqp8,54
sqlparse-0.3.0.dist-info/top_level.txt,sha256=eRYisOR7d8EtLKXuWUUAAMOhODItOqrkpxkAGD8CISo,9
sqlparse-0.3.0.dist-info/RECORD,,
../../../bin/sqlformat,sha256=7AaJs39h263DC_lmnA7xmCchMGfKQN82n6LnsyjirRI,256
../../../bin/sqlformat,sha256=ok4bpX4qeThrS0hEgCdScLnCrSVUhqu3CQhFQVMp6K0,269
sqlparse-0.3.0.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
sqlparse/filters/__pycache__/output.cpython-37.pyc,,
sqlparse/filters/__pycache__/aligned_indent.cpython-37.pyc,,
+1 -1
View File
@@ -1 +1 @@
{"last_check":"2019-11-05T13:22:52Z","pypi_version":"19.3.1"}
{"last_check":"2019-11-19T13:10:17Z","pypi_version":"19.3.1"}