示例#1
0
    def insertRequest(self, form, nid):
        # New Resource
        if len(form) == 3:
            rname = form['rname']
            catid = form['catid']
            qty = form['qty']
            if rname and catid and qty:
                dao = ResourcesDAO()
                resource = dao.getResourcesByRname(rname)
                if not resource:
                    dao2 = CategoriesDAO()
                    if not dao2.getCategoryById(catid):
                        return jsonify(Error="Category Not Found"), 404
                    rid = dao.insert(rname, catid)
                else:
                    rid = (resource[0])[0]

                dao = ResourceRequestsDAO()
                req_id = dao.insertRequest(nid)

                dao3 = ResourceRequestDetailsDAO()
                dao3.insertRequestDetails(req_id, rid, qty)

                table = dao.getRequestByIdWithDetails(req_id)

                if not table:
                    return jsonify(Error="Request Not Found"), 404
                else:
                    print(table)
                    result = ResourceRequest().build_dict_from_table_details(
                        table)
                    return jsonify(result)
        elif len(form) != 2:
            return jsonify(Error="Malformed post request"), 400
        else:
            # Existing Resource
            rid = form['rid']
            qty = form['qty']

            if rid and qty:
                dao = ResourcesDAO()
                if not dao.getResourceById(rid):
                    return jsonify(Error="Resource Not Found"), 404

                dao2 = ResourceRequestsDAO()
                reqid = dao2.insertRequest(nid)
                dao3 = ResourceRequestDetailsDAO()
                dao3.insertRequestDetails(reqid, rid, qty)

                result = ResourceRequest().build_dict_from_row_resource(
                    dao2.getRequestByIdWithDetails2(reqid))
                return jsonify(result), 201
            else:
                return jsonify(
                    Error="Unexpected attributes in post request"), 400
 def getLocationByResourceId(self, r_id):
         dao = ResourcesDAO()
         location = dao.getLocationByResourceId(r_id)
         if not location:
             return jsonify(Error = 'Resource Not Found'),404
         result = location[0][0]
         return result
示例#3
0
 def deleteResource(self, resourceid):
     dao = ResourcesDAO()
     if not dao.getResourceById(resourceid):
         return jsonify(Error="Resource not found."), 404
     else:
         dao.delete(resourceid)
         return jsonify(DeleteStatus="OK"), 200
示例#4
0
 def insertResourcesJson(self, json):
     rname = json['rname']
     rtype = json['rtype']
     rprice = json['rprice']
     rlocation = json['rlocation']
     rstock = json['rstock']
     sid = json['sid']
     if not SupplierDAO().getSupplierById(sid):
         return jsonify(Error="Supplier Not Found"), 404
     if rlocation == 'Ponce':
         rlocation = '18.0107279,-66.6141375'
     elif rlocation == 'Mayaguez':
         rlocation = '18.201108,-67.1401665'
     elif rlocation == 'San Juan':
         rlocation = '18.46542,-66.1172515'
     if ',' in rlocation and len(rlocation) != 1:
         rlocation = "https://maps.google.com/?q=" + rlocation
     if rname and rtype and rprice and rlocation and rstock and sid:
         dao = ResourcesDAO()
         rid = dao.insert(rname, rtype, rprice, rlocation, rstock)
         dao.insertSupplierOfResource(sid, rid)
         result = self.build_resource_attributes(rid, rname, rtype, rprice,
                                                 rlocation, rstock)
         return jsonify(Resoure=result), 201
     else:
         return jsonify(Error="Unexpected attributes in post request"), 400
示例#5
0
 def getAvailableByKeyword(self, keyword):
     dao = ResourcesDAO()
     row = dao.getAvailableByKeyword(keyword)
     if not row:
         return jsonify(Error="Resource Not Available"), 404
     else:
         resource = self.build_resource_dict(row)
         return jsonify(ResourceSearchResult=resource)
示例#6
0
 def getAvailableResources(self):
     dao = ResourcesDAO()
     resource_list = dao.getAvailableResources()
     result_list = []
     for row in resource_list:
         result = self.build_resource_dict(row)
         result_list.append(result)
     return jsonify(AvailableResources=result_list)
示例#7
0
 def getAResource(self, rid):
     dao = ResourcesDAO()
     row = dao.getAResource(rid)
     if not row:
         return jsonify(Error="Resource Not Found"), 404
     else:
         request = self.build_resource_dict(row)
         return jsonify(Resource=request)
 def getAllResourcesReserves(self):
     dao = ResourcesDAO()
     resource_list = dao.getAllResourcesReserves()
     result_list = []
     for row in resource_list:
         result = self.build_resources_requests_dict(row)
         result_list.append(result)
     return jsonify(ResourcesReserves=result_list)
 def getResourceById(self,r_id):
     dao = ResourcesDAO()
     row = dao.getResourceById(r_id)
     if not row:
         return jsonify(Eror = 'Resource Not Found'),404
     else:
         r = self.build_resource_dict(row)
     return jsonify(Resource=r)
 def getResourcesAvailableWeekly(self):
     dao = ResourcesDAO()
     resource_list = dao.getResourcesAvailableWeekly()
     result_list = []
     for row in resource_list:
         result = self.build_resourcesAvailable_weekly_dict(row)
         result_list.append(result)
     return jsonify(ResourcesAvailableWeekly=result_list)
 def getResourcesInNeedDaily(self):
     dao = ResourcesDAO()
     resource_list = dao.getResourcesInNeedDaily()
     result_list = []
     for row in resource_list:
         result = self.build_resourcesInNeed_daily_dict(row)
         result_list.append(result)
     return jsonify(ResourcesInNeedDaily=result_list)
 def getResourcesAvailableBySenateRegion(self):
     dao = ResourcesDAO()
     resource_list = dao.getResourcesAvailableBySenateRegion()
     result_list = []
     for row in resource_list:
         result = self.build_resourcesAvailable_by_senate_region_dict(row)
         result_list.append(result)
     return jsonify(ResourcesAvailableBySenateRegion=result_list)
 def sortResourcesAvailableByResourceName(self):
     dao = ResourcesDAO()
     resource_list = dao.sortResourcesAvailableByResourceName()
     result_list = []
     for row in resource_list:
         result = self.build_resources_available_dict(row)
         result_list.append(result)
     return jsonify(SortResourcesAvailableByResourceName=result_list)
示例#14
0
 def getSenateAvailableStats(self):
     dao = ResourcesDAO()
     weekly_list = dao.getSenateStats()
     result_list = []
     for row in range(0, 8):
         result = self.build_senate_available_dict(weekly_list, row * 16)
         result_list.append(result)
     return jsonify(SenateAvailabilityDashboard=result_list)
示例#15
0
 def getResourceByCategoryName(self, categoryname):
     dao = ResourcesDAO()
     row = dao.getResourcesByCategoryName(categoryname)
     if not row:
         return jsonify(Error="Resource Not Found "), 404
     else:
         resource = self.build_resource_dict(row)
         return jsonify(Resource=resource)
示例#16
0
 def getResourceById(self, resourceID):
     dao = ResourcesDAO()
     resources_list = dao.getResourceById(resourceID)
     result_list = []
     for row in resources_list:
         result = self.build_resourceInfoByID_dict(row)
         result_list.append(result)
     return jsonify(Resource=result_list)
示例#17
0
 def getResourceAvailabilityById(self, resourceid):
     dao = ResourcesDAO()
     row = dao.getResourceAvailabilityById(resourceid)
     if not row:
         return jsonify(Error="Resource Not Found "), 404
     else:
         resource = self.build_resource_dict(row)
         return jsonify(Resource=resource)
示例#18
0
 def getAllResourcesInfo(self):
     dao = ResourcesDAO()
     resources_list = dao.getAllResourcesInfo()
     result_list = []
     for row in resources_list:
         result = self.build_resourcesInf_dict(row)
         result_list.append(result)
     return jsonify(Resources=result_list)
示例#19
0
 def getResourceBySupplier(self, collectionCenterID):
     dao = ResourcesDAO()
     resources_list = dao.getResourceByCollectionCenterID(collectionCenterID)
     result_list = []
     for row in resources_list:
         result = self.build_resourcesBySupplier_dict(row)
         result_list.append(result)
     return jsonify(Resource=result_list)
示例#20
0
 def add(self, json):
     if json['type'] and json['name'] and json['description']:
         resource = ResourcesDAO().add(json)
         resource_list = to_specified_format(resource, RESOURCE_FORMAT)
         return jsonify(Reservation=resource_list), CREATED
     else:
         return jsonify(
             Error='Unexpected attributes in post request'), BAD_REQUEST
示例#21
0
 def getAllResources(self):
     dao = ResourcesDAO()
     resources_list = dao.getAllResources()
     result_list = []
     for row in resources_list:
         result = Resource().build_dict_from_row(row)
         result_list.append(result)
     return jsonify(result_list)
示例#22
0
 def getResourceById(self, rid):
     dao = ResourcesDAO()
     row = dao.getResourceById(rid)
     if not row:
         return jsonify(Error="Resource Not Found"), 404
     else:
         resource = Resource().build_dict_from_row(row)
         return jsonify(resource)
示例#23
0
 def getResourceById(self, resID):
     dao = ResourcesDAO()
     row = dao.getResourceById(resID)
     if not row:
         return jsonify(Error="User not found"), 404
     else:
         resource = self.build_resource_dict(row)
         return jsonify(Resource=resource)
示例#24
0
 def getResourceRequestedByRequestID(self, rid, ord_id):
     dao = ResourcesDAO()
     requests = dao.getResourceRequestedByRequestID(rid, ord_id)
     dic = Dictionary()
     result_list = []
     for row in requests:
         result = dic.build_resource_dict(row)
         result_list.append(result)
     return jsonify(Requests=result_list), 200
示例#25
0
 def getResourceAvailableByName(self, rname):
     dao = ResourcesDAO()
     requests = dao.getResourceAvailableByName(rname)
     dic = Dictionary()
     result_list = []
     for row in requests:
         result = dic.build_resource_dict(row)
         result_list.append(result)
     return jsonify(Requests=result_list), 200
示例#26
0
    def getAllResourcesAvailableOrderByResourceName(self):
        dao = ResourcesDAO()
        resources_list = dao.getResourcesAvailableOrderByResourceName()
        result_list = []
        for row in resources_list:
            result = self.build_resource_dict(row)
            result_list.append(result)

        return jsonify(Resources=result_list)
示例#27
0
 def deleteResource(selfself, resID):
     dao = ResourcesDAO()
     type = dao.getResourceType(resID)
     if not type:
         return jsonify(Error = "Resource not found."), 404
     else:
         dao.delete(resID, type)
         #return jsonify(DeleteStatus = "OK"), 200
         return "<h3>Resource with ID: " + resID + " was removed from the database.</h3>"
示例#28
0
 def getAllDailyStats(self):
     dao = ResourcesDAO()
     daily_list = dao.getDailyStats()
     result = []
     result1 = self.build_daily_needs_dict(daily_list)
     result2 = self.build_daily_available_dict(daily_list)
     result.append(result1)
     result.append(result2)
     return jsonify(DailyDashboard=result)
示例#29
0
    def getAllResources(self):
        dao = ResourcesDAO()
        resources_list = dao.getAllResources()
        result_list = []
        # resources_list = [0,0,'papel de toilet', 5, 10]
        for row in resources_list:
            result = self.build_resource_dict(row)
            result_list.append(result)

        return jsonify(Resources=result_list)
示例#30
0
 def getResourcesByCity(self, city):
     dao = ResourcesDAO()
     suppliers_list = dao.getResourcesByCity(city)
     if len(suppliers_list) == 0:
         return jsonify(Error="City Not Found"), 404
     result_list = []
     for row in suppliers_list:
         result = self.build_user_dict(row)
         result_list.append(result)
     return jsonify(Suppliers=result_list)