def generate_gallery(): try: # user_login = session.query(UserLogins).filter(and_( # UserLogins.login == login, # UserLogins.password == encrypted_password)) \ # .first() products = session.query(Products).filter(and_( Products.default_image_id!=None, Products.gallery_images==None )).all() for p in products: arr = [] arr.append(p.default_image_id) p.gallery_images = arr session.add(p) session.commit() t=p pass e=0 pass except Exception as e: pass
def check_default_address(entity): try: client_id = entity.client_id is_default = entity.is_default id = entity.id client_addresses = session.query(ClientAddresses).filter( ClientAddresses.client_id == client_id).all() if (len(client_addresses) == 1): for client_address in client_addresses: client_address.is_default = True session.add(client_address) session.commit() return if (is_default == False): return for client_address in client_addresses: if (client_address.id == id): client_address.is_default = True else: client_address.is_default = False session.add(client_address) session.commit() pass except Exception as e: pass
def generate_partners(): try: partner_names = [ 'EURASIAN FOODS', 'Келешек - STAR', 'Dala-Kent', 'Южный Престиж', 'Madina', 'ИП "Кофейные напитки"', 'Бөрте Милка', 'Доставка лепешек', 'ИП Хасанова', 'ASDECOR', 'ИП НҰРМҰХАММЕД', 'Южная Корона', 'ИП Париж', 'Красивая Меча', 'ТОО АРСЕНОВ', 'ИП Ерганов' 'PANDORA GROUP', 'ТОО Омар(Yunus, Comili,Elvan,Today)', 'ИП Санжар', 'ИП Шым-Бизнес (Bionix, Voka)', 'VOKA', 'BIONIX', 'Нирвана', 'ИП Ахмедов', 'ТОО "Dena Distribution"', 'ТОО "Hydrolife Bottlers Kazakhstan"', 'Anadolu Marketing', 'ИП Юдаков', 'BASTAU', 'ТОО "РАУАН"', 'ТОО "NIK 1"', 'BRIS -Company', 'ТОО "Чайный центр"', 'Разновидный курт', 'TURKUAZ Group of Companies', 'ТОО "Салем"', 'ТОО "ЖанИС"', 'ТОО "Московские Деликатесы"', 'ИП Хадиметов', 'ТОО "Line Logistic"', 'ТОО "Аврора Брендс"', 'Арахис Ташкентский', 'ИП Леспеков', 'ТОО "АсКом-Азия"', 'ТОО OASIS GROUP', 'ТОО "Гәкку Әулие ата құс"', 'Адам', 'ИП "Дарина"', 'ТОО "Sea Bass" (Русалочка)', 'ИП Болатбек Т', 'ТОО "TASS GROUP"', 'ИП Пак', 'aДәм' ] for name in partner_names: data = {'name': name} partner = PartnersCatalog(data) session.add(partner) session.commit() pass except Exception as e: pass
def get(self): try: action_type = 'GET' parser = reqparse.RequestParser() parser.add_argument('user_id') args = parser.parse_args() if (len(args) == 0): abort(400, message='Arguments not found') user_id = args['user_id'] user_bonuses = session.query(UserBonuses).filter(and_( UserBonuses.user_id == user_id, UserBonuses.state== True)) \ .all() for bonus in user_bonuses: bonus.state = False session.add(bonus) session.commit() response = {'status': 200} return response except Exception as e: if (hasattr(e, 'data')): if (e.data != None and "message" in e.data): abort(400, message=e.data["message"]) abort(400, message="Неопознанная ошибка")
def post(self): try: json_data = request.get_json(force=True) log = Log(message=json_data["message"]) session.add(log) session.commit() return log, 201 except Exception as e: session.rollback() abort(400, message="Error while adding record Log")
def post(self): try: json_data = request.get_json(force=True) entity = MODEL(json_data) session.add(entity) session.commit() return entity, 201 except Exception as e: session.rollback() abort(400, message="Error while adding record " + ENTITY_NAME)
def post(self): try: json_data = request.get_json(force=True) client_type = ClientTypes(name=json_data["name"]) session.add(client_type) session.commit() return client_type, 201 except Exception as e: session.rollback() abort(400, message="Error while adding record Client Type")
def config_import(): with open(config_path, 'r') as f: cc_json = json.load(f) cc = ChimeraConfig() for key, value in cc_json.items(): setattr(cc, key, value) session.query(ChimeraConfig).delete() session.add(cc) session.commit() print('Config imported, restart chimera!')
def post(self): try: json_data = request.get_json(force=True) user_role = UserRoles(json_data['name']) session.add(user_role) session.commit() return user_role, 201 except Exception as e: session.rollback() abort(400, message="Error in adding User Role")
def post(self): try: json_data = request.get_json(force=True) action_log_type = ActionLogTypes(message=json_data["message"]) session.add(action_log_type) session.commit() return action_log_type, 201 except Exception as e: session.rollback() abort(400, message="Error while adding record Action Log Type")
def put(self, id): try: # session.autocommit = False # session.autoflush = False json_data = request.get_json(force=True) entity = session.query(MODEL).filter(MODEL.id == id).first() if not entity: abort(404, message=ENTITY_NAME + " {} doesn't exist".format(id)) product_positions = session.query(ProductsPositions).filter( ProductsPositions.products_positions.any(entity.id)).all() if product_positions is not None: session.bulk_update_mappings(ProductsPositions, [{ 'id': x.id, 'products_positions': list(filter(lambda y: y != entity.id, x.products_positions)) } for x in product_positions]) session.commit() db_transformer.transform_update_params(entity, json_data) session.add(entity) session.commit() # api_url = settings.API_URL # if hasattr(entity, 'default_image_data'): # if (entity.default_image_data != None and entity.default_image_data.file_path != None): # entity.default_image_data.file_path = urllib.parse.urljoin(api_url, # entity.default_image_data.file_path) # if hasattr(entity, 'default_image_data'): # if (entity.default_image_data != None and entity.default_image_data.thumb_file_path != None): # entity.default_image_data.thumb_file_path = urllib.parse.urljoin(api_url, # entity.default_image_data.thumb_file_path) # if hasattr(entity, 'default_image_data'): # if (entity.default_image_data != None and entity.default_image_data.optimized_size_file_path != None): # entity.default_image_data.optimized_size_file_path = urllib.parse.urljoin(api_url, # entity.default_image_data.optimized_size_file_path) entity.images_data = [] if (entity.gallery_images != None and len(entity.gallery_images) > 0): for img_id in entity.gallery_images: image = session.query(Attachments).filter( Attachments.id == img_id).first() if not image: continue entity.images_data.append(image) return entity, 201 except Exception as e: session.rollback() abort(400, message="Error while update " + ENTITY_NAME) finally: pass
def populate_aws(eventSlug, start, end, pageSize): games = [] for i in range(start, end): try: games.extend(get_games(eventSlug, i, pageSize)) except Exception as e: print(e) for game in games: session.add(game) session.commit()
def post(self): try: json_data = request.get_json(force=True) client = Clients(name=json_data["name"], registration_number=json_data["registration_number"], lock_state=json_data["lock_state"], client_type_id=json_data["client_type_id"]) session.add(client) session.commit() return client, 201 except Exception as e: session.rollback() abort(400, message="Error while adding record Client")
def put(self, id): try: json_data = request.get_json(force=True) user_group_setting = session.query(UserGroupSettings).filter( UserGroupSettings.id == id).first() user_group_setting.data = json_data['data'] session.add(user_group_setting) session.commit() return user_group_setting, 201 except Exception as e: session.rollback() abort(400, message="Error while update User Group Settings")
def put(self, id): try: json_data = request.get_json(force=True) client_type = session.query(ClientTypes).filter( ClientTypes.id == id).first() client_type.name = json_data['name'] session.add(client_type) session.commit() return client_type, 201 except Exception as e: session.rollback() abort(400, message="Error while update Client Type")
def put(self, id): try: json_data = request.get_json(force=True) object_view = session.query(ObjectViews).filter( ObjectViews.id == id).first() object_view.data = json_data['data'] session.add(object_view) session.commit() return object_view, 201 except Exception as e: session.rollback() abort(400, message="Error while update Object Views")
def post(self): try: json_data = request.get_json(force=True) setting = Settings(name=json_data["name"], value=json_data["value"]) session.add(setting) session.commit() return setting, 201 except Exception as e: session.rollback() abort(400, message="Error while adding record Settings")
def post(self): try: json_data = request.get_json(force=True) action_log = ActionLog(message=json_data["message"], user_id=json_data["user_id"], action_type_id=json_data["action_type_id"]) session.add(action_log) session.commit() return action_log, 201 except Exception as e: session.rollback() abort(400, message="Error while adding record Action Log")
def post(self): try: json_data = request.get_json(force=True) user_group = UserGroups( user_creator_id=json_data['user_creator_id'], group_name=json_data['group_name']) session.add(user_group) session.commit() return user_group, 201 except Exception as e: session.rollback() abort(400, message="Error while adding record User Group")
def put(self, id): try: json_data = request.get_json(force=True) user_role = session.query(UserRoles).filter( UserRoles.id == id).first() user_role.task = json_data['name'] session.add(user_role) session.commit() return user_role, 201 except Exception as e: session.rollback() abort(400, message="Error while update user role")
def put(self, id): try: json_data = request.get_json(force=True) group_object_right = session.query(GroupObjectRights).filter( GroupObjectRights.id == id).first() group_object_right.data = json_data['data'] session.add(group_object_right) session.commit() return group_object_right, 201 except Exception as e: session.rollback() abort(400, message="Error while update Group Object Rights")
def put(self, id): try: # session.autocommit = False # session.autoflush = False json_data = request.get_json(force=True) entity = session.query(MODEL).filter(MODEL.id == id).first() if not entity: abort(404, message=ENTITY_NAME + " {} doesn't exist".format(id)) # check if this category has another parent_id, so we should delete it from positions if json_data['parent_category_id'] != entity.parent_category_id\ or json_data.get('is_delete', False)\ or json_data.get('is_lock', False): position = session.query(ProductCategoryPositions) \ .filter(ProductCategoryPositions.parent_category_id == entity.parent_category_id).first() if position is not None: position.child_category_positions = [e for e in position.child_category_positions if e != entity.id] session.add(position) session.commit() db_transformer.transform_update_params(entity, json_data) session.add(entity) session.commit() # session.close() # api_url = settings.API_URL # if hasattr(entity, 'default_image_data'): # if (entity.default_image_data != None and entity.default_image_data.file_path != None): # entity.default_image_data.file_path = urllib.parse.urljoin(api_url, # entity.default_image_data.file_path) # if hasattr(entity, 'default_image_data'): # if (entity.default_image_data != None and entity.default_image_data.thumb_file_path != None): # entity.default_image_data.thumb_file_path = urllib.parse.urljoin(api_url, # entity.default_image_data.thumb_file_path) # if hasattr(entity, 'default_image_data'): # if (entity.default_image_data != None and entity.default_image_data.optimized_size_file_path != None): # entity.default_image_data.optimized_size_file_path = urllib.parse.urljoin(api_url, # entity.default_image_data.optimized_size_file_path) # entity.images_data = [] if entity.images is not None and len(entity.images) > 0: for img_id in entity.images: image = session.query(Attachments).filter(Attachments.id == img_id).first() if not image: continue entity.images_data.append(image) return entity, 201 except Exception as e: session.rollback() abort(400, message="Error while update " + ENTITY_NAME) finally: pass
def post(self): try: json_data = request.get_json(force=True) #shared_user_id, object_id shared_group_object = SharedGroupObjects( shared_user_id=json_data["shared_user_id"], object_id=json_data["object_id"]) session.add(shared_group_object) session.commit() return shared_group_object, 201 except Exception as e: session.rollback() abort(400, message="Error while adding record Shared Group Object")
def put(self, id): try: json_data = request.get_json(force=True) shared_group_object = session.query(SharedGroupObjects).filter( SharedGroupObjects.id == id).first() shared_group_object.lock_state = json_data['lock_state'] shared_group_object.group_members = json_data['group_members'] session.add(shared_group_object) session.commit() return shared_group_object, 201 except Exception as e: session.rollback() abort(400, message="Error while update Shared Group Object")
def post(self): try: json_data = request.get_json(force=True) entity = session.query(Messages).filter(Messages.id == json_data['id']).first() if not entity: abort(404, message="Record doesn't exist".format(id)) entity.is_read = True session.add(entity) session.commit() return entity, 201 except Exception as e: session.rollback() abort(400, message="Error while updating record")
def put(self, id): try: json_data = request.get_json(force=True) action_log_type = session.query(ActionLogTypes).filter( ActionLogTypes.id == id).first() action_log_type.message = json_data['message'] action_log_type.code = json_data['code'] session.add(action_log_type) session.commit() return action_log_type, 201 except Exception as e: session.rollback() abort(400, message="Error while update Action Log Type")
def put(self, id): try: json_data = request.get_json(force=True) entity = session.query(MODEL).filter(MODEL.id == id).first() if not entity: abort(404, message=ENTITY_NAME + " {} doesn't exist".format(id)) db_transformer.transform_update_params(entity,json_data) session.add(entity) session.commit() return entity, 201 except Exception as e: session.rollback() abort(400, message="Error while update "+ENTITY_NAME)
def put(self, id): try: json_data = request.get_json(force=True) setting_setting = session.query(Settings).filter( Settings.id == id).first() setting_setting.name = json_data['name'] setting_setting.value = json_data['value'] session.add(setting_setting) session.commit() return setting_setting, 201 except Exception as e: session.rollback() abort(400, message="Error while update Settings")
def post(self): try: json_data = request.get_json(force=True) en_pass = str(base64.b64encode(json_data["password"])) user_login = UserLogins(login=json_data["login"], password=en_pass, user_id=json_data["user_id"]) session.add(user_login) session.commit() return user_login, 201 except Exception as e: session.rollback() abort(400, message="Error while adding record User Login")
def post(self): try: json_data = request.get_json(force=True) password = json_data["password"] encrypted_password = str(base64.b64encode(bytes(password, "utf-8"))) json_data["password"] = encrypted_password entity = MODEL(json_data) session.add(entity) session.commit() return entity, 201 except Exception as e: session.rollback() abort(400, message="Error while adding record " + ENTITY_NAME)