fixed some issues with non-used tags

This commit is contained in:
Esther Kleinhenz
2018-10-24 19:04:43 +02:00
parent f5980566ae
commit 7ed667d043
5 changed files with 121 additions and 19 deletions
+5 -12
View File
@@ -12,18 +12,11 @@
</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>
</button>
<input class="searchfield" id="searchbox" name="q" type="text" placeholder="Search">
</form>
<div class="table-responsive">
<table class="table table-striped table-bordered table-hover">
</table>
</div>
{% if messages %}
{% for message in messages %}
<div {% if message.tags %} class="{{ message.tags }}" {% endif %}>{{ message }}</div>
{% endfor %}
{% endif %}
<form class="post-form" method="post">
{% csrf_token %} {{form.as_p}}
<button type="submit" class="save btn btn-outline-dark">Save</button>
+1
View File
@@ -1,4 +1,5 @@
{% extends "base.html" %} {% block content %}
{% load taggit_templatetags2_tags %}
<div>
</div>
+20
View File
@@ -0,0 +1,20 @@
{% 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 }}
</div>
<h1>
<a href="{% url 'post_detail' pk=post.pk %}">{{ post.title }}</a>
</h1>
<p>{{ post.text|linebreaks }}</p>
Tags: {% for tag in post.tags.all %}
<a href="{% url 'student_page_remove' tag.slug %}">{{ tag.name }}</a>
{% if not forloop.last %}, {% endif %} {% endfor %} <p>
{{ post.author }}
</p>
</div>
{% endfor %}
</div>
{% endblock %}
+10 -7
View File
@@ -13,6 +13,8 @@ import sys
import collections
from taggit_templatetags2.views import TagCanvasListView
from django.contrib.auth.models import User
from django.contrib import messages
import logging
@@ -135,10 +137,13 @@ def student_page(request):
obj.user = request.user
obj.save()
m_tags = form.cleaned_data['m_tags']
obj.tags.add(*m_tags)
form.save_m2m()
return redirect('/student/')
tags = Tag.objects.all()
if m_tags in tags:
obj.tags.add(*m_tags)
form.save_m2m()
return redirect('/student/')
else:
messages.info(request, 'Sorry !! Den Tag den du suchst gibt es leider nicht!')
else:
form = NewTagForm()
return render(request, 'student_page.html', {'form':form})
@@ -150,11 +155,9 @@ def tag_list(request):
if u:
tags_user = Tag.objects.filter(customuser__user = u)
log.info(tags_user)
arr = []
for tag in tags_user:
arr.append(str(tag))
log.info(tag)
posts = Post.objects.filter(tags__in=[tag]).order_by('-published_date')
log.info(posts)
return render(request, 'tag_list.html', locals())
class TagSearch(TagCanvasListView):