From 7ed667d04307dd95ed449339b8e61be29ee0b0cf Mon Sep 17 00:00:00 2001 From: Esther Kleinhenz Date: Wed, 24 Oct 2018 19:04:43 +0200 Subject: [PATCH] fixed some issues with non-used tags --- application/templates/student_page.html | 17 ++--- application/templates/tag_list.html | 1 + application/templates/tag_remove.html | 20 ++++++ application/views.py | 17 +++-- log.txt | 85 +++++++++++++++++++++++++ 5 files changed, 121 insertions(+), 19 deletions(-) create mode 100644 application/templates/tag_remove.html diff --git a/application/templates/student_page.html b/application/templates/student_page.html index 0812182..ee46f5a 100644 --- a/application/templates/student_page.html +++ b/application/templates/student_page.html @@ -12,18 +12,11 @@
-
-
- - -
-
- -
-
- +{% if messages %} +{% for message in messages %} +
{{ message }}
+{% endfor %} +{% endif %}
{% csrf_token %} {{form.as_p}} diff --git a/application/templates/tag_list.html b/application/templates/tag_list.html index 041f4ef..4347319 100644 --- a/application/templates/tag_list.html +++ b/application/templates/tag_list.html @@ -1,4 +1,5 @@ {% extends "base.html" %} {% block content %} + {% load taggit_templatetags2_tags %}
diff --git a/application/templates/tag_remove.html b/application/templates/tag_remove.html new file mode 100644 index 0000000..11a97bd --- /dev/null +++ b/application/templates/tag_remove.html @@ -0,0 +1,20 @@ +{% extends 'base.html' %} {% block content %} +{% if tag %} Posts tagged with "{{ tag.name }}" {% endif %} +{% for post in posts %} +
+
+ {{ post.published_date }} +
+

+ {{ post.title }} +

+

{{ post.text|linebreaks }}

+ Tags: {% for tag in post.tags.all %} + {{ tag.name }} + {% if not forloop.last %}, {% endif %} {% endfor %}

+ {{ post.author }} +

+
+{% endfor %} + +{% endblock %} \ No newline at end of file diff --git a/application/views.py b/application/views.py index f792e68..7c6de77 100644 --- a/application/views.py +++ b/application/views.py @@ -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): diff --git a/log.txt b/log.txt index bf3dfd3..29bb3f4 100644 --- a/log.txt +++ b/log.txt @@ -315,3 +315,88 @@ [22/Oct/2018 18:55:43] INFO [mysite:152] , ]> [22/Oct/2018 18:55:43] INFO [mysite:156] bamberg [22/Oct/2018 18:55:43] INFO [mysite:156] test +[24/Oct/2018 15:10:56] INFO [mysite:152] ]> +[24/Oct/2018 15:10:56] INFO [mysite:156] stefan +[24/Oct/2018 15:11:37] INFO [mysite:152] ]> +[24/Oct/2018 15:11:37] INFO [mysite:156] stefan +[24/Oct/2018 15:11:37] INFO [mysite:158] +[24/Oct/2018 15:13:48] INFO [mysite:152] ]> +[24/Oct/2018 15:13:48] INFO [mysite:156] stefan +[24/Oct/2018 15:13:48] INFO [mysite:158] +[24/Oct/2018 15:15:46] INFO [mysite:153] ]> +[24/Oct/2018 15:15:46] INFO [mysite:157] stefan +[24/Oct/2018 15:15:55] INFO [mysite:153] ]> +[24/Oct/2018 15:15:55] INFO [mysite:157] stefan +[24/Oct/2018 15:15:55] INFO [mysite:159] +[24/Oct/2018 15:17:17] INFO [mysite:152] ]> +[24/Oct/2018 15:17:17] INFO [mysite:156] stefan +[24/Oct/2018 15:17:17] INFO [mysite:158] +[24/Oct/2018 15:18:27] INFO [mysite:152] ]> +[24/Oct/2018 15:18:27] INFO [mysite:156] stefan +[24/Oct/2018 15:18:27] INFO [mysite:158] +[24/Oct/2018 15:21:10] INFO [mysite:150] , , ]> +[24/Oct/2018 15:21:10] INFO [mysite:154] ]> +[24/Oct/2018 15:21:10] INFO [mysite:158] stefan +[24/Oct/2018 15:21:10] INFO [mysite:160] +[24/Oct/2018 15:22:12] INFO [mysite:152] ]> +[24/Oct/2018 15:22:12] INFO [mysite:156] ['stefan'] +[24/Oct/2018 15:22:12] INFO [mysite:158] +[24/Oct/2018 15:22:29] INFO [mysite:152] ]> +[24/Oct/2018 15:22:29] INFO [mysite:156] ['stefan'] +[24/Oct/2018 15:22:57] INFO [mysite:152] ]> +[24/Oct/2018 15:22:57] INFO [mysite:155] +[24/Oct/2018 15:23:36] INFO [mysite:152] , ]> +[24/Oct/2018 15:23:36] INFO [mysite:155] +[24/Oct/2018 15:23:36] INFO [mysite:155] , , ]> +[24/Oct/2018 15:24:29] INFO [mysite:152] , , ]> +[24/Oct/2018 15:24:29] INFO [mysite:155] +[24/Oct/2018 15:24:29] INFO [mysite:155] , , ]> +[24/Oct/2018 15:24:29] INFO [mysite:155] +[24/Oct/2018 15:26:03] INFO [mysite:152] , ]> +[24/Oct/2018 15:26:03] INFO [mysite:155] +[24/Oct/2018 15:26:03] INFO [mysite:155] , ]> +[24/Oct/2018 15:51:54] INFO [mysite:152] , , ]> +[24/Oct/2018 15:51:55] INFO [mysite:155] +[24/Oct/2018 15:51:55] INFO [mysite:155] , , ]> +[24/Oct/2018 15:51:55] INFO [mysite:155] +[24/Oct/2018 15:53:01] INFO [mysite:152] , ]> +[24/Oct/2018 15:53:01] INFO [mysite:155] +[24/Oct/2018 15:53:01] INFO [mysite:155] , , ]> +[24/Oct/2018 15:53:28] INFO [mysite:152] , , ]> +[24/Oct/2018 15:53:28] INFO [mysite:155] +[24/Oct/2018 15:53:28] INFO [mysite:155] , , ]> +[24/Oct/2018 15:53:28] INFO [mysite:155] +[24/Oct/2018 18:41:24] INFO [mysite:186] None +[24/Oct/2018 18:41:31] INFO [mysite:186] bla +[24/Oct/2018 18:42:12] INFO [mysite:186] avoiddouble +[24/Oct/2018 18:42:20] INFO [mysite:186] hi +[24/Oct/2018 18:56:30] INFO [mysite:158] , ]> +[24/Oct/2018 18:56:30] INFO [mysite:161] +[24/Oct/2018 18:56:30] INFO [mysite:161] , , ]> +[24/Oct/2018 18:56:45] INFO [mysite:190] None +[24/Oct/2018 18:56:49] INFO [mysite:190] bamberg +[24/Oct/2018 18:57:29] INFO [mysite:189] bamberg +[24/Oct/2018 19:00:30] INFO [mysite:189] None +[24/Oct/2018 19:00:30] INFO [mysite:191] +[24/Oct/2018 19:00:33] INFO [mysite:189] hi +[24/Oct/2018 19:00:33] INFO [mysite:191] , ]> +[24/Oct/2018 19:00:38] INFO [mysite:189] bamberg +[24/Oct/2018 19:00:38] INFO [mysite:191] +[24/Oct/2018 19:00:54] INFO [mysite:189] bamberg +[24/Oct/2018 19:00:54] INFO [mysite:191] +[24/Oct/2018 19:01:16] INFO [mysite:189] test +[24/Oct/2018 19:01:16] INFO [mysite:191] , , ]> +[24/Oct/2018 19:01:20] INFO [mysite:189] third +[24/Oct/2018 19:01:20] INFO [mysite:191] ]> +[24/Oct/2018 19:01:35] INFO [mysite:189] None +[24/Oct/2018 19:01:35] INFO [mysite:191] +[24/Oct/2018 19:01:40] INFO [mysite:189] bamberg +[24/Oct/2018 19:01:40] INFO [mysite:191] +[24/Oct/2018 19:03:03] INFO [mysite:189] None +[24/Oct/2018 19:03:03] INFO [mysite:191] +[24/Oct/2018 19:03:08] INFO [mysite:189] bamberg +[24/Oct/2018 19:03:08] INFO [mysite:191] +[24/Oct/2018 19:03:28] INFO [mysite:189] bamberg +[24/Oct/2018 19:03:28] INFO [mysite:191] ]> +[24/Oct/2018 19:03:45] INFO [mysite:189] bamberg +[24/Oct/2018 19:03:45] INFO [mysite:191] , ]>