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 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
Beispiel #3
0
    def post(self):
        try:
            json_data = request.get_json(force=True)
            login = json_data["login"]
            password = json_data["password"]
            o_password = copy.copy(password)
            t = bytes(password, 'utf-8')
            password = str(base64.b64encode(t))
            user_login = session.query(UserLogins).filter(and_(
                UserLogins.login == login,
                UserLogins.password == password))\
                .first()
            if user_login is None:
                message = "Попытка авторизации с IP адреса " + request.remote_addr + ". Данными Login="******" Password="******"User doesn't exist")
            user_login.last_login_date = datetime.datetime.now()
            session.add(user_login)
            message = "Пользователь " + user_login.user_data.first_name + " " + user_login.user_data.last_name + " зашел в кабинет (компания " + user_login.user_data.client.name + ")"
            log = Log(message)
            session.add(log)
            session.commit()
            return user_login
        except Exception as e:
            session.rollback()

            abort(400, message="Error Auth")
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 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="Неопознанная ошибка")
Beispiel #6
0
    def fan_out(self, period=30):
        LOGGER.debug('Fanning out rows...')

        stations = session.query(WeatherStation).filter_by(is_sent=0).all()
        for station in stations:
            session.begin()
            try:
                LOGGER.debug('Fanning out station %s' % str(station))
                self.publish_station(station)
                station.is_sent = 1
                session.commit()
            except Exception as e:
                LOGGER.error('Error %s when processing station.', str(e))
                session.rollback()
                raise

        metrics = session.query(Metric).filter_by(is_sent=0).all()
        for metric in metrics:
            session.begin()
            try:
                LOGGER.debug('Fanning out metric %s' % str(metric))
                self.publish_metric(metric)
                metric.is_sent = 1
                session.commit()
            except Exception as e:
                LOGGER.error('Error %s when processing metric.', str(e))
                session.rollback()
                raise

        threading.Timer(period, self.fan_out, [period]).start()  # Periodic loop.
Beispiel #7
0
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)
         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 clean_log_by_condition():
    try:
        logs = session.query(Log).all()

        if (len(logs) > 2000):
            session.query(Log).delete()
            session.commit()
        pass
    except Exception as e:
        session.rollback()
 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")
Beispiel #11
0
 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")
Beispiel #12
0
 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")
Beispiel #13
0
 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)
Beispiel #14
0
    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
Beispiel #15
0
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()
Beispiel #16
0
 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")
Beispiel #17
0
 def delete(self, id):
     try:
         setting = session.query(Settings).filter(Settings.id == id).first()
         if not setting:
             abort(404, message=" Settings {} doesn't exist".format(id))
         session.delete(setting)
         session.commit()
         return {}, 204
     except Exception as e:
         session.rollback()
         abort(400, message="Error while remove  Settings")
Beispiel #18
0
 def delete(self, id):
     try:
         object = session.query(Objects).filter(Objects.id == id).first()
         if not object:
             abort(404, message="Object {} doesn't exist".format(id))
         session.delete(object)
         session.commit()
         return {}, 204
     except Exception as e:
         session.rollback()
         abort(400, message="Error while remove Entity")
Beispiel #19
0
 def delete(self, id):
     try:
         client = session.query(Clients).filter(Clients.id == id).first()
         if not client:
             abort(404, message="Client type {} doesn't exist".format(id))
         session.delete(client)
         session.commit()
         return {}, 204
     except Exception as e:
         session.rollback()
         abort(400, message="Error while remove Client")
Beispiel #20
0
 def delete(self, id):
     try:
         entity = session.query(MODEL).filter(MODEL.id == id).first()
         if not entity:
             abort(404, message=ENTITY_NAME+" {} doesn't exist".format(id))
         session.delete(entity)
         session.commit()
         return {}, 204
     except Exception as e:
         session.rollback()
         abort(400, message="Error while remove "+ENTITY_NAME)
Beispiel #21
0
 def delete(self, id):
     try:
         schema = session.query(Schemas).filter(Schemas.id == id).first()
         if not schema:
             abort(404, message="Client type {} doesn't exist".format(id))
         session.delete(schema)
         session.commit()
         return {}, 204
     except Exception as e:
         # db.db.init_session()
         session.rollback()
         abort(400, message="Error in remove schema".format(id))
Beispiel #22
0
 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")
Beispiel #23
0
 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 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 delete(self, id):
     try:
         user_role = session.query(UserRoles).filter(
             UserRoles.id == id).first()
         if not user_role:
             abort(404, message="User role {} doesn't exist".format(id))
         session.delete(user_role)
         session.commit()
         return {}, 204
     except Exception as e:
         session.rollback()
         abort(400, message="Error while remove 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")
Beispiel #27
0
 def delete(self, id):
     try:
         action_log = session.query(ActionLog).filter(
             ActionLog.id == id).first()
         if not action_log:
             abort(404, message="Action log {} doesn't exist".format(id))
         session.delete(action_log)
         session.commit()
         return {}, 204
     except Exception as e:
         session.rollback()
         abort(400, message="Error while remove Action 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")
Beispiel #29
0
 def delete(self, id):
     try:
         user_login = session.query(UserLogins).filter(
             UserLogins.id == id).first()
         if not user_login:
             abort(404, message="User Login {} doesn't exist".format(id))
         session.delete(user_login)
         session.commit()
         return {}, 204
     except Exception as e:
         session.rollback()
         abort(400, message="Error remove user login")
Beispiel #30
0
 def delete(self, id):
     try:
         client_info = session.query(ClientInfo).filter(
             ClientInfo.id == id).first()
         if not client_info:
             abort(404, message="Attachment  {} doesn't exist".format(id))
         session.delete(client_info)
         session.commit()
         return {}, 204
     except Exception as e:
         session.rollback()
         abort(400, message="Error while remove Attachment ")
Beispiel #31
0
    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")
Beispiel #32
0
    def on_message(self, unused_channel, basic_deliver, properties, body):
        LOGGER.info('Received message # %s from %s: %s',
                    basic_deliver.delivery_tag, properties.app_id, body)

        try:
            msg_dict = json.loads(body)
            action = msg_dict['action']
            data = msg_dict['data']

            if action == 'add_metric':
                metric_type = session.query(MetricType).filter_by(
                    id=data['metric_type_id']).first()

                station = session.query(WeatherStation).filter_by(
                    id=data['weather_station_id']).first()

                metric = Metric(id=data['id'], value=data['value'],
                                metric_type=metric_type,
                                weather_station=station, is_sent=1,
                                timestamp=datetime.datetime.fromtimestamp(
                                    data['timestamp']))

                session.begin()
                session.merge(metric)
                session.commit()
            elif action == 'add_station':
                types = session.query(MetricType).filter(
                    MetricType.id.in_(data['metric_types'])).all()

                station = WeatherStation(id=data['id'], name=data['name'],
                                         latitude=data['latitude'],
                                         longitude=data['longitude'],
                                         metric_types=types, is_sent=1)

                session.begin()
                session.merge(station)
                session.commit()
        except Exception as e:
            LOGGER.error('Error %s when processing message.', str(e))

        self.acknowledge_message(basic_deliver.delivery_tag)