def respect_privacy(request, accountid): """ Check if the currently logged in user is allowed to see private TS data :param request: django request object - request.user is the website user :param accountid: int - user with the TrueSkill data that may be privacy protected :return: bool - if True: use only rounded numbers / don't show TS history graphs / etc """ accountid = int(accountid) if request.user.is_authenticated( ) and accountid == request.user.userprofile.accountid: # if the logged in user has the same accountid as the parameter accountid -> no privacy protection privacy = False else: # request privacyMode of player from SLDB try: privacy_mode = get_sldb_pref(accountid, "privacyMode") if privacy_mode == "0": privacy = False else: privacy = True except SLDBConnectionError as exc: logger.error( "Could not retrieve privacyMode for accountid '%s' from SLDB: %s", accountid, exc) privacy = True return privacy
def sldb_privacy_mode(request): c = all_page_infos(request) accountid = request.user.userprofile.accountid try: c["current_privacy_mode"] = get_sldb_pref(accountid, "privacyMode") except SLDBConnectionError as exc: logger.error("get_sldb_pref(%r, \"privacyMode\"): %s", accountid, exc) c["current_privacy_mode"] = -1 logger.debug("current_privacy_mode: %s (user: %s)", str(c["current_privacy_mode"]), request.user) if request.method == 'POST': # # POST # form = SLDBPrivacyForm(request.POST) if form.is_valid(): c["in_post"] = True new_mode = int(form.cleaned_data["mode"]) logger.debug("new_mode: %d (user: %s)", new_mode, request.user) try: sldb_pref = set_sldb_pref(accountid, "privacyMode", str(new_mode)) except: logger.exception("FIXME: to broad exception handling.") c["new_privacy_mode"] = -1 else: c["new_privacy_mode"] = new_mode logger.debug("new_privacy_mode: %d (user: %s)", new_mode, request.user) else: # # GET # form = SLDBPrivacyForm({'mode': c["current_privacy_mode"]}) c['form'] = form return render(request, 'sldb_privacy_mode.html', c)
def respect_privacy(request, accountid): """ Check if the currently logged in user is allowed to see private TS data :param request: django request object - request.user is the website user :param accountid: int - user with the TrueSkill data that may be privacy protected :return: bool - if True: use only rounded numbers / don't show TS history graphs / etc """ accountid = int(accountid) if request.user.is_authenticated() and accountid == request.user.userprofile.accountid: # if the logged in user has the same accountid as the parameter accountid -> no privacy protection privacy = False else: # request privacyMode of player from SLDB try: privacy_mode = get_sldb_pref(accountid, "privacyMode") if privacy_mode == "0": privacy = False else: privacy = True except SLDBConnectionError as exc: logger.error("Could not retrieve privacyMode for accountid '%s' from SLDB: %s", accountid, exc) privacy = True return privacy