def user_board_listing(request, account_id): """Return a paginated board listing view for account with account_id.""" metric_timeout_seconds = 60 * 2 queries = { # default to boards contributed to None: lambda x: ('contributed to', user_boards_contributed(x, viewing_user=request.user)), 'created': lambda x: ('created', user_boards_created(x, viewing_user=request.user)), 'evaluated': lambda x: ('evaluated', user_boards_evaluated(x, viewing_user=request.user)), 'contribute': lambda x: ('contributed to', user_boards_contributed(x, viewing_user=request.user)), } user = get_object_or_404(User, pk=account_id) query = request.GET.get('query') verb, board_list = queries.get(query, queries[None])(user) desc = _('List of intelligence boards user {username} has {verb}').format(username=user.username, verb=verb) context = { 'user': user, 'boards': make_paginator(request, board_list), 'contributors': cache.get_or_set('contributor_count', generate_contributor_count(), metric_timeout_seconds), 'evaluators': cache.get_or_set('evaluator_count', generate_evaluator_count(), metric_timeout_seconds), 'meta_description': desc, 'verb': verb } return render(request, 'boards/user_boards.html', context)
def user_board_listing(request, account_id): """Return a paginated board listing view for account with account_id.""" metric_timeout_seconds = 60 * 2 queries = { # default to boards contributed to None: lambda x: ( "contributed to", user_boards_contributed(x, viewing_user=request.user), ), "created": lambda x: ( "created", user_boards_created(x, viewing_user=request.user), ), "evaluated": lambda x: ( "evaluated", user_boards_evaluated(x, viewing_user=request.user), ), "contribute": lambda x: ( "contributed to", user_boards_contributed(x, viewing_user=request.user), ), } user = get_object_or_404(User, pk=account_id) query = request.GET.get("query") verb, board_list = queries.get(query, queries[None])(user) desc = _("List of intelligence boards user {username} has {verb}").format( username=user.username, verb=verb) return render( request, "boards/user_boards.html", { "user": user, "boards": make_paginator(request, board_list), "contributors": cache.get_or_set( "contributor_count", generate_contributor_count(), metric_timeout_seconds, ), "evaluators": cache.get_or_set("evaluator_count", generate_evaluator_count(), metric_timeout_seconds), "meta_description": desc, "verb": verb, }, )
def public_profile(request, account_id): """Return a view of the public profile associated with account_id.""" user = get_object_or_404(User, pk=account_id) context = { 'user': user, 'boards_created': user_boards_created(user, viewing_user=request.user)[:5], 'boards_contributed': user_boards_contributed(user, viewing_user=request.user), 'board_voted': user_boards_evaluated(user, viewing_user=request.user), 'meta_description': _("Account profile for user {name}").format(name=user), } return render(request, 'boards/public_profile.html', context)
def private_profile(request): """Return a view of the private profile associated with the authenticated user and handle settings.""" user = request.user if request.method == 'POST': form = SettingsForm(request.POST, instance=user.settings) if form.is_valid(): form.save() messages.success(request, _('Updated account settings.')) else: form = SettingsForm(instance=user.settings) context = { 'user': user, 'boards_created': user_boards_created(user, viewing_user=user)[:5], 'boards_contributed': user_boards_contributed(user, viewing_user=user), 'board_voted': user_boards_evaluated(user, viewing_user=user), 'meta_description': _('Account profile for user {name}').format(name=user), 'notifications': request.user.notifications.unread(), 'settings_form': form, } return render(request, 'boards/profile.html', context)
def private_profile(request): """Return a view of the private profile associated with the authenticated user and handle settings.""" user = request.user if request.method == "POST": form = SettingsForm(request.POST, instance=user.settings) if form.is_valid(): form.save() messages.success(request, _("Updated account settings.")) else: form = SettingsForm(instance=user.settings) context = { "user": user, "boards_created": user_boards_created(user, viewing_user=user)[:5], "boards_contributed": user_boards_contributed(user, viewing_user=user), "board_voted": user_boards_evaluated(user, viewing_user=user), "meta_description": _("Account profile for user {name}").format(name=user), "notifications": request.user.notifications.unread(), "settings_form": form, } return render(request, "boards/profile.html", context)