def deleteRegion(self, rname): dao = RegionDAO() if not dao.getRegionByName(rname): return jsonify(Error="Region not found."), 404 else: dao.deleteRegion(rname) return jsonify(DeleteStatus="OK"), 200
def getAllRegion(self): dao = RegionDAO() region_list = dao.getAllRegion() result_list = [] for row in region_list: result = self.build_region_dict(row) result_list.append(result) return jsonify(Regions=result_list)
def getRegionById(self, region_id): dao = RegionDAO() row = dao.getRegionById(region_id) if not row: return jsonify(Error="Region Not Found"), 404 else: region = self.build_region_dict(row) return jsonify(Region=region)
def searchSupplierOfThisResourceOnThisRegion(self,rname, rsid, args): daoRes = ResourceDAO() daoRegion = RegionDAO() dao = SupplierDAO() if not daoRegion.getRegionByName(rname): return jsonify(Error = 'Region 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.getSupplierOfThisResourceOnThisRegionByAfirstAlastEmailPhone(rname, rsid, afirst, alast, email, phone) elif(len(args) == 3) and afirst and alast and email: suppliers_list = dao.getSupplierOfThisResourceOnThisRegionByAfirstAlastEmail(rname, rsid, afirst, alast, email) elif(len(args) == 3) and afirst and alast and phone: suppliers_list = dao.getSupplierOfThisResourceOnThisRegionByAfirstAlastPhone(rname, rsid, afirst, alast, phone) elif(len(args) == 3) and afirst and phone and email: suppliers_list = dao.getSupplierOfThisResourceOnThisRegionByAfirstPhoneEmail(rname, rsid, afirst, phone, email) elif(len(args) == 3) and alast and email and phone: suppliers_list = dao.getSupplierOfThisResourceOnThisRegionByAlastEmailPhone(rname, rsid, alast, email, phone) elif(len(args) == 2) and afirst and alast: suppliers_list = dao.getSupplierOfThisResourceOnThisRegionByAfirstAlast(rname, rsid, afirst, alast) elif(len(args) == 2) and afirst and email: suppliers_list = dao.getSupplierOfThisResourceOnThisRegionByAfirstEmail(rname, rsid, afirst, email) elif(len(args) == 2) and afirst and phone: suppliers_list = dao.getSupplierOfThisResourceOnThisRegionByAfirstPhone(rname, rsid, afirst, phone) elif(len(args) == 2) and alast and email: suppliers_list = dao.getSupplierOfThisResourceOnThisRegionByAlastEmail(rname, rsid, alast, email) elif(len(args) == 2) and alast and phone: suppliers_list = dao.getSupplierOfThisResourceOnThisRegionByAlastPhone(rname, rsid, alast, phone) elif(len(args) == 2) and email and phone: suppliers_list = dao.getSupplierOfThisResourceOnThisRegionByEmailPhone(rname, rsid, email, phone) elif(len(args) == 1) and afirst: suppliers_list = dao.getSupplierOfThisResourceOnThisRegionByAfirst(rname, rsid, afirst) elif(len(args) == 1) and alast: suppliers_list = dao.getSupplierOfThisResourceOnThisRegionByAlast(rname, rsid, alast) elif(len(args) == 1) and email: suppliers_list = dao.getSupplierOfThisResourceOnThisRegionByEmail(rname, rsid, email) elif(len(args) == 1) and phone: suppliers_list = dao.getSupplierOfThisResourceOnThisRegionByPhone(rname, 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 getResourcesBySRegionId(self, region_id): dao = RegionDAO() if not dao.getRegionById(region_id): return jsonify(Error="Reggion Not Found"), 404 resources_list = dao.getResourcesByRegionId(region_id) result_list = [] for row in resources_list: result = self.build_resource_dict(row) result_list.append(result) return jsonify(Resources=result_list)
def searchAdministratorsOnThisRegion(self, rname, args): daoReg = RegionDAO() dao = AdministratorDAO() if not daoReg.getRegionByName(rname): return jsonify(Error = 'Region 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.getAdministratorsOnThisRegionAfirstAlastEmailPhone(rname, afirst, alast, email, phone) elif(len(args) == 3) and afirst and alast and email: administrators_list = dao.getAdministratorsOnThisRegionByAfirstAlastEmail(rname, afirst, alast, email) elif(len(args) == 3) and afirst and alast and phone: administrators_list = dao.getAdministratorsOnThisRegionByAfirstAlastPhone(rname, afirst, alast, phone) elif(len(args) == 3) and afirst and phone and email: administrators_list = dao.getAdministratorsOnThisRegionByAfirstPhoneEmail(rname, afirst, phone, email) elif(len(args) == 3) and alast and email and phone: administrators_list = dao.getAdministratorsOnThisRegionByAlastEmailPhone(rname, alast, email, phone) elif(len(args) == 2) and afirst and alast: administrators_list = dao.getAdministratorsOnThisRegionByAfirstAlast(rname, afirst, alast) elif(len(args) == 2) and afirst and email: administrators_list = dao.getAdministratorsOnThisRegionByAfirstEmail(rname, afirst, email) elif(len(args) == 2) and afirst and phone: administrators_list = dao.getAdministratorsOnThisRegionByAfirstPhone(rname, afirst, phone) elif(len(args) == 2) and alast and email: administrators_list = dao.getAdministratorsOnThisRegionByAlastEmail(rname, alast, email) elif(len(args) == 2) and alast and phone: administrators_list = dao.getAdministratorsOnThisRegionByAlastPhone(rname, alast, phone) elif(len(args) == 2) and email and phone: administrators_list = dao.getAdministratorsOnThisRegionByEmailPhone(rname, email, phone) elif(len(args) == 1) and afirst: administrators_list = dao.getAdministratorsOnThisRegionByAfirst(rname, afirst) elif(len(args) == 1) and alast: administrators_list = dao.getAdministratorsOnThisRegionByAlast(rname, alast) elif(len(args) == 1) and email: administrators_list = dao.getAdministratorsOnThisRegionByEmail(rname, email) elif(len(args) == 1) and phone: administrators_list = dao.getAdministratorsOnThisRegionByPhone(rname, 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 addNewRegion(self, form): if len(form) != 1: return jsonify(Error="Malformed post request"), 400 else: rname = form['rname'] if rname: dao = RegionDAO() regionName = dao.addNewRegion(rname) result = self.build_region_attribute(regionName) return jsonify(Region=result), 201 else: return jsonify( Error="Unexpected attributes in post request"), 400
def searchRegions(self, args): rname = args.get("rname") dao = RegionDAO() regions_list = [] if (len(args) == 1) and rname: regions_list = dao.getRegionsByName(rname) else: return jsonify(Error="Malformed query string"), 400 result_list = [] for row in regions_list: result = self.build_region_dict(row) result_list.append(result) return jsonify(Regions=result_list)
def getRequesterRegion(self, rid): daoReq = RequesterDAO() dao = RegionDAO() if not daoReq.getRequesterById(rid): return jsonify(Error='Requester Not Found'), 404 regions_list = dao.getRequesterRegion(rid) result_list = [] for row in regions_list: result = self.build_region_dict(row) result_list.append(result) return jsonify(Region=result_list)
def getAdministratorRegion(self, adminId): daoAdmin = AdministratorDAO() dao = RegionDAO() if not daoAdmin.getAdministratorById(adminId): return jsonify(Error='Administrator Not Found'), 404 regions_list = dao.getAdministratorRegion(adminId) result_list = [] for row in regions_list: result = self.build_region_dict(row) result_list.append(result) return jsonify(Region=result_list)
def getAccountRegion(self, aid): daoAcc = AccountDAO() dao = RegionDAO() if not daoAcc.getAccountById(aid): return jsonify(Error='Account Not Found'), 404 regions_list = dao.getAccountRegion(aid) result_list = [] for row in regions_list: result = self.build_region_dict(row) result_list.append(result) return jsonify(Region=result_list)
def getRegionOfThisAddress(self, addId): daoAdd = AddressDAO() dao = RegionDAO() if not daoAdd.getAddressById(addId): return jsonify(Error='Address Not Found'), 404 regions_list = dao.getRegionOfThisAddress(addId) result_list = [] for row in regions_list: result = self.build_region_dict(row) result_list.append(result) return jsonify(Region=result_list)
def getSuppliersOnThisRegion(self, rname): daoReg = RegionDAO() dao = SupplierDAO() if not daoReg.getRegionByName(rname): return jsonify(Error="Region Not Found"), 404 suppliers_list = dao.getSuppliersOnThisRegion(rname) result_list = [] for row in suppliers_list: result = self.build_supplier_dict(row) result_list.append(result) return jsonify(Suppliers = 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 getAddressesOnThisRegion(self, rname): daoReg = RegionDAO() dao = AddressDAO() if not daoReg.getRegionByName(rname): return jsonify(Error="Region Not Found"), 404 addresses_list = dao.getAddressesOnThisRegion(rname) result_list = [] for row in addresses_list: result = self.build_address_dict(row) result_list.append(result) return jsonify(Addresses=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 getSupplierRegion(self, sid): daoSup = SupplierDAO() dao = RegionDAO() if not daoSup.getSupplierById(sid): return jsonify(Error='Supplier Not Found'), 404 regions_list = dao.getSupplierRegion(sid) result_list = [] for row in regions_list: result = self.build_region_dict(row) result_list.append(result) return jsonify(Region=result_list)
def getResourceRequestedRegion(self, rrid): daoResRec = ResourceRequestedDAO() dao = RegionDAO() if not daoResRec.getResourceRequestedById(rrid): return jsonify(Error='Resource Not Found'), 404 regions_list = dao.getResourceRequestedRegion(rrid) result_list = [] for row in regions_list: result = self.build_region_dict(row) result_list.append(result) return jsonify(Region=result_list)
def searchRegions(self, args): region_name = args.get("region_name") region_number = args.get("region_number") dao = RegionDAO() regions_list = [] if (len(args) == 1) and region_name: regions_list = dao.getRegionByRegionName(region_name) elif (len(args) == 1) and region_number: regions_list = dao.getRegionByRegionNumber(region_number) elif (len(args) == 2) and region_name and region_number: regions_list = dao.getRegionByRegionNameAndRegionNumber(region_name, region_number) else: return jsonify(Error="Malformed query string"), 400 result_list = [] for row in regions_list: result = self.build_region_dict(row) regions_list.append(result) return jsonify(Region=result_list)
def getSupplierOfThisResourceOnThisRegion(self, rname, rsid): daoRes = ResourceDAO() daoRegion = RegionDAO() dao = SupplierDAO() if not daoRegion.getRegionByName(rname): return jsonify(Error = 'Region Not Found'), 404 if not daoRes.getResourceById(rsid): return jsonify(Error = 'Resource Not Found'), 404 suppliers_list = dao.getSupplierOfThisResourceOnThisRegion(rname, rsid) result_list = [] for row in suppliers_list: result = self.build_supplier_dict(row) result_list.append(result) return jsonify(Supplier = result_list)
def getCategoriesByRegionName(self, rname): if not RegionDAO().getRegionByName(rname): return jsonify(Error="Region Not Found"), 404 else: category_list = CategoryDAO().getCategoriesByRegionName(rname) 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 searchAddressesOnThisRegion(self, rname, args): daoReg = RegionDAO() dao = AddressDAO() if not daoReg.getRegionByName(rname): return jsonify(Error="Region 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.getAddressOnThisRegionByStreetNumberUnitZipCode( rname, street, number, unit, zipcode) elif (len(args) == 3) and street and number and unit: addresses_list = dao.getAddressesOnThisRegionByStreetNumberUnit( rname, street, number, unit) elif (len(args) == 3) and street and number and zipcode: addresses_list = dao.getAddressesOnThisRegionByStreetNumberZipCode( rname, street, number, zipcode) elif (len(args) == 3) and street and zipcode and unit: addresses_list = dao.getAddressesOnThisRegionByStreetZipCodeUnit( rname, street, zipcode, unit) elif (len(args) == 3) and number and unit and zipcode: addresses_list = dao.getAddressesOnThisRegionByNumberUnitZipCode( rname, number, unit, zipcode) elif (len(args) == 2) and street and number: addresses_list = dao.getAddressesOnThisRegionByStreetNumber( rname, street, number) elif (len(args) == 2) and street and unit: addresses_list = dao.getAddressesOnThisRegionByStreetUnit( rname, street, unit) elif (len(args) == 2) and street and zipcode: addresses_list = dao.getAddressesOnThisRegionByStreetZipCode( rname, street, zipcode) elif (len(args) == 2) and number and unit: addresses_list = dao.getAddressesOnThisRegionByNumberUnit( rname, number, unit) elif (len(args) == 2) and number and zipcode: addresses_list = dao.getAddressesOnThisRegionByNumberZipCode( rname, number, zipcode) elif (len(args) == 2) and unit and zipcode: addresses_list = dao.getAddressesOnThisRegionByUnitZipCode( rname, unit, zipcode) elif (len(args) == 1) and street: addresses_list = dao.getAddressesOnThisRegionByStreet( rname, street) elif (len(args) == 1) and number: addresses_list = dao.getAddressesOnThisRegionByNumber( rname, number) elif (len(args) == 1) and unit: addresses_list = dao.getAddressesOnThisRegionByUnit(rname, unit) elif (len(args) == 1) and zipcode: addresses_list = dao.getAddressesOnThisRegionByZipCode( rname, 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)
def searchRequestersOnThisRegion(self, rname, args): dao = RequesterDAO() daoReg = RegionDAO() if not daoReg.getRegionByName(rname): return jsonify(Error='Region 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.getRequestersOnThisRegionAfirstAlastEmailPhone( rname, afirst, alast, email, phone) elif (len(args) == 3) and afirst and alast and email: requesters_list = dao.getRequestersOnThisRegionByAfirstAlastEmail( rname, afirst, alast, email) elif (len(args) == 3) and afirst and alast and phone: requesters_list = dao.getRequestersOnThisRegionByAfirstAlastPhone( rname, afirst, alast, phone) elif (len(args) == 3) and afirst and phone and email: requesters_list = dao.getRequestersOnThisRegionByAfirstPhoneEmail( rname, afirst, phone, email) elif (len(args) == 3) and alast and email and phone: requesters_list = dao.getRequestersOnThisRegionByAlastEmailPhone( rname, alast, email, phone) elif (len(args) == 2) and afirst and alast: requesters_list = dao.getRequestersOnThisRegionByAfirstAlast( rname, afirst, alast) elif (len(args) == 2) and afirst and email: requesters_list = dao.getRequestersOnThisRegionByAfirstEmail( rname, afirst, email) elif (len(args) == 2) and afirst and phone: requesters_list = dao.getRequestersOnThisRegionByAfirstPhone( rname, afirst, phone) elif (len(args) == 2) and alast and email: requesters_list = dao.getRequestersOnThisRegionByAlastEmail( rname, alast, email) elif (len(args) == 2) and alast and phone: requesters_list = dao.getRequestersOnThisRegionByAlastPhone( rname, alast, phone) elif (len(args) == 2) and email and phone: requesters_list = dao.getRequestersOnThisRegionByEmailPhone( rname, email, phone) elif (len(args) == 1) and afirst: requesters_list = dao.getRequestersOnThisRegionByAfirst( rname, afirst) elif (len(args) == 1) and alast: requesters_list = dao.getRequestersOnThisRegionByAlast( rname, alast) elif (len(args) == 1) and email: requesters_list = dao.getRequestersOnThisRegionByEmail( rname, email) elif (len(args) == 1) and phone: requesters_list = dao.getRequestersOnThisRegionByPhone( rname, 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)