Skip to content
This repository has been archived by the owner on Jul 22, 2022. It is now read-only.

Fave/block tags #88

Merged
merged 4 commits into from
Nov 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ testtags: ## Run only tests tagged with a certain tag or tags (comma separated)

.PHONY: rapidcoverage
rapidcoverage: ## Run tests in four parallel threads and generate coverage from that (may be unstable)
tox --notest -e 3.5
venv/bin/coverage erase
detox -e rapidcov-1,rapidcov-2,rapidcov-3,rapidcov-4
tox -e rapidcoverage
Expand Down
2 changes: 1 addition & 1 deletion core/fixtures/flatpages.json

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion core/management/commands/git_revno.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ def handle(self, *args, **kwargs):
"""
revno = subprocess.check_output(
['git', 'rev-parse', '--verify', 'HEAD']).strip()
try:
revno = revno.decode()
except:
pass

with open(os.sep.join(['honeycomb', 'revno.py']), 'w') as f:
f.write("GIT_REVNO = '{}'\nVERSION = '{}'\n".format(
revno, kwargs['tag']))
str(revno), kwargs['tag']))
12 changes: 12 additions & 0 deletions flatpage-defaults/about-help-tags.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
## All about tags

Tags are a very general way to categorize submissions. A submission can have many tags, and a tag can belong to many submissions. This means that you can describe what's happening in a submission through the use of tags. For instance, you could say that your submission is fiction, involves romance between a homosexual couple and has violence (but not between the members of the relationship). You can get as general or as specific as you want with tags.

A lot of different sites have tags like this, whether they call them 'categories' on a news site or 'hashtags' on Twitter. Honeycomb allows you to do a few neat things with tags, however.

Of course, you can list all tags on the site within a tag cloud, which shows tags according to size, where the more popular a tag is, the larger the text is. You can list all submissions tagged with a certain tag, as well, which lets you find submissions that might also contain something that you enjoy.

To that end, you can favorite tags on Honeycomb. This lets you follow submissions that contain topics that you like. For instance, you could favorite 'science fiction', 'foxes', and 'humor', and easily have a list of submissions that fall under one or more of those tags.

Not everyone likes everything, though, and to that end, Honeycomb allows you to block a tag. For instance, if you just *hate* science fiction, you could block that tag and then submissions tagged with 'science fiction' would no longer show up in lists of submissions for you (though you'll still be able to view a submission with blocked tags directly, if someone provides you with the link). Of course, you can remove favorites and submissions to change the way you view submissions.

## Tagging submissions

Honeycomb uses a tagging system called *taggit*. Taggit allows you to tag in several ways! You can tag your submissions as a comma separated list of tags - if you need to use a comma in a tag for some reason, you can wrap the tag in quotes (e.g: `"look ma, no hands"`) - or, if you want to be super simple, by just a space-delimited set of words. The tagging system is fairly flexible, and treats tag inputs like such:
Expand Down
2 changes: 1 addition & 1 deletion honeycomb/revno.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
GIT_REVNO = '559368953e5c06fad31d3a465966e0504a0bf260'
GIT_REVNO = '4e21d7e00c0a1b88a24a77c2a1cdca2d682d214c'
VERSION = 'pre-release'
Binary file modified models.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 12 additions & 10 deletions sloc.tsv
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Count Location
44 CONTRIBUTING.md
13 DEPLOYING.md
110 Makefile
119 Makefile
3 README.md
9 RELEASE.md
1 activitystream/__init__.py
Expand Down Expand Up @@ -36,6 +36,7 @@ Count Location
81 administration/templates/view_flag.html
0 administration/templatetags/__init__.py
15 administration/templatetags/flag_extras.py
16 administration/templatetags/test_flag_extras.py
547 administration/test_application.py
413 administration/test_ban.py
654 administration/test_flag.py
Expand All @@ -48,7 +49,7 @@ Count Location
0 core/management/__init__.py
0 core/management/commands/__init__.py
7 core/management/commands/clear_old_notifications.py
20 core/management/commands/git_revno.py
24 core/management/commands/git_revno.py
7 core/management/commands/rotate_activitystream.py
15 core/management/commands/test_git_revno.py
40 core/management/commands/test_update_flatpages.py
Expand Down Expand Up @@ -82,7 +83,7 @@ Count Location
0 flatpage-defaults/about-help-promoting.md
0 flatpage-defaults/about-help-publishers.md
30 flatpage-defaults/about-help-submissions.md
35 flatpage-defaults/about-help-tags.md
40 flatpage-defaults/about-help-tags.md
0 flatpage-defaults/about-help-user.md
11 flatpage-defaults/about-terms.md
16 gen-badge.sh
Expand Down Expand Up @@ -141,24 +142,25 @@ Count Location
478 submissions/test_folders.py
864 submissions/tests.py
48 submissions/urls.py
26 submissions/utils.py
28 submissions/utils.py
298 submissions/views.py
0 tags/__init__.py
4 tags/apps.py
66 tags/templates/list_submissions_with_favorite_tags.html
12 tags/templates/list_tags.html
76 tags/templates/view_tag.html
119 tags/templates/view_tag.html
0 tags/templatetags/__init__.py
48 tags/templatetags/tag_extras.py
116 tags/tests.py
27 tags/urls.py
78 tags/views.py
276 tags/tests.py
30 tags/urls.py
140 tags/views.py
0 usermgmt/__init__.py
0 usermgmt/admin.py
4 usermgmt/apps.py
37 usermgmt/forms.py
10 usermgmt/group_models.py
119 usermgmt/group_views.py
169 usermgmt/models.py
172 usermgmt/models.py
24 usermgmt/templates/confirm_delete_group.html
20 usermgmt/templates/list_groups.html
107 usermgmt/templates/profile-tabs-snippet.html
Expand Down Expand Up @@ -186,4 +188,4 @@ Count Location
24 usermgmt/urls.py
9 usermgmt/utils.py
87 usermgmt/views.py
12517 TOTAL
12890 TOTAL
6 changes: 5 additions & 1 deletion submissions/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.db.models import Q


def filters_for_authenticated_user(reader):
def filters_for_authenticated_user(reader, blocked_tags=True):
"""Gets submission filters for an authenticated user.

Args:
Expand All @@ -25,6 +25,10 @@ def filters_for_authenticated_user(reader):
(Q(restricted_to_groups=True) &
Q(allowed_groups__in=reader.friendgroup_set.all())))

# Filter out blocked tags if we've been asked
if blocked_tags:
query &= ~Q(tags__in=reader.profile.blocked_tags.all())

# Shortcut to allow authors all access
query = Q(owner=reader) | query
return query
Expand Down
2 changes: 1 addition & 1 deletion submissions/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def view_submission(request, username=None, submission_id=None,
author = submission.owner
try:
submission = Submission.objects.get(Q(id=submission_id) & (
filters_for_authenticated_user(reader) if
filters_for_authenticated_user(reader, blocked_tags=False) if
reader.is_authenticated else filters_for_anonymous_user()))
except Submission.DoesNotExist:
# XXX Perhaps we should distinguish between 403 and 404 at some point
Expand Down
67 changes: 67 additions & 0 deletions tags/templates/list_submissions_with_favorite_tags.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{% extends 'base.html' %}
{% load tag_extras %}

{% block content %}
<div class="row">
<div class="col-md-8 col-md-offset-2 tag-cloud">
<h2><small>Your favorite tags</small></h2>
{% get_weighted_tags user.profile.favorite_tags as weighted_tags %}
{% for tag in weighted_tags %}
<a href="{% url 'tags:view_tag' tag_slug=tag.slug %}" style="font-size:calc(7px * {{ tag.weight }});">{{ tag }}</a>
{% endfor %}
</div>
</div>
<div class="row">
<div class="col-md-8 col-md-offset-2">
<p>
<em>Showing results {{ submissions.start_index }} through {{ submissions.end_index }} of {{ submissions.paginator.count }}</em>
</p>
</div>
</div>
<div class="row">
<div class="col-md-8 col-md-offset-2">
{% for submission in submissions %}
<div class="row striped-item">
<div class="col-md-12">
{% include 'submission-list-snippet.html' with submission=submission author=submission.owner %}
</div>
</div>
{% endfor %}
</div>
</div>
{% if submissions.has_next or submissions.has_previous %}
<div class="row">
<div class="col-md-12 text-center">
<nav aria-label="Submission pages">
<ul class="pagination">
{% if submissions.has_previous %}
<li>
<a href="{{ url_prefix }}page/{{ submissions.previous_page_number }}/" aria-label="Previous">
<span aria-hidden="true">&laquo;</span>
</a>
</li>
{% else %}
<li class="disabled"><span aria-hidden="true">&laquo;</span></li>
{% endif %}
{% for page in submissions.paginator.page_range %}
{% if submissions.number == page %}
<li class="active"><a href="{{ url_prefix }}page/{{ page }}/">{{ page }} <span class="sr-only">(current)</span></a></li>
{% else %}
<li><a href="{{ url_prefix }}page/{{ page }}/">{{ page }}</a></li>
{% endif %}
{% endfor %}
{% if submissions.has_next %}
<li>
<a href="{{ url_prefix }}page/{{ submissions.next_page_number }}/" aria-label="Next">
<span aria-hidden="true">&raquo;</span>
</a>
</li>
{% else %}
<li class="disabled"><span aria-hidden="true">&raquo;</span></li>
{% endif %}
</ul>
</nav>
</div>
</div>
{% endif %}
{% endblock %}
47 changes: 45 additions & 2 deletions tags/templates/view_tag.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ <h2>Tag flagged <small>{{ active_flag.subject }}</small></h2>
{% endif %}
<div class="row">
<div class="col-md-8 col-md-offset-2">
<p>
<div class="pull-left">
<em>Showing results {{ submissions.start_index }} through {{ submissions.end_index }} of {{ submissions.paginator.count }}</em>
{% if not active_flag %}
<span class="pull-right">
Expand All @@ -25,7 +25,50 @@ <h2>Tag flagged <small>{{ active_flag.subject }}</small></h2>
</a>
</span>
{% endif %}
</p>
</div>
{% if user.is_authenticated %}
<div class="pull-right">
{% if tag not in user.profile.favorite_tags.all %}
{% if tag not in user.profile.blocked_tags.all %}
<form method="post" class="inline" action="{% url 'tags:favorite_tag' tag_slug=tag.slug %}">
{% csrf_token %}
<button class="btn btn-success" type="submit">
<span class="glyphicon glyphicon-plus"></span>
Favorite tag
</button>
</form>
{% endif %}
{% else %}
<form method="post" class="inline" action="{% url 'tags:unfavorite_tag' tag_slug=tag.slug %}">
{% csrf_token %}
<button class="btn btn-warning" type="submit">
<span class="glyphicon glyphicon-minus"></span>
Unfavorite tag
</button>
</form>
{% endif %}
{% if tag not in user.profile.blocked_tags.all %}
{% if tag not in user.profile.favorite_tags.all %}
<form method="post" class="inline" action="{% url 'tags:block_tag' tag_slug=tag.slug %}">
{% csrf_token %}
<button class="btn btn-danger" type="submit">
<span class="glyphicon glyphicon-ban-circle"></span>
Block tag
</button>
</form>
{% endif %}
{% else %}
<form method="post" class="inline" action="{% url 'tags:unblock_tag' tag_slug=tag.slug %}">
{% csrf_token %}
<button class="btn btn-warning" type="submit">
<span class="glyphicon glyphicon-ok-circle"></span>
Unblock tag
</button>
</form>
{% endif %}
</div>
{% endif %}
<p class="clearfix">&nbsp;</p>
</div>
</div>
<div class="row">
Expand Down
Loading