def accept(self): if self.status != STATUS_ACCEPTED and not self.reciprocated_teather_id: new = Teather(owning_profile=self.teathered_profile, teathered_profile=self.owning_profile, status=STATUS_ACCEPTED, reciprocated_teather=None) Session.add(new) self.status = STATUS_ACCEPTED self.reciprocated_teather = new return new return None
def teather(self, other_profile, latitude=None, longitude=None): """ same as following. self.teather(other) means the current profile is following 'other' """ q = Session.query(Teather) q = q.filter(Teather.teathered_profile_id==other_profile.id) existing = q.filter(Teather.owning_profile_id==self.id).first() if existing: return existing q = Session.query(Teather).filter(Teather.owning_profile_id==other_profile.id) recip = q.filter(Teather.teathered_profile_id==self.id).first() if recip: new = recip.accept() else: new = Teather(owning_profile=self, teathered_profile=other_profile, status=STATUS_PENDING, latitude=latitude, longitude=longitude) Session.add(new) return new
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