From aa57d4bd410087bb1646b7c88d3e20fa0b9ad93c Mon Sep 17 00:00:00 2001 From: Stefan Koegl Date: Wed, 28 Jul 2010 22:34:54 +0200 Subject: [PATCH] add "My Tags" view at /tags/ --- htdocs/media/screen.css | 8 ++--- mygpo/urls.py | 2 ++ mygpo/web/templates/mytags.html | 71 ++++++++++++++++++++++++++++++++++++++++ mygpo/web/templates/podcast.html | 2 +- mygpo/web/templatetags/menu.py | 1 + mygpo/web/views/__init__.py | 22 ++++++++++++- mygpo/web/views/podcast.py | 7 ++++ 7 files changed, 107 insertions(+), 6 deletions(-) create mode 100644 mygpo/web/templates/mytags.html diff --git a/htdocs/media/screen.css b/htdocs/media/screen.css index 27197d7e..8c6ea2f2 100644 --- a/htdocs/media/screen.css +++ b/htdocs/media/screen.css @@ -672,7 +672,7 @@ div.come-in-box margin-right: 3%; } -#tag-list +div.tag-list { padding-left: 2%; padding-bottom: 2%; @@ -683,18 +683,18 @@ div.come-in-box width: 45%; } -#tag-list span.other +.tag-list span.other { color: #888; } -#tag-list span.own a.remove +.tag-list span.own a.remove { font-size: .7em; font-weight: bold; } -#tag-list span.own +.tag-list span.own { color: black; } diff --git a/mygpo/urls.py b/mygpo/urls.py index cb0ac8c2..fffcd529 100644 --- a/mygpo/urls.py +++ b/mygpo/urls.py @@ -93,6 +93,8 @@ urlpatterns = patterns('', (r'^search/', 'mygpo.search.views.search'), + (r'^tags/', 'mygpo.web.views.mytags'), + #Legacy API (r'^upload$', 'mygpo.api.legacy.upload'), (r'^getlist$', 'mygpo.api.legacy.getlist'), diff --git a/mygpo/web/templates/mytags.html b/mygpo/web/templates/mytags.html new file mode 100644 index 00000000..e12f1324 --- /dev/null +++ b/mygpo/web/templates/mytags.html @@ -0,0 +1,71 @@ +{% extends "base.html" %} +{% load i18n %} +{% load devices %} +{% load episodes %} +{% load podcasts %} + +{% load menu %} +{% block mainmenu %}{{ "/subscriptions/"|main_menu }}{% endblock %} +{% block sectionmenu %}{{ "/tags/"|section_menu }}{% endblock %} + +{% block title %}{% trans "My Tags" %}{% endblock %} + +{% block content %} + + {% if tags_podcast %} + +

{% trans "Tagged Podcasts" %}

+ + {% for podcast, taglist in tags_podcast.items %} + + + + + + {% endfor %} +
{{ podcast|podcast_logo }}{{ podcast.title|striptags}} + {% for tag in taglist %}{% spaceless %} + {% if tag.is_own %} + {{ tag.tag }} X + {% else %} + {{ tag.tag }} + {% endif %} + {% if not forloop.last %},{% endif %} + {% endspaceless %} + {% endfor %} + {% if user.is_authenticated %} +
+ + + +
+ {% endif %} +
+ + +

{% trans "All your Tags" %}

+ + {% for tag, podcast_list in tags_tag.items %} + + + + + {% endfor %} + +
{{ tag }} + {% for podcast in podcast_list %} + {{ podcast.podcast|podcast_logo }} + {% endfor %} +
+ + + {% else %} + +

{% trans "My Tags" %}

+
+ {% blocktrans %}You didn't tag any photos yet. Go to your subscriptions and tag some.{% endblocktrans %} +
+ {% endif %} + +{% endblock %} + diff --git a/mygpo/web/templates/podcast.html b/mygpo/web/templates/podcast.html index 70b2b05d..306841c8 100755 --- a/mygpo/web/templates/podcast.html +++ b/mygpo/web/templates/podcast.html @@ -97,7 +97,7 @@ {% endif %} -
+

Tags

{% for tag in tags %}{% spaceless %} {% if tag.is_own %} diff --git a/mygpo/web/templatetags/menu.py b/mygpo/web/templatetags/menu.py index 1feb96b6..c6c3ffe9 100644 --- a/mygpo/web/templatetags/menu.py +++ b/mygpo/web/templatetags/menu.py @@ -24,6 +24,7 @@ MENU_STRUCTURE = ( (_('My Podcasts'), ( ('/subscriptions/', _('Subscriptions')), ('/favorites/', _('Favorite Episodes')), + ('/tags/', _('My Tags')), ('/devices/', _('Devices')), ('/device/', _('Device')), ('/history/', _('History')), diff --git a/mygpo/web/views/__init__.py b/mygpo/web/views/__init__.py index 8a5098ce..fcc93bdb 100644 --- a/mygpo/web/views/__init__.py +++ b/mygpo/web/views/__init__.py @@ -20,7 +20,7 @@ from django.contrib.auth import authenticate, login, logout from django.contrib.auth.models import User from django.template import RequestContext from mygpo.api.models import Podcast, Episode, Device, EpisodeAction, SubscriptionAction, ToplistEntry, EpisodeToplistEntry, Subscription, SuggestionEntry, SyncGroup, SUBSCRIBE_ACTION, UNSUBSCRIBE_ACTION, SubscriptionMeta, UserProfile -from mygpo.data.models import Listener, SuggestionBlacklist +from mygpo.data.models import Listener, SuggestionBlacklist, PodcastTag from mygpo.data.mimetype import CONTENT_TYPES from mygpo.web.models import Rating, SecurityToken from mygpo.web.forms import UserAccountForm, DeviceForm, SyncForm, PrivacyForm, ResendActivationForm @@ -504,3 +504,23 @@ def gpodder_example_podcasts(request): return render_to_response('gpodder_examples.opml', { 'sponsored_podcast': sponsored_podcast }, context_instance=RequestContext(request)) + +@login_required +def mytags(request): + tags_podcast = {} + tags_tag = {} + for tag in PodcastTag.objects.filter(user=request.user): + if not tag.podcast in tags_podcast: + tags_podcast[tag.podcast] = [] + + if not tag.tag in tags_tag: + tags_tag[tag.tag] = [] + + tag.is_own = True + tags_podcast[tag.podcast].append(tag) + tags_tag[tag.tag].append(tag) + + return render_to_response('mytags.html', { + 'tags_podcast': tags_podcast, + 'tags_tag': tags_tag, + }, context_instance=RequestContext(request)) diff --git a/mygpo/web/views/podcast.py b/mygpo/web/views/podcast.py index 4812adb2..3e5ec365 100644 --- a/mygpo/web/views/podcast.py +++ b/mygpo/web/views/podcast.py @@ -156,6 +156,9 @@ def add_tag(request, pid): t = t.strip() tag = PodcastTag.objects.get_or_create(podcast=podcast, tag=t, source='user', user=request.user) + if request.GET.get('next', '') == 'mytags': + return HttpResponseRedirect('/tags/') + return HttpResponseRedirect('/podcast/%s' % pid) @@ -167,5 +170,9 @@ def remove_tag(request, pid): return HttpResponseBadRequest() PodcastTag.objects.filter(podcast=podcast, tag=tag_str, source='user', user=request.user).delete() + + if request.GET.get('next', '') == 'mytags': + return HttpResponseRedirect('/tags/') + return HttpResponseRedirect('/podcast/%s' % pid) -- 2.11.4.GIT