def __init__(self, boomer_id): try: boomer_id = boomer_id.id except: pass assert type(boomer_id) in [str, unicode], debug_type(boomer_id) self.boomer_id = make_username(boomer_id)
def get_member(member): if not member: return None if isinstance(member, Member): return member assert type(member) in [str, unicode], debug_type(member) member = make_username(member) def get_member_nocache(member_id): try: return Session.query(Member).with_polymorphic('*').get(member_id) except NoResultFound: return None cache = _cache.get('member') cache_func = lambda: get_member_nocache(member) if cache: result = cache.get(key='member:%s' % member, createfunc=cache_func) #try: #Session.add(result) #return result #except InvalidRequestError: return Session.merge(result, load=False) return cache_func()
def get_member_email(member): if not member: return None if isinstance(member, Member): return member assert type(member) in [str, unicode], debug_type(member) try: return Session.query(User).filter_by(email=member).one() except NoResultFound: return None
def action_list_for(self, member, role): assert not member or isinstance(member, Member), debug_type( member ) # just a double check in case any of the codebase pass's a member dict here accidentaly action_list = [] if self.editable_by(member): action_list.append('edit') if self.viewable_by(member): action_list.append('view') if member and self.private == False and self.creator != member: action_list.append('flag') if self.private == False: action_list.append('aggregate') if self.creator == member and has_role_required('editor', role): action_list.append('delete') return action_list
def get_license(code): code = code or u"Unspecified" # get_license(None) should return the default assert type(code) in [str, unicode], debug_type(code) return Session.query(License).get(code)
def get_message(message_id): assert str(message_id).isdigit(), debug_type(message_id) return Session.query(Message).options(joinedload('source')).options(joinedload('target')).get(int(message_id))
def from_string(s): assert type(s) in [str, unicode], debug_type(s) return CreatorFilter(s)
def __init__(self, parent_id): assert type(parent_id) in [int, bool], debug_type(parent_id) self.parent_id = parent_id
def __init__(self, comparitor, date): assert comparitor in ["<", ">", "IS"], debug_type(comparitor) # FIXME: validate date self.comparitor = comparitor self.date = date
def __init__(self, type): assert type in ['article', 'assignment', 'draft'], debug_type(type) self.type = type