def create(petition: PetitionIn, expand: bool = False, token: str = Security(security)): if not allowed_to_control_petition(token): raise HTTPException( status_code=HTTP_401_UNAUTHORIZED, detail="Not authorized to control this petition", ) try: petition_object, ci_uid = _generate_petition_object(petition) except FileNotFoundError: raise HTTPException( status_code=HTTP_404_NOT_FOUND, detail="Credential issuer is not validated, missing info/keys/credentials", ) except ConnectionError: raise HTTPException( status_code=HTTP_424_FAILED_DEPENDENCY, detail="Credential issuer server is not available", ) p = Petition( petition=petition_object, petition_id=petition.petition_id, credential_issuer_uid=ci_uid, credential_issuer_url=petition.credential_issuer_url, ) try: DBSession.add(p) DBSession.commit() except IntegrityError: DBSession.rollback() raise HTTPException( status_code=HTTP_409_CONFLICT, detail="Duplicate Petition Id" ) return p.publish(expand)
def create_user(data): time = datetime.now().strftime('%Y-%m-%d %H:%M:%S') db_session = DBSession() print(data) user = db_session.query(User).filter( User.email == data['email']).first() if user: return {'status': 'error', 'message': 'message'} password = sha512(data['password'].encode('utf-8')).hexdigest() new_user = User( username=data['username'], password=password, email=data['email'], confirmed_at=time, is_active=True, is_admin=data['is_admin']) try: db_session.add(new_user) db_session.commit() result = {'status': 'OK', 'user': data['username']} except: db_session.rollback() result = {'status': 'error'} db_session.close() return result
def sendMessageToUser(cls, message, userId): if str(userId) == "#": user = _InnectusUser _sendMessageViaMail(message, user) else: user = DBSession.query(User).filter(User.user_id == userId).one() #_sendMessageViaMail(message, user) userMessage = cls(user, message) DBSession.add(userMessage)
def setUp(self): ''' Need a row of data in the login audit table ''' super(TestUserAdministration, self).setUp() aud = AuditLogin(dict(REMOTE_ADDR='127.0.0.1'), dict(user_name='chemadmin')) result = AuditLoginResult.get('LOGIN_SUCCESS') aud.login_result = result log.debug(aud in DBSession()) DBSession.add(aud) transaction.commit()
def setup(self): try: new_attrs = {} new_attrs.update(self.attrs) new_attrs.update(self.do_get_dependencies()) setup() self.obj = self.klass(**new_attrs) DBSession.add(self.obj) DBSession.flush() return self.obj except: DBSession.rollback() raise
def sendMessage(title, text, recipients, parentId=None, authorId=None): from tg import request authorId = None if authorId is None: authorId = request.identity['user'].user_id msg = Message(title=title, text=text, author_id=authorId, parent_id=parentId) DBSession.add(msg) DBSession.flush() UserMessage.sendMessageToUsers(msg, recipients)
def setUp(self): super(TestStructureSearch,self).setUp() org=DBSession.query(ReagentVendor).first() for name, smiles in self.smilesToReg.items(): mol = ReagentMol(toMolFromSmiles(smiles)) mol.mol_name = name submitter = User.by_user_name('chemadmin') lot = ReagentLot() lot.lot_submitter_id = submitter.user_id lot.lot_source_org_id = org.vendor_id mol.addLot(lot, 0) DBSession.add(mol) DBSession.flush()
def create_author(data): db_session = DBSession() new_author = Authors(**data) try: db_session.add(new_author) db_session.commit() result = {'status': 'OK', 'author': data['fullname']} except: db_session.rollback() result = {'status': 'error'} db_session.close() return result
def loadFeedDict(cls, feeds): for feed in feeds: guid = feed["id"] try: message = DBSession.query(Message).filter(Message.guid == guid).one() if _compareTime(message.updated.timetuple(),feed["updated_parsed"]) < 0: message.update(title=feed["title"], link=feed["link"], updated=feed["updated"], text=feed["summary"]) userMessages = DBSession.query(UserMessage).filter(UserMessage.message == message.message_id).all() for userMessage in userMessages: userMessage.new = True except NoResultFound: message = Message(text=feed["summary"], guid=feed["id"], **feed) DBSession.add(message) DBSession.flush() cls.sendMessageToAllUsers(message)
def create_book(data): db_session = DBSession() new_book = Books(name=data['name'], type_id=data['type_id'], author_id=data['author_id'], book_translator=data['book_translator']) try: db_session.add(new_book) db_session.commit() result = {'status': 'OK', 'book': data['name']} except: db_session.rollback() result = {'status': 'error'} db_session.close() return result
def create_type(data): db_session = DBSession() book_type = db_session.query(Types).filter( Types.name == data['name']).first() if book_type: return {'status': 'error', 'message': 'message'} new_type = Types(name=data['name']) try: db_session.add(new_type) db_session.commit() result = {'status': 'OK', 'type': data['name']} except: db_session.rollback() result = {'status': 'error'} db_session.close() return result
def gridInsert(self, modelObjects,row): mol=modelObjects[self._molClass] DBSession.add(mol) DBSession.flush() return mol,
def sendMessageToAllUsers(cls, message): users = DBSession.query(User).all() for user in users: userMessage = cls(user, message) DBSession.add(userMessage)