def unsubscribe(request): token = request.REQUEST.get('token', '') email = request.REQUEST.get('email') unsubscribe_all_link = 'http://{}/unsubscribe?'.format(settings.DOMAIN) + urlencode({ 'action': 'ALL', 'token': util.token(email), 'email': email, }) ctx = { 'token': token, 'email': email, 'unsubscribed': False, 'unsubscribed_on_get': False, 'unsubscribed_settings': None, 'user': None, 'error': False, 'action': request.REQUEST.get('action'), 'unsubscribe_all_link': unsubscribe_all_link, } template_name = 'unsubscribe.html' if email and util.token(email) == token: # No user_id associated with the sent email, unsubscribe this email address from all email find_user = User.objects.filter(email=email) # If there is one and only one user with that email address, then pick them, otherwise we'll fall back to just an email address user = ctx['unsubscribing_user'] = find_user[0] if find_user.count() == 1 else None else: ctx['error'] = True return r2r_jinja(template_name, ctx, request) all_actions = EmailChannel.all_handled_actions() if user: # Support for unsubscribe headers. # We support passing in 'actions' action = request.REQUEST.get('action') if action and (action in EmailChannel.all_handled_actions() or action.upper() == 'ALL'): ctx['unsubscribed_on_get'] = ctx['unsubscribed'] = True user.kv.subscriptions.unsubscribe(action) Metrics.unsubscribe_action.record(request, action=action, method=request.method) if request.method == 'POST': # Handle the 'ALL' case separately because the semantics for it are inverted. # ie, if ALL is checked, it means to DISABLE. While if REMIXED is checked, it means ENABLE. handle_unsubscribe_post(user, request.REQUEST, request) # We use this dictionary to render the checkboxes in the html. ctx['unsubscribed'] = ctx['unsubscribed'] or get_unsubscriptions(user, all_actions) ctx['unsubscribed_settings'] = get_unsubscriptions(user) template_name = 'unsubscribe_for_user.html' else: ctx['error'] = True return r2r_jinja(template_name, ctx, request) return r2r_jinja(template_name, ctx, request)
def user_view(request, username, userpage_type): nav = browse.Navigation.load_json_or_404({ 'userpage_type': userpage_type, 'user': username, 'offset': request.GET.get('offset'), 'mobile': request.is_mobile, }) nav_data = nav.dump_json() posts = browse.get_user_data(request.user, nav) viewer_is_staff = request.user.is_authenticated() and request.user.is_staff user = get_object_or_404(User, username=username) private_beta_member = (user.id <= 63015) user_is_staff = user.is_staff friendlyname = "you" if user == request.user else username # A template variable that tells us if the current user is viewing her profile. user_is_self = user == request.user user_can_see_anonymous = (request.user == user or viewer_is_staff) showing_anonymous = True viewer_is_following = request.user.is_authenticated() and request.user.is_following(user) hide_userpage_from_google = user.has_lab('hide_userpage_from_google') if userpage_type == 'top' or userpage_type == 'top_anonymous': sort_method = 'top' elif userpage_type == 'new' or userpage_type == 'new_anonymous': sort_method = 'new' elif userpage_type == 'stickered': sort_method = 'stickered' # Can this comment be deleted by this user? # We only want to show the delete button if the user is looking at her user page. So we suppress it in the # browse pages for two reasons: # 1. It adds clutter to the page. There is already a lot of stuff going on in browse pages. # 2. It might encourage deletes. show_delete_option = user_is_self and userpage_type not in ['stickered'] sort = sort_method # The Jinja template expects "posts" to be called "tiles". tiles = posts render_options = tile_render_options(sort, False) avatar_comment = None bio = "" if user.userinfo.profile_image is not None: avatar_comment = Comment.details_by_id(user.userinfo.profile_image.id)() bio = user.userinfo.profile_image.reply_text if request.is_mobile: return r2r_jinja('mobile/user.html', locals()) return r2r_jinja('user/profile.html', locals())
def thread(request, short_id, page=None, gotoreply=None, sort_by_top=False, template_name='comment/new_base_thread.django.html'): from apps.monster.models import MONSTER_GROUP if not request.user.is_authenticated() and template_name == 'comment/new_base_thread.django.html' and not features.thread_new(request): return logged_out_thread_view(request, short_id, page=page, gotoreply=gotoreply) view_data = CommentViewData(request, short_id, page=page, gotoreply=gotoreply) if '/p/' + short_id == request.user.kv.post_pending_signup_url.get(): request.user.kv.post_pending_signup_url.delete() ctx = view_data.thread_context() ctx['request'] = request # monstermash posts redirect to monstermash app if ctx['op_comment'].category == MONSTER_GROUP and not ctx['viewer_is_staff']: return HttpResponseRedirect('/monster/{0}'.format(ctx['op_comment'].short_id())) # all hidden group posts are invisible to normal users if ctx['op_comment'].category in settings.HIDDEN_GROUPS and not ctx['viewer_is_staff']: return Http404() # If we hit the size threshold, record metric that the user is viewing a large thread if ctx['large_thread_view']: Metrics.large_thread_view.record(request) ctx['remix_invite_share_view'] = 'rmi' in request.GET if ctx['remix_invite_share_view']: ctx['fb_metadata']['title'] = "Come Remix With Me!" if ctx['op_comment'].title: ctx['fb_metadata']['description'] = """I just started a thread on Canvas, "{0}". Click the link to add your remix to the thread!""".format(op_comment.title) else: ctx['fb_metadata']['description'] = "I just started a thread on Canvas. Click the link to add your remix to the thread!" # Inviting experiment ctx['is_in_invite_remixers_v2'] = False ctx.update({ 'request': request, 'sort_by_top': sort_by_top, }) if request.is_mobile: return r2r_jinja("mobile/thread.html", ctx) if features.thread_new(request): ctx['has_top_remixes'] = bool(len(ctx['top_remixes'])) if sort_by_top: ctx['replies'] = ctx['top_remixes'] ctx['has_top_remixes'] = True return r2r_jinja('threads_new/thread.html', ctx, request) return r2r(template_name, ctx)
def unsubscribe(request): token = request.REQUEST.get('token', '') email = request.REQUEST.get('email') ctx = { 'token': token, 'email': email, 'unsubscribed': False, 'unsubscribed_on_get': False, 'unsubscribed_settings': None, 'user': None, 'error': False, } template_name = 'unsubscribe.html' if email and util.token(email) == token: # No user_id associated with the sent email, unsubscribe this email address from all email find_user = User.objects.filter(email=email) # If there is one and only one user with that email address, then pick them, otherwise we'll fall back to just an email address user = ctx['user'] = find_user[0] if find_user.count() == 1 else None else: ctx['error'] = True return r2r_jinja(template_name, ctx, request) all_actions = EmailChannel.all_handled_actions() if user: # Support for unsubscribe headers. # We support passing in 'actions' action = request.REQUEST.get('action') if action and (action in EmailChannel.all_handled_actions() or action.upper() == 'ALL'): ctx['unsubscribed_on_get'] = ctx['unsubscribed'] = True user.kv.subscriptions.unsubscribe(action) Metrics.unsubscribe_action.record(request, action=action, method=request.method) if request.method == 'POST': # Handle the 'ALL' case separately because the semantics for it are inverted. # ie, if ALL is checked, it means to DISABLE. While if REMIXED is checked, it means ENABLE. handle_unsubscribe_post(user, request.REQUEST, request) # We use this dictionary to render the checkboxes in the html. ctx['unsubscribed'] = ctx['unsubscribed'] or get_unsubscriptions( user, all_actions) ctx['unsubscribed_settings'] = get_unsubscriptions(user) template_name = 'unsubscribe_for_user.html' else: unsubscribe_newsletter(email) ctx['unsubscribed'] = True Metrics.unsubscribe_email_address.record(request) return r2r_jinja(template_name, ctx, request)
def staff_stars(request): ctx = { 'comments': QuestComment.objects.filter( stickers__user__is_staff=True, ).distinct().order_by('-id') } return r2r_jinja('staff/comments_grid.html', ctx, request)
def ugq_new(request): ctx = { 'comments': Quest.unjudged().filter(ugq=True).order_by('-id')[:knobs.WHITELIST_COMMENTS_PER_PAGE], 'body_class': 'new_ugq', 'unjudged_count': Quest.objects.filter(ugq=True, judged=False).count(), } return r2r_jinja('whitelisting/new.html', ctx, request)
def signup(request, skip_invite_code=None, template="signup/signup.html", success_redirect="/onboarding/start"): cookies_to_delete = [] cookies_to_set = {} error_context = get_signup_context(request, skip_invite_code, template, cookies_to_set, cookies_to_delete) Metrics.signup_form_view.record(request) def process_response(response): for key in cookies_to_delete: response.delete_cookie(key) for key, val in cookies_to_set.items(): response.set_cookie(key, val) return response if not error_context: # error_context is only None if this is a POST (and with no errors). # DEPRECATED: next and next_params. we use cookies for these now - see get_signup_context if request.POST.get('next'): next_params = request.POST.get('next_params', '') if next_params: next_params = '?' + next_params success_redirect = request.POST['next'] return process_response(HttpResponseRedirect(success_redirect + next_params)) return process_response(HttpResponseRedirect(success_redirect)) else: request.session['failed_signup'] = True if template == "signup_prompt.django.html": return process_response(r2r(template, error_context)) return process_response(r2r_jinja(template, error_context, request))
def password_reset_confirm(request, uidb36=None, token=None, template_name='registration/password_reset_confirm.html', token_generator=default_token_generator, set_password_form=SetPasswordForm, post_reset_redirect=None): """ View that checks the hash in a password reset link and presents a form for entering a new password. """ assert uidb36 is not None and token is not None # checked by URLconf if post_reset_redirect is None: post_reset_redirect = reverse('drawquest.apps.drawquest_auth.views.password_reset_complete') try: uid_int = base36_to_int(uidb36) user = User.objects.get(id=uid_int) except (ValueError, User.DoesNotExist): user = None ctx = {} if user is not None and token_generator.check_token(user, token): ctx['validlink'] = True if request.method == 'POST': form = set_password_form(user, request.POST) if form.is_valid(): form.save() return HttpResponseRedirect(post_reset_redirect) else: form = set_password_form(None) else: ctx['validlink'] = False form = None ctx['form'] = form return r2r_jinja(template_name, ctx, request)
def all_paginated(request, after_id=None): ctx = { 'comments': QuestComment.all_objects.filter(id__gt=after_id, ).order_by('-id') [:knobs.WHITELIST_COMMENTS_PER_PAGE], } return r2r_jinja('whitelisting/whitelist_items.html', ctx, request)
def password_reset( request, is_admin_site=False, template_name='registration/password_reset_form.html', domain_override='example.com', email_template_name='registration/password_reset_email.html', password_reset_form=PasswordResetForm, token_generator=default_token_generator, post_reset_redirect=None): if post_reset_redirect is None: post_reset_redirect = reverse( 'drawquest.apps.drawquest_auth.views.password_reset_done') if request.method == "POST": form = password_reset_form(request.POST) if form.is_valid(): opts = {} opts['use_https'] = request.is_secure() opts['token_generator'] = token_generator opts['email_template_name'] = email_template_name opts['request'] = request if domain_override: opts['domain_override'] = domain_override if is_admin_site: opts['domain_override'] = request.META['HTTP_HOST'] form.save(**opts) return HttpResponseRedirect(post_reset_redirect) else: form = password_reset_form() return r2r_jinja(template_name, {'form': form}, request)
def share_page(request, short_id): try: comment_id = get_mapping_id_from_short_id(short_id) except ValueError: raise Http404 comment = get_object_or_404(QuestComment, id=comment_id) comment_details = comment.details() quest_details = QuestDetails.from_id(comment_details.quest_id) author_details = UserDetails.from_id(comment.author_id) ctx = { 'quest': quest_details, 'quest_template_url': '', 'comment': comment_details, 'author': author_details, 'private_profile': bool(UserKV(comment.author_id).web_profile_privacy.get()), } if quest_details.content: ctx.update({ 'quest_template_url': quest_details.content.get_absolute_url_for_image_type('gallery'), 'original_quest_template_url': quest_details.content.get_absolute_url_for_image_type('original'), }) return r2r_jinja('quest_comments/share_comment_page.html', ctx, request)
def max_strokes(request, stroke_count): contents = Content.objects.filter(stroke_count__lte=stroke_count).exclude(stroke_count__isnull=True) contents = contents[:500] ctx = { 'comments': [QuestComment.objects.get(id=content.first_caption.id) for content in contents], } return r2r_jinja('staff/comments_grid.html', ctx, request)
def flag_queue_paginated(request, after_id=None): ctx = { 'comments': QuestComment.unjudged_flagged().filter( id__gt=after_id, ).order_by('id')[:knobs.WHITELIST_COMMENTS_PER_PAGE], } return r2r_jinja('whitelisting/whitelist_items.html', ctx, request)
def user_edit(request, username): viewer_is_staff = request.user.is_authenticated() and request.user.is_staff if request.user.username != username and not viewer_is_staff: raise PermissionDenied() user = get_object_or_404(User, username=username) current = user.userinfo.profile_image show_start_options = current is None bio_text = "" try: start_content = Content.all_objects.get(id=Content.DRAW_FROM_SCRATCH_PK).details() except Content.DoesNotExist: start_content = None if current is not None: start_content = current.reply_content.details() bio_text = current.reply_text else: bio_text = user.userinfo.bio_text thread_op = current if current is not None and current.parent_comment: thread_op = current.parent_comment ctx = { 'start_content': start_content, 'show_start_options': current is None, 'viewer_is_staff': viewer_is_staff, 'current_comment': current.details() if current is not None else None, 'bio_text': bio_text, 'thread_op': thread_op.details() if thread_op is not None else None, } return r2r_jinja("user/profile_edit.html", ctx, request)
def create(request): ctx = { 'request': request, 'monster_group': MONSTER_GROUP, 'monster_content': Content.all_objects.get(id=Content.SMALL_DRAW_FROM_SCRATCH_PK).details(), } return r2r_jinja('monster/create.html', ctx)
def password_reset( request, is_admin_site=False, template_name="registration/password_reset_form.html", domain_override="example.com", email_template_name="registration/password_reset_email.html", password_reset_form=PasswordResetForm, token_generator=default_token_generator, post_reset_redirect=None, ): if post_reset_redirect is None: post_reset_redirect = reverse("drawquest.apps.drawquest_auth.views.password_reset_done") if request.method == "POST": form = password_reset_form(request.POST) if form.is_valid(): opts = {} opts["use_https"] = request.is_secure() opts["token_generator"] = token_generator opts["email_template_name"] = email_template_name opts["request"] = request if domain_override: opts["domain_override"] = domain_override if is_admin_site: opts["domain_override"] = request.META["HTTP_HOST"] form.save(**opts) return HttpResponseRedirect(post_reset_redirect) else: form = password_reset_form() return r2r_jinja(template_name, {"form": form}, request)
def flag_queue(request): ctx = { 'comments': QuestComment.unjudged_flagged().order_by('id')[:knobs.WHITELIST_COMMENTS_PER_PAGE], 'body_class': 'flag_queue', 'unjudged_count': QuestComment.objects.filter(judged=False).count(), } return r2r_jinja('whitelisting/flagged.html', ctx, request)
def share_page(request, short_id): try: comment_id = get_mapping_id_from_short_id(short_id) except ValueError: raise Http404 comment = get_object_or_404(QuestComment, id=comment_id) comment_details = comment.details() quest_details = QuestDetails.from_id(comment_details.quest_id) author_details = UserDetails.from_id(comment.author_id) ctx = { "quest": quest_details, "quest_template_url": "", "comment": comment_details, "author": author_details, "private_profile": bool(UserKV(comment.author_id).web_profile_privacy.get()), } if quest_details.content: ctx.update( { "quest_template_url": quest_details.content.get_absolute_url_for_image_type("gallery"), "original_quest_template_url": quest_details.content.get_absolute_url_for_image_type("original"), } ) return r2r_jinja("quest_comments/share_comment_page.html", ctx, request)
def all_paginated(request, after_id=None): ctx = { 'comments': QuestComment.all_objects.filter( id__gt=after_id, ).order_by('-id')[:knobs.WHITELIST_COMMENTS_PER_PAGE], } return r2r_jinja('whitelisting/whitelist_items.html', ctx, request)
def flag_queue(request): ctx = { 'comments': QuestComment.unjudged_flagged().order_by('id') [:knobs.WHITELIST_COMMENTS_PER_PAGE], } return r2r_jinja('whitelisting/flagged.html', ctx, request)
def all(request): ctx = { 'comments': QuestComment.all_objects.all().order_by('-id')[:knobs.WHITELIST_COMMENTS_PER_PAGE], 'body_class': 'all', 'unjudged_count': QuestComment.objects.filter(judged=False).count(), } return r2r_jinja('whitelisting/all.html', ctx, request)
def all(request): ctx = { 'comments': QuestComment.all_objects.all().order_by('-id') [:knobs.WHITELIST_COMMENTS_PER_PAGE], } return r2r_jinja('whitelisting/new.html', ctx, request)
def flag_queue_paginated(request, after_id=None): ctx = { 'comments': QuestComment.unjudged_flagged().filter(id__gt=after_id, ).order_by( 'id')[:knobs.WHITELIST_COMMENTS_PER_PAGE], } return r2r_jinja('whitelisting/whitelist_items.html', ctx, request)
def quest(request, short_id, slug=None): quest = get_object_or_404(Quest, id=base36decode_or_404(short_id)) _slug = slugify(quest.title) if _slug and _slug != slug: return redirect('quest', base36encode(quest.id), _slug) quest_details = quest.details() ctx = { 'quest': quest_details, 'comments': top_gallery_comments(quest, include_reactions=False), 'quest_template_url': '', 'original_quest_template_url': '', } if quest.reply_content_id: ctx.update({ 'quest_template_url': quest_details.content.get_absolute_url_for_image_type('gallery'), 'original_quest_template_url': quest_details.content.get_absolute_url_for_image_type('original'), }) return r2r_jinja('quests/quest.html', ctx, request)
def user_ip_history(request, username): user = get_object_or_404(User, username=username) ip_history = [(int_to_ip(ip), timestamp) for (ip, timestamp) in user.redis.ip_history.with_scores[:]] ctx = { 'target_user': user, 'ip_history': ip_history, } return r2r_jinja('staff/ip_history.html', ctx, request)
def stamps_used(request, content): content = Content.objects.get(id=content) stamps = content.stamps_used.all() ctx = { 'content': content, 'stamps': stamps, } return r2r_jinja('stamps_used.html', ctx, request)
def user_activity_stream(request, username): user = User.objects.get(username=username) activities = legacy_get_activity_stream_items(user, count=450) ctx = { 'examined_user': user, 'activities': activities, } return r2r_jinja('staff/activity_stream.html', ctx, request)
def user_iap_receipts(request, username): user = User.objects.get(username=username) receipts = user.iap_receipts.all().order_by('-timestamp') ctx = { 'examined_user': user, 'receipts': receipts, } return r2r_jinja('staff/iap_receipts.html', ctx, request)
def ip_user_history(request, ip): ip_int = ip_to_int(ip) history = IP(ip_int).user_history.with_scores[:] users = User.objects.in_bulk_list([user for (user, ts) in history]) history = zip(users, [ts for (user, ts) in history]) ctx = { 'history': history, } return r2r_jinja('staff/user_history.html', ctx, request)
def blocking_coc(request): if request.method == "POST": if UserWarning.objects.filter(user=request.user, confirmed=0): return HttpResponseRedirect('/warning') else: request.user.redis.user_kv.hdel('sandbox') return HttpResponseRedirect('/') else: return r2r_jinja('blocking_coc.html', locals(), request)
def sticky_admin(request): if request.method == 'POST': loaded = {} delete = [] for key, val in request.POST.iteritems(): if 'sort_order' not in key and 'text' not in key: continue _, id_ = key.split('-') op = get_object_or_404(Comment, id=id_) sticky = None if 'sort_order' in key: if val is None or not str(val).strip(): try: sticky = StickyThread.objects.get(comment=op) delete.append(sticky.id) except StickyThread.DoesNotExist: pass continue try: ordinal = int(val) except ValueError: ordinal = 0 if id_ not in loaded: loaded[id_] = sticky = StickyThread.get_or_create(op) else: sticky = loaded[id_] sticky.sort = ordinal elif 'text' in key: if id_ not in loaded: loaded[id_] = sticky = StickyThread.get_or_create(op) else: sticky = loaded[id_] sticky.text = val for _, sticky in loaded.iteritems(): if sticky.id in delete: sticky.delete() else: sticky.save() page_updated = True else: page_updated = False if page_updated: update_sticky_thread_cache() ctx = { 'sticky_threads': sticky_threads(), 'page_updated': page_updated, } return r2r_jinja('sticky_threads/admin.html', ctx, request)
def whitelisting_paginated(request, after_id=None): freeze_id = redis.get('dq:comment_freeze_id') comments = [] if after_id >= freeze_id: comments = QuestComment.unjudged().filter(id__gt=after_id, ).order_by( 'id')[:knobs.WHITELIST_COMMENTS_PER_PAGE], return r2r_jinja('whitelisting/whitelist_items.html', {'comments': comments}, request)
def whitelisting_paginated(request, after_id=None): freeze_id = redis.get('dq:comment_freeze_id') comments = [] if after_id >= freeze_id: comments = QuestComment.unjudged().filter( id__gt=after_id, ).order_by('id')[:knobs.WHITELIST_COMMENTS_PER_PAGE], return r2r_jinja('whitelisting/whitelist_items.html', {'comments': comments}, request)
def ugq_new(request): ctx = { 'comments': Quest.unjudged().filter( ugq=True).order_by('-id')[:knobs.WHITELIST_COMMENTS_PER_PAGE], 'body_class': 'new_ugq', 'unjudged_count': Quest.objects.filter(ugq=True, judged=False).count(), } return r2r_jinja('whitelisting/new.html', ctx, request)
def disabled(request): ctx = { 'comments': QuestComment.disabled().order_by('-id') [:knobs.WHITELIST_COMMENTS_PER_PAGE], 'body_class': 'disabled', 'unjudged_count': QuestComment.objects.filter(judged=False).count(), } return r2r_jinja('whitelisting/disabled.html', ctx, request)
def logged_out_thread_view(request, short_id, page=None, gotoreply=None): view_data = CommentViewData(request, short_id, page=page, gotoreply=gotoreply) ctx = view_data.thread_context() if request.is_mobile: return r2r_jinja('mobile/thread.html', ctx) fact.record('flow_start', request, {}) return render_to_response('threads/new_thread.django.html', ctx, context_instance=RequestContext(request))
def max_strokes(request, stroke_count): contents = Content.objects.filter(stroke_count__lte=stroke_count).exclude( stroke_count__isnull=True) contents = contents[:500] ctx = { 'comments': [ QuestComment.objects.get(id=content.first_caption.id) for content in contents ], } return r2r_jinja('staff/comments_grid.html', ctx, request)
def thread_comment_details(request, comment_id): comment = get_object_or_404(Comment, pk=comment_id) replies = [c.details() for c in comment.get_deep_replies()] remixes = [c.details() for c in comment.get_remixes()] ctx = { 'request': request, 'replies': replies, 'remixes': remixes, } return r2r_jinja('threads/comment_details.html', ctx)
def support(request): ctx = {} if request.method == 'POST': form = SupportForm(request.POST) if form.is_valid(): subject = 'Support request from {}'.format(form.cleaned_data['username']) body = form.cleaned_data['message'] mail = EmailMessage(subject, body, '*****@*****.**', ['*****@*****.**'], headers={'Reply-To': form.cleaned_data['sender']}) mail.send() return r2r_jinja('drawquest/support_submitted.html', ctx, request) ctx['form'] = form else: form = SupportForm() ctx['form'] = form return r2r_jinja('drawquest/support.html', ctx, request)
def new_divvy(request, id_range=None): from_, to = get_divvy_range(id_range) per_page = knobs.WHITELIST_COMMENTS_PER_PAGE * (to - from_) comments = divvy(QuestComment.unjudged().order_by('-id')[:per_page], from_, to) ctx = { 'comments': comments, 'body_class': 'new', 'unjudged_count': QuestComment.objects.filter(judged=False).count(), } return r2r_jinja('whitelisting/new.html', ctx, request)
def random(request): part = MonsterPart.get_random_new_monster(request.user) skip = 'skip' in request.GET if part: if skip: Metrics.skip_monster.record(request, monster_id=part.id) else: Metrics.random_monster_complete.record(request, monster_id=part.id) return HttpResponseRedirect('/monster/{0}/complete'.format(base36encode(part.id))) else: Metrics.no_more_monsters.record(request) ctx = {'request':request} return r2r_jinja('monster/nomore.html', ctx)
def ugq_moderation(request): flagged = Quest.unjudged_flagged().filter(ugq=True).order_by('-id') unknown = Quest.by_unknown_users().filter(ugq=True).order_by('-id').exclude(flags__undone=False) ctx = _moderation_context([flagged, unknown], id_range=None) ctx.update({ 'flagged_count': flagged.count(), 'trusted_user_count': UserInfo.objects.filter(trusted=True).count(), 'body_class': 'ugq_moderation', }) return r2r_jinja('whitelisting/ugq_moderation.html', ctx, request)
def suggested_users(request): user_list = [] users = sample(SUGGESTED_USERS, 5) users = list(User.objects.filter(username__in=users, is_active=True)) for user in users: if user.userinfo.profile_image is not None: avatar_comment = Comment.details_by_id( user.userinfo.profile_image.id)() else: avatar_comment = None is_following = False try: is_following = request.user.is_following(user) except AttributeError: pass user_list.append({ 'user': user, 'avatar_comment': avatar_comment, 'is_following': is_following, 'is_self': request.user == user, }) topics = sample(SUGGESTED_TOPICS, 5) topics = [{'name': topic} for topic in topics] topic_previews = Content.all_objects.filter( id__in=SUGGESTED_TOPIC_PREVIEWS.values()) topic_previews = CachedCall.multicall( [preview.details for preview in topic_previews]) preview_mapping = dict([(content['id'], content) for content in topic_previews]) try: followed_tags = request.user.redis.followed_tags except AttributeError: followed_tags = [] for topic in topics: topic['preview'] = preview_mapping.get( SUGGESTED_TOPIC_PREVIEWS[topic['name']]) topic['is_following'] = topic['name'] in followed_tags ctx = { 'request': request, 'users': user_list, 'topics': topics, } return r2r_jinja('onboarding/suggested_users.html', ctx, request)