예제 #1
0
파일: views.py 프로젝트: ahrokib/mozillians
def _profile(request, person, use_master):
    vouch_form = None
    ldap = UserSession.connect(request)
    profile = person.get_profile()

    # TODO: rely more on db for this test
    if not profile.is_vouched and request.user.unique_id != person.unique_id:
        vouch_form = forms.VouchForm(initial=dict(vouchee=person.unique_id))

    services = ldap.profile_service_ids(person.unique_id, use_master)

    person.irc_nickname = None
    if MOZILLA_IRC_SERVICE_URI in services:
        person.irc_nickname = services[MOZILLA_IRC_SERVICE_URI]
        del services[MOZILLA_IRC_SERVICE_URI]

    # Get user groups from their profile.
    groups = person.get_profile().groups.all()

    data = dict(person=person,
                profile=profile,
                vouch_form=vouch_form,
                services=services,
                groups=groups)
    return render(request, 'phonebook/profile.html', data)
예제 #2
0
파일: views.py 프로젝트: ahrokib/mozillians
def vouch(request):
    """
    When a voucher approves a vouch for a vouchee, there
    can be a replication lag between master -> slave. As a
    result, there is a possibility that viewing the vouchee's
    profile will not show the updated state. So we currently
    will cache the state for immediate feedback.
    """
    form = forms.VouchForm(request.POST)
    if form.is_valid():
        data = form.cleaned_data
        vouchee = data.get('vouchee')
        # TODO: make the form give us the User's id...
        p = UserProfile.objects.get_by_unique_id(vouchee)
        p.vouch(request.user.get_profile())

        # TODO: Is this still necessary?...
        cache.set('vouched_' + vouchee, True)

        # Notify the current user that they vouched successfully.
        msg = _(u'Thanks for vouching for a fellow Mozillian! '
                'This user is now vouched!')
        messages.info(request, msg)

        return redirect(reverse('profile', args=[vouchee]))
예제 #3
0
파일: views.py 프로젝트: sumlaj/mozillians
def profile(request, username):
    """View a profile by username."""
    user = get_object_or_404(User, username=username)
    vouch_form = None
    profile = user.get_profile()

    if not profile.is_vouched and request.user.get_profile().is_vouched:
        vouch_form = forms.VouchForm(initial=dict(vouchee=profile.pk))

    data = dict(shown_user=user, profile=profile, vouch_form=vouch_form)
    return render(request, 'phonebook/profile.html', data)
예제 #4
0
파일: views.py 프로젝트: sumlaj/mozillians
def vouch(request):
    """Vouch a user."""
    form = forms.VouchForm(request.POST)

    if form.is_valid():
        p = UserProfile.objects.get(pk=form.cleaned_data.get('vouchee'))
        p.vouch(request.user.get_profile())

        # Notify the current user that they vouched successfully.
        msg = _(u'Thanks for vouching for a fellow Mozillian! '
                'This user is now vouched!')
        messages.info(request, msg)

        return redirect(reverse('profile', args=[p.user.username]))

    return HttpResponseForbidden
예제 #5
0
def profile(request, username):
    """View a profile by username."""
    user = get_object_or_404(User, username=username)

    vouch_form = None
    profile = user.get_profile()

    if not profile.is_vouched and request.user.username != username:
        vouch_form = forms.VouchForm(initial=dict(vouchee=profile.pk))

    # Get user groups from their profile.
    groups = profile.groups.all()

    data = dict(shown_user=user,
                profile=profile,
                vouch_form=vouch_form,
                groups=groups)
    return render(request, 'phonebook/profile.html', data)