Compare commits
3 Commits
666b5e909a
...
b4415af0b8
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b4415af0b8 | ||
|
|
9be60fb7a4 | ||
|
|
65188e033e |
@ -1,3 +1,5 @@
|
|||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
from .models import Post
|
||||||
|
|
||||||
|
admin.site.register(Post)
|
||||||
# Register your models here.
|
# Register your models here.
|
||||||
|
|||||||
20
application/migrations/0002_post_tags.py
Normal file
20
application/migrations/0002_post_tags.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
# Generated by Django 2.0.6 on 2018-07-15 12:30
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
import taggit.managers
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('taggit', '0002_auto_20150616_2121'),
|
||||||
|
('application', '0001_initial'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='post',
|
||||||
|
name='tags',
|
||||||
|
field=taggit.managers.TaggableManager(help_text='A comma-separated list of tags.', through='taggit.TaggedItem', to='taggit.Tag', verbose_name='Tags'),
|
||||||
|
),
|
||||||
|
]
|
||||||
@ -6,8 +6,10 @@
|
|||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||||
<title> {% block title %}Seitenname{% endblock %}</title>
|
<title> {% block title %}Seitenname{% endblock %}</title>
|
||||||
<link href="{% static 'css/mysite.css' %}" rel="stylesheet">
|
<link href="{% static 'css/application.css' %}" rel="stylesheet">
|
||||||
<link href="{% static 'bootstrap/css/bootstrap.css' %}" rel="stylesheet">
|
<link href="{% static 'bootstrap/css/bootstrap.css' %}" rel="stylesheet">
|
||||||
|
<link href="{% static 'css/signin.css' %}" rel="stylesheet">
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
@ -31,8 +33,13 @@
|
|||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link" href="{% url 'admin:index' %}">Administration</a>
|
<a class="nav-link" href="{% url 'admin:index' %}">Administration</a>
|
||||||
</li>
|
</li>
|
||||||
{% endif %} {% if user.is_staff %}
|
{% elif user.is_staff %}
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="{% url 'logout' %}">Administration</a>
|
||||||
|
</li>
|
||||||
|
{% else %}
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link" href="{% url 'student_page' %}">My Page</a>
|
||||||
</li>
|
</li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</ul>
|
</ul>
|
||||||
@ -76,8 +83,13 @@
|
|||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
|
<div class="content container">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-md-8">
|
||||||
{% block content %} {% endblock %}
|
{% block content %} {% endblock %}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
|
<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>
|
<script src="{% static 'bootstrap/js/bootstrap.bundle.js' %}"></script>
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
@ -5,13 +5,13 @@
|
|||||||
{{ post.published_date }}
|
{{ post.published_date }}
|
||||||
</div>
|
</div>
|
||||||
{% else %}
|
{% else %}
|
||||||
<a class="btn btn-default" href="{% url 'post_publish' pk=post.pk %}">Publish</a>
|
<a class="btn btn-outline-dark" href="{% url 'post_publish' pk=post.pk %}">Publish</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<a class="btn btn-default" href="{% url 'post_edit' pk=post.pk %}">
|
<a class="btn btn-outline-dark" href="{% url 'post_edit' pk=post.pk %}">
|
||||||
<span class="glyphicon glyphicon-pencil"></span>
|
<span class="glyphicon glyphicon-pencil">Edit</span>
|
||||||
</a>
|
</a>
|
||||||
<a class="btn btn-default" href="{% url 'post_remove' pk=post.pk %}">
|
<a class="btn btn-outline-dark" href="{% url 'post_remove' pk=post.pk %}">
|
||||||
<span class="glyphicon glyphicon-remove"></span>
|
<span class="glyphicon glyphicon-remove">Remove</span>
|
||||||
</a>
|
</a>
|
||||||
<h1>{{ post.title }}</h1>
|
<h1>{{ post.title }}</h1>
|
||||||
<p>{{ post.text|linebreaksbr }}</p>
|
<p>{{ post.text|linebreaksbr }}</p>
|
||||||
|
|||||||
@ -4,6 +4,6 @@
|
|||||||
<h1>New post</h1>
|
<h1>New post</h1>
|
||||||
<form method="POST" class="post-form">{% csrf_token %}
|
<form method="POST" class="post-form">{% csrf_token %}
|
||||||
{{ form.as_p }}
|
{{ form.as_p }}
|
||||||
<button type="submit" class="save btn btn-default">Save</button>
|
<button type="submit" class="save btn btn-outline-dark">Save</button>
|
||||||
</form>
|
</form>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
@ -24,7 +24,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<input type="submit" value="login" />
|
<input type="submit" value="login" class="btn btn-lg btn-primary"/>
|
||||||
<input type="hidden" name="next" value="{{ next }}" />
|
<input type="hidden" name="next" value="{{ next }}" />
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
3
application/templates/student_page.html
Normal file
3
application/templates/student_page.html
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
{% block content %}
|
||||||
|
{% endblock %}
|
||||||
@ -3,6 +3,7 @@ from . import views
|
|||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^$', views.post_list, name='post_list'),
|
url(r'^$', views.post_list, name='post_list'),
|
||||||
|
url(r'^student/', views.student_page, name='student_page'),
|
||||||
url(r'^post/(?P<pk>\d+)/$', views.post_detail, name='post_detail'),
|
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/new/$', views.post_new, name='post_new'),
|
||||||
url(r'^post/(?P<pk>\d+)/edit/$', views.post_edit, name='post_edit'),
|
url(r'^post/(?P<pk>\d+)/edit/$', views.post_edit, name='post_edit'),
|
||||||
|
|||||||
@ -4,6 +4,7 @@ from .models import Post
|
|||||||
from .forms import PostForm
|
from .forms import PostForm
|
||||||
from django.shortcuts import redirect
|
from django.shortcuts import redirect
|
||||||
from django.contrib.auth.decorators import login_required
|
from django.contrib.auth.decorators import login_required
|
||||||
|
from django.contrib.admin.views.decorators import staff_member_required
|
||||||
from django.contrib.auth import authenticate, login, logout
|
from django.contrib.auth import authenticate, login, logout
|
||||||
import logging
|
import logging
|
||||||
import mysite.settings
|
import mysite.settings
|
||||||
@ -35,18 +36,19 @@ def navlogin(request):
|
|||||||
context = {'error': error}
|
context = {'error': error}
|
||||||
return render(request, 'index.html', context)
|
return render(request, 'index.html', context)
|
||||||
|
|
||||||
|
@login_required
|
||||||
def post_list(request):
|
def post_list(request):
|
||||||
posts = Post.objects.filter(
|
posts = Post.objects.filter(
|
||||||
published_date__lte=timezone.now()).order_by('published_date')
|
published_date__lte=timezone.now()).order_by('published_date')
|
||||||
return render(request, 'post_list.html', {'posts': posts})
|
return render(request, 'post_list.html', {'posts': posts})
|
||||||
|
|
||||||
|
@login_required
|
||||||
def post_detail(request, pk):
|
def post_detail(request, pk):
|
||||||
post = get_object_or_404(Post, pk=pk)
|
post = get_object_or_404(Post, pk=pk)
|
||||||
return render(request, 'post_detail.html', {'post': post})
|
return render(request, 'post_detail.html', {'post': post})
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
|
@staff_member_required
|
||||||
def post_new(request):
|
def post_new(request):
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
form = PostForm(request.POST)
|
form = PostForm(request.POST)
|
||||||
@ -60,6 +62,7 @@ def post_new(request):
|
|||||||
return render(request, 'post_edit.html', {'form': form})
|
return render(request, 'post_edit.html', {'form': form})
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
|
@staff_member_required
|
||||||
def post_edit(request, pk):
|
def post_edit(request, pk):
|
||||||
post = get_object_or_404(Post, pk=pk)
|
post = get_object_or_404(Post, pk=pk)
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
@ -74,19 +77,26 @@ def post_edit(request, pk):
|
|||||||
return render(request, 'post_edit.html', {'form': form})
|
return render(request, 'post_edit.html', {'form': form})
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
|
@staff_member_required
|
||||||
def post_draft_list(request):
|
def post_draft_list(request):
|
||||||
posts = Post.objects.filter(
|
posts = Post.objects.filter(
|
||||||
published_date__isnull=True).order_by('created_date')
|
published_date__isnull=True).order_by('created_date')
|
||||||
return render(request, 'post_draft_list.html', {'posts': posts})
|
return render(request, 'post_draft_list.html', {'posts': posts})
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
|
@staff_member_required
|
||||||
def post_publish(request, pk):
|
def post_publish(request, pk):
|
||||||
post = get_object_or_404(Post, pk=pk)
|
post = get_object_or_404(Post, pk=pk)
|
||||||
post.publish()
|
post.publish()
|
||||||
return redirect('post_detail', pk=pk)
|
return redirect('post_detail', pk=pk)
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
|
@staff_member_required
|
||||||
def post_remove(request, pk):
|
def post_remove(request, pk):
|
||||||
post = get_object_or_404(Post, pk=pk)
|
post = get_object_or_404(Post, pk=pk)
|
||||||
post.delete()
|
post.delete()
|
||||||
return redirect('post_list')
|
return redirect('post_list')
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
def student_page(request):
|
||||||
|
return render(request, 'student_page.html', {})
|
||||||
|
|||||||
@ -43,8 +43,8 @@ INSTALLED_APPS = [
|
|||||||
'django.contrib.sessions',
|
'django.contrib.sessions',
|
||||||
'django.contrib.messages',
|
'django.contrib.messages',
|
||||||
'django.contrib.staticfiles',
|
'django.contrib.staticfiles',
|
||||||
'taggit',
|
|
||||||
'application',
|
'application',
|
||||||
|
'taggit',
|
||||||
]
|
]
|
||||||
|
|
||||||
MIDDLEWARE = [
|
MIDDLEWARE = [
|
||||||
|
|||||||
@ -23,8 +23,8 @@ import application.views
|
|||||||
|
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^$', TemplateView.as_view(template_name="index.html")),
|
|
||||||
url(r'^admin/', admin.site.urls),
|
url(r'^admin/', admin.site.urls),
|
||||||
url(r'^navlogin/', application.views.navlogin, name='navlogin'),
|
url(r'^navlogin/', application.views.navlogin, name='navlogin'),
|
||||||
url(r'^accounts/', include('django.contrib.auth.urls')),
|
url(r'^accounts/', include('django.contrib.auth.urls')),
|
||||||
|
url(r'', include('application.urls'))
|
||||||
]
|
]
|
||||||
Loading…
x
Reference in New Issue
Block a user