def mytags(request): tags_podcast = {} tags_tag = defaultdict(list) for podcast_id, taglist in Tag.for_user(request.user).items(): podcast = Podcast.get(podcast_id) tags_podcast[podcast] = taglist for tag in taglist: tags_tag[ tag ].append(podcast) return render(request, 'mytags.html', { 'tags_podcast': tags_podcast, 'tags_tag': dict(tags_tag.items()), })
def get_tags(podcast, user): tags = {} for t in Tag.for_podcast(podcast): tag_str = t.lower() tags[tag_str] = False if not user.is_anonymous(): users_tags = Tag.for_user(user, podcast.get_id()) for t in users_tags.get(podcast.get_id(), []): tag_str = t.lower() tags[tag_str] = True tag_list = [{'tag': key, 'is_own': value} for key, value in tags.iteritems()] tag_list.sort(key=lambda x: x['tag']) if len(tag_list) > MAX_TAGS_ON_PAGE: tag_list = filter(lambda x: x['is_own'], tag_list) tag_list.append({'tag': '...', 'is_own': False}) return tag_list