Beispiel #1
0
 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))
Beispiel #2
0
    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()
Beispiel #3
0
 def get(self):
     tracking_number = self.request.get("kolliid")
     
     
     if len(tracking_number) < 9:
         xml = ParcelHelper().tracking_number_error_as_xml()
     else:
         parcel_query = Parcel.all()
         parcel_query.filter("tracking_number =", tracking_number)
         parcel = parcel_query.get()
         
         if parcel is None:
             xml = ParcelHelper().no_parcel_as_xml(tracking_number)
         else:
             events_query = ParcelEvent.all()
             logging.info( parcel )
             events_query.ancestor(parcel.key())
             events = events_query.fetch(100)
             
             xml = ParcelHelper().parcel_as_xml(tracking_number, parcel, events)
     
     self.response.headers["Content-Type"] =  "text/xml; charset=ISO-8859-1"
     self.response.out.write(xml)
Beispiel #4
0
                response_dict = event.to_dict()
        
        self.response.headers["Content-Type"] =  "application/json; charset=UTF-8"
        self.response.out.write(json.dumps(response_dict))

    def put(self, parcel_id, parcel_event_id):
        try:
            data = json.load(self.request.body_file)
        except Exception, e:
            self.write_error(400, 1000, "Invalid body (should be json parcel)")
            return

        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.update_from_dict(data)
            parcel.put()
        else:
            #no update support for parcel events yet
            pass
        
        return self.no_content()

    def delete(self, parcel_id, parcel_event_id):
        if parcel_id is None:
            return self.not_found()
Beispiel #5
0
 def load(self):
     p1 = Parcel(
             tracking_number     = "151825825SE",
             customer_name       = "TELIA INFOMEDIA REKLAM AB",
             customer_id         = "3502560000",
             status_code         = 7,
             status_description  = "-",
             service_name        = "Foetagspaket 16.00",
             service_code        = 15,
             receiver_zip        = "85232",
             receiver_city       = "Boras",
             date_sent           = datetime(2010, 04, 05),
             date_delivered      = datetime(2010, 04, 18),
             actual_weight       = "2.7"
         )
     p1.put()
     
     p1_events = [
         {
             "date":         datetime(2010, 04, 05, 20, 00),
             "location":     "Boras",
             "code" :        20,
             "description":  "Inkommet inhamtningsterminal"
         },
         {
             "date":         datetime(2010, 04, 06, 8, 19),
             "location":     "Ange",
             "code" :        22,
             "description":  "Inkommet spridande terminal"
         },
         {
             "date":         datetime(2010, 04, 06, 13, 33),
             "location":     "Sunsdsvall 1",
             "code" :        25,
             "description":  "Summarisk kvittenslista skapad"
         },
         {
             "date":         datetime(2010, 04, 06, 14, 23),
             "location":     "Sunsdsvall lokal",
             "code" :        97,
             "description":  "Kolli ej utlamnat"
         },
         {
             "date":         datetime(2010, 04, 06, 14, 52),
             "location":     "Sunsdsvall lokal",
             "code" :        43,
             "description":  "Aviserat, kvitterat Pk"
         },
         {
             "date":         datetime(2010, 04, 06, 15, 06),
             "location":     "Sunsdsvall 1",
             "code" :        40,
             "description":  "Ankomst postkontor"
         },
         {
             "date":         datetime(2010, 04, 18, 11, 06),
             "location":     "Sunsdsvall 1",
             "code" :        49,
             "description":  "Utlamnat postkontor"
         },
         {
             "date":         datetime(2010, 04, 18, 11, 32),
             "location":     "Sunsdsvall lokal",
             "code" :        31,
             "description":  "Utlamnat mottagare, kollireg"
         },
         {
             "date":         datetime(2010, 04, 25, 11, 52),
             "location":     "System Ange",
             "code" :        30,
             "description":  "Kvittensreg. vid scannerstat."
         },
         {
             "error":        True,
             "date":         datetime(2010, 04, 06, 11, 52),
             "location":     "Sunsdsvall lokal",
             "code" :        802,
             "description":  "Stangt hos mottagare"
         },
     ]