def getUsersMapping(): """Returns a dictionary: email -> { fname, lname, photo, affiliation }. - level 1 caching = global variable. - level 2 caching = memcache """ USER_MAPPING_MEMCACHE_KEY = '__USER_MAPPING__' global USER_MAPPING if USER_MAPPING: return USER_MAPPING __user_mapping__ = memcache.get(USER_MAPPING_MEMCACHE_KEY) if __user_mapping__: logging.info('USER_MAPPING already set.') USER_MAPPING = __user_mapping__ return __user_mapping__ logging.info('Building USER_MAPPING.') all_users = UserProfile.query().fetch(limit=500) users_mapping = {} for u in all_users: users_mapping[u.key.id()] = u #{ #'fname': u.fname, 'lname': u.lname, #'photoURL': u.photoUrl, 'affiliation': u.affiliation } memcache.add(USER_MAPPING_MEMCACHE_KEY, users_mapping) USER_MAPPING = users_mapping logging.info(users_mapping) return users_mapping
def get(self): (template_data, template) = get_template('templates/wall_of_shame.html') all_users = [k.id() for k in UserProfile.query().fetch(keys_only=True)] current_week = (datetime.today() - SnippetHandler.SNIPPET_START_DATE).days / 7 snippet_stats = {} for user in all_users: snippet_stats [user] = {} all_snippets = [] RANGE = range(36, current_week) for i in RANGE: all_snippets.extend(UserSnippet.getAllSnippetsByWeek(i)) for snippet in all_snippets: (week, user) = snippet.getWeekAndUser() snippet_stats.setdefault(user, {})[int(week)] = '1' all_users_stats = [ (u, [ snippet_stats[u].setdefault(k, '-1') for k in RANGE ]) for u in all_users ] # We check snippets from last week. snippets_good = [k.key.id() for k in UserSnippet.getAllSnippetsByWeek(current_week-1)] template_data['snippets_good'] = sorted(snippets_good) template_data['snippets_bad'] = sorted(list(set(all_users) - set(snippets_good))) template_data['all_users_stats'] = all_users_stats self.response.out.write(template.render(template_data))
def deleteAllDomainUsers(dryRun=True): if dryRun: retunr from model import UserProfile all_users_keys = UserProfile.query().fetch(keys_only=True) for key in all_users_keys: key.delete()
def get(self): (template_data, template) = get_template('templates/wall_of_shame.html') all_users = [k.id() for k in UserProfile.query().fetch(keys_only=True)] current_week = (datetime.today() - SnippetHandler.SNIPPET_START_DATE).days / 7 snippet_stats = {} for user in all_users: snippet_stats[user] = {} all_snippets = [] RANGE = range(36, current_week) for i in RANGE: all_snippets.extend(UserSnippet.getAllSnippetsByWeek(i)) for snippet in all_snippets: (week, user) = snippet.getWeekAndUser() snippet_stats.setdefault(user, {})[int(week)] = '1' all_users_stats = [ (u, [snippet_stats[u].setdefault(k, '-1') for k in RANGE]) for u in all_users ] # We check snippets from last week. snippets_good = [ k.key.id() for k in UserSnippet.getAllSnippetsByWeek(current_week - 1) ] template_data['snippets_good'] = sorted(snippets_good) template_data['snippets_bad'] = sorted( list(set(all_users) - set(snippets_good))) template_data['all_users_stats'] = all_users_stats self.response.out.write(template.render(template_data))
def get(self): (template_data, template) = get_template('templates/update_users.html') from domain_services import getDomainUsers currentUsers = [ k.id() for k in UserProfile.query().fetch(keys_only=True)] domainUsers = [ k for k in getDomainUsers() if k['orgUnitPath'] == '/'] missingUsers = [k for k in domainUsers if k['primaryEmail'] not in currentUsers] template_data['new_users'] = [k['primaryEmail'] for k in missingUsers] self.response.out.write(template.render(template_data))
def post(self): from domain_services import getDomainUsers, createNewUser currentUsers = [ k.id() for k in UserProfile.query().fetch(keys_only=True)] domainUsers = [ k for k in getDomainUsers() if k['orgUnitPath'] == '/'] missingUsers = [k for k in domainUsers if k['primaryEmail'] not in currentUsers] for user in missingUsers: createNewUser(user['name']['givenName'], user['name']['familyName'], user['primaryEmail']) logging.info("Creating user %s:" % user['primaryEmail']) self.redirect('/update-users')
def removeUser(email): p = UserProject.query(UserProject.members == email).get() p.members.remove('*****@*****.**') p.put() if p.members == []: # If only member, then we remove the project. p.key.delete() u = UserProfile.query(UserProfile.email == email).get() u.key.delete()
def get(self): (template_data, template) = get_template('templates/update_users.html') from domain_services import getDomainUsers currentUsers = [ k.id() for k in UserProfile.query().fetch(keys_only=True) ] domainUsers = [k for k in getDomainUsers() if k['orgUnitPath'] == '/'] missingUsers = [ k for k in domainUsers if k['primaryEmail'] not in currentUsers ] template_data['new_users'] = [k['primaryEmail'] for k in missingUsers] self.response.out.write(template.render(template_data))
def post(self): from domain_services import getDomainUsers, createNewUser currentUsers = [ k.id() for k in UserProfile.query().fetch(keys_only=True) ] domainUsers = [k for k in getDomainUsers() if k['orgUnitPath'] == '/'] missingUsers = [ k for k in domainUsers if k['primaryEmail'] not in currentUsers ] for user in missingUsers: createNewUser(user['name']['givenName'], user['name']['familyName'], user['primaryEmail']) logging.info("Creating user %s:" % user['primaryEmail']) self.redirect('/update-users')
def get(self): user = users.get_current_user() me = getUserProfile(user.email()) all_profiles = memcache.get('__UserProfile_ALL__') if all_profiles is None: logging.info("memcache MISS.") all_profiles = UserProfile.query(UserProfile.isDormant == False).order(UserProfile.lname, UserProfile.fname).fetch(limit=500) memcache.add('__UserProfile_ALL__', all_profiles, time=60 * 5) else: logging.info("memcache HIT.") all_users = {} for user in all_profiles: all_users.setdefault(user.affiliation, []).append(user) template_values = { 'me': me, 'admin': users.is_current_user_admin(), #TODO (arnaud): sort 'faculty': all_users.setdefault('GovLab', []), 'mit_students': all_users.setdefault('MIT', []), 'nyu_students': all_users.setdefault('NYU', []), 'online_students': all_users.setdefault('online', []) } template = get_template('templates/class_roster.html') self.response.out.write(template.render(template_values))
def get(self): govlabUsers = UserProfile.query().order(UserProfile.lname, UserProfile.fname).fetch(limit=50) (template_data, template) = get_template('templates/team.html') template_data['team'] = govlabUsers self.response.out.write(template.render(template_data))
def getUserLinkedinData(): profiles = [] for profile in UserProfile.query().fetch(): if profile.linkedin: profiles.append(profile.linkedin['profile']) print json.dumps(profiles)
def get(self): govlabUsers = UserProfile.query().order( UserProfile.lname, UserProfile.fname).fetch(limit=50) (template_data, template) = get_template('templates/team.html') template_data['team'] = govlabUsers self.response.out.write(template.render(template_data))