def add_relationship(self, other_user, relationship): rel = UserRelationship() rel.user = self rel.target = other_user rel.relationship = relationship try: Session.add(rel) except IntegrityError: pass return
def get_by_text(cls, text, create=False): text = Tag.sanitize(text) if not Tag.cache_by_text.has_key(text): try: tag = Session.query(Tag).filter(Tag.text == text).one() Tag.cache_by_id[tag.id] = tag except InvalidRequestError: if create: # Need to create tag tag = Tag(text=text) Session.add(tag) else: return None Tag.cache_by_text[text] = tag return Tag.cache_by_text[text]
def get_by_text(cls, text, create = False): text = Tag.sanitize(text) if not Tag.cache_by_text.has_key(text): try: tag = Session.query(Tag).filter(Tag.text == text).one() Tag.cache_by_id[tag.id] = tag except InvalidRequestError: if create: # Need to create tag tag = Tag(text=text) Session.add(tag) else: return None Tag.cache_by_text[text] = tag return Tag.cache_by_text[text]