Compare commits
4 Commits
5a30a0adea
...
e78011daca
Author | SHA1 | Date | |
---|---|---|---|
![]() |
e78011daca | ||
![]() |
768a3e4a2e | ||
![]() |
6cdbec7315 | ||
![]() |
b8a6c16ac2 |
@ -6,7 +6,7 @@ from django.contrib.auth.forms import UserCreationForm, UserChangeForm
|
||||
class PostForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Post
|
||||
fields = ('title', 'text', 'published_date', 'tags')
|
||||
fields = ('title', 'text', 'published_date','tags')
|
||||
|
||||
class NewTagForm(forms.ModelForm):
|
||||
m_tags = TagField()
|
||||
|
20
application/migrations/0003_auto_20180830_1814.py
Normal file
20
application/migrations/0003_auto_20180830_1814.py
Normal file
@ -0,0 +1,20 @@
|
||||
# Generated by Django 2.1 on 2018-08-30 16:14
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('application', '0002_auto_20180818_1734'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='customuser',
|
||||
name='user',
|
||||
field=models.OneToOneField(default=None, null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
|
||||
),
|
||||
]
|
20
application/migrations/0004_auto_20180831_1019.py
Normal file
20
application/migrations/0004_auto_20180831_1019.py
Normal file
@ -0,0 +1,20 @@
|
||||
# Generated by Django 2.1 on 2018-08-31 08:19
|
||||
|
||||
from django.conf import settings
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('application', '0003_auto_20180830_1814'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='customuser',
|
||||
name='user',
|
||||
field=models.OneToOneField(null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
|
||||
),
|
||||
]
|
@ -4,7 +4,7 @@ from django.utils import timezone
|
||||
from taggit.managers import TaggableManager
|
||||
|
||||
class CustomUser(models.Model):
|
||||
user = models.OneToOneField(User, null = True, on_delete=models.CASCADE)
|
||||
user = models.OneToOneField('auth.User', null = True, on_delete=models.CASCADE)
|
||||
tags = TaggableManager()
|
||||
|
||||
|
||||
|
@ -31,10 +31,20 @@
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{% url 'admin:index' %}">Administration</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="nav-link" href="{% url 'post_list' %}">Dashboard</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{% url 'student_page' %}">Studentenansicht</a>
|
||||
</li>
|
||||
{% elif user.is_staff %}
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{% url 'logout' %}">Administration</a>
|
||||
</li>
|
||||
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{% url 'post_list' %}">Dashboard</a>
|
||||
</li>
|
||||
{% else %}
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{% url 'student_page' %}">{{user.get_username}}'s Dashboard</a>
|
||||
@ -60,8 +70,7 @@
|
||||
<li>
|
||||
<form class="form" role="form" method="post" action="{% url 'login' %}" accept-charset="UTF-8" id="login-nav">
|
||||
{% csrf_token %} {% if next %}
|
||||
<input type="hidden" name="next" value="{{ next }}" />
|
||||
{% endif %}
|
||||
<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>
|
||||
@ -92,7 +101,7 @@
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
|
||||
<script src="{% static 'bootstrap/js/jquery-1.11.1.js' %} "></script>
|
||||
<script src="{% static 'bootstrap/jsjquery.tagcanvas.min.js' %} " type="text/javascript"></script>
|
||||
<script src="{% static 'js/app.js' %}"></script>
|
||||
<script src="{% static 'js/app.js' %}"></script>
|
||||
<script src="{% static 'bootstrap/js/bootstrap.bundle.js' %}"></script>
|
||||
</body>
|
||||
|
||||
|
@ -1,4 +1,6 @@
|
||||
{% extends 'base.html' %} {% block content %} {% for post in posts %} {% load taggit_templatetags2_tags %}
|
||||
{% extends 'base.html' %} {% block content %}
|
||||
{% if tag %} Posts tagged with "{{ tag.name }}" {% endif %}
|
||||
{% for post in posts %}
|
||||
<div class="post">
|
||||
<div class="date">
|
||||
{{ post.published_date }}
|
||||
@ -7,15 +9,11 @@
|
||||
<a href="{% url 'post_detail' pk=post.pk %}">{{ post.title }}</a>
|
||||
</h1>
|
||||
<p>{{ post.text|linebreaks }}</p>
|
||||
<p>
|
||||
{% for tag in post.tags.all %}
|
||||
<a href="">{{ tag.name }}, </a>
|
||||
{% endfor %}
|
||||
</p>
|
||||
<p>
|
||||
Tags: {% for tag in post.tags.all %}
|
||||
<a href="{% url 'post_list_by_tag' tag.slug %}">{{ tag.name }}</a>
|
||||
{% if not forloop.last %}, {% endif %} {% endfor %} <p>
|
||||
{{ post.author }}
|
||||
</p>
|
||||
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
|
@ -1,5 +1,18 @@
|
||||
{% extends "base.html" %} {% block content %}
|
||||
{% extends "base.html" %} {% block content %} {% load taggit_templatetags2_tags %} {% get_taglist as tags for 'application.post'%}
|
||||
|
||||
<div id="">
|
||||
<ul>
|
||||
{% for tag in tags %}
|
||||
<li>{{tag}}
|
||||
<a class="btn btn-outline-dark" href="{% url 'tag_remove' %}">
|
||||
<span class="glyphicon glyphicon-remove">Remove</span>
|
||||
</a>
|
||||
</li>
|
||||
{{ result }} {% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
<div>
|
||||
</div>
|
||||
<form id="searchform" action="{% url 'blog_search_list_view' %}" method="get" accept-charset="utf-8">
|
||||
<button class="searchbutton" type="submit">
|
||||
<i class="fa fa-search"></i>
|
||||
@ -12,8 +25,7 @@
|
||||
</div>
|
||||
|
||||
<form class="post-form" method="post">
|
||||
{% csrf_token %}
|
||||
{{form.as_p}}
|
||||
{% csrf_token %} {{form.as_p}}
|
||||
<button type="submit" class="save btn btn-outline-dark">Save</button>
|
||||
</form>
|
||||
{% endblock %}
|
25
application/templates/tag_list.html
Normal file
25
application/templates/tag_list.html
Normal file
@ -0,0 +1,25 @@
|
||||
{% extends "base.html" %} {% block content %} {% load taggit_templatetags2_tags %}
|
||||
{% get_taglist as tags for 'application.customuser'%}
|
||||
|
||||
|
||||
<div id="">
|
||||
Your tags:
|
||||
<ul>
|
||||
{% for tag in tags %}
|
||||
<li>
|
||||
<a href="{% url 'post_list_by_tag' tag.slug %}">{{ tag }}</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</div>
|
||||
<div>
|
||||
{{ tags }} {{ u }}
|
||||
</div>
|
||||
<div>
|
||||
from List: {% for tag in tags %}
|
||||
|
||||
{% for tag in posts %}
|
||||
<p>{{ tag.name }} </p>{% endfor %}{% endfor %}
|
||||
|
||||
</div>
|
||||
{% endblock %}
|
@ -5,6 +5,9 @@ from . import views
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^$', views.post_list, name='post_list'),
|
||||
url(r'^tag/(?P<slug>[-\w]+)/$', views.post_list, name='post_list_by_tag'),
|
||||
url(r'^taglist/$', views.tag_list, name='tag_list'),
|
||||
url(r'^taglist/(?P<slug>[-\w]+)/$', views.post_list, name='post_list_by_tag'),
|
||||
url(r'^student/', views.student_page, name='student_page'),
|
||||
url(r'^search/', views.blog_search_list_view, name='blog_search_list_view'),
|
||||
url(r'^post/(?P<pk>\d+)/$', views.post_detail, name='post_detail'),
|
||||
@ -13,6 +16,7 @@ urlpatterns = [
|
||||
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'),
|
||||
url(r'^tags/', include('taggit_templatetags2.urls')),
|
||||
url(r'^student/remove/$', views.tag_remove, name='tag_remove'),
|
||||
url(r'^tags/', include('taggit_templatetags2.urls')),
|
||||
]
|
||||
|
||||
|
@ -1,12 +1,16 @@
|
||||
from django.shortcuts import render, get_object_or_404
|
||||
from django.utils import timezone
|
||||
from .models import Post, CustomUser
|
||||
from taggit.models import Tag
|
||||
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
|
||||
from .forms import PostForm, NewTagForm
|
||||
from django.shortcuts import redirect
|
||||
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.db.models import Q
|
||||
import sys
|
||||
import collections
|
||||
from taggit_templatetags2.views import TagCanvasListView
|
||||
|
||||
import logging
|
||||
@ -42,10 +46,13 @@ def navlogin(request):
|
||||
|
||||
|
||||
@login_required
|
||||
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_list(request, slug=None):
|
||||
posts = Post.objects.filter(published_date__lte=timezone.now()).order_by('published_date')
|
||||
if slug:
|
||||
tag = get_object_or_404(Tag, slug=slug)
|
||||
posts= posts.filter(tags__in=[tag])
|
||||
page = request.GET.get('page')
|
||||
return render(request, 'post_list.html', locals())
|
||||
|
||||
|
||||
@login_required
|
||||
@ -79,6 +86,7 @@ def post_edit(request, pk):
|
||||
post = form.save(commit=False)
|
||||
post.author = request.user
|
||||
post.save()
|
||||
form.save_m2m()
|
||||
return redirect('post_detail', pk=post.pk)
|
||||
else:
|
||||
form = PostForm(instance=post)
|
||||
@ -109,9 +117,18 @@ def post_remove(request, pk):
|
||||
return redirect('post_list')
|
||||
|
||||
|
||||
@login_required
|
||||
def tag_remove(request):
|
||||
tag_to_delete = CustomUser.objects.get(tags)
|
||||
obj.user = request.user
|
||||
obj.save()
|
||||
obj.tags.tag_remove(tag_to_delete)
|
||||
obj.save_m2m()
|
||||
return redirect('student_page')
|
||||
|
||||
@login_required
|
||||
def student_page(request):
|
||||
user_instance = CustomUser.objects.get(user=request.user)
|
||||
user_instance = get_object_or_404(CustomUser, user=request.user)
|
||||
if request.method == "POST":
|
||||
form = NewTagForm(request.POST, instance=user_instance)
|
||||
if form.is_valid():
|
||||
@ -128,7 +145,11 @@ def student_page(request):
|
||||
|
||||
return render(request, 'student_page.html', {'form':form})
|
||||
|
||||
|
||||
@login_required
|
||||
def tag_list(request):
|
||||
u= CustomUser.objects.get(user=request.user)
|
||||
tags= Tag.objects.filter(name=u)
|
||||
return render(request, 'tag_list.html', locals())
|
||||
|
||||
|
||||
class TagSearch(TagCanvasListView):
|
||||
|
Loading…
x
Reference in New Issue
Block a user