def get(id, active_only=True): try: if active_only: return Session.query(Post).filter(Post.status == 1).filter(Post.id == id).first() else: return Session.query(Post).get(id) except TypeError: return None
def add_to_post(tag_id,post_id): try: tag_post = Tag_Post(None,post_id,tag_id) Session.add(tag_post) Session.commit() except: # Couldn't add tag to post - already exists! # TODO: This should be logged to avoid future nasty bugs pass
def __call__(self, environ, start_response): """Invoke the Controller""" # WSGIController.__call__ dispatches to the Controller method # the request is routed to. This routing information is # available in environ['pylons.routes_dict'] try: return WSGIController.__call__(self, environ, start_response) finally: Session.remove()
def init_data(): print "Initing box data" query = Session.query(Box) for rec in values: if not query.get(rec[0]): item = Box() item.name = unicode(rec[1]) item.template = unicode(rec[2]) Session.add(item) Session.commit()
def init_data(): print "Initing config data" query = Session.query(Config) for rec in values: if not query.get(unicode(rec[0])): config = Config() config.id = unicode(rec[0]) config.value = unicode(rec[1]) Session.add(config) Session.commit()
def init_data(): print "Initing boxes data" query = Session.query(Boxes) for rec in values: if not query.get(rec[0]): item = Boxes() item.box_id = rec[1] item.status = rec[2] item.order = rec[3] Session.add(item) Session.commit()
def init_data(): print "Initing media data" query = Session.query(Media) for rec in values: if not query.get(rec[0]): media = Media() media.id = rec[0] media.name = unicode(rec[1]) media.url = unicode(rec[2]) Session.add(media) Session.commit()
def init_data(): print "Initing page_type data" query = Session.query(Page_Type) for rec in values: if not query.get(rec[0]): page_type = Page_Type() page_type.id = rec[0] page_type.name = unicode(rec[1]) page_type.controller = unicode(rec[2]) page_type.action = unicode(rec[3]) page_type.param = unicode(rec[4]) Session.add(page_type) Session.commit()
def init_data(): print "Initing page data" query = Session.query(Page) for rec in values: if not query.get(rec[0]): page = Page() page.id = rec[0] page.name = unicode(rec[1]) page.status = rec[2] page.page_order = rec[3] page.url = unicode(rec[4]) page.type = rec[5] Session.add(page) Session.commit()
def init_data(): print "Initing social data" query = Session.query(Social) for rec in values: if not query.get(rec[0]): social = Social() social.id = rec[0] social.name = unicode(rec[1]) social.status = rec[2] social.priority = rec[3] social.url = unicode(rec[4]) social.media_id = rec[5] Session.add(social) Session.commit()
def get_tag_counts(order=False): from argonaut.model.tag import Tag if order: s = select([Tag.name, func.count(Tag_Post.tag_id)], Tag.id == Tag_Post.tag_id).group_by(Tag.name).order_by(func.count(Tag_Post.tag_id).desc()) else: s = select([Tag.name, func.count(Tag_Post.tag_id)], Tag.id == Tag_Post.tag_id).group_by(Tag.name) tags = Session.execute(s) return tags
def get_url(id, url_param): route = Session.query(Page_Type).get(id) if url_param: target = url(controller=route.controller, action=route.action, id=url_param) elif len(route.param) > 0: target = url(controller=route.controller, action=route.action, id=route.param) else: target = url(controller=route.controller, action=route.action) return target
def get_many(amount=10, order='asc', active_only=True, count_only=False, filter=None): try: query = Session.query(Post) if active_only: query = query.filter(Post.status == 1) if filter: query = query.filter(or_(Post.subject.like('%'+filter+'%'),Post.body.like('%'+filter+'%'))) if count_only: return query.limit(amount).count() else: if order == 'desc': return query.order_by(Post.id.desc()).limit(amount) else: return query.order_by(Post.id.asc()).limit(amount) except Exception: return None
def get_tags(id): from argonaut.model.post import Post from argonaut.model.tag import Tag return Session.query(Tag).filter(Post.id==id).filter(Post.id==Tag_Post.post_id).filter(Tag_Post.tag_id==Tag.id).all()
def get_page_id_with_type(type): from argonaut.model.page_type import Page_Type return int(Session.query(Page).join(Page_Type).filter(Page_Type.name==type).order_by(Page.id.desc()).first().id)
def get_id_by_url_param(url_param): return Session.query(Page).filter(Page.url_param == url_param).first().id
def save(post): Session.add(post) Session.commit()
def get_name(id): return str(Session.query(Media).get(id).name)
def get_page_type_id(id): return Session.query(Page).get(id).page_type_id
def init_data(): print "Initing auth data" query = Session.query(User) for rec in user_values: if not query.get(unicode(rec[0])): user = User() user.username = unicode(rec[1]) user.email = unicode(rec[2]) user._set_password(unicode(rec[3])) user.name = unicode(rec[4]) Session.add(user) Session.commit() query = Session.query(Group) for rec in group_values: if not query.get(unicode(rec[0])): group = Group() group.name = unicode(rec[1]) Session.add(group) Session.commit() query = Session.query(Permission) for rec in permission_values: if not query.get(unicode(rec[0])): permission = Permission() permission.name = unicode(rec[1]) Session.add(permission) Session.commit() query = Session.query(User_Group) for rec in user_group_values: if not query.get(unicode(rec[0])): user_group = User_Group() user_group.user_id = unicode(rec[1]) user_group.group_id = unicode(rec[2]) Session.add(user_group) Session.commit() query = Session.query(Group_Permission) for rec in group_permission_values: if not query.get(unicode(rec[0])): group_permission = Group_Permission() group_permission.group_id = unicode(rec[1]) group_permission.permission_id = unicode(rec[2]) Session.add(group_permission) Session.commit()
def get_user_id(username): return Session.query(User).filter(User.username == username).first().id
def get_user_mail(id): try: return Session.query(User).filter(User.id == id).first().email except AttributeError: return None
def get_user_name(username=None, id=None): if username: return Session.query(User).filter(User.username == username).first().name if id: return Session.query(User).filter(User.id == id).first().name
def get_id_by_type_param(param): from argonaut.model.page_type import Page_Type return int(Session.query(Page).join(Page_Type).filter(Page_Type.param==param).order_by(Page.id.desc()).first().id)
def get_first(): return Session.query(Page).order_by(Page.page_order).first()
def get_all(): return Session.query(Media).all()
def get_first(): return Session.query(Media).first()
def get_url(id): return Session.query(Media).get(id).url
def get_by_tag_name(name): from argonaut.model.tag import Tag from argonaut.model.tag_post import Tag_Post return Session.query(Post).join(Tag_Post).join(Tag).filter(Post.status==1).filter(Tag.name==name).order_by(Post.id.desc())
def get_url_param(id): return Session.query(Page).get(id).url_param