def get_relevent_lang_tags(user, language=None): rev_tags = [] rev_languages = [] res = UserTag.gql("WHERE user=:1", user) userTags = res.fetch(settings.RELEVENT_TAG_LIMIT) if not userTags: return ([],[]) for ut in userTags: rev_languages.extend(ut.tag.languages) if language == None or language in ut.tag.languages: rev_tags.append(ut.tag) return (rev_tags, [get_language(lang) for lang in set(rev_languages)])
def tag_list(request, user_id): user = UserPref.get_by_id(int(user_id)) if not user: raise Http404 tmp_tags = UserTag.all().filter('user', user.key()) tags = [] for ut in tmp_tags: try: tags.append(ut.tag) except: pass return object_list(request, queryset=tags, allow_empty=True, template_name='account/tag_list.html', extra_context={'CURRENT_USER': user, 'CURRENT_PAGE': 'user_tag_list'}, paginate_by=settings.TAG_LIST_PAGE_SIZE)
def language_tags(request, language, user_id): user = UserPref.get_by_id(int(user_id)) if not user: raise Http404 tmp_tags = UserTag.all().filter('user', user.key()) tags = [] for ut in tmp_tags: if language in ut.tag.languages: tags.append(ut.tag) for l, v in settings.SUPPORT_LANGUAGES.items(): if l == language: current_language = {'name':v, 'key':l} break; return object_list(request, queryset=tags, allow_empty=True, template_name='account/tag_list.html', extra_context={'CURRENT_USER': user, 'CURRENT_LANGUAGE': current_language, 'CURRENT_PAGE': 'user_tag_list'}, paginate_by=settings.TAG_LIST_PAGE_SIZE)