def insertCollectionCenter(self, form): if form and len(form) == 6: ccname = form['ccname'] street = form['street'] town = form['town'] state = form['state'] country = form['country'] zipcode = form['zipcode'] if ccname and street and town and state and country and zipcode: dao = CollectionCenterDAO() ccid = dao.insert(ccname, street, town, state, country, zipcode) result = {} result['ccid'] = ccid result['street'] = street result['town'] = town result['state'] = state result['country'] = country result['ccname'] = ccname result['zipcode'] = zipcode return jsonify(Supplier=result), 201 else: return jsonify(Error="Malformed post request") else: return jsonify(Error="Malformed post request")
def deleteCollectionCenter(selfself, ccid): dao = CollectionCenterDAO() if not dao.getCenterByID(ccid): return jsonify(Error="Center not found."), 404 else: dao.delete(ccid) return jsonify(DeleteStatus="OK"), 200
def getCenterByName(self, ccname): dao = CollectionCenterDAO() row = dao.getCenterByName(ccname) if not row: return jsonify(Error="Collection Center Not Found"), 404 else: location = self.build_collectionCenter_dict(row) return jsonify(Location=location)
def getAllResources(self): dao = CollectionCenterDAO() collectioncenter_list = dao.getCenterByResourcesAvailable() result_list = [] for row in collectioncenter_list: result = self.build_ccByresourceType_dict(row) result_list.append(result) return jsonify(CollectionCenter=result_list)
def getAllCenters(self): dao = CollectionCenterDAO() location_list = dao.getAllCenters() result_list = [] for row in location_list: result = self.build_collectioncenter_dict(row) result_list.append(result) return jsonify(CollectionCenter=result_list)
def searchResorcebyCenterID(self, args): ccid = args.get('ccid') if len(ccid) < 1: return jsonify(Error="NO ARGUMENTS ENTER BY CENTER ID") elif ccid: dao = CollectionCenterDAO() collectioncenter_list = dao.getResourcesByCenterID(ccid) result_list = [] for row in collectioncenter_list: result = self.build_ccByresourceType_dict(row) result_list.append(result) return jsonify(Resources=result_list)
def updateCollectionCenter(self, ccid, form): dao = CollectionCenterDAO() if not dao.getCenterByID(ccid): return jsonify(Error="Center not found."), 404 else: if len(form) != 6: return jsonify(Error="Malformed update request"), 400 else: ccname = form['ccname'] street = form['street'] town = form['town'] state = form['state'] country = form['country'] zipcode = form['zipcode'] if ccname and street and town and state and country and zipcode: dao.update(ccid, ccname, street, town, state, country, zipcode) result = self.build_collectioncenter_attributes( ccid, ccname, street, town, state, country, zipcode) return jsonify(Center=result), 200 else: return jsonify( Error="Unexpected attributes in update request"), 400
def insertResource(self, form): if form and len(form) < 5: return jsonify(Error="Malformed post request"), 400 else: collectionCenterID = form['collectionCenterID'] resourceType = form['resourceType'] buy_free = form['buy_free'] market_price = form['market_price'] resQty = form['qty'] dao = ResourcesDAO() result = None daoCenter = CollectionCenterDAO() if not daoCenter.getCenterByID(collectionCenterID): return jsonify(Error="Center not found."), 404 resID = dao.insertResource(collectionCenterID, resourceType, buy_free, market_price, resQty) if resourceType == 'water': waterType = form['waterType'] waterBrand = form['waterBrand'] if waterType and waterBrand and resQty: dao.insertWater(resID, waterType, waterBrand, resQty) elif resourceType == 'food': foodTypeID = form['foodTypeID'] foodName = form['foodName'] if foodTypeID and foodName and resQty: dao.insertFood(resID, foodTypeID, foodName, resQty) elif resourceType == 'ice': iceBrand = form['iceBrand'] if iceBrand and resQty: dao.insertIce(resID, iceBrand, resQty) elif resourceType == 'clothing': clothingType = form['clothingType'] clothing_size = form['clothing_size'] if clothingType and clothing_size and resQty: dao.insertClothing(resID, clothingType, clothing_size, resQty) elif resourceType == 'gas': gasTypeID = form['gasTypeID'] gasBrand = form['gasBrand'] gasOctanage = form['gasOctanage'] if gasTypeID and gasBrand and gasOctanage and resQty: dao.insertGas(resID, gasTypeID, gasBrand, gasOctanage, resQty) elif resourceType == 'medicalDevices': medicalDeviceType = form['medicalDeviceType'] medDevName = form['medDevName'] medDevManufacturer = form['medDevManufacturer'] toTreat = form['toTreat'] if medicalDeviceType and medDevName and medDevManufacturer and toTreat and resQty: dao.insertMedical(resID, medicalDeviceType, medDevName, medDevManufacturer, toTreat, resQty) elif resourceType == 'heavyEquipment': heavyEquipmentType = form['heavyEquipmentType'] heavyEquipmentBrand = form['heavyEquipmentBrand'] if heavyEquipmentType and heavyEquipmentBrand: dao.insertHeavy(resID, heavyEquipmentType, heavyEquipmentBrand) elif resourceType == 'tools': toolType = form['toolType'] toolBrand = form['toolBrand'] if toolType and toolBrand and resQty: dao.insertTools(resID, toolType, toolBrand, resQty) elif resourceType == 'powerGenerator': powerGeneratorType = form['powerGeneratorType'] powerGeneratorBrand = form['powerGeneratorBrand'] watts = form['watts'] if powerGeneratorType and powerGeneratorBrand and watts and resQty: dao.insertPower(resID, powerGeneratorType, powerGeneratorBrand, watts, resQty) elif resourceType == 'batteries': batteryType = form['batteryType'] batteryBrand = form['batteryBrand'] batteryVoltage = form['batteryVoltage'] if batteryType and batteryBrand and batteryVoltage and resQty: dao.insertBatteries(resID, batteryType, batteryBrand, batteryVoltage, resQty) elif resourceType == 'medicicne': medicineType = form['medicineType'] medicine_form = form['medicine_form'] medicine_name = form['medicine_name'] medicine_exp_date = form['medicine_exp_date'] medicine_manufacturer = form['medicine_manufacturer'] if medicineType and medicine_form and medicine_name and medicine_exp_date and medicine_manufacturer and resQty: dao.insertMedicine(resID, medicineType, medicine_form, medicine_name, medicine_exp_date, medicine_manufacturer, resQty) else: return jsonify(Error="Unexpected attributes in post request"), 400 #result = self.build_resourcesInf_dict(resID, collectionCenterID, resourceType, buy_free, market_price, resQty) #return jsonify(Resource=result), 201 return self.getAllResourcesInfo()
def searchCenter(self, args): ccid = args.get('ccid') ccname = args.get('ccname') street = args.get('street') town = args.get('town') state = args.get('state') country = args.get('country') zipcode = args.get('zipcode') rtid = args.get('rtid') rtype = args.get('rtype') rname = args.get('rname') ravailable = args.get('ravailable') ccorders = args.get('ccorders') watts = args.get('watts') bvoltage = args.get('bvoltage') dao = CollectionCenterDAO() if (len(args) == 1) and ccid: collectioncenter_list = dao.getCenterByID(ccid) result_list = [] for row in collectioncenter_list: result = self.build_collectioncenter_dict(row) result_list.append(result) return jsonify(Center=result_list) if (len(args) == 1) and ccname: collectioncenter_list = dao.getResourcesAvailable(ccname) result_list = [] for row in collectioncenter_list: result = self.build_ccByresourceType_dict(row) result_list.append(result) return jsonify(Resources=result_list) elif (len(args) == 1) and street: collectioncenter_list = dao.getCenterByStreet(street) elif (len(args) == 1) and town: collectioncenter_list = dao.getCenterByTown(town) elif (len(args) == 1) and country: collectioncenter_list = dao.getCenterByCountry(country) elif (len(args) == 1) and zipcode: collectioncenter_list = dao.getCenterByZip(zipcode) elif (len(args) == 2) and ccorders and ccname: collectioncenter_list = dao.getOrdersbyCCName(ccname) result_list = [] for row in collectioncenter_list: result = self.build_resourcepurchasedByCC_dict(row) result_list.append(result) return jsonify(OrdersByCollectionCenter=result_list) #FUEL elif (len(args) == 1) and rname == 'fuel': collectioncenter_list = dao.getCenterByFuel(rname) result_list = [] for row in collectioncenter_list: result = self.build_fuel_dict(row) result_list.append(result) return jsonify(Fuel=result_list) elif (len(args) == 2) and rname == 'fuel' and (rtype): #fueltype collectioncenter_list = dao.getCenterByFuelType(rtype) result_list = [] for row in collectioncenter_list: result = self.build_fuel_dict(row) result_list.append(result) return jsonify(Fuel=result_list) elif (len(args) == 3) and rname == 'fuel' and (rtype) and (country or state or town): if (country): collectioncenter_list = dao.getCenterByFuelTypeAndCountry( rtype, country) elif (state): collectioncenter_list = dao.getCenterByFuelTypeAndState( rtype, state) elif (town): collectioncenter_list = dao.getCenterByFuelTypeAndTown( rtype, town) result_list = [] for row in collectioncenter_list: result = self.build_fuel_dict(row) result_list.append(result) return jsonify(Fuel=result_list) ##=======================================================================================================## # Water elif (len(args) == 1) and rname == 'water': collectioncenter_list = dao.getCenterByWater() result_list = [] for row in collectioncenter_list: result = self.build_water_dict(row) result_list.append(result) return jsonify(Water=result_list) elif (len(args) == 2) and rname == 'water' and (state or country or town): if (state): collectioncenter_list = dao.getCenterByWaterAndState(state) elif (country): collectioncenter_list = dao.getCenterByWaterAndCountry(country) elif (town): collectioncenter_list = dao.getCenterByWaterAndTown(town) result_list = [] for row in collectioncenter_list: result = self.build_water_dict(row) result_list.append(result) return jsonify(Water=result_list) elif (len(args) == 2) and rname == 'water' and rtype: # watertype collectioncenter_list = dao.getCenterByWaterType(rtype) result_list = [] for row in collectioncenter_list: result = self.build_water_dict(row) result_list.append(result) return jsonify(Water=result_list) elif (len(args) == 3) and rname == 'water' and (rtype) and (country or state or town): if (country): collectioncenter_list = dao.getCenterByWaterTypeAndCountry( rtype, country) elif (state): collectioncenter_list = dao.getCenterByWaterTypeAndState( rtype, state) elif (town): collectioncenter_list = dao.getCenterByWaterTypeAndTown( rtype, town) result_list = [] for row in collectioncenter_list: result = self.build_water_dict(row) result_list.append(result) return jsonify(Water=result_list) ##===============================================================================================================## ##FOOD elif (len(args) == 1) and rname == 'food': collectioncenter_list = dao.getCenterByFood() result_list = [] for row in collectioncenter_list: result = self.build_food_dict(row) result_list.append(result) return jsonify(FOOD=result_list) elif (len(args) == 2) and rname == 'food' and (state or country or town): if (state): collectioncenter_list = dao.getCenterByFoodAndState(state) elif (country): collectioncenter_list = dao.getCenterByFoodAndCountry(country) elif (town): collectioncenter_list = dao.getCenterByFoodAndTown(town) result_list = [] for row in collectioncenter_list: result = self.build_food_dict(row) result_list.append(result) return jsonify(Food=result_list) elif (len(args) == 2) and rname == 'food' and rtype: collectioncenter_list = dao.getCenterByFoodType(rtype) result_list = [] for row in collectioncenter_list: result = self.build_food_dict(row) result_list.append(result) return jsonify(FOOD=result_list) elif (len(args) == 3) and rname == 'food' and rtype and (state or country or town): if (state): collectioncenter_list = dao.getCenterByFoodTypeAndState( rtype, state) elif (country): collectioncenter_list = dao.getCenterByFoodTypeAndCountry( rtype, country) elif (town): collectioncenter_list = dao.getCenterByFoodTypeAndTown( rtype, town) result_list = [] for row in collectioncenter_list: result = self.build_food_dict(row) result_list.append(result) return jsonify(Food=result_list) ##################################################################################### elif (len(args) == 3) and rname == 'food' and rtype and (country or state or town): if (country): collectioncenter_list = dao.getCenterByFoodTypeAndCountry( rtype, country) elif (state): collectioncenter_list = dao.getCenterByFoodTypeAndState( rtype, state) elif (town): collectioncenter_list = dao.getCenterByFoodTypeAndTown( rtype, town) result_list = [] for row in collectioncenter_list: result = self.build_food_dict(row) result_list.append(result) return jsonify(FOOD=result_list) ##================================================================================================================## ##MEDICINE elif (len(args) == 1) and rname == 'medicine': collectioncenter_list = dao.getCenterByMedicine() result_list = [] for row in collectioncenter_list: result = self.build_medicine_dict(row) result_list.append(result) return jsonify(Medicine=result_list) elif (len(args) == 2) and (rname == 'medicine') and (country or state or town): if (town): collectioncenter_list = dao.getCenterByMedicineAndTown(town) elif (state): collectioncenter_list = dao.getCenterByMedicineAndState(state) elif (country): collectioncenter_list = dao.getCenterByMedicineAndCountry( country) result_list = [] for row in collectioncenter_list: result = self.build_medicine_dict(row) result_list.append(result) return jsonify(Medicine=result_list) ##================================================================================================================## ##HEAVY EQUIPMENT elif (len(args) == 1) and rname == 'heavyequipment': collectioncenter_list = dao.getCenterByHeavyEquipment() result_list = [] for row in collectioncenter_list: result = self.build_heavyequipment_dict(row) result_list.append(result) return jsonify(HeavyEquipment=result_list) elif (len(args) == 2) and (rname == 'heavyequipment') and (country or state or town): if (town): collectioncenter_list = dao.getCenterByHeavyEquipmentAndTown( town) elif (state): collectioncenter_list = dao.getCenterByHeavyEquipmentAndState( state) elif (country): collectioncenter_list = dao.getCenterByHeavyEquipmentAndCountry( country) result_list = [] for row in collectioncenter_list: result = self.build_heavyequipment_dict(row) result_list.append(result) return jsonify(HeavyEquipment=result_list) ##================================================================================================================## ##POWER GENERATORS elif (len(args) == 1) and rname == 'powergenerator': collectioncenter_list = dao.getCenterByPowerGenerator() result_list = [] for row in collectioncenter_list: result = self.build_powergenerator_dict(row) result_list.append(result) return jsonify(POWERGENERATOR=result_list) elif (len(args) == 2) and (rname == 'powergenerator') and (country or state or town): if (town): collectioncenter_list = dao.getCenterByPowerGeneratorAndTown( town) elif (state): collectioncenter_list = dao.getCenterByPowerGeneratorAndState( state) elif (country): collectioncenter_list = dao.getCenterByPowerGeneratorAndCountry( country) result_list = [] for row in collectioncenter_list: result = self.build_powergenerator_dict(row) result_list.append(result) return jsonify(POWERGENERATOR=result_list) elif (len(args) == 2) and (rname == 'powergenerator') and watts: collectioncenter_list = dao.getCenterByPowerGeneratorAndWatts( watts) result_list = [] for row in collectioncenter_list: result = self.build_powergenerator_dict(row) result_list.append(result) return jsonify(POWERGENERATOR=result_list) elif (len(args) == 3) and (rname == 'powergenerator') and watts and ( country or state or town): if (town): collectioncenter_list = dao.getCenterByPowerGeneratorAndWattsAndTown( watts, town) elif (state): collectioncenter_list = dao.getCenterByPowerGeneratorAndWattsAndState( watts, state) elif (country): collectioncenter_list = dao.getCenterByPowerGeneratorAndWattsAndCountry( watts, country) result_list = [] for row in collectioncenter_list: result = self.build_powergenerator_dict(row) result_list.append(result) return jsonify(POWERGENERATOR=result_list) ##================================================================================================================## ##================================================================================================================## ##CLOTHING elif (len(args) == 1) and rname == 'clothing': collectioncenter_list = dao.getCenterByClothing() result_list = [] for row in collectioncenter_list: result = self.build_clothing_dict(row) result_list.append(result) return jsonify(CLOTHING=result_list) elif (len(args) == 2) and (rname == 'clothing') and (country or state or town): if (town): collectioncenter_list = dao.getCenterByClothingAndTown(town) elif (state): collectioncenter_list = dao.getCenterByClothingAndState(state) elif (country): collectioncenter_list = dao.getCenterByClothingAndCountry( country) result_list = [] for row in collectioncenter_list: result = self.build_clothing_dict(row) result_list.append(result) return jsonify(CLOTHING=result_list) ##================================================================================================================## ##BATTERY elif (len(args) == 1) and rname == 'battery': collectioncenter_list = dao.getCenterByBattery() result_list = [] for row in collectioncenter_list: result = self.build_battery_dict(row) result_list.append(result) return jsonify(BATTERY=result_list) elif (len(args) == 2) and (rname == 'battery') and (country or state or town): if (town): collectioncenter_list = dao.getCenterByBatteryAndTown(town) elif (state): collectioncenter_list = dao.getCenterByBatteryAndState(state) elif (country): collectioncenter_list = dao.getCenterByBatteryAndCountry( country) result_list = [] for row in collectioncenter_list: result = self.build_battery_dict(row) result_list.append(result) return jsonify(BATERRY=result_list) elif (len(args) == 2) and (rname == 'battery') and bvoltage: collectioncenter_list = dao.getCenterByBatteryAndBVoltage(bvoltage) result_list = [] for row in collectioncenter_list: result = self.build_battery_dict(row) result_list.append(result) return jsonify(BATERRY=result_list) elif (len(args) == 3) and (rname == 'battery') and bvoltage and (country or state or town): if (town): collectioncenter_list = dao.getCenterByBatteryAndBVoltageAndTown( bvoltage, town) elif (state): collectioncenter_list = dao.getCenterByBatteryAndBVoltageAndState( bvoltage, state) elif (country): collectioncenter_list = dao.getCenterByBatteryAndBVoltageAndCountry( bvoltage, country) result_list = [] for row in collectioncenter_list: result = self.build_battery_dict(row) result_list.append(result) return jsonify(BATERRY=result_list) ##============================================================================================================## ##TOOLS elif (len(args) == 1) and rname == 'tools': collectioncenter_list = dao.getCenterByTools() result_list = [] for row in collectioncenter_list: result = self.build_tools_dict(row) result_list.append(result) return jsonify(TOOLS=result_list) elif (len(args) == 2) and (rname == 'tools') and (country or state or town): if (town): collectioncenter_list = dao.getCenterByToolsAndTown(town) elif (state): collectioncenter_list = dao.getCenterByToolsAndState(state) elif (country): collectioncenter_list = dao.getCenterByToolsAndCountry(country) result_list = [] for row in collectioncenter_list: result = self.build_tools_dict(row) result_list.append(result) return jsonify(TOOLS=result_list) ##============================================================================================================## #ICE elif (len(args) == 1) and rname == 'ice': collectioncenter_list = dao.getCenterByIce() result_list = [] for row in collectioncenter_list: result = self.build_ice_dict(row) result_list.append(result) return jsonify(ICE=result_list) elif (len(args) == 2) and (rname == 'ice') and (country or state or town): if (town): collectioncenter_list = dao.getCenterByIceAndTown(town) elif (state): collectioncenter_list = dao.getCenterByIceAndState(state) elif (country): collectioncenter_list = dao.getCenterByIceAndCountry(country) result_list = [] for row in collectioncenter_list: result = self.build_ice_dict(row) result_list.append(result) return jsonify(ICE=result_list) ##============================================================================================================## ##MEDICAL DEVICES elif (len(args) == 1) and rname == 'md': collectioncenter_list = dao.getCenterByMedicalDevices() result_list = [] for row in collectioncenter_list: result = self.build_medicalDevice_dict(row) result_list.append(result) return jsonify(MedicalDevices=result_list) elif (len(args) == 2) and (rname == 'md') and (country or state or town): if (town): collectioncenter_list = dao.getCenterByMedicalDeviceAndTown( town) elif (state): collectioncenter_list = dao.getCenterByMedicalDeviceAndState( state) elif (country): collectioncenter_list = dao.getCenterByMedicalDeviceAndCountry( country) result_list = [] for row in collectioncenter_list: result = self.build_medicalDevice_dict(row) result_list.append(result) return jsonify(MedicalDevices=result_list) ##================================================================================================================## elif (len(args) == 1) and ravailable: collectioncenter_list = dao.getCenterByResourcesAvailable() result_list = [] for row in collectioncenter_list: result = self.build_ccByresourceType_dict(row) result_list.append(result) return jsonify(ResourcesAvailable=result_list) elif (len(args) == 2) and ravailable and ccname: collectioncenter_list = dao.getCenterByResourcesAvailableAndCenterName( ccname) result_list = [] for row in collectioncenter_list: result = self.build_ccByresourceType_dict(row) result_list.append(result) return jsonify(ResourcesAvailable=result_list) elif (len(args) == 2) and ravailable and country: collectioncenter_list = dao.getCenterByResourcesAvailableAndCountry( country) result_list = [] for row in collectioncenter_list: result = self.build_ccByresourceType_dict(row) result_list.append(result) return jsonify(ResourcesAvailable=result_list) elif (len(args) == 2) and ravailable and state: collectioncenter_list = dao.getCenterByResourcesAvailableAndState( state) result_list = [] for row in collectioncenter_list: result = self.build_ccByresourceType_dict(row) result_list.append(result) return jsonify(ResourcesAvailable=result_list) elif (len(args) == 2) and ravailable and town: collectioncenter_list = dao.getCenterByResourcesAvailableAndTown( town) result_list = [] for row in collectioncenter_list: result = self.build_ccByresourceType_dict(row) result_list.append(result) return jsonify(ResourcesAvailable=result_list) elif (len(args) == 1) and rtype: #specific resource type of resource collectioncenter_list = dao.getCenterByResourceType(rtype) result_list = [] for row in collectioncenter_list: result = self.build_ccByresourceType_dict(row) result_list.append(result) return jsonify(CollectionCenter=result_list) elif (len(args) == 2) and rtype and country: collectioncenter_list = dao.getCenterByResourceTypeAndCountry( rtype, country) result_list = [] for row in collectioncenter_list: result = self.build_ccByresourceType_dict(row) result_list.append(result) return jsonify(CollectionCenter=result_list) elif (len(args) == 2) and rtype and state: collectioncenter_list = dao.getCenterByResourceTypeAndState( rtype, state) result_list = [] for row in collectioncenter_list: result = self.build_ccByresourceType_dict(row) result_list.append(result) return jsonify(CollectionCenter=result_list) elif (len(args) == 2) and rtype and town: collectioncenter_list = dao.getCenterByResourceTypeAndTown( rtype, town) result_list = [] for row in collectioncenter_list: result = self.build_ccByresourceType_dict(row) result_list.append(result) return jsonify(CollectionCenter=result_list) elif (len(args) == 2) and rtype and ccname: collectioncenter_list = dao.getCenterByResourceTypeAndCenterName( rtype, ccname) result_list = [] for row in collectioncenter_list: result = self.build_ccByresourceType_dict(row) result_list.append(result) return jsonify(CollectionCenter=result_list) # elif(len(args)==1) and announcement: # collectioncenter_list = dao.getAnnouncementResources() # result_list=[] # for row in collectioncenter_list: # result = self.build_announcement_dict(row) # result_list.append(result) #return jsonify(Annoucemnet=result_list) else: return jsonify(Error="Malformed query string"), 400 result_list = [] for row in collectioncenter_list: result = self.build_collectioncenter_dict(row) result_list.append(result) return jsonify(CollectionCenter=result_list)