def find_unclaimed(cls, email): P = cls DP = data.DataPoint handler = data.get_handler('email', email) profile = Session.query(P).join(DP).filter(P.user==None).filter(DP.key==u'email').filter(DP.value==handler.normalized).first() return profile
def get(real_user, user, profile=None, email=None): if profile: return profile P = profiles.Profile DP = data.DataPoint #fetch all if not profile and not email: return user.profile.fetch_teathers() # for email handler = data.get_handler('email', email) profile = Session.query(P).join(DP).filter(DP.key==u'email').filter(DP.value==handler.normalized).first() return profile
def _to_python(self, value, state): # we don't support multiple values, so we run a quick check here (we got a webapp where this was a problem) if type(value) != type(u""): raise fv.Invalid('You must supply a valid email.', value, state) handler = data.get_handler('email', value) P = profiles.Profile DP = data.DataPoint user = Session.query(users.User).filter(sa.func.lower(users.User.email)==handler.normalized).first() profile = Session.query(P).join(DP).filter(P.user!=None).filter(DP.key==u'email').filter(DP.value==handler.normalized).first() # if this user is the same as the logged in one then don't throw the error - # allows keeping old email address when editing contact info if (user and user != self.user) or (profile and profile.user != self.user): raise fv.Invalid('That user already exists. Please choose another.', value, state) return value
def add_data(self, user, key, value, type=u''): """ Blindly adds data to a profile """ if not user: raise exceptions.AppException('Gimmie a user', field=u'user', code=exceptions.INVALID) #we overwrite any keys that were created by this user. q = Session.query(data.DataPoint).filter(data.DataPoint.profile==self) q = q.filter(data.DataPoint.key==key) q = q.filter(data.DataPoint.owner==user) d = q.first() handler = data.get_handler(key, value) if d: d.value = handler.normalized else: d = data.DataPoint(profile=self, owner=user, key=key, value=handler.normalized, type=type) Session.add(d) return d