def deleteCity(self, cname): dao = CityDAO() if not dao.getCityByName(cname): return jsonify(Error="City not found."), 404 else: dao.deleteCity(cname) return jsonify(DeleteStatus="OK"), 200
def getCityByName(self, cname): dao = CityDAO() row = dao.getCityByName(cname) if not row: return jsonify(Error="City Not Found"), 404 else: city = self.build_city_dict(row) return jsonify(City=city)
def getAllCities(self): dao = CityDAO() cities_list = dao.getAllCities() result_list = [] for city in cities_list: result = self.build_city_dict(city) result_list.append(result) return jsonify(Cities=result_list)
def searchSupplierOfThisResourceOnThisCity(self,cname, rsid, args): daoRes = ResourceDAO() daoCity = CityDAO() dao = SupplierDAO() if not daoCity.getCityByName(cname): return jsonify(Error = 'City Not Found'), 404 if not daoRes.getResourceById(rsid): return jsonify(Error = 'Resource Not Found'), 404 afirst = args.get('afirst') alast = args.get('alast') email = args.get('email') phone = args.get('phone') suppliers_list = [] if(len(args) == 4) and afirst and alast and email and phone: suppliers_list = dao.getSupplierOfThisResourceOnThisCityByAfirstAlastEmailPhone(cname, rsid, afirst, alast, email, phone) elif(len(args) == 3) and afirst and alast and email: suppliers_list = dao.getSupplierOfThisResourceOnThisCityByAfirstAlastEmail(cname, rsid, afirst, alast, email) elif(len(args) == 3) and afirst and alast and phone: suppliers_list = dao.getSupplierOfThisResourceOnThisCityByAfirstAlastPhone(cname, rsid, afirst, alast, phone) elif(len(args) == 3) and afirst and phone and email: suppliers_list = dao.getSupplierOfThisResourceOnThisCityByAfirstPhoneEmail(cname, rsid, afirst, phone, email) elif(len(args) == 3) and alast and email and phone: suppliers_list = dao.getSupplierOfThisResourceOnThisCityByAlastEmailPhone(cname, rsid, alast, email, phone) elif(len(args) == 2) and afirst and alast: suppliers_list = dao.getSupplierOfThisResourceOnThisCityByAfirstAlast(cname, rsid, afirst, alast) elif(len(args) == 2) and afirst and email: suppliers_list = dao.getSupplierOfThisResourceOnThisCityByAfirstEmail(cname, rsid, afirst, email) elif(len(args) == 2) and afirst and phone: suppliers_list = dao.getSupplierOfThisResourceOnThisCityByAfirstPhone(cname, rsid, afirst, phone) elif(len(args) == 2) and alast and email: suppliers_list = dao.getSupplierOfThisResourceOnThisCityByAlastEmail(cname, rsid, alast, email) elif(len(args) == 2) and alast and phone: suppliers_list = dao.getSupplierOfThisResourceOnThisCityByAlastPhone(cname, rsid, alast, phone) elif(len(args) == 2) and email and phone: suppliers_list = dao.getSupplierOfThisResourceOnThisCityByEmailPhone(cname, rsid, email, phone) elif(len(args) == 1) and afirst: suppliers_list = dao.getSupplierOfThisResourceOnThisCityByAfirst(cname, rsid, afirst) elif(len(args) == 1) and alast: suppliers_list = dao.getSupplierOfThisResourceOnThisCityByAlast(cname, rsid, alast) elif(len(args) == 1) and email: suppliers_list = dao.getSupplierOfThisResourceOnThisCityByEmail(cname, rsid, email) elif(len(args) == 1) and phone: suppliers_list = dao.getSupplierOfThisResourceOnThisCityByPhone(cname, rsid, phone) else: return jsonify(Error = "Malformed query string"), 400 result_list = [] for row in suppliers_list: result = self.build_supplier_dict(row) result_list.append(result) return jsonify(Suppliers = result_list)
def searchAdministratorsOnThisCity(self, cname, args): daoCity = CityDAO() dao = AdministratorDAO() if not daoCity.getCityByName(cname): return jsonify(Error = 'City Not Found'), 404 afirst = args.get('afirst') #street alast = args.get('alast') #number email = args.get('email') #unit phone = args.get('phone') #zipcode administrators_list = [] if(len(args) == 4) and afirst and alast and email and phone: administrators_list = dao.getAdministratorsOnThisCityAfirstAlastEmailPhone(cname, afirst, alast, email, phone) elif(len(args) == 3) and afirst and alast and email: administrators_list = dao.getAdministratorsOnThisCityByAfirstAlastEmail(cname, afirst, alast, email) elif(len(args) == 3) and afirst and alast and phone: administrators_list = dao.getAdministratorsOnThisCityByAfirstAlastPhone(cname, afirst, alast, phone) elif(len(args) == 3) and afirst and phone and email: administrators_list = dao.getAdministratorsOnThisCityByAfirstPhoneEmail(cname, afirst, phone, email) elif(len(args) == 3) and alast and email and phone: administrators_list = dao.getAdministratorsOnThisCityByAlastEmailPhone(cname, alast, email, phone) elif(len(args) == 2) and afirst and alast: administrators_list = dao.getAdministratorsOnThisCityByAfirstAlast(cname, afirst, alast) elif(len(args) == 2) and afirst and email: administrators_list = dao.getAdministratorsOnThisCityByAfirstEmail(cname, afirst, email) elif(len(args) == 2) and afirst and phone: administrators_list = dao.getAdministratorsOnThisCityByAfirstPhone(cname, afirst, phone) elif(len(args) == 2) and alast and email: administrators_list = dao.getAdministratorsOnThisCityByAlastEmail(cname, alast, email) elif(len(args) == 2) and alast and phone: administrators_list = dao.getAdministratorsOnThisCityByAlastPhone(cname, alast, phone) elif(len(args) == 2) and email and phone: administrators_list = dao.getAdministratorsOnThisCityByEmailPhone(cname, email, phone) elif(len(args) == 1) and afirst: administrators_list = dao.getAdministratorsOnThisCityByAfirst(cname, afirst) elif(len(args) == 1) and alast: administrators_list = dao.getAdministratorsOnThisCityByAlast(cname, alast) elif(len(args) == 1) and email: administrators_list = dao.getAdministratorsOnThisCityByEmail(cname, email) elif(len(args) == 1) and phone: administrators_list = dao.getAdministratorsOnThisCityByPhone(cname, phone) else: return jsonify(Error = "Malformed query string"), 400 result_list = [] for row in administrators_list: result = self.build_administrator_dict(row) result_list.append(result) return jsonify(Administrators = result_list)
def searchCities(self, args): cname = args.get("cname") dao = CityDAO() cities_list = [] if (len(args) == 1) and cname: cities_list = dao.getCitiesByName(cname) else: return jsonify(Error="Malformed query string"), 400 result_list = [] for row in cities_list: result = self.build_city_dict(row) result_list.append(result) return jsonify(Cities=result_list)
def getCityOfThisAddress(self, addId): daoAdd = AddressDAO() dao = CityDAO() if not daoAdd.getAddressById(addId): return jsonify(Error='Address Not Found'), 404 cities_list = dao.getCityOfThisAddress(addId) result_list = [] for row in cities_list: result = self.build_city_dict(row) result_list.append(result) return jsonify(City=result_list)
def getCitiesOnThisRegion(self, rname): daoReg = RegionDAO() dao = CityDAO() if not daoReg.getRegionByName(rname): return jsonify(Error='Region Not Found'), 404 cities_list = dao.getCitiesOnThisRegion(rname) result_list = [] for row in cities_list: result = self.build_city_dict(row) result_list.append(result) return jsonify(Cities=cities_list)
def getAccountCity(self, aid): daoAcc = AccountDAO() dao = CityDAO() if not daoAcc.getAccountById(aid): return jsonify(Error='Account Not Found'), 404 cities_list = dao.getAccountCity(aid) result_list = [] for row in cities_list: result = self.build_city_dict(row) result_list.append(result) return jsonify(City=result_list)
def getAdministratorCity(self, adminId): daoAdmin = AdministratorDAO() dao = CityDAO() if not daoAdmin.getAdministratorById(adminId): return jsonify(Error='Administrator Not Found'), 404 cities_list = dao.getAdministratorCity(adminId) result_list = [] for row in cities_list: result = self.build_city_dict(row) result_list.append(result) return jsonify(City=result_list)
def getSuppliersOnThisCity(self, cname): daoCities = CityDAO() dao = SupplierDAO() if not daoCities.getCityByName(cname): return jsonify(Error="City Not Found"), 404 suppliers_list = dao.getSuppliersOnThisCity(cname) result_list = [] for row in suppliers_list: result = self.build_supplier_dict(row) result_list.append(result) return jsonify(Suppliers = result_list)
def addNewCity(self, form): if len(form) != 2: return jsonify(Error="Malformed post request"), 400 else: cname = form['cname'] rname = form['rname'] if cname and rname: dao = CityDAO() cityName = dao.addNewCity(cname, rname) result = self.build_city_attributes(cityName) return jsonify(City=result), 201 else: return jsonify( Error="Unexpected attributes in post request"), 400
def getAddressesOnThisCity(self, cname): daoCities = CityDAO() dao = AddressDAO() if not daoCities.getCityByName(cname): return jsonify(Error="City Not Found"), 404 addresses_list = dao.getAddressesOnThisCity(cname) result_list = [] for row in addresses_list: result = self.build_address_dict(row) result_list.append(result) return jsonify(Addresses=result_list)
def getRequesterCity(self, rid): daoReq = RequesterDAO() dao = CityDAO() if not daoReq.getRequesterById(rid): return jsonify(Error='Requester Not Found'), 404 cities_list = dao.getRequesterCity(rid) result_list = [] for row in cities_list: result = self.build_city_dict(row) result_list.append(result) return jsonify(City=result_list)
def getSupplierCity(self, sid): daoSup = SupplierDAO() dao = CityDAO() if not daoSup.getSupplierById(sid): return jsonify(Error='Supplier Not Found'), 404 cities_list = dao.getSupplierCity(sid) result_list = [] for row in cities_list: result = self.build_city_dict(row) result_list.append(result) return jsonify(City=result_list)
def getCityRegion(self, cname): daoCities = CityDAO() dao = RegionDAO() if not daoCities.getCityByName(cname): return jsonify(Error="City Not Found"), 404 regions_list = dao.getCityRegion(cname) result_list = [] for row in regions_list: result = self.build_region_dict(row) result_list.append(result) return jsonify(Regions=result_list)
def getAdministratorsOnThisCity(self, cname): daoCity = CityDAO() dao = AdministratorDAO() if not daoCity.getCityByName(cname): return jsonify(Error="City Not Found"), 404 administrators_list = dao.getAdministratorsOnThisCity(cname) result_list = [] for row in administrators_list: result = self.build_administrator_dict(row) result_list.append(result) return jsonify(Administrators = result_list)
def getRequestersOnThisCity(self, cname): daoCity = CityDAO() dao = RequesterDAO() if not daoCity.getCityByName(cname): return jsonify(Error="City Not Found"), 404 requesters_list = dao.getRequestersOnThisCity(cname) result_list = [] for row in requesters_list: result = self.build_requester_dict(row) result_list.append(result) return jsonify(Requesters=result_list)
def getSupplierOfThisResourceOnThisCity(self, cname, rsid): daoRes = ResourceDAO() daoCity = CityDAO() dao = SupplierDAO() if not daoCity.getCityByName(cname): return jsonify(Error = 'City Not Found'), 404 if not daoRes.getResourceById(rsid): return jsonify(Error = 'Resource Not Found'), 404 suppliers_list = dao.getSupplierOfThisResourceOnThisCity(cname, rsid) result_list = [] for row in suppliers_list: result = self.build_supplier_dict(row) result_list.append(result) return jsonify(Supplier = result_list)
def getCategoriesByCityName(self, cname): if not CityDAO().getCityByName(cname): return jsonify(Error="City Not Found"), 404 else: category_list = CategoryDAO().getCategoriesByCityName(cname) result_list = [] for row in category_list: result = self.build_category_dict(row) result_list.append(result) if not result_list: return jsonify(Error="Categories Not Found"), 404 else: return jsonify(Categories=result_list)
def searchAddressesOnThisCity(self, cname, args): daoCities = CityDAO() dao = AddressDAO() if not daoCities.getCityByName(cname): return jsonify(Error="City Not Found"), 404 street = args.get('street') number = args.get('number') unit = args.get('unit') zipcode = args.get('zipcode') addresses_list = [] if (len(args) == 4) and street and number and unit and zipcode: addresses_list = dao.getAddressOnThisCityByStreetNumberUnitZipCode( cname, street, number, unit, zipcode) elif (len(args) == 3) and street and number and unit: addresses_list = dao.getAddressesOnThisCityByStreetNumberUnit( cname, street, number, unit) elif (len(args) == 3) and street and number and zipcode: addresses_list = dao.getAddressesOnThisCityByStreetNumberZipCode( cname, street, number, zipcode) elif (len(args) == 3) and street and zipcode and unit: addresses_list = dao.getAddressesOnThisCityByStreetZipCodeUnit( cname, street, zipcode, unit) elif (len(args) == 3) and number and unit and zipcode: addresses_list = dao.getAddressesOnThisCityByNumberUnitZipCode( cname, number, unit, zipcode) elif (len(args) == 2) and street and number: addresses_list = dao.getAddressesOnThisCityByStreetNumber( cname, street, number) elif (len(args) == 2) and street and unit: addresses_list = dao.getAddressesOnThisCityByStreetUnit( cname, street, unit) elif (len(args) == 2) and street and zipcode: addresses_list = dao.getAddressesOnThisCityByStreetZipCode( cname, street, zipcode) elif (len(args) == 2) and number and unit: addresses_list = dao.getAddressesOnThisCityByNumberUnit( cname, number, unit) elif (len(args) == 2) and number and zipcode: addresses_list = dao.getAddressesOnThisCityByNumberZipCode( cname, number, zipcode) elif (len(args) == 2) and unit and zipcode: addresses_list = dao.getAddressesOnThisCityByUnitZipCode( cname, unit, zipcode) elif (len(args) == 1) and street: addresses_list = dao.getAddressesOnThisCityByStreet(cname, street) elif (len(args) == 1) and number: addresses_list = dao.getAddressesOnThisCityByNumber(cname, number) elif (len(args) == 1) and unit: addresses_list = dao.getAddressesOnThisCityByUnit(cname, unit) elif (len(args) == 1) and zipcode: addresses_list = dao.getAddressesOnThisCityByZipCode( cname, zipcode) else: return jsonify(Error="Malformed query string"), 400 result_list = [] for row in addresses_list: result = self.build_address_dict(row) result_list.append(result) return jsonify(Addresses=result_list)
import csv from dao.city import CityDAO from dao.province import ProvinceDAO from dao.county import CountyDAO from dao.commune import CommuneDAO from dao.district import DistrictDAO from dao.village import VillageDAO from dao.utils import config # read configuration cfg = config() # DAO to manipulate collections city = CityDAO() province = ProvinceDAO() commune = CommuneDAO() county = CountyDAO() district = DistrictDAO() village = VillageDAO() # drop all collections before load def refresh(): if cfg['mongo']['refresh']: city.truncate() province.truncate() commune.truncate() county.truncate() district.truncate() village.truncate()
def searchRequestersOnThisCity(self, cname, args): daoCity = CityDAO() dao = RequesterDAO() if not daoCity.getCityByName(cname): return jsonify(Error='City Not Found'), 404 afirst = args.get('afirst') alast = args.get('alast') email = args.get('email') phone = args.get('phone') requesters_list = [] if (len(args) == 4) and afirst and alast and email and phone: requesters_list = dao.getRequestersOnThisCityAfirstAlastEmailPhone( cname, afirst, alast, email, phone) elif (len(args) == 3) and afirst and alast and email: requesters_list = dao.getRequestersOnThisCityByAfirstAlastEmail( cname, afirst, alast, email) elif (len(args) == 3) and afirst and alast and phone: requesters_list = dao.getRequestersOnThisCityByAfirstAlastPhone( cname, afirst, alast, phone) elif (len(args) == 3) and afirst and phone and email: requesters_list = dao.getRequestersOnThisCityByAfirstPhoneEmail( cname, afirst, phone, email) elif (len(args) == 3) and alast and email and phone: requesters_list = dao.getRequestersOnThisCityByAlastEmailPhone( cname, alast, email, phone) elif (len(args) == 2) and afirst and alast: requesters_list = dao.getRequestersOnThisCityByAfirstAlast( cname, afirst, alast) elif (len(args) == 2) and afirst and email: requesters_list = dao.getRequestersOnThisCityByAfirstEmail( cname, afirst, email) elif (len(args) == 2) and afirst and phone: requesters_list = dao.getRequestersOnThisCityByAfirstPhone( cname, afirst, phone) elif (len(args) == 2) and alast and email: requesters_list = dao.getRequestersOnThisCityByAlastEmail( cname, alast, email) elif (len(args) == 2) and alast and phone: requesters_list = dao.getRequestersOnThisCityByAlastPhone( cname, alast, phone) elif (len(args) == 2) and email and phone: requesters_list = dao.getRequestersOnThisCityByEmailPhone( cname, email, phone) elif (len(args) == 1) and afirst: requesters_list = dao.getRequestersOnThisCityByAfirst( cname, afirst) elif (len(args) == 1) and alast: requesters_list = dao.getRequestersOnThisCityByAlast(cname, alast) elif (len(args) == 1) and email: requesters_list = dao.getRequestersOnThisCityByEmail(cname, email) elif (len(args) == 1) and phone: requesters_list = dao.getRequestersOnThisCityByPhone(cname, phone) else: return jsonify(Error="Malformed query string"), 400 result_list = [] for row in requesters_list: result = self.build_requester_dict(row) result_list.append(result) return jsonify(Requesters=result_list)