def suggestions(request): suggestion_obj = Suggestions.for_user(request.user) suggestions = suggestion_obj.get_podcasts() current_site = RequestSite(request) return render(request, 'suggestions.html', { 'entries': suggestions, 'url': current_site })
def suggestions_for_user(user): if not user: raise QueryParameterMissing('user') from mygpo.users.models import Suggestions db = get_main_database() s = get_single_result(db, 'suggestions/by_user', key = user._id, include_docs = True, schema = Suggestions, ) if not s: s = Suggestions() s.user = user._id return s
def suggestions(request, count, format): count = parse_range(count, 1, 100, 100) suggestion_obj = Suggestions.for_user(request.user) suggestions = suggestion_obj.get_podcasts(count) title = _('gpodder.net - %(count)d Suggestions') % {'count': len(suggestions)} domain = RequestSite(request).domain p_data = lambda p: podcast_data(p, domain) return format_podcast_list(suggestions, format, title, json_map=p_data, jsonp_padding=request.GET.get('jsonp'))
def rate_suggestions(request): rating_val = int(request.GET.get('rate', None)) suggestion = Suggestions.for_user(request.user) suggestion.rate(rating_val, request.user._id) suggestion.save() messages.success(request, _('Thanks for rating!')) return HttpResponseRedirect(reverse('suggestions'))
def handle(self, *args, **options): docs = set() for username in options.get('users', []): user = User.get_user(username) # User docs.add(user._id) # Suggestions suggestions = Suggestions.for_user(user) docs.add(suggestions._id) # Podcast States for p_state in PodcastUserState.for_user(user): docs.add(p_state._id) # Categories for tag in p_state.tags: c = Category.for_tag(tag) if c: docs.add(c._id) # Podcast podcast = Podcast.get(p_state.podcast) docs.add(podcast._id) # Categories for s in podcast.tags: for tag in podcast.tags[s]: c = Category.for_tag(tag) if c: docs.add(c._id) # Episodes for episode in podcast.get_episodes(): docs.add(episode._id) # Episode States e_state = episode.get_user_state(user) if e_state._id: docs.add(e_state._id) db = get_main_database() docs = sorted(docs) self.dump(docs, db)
def blacklist(request, podcast_id): podcast_id = int(podcast_id) blacklisted_podcast = Podcast.for_oldid(podcast_id) suggestion = Suggestions.for_user(request.user) @repeat_on_conflict(['suggestion']) def _update(suggestion, podcast_id): suggestion.blacklist.append(podcast_id) suggestion.save() _update(suggestion=suggestion, podcast_id=blacklisted_podcast.get_id()) request.user.suggestions_up_to_date = False request.user.save() return HttpResponseRedirect(reverse('suggestions'))
def handle(self, *args, **options): max_suggestions = options.get('max') if options.get('username'): users = [User.get_user(options.get('username'))] else: users = User.all_users() users = filter(lambda u: u.is_active, users) if options.get('outdated'): users = filter(lambda u: not u.suggestions_up_to_date, users) if options.get('max_users'): users = users[:int(options.get('max_users'))] total = len(users) for n, user in enumerate(users): suggestion = Suggestions.for_user(user) subscribed_podcasts = list(set(user.get_subscribed_podcasts())) subscribed_podcasts = filter(None, subscribed_podcasts) subscribed_podcasts = filter(None, subscribed_podcasts) related = chain.from_iterable([p.related_podcasts for p in subscribed_podcasts]) related = filter(lambda pid: not pid in suggestion.blacklist, related) counter = Counter(related) get_podcast_id = itemgetter(0) suggested = map(get_podcast_id, counter.most_common(max_suggestions)) suggestion.podcasts = suggested suggestion.save() _update_user(user=user) progress(n+1, total)