def handle_entity(self, entity): q = db.GqlQuery("select * from User where email = :1", entity.email) if q.fetch(1): return None else: views._reindex(entity) print "adding: " + entity.email return entity
def setUp(self): # assert self.client.login(email="*****@*****.**") self.activeUser = User(email='*****@*****.**', first_name='Active', last_name='User', is_active=True, password='******') _reindex(self.activeUser) self.activeUser.save() self.inactiveUser = User(email='*****@*****.**', first_name='Inactive', last_name='User', is_active=False, password='******') _reindex(self.inactiveUser) self.inactiveUser.save()
def sync_user(request): user = request.POST.get('user') if not user: return http.HttpResponseBadRequest() user = json.loads(user) qs = User.all().filter('external_id =', user['member_id']) users = qs.fetch(1) dj_user = None if len(users): dj_user = users[0] else: # No previously sync'd user exists. # Let's check by email to see if an old # user exists with the same email. qs = User.all().filter('email =', user['email']) if qs.count(2) == 2: raise LookupError('More than one user for %s; ' 'aborting sync' % user['email']) users = qs.fetch(1) if len(users): log.info('Linking user %s to ID %s' % (user['email'], user['member_id'])) dj_user = users[0] fields = { 'first_name': user['name_first'], 'last_name': user['name_last'], 'email': user['email'], 'dj_name': user['nick'], 'external_id': user['member_id'], 'is_active': True, } if not dj_user: fields['roles'] = [roles.DJ] dj_user = User(**fields) else: for k, v in fields.items(): setattr(dj_user, k, v) if roles.DJ not in dj_user.roles: dj_user.roles.append(roles.DJ) _reindex(dj_user) dj_user.put() return http.HttpResponse('OK')
def setUp(self): # assert self.client.login(email="*****@*****.**") self.activeUser = User( email='*****@*****.**', first_name='Active', last_name='User', is_active=True, password='******' ) _reindex(self.activeUser) self.activeUser.save() self.inactiveUser = User( email='*****@*****.**', first_name='Inactive', last_name='User', is_active=False, password='******' ) _reindex(self.inactiveUser) self.inactiveUser.save()