praktikum Aufgabe7 * Style geändert
This commit is contained in:
parent
dd08dc74f6
commit
f91294bf07
@ -37,7 +37,8 @@ INSTALLED_APPS = [
|
|||||||
'django.contrib.sessions',
|
'django.contrib.sessions',
|
||||||
'django.contrib.messages',
|
'django.contrib.messages',
|
||||||
'django.contrib.staticfiles',
|
'django.contrib.staticfiles',
|
||||||
'posts.apps.PostsConfig'
|
'posts.apps.PostsConfig',
|
||||||
|
'rest_framework'
|
||||||
]
|
]
|
||||||
|
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
|
@ -21,5 +21,5 @@ from posts import views
|
|||||||
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'))
|
||||||
]
|
]
|
||||||
|
10
posts/serializers.py
Normal file
10
posts/serializers.py
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
from rest_framework import serializers
|
||||||
|
|
||||||
|
from posts.models import Notice
|
||||||
|
|
||||||
|
|
||||||
|
class NoticeSerializer(serializers.ModelSerializer):
|
||||||
|
class Meta:
|
||||||
|
model = Notice
|
||||||
|
fields = ('id', 'notice_title', 'notice_text', 'pub_start', 'pub_end')
|
||||||
|
|
@ -1,11 +1,14 @@
|
|||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
<h1>Neue Nachricht</h1>
|
<h1>Neue Nachricht</h1>
|
||||||
<form method="POST">
|
<form method="POST">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
{{ form.as_p }}
|
{{ form.as_p }}
|
||||||
<button type="submit" class="save btn btn-default">Speichern</button>
|
<button type="submit" class="save btn btn-default">Speichern</button>
|
||||||
</form>
|
</form>
|
||||||
|
{% if user.is_authenticated %}
|
||||||
|
<p><a href="{% url 'logout' %}?next=/posts/home"
|
||||||
|
class="btn btn-warning">Abmelden</a></p>
|
||||||
|
{% endif %}
|
||||||
{% endblock %}
|
{% endblock %}
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
|
|
||||||
<div class="card w-100">
|
<div class="card w-100">
|
||||||
<div class="card-body">
|
<div class="card-body jumbotron" style="background: ghostwhite">
|
||||||
{% for notice in allnotice %}
|
{% for notice in allnotice %}
|
||||||
<h5 class="card-title">{{ notice.notice_title }}</h5>
|
<h5 class="card-title">{{ notice.notice_title }}</h5>
|
||||||
<p class="card-text">{{ notice.notice_text |linebreaks }}</p>
|
<p class="card-text">{{ notice.notice_text |linebreaks }}</p>
|
||||||
@ -18,3 +18,9 @@
|
|||||||
|
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.test{
|
||||||
|
background-color: darkgray;
|
||||||
|
}
|
||||||
|
</style>
|
32
posts/templates/registration/login.html
Normal file
32
posts/templates/registration/login.html
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
{% extends 'base.html' %}
|
||||||
|
{% block title %}
|
||||||
|
Login
|
||||||
|
{% endblock %}
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
{% if next %}
|
||||||
|
{% if user.is_authenticated %}
|
||||||
|
<p>Your account doesn't have access to this page. To proceed,
|
||||||
|
please login with an account that has access.</p>
|
||||||
|
{% else %}
|
||||||
|
<p>Please login to see this page.</p>
|
||||||
|
{% endif %}
|
||||||
|
{% endif %}
|
||||||
|
<form method="post" action="{% url 'login' %}">
|
||||||
|
{% csrf_token %}
|
||||||
|
<div>
|
||||||
|
<tb>{{ form.username.label_tag }}</tb>
|
||||||
|
<p>{{ form.username }}</p>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<p>{{ form.password.label_tag }}</p>
|
||||||
|
<p>{{ form.password }}</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<input type="submit" value="login"/>
|
||||||
|
<input type="hidden" name="next" value="{{ next }}"/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</form>
|
||||||
|
{% endblock %}
|
@ -8,5 +8,7 @@ urlpatterns = [
|
|||||||
path('home', views.welcome_seite),
|
path('home', views.welcome_seite),
|
||||||
path('about', views.about_seite),
|
path('about', views.about_seite),
|
||||||
url(r'^new', views.new, name='new'),
|
url(r'^new', views.new, name='new'),
|
||||||
path('delete/<int:deleteId>', views.delete, name ='delete')
|
path('delete/<int:deleteId>', views.delete, name ='delete'),
|
||||||
|
path('notices', views.notice_list),
|
||||||
|
path('notices/<int:id>', views.notice_detail)
|
||||||
]
|
]
|
@ -1,11 +1,18 @@
|
|||||||
from django.http import HttpResponse
|
from django.contrib.admin.views.decorators import staff_member_required
|
||||||
|
from django.contrib.auth.decorators import login_required
|
||||||
|
from django.http import HttpResponse, JsonResponse
|
||||||
from django.shortcuts import render, redirect
|
from django.shortcuts import render, redirect
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
from django.views.decorators.csrf import csrf_exempt
|
||||||
|
from rest_framework.parsers import JSONParser
|
||||||
|
|
||||||
from posts.forms import NoticeForm
|
from posts.forms import NoticeForm
|
||||||
from posts.models import Notice
|
from posts.models import Notice
|
||||||
|
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
|
from posts.serializers import NoticeSerializer
|
||||||
|
|
||||||
|
|
||||||
def index(request):
|
def index(request):
|
||||||
notices = Notice.objects.all()
|
notices = Notice.objects.all()
|
||||||
notices = notices.filter(pub_start__lte=timezone.now())
|
notices = notices.filter(pub_start__lte=timezone.now())
|
||||||
@ -18,6 +25,8 @@ def welcome_seite(request):
|
|||||||
def about_seite(request):
|
def about_seite(request):
|
||||||
return render(request, 'posts/about.html')
|
return render(request, 'posts/about.html')
|
||||||
|
|
||||||
|
|
||||||
|
@login_required
|
||||||
def new(request):
|
def new(request):
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
form = NoticeForm(request.POST)
|
form = NoticeForm(request.POST)
|
||||||
@ -32,9 +41,48 @@ def new(request):
|
|||||||
return render(request, 'posts/edit.html', context)
|
return render(request, 'posts/edit.html', context)
|
||||||
|
|
||||||
|
|
||||||
|
@staff_member_required
|
||||||
def delete(request, deleteId = None):
|
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:
|
||||||
delNotice.delete()
|
delNotice.delete()
|
||||||
return redirect('index')
|
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)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -11,21 +11,24 @@
|
|||||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
|
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
|
||||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
|
||||||
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
|
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
|
||||||
|
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
|
||||||
|
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
|
||||||
|
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
|
||||||
<title>{% block title %}First Django Application{% endblock %}</title>
|
<title>{% block title %}First Django Application{% endblock %}</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<nav>
|
<nav>
|
||||||
{% block nav %}
|
{% block nav %}
|
||||||
<nav class="navbar navbar-expand-sm bg-dark navbar-dark">
|
<nav class="navbar navbar-expand-sm bg-info navbar-dark">
|
||||||
<ul class="navbar-nav">
|
<ul class="navbar-nav">
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link" href="/posts/home">Home</a>
|
<a class="nav-link" href="/posts/home">Home</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link" href="https://www.google.de/?hl=de">google</a>
|
<a class="nav-link" href="https://www.google.de/?hl=de" target="_blank">google</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link" href="https://www.th-nuernberg.de/fakultaeten/efi/">Efi</a>
|
<a class="nav-link" href="https://www.th-nuernberg.de/fakultaeten/efi/" target="_blank">Efi</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link" href="/posts/about">about</a>
|
<a class="nav-link" href="/posts/about">about</a>
|
||||||
@ -34,6 +37,7 @@
|
|||||||
<a class="nav-link" href="/posts/notice">notice</a>
|
<a class="nav-link" href="/posts/notice">notice</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
</nav>
|
</nav>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
</nav>
|
</nav>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user