Browse Source

added post search

newsletter
Esther Kleinhenz 6 years ago
parent
commit
df5d420505
5 changed files with 112 additions and 50 deletions
  1. 0
    1
      application/models.py
  2. 20
    25
      application/templates/blog_search_list_view.html
  3. 1
    0
      application/urls.py
  4. 11
    24
      application/views.py
  5. 80
    0
      log.txt

+ 0
- 1
application/models.py View File

@@ -8,7 +8,6 @@ class CustomUser(models.Model):
user = models.OneToOneField(User, null=True, on_delete=models.CASCADE)
tags = TaggableManager()


class Post(models.Model):
author = models.ForeignKey('auth.User', on_delete=models.CASCADE)
title = models.CharField(max_length=200)

+ 20
- 25
application/templates/blog_search_list_view.html View File

@@ -1,32 +1,27 @@
{% 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}} ({{tag.num_times}})
</li>
{{ result }}
{% endfor %}
</ul>
</div>
{% include "taggit_templatetags2/tagcanvas_include_js_static.html" %}

<div id="tag-cloud">
</div>

{% get_tagcloud as tags for 'application' %}
{% include_tagcloud 'application.Post' %}
<form type="get" action="." style="margin: 0">
<input id="search_box" type="text" name="search_box" placeholder="Search..." >
<button id="search_submit" type="submit" >Submit</button>
<input id="search_box" type="text" name="search_box" placeholder="Search...">
<button id="search_submit" type="submit">Submit</button>
</form>
<div>
<ul>
{% for tag in tags %}
<li>
{{tag}}
</li>
{% endfor %}

</ul>
{% 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 'post_list_by_tag' tag.slug %}">{{ tag.name }}</a>
{% if not forloop.last %}, {% endif %} {% endfor %} <p>
{{ post.author }}
</p>
</div>
{% endfor %}
</div>
{% endblock %}

+ 1
- 0
application/urls.py View File

@@ -13,6 +13,7 @@ urlpatterns = [
url(r'^taglist/$', views.tag_list, name='tag_list'),
url(r'^student/', views.student_page, name='student_page'),
url(r'^search/', views.blog_search_list_view, name='blog_search_list_view'),
url(r'^search/result/$', views.blog_search_list_view, name='post_list_by_search'),
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'),

+ 11
- 24
application/views.py View File

@@ -46,11 +46,12 @@ def navlogin(request):

@login_required
def post_list(request, slug=None):
log = logging.getLogger('mysite')
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')
posts = posts.filter(tags__in=[tag])
log.info(posts)
return render(request, 'post_list.html', locals())


@@ -152,12 +153,6 @@ def tag_list(request):
arr = []
for tag in tags:
arr.append(str(tag))
"""
arr.append(tags)
for tag in tags:
arr.append(str(tag))
listing = list(arr)
"""
return render(request, 'tag_list.html', locals())

class TagSearch(TagCanvasListView):
@@ -181,22 +176,14 @@ class TagSearch(TagCanvasListView):
cObj = cObj.order_by(var_get_order_by)
return cObj
def blog_search_list_view(request):
return render(request, 'blog_search_list_view.html', {})
def blog_search_list_view(request):
log = logging.getLogger('mysite')
posts = Post.objects.filter(published_date__lte=timezone.now()).order_by('published_date')
if request.method == 'GET':
search_query = request.GET.get('search_box', None)
log.info(search_query)
posts = posts.filter(tags__name__in=[search_query])
return render(request, 'blog_search_list_view.html', locals())

def tag_cloud(request):
return render(request, 'tag_cloud.html', {})

"""
@login_required
def post_of_user_list(request):
u= CustomUser.objects.get(user=request.user)
tag =[]

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())
"""

+ 80
- 0
log.txt View File

@@ -55,3 +55,83 @@
[19/Oct/2018 18:12:56] INFO [mysite:149] CustomUser object (25)
[19/Oct/2018 18:15:29] INFO [mysite:149] CustomUser object (25)
[20/Oct/2018 17:20:58] INFO [mysite:149] CustomUser object (25)
[20/Oct/2018 17:54:57] INFO [mysite:149] CustomUser object (25)
[20/Oct/2018 18:03:09] INFO [mysite:149] CustomUser object (25)
[20/Oct/2018 18:18:52] INFO [mysite:149] CustomUser object (25)
[20/Oct/2018 19:14:57] INFO [mysite:183] None
[20/Oct/2018 19:15:00] INFO [mysite:183] test
[20/Oct/2018 19:15:45] INFO [mysite:183] test
[20/Oct/2018 19:17:52] INFO [mysite:183] test
[20/Oct/2018 19:18:31] INFO [mysite:183] test
[20/Oct/2018 19:19:01] INFO [mysite:183] test
[20/Oct/2018 19:20:08] INFO [mysite:184] test
[20/Oct/2018 19:24:45] INFO [mysite:184] None
[20/Oct/2018 19:26:30] INFO [mysite:184] None
[20/Oct/2018 19:29:44] INFO [mysite:184] test
[20/Oct/2018 19:32:09] INFO [mysite:184] test
[20/Oct/2018 19:33:14] INFO [mysite:184] 5
[20/Oct/2018 22:26:02] INFO [mysite:184] hi
[20/Oct/2018 22:26:09] INFO [mysite:184] 2
[20/Oct/2018 22:26:39] INFO [mysite:184] 2
[20/Oct/2018 22:35:49] INFO [mysite:183] 2
[20/Oct/2018 22:35:55] INFO [mysite:183] 3
[20/Oct/2018 22:51:06] INFO [mysite:183] hi
[20/Oct/2018 22:53:24] INFO [mysite:183] hi
[20/Oct/2018 22:54:12] INFO [mysite:183] hi
[20/Oct/2018 22:57:38] INFO [mysite:181] <QuerySet [<Post: first post>, <Post: second bla>, <Post: Third one>]>
[20/Oct/2018 22:57:39] INFO [mysite:184] hi
[20/Oct/2018 22:59:11] INFO [mysite:181] <QuerySet [<Post: second bla>, <Post: first post>, <Post: Third one>]>
[20/Oct/2018 22:59:11] INFO [mysite:184] hi
[20/Oct/2018 23:01:53] INFO [mysite:181] <QuerySet [<Post: second bla>, <Post: first post>, <Post: Third one>]>
[20/Oct/2018 23:01:53] INFO [mysite:184] hi
[20/Oct/2018 23:02:06] INFO [mysite:181] <QuerySet [<Post: second bla>, <Post: first post>, <Post: Third one>]>
[20/Oct/2018 23:02:06] INFO [mysite:184] 5
[20/Oct/2018 23:02:22] INFO [mysite:181] <QuerySet [<Post: second bla>, <Post: first post>, <Post: Third one>]>
[20/Oct/2018 23:02:22] INFO [mysite:184] 5
[20/Oct/2018 23:02:45] INFO [mysite:181] <QuerySet [<Post: second bla>, <Post: first post>, <Post: Third one>]>
[20/Oct/2018 23:02:45] INFO [mysite:184] 5
[20/Oct/2018 23:03:07] INFO [mysite:181] <QuerySet [<Post: second bla>, <Post: first post>, <Post: Third one>]>
[20/Oct/2018 23:03:07] INFO [mysite:184] 5
[20/Oct/2018 23:03:46] INFO [mysite:181] <QuerySet [<Post: second bla>, <Post: first post>, <Post: Third one>]>
[20/Oct/2018 23:03:46] INFO [mysite:184] 5
[20/Oct/2018 23:04:35] INFO [mysite:181] <QuerySet [<Post: second bla>, <Post: first post>, <Post: Third one>]>
[20/Oct/2018 23:04:35] INFO [mysite:184] 5
[20/Oct/2018 23:06:49] INFO [mysite:181] <QuerySet [<Post: second bla>, <Post: first post>, <Post: Third one>]>
[20/Oct/2018 23:06:49] INFO [mysite:184] hi
[20/Oct/2018 23:15:41] INFO [mysite:181] <QuerySet [<Post: second bla>, <Post: first post>, <Post: Third one>]>
[20/Oct/2018 23:15:41] INFO [mysite:184] hi
[20/Oct/2018 23:17:19] INFO [mysite:181] <QuerySet [<Post: second bla>, <Post: first post>, <Post: Third one>]>
[20/Oct/2018 23:17:19] INFO [mysite:184] hi
[20/Oct/2018 23:17:38] INFO [mysite:181] <QuerySet [<Post: second bla>, <Post: first post>, <Post: Third one>]>
[20/Oct/2018 23:17:38] INFO [mysite:184] hi
[20/Oct/2018 23:19:11] INFO [mysite:181] <QuerySet [<Post: second bla>, <Post: first post>, <Post: Third one>]>
[20/Oct/2018 23:19:11] INFO [mysite:184] hi
[20/Oct/2018 23:24:22] INFO [mysite:181] <QuerySet [<Post: second bla>, <Post: first post>, <Post: Third one>]>
[20/Oct/2018 23:24:23] INFO [mysite:184] hi
[20/Oct/2018 23:24:42] INFO [mysite:181] <QuerySet [<Post: second bla>, <Post: first post>, <Post: Third one>]>
[20/Oct/2018 23:24:42] INFO [mysite:184] hi
[20/Oct/2018 23:24:49] INFO [mysite:181] <QuerySet [<Post: second bla>, <Post: first post>, <Post: Third one>]>
[20/Oct/2018 23:24:49] INFO [mysite:184] hi
[20/Oct/2018 23:24:54] INFO [mysite:181] <QuerySet [<Post: second bla>, <Post: first post>, <Post: Third one>]>
[20/Oct/2018 23:24:54] INFO [mysite:184] test
[20/Oct/2018 23:25:01] INFO [mysite:181] <QuerySet [<Post: second bla>, <Post: first post>, <Post: Third one>]>
[20/Oct/2018 23:25:01] INFO [mysite:184] third
[20/Oct/2018 23:28:54] INFO [mysite:182] None
[20/Oct/2018 23:29:00] INFO [mysite:182] hi
[20/Oct/2018 23:29:42] INFO [mysite:182] hi
[20/Oct/2018 23:30:53] INFO [mysite:182] hi
[20/Oct/2018 23:34:29] INFO [mysite:184] hi
[20/Oct/2018 23:34:34] INFO [mysite:54] <QuerySet [<Post: second bla>]>
[20/Oct/2018 23:38:12] INFO [mysite:54] <QuerySet [<Post: second bla>]>
[20/Oct/2018 23:38:18] INFO [mysite:184] None
[20/Oct/2018 23:38:25] INFO [mysite:184] hi
[20/Oct/2018 23:40:03] INFO [mysite:184] hi
[20/Oct/2018 23:40:10] INFO [mysite:184] first
[20/Oct/2018 23:41:01] INFO [mysite:184] first
[20/Oct/2018 23:41:12] INFO [mysite:184] h
[20/Oct/2018 23:41:28] INFO [mysite:184] h
[20/Oct/2018 23:41:32] INFO [mysite:184] h
[20/Oct/2018 23:41:38] INFO [mysite:184] h
[20/Oct/2018 23:41:40] INFO [mysite:184] hi
[20/Oct/2018 23:41:50] INFO [mysite:184] hi
[20/Oct/2018 23:41:56] INFO [mysite:184] taggit

Loading…
Cancel
Save