Changeset aa2aa58 for asadb


Ignore:
Timestamp:
Nov 2, 2011, 11:05:58 PM (14 years ago)
Author:
Alex Dehnert <adehnert@…>
Branches:
master, space-access, stable, stage, test-hooks
Children:
7a875d1
Parents:
2b38cb9
git-author:
Alex Dehnert <adehnert@…> (11/02/11 23:05:58)
git-committer:
Alex Dehnert <adehnert@…> (11/02/11 23:05:58)
Message:

Add account lookup tool

Given an account number and a username, find the group and what roles,
if any, the person holds in that group

Location:
asadb/groups
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • asadb/groups/urls.py

    r2919697 raa2aa58  
    2020    url(r'^recent_changes/$', groups.views.GroupHistoryView.as_view(), name='manage-history', ),
    2121    url(r'^signatories/$', groups.views.view_signatories, name='signatories', ),
     22    url(r'^account_lookup/$', groups.views.account_lookup, name='account-lookup', ),
    2223)
    2324
  • asadb/groups/views.py

    r2919697 raa2aa58  
    766766            context['title'] = "Recent Changes"
    767767        return context
     768
     769
     770class AccountLookupForm(forms.Form):
     771    account_number = forms.IntegerField()
     772    username = forms.CharField(help_text="Athena username of person to check")
     773
     774def account_lookup(request, ):
     775    msg = None
     776    msg_type = ""
     777    account_number = None
     778    username = None
     779    group = None
     780    office_holders = []
     781
     782    initial = {}
     783
     784    if 'search' in request.GET: # If the form has been submitted...
     785        # A form bound to the POST data
     786        form = AccountLookupForm(request.GET)
     787
     788        if form.is_valid(): # All validation rules pass
     789            account_number = form.cleaned_data['account_number']
     790            username = form.cleaned_data['username']
     791            account_q = Q(main_account_id=account_number) | Q(funding_account_id=account_number)
     792            try:
     793                group = groups.models.Group.objects.get(account_q)
     794                office_holders = group.officers(person=username)
     795                office_holders = office_holders.filter(role__publicly_visible=True)
     796            except groups.models.Group.DoesNotExist:
     797                msg = "Group not found"
     798                msg_type = "error"
     799
     800    else:
     801        form = AccountLookupForm()
     802
     803    context = {
     804        'username':     username,
     805        'account_number': account_number,
     806        'group':        group,
     807        'office_holders': office_holders,
     808        'form':         form,
     809        'msg':          msg,
     810        'msg_type':     msg_type,
     811    }
     812    return render_to_response('groups/account_lookup.html', context, context_instance=RequestContext(request), )
Note: See TracChangeset for help on using the changeset viewer.