Beispiel #1
0
    def get(self):
        id_edit = self.request.get("id_edit")
        if id_edit:
            temp = {}
            addressbook = AddressBook.get_by_id(int(id_edit))
            if addressbook:
                temp["id"] = addressbook.key.id()
                temp["fullname"] = addressbook.fullname
                temp["email"] = addressbook.email
                temp["phone"] = addressbook.phone
                temp["address"] = addressbook.address

            self.response.out.write(simplejson.dumps(temp))
            return

        id_delete = self.request.get("id_delete")
        if id_delete:
            temp = {}
            addressbook = AddressBook.get_by_id(int(id_delete))
            if addressbook:
                addressbook.key.delete()
                
                temp["message"] = "Success"

            self.response.out.write(simplejson.dumps(temp))
            return

        addressbooks = AddressBook.query().order(-AddressBook.created).fetch(100)
        if addressbooks:
            datas = []
            for ab in addressbooks:
                temp = {}
                temp["id"] = ab.key.id()
                temp["fullname"] = ab.fullname
                temp["email"] = ab.email
                temp["phone"] = ab.phone
                temp["address"] = ab.address
                datas.append(temp)

            self.response.out.write(simplejson.dumps(datas))
Beispiel #2
0
    def put(self, *args, **kwargs):
        temp = {}
        id = kwargs["id"]
        details = self.request.body

        if id and details:
            newmessage = simplejson.loads(details)

            addressbook = AddressBook.get_by_id(int(id))
            addressbook.fullname = newmessage["fullname"]
            addressbook.email = newmessage["email"]
            addressbook.phone = newmessage["phone"]
            addressbook.address = newmessage["address"]
            addressbook.put()

            temp["id"] = addressbook.key.id()
            temp["fullname"] = newmessage["fullname"]
            temp["email"] = newmessage["email"]
            temp["phone"] = newmessage["phone"]
            temp["address"] = newmessage["address"]

        self.response.out.write(simplejson.dumps(temp))