コード例 #1
0
ファイル: views.py プロジェクト: Baljan/cafesys-fork
def _trade_answer(request, request_pk, redir, accept):
    u = request.user
    tr = baljan.models.TradeRequest.objects.get(pk=int(request_pk))
    assert tr in trades.requests_sent_to(u)
    if accept:
        tr.accept()
    else:
        tr.deny()
    return HttpResponseRedirect(redir)
コード例 #2
0
ファイル: views.py プロジェクト: Baljan/cafesys-fork
def see_user(request, who):
    u = request.user
    tpl = {}

    watched = User.objects.get(username__exact=who)
    watching_self = u == watched
    if u.is_authenticated():
        profile_form_cls_inst = (
                (baljan.forms.UserForm, u),
                (baljan.forms.ProfileForm, u.get_profile()),
                )

    if watching_self and request.method == 'POST':
        profile_forms = [c(request.POST, request.FILES, instance=i) 
                for c, i in profile_form_cls_inst]

        # Make sure all forms are valid before saving.
        all_valid = True
        for f in profile_forms:
            if not f.is_valid():
                all_valid = False
        if all_valid:
            for f in profile_forms:
                f.save()
        watched = User.objects.get(username__exact=who)

    tpl['watched'] = watched
    tpl['watching_self'] = watching_self
    tpl['watched_groups'] = pseudogroups.real_only().filter(user=watched).order_by('name')

    are_friends = False
    pending_friends = False
    if u.is_authenticated():
        are_friends = watched in u.get_profile().friend_users()
        if are_friends:
            pass
        else:
            pending_friends = friendrequests.pending_between(u, watched)

    tpl['are_friends'] = are_friends
    tpl['pending_friends'] = pending_friends

    tpl['friend_request_classes'] = (
            'confirmed-highlight' if are_friends or watching_self else '',
            'pending-highlight' if pending_friends else '',
            )

    tpl['friends'] = watched.get_profile().friend_users().order_by('first_name', 'last_name')
    if watching_self:
        tpl['sent_friend_requests'] = friendrequests.sent_by(u)
        tpl['received_friend_requests'] = friendrequests.sent_to(u)
        jgr = baljan.models.JoinGroupRequest.objects.filter(user=u)
        tpl['join_group_requests'] = jgr
        tpl['sent_trade_requests'] = tr_sent = trades.requests_sent_by(u)
        tpl['received_trade_requests'] = tr_recd = trades.requests_sent_to(u)
        tpl['trade_requests'] = tr_sent or tr_recd
        profile_forms = [c(instance=i) for c, i in profile_form_cls_inst]
        tpl['profile_forms'] = profile_forms
    
    # Call duties come after work shifts because they are more frequent.
    tpl['signup_types'] = (
            (_("work shifts"), ['work'], signups_for(watched)),
            (_("call duties"), ['call-duty'], callduties_for(watched)),
            )
    return render_to_response('baljan/user.html', tpl,
            context_instance=RequestContext(request))