Changeset e5c5180


Ignore:
Timestamp:
Feb 11, 2014, 2:05:46 AM (12 years ago)
Author:
Alex Dehnert <adehnert@…>
Branches:
master, stable, stage
Children:
ff71c3a, 8442dd7
Parents:
4193cf3 (diff), 86986f5 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
git-author:
Alex Dehnert <adehnert@…> (02/11/14 02:05:46)
git-committer:
Alex Dehnert <adehnert@…> (02/11/14 02:05:46)
Message:

Fixes to the people lookup tool

Merge branch 'people-lookup'

  • people-lookup: People lookup: Handle more name formats (ASA-#253) People lookup: specify intended format (ASA-#253) People lookup: handle round numbers (ASA-#253) People lookup: force names to lowercase (ASA-#252)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • asadb/forms/models.py

    r4193cf3 r86986f5  
    33import json
    44import os
     5import re
    56
    67import ldap
     
    213214
    214215class PeopleStatusLookup(models.Model):
    215     people = models.TextField(help_text="Enter some usernames or email addresses to look up here.")
     216    people = models.TextField(help_text="Enter some usernames or email addresses, separated by newlines, to look up here.")
    216217    requestor = models.ForeignKey(User, null=True, blank=True, )
    217218    referer = models.URLField(blank=True)
     
    234235            username_chunks.append(usernames[start:end])
    235236            start = end
    236         username_chunks.append(usernames[end:])
    237         print username_chunks
     237        extra = usernames[end:]
     238        if extra:
     239            username_chunks.append(extra)
    238240
    239241        results = []
     
    244246            results.extend(batch_results)
    245247
    246         left = set(usernames)
     248        left = set([u.lower() for u in usernames])
    247249        undergrads = []
    248250        grads = []
     
    259261        for result in results:
    260262            username = result[1]['uid'][0]
    261             left.remove(username)
     263            left.remove(username.lower())
    262264            affiliation = result[1].get('eduPersonAffiliation', ['secret'])[0]
    263265            if affiliation == 'student':
     
    297299        return results
    298300
     301    def split_people(self):
     302        splitted = re.split(r'[\n,]+', self.people)
     303        people = []
     304        for name in splitted:
     305            name = name.strip()
     306            if len(name) > 2 and (name[0] == '(') and (name[-1] == ')'):
     307                name = name[1:-1]
     308            name = name.replace(' at ', '@')
     309            if name:
     310                people.append(name)
     311        return people
     312
    299313    def update_classified_people(self):
    300         people = [p for p in [p.strip() for p in self.people.split('\n')] if p]
     314        people = self.split_people()
    301315        self._classified_people = self.classify_people(people)
    302316        self.classified_people_json = json.dumps(self._classified_people)
Note: See TracChangeset for help on using the changeset viewer.