def identity_by_identifier(identifier): try: return session.query(Identity).filter(Identity.identifier == identifier).first() except Exception, e: logging.exception(e) session.rollback() raise ValueError("Unable to select identity for identifier")
def purchase(id): try: return session.query(Purchase).filter(Purchase.id == id).one() except Exception, e: logging.exception(e) session.rollback() raise ValueError("Unable to select purchase")
def purchase_for_user_app(userid, appid): try: return session.query(Purchase).filter(Purchase.user_id == userid).filter(Purchase.app_id == appid).first() except Exception, e: logging.exception(e) session.rollback() raise ValueError("Unable to select purchases for user")
def application(id): try: return session.query(Application).filter(Application.id == int(id)).one() except Exception, e: logging.exception(e) session.rollback() raise ValueError("Unable to select application")
def applications(): try: return session.query(Application).all() except Exception, e: logging.exception(e) session.rollback() raise ValueError("Unable to select applications")
def createApplication(manifestText, manifestSrc, manifestObj = None): try: if not manifestObj: manifestObj = json.loads(manifestSrc) name = manifestObj['name'] baseURL = manifestObj['base_url'] icon96 = None if 'icons' in manifestObj: if '96' in manifestObj['icons']: icon96 = manifestObj['icons']['96'] else: key = manifestObj['icons'].keys()[0] icon96 = manifestObj['icons'][key] description = manifestObj['description'] a = Application(name, manifestSrc, manifestText, baseURL, datetime.now(), icon96, description) session.add(a) session.commit() return a except sqlalchemy.exc.IntegrityError: session.rollback() raise ValueError("An application is already registered for that launch URL.") except Exception, e: logging.exception(e) session.rollback() raise ValueError("Unable to create application")
def createApplication(manifestText, manifestSrc, manifestObj=None): try: if not manifestObj: manifestObj = json.loads(manifestSrc) name = manifestObj["name"] baseURL = manifestObj["base_url"] icon96 = None if "icons" in manifestObj: if "96" in manifestObj["icons"]: icon96 = manifestObj["icons"]["96"] else: key = manifestObj["icons"].keys()[0] icon96 = manifestObj["icons"][key] description = manifestObj["description"] a = Application(name, manifestSrc, manifestText, baseURL, datetime.now(), icon96, description) session.add(a) session.commit() return a except sqlalchemy.exc.IntegrityError: session.rollback() raise ValueError("An application is already registered for that launch URL.") except Exception, e: logging.exception(e) session.rollback() raise ValueError("Unable to create application")
def user(id): try: return session.query(User).filter(User.id == id).first() except Exception, e: logging.exception(e) session.rollback() raise ValueError("Unable to select user")
def remove_purchase_for_user_app(userid, appid): try: session.query(Purchase).filter(Purchase.user_id == userid).filter(Purchase.app_id == appid).delete() session.commit() except Exception, e: logging.exception(e) session.rollback() raise ValueError("Unable to remove purchase")
def save(obj): try: session.add(obj) session.commit() except Exception, e: logging.exception(e) session.rollback() raise ValueError("Unable to save object")
def categories(parent=None): try: q = session.query(Category) if parent: q = q.filter(Category.parent_id == parent) return q.all() except Exception, e: logging.exception(e) session.rollback() raise ValueError("Unable to select categories")
def createPurchaseForUserApp(uid, appid): try: p = Purchase(uid, appid, datetime.now()) session.add(p) session.commit() return p except Exception, e: logging.exception(e) session.rollback() raise ValueError("Unable to create purchase")
def createCategory(name, parent=None): try: if parent and (len(parent) == 0 or parent == 0): parent = None c = Category(name, parent=parent) session.add(c) session.commit() return c except Exception, e: session.rollback() raise ValueError("Error while creating category: %s" % e)
def addIdentity(uid, identifier, displayName, email): try: id = Identity(uid, identifier, displayName, email, datetime.now()) session.add(id) session.commit() return id except sqlalchemy.exc.IntegrityError, e: logging.exception(e) session.rollback() raise ValueError("Unable to create identity")
def createUser(): try: u = User() session.add(u) session.commit() return u except sqlalchemy.exc.IntegrityError, e: logging.exception(e) session.rollback() raise ValueError("Unable to create user")
def bing_user(): try: # 判断是否登陆,登陆了session中包含ADMIN_EMAIL键 if config.ADMIN_UUID in session: admin_email = session.get(config.ADMIN_UUID) admin_user = db_session.query(Admin).filter( Admin.admin_email == admin_email).first() # 如果从数据库中查询到了user用户(以防存在假的cookie, 概率几乎没有) if admin_user: g.admin_user = admin_user except Exception as err: db_session.rollback()
def delete_user(id): try: user = session.query(Employee).get(id) user2 = session.query(Skills).filter_by(emp_id=id).first() #if user user2 !=None: session.delete(user) session.delete(user2) session.commit() final = {"firstname": user.firstname, "lastname": user.lastname} return final except Exception as e: return e session.rollback()
def createUser(): try: u = User() session.add(u) session.commit() return u except sqlalchemy.exc.IntegrityError, e: logging.exception(e) session.rollback() raise ValueError("Unable to create user") except Exception, e: logging.exception(e) session.rollback() raise ValueError("Unable to create application") def user(id): try: return session.query(User).filter(User.id == id).first() except Exception, e: logging.exception(e) session.rollback() raise ValueError("Unable to select user") def addIdentity(uid, identifier, displayName, email): try: id = Identity(uid, identifier, displayName, email, datetime.now())
def createUser(): try: u = User() session.add(u) session.commit() return u except sqlalchemy.exc.IntegrityError, e: logging.exception(e) session.rollback() raise ValueError("Unable to create user") except Exception, e: logging.exception(e) session.rollback() raise ValueError("Unable to create application") def user(id): try: return session.query(User).filter(User.id == id).first() except Exception, e: logging.exception(e) session.rollback() raise ValueError("Unable to select user") def addIdentity(uid, identifier, displayName, email): try: id = Identity(uid, identifier, displayName, email, datetime.now()) session.add(id)