Skip to content

Commit

Permalink
Inserted tag filtering functionality into table view.
Browse files Browse the repository at this point in the history
  • Loading branch information
bensonchan committed Nov 12, 2014
1 parent 7f44e06 commit 8ae751c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
Binary file modified messageboard/db.sqlite3
Binary file not shown.
9 changes: 8 additions & 1 deletion messageboard/mainsite/templates/tableview.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,15 @@ <h1> Message Board </h1>
<li><a href="{% url 'mainsite:create_topic' %}">Create a Topic</a></li>
<li><a href="{% url 'mainsite:subscribed_topics' %}">My Subscribed Topics</a></li>
</ul>
<form action="" method="POST">
{% csrf_token %}
<input type="text" name="tag_name">
<input type="submit" name="filter_tag" value="Filter by Tag">
<p>Leave blank to show all.</p>
</form>
</div>
<div class="allTopics" align="center">

{% for topic in topics %}
<div class="topicBox">
<div class="title">
Expand All @@ -39,7 +46,7 @@ <h1> Message Board </h1>
<p>
Tags:
{% for tag in topic.tags.all %}
{{ tag }}
[{{ tag }}]
{% endfor %}
</p>
<p>
Expand Down
11 changes: 10 additions & 1 deletion messageboard/mainsite/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
@login_required(login_url='/mainsite/login')
def tableview(request):
tag_error = "" # Displayed error message when creating/deleting tags.
topic_list = Topic.objects.all()

if "post" in request.POST:
message = Message()
message.creator = request.user
Expand Down Expand Up @@ -62,8 +64,15 @@ def tableview(request):
tag.delete()
except Tag.DoesNotExist:
pass # Do nothing is tag doesn't exist
elif "filter_tag" in request.POST:
tag_name = request.POST['tag_name']
if tag_name:
try:
tag = Tag.objects.get(tag_name=tag_name)
topic_list = tag.tagged_topics.all()
except Tag.DoesNotExist:
topic_list = []

topic_list = Topic.objects.all()
message_list = Message.objects.all()
return render(request, 'tableview.html', {
'topics': topic_list,
Expand Down

0 comments on commit 8ae751c

Please sign in to comment.