コード例 #1
0
def dashboard(user_url_segment=None):
    if user_url_segment is None:
        target_user = UserData.get_current_user_data()
    else:
        target_user = UserData.get_from_url_segment(user_url_segment)
    if target_user is None:
        template_values = {
            'target_user': user_url_segment,
        }
        return render_jinja_template("noprofile.html", template_values), 404

    if target_user.username != user_url_segment:
        return redirect('/dashboard/{0}'.format(target_user.username))

    # If looking at the current user's profile, hilight the users name in the
    # nav bar
    if target_user == UserData.get_current_user_data():
        return redirect('/'.format(target_user.username))
    else:
        active = None

    template_values = {
        'target_user': target_user,
    }
    return render_jinja_template("dashboard.html", template_values)
コード例 #2
0
def profile(user_url_segment):
    target_user = UserData.get_from_url_segment(user_url_segment)
    if target_user is None:
        template_values = {
            'target_user': user_url_segment,
        }
        return render_jinja_template("noprofile.html", template_values), 404

    if target_user.username != user_url_segment:
        return redirect('/profile/{0}'.format(target_user.username))

    # If looking at the current user's profile, hilight the users name in the
    # nav bar
    if target_user == UserData.get_current_user_data():
        active = 'profile'
    else:
        active = None

    template_values = {
        'active_page': active,
        'target_user': target_user,
    }
    return render_jinja_template("profile.html", template_values)
コード例 #3
0
        def wrapper(*args, **kwargs):
            current_user = UserData.get_current_user_data()
            if not current_user:
                template_values = {
                    u'message': u"Not logged in",
                    u'html_template': u"nologin.html",
                }
                return build_response(output_format, template_values)

            missing_perms = []
            if 'user_url_segment' in kwargs:
                other_user_url_segment = kwargs['user_url_segment']
            elif 'user_id' in kwargs:
                other_user_url_segment = kwargs['user_id']
            else:
                other_user_url_segment = None

            if other_user_url_segment:
                other_user = UserData.get_from_url_segment(other_user_url_segment)
            else:
                other_user = None

            for p in perms:
                if not check_perms(current_user, p, other_user):
                    missing_perms.append(p)

            template_values = {
                u'message': "Don't have permission",
                u'html_template': "nopermission.html",
                u'perms': missing_perms,
            }
            if len(missing_perms) > 0 and logic == 'and':
                return build_response(output_format, template_values)
            elif len(missing_perms) == len(perms) and logic == 'or':
                return build_response(output_format, template_values)

            return f(*args, **kwargs)