def get(self, **kwargs): try: id = kwargs.pop("requisition.id") transaction.manager: return DBSession.query(Requisition).get(id).first() except KeyError as err: return DBSession.query(Requisition).filter(voided = False)
def get(self, **kwargs): """ Retrieve a user or list of users depending on the arguments passed to the function """ #Determine if user is searching by id or username user_id = kwargs.pop("user_id", None) username = kwargs.pop("username", None) try: print user_id user_id = int(user_id) except TypeError or ValueError: user_id = 0 if username is None and user_id == 0: print "USERNAME IS NONW AND USERID = 0" return self._all() elif user_id > 0 and username is None: print "USERNAME IS NONW AND USERID = 0" return DBSession.query(User).get(user_id) elif user_id == 0 and username is not None: print "USERNAME IS NOT NONE AND USERID = 0" if len(username) == 0: raise ValueError("Illegal username entered") users = DBSession.query(User). \ filter(or_(User.username.like('%' + username + '%'),\ User.fullname.like('%' + username + '%'))).all() return users elif user_id > 0 and username is not None: print "BOTH ARE FILLED INUSERNAME IS NOT NONE AND USERID = 0" users = DBSession.query(User).filter( \ or_(User.id == user_id,\ User.username.like('%' + username + '%'))).all() return
def get(self, **kwargs): try: department_id = kwargs.pop("department.id") return DBSession.query(Department).get(int(department_id)).first() except KeyError as err: print err return DBSession.query(Department).all() return None
def get(self, *args, **kwargs): department_id = 0 if len(args): department_id = args[0] return DBSession.query(Department).get(int(department_id)) elif not len(args) and not len(kwargs): return DBSession.query(Department).\ filter(Department.voided == False).all() return False
def index(self, class_name): if isinstance(class_name, User): with transaction.manager: users = [user.id for user in DBSession.query(User).all()] #rint [("User: %s class: %s") % (user.serialize, class_name.serialize) for user in users if user == class_name] return users.index(class_name.id) elif isinstance(class_name, Permission): with transaction.manager: permissions = DBSession.query(Permission).all() return permissions.index(class_name) return -1
def delete_branch(self, j_branch): branch_id = j_branch.pop("suppliers_branch_id", None) if not branch_id: raise KeyError("Invalid Branch") branch = DBSession.query(SupplierBranch).get(branch_id) with transaction.manager: DBSession.delete(branch)
def _create(): supplier = DBSession.query(Supplier).get(supplier_id) print supplier.to_dict if supplier is None: raise TypeError("Could not find supplier with id: %s" % supplier_id) branch = SupplierBranch(supplier_id) branch = _setattr(branch) del branch.id with transaction.manager: DBSession.add(branch)
def delete(self, supplier): """ Mark a Supplier as deleted. The database delete operation occurs upon flush(). """ supplier = DBSession.query(Supplier).get(supplier.id) if not supplier: raise ValueError("Did not find Supplier") if _validate(supplier): with transaction.manager: DBSession.delete(supplier) return True
def delete(self, j_group): try: name = j_group.pop("group.name") self.id = j_group.pop("group.id") except KeyError as err: print err raise KeyError() with transaction.manager: group = DBSession.query(Group).get(self.id) #Complete deletion may not be the best option. An alternative - #option is to void the instance #DBSession.delete(group) group.void = True DBSession.merge(group) transaction.commit()
def _update(): """ Update an existing Group """ try: self.id = j_group.pop("group.id") self.name = j_group.pop("group.name") except KeyError as err: print err raise KeyError with transaction.manager: group = DBSession.query(Group).get(self.id) if group is None: raise ValueError("Group not found") group.name = self.name group.modified_by = self.modified_by group.modified_date = self.now DBSession.merge(group) transaction.commit()
def get(self, **kwargs): """ Copy the state an instance onto the persistent instance with the same identifier. If there is no persistent instance currently associated with the session, it will be loaded. Return the persistent instance. If the given instance is unsaved, save a copy of and return it as a newly persistent instance. The given instance does not become associated with the session. """ supplier_id = kwargs.pop(self.supplier_id_key, None) supplier_name = kwargs.pop(self.supplier_name_key, None) suppliers = None if supplier_id and not supplier_name: try: supplier_id = int(supplier_id) except TypeError: raise TypeError("Invalid Supplier Id submitted") return self._all() elif supplier_name: return DBSession.query(Supplier).filter(Supplier.name.like("%" + supplier_name + "%")).all() elif not supplier_id and not supplier_name: return self._all() return None
def _all(self): """ Return all suppliers """ users = DBSession.query(Supplier).order_by(Supplier.id).options(joinedload("branches")).all() or None return users
def _update(): item = DBSession.query(Item).get(item_id) _setattr(item) with transaction.manager: DBSession.merge(item) return True
def _all(self): with transaction.manager: return DBSession.query(Permission). \ order_by(Permission.id).all()
def get(self, **kwargs): return DBSession.query(Group).filter(void = False)
def permissions(request): permissions = DBSession.query(Permission).all() for permission in permissions: print ("%s %s %s") % (permission.id, permission.name, permission.description) return permissions
def _update(): branch = DBSession.query(SupplierBranch).get(branch_id) branch = _setattr(branch) with transaction.manager: DBSession.merge(branch)