Changeset d66942f for asadb


Ignore:
Timestamp:
Dec 3, 2013, 12:21:44 AM (13 years ago)
Author:
Alex Dehnert <adehnert@…>
Branches:
master, stable, stage
Children:
ed7ddec
Parents:
88a856b
git-author:
Alex Dehnert <adehnert@…> (12/02/13 23:56:40)
git-committer:
Alex Dehnert <adehnert@…> (12/03/13 00:21:44)
Message:

People lookup: make the UI more reasonable

Location:
asadb
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • asadb/forms/models.py

    r88a856b rd66942f  
    243243            'affiliate': other,
    244244        }
    245         descriptions = {
    246             'undergrads': 'Undergraduate students',
    247             'grads': 'Graduate students',
    248             'staff': 'MIT Staff (including faculty)',
    249             'secret': 'People with directory information suppressed. These people have Athena accounts, but they could have any MIT affiliation, including just being a student group member.',
    250             'affiliate': 'This includes some alumni, group members with Athena accounts sponsored through SAO, and many others.',
    251         }
    252245        for result in results:
    253246            username = result[1]['uid'][0]
     
    257250                year = result[1].get('mitDirStudentYear', [None])[0]
    258251                if year == 'G':
    259                     grads.append(username)
     252                    grads.append((username, None))
    260253                elif year.isdigit():
    261254                    undergrads.append((username, year))
     
    263256                    other.append((username, year))
    264257            else:
    265                 info[affiliation].append(username)
    266         info['unknown'] = left
    267         descriptions['unknown'] = "While this looks like an Athena account, we couldn't find it. This could be a deactivated account, or it might never have existed."
    268         return descriptions, info
     258                info[affiliation].append((username, None, ))
     259        info['unknown'] = [(u, None) for u in left]
     260        return info
    269261
    270262    def classify_people(self, people):
    271263        mit_usernames = set()
    272         alum_addresses = set()
    273         other_mit_addresses = set()
    274         nonmit_addresses = set()
     264        alum_addresses = []
     265        other_mit_addresses = []
     266        nonmit_addresses = []
    275267
    276268        for name in people:
     
    279271                mit_usernames.add(local)
    280272            elif domain.lower() == 'alum.mit.edu':
    281                 alum_addresses.add(name)
     273                alum_addresses.append((name, None))
    282274            elif domain.endswith('.mit.edu'):
    283                 other_mit_addresses.add(name)
     275                other_mit_addresses.append((name, None))
    284276            else:
    285                 nonmit_addresses.add(name)
    286 
    287         descriptions, results = self.ldap_classify(mit_usernames)
    288         descriptions['alum'] = "Alumni Association addresses"
    289         descriptions['other-mit'] = ".mit.edu addresses that aren't @mit.edu or @alum.mit.edu."
    290         descriptions['non-mit'] = "Non-MIT addresses, including outside addresses of MIT students."
     277                nonmit_addresses.append((name, None))
     278
     279        results = self.ldap_classify(mit_usernames)
    291280        results['alum'] = alum_addresses
    292281        results['other-mit'] = other_mit_addresses
    293282        results['non-mit'] = nonmit_addresses
    294 
    295         sorted_results = {}
    296         for k, v in results.items():
    297             sorted_results[k] = {
    298                 'description': descriptions[k],
    299                 'people': sorted(v),
    300             }
    301         return sorted_results
     283        return results
    302284
    303285    def update_classified_people(self):
    304         people = [p.strip() for p in self.people.split('\n')]
    305         print people
     286        people = [p for p in [p.strip() for p in self.people.split('\n')] if p]
    306287        self._classified_people = self.classify_people(people)
    307288        self.classified_people_json = json.dumps(self._classified_people)
     
    314295        return self._classified_people
    315296
     297    def classifications_with_descriptions(self):
     298        descriptions = {
     299            'undergrads':   'Undergraduate students (class year in parentheses)',
     300            'grads':        'Graduate students',
     301            'alum':         "Alumni Association addresses",
     302            'staff':        'MIT Staff (including faculty)',
     303            'affiliate':    'This includes some alumni, group members with Athena accounts sponsored through SAO, and many others.',
     304            'secret':       'People with directory information suppressed. These people have Athena accounts, but they could have any MIT affiliation, including just being a student group member.',
     305            'unknown':      "While this looks like an Athena account, we couldn't find it. This could be a deactivated account, or it might never have existed.",
     306            'other-mit':    ".mit.edu addresses that aren't @mit.edu or @alum.mit.edu.",
     307            'non-mit':      "Non-MIT addresses, including outside addresses of MIT students.",
     308        }
     309
     310        names = (
     311            ('undergrads', 'Undergrads', ),
     312            ('grads', 'Grad students', ),
     313            ('alum', 'Alumni', ),
     314            ('staff', 'Staff', ),
     315            ('affiliate', 'Affiliates', ),
     316            ('secret', 'Secret', ),
     317            ('unknown', 'Unknown', ),
     318            ('other-mit', 'Other MIT addresses', ),
     319            ('non-mit', 'Non-MIT addresses', ),
     320        )
     321
     322        classifications = self.classified_people
     323        sorted_results = []
     324        for k, label in names:
     325            sorted_results.append({
     326                'label': label,
     327                'description': descriptions[k],
     328                'people': sorted(classifications[k]),
     329            })
     330        return sorted_results
     331
    316332
    317333##########
  • asadb/forms/views.py

    r88a856b rd66942f  
    572572                lookup.requestor = request.user
    573573                lookup.referer = request.META['HTTP_REFERER']
    574                 results = lookup.update_classified_people()
     574                lookup.update_classified_people()
     575                results = lookup.classifications_with_descriptions()
    575576                lookup.save()
    576577        else:
     
    580581        if request.user.has_perm('forms.view_peoplestatusupdate'):
    581582            lookup = get_object_or_404(forms.models.PeopleStatusLookup, pk=int(pk))
    582             results = lookup.classified_people
     583            results = lookup.classifications_with_descriptions()
    583584            form = None
    584585        else:
  • asadb/template/membership/people-lookup.html

    r88a856b rd66942f  
    44{% block content %}
    55
    6 <h2>People lookup</h2>
     6<h1>People lookup</h1>
    77
    88{% if form %}
    9 <p>You can specify a list of email addresses and/or MIT usernames below, and we'll try to identify which ones are undergrads, grad students, etc.. This is not definitive (<kbd>joe.mit.student@gmail.com</kbd> will show up as "other", for example, and we can't check the student status of people who chose to suppress MIT directory information), but it may be a good first step in figuring out the breakdown of your membership numbers.</p>
     9<p>You can specify a list of email addresses and/or MIT usernames below, and we'll try to identify which ones are undergrads, grad students, and so forth:</p>
    1010
    1111<form enctype="multipart/form-data" method="post" action="">
     
    2020
    2121{% if results %}
     22<h2>Results</h2>
     23
     24<p>This information is not definitive (<kbd>joe.mit.student@gmail.com</kbd> will show up as "other", for example, and we can't check the student status of people who chose to suppress MIT directory information), but we hope it can be helpful in figuring out the breakdown of your membership numbers.</p>
     25
     26<p><em>If you wish to use this for an ASA form, <strong>you</strong> will need to transfer the numbers yourself &ndash; we do not do that automatically.</em></p>
     27
    2228<table class='pretty-table'>
    2329<tr>
    2430    <th>Type</th>
    25     <th>Description</th>
     31    <th style='width: 20em;'>Description</th>
    2632    <th>Number</th>
    2733    <th>People</th>
    2834</tr>
    29 {% for name,result in results.items %}
     35{% for result in results %}
    3036<tr>
    31     <th>{{name}}</th>
     37    <th>{{result.label}}</th>
    3238    <td>{{result.description}}</td>
    33     <td>{{result.people|length}}</td>
     39    <td style='text-align: right; padding: 0.5em;'>{{result.people|length}}</td>
    3440    <td><ul>
    3541        {% for person in result.people %}
    36         <li>{{person}}</li>
     42        <li>{{person.0}}{% if person.1 %} ({{person.1}}){%endif%}</li>
    3743        {% endfor %}
    3844    </ul></td>
Note: See TracChangeset for help on using the changeset viewer.