Compare commits

...
7 Commits
Author SHA1 Message Date
pouanideumassse68079 c97f4b9c7f Praktikum8 2019-12-10 15:33:46 +01:00
pouanideumassse68079 d3fc3d5e39 Praktikum8 2019-12-03 16:29:45 +01:00
pouanideumassse68079 10d2dabced Praktikum8 2019-12-03 16:27:31 +01:00
pouanideumassse68079 76d25a6370 Praktikum8 2019-12-03 15:29:40 +01:00
pouanideumassse68079 f434511bd0 djangoprojekt 2019-11-26 15:56:12 +01:00
pouanideumassse68079 7acbbe32c3 djangoprojekt 2019-11-19 17:04:37 +01:00
pouanideumassse68079 e6b64e7877 djangoprojekt 2019-11-14 12:51:47 +01:00
18 changed files with 233 additions and 8 deletions

No files matched your search

+4
View File
@@ -0,0 +1,4 @@
db.sqlite3
bin/*
venv/*
lib/*
+3
View File
@@ -1,3 +1,6 @@
# Default ignored files # Default ignored files
/workspace.xml /workspace.xml
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
+22
View File
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
<data-source source="LOCAL" name="db" uuid="d9ef4968-0bb1-40c4-8bac-a12a0fb7e9f1">
<driver-ref>sqlite.xerial</driver-ref>
<synchronize>true</synchronize>
<jdbc-driver>org.sqlite.JDBC</jdbc-driver>
<jdbc-url>jdbc:sqlite:$PROJECT_DIR$/db.sqlite3</jdbc-url>
<driver-properties>
<property name="enable_load_extension" value="true" />
</driver-properties>
<libraries>
<library>
<url>file://$APPLICATION_CONFIG_DIR$/jdbc-drivers/Xerial SQLiteJDBC/3.25.1/sqlite-jdbc-3.25.1.jar</url>
</library>
<library>
<url>file://$APPLICATION_CONFIG_DIR$/jdbc-drivers/Xerial SQLiteJDBC/3.25.1/license.txt</url>
</library>
</libraries>
</data-source>
</component>
</project>
BIN
View File
Binary file not shown.
View File
Whitespace-only changes.
+7 -1
View File
@@ -38,6 +38,10 @@ INSTALLED_APPS = [
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'posts', 'posts',
'rest_framework',
'channels',
'django_eventstream',
] ]
MIDDLEWARE = [ MIDDLEWARE = [
@@ -48,6 +52,7 @@ 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'
] ]
ROOT_URLCONF = 'news1.urls' ROOT_URLCONF = 'news1.urls'
@@ -70,6 +75,7 @@ TEMPLATES = [
] ]
WSGI_APPLICATION = 'news1.wsgi.application' WSGI_APPLICATION = 'news1.wsgi.application'
ASGI_APPLICATION = 'news1.routing.application'
# Database # Database
@@ -105,7 +111,7 @@ AUTH_PASSWORD_VALIDATORS = [
# Internationalization # Internationalization
# https://docs.djangoproject.com/en/2.2/topics/i18n/ # https://docs.djangoproject.com/en/2.2/topics/i18n/
LANGUAGE_CODE = 'en-us' LANGUAGE_CODE = 'de-de'
TIME_ZONE = 'UTC' TIME_ZONE = 'UTC'
+2
View File
@@ -18,5 +18,7 @@ from django.urls import path, include
urlpatterns = [ urlpatterns = [
path('posts/' , include('posts.urls')), path('posts/' , include('posts.urls')),
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
path('accounts/' , include('django.contrib.auth.urls')),
] ]
+12
View File
@@ -0,0 +1,12 @@
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-12 12:46
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()),
],
),
]
+11 -1
View File
@@ -1,3 +1,13 @@
from django.db import models from django.db import models
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()
# Create your models here.
+7
View File
@@ -0,0 +1,7 @@
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')
+11
View File
@@ -0,0 +1,11 @@
{% extends 'base.html'%}
{% block content %}
<h1>Neue Nachricht</h1>
<form method="POST">
{% csrf_token %}
{{ form.as_p }}
<button type="submit" class="save btn btn-default">Speichern</button>
</form>
{% endblock %}
+1 -1
View File
@@ -8,7 +8,7 @@
<p class="lead">Hier ist meine Internet Seite Aufgrung mein Projektarbeit für der Winter Semester 2019.</p> <p class="lead">Hier ist meine Internet Seite Aufgrung mein Projektarbeit für der Winter Semester 2019.</p>
<hr class="my-4"> <hr class="my-4">
<p>Und der Bericht wird am ende der Semester abgegeben werden und danach vorgetragen.</p> <p>Und der Bericht wird am ende der Semester abgegeben werden und danach vorgetragen.</p>
<a class="btn btn-primary btn-lg" href="#" role="button">Return</a> <a class="btn btn-primary btn-lg" href="http://www.google.de" role="button">Weiter</a>
</div> </div>
<h1>Index der posts Applikation</h1> <h1>Index der posts Applikation</h1>
{% endblock %} {% endblock %}
+26
View File
@@ -0,0 +1,26 @@
{% extends 'base.html'%}
{% block content %}
<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 löschen</a></p>
<hr>
{% endfor %}
<p><a href="{% url 'new' %}" class="btn btn-info" role="button">Neue Nachricht</a></p>
<p><a href="{% url 'logout' %}" class="btn btn-warning">Abmelden</a></p>
</div>
<script>
var es = new ReconnectingEventSource('/events/');
es.addEventListener('message',function(e) {
console.log(e.data); location.reload();false
})
</script>
{% endblock %}
+6 -1
View File
@@ -1,6 +1,11 @@
from django.urls import path from django.urls import path
from.import views from.import views
urlpatterns =[ 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),
] ]
+71 -3
View File
@@ -1,6 +1,74 @@
from django.shortcuts import render from django.contrib.auth.decorators import login_required
from django.shortcuts import render, redirect
from django.views.decorators.csrf import csrf_exempt
from django_eventstream import send_event
from rest_framework.parsers import JSONParser
from posts.forms import NoticeForm
from posts.serializers import NoticeSerializer
from.models import Notice
from django.utils import timezone
from django.http import HttpResponse, JsonResponse
# Create your views here.
def index(request): def index(request):
return render(request, 'posts/index.html') 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/notice.html', context)
@login_required
def new(request):
if request.method == "POST":
form = NoticeForm(request.POST)
if form.is_valid():
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('index')
context = {'form': NoticeForm()}
return render(request, 'posts/edit.html', context)
def delete(request, deleteId=None):
if deleteId !=None:
delNotice= Notice.objects.get(id=deleteId)
if delNotice!= None:
delNotice.delete()
send_event('notice', 'message', deleteId)
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=201)
@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 -1
View File
@@ -1,6 +1,9 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="fr"> <html lang="fr">
<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="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">
@@ -38,7 +41,7 @@
Dropdown Dropdown
</a> </a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown"> <div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="#">Action</a> <a class="dropdown-item" href="http://www.kavo.com">Kavo</a>
<a class="dropdown-item" href="#">Another action</a> <a class="dropdown-item" href="#">Another action</a>
<div class="dropdown-divider"></div> <div class="dropdown-divider"></div>
<a class="dropdown-item" href="#">Something else here</a> <a class="dropdown-item" href="#">Something else here</a>
+22
View File
@@ -0,0 +1,22 @@
{% extends 'base.html' %}
{% block title %}
{% if user.is_authenticated %}
<p><a href="{% url 'logout' %}?next=/posts"
class="btn btn-warning">Abmelden</a></p>
{% endif %}
Login
{% endblock %}
{% block content %}
<form method="post" action="{% url 'login' %}">
{% csrf_token %}
Benutzername: {{ form.username }} <br>
Passwort: {{ form.password }} <br>
<button type="submit" class="btn btn-default">Anmelden</button>
<input type="hidden" name="next" value="{{ next }}"/>
</form>
{% endblock %}