added medinf login and fixed navlogin issues
This commit is contained in:
parent
0bc13ada46
commit
b5eb32c843
9
application/forms.py
Normal file
9
application/forms.py
Normal file
@ -0,0 +1,9 @@
|
||||
from django import forms
|
||||
|
||||
from .models import Post
|
||||
|
||||
class PostForm(forms.ModelForm):
|
||||
|
||||
class Meta:
|
||||
model = Post
|
||||
fields = ('title', 'text')
|
29
application/migrations/0001_initial.py
Normal file
29
application/migrations/0001_initial.py
Normal file
@ -0,0 +1,29 @@
|
||||
# Generated by Django 2.0.6 on 2018-06-28 09:13
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
import django.utils.timezone
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Post',
|
||||
fields=[
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('title', models.CharField(max_length=200)),
|
||||
('text', models.TextField()),
|
||||
('created_date', models.DateTimeField(default=django.utils.timezone.now)),
|
||||
('published_date', models.DateTimeField(blank=True, null=True)),
|
||||
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
|
||||
],
|
||||
),
|
||||
]
|
46
application/static/css/application.css
Normal file
46
application/static/css/application.css
Normal file
@ -0,0 +1,46 @@
|
||||
#navbar-efi {
|
||||
background-color: #ffe240;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
/* Login Dropdown */
|
||||
|
||||
#login-dp{
|
||||
min-width: 250px;
|
||||
padding: 14px 14px 0;
|
||||
overflow:hidden;
|
||||
background-color:rgba(255,255,255,.8);
|
||||
}
|
||||
#login-dp .bottom{
|
||||
background-color:rgba(255,255,255,.8);
|
||||
border-top:1px solid #ddd;
|
||||
clear:both;
|
||||
padding:14px;
|
||||
}
|
||||
#login-dp .form-group {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
#login-button {
|
||||
text-align: right;
|
||||
min-width: 250px;
|
||||
}
|
||||
|
||||
|
||||
#login-button:focus {
|
||||
border-color: rgba(0, 0, 0, 0.8);
|
||||
box-shadow: 0 10px 10px rgba(0, 0, 0, 0.075) inset, 0 0 8px rgba(126, 239, 104, 0.6);
|
||||
outline: 0 none;
|
||||
}
|
||||
|
||||
|
||||
@media(max-width:768px){
|
||||
#login-dp{
|
||||
background-color: inherit;
|
||||
color: #fff;
|
||||
}
|
||||
#login-dp .bottom{
|
||||
background-color: inherit;
|
||||
border-top:0 none;
|
||||
}
|
||||
}
|
85
application/templates/base.html
Normal file
85
application/templates/base.html
Normal file
@ -0,0 +1,85 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="de">
|
||||
{% load static %}
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||
<title> {% block title %}Seitenname{% endblock %}</title>
|
||||
<link href="{% static 'css/application.css' %}" rel="stylesheet">
|
||||
<link href="{% static 'bootstrap/css/bootstrap.css' %}" rel="stylesheet">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
|
||||
<!-- Navigation -->
|
||||
<nav id="navbar-efi" class="navbar navbar-expand-lg navbar-light">
|
||||
|
||||
<a class="navbar-brand" href="#">
|
||||
<img src="{% static 'images/efi.jpg' %}" width="35" height="35" alt="efi">
|
||||
</a>
|
||||
|
||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent"
|
||||
aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
||||
<div class="collapse navbar-collapse" id="navbarSupportedContent">
|
||||
<ul class="navbar-nav mr-auto">
|
||||
{% if user.is_superuser %}
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{% url 'admin:index' %}">Administration</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% if user.is_staff %}
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{% url 'studis:index' %}">Stammdaten</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
|
||||
<ul class="nav navbar-nav navbar-right">
|
||||
{% if user.is_authenticated %}
|
||||
<li class="nav-item">
|
||||
<a class="nav-link disabled" href="#">{{ user.first_name }} {{ user.last_name }}</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{% url 'logout' %}?next={{ LOGOUT_REDIRECT_URL }}">Abmelden</a>
|
||||
</li>
|
||||
{% else %}
|
||||
<li class="dropdown">
|
||||
<a id="login-button" href="#" class="dropdown-toggle nav-link" data-toggle="dropdown">
|
||||
Anmelden<span class="caret"></span>
|
||||
</a>
|
||||
<ul id="login-dp" class="dropdown-menu">
|
||||
<li>
|
||||
<form class="form" role="form" method="post" action="{% url 'navlogin' %}" accept-charset="UTF-8" id="login-nav">
|
||||
{% csrf_token %}
|
||||
{% if next %}
|
||||
<input type="hidden" name="next" value="{{ next }}" />
|
||||
{% endif %}
|
||||
<div class="form-group">
|
||||
<label class="sr-only" for="username">Benutzername</label>
|
||||
<input type="text" class="form-control" id="username" name="username" placeholder="Benutzername" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label class="sr-only" for="password">Kennwort</label>
|
||||
<input type="password" class="form-control" id="password" name="password" placeholder="Kennwort" required>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<button type="submit" class="btn btn-primary btn-block">Anmelden</button>
|
||||
</div>
|
||||
</form>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
{% block content %} {% endblock %}
|
||||
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
|
||||
<script src="{% static 'bootstrap/js/bootstrap.bundle.js' %}"></script>
|
||||
</body>
|
||||
</html>
|
23
application/templates/index.html
Normal file
23
application/templates/index.html
Normal file
@ -0,0 +1,23 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<div class="container">
|
||||
<div class="jumbotron">
|
||||
<h1>efi Medizintechnik Informationssystem</h1>
|
||||
{% if user.is_authenticated %}
|
||||
<p>Herzlich Willkommen!</p>
|
||||
{% else %}
|
||||
<p>Bitte melden Sie sich mit Ihrer Domänenkennung an.</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
{% if error %}
|
||||
<div class="alert alert-danger">
|
||||
{{ error }}
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
19
application/templates/post_detail.html
Normal file
19
application/templates/post_detail.html
Normal file
@ -0,0 +1,19 @@
|
||||
{% extends 'base.html' %} {% block content %}
|
||||
<div class="post">
|
||||
{% if post.published_date %}
|
||||
<div class="date">
|
||||
{{ post.published_date }}
|
||||
</div>
|
||||
{% else %}
|
||||
<a class="btn btn-default" href="{% url 'post_publish' pk=post.pk %}">Publish</a>
|
||||
{% endif %}
|
||||
<a class="btn btn-default" href="{% url 'post_edit' pk=post.pk %}">
|
||||
<span class="glyphicon glyphicon-pencil"></span>
|
||||
</a>
|
||||
<a class="btn btn-default" href="{% url 'post_remove' pk=post.pk %}">
|
||||
<span class="glyphicon glyphicon-remove"></span>
|
||||
</a>
|
||||
<h1>{{ post.title }}</h1>
|
||||
<p>{{ post.text|linebreaksbr }}</p>
|
||||
</div>
|
||||
{% endblock %}
|
11
application/templates/post_draft_list.html
Normal file
11
application/templates/post_draft_list.html
Normal file
@ -0,0 +1,11 @@
|
||||
{% extends 'base.html' %}
|
||||
|
||||
{% block content %}
|
||||
{% for post in posts %}
|
||||
<div class="post">
|
||||
<p class="date">created: {{ post.created_date|date:'d-m-Y' }}</p>
|
||||
<h1><a href="{% url 'post_detail' pk=post.pk %}">{{ post.title }}</a></h1>
|
||||
<p>{{ post.text|truncatechars:200 }}</p>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endblock %}
|
9
application/templates/post_edit.html
Normal file
9
application/templates/post_edit.html
Normal file
@ -0,0 +1,9 @@
|
||||
{% extends 'base.html' %}
|
||||
|
||||
{% block content %}
|
||||
<h1>New post</h1>
|
||||
<form method="POST" class="post-form">{% csrf_token %}
|
||||
{{ form.as_p }}
|
||||
<button type="submit" class="save btn btn-default">Save</button>
|
||||
</form>
|
||||
{% endblock %}
|
11
application/templates/post_list.html
Normal file
11
application/templates/post_list.html
Normal file
@ -0,0 +1,11 @@
|
||||
{% extends 'base.html' %} {% block content %} {% for post in posts %}
|
||||
<div class="post">
|
||||
<div class="date">
|
||||
{{ post.published_date }}
|
||||
</div>
|
||||
<h1>
|
||||
<a href="{% url 'post_detail' pk=post.pk %}">{{ post.title }}</a>
|
||||
</h1>
|
||||
<p>{{ post.text|linebreaks }}</p>
|
||||
</div>
|
||||
{% endfor %} {% endblock %}
|
27
application/templates/registration/login.html
Normal file
27
application/templates/registration/login.html
Normal file
@ -0,0 +1,27 @@
|
||||
{% extends "base.html" %} {% block content %} {% if form.errors %}
|
||||
<p>Your username and password didn't match. Please try again.</p>
|
||||
{% endif %} {% 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>
|
||||
<td>{{ form.username.label_tag }}</td>
|
||||
<td>{{ form.username }}</td>
|
||||
</div>
|
||||
<div>
|
||||
<td>{{ form.password.label_tag }}</td>
|
||||
<td>{{ form.password }}</td>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<input type="submit" value="login" />
|
||||
<input type="hidden" name="next" value="{{ next }}" />
|
||||
</div>
|
||||
</form>
|
||||
|
||||
{% endblock %}
|
12
application/urls.py
Normal file
12
application/urls.py
Normal file
@ -0,0 +1,12 @@
|
||||
from django.conf.urls import url
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^$', views.post_list, name='post_list'),
|
||||
url(r'^post/(?P<pk>\d+)/$', views.post_detail, name='post_detail'),
|
||||
url(r'^post/new/$', views.post_new, name='post_new'),
|
||||
url(r'^post/(?P<pk>\d+)/edit/$', views.post_edit, name='post_edit'),
|
||||
url(r'^drafts/$', views.post_draft_list, name='post_draft_list'),
|
||||
url(r'^post/(?P<pk>\d+)/publish/$', views.post_publish, name='post_publish'),
|
||||
url(r'^post/(?P<pk>\d+)/remove/$', views.post_remove, name='post_remove'),
|
||||
]
|
@ -1,3 +1,92 @@
|
||||
from django.shortcuts import render
|
||||
from django.shortcuts import render, get_object_or_404
|
||||
from django.utils import timezone
|
||||
from .models import Post
|
||||
from .forms import PostForm
|
||||
from django.shortcuts import redirect
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.contrib.auth import authenticate, login, logout
|
||||
import logging
|
||||
import mysite.settings
|
||||
|
||||
|
||||
# Create your views here.
|
||||
|
||||
|
||||
def navlogin(request):
|
||||
|
||||
log = logging.getLogger('medinf')
|
||||
logout(request)
|
||||
error = ""
|
||||
if request.POST:
|
||||
username = request.POST.get("username", "?")
|
||||
password = request.POST.get("password", "?")
|
||||
|
||||
user = authenticate(username=username, password=password)
|
||||
if user is not None:
|
||||
if user.is_active:
|
||||
login(request, user)
|
||||
return redirect(mysite.settings.LOGIN_REDIRECT_URL)
|
||||
else:
|
||||
log.info("Inactive user {} tried to login".format(username))
|
||||
error = "Ihre Benutzerkennung wurde deaktiviert."
|
||||
else:
|
||||
log.info("Login failed for {}".format(username))
|
||||
error = "Benutzername oder Kennwort falsch."
|
||||
context = {'error': error}
|
||||
return render(request, 'index.html', context)
|
||||
|
||||
|
||||
def post_list(request):
|
||||
posts = Post.objects.filter(
|
||||
published_date__lte=timezone.now()).order_by('published_date')
|
||||
return render(request, 'post_list.html', {'posts': posts})
|
||||
|
||||
|
||||
def post_detail(request, pk):
|
||||
post = get_object_or_404(Post, pk=pk)
|
||||
return render(request, 'post_detail.html', {'post': post})
|
||||
|
||||
@login_required
|
||||
def post_new(request):
|
||||
if request.method == "POST":
|
||||
form = PostForm(request.POST)
|
||||
if form.is_valid():
|
||||
post = form.save(commit=False)
|
||||
post.author = request.user
|
||||
post.save()
|
||||
return redirect('post_detail', pk=post.pk)
|
||||
else:
|
||||
form = PostForm()
|
||||
return render(request, 'post_edit.html', {'form': form})
|
||||
|
||||
@login_required
|
||||
def post_edit(request, pk):
|
||||
post = get_object_or_404(Post, pk=pk)
|
||||
if request.method == "POST":
|
||||
form = PostForm(request.POST, instance=post)
|
||||
if form.is_valid():
|
||||
post = form.save(commit=False)
|
||||
post.author = request.user
|
||||
post.save()
|
||||
return redirect('post_detail', pk=post.pk)
|
||||
else:
|
||||
form = PostForm(instance=post)
|
||||
return render(request, 'post_edit.html', {'form': form})
|
||||
|
||||
@login_required
|
||||
def post_draft_list(request):
|
||||
posts = Post.objects.filter(
|
||||
published_date__isnull=True).order_by('created_date')
|
||||
return render(request, 'post_draft_list.html', {'posts': posts})
|
||||
|
||||
@login_required
|
||||
def post_publish(request, pk):
|
||||
post = get_object_or_404(Post, pk=pk)
|
||||
post.publish()
|
||||
return redirect('post_detail', pk=pk)
|
||||
|
||||
@login_required
|
||||
def post_remove(request, pk):
|
||||
post = get_object_or_404(Post, pk=pk)
|
||||
post.delete()
|
||||
return redirect('post_list')
|
||||
|
@ -14,8 +14,17 @@ Including another URLconf
|
||||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
|
||||
"""
|
||||
from django.contrib import admin
|
||||
from django.urls import path
|
||||
from django.conf.urls import include, url
|
||||
|
||||
from django.contrib.auth import views
|
||||
import application.views
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
path('admin/', admin.site.urls),
|
||||
url(r'^admin/', admin.site.urls),
|
||||
url(r'^navlogin/', application.views.navlogin, name='navlogin'),
|
||||
url(r'^accounts/login/$', views.login, name='login'),
|
||||
url(r'^accounts/logout/$', views.logout,
|
||||
name='logout', kwargs={'next_page': '/'}),
|
||||
url(r'', include('application.urls')),
|
||||
]
|
||||
|
Loading…
x
Reference in New Issue
Block a user