コード例 #1
0
ファイル: handlers.py プロジェクト: nollbit/posten-mock
 def get(self, parcel_id, parcel_event_id):
     response_dict = None
     if parcel_id is None:
         # show all parcels, sans events
         pq = Parcel.all()
         parcels = pq.fetch(100)
         response_dict = [p.to_dict() for p in parcels]
     else:
         # show single parcel, with events
         # unless event id set,
         # in that case, just return the event
         parcel = Parcel.get_by_id(int(parcel_id))
         if parcel is None:
             return self.not_found()
         response_dict = parcel.to_dict()
         
         if parcel_event_id is None:
             eq = ParcelEvent.all()
             eq.ancestor(parcel)
             eq.order("date")
             events = eq.fetch(100)
             event_dicts = [e.to_dict() for e in events]
             response_dict["events"] = event_dicts
         else:
             event = ParcelEvent.get_by_id(int(parcel_event_id), parent=parcel)
             if event is None:
                 return self.not_found()
             response_dict = event.to_dict()
     
     self.response.headers["Content-Type"] =  "application/json; charset=UTF-8"
     self.response.out.write(json.dumps(response_dict))
コード例 #2
0
ファイル: handlers.py プロジェクト: nollbit/posten-mock
    def delete(self, parcel_id, parcel_event_id):
        if parcel_id is None:
            return self.not_found()

        parcel = Parcel.get_by_id(int(parcel_id))
        if parcel is None:
            return self.not_found()

        if parcel_event_id is None:
            parcel.delete()
        else:
            parcelEvent = ParcelEvent.get_by_id(int(parcel_event_id), parent=parcel)
            if parcelEvent is None:
                return self.not_found()
                
            parcelEvent.delete()

        return self.no_content()