示例#1
0
 def post(self, *args, **kwargs):
     selected = ""
     try:
         province = int(self.get_argument('province', 0))
         _all = self.get_argument('all', 'false')
         _all = True if _all == 'true' else False
         cities = ProvinceCityModel(province=province).get_all_city()
         html = '<option value="all">همه شهر ها</option>' if _all else '<option value="">انتخاب کنید.</option>'
         try:
             __a = True
             for i in cities:
                 if __a:
                     selected = str(i['_id'])
                 html += "<option value=" + str(
                     i['_id']) + ">" + i['name'].encode(
                         "utf-8") + "</option>"
                 __a = False
         except:
             pass
         self.write(dict(html=html, selected=selected))
     except:
         self.write(
             dict(html="<option selected value="
                  ">انتخاب کنید.</option>",
                  selected=selected))
 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 []
示例#4
0
    def get(self, *args, **kwargs):
        main = True
        try:
            name = args[0]
            main = False
        except:
            name = "all"
        try:
            unit = ObjectId(args[1])
            main = False
        except:
            unit = "all"
        try:
            province = int(args[2])
            main = False
        except:
            province = "all"
        try:
            city = int(args[3])
            main = False
        except:
            city = "all"

        self.data['count'] = 0
        self.data['companies'] = []
        if not main:
            self.data['companies'] = CompaniesModel().user_search(
                name=name, province=province, city=city, unit=unit)
            self.data['count'] = CompaniesModel().user_search_count(
                name=name, province=province, city=city, unit=unit)
        self.data['this_name'] = name if name != "all" else ""

        self.data['this_province'] = province if province != "all" else ""
        self.data['this_city'] = city if city != "all" else ""
        self.data['this_unit'] = unit if unit != "all" else ""
        self.data['units'] = UnitCompaniesModel().get_all()
        self.data['provinces'] = ProvinceCityModel().get_all_province()
        self.data['cities'] = ProvinceCityModel(
            province=province).get_all_city()
        self.render('user/search_companies.html', **self.data)
 def user_search(name="all",
                 province="all",
                 city="all",
                 unit="all",
                 page=1,
                 size=30):
     try:
         __body = {"$and": [{"active": True}]}
         if name != 'all':
             __body['$and'].append(dict(name={"$regex": name}))
         if province != 'all':
             __body['$and'].append(dict(province=province))
         if city != 'all':
             __body['$and'].append(dict(city=city))
         if unit != 'all':
             __body['$and'].append(dict(unit=unit))
         if not len(__body['$and']):
             __body = {}
         __key = {
             'name': 1,
             'image': 1,
             'city': 1,
             'industrial_town': 1,
             'description': 1
         }
         __a = MongodbModel(body=__body,
                            key=__key,
                            collection="companies",
                            sort="name",
                            page=page,
                            size=size,
                            ascending=1).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']))
         __r = sorted(__r, key=lambda k: k['name'])
         return __r
     except:
         return []
 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
示例#7
0
 def get(self, *args, **kwargs):
     self.data['units'] = UnitCompaniesModel().get_all()
     self.data['industrial_towns'] = IndustrialTownCompaniesModel().get_all(
     )
     self.data['provinces'] = ProvinceCityModel().get_all_province()
     self.render('user/register_companies.html', **self.data)
    def get_company(__c):
        try:

            def __get(__n, __d):
                return __c[__n] if __n in __c.keys() else __d

            try:
                products = []
                for i in __c['products']:
                    __p = ProductsModel(_id=i).get_one()
                    if __p is not False:
                        products.append(__p)
            except:
                products = []
            try:
                materials = []
                for i in __c['materials']:
                    __p = ProductsModel(_id=i).get_one()
                    if __p is not False:
                        materials.append(__p)
            except:
                materials = []
            try:
                province_name = ProvinceCityModel(
                    _id=__c['province']).get_province()['name']
            except:
                province_name = "-"
            try:
                city_name = ProvinceCityModel(
                    _id=__c['city']).get_city()['name']
            except:
                city_name = "-"
            try:
                unit_name = UnitCompaniesModel(
                    _id=__c['unit']).get_one()['name']
            except:
                unit_name = "-"
            try:
                industrial_town_name = IndustrialTownCompaniesModel(
                    _id=__c['industrial_town']).get_one()['name']
            except:
                industrial_town_name = "-"

            return dict(_id=__get("_id", None),
                        name=__get("name", ""),
                        main_page=__get("main_page", False),
                        slider=__get("slider", False),
                        active=__get("active", False),
                        logo=__get("logo", ""),
                        slider_image=__get("slider_image", ""),
                        image=__get("image", ""),
                        address=__get("address", ""),
                        phone=__get("phone", ""),
                        phone2=__get("phone2", ""),
                        mobile=__get("mobile", ""),
                        fax=__get("fax", ""),
                        site=__get("site", ""),
                        email=__get("email", ""),
                        ceo=__get("ceo", ""),
                        coordinator=__get("coordinator", ""),
                        mobile_coordinator=__get("mobile_coordinator", ""),
                        products_info=__get("products_info", ""),
                        materials_info=__get("materials_info", ""),
                        owner=__get("owner", ""),
                        province=__get("province", ""),
                        province_name=province_name,
                        city_name=city_name,
                        city=__get("city", ""),
                        unit=__get("unit", ""),
                        unit_name=unit_name,
                        industrial_town=__get("industrial_town", ""),
                        industrial_town_name=industrial_town_name,
                        images=__get("images", []),
                        materials=materials,
                        products=products,
                        description=__get("description", ""),
                        about=__get("about", ""))
        except:
            return False