示例#1
0
def see_group(request, group_name):
    user = request.user
    tpl = {}
    tpl['group'] = group = Group.objects.get(name__exact=group_name)
    tpl['other_groups'] = pseudogroups.real_only().exclude(name__exact=group_name).order_by('name')
    tpl['members'] = members = group.user_set.all().order_by('first_name', 'last_name')
    tpl['pseudo_groups'] = pseudo_groups = pseudogroups.for_group(group)
    return render_to_response('baljan/group.html', tpl,
            context_instance=RequestContext(request))
示例#2
0
def search_person(request):
    tpl = {}
    terms = ""
    hits = []
    if request.method == 'POST':
        terms = request.POST['search-terms']
        hits = baljan.search.for_person(terms)

    if request.is_ajax():
        ser = serialize('json', hits, fields=(
            'first_name', 'last_name', 'username',
            ))
        return HttpResponse(ser)

    tpl['terms'] = terms
    tpl['hits'] = hits
    tpl['groups'] = pseudogroups.real_only().order_by('name')
    return render_to_response('baljan/search_person.html', tpl,
            context_instance=RequestContext(request))
示例#3
0
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))