def get_similar(count=4, _id=None): try: __body = {"image": {"$ne": None}, "_id": {"$ne": _id}} __key = {'name': 1, 'image': 1} __count = MongodbModel(body=__body, collection="services").count() __rand = [] __r = [] while len(__rand) < count: _num = random.randint(0, __count - 1) if _num not in __rand: __rand.append(_num) for i in __rand: __i = MongodbModel(body=__body, key=__key, size=i, collection="services").get_all_key_random() try: __r.append( dict( _id=__i['_id'], name=__i['name'], image=__i['image'], )) except: pass return __r except: return []
def get_one_main_page(__id=None): try: __body = {'_id': __id} __key = {'name': 1, 'image': 1, "special_offer_text": 1} __i = MongodbModel(body=__body, key=__key, collection="services").get_one_key() return dict( _id=__i['_id'], name=__i['name'], special_offer_text=__i['special_offer_text'], image=__i['image'] if "image" in __i.keys() else "", ) except: return False
def get_one_main_page(__id=None): try: __body = {'_id': __id} __key = {'name': 1, 'image': 1, "special_offer_text": 1} __i = MongodbModel(body=__body, key=__key, collection="services").get_one_key() return dict( _id=__i['_id'], name=__i['name'], special_offer_text=__i['special_offer_text'], image=__i['image'] if "image" in __i.keys() else "", ) except: return False
def get_one_main_page(__id=None): try: __body = {'_id': __id} __key = {'name': 1, 'image': 1, 'city': 1, 'industrial_town': 1, 'description': 1} __i = MongodbModel(body=__body, key=__key, collection="companies").get_one_key() return dict( _id=__i['_id'], name=__i['name'], image=__i['image'] if "image" in __i.keys() else "", city=ProvinceCityModel(_id=__i['city']).get_city()['name'], industrial_town=IndustrialTownCompaniesModel(_id=__i['industrial_town']).get_one()['name'], description=__i['description'] ) except: return False
def update_compare(self): try: __body = { "$set": { "name": self.name, "description": self.description, "unit": self.unit, "industrial_town": self.industrial_town, "address": self.address, "phone": self.phone, "phone2": self.phone2, "mobile": self.mobile, "fax": self.fax, "site": self.site, "email": self.email, "province": self.province, "city": self.city, "ceo": self.ceo, "coordinator": self.coordinator, "mobile_coordinator": self.mobile_coordinator, "products_info": self.products_info, "materials_info": self.materials_info, "owner": self.owner, } } __condition = {"_id": self.id} MongodbModel(body=__body, condition=__condition, collection="companies").update() return True except: return False
def get_main_page(): unit_sections = [] try: __body = {"key": "MAIN_PAGE"} __a = MongodbModel(body=__body, collection="setting").get_one() __c = CompaniesModel() try: for i in __a['unit_sections']: a = dict(unit_name=UnitCompaniesModel( _id=i['unit']).get_one()['name'], unit_id=i['unit'], format=i['format'], sort=i['sort'] if 'sort' in i.keys() else "", companies=[]) for j in i['companies']: _com = __c.get_one_main_page(j) if _com is not False: a['companies'].append(_com) if len(a['companies']): unit_sections.append(a) except: pass unit_sections = sorted(unit_sections, key=lambda k: k['sort']) return dict(unit_sections=unit_sections) except: return dict(unit_sections=unit_sections)
def get_all(): try: __body = {} __a = MongodbModel(body=__body, collection="orders").get_all() __r = [] for __i in __a: try: service_name = ServicesModel( _id=__i['service']).get_one()['name'] except: service_name = '-' __r.append( dict( _id=__i['_id'], name=__i['name'], service=__i['service'], service_name=service_name, count=__i['count'], phone=__i['phone'], address=__i['address'], description=__i['description'], )) return __r except: return []
def get_one(self): try: __body = {"_id": self.id} return MongodbModel( body=__body, collection="industrial_town_companies").get_one() except: return False
def get_format_slide_show(): try: __body = {"key": "SLIDE_SHOW"} return MongodbModel(body=__body, collection="setting").get_one()['formats'] except: return []
def delete(self): try: __body = {"_id": self.id} MongodbModel(body=__body, collection="services").delete() return True except: return False
def get_one(self): try: __body = {"_id": self.id} __c = MongodbModel(body=__body, collection="products").get_one() def __get(__n, __d): return __c[__n] if __n in __c.keys() else __d try: type_name = TypeProductsModel(_id=__c['type']).get_one()['name'] except: type_name = '-' try: sub_type_name = TypeProductsModel(_id=__c['sub_type']).get_one()['name'] except: sub_type_name = '-' return dict( _id=__get("_id", None), name=__get("name", ""), image=__get("image", ""), type=__get("type", ""), type_name=type_name, sub_type_name=sub_type_name, sub_type=__get("sub_type", "") ) except: return False
def insert(self): try: __body = {"name": self.name, "parent": self.parent} MongodbModel(body=__body, collection="type_products").insert() return True except: return False
def get_all_like_main_page(_text=""): try: __body = { 'name': { "$regex": _text }, "main_page": True, "special_offer": True } __key = {'name': 1, 'image': 1, 'special_offer_text': 1} __a = MongodbModel(body=__body, key=__key, collection="services", sort="name", ascending=1, size=10).get_all_key_pagination() __r = [] for __i in __a: __r.append( dict( _id=__i['_id'], name=__i['name'], special_offer_text=__i['special_offer_text'], image=__i['image'] if "image" in __i.keys() else "", )) return __r except: return []
def get_one(self): try: __body = {"_id": self.id} return MongodbModel(body=__body, collection="type_products").get_one() except: return False
def get_by_unit(unit=None, size=8): try: __body = {'unit': unit, "active": True} __key = { 'name': 1, 'image': 1, 'city': 1, 'industrial_town': 1, 'description': 1 } __a = MongodbModel(body=__body, key=__key, collection="companies", sort="name", ascending=1, size=size).get_all_key_pagination() __r = [] for __i in __a: __r.append( dict(_id=__i['_id'], name=__i['name'], image=__i['image'] if "image" in __i.keys() else "", city=ProvinceCityModel( _id=__i['city']).get_city()['name'], industrial_town=IndustrialTownCompaniesModel( _id=__i['industrial_town']).get_one()['name'], description=__i['description'])) return __r except: return []
def get_all_active_main_page(_text="", _unit=None): try: __body = {'name': {"$regex": _text}, "active": True} if _unit is not None: __body['unit'] = _unit __key = { 'name': 1, 'image': 1, 'city': 1, 'industrial_town': 1, 'description': 1 } __a = MongodbModel(body=__body, key=__key, collection="companies", sort="name", ascending=1, size=10).get_all_key_pagination() __r = [] for __i in __a: __r.append( dict(_id=__i['_id'], name=__i['name'], image=__i['image'] if "image" in __i.keys() else "", city=ProvinceCityModel( _id=__i['city']).get_city()['name'], industrial_town=IndustrialTownCompaniesModel( _id=__i['industrial_town']).get_one()['name'], description=__i['description'])) return __r except: return []
def get_all_by_like_has_slider(__text=""): try: __body = { 'name': { "$regex": __text }, "slider": True, "active": True } __key = {'name': 1, 'logo': 1, "slider_image": 1} __a = MongodbModel(body=__body, key=__key, collection="companies", sort="name", ascending=1, size=10).get_all_key_pagination() __r = [] for __i in __a: __r.append( dict( _id=__i['_id'], name=__i['name'], logo=__i['logo'], slider_image=__i['slider_image'] if 'slider_image' in __i.keys() else None, )) return __r except: return []
def insert(self): try: __body = {"name": self.name} MongodbModel(body=__body, collection="industrial_town_companies").insert() return True except: return False
def delete(self): try: __body = {"_id": self.id} MongodbModel(body=__body, collection="industrial_town_companies").delete() return True except: return False
def get_one(self): try: __body = {"_id": self.id} __c = MongodbModel(body=__body, collection="companies").get_one() return self.get_company(__c) except: return False
def get_materials(self): try: __body = {"_id": self.id} __key = {"materials": 1} __c = MongodbModel(body=__body, key=__key, collection="companies").get_one_key() return __c['materials'] except: return []
def delete_format_slide_show(_format=None): try: __condition = {"key": "SLIDE_SHOW"} __body = {"$pull": {"formats": {"_id": _format}}} return MongodbModel(body=__body, condition=__condition, collection="setting").update() except: return False
def get_products(self): try: __body = {"_id": self.id} __key = {"products": 1} __c = MongodbModel(body=__body, key=__key, collection="companies").get_one_key() return __c['products'] except: return []
def get_all_city(self): try: __body = {"province": self.province} return [ i for i in MongodbModel(body=__body, collection="city").get_all() ] except: return []
def get_all_province(): try: __body = {} return [ i for i in MongodbModel(body=__body, collection="province").get_all() ] except: return []
def get_all(): try: __body = {} return [ i for i in MongodbModel(body=__body, collection="industrial_town_companies").get_all() ] except: return []
def update(self): try: __body = {"$set": {"name": self.name, "parent": self.parent}} __condition = {"_id": self.id} MongodbModel(body=__body, condition=__condition, collection="type_products").update() return True except: return False
def get_all_main_page(): try: __body = {"main_page": True} __a = MongodbModel(body=__body, collection="services").get_all() __r = [] for __i in __a: __r.append(__i) return __r except: return []
def update(self): try: __body = {"$set": {"name": self.name}} __condition = {"_id": self.id} MongodbModel(body=__body, condition=__condition, collection="industrial_town_companies").update() return True except: return False
def get_all_pagination(page=1, size=15): try: __body = {} __a = MongodbModel(body=__body, collection="services", page=page, size=size, sort="name", ascending=1)\ .get_all_key_pagination() __r = [] for __i in __a: __r.append(__i) return __r except: return []
def get_all_sub(self): try: __body = {"parent": self.parent} __r = MongodbModel(body=__body, collection="type_products").get_all() __l = [] for i in __r: __l.append(dict(_id=i['_id'], name=i['name'])) return __l except: return []
def delete_material(self, material): try: __body = {"$pull": {"materials": material}} __condition = {'_id': self.id} MongodbModel(body=__body, condition=__condition, collection="companies").update() return True except: return False