def edit_role2(post, permissions): #Обновлеяем запись obj = get_role2(post['id']) if not obj: return False obj.name = post['rolename'] obj.rolesgroup = post['rolegroup'] obj.description = post['description'] obj.ordering = post['order'] #Удаляем роли DBSession.query(PermissionsRoles).filter(PermissionsRoles.role_id == post['id']).delete() #Добавляем роли for e in permissions: pr = PermissionsRoles(post['id'], e) DBSession.add(pr) try: transaction.commit() except: transaction.rollback() return False else: return True
def activity_user(itemid): user = get_user(itemid) user.activity = time.time() try: transaction.commit() except: transaction.rollback()
def front_page_view(request): session = request.session if not ("ss" in session): if "op_type" in request.POST and request.POST["op_type"] == "sign_in": if ("login" in request.POST and "hesh" in request.POST): try: user = DBSession.query(ModelUsers).filter(ModelUsers.login == request.POST["login"], \ ModelUsers.password == request.POST["hesh"]).first() except DBAPIError: return Response(conn_err_msg, content_type='text/plain', status_int=500) else: msg = "login and/or password not send" return Response(msg, content_type='text/plain') if user == None: msg = "no such user in database" return Response(msg, content_type='text/plain') else: session["ss"] = "insession" print request.POST["login"], request.POST["hesh"] return {"plates": plates} elif "op_type" in request.POST and request.POST["op_type"] == "sign_up": post = request.POST user = ModelUsers(3, post["f_name"], post["l_name"], post["login"], post["hesh"], post["email"], 1) try: DBSession.add(user) transaction.commit() except DBAPIError: transaction.rollback() return Response("adding user error %s" % DBAPIError, content_type='text/plain', status_int=500) return {"plates": plates} else: return Response("wrong parameters %s" % request.POST, content_type='text/plain') return{"plates": plates}
def delete_permissions(delitems): try: for e in delitems: DBSession.query(Permissions).filter(Permissions.id == e).delete() transaction.commit() result = 1 except: transaction.rollback() result = 0 return result
def delete_posts(delitems, thread='blog'): try: for e in delitems: DBSession.query(Blogs).filter(Blogs.id == e).delete() DBSession.query(Comments).filter(Comments.thread == thread).filter(Comments.threadid == e).delete() transaction.commit() result = 1 except: transaction.rollback() result = 0 return result
def edit_permission2(post): #Обновлеяем запись obj = get_permission2(post['id']) if not obj: return False obj.permname = post['permname'] obj.description = post['description'] obj.ordering = post['order'] try: transaction.commit() except: transaction.rollback() return False else: return True
def doerr(self, id, dorb=0): """Test controller that raises an error. This controller will raise an exception after trying to create a new User. This new user should not be in the database at the end because the rollback should make it disapear. dorb is a flag to check that if a rollback occurs inside the controller code, the exception does not cause problems. """ u = User() u.user_id = int(id) session.save(u) session.flush() if int(dorb) == 1: transaction.rollback() raise Exception('test')
def front_page_view(request): session = request.session if not ("ss" in session): if "op_type" in request.POST and request.POST["op_type"] == "sign_in": if ("login" in request.POST and "hesh" in request.POST): print "hesh = %s" % (request.POST["hesh"]) print "password = %s" % (request.POST["password"]) try: user = DBSession.query(ModelUsers).filter(ModelUsers.login == request.POST["login"], \ ModelUsers.password == request.POST["hesh"]).first() except DBAPIError: return Response(conn_err_msg, content_type='text/plain', status_int=500) else: msg = "login and/or password not send" return Response(msg, content_type='text/plain') if user == None: msg = "no such user in database" return Response(msg, content_type='text/plain') else: session["ss"] = "insession" print request.POST["login"], request.POST["hesh"] return {"plates": plates} elif "op_type" in request.POST and request.POST["op_type"] == "sign_up": post = request.POST user = ModelUsers(3, post["f_name"], post["l_name"], post["login"], post["hesh"], post["email"], 1) try: DBSession.add(user) transaction.commit() except DBAPIError: transaction.rollback() return Response("adding user error %s" % DBAPIError, content_type='text/plain', status_int=500) return {"plates": plates} else: return Response("wrong parameters %s" % request.POST, content_type='text/plain') return {"plates": plates}
def __call__(self, environ, start_response): # TODO - G.M - 18-05-2018 - This code should not create trouble # with thread and database, this should be verify. # see https://github.com/tracim/tracim_backend/issues/62 tm = transaction.manager session = get_tm_session(self.session_factory, tm) registry = get_current_registry() registry.ldap_connector = None if AuthType.LDAP in self.app_config.AUTH_TYPES: registry = self.setup_ldap(registry, self.app_config) environ['tracim_registry'] = registry environ['tracim_context'] = WebdavTracimContext(environ, self.app_config, session) try: app = self._application(environ, start_response) except Exception as exc: transaction.rollback() raise exc finally: transaction.commit() session.close() return app
def github_full_scan(settings=None): url_like = 'https://github.com/%/releases/download/%' urls = DBSession.query(URL).filter_by(active=True).filter( URL.url.like(url_like)).all() api_urls = [] if urls: for url in urls: (repouser, reponame) = github_parse_user_repo(url) api_urls.append(github_user_repo_to_api(repouser, reponame)) api_urls = set(api_urls) headers = {} headers[ 'User-Agent'] = 'Mozilla/5.0 (Nintendo 3DS; Mobile; rv:10.0) Gecko/20100101 TitleDB/1.0' for github_api_url in api_urls: userpass = json.load(open("private/github_credentials.json")) req = requests.get(github_api_url, headers=headers, auth=(userpass['username'], userpass['password'])) data = json.loads(req.text) #import pdb; pdb.set_trace() if 'assets' in data: for asset in data['assets']: try: with transaction.manager: with DBSession.begin_nested(): titledb.magic.process_url( asset['browser_download_url'], settings=settings) #transaction.commit() except: transaction.rollback() else: log.info("GitHub API Failure: %s", github_api_url)
def __call__(self, environ, start_response): # TODO - G.M - 18-05-2018 - This code should not create trouble # with thread and database, this should be verify. # see https://github.com/tracim/tracim_backend/issues/62 tm = transaction.manager session = get_tm_session(self.session_factory, tm) registry = get_current_registry() registry.ldap_connector = None if AuthType.LDAP in self.app_config.AUTH_TYPES: registry = self.setup_ldap(registry, self.app_config) environ['tracim_registry'] = registry environ['tracim_context'] = WebdavTracimContext( environ, self.app_config, session) try: app = self._application(environ, start_response) except Exception as exc: transaction.rollback() raise exc finally: transaction.commit() session.close() return app
def main(): print(info) get_user_command = input(">>") while get_user_command.split()[0] != "END": if get_user_command.split()[0] == "BEGIN": while get_user_command.split()[0] != ("COMMIT"): print('TRANSACTION') get_user_command = input(">>") if get_user_command.split()[0] == "SET": try: update_data_base_transaction( get_user_command.split()[1], get_user_command.split()[2], data_base) except IndexError: print(info) elif get_user_command.split()[0] == "GET": try: get_value_transaction(get_user_command.split()[1], data_base) except IndexError: print(info) elif get_user_command.split()[0] == "UNSET": try: delete_key(get_user_command.split()[1]) except IndexError: print(info) elif get_user_command.split()[0] == "COUNTS": try: list_of_set_values = [] count_transaction(get_user_command.split()[1], data_base, list_of_set_values) except IndexError: print(info) elif get_user_command.split()[0] == "ROLLBACK": rollback(data_base) elif get_user_command.split()[0] == "COMMIT": commit(data_base) elif get_user_command.split()[0] == "BEGIN": pass else: print('COMMIT YOUR TRANSACTION') get_user_command = input(">>") else: if get_user_command.split()[0] == "SET": try: update_data_base(get_user_command.split()[1], get_user_command.split()[2]) except IndexError: print(info) elif get_user_command.split()[0] == "GET": try: get_value(get_user_command.split()[1]) except IndexError: print(info) elif get_user_command.split()[0] == "UNSET": try: delete_key(get_user_command.split()[1]) except IndexError: print(info) elif get_user_command.split()[0] == "COUNTS": try: count(get_user_command.split()[1]) except IndexError: print(info) else: print(info) get_user_command = input(">>") print("FINIHING PROGRAMM")
def teardown(): transaction.rollback() connection.close() DBSession.remove()