Esempio n. 1
0
    def post(self, key):
        '''
        Resend post with *key* as key to the contact given in the posted
        JSON. Corresponding activity ID is given inside the posted json.
        Here is the format : {"contactId":"data","activityId":"data"}
        '''
        picture = PictureManager.get_picture(key)
        idInfos = self.request.body

        ids = json_decode(idInfos)

        if picture and idInfos:

            contactId = ids["contactId"]
            activityId = ids["activityId"]

            contact = ContactManager.getTrustedContact(contactId)
            activity = ActivityManager.get_activity(activityId)

            if not contact:
                self.return_failure("Contact not found", 404)
            elif not activity:
                self.return_failure("Activity not found", 404)
            else:
                info = "Attemp to resend a picture to contact: {}."
                logger.info(info.format(contact.name))
                self.forward_to_contact(picture, contact, activity)
        else:
            self.return_failure("Picture not found", 404)
Esempio n. 2
0
    def post(self, key):
        '''
        Resend post with *key* as key to the contact given in the posted
        JSON. Corresponding activity ID is given inside the posted json.
        Here is the format : {"contactId":"data","activityId":"data"}
        '''
        picture = PictureManager.get_picture(key)
        idInfos = self.request.body

        ids = json_decode(idInfos)

        if picture and idInfos:

            contactId = ids["contactId"]
            activityId = ids["activityId"]

            contact = ContactManager.getTrustedContact(contactId)
            activity = ActivityManager.get_activity(activityId)

            if not contact:
                self.return_failure("Contact not found", 404)
            elif not activity:
                self.return_failure("Activity not found", 404)
            else:
                info = "Attemp to resend a picture to contact: {}."
                logger.info(info.format(contact.name))
                self.forward_to_contact(picture, contact, activity)
        else:
            self.return_failure("Picture not found", 404)
Esempio n. 3
0
def ensure_that_picture_date_is_ok_with_time_zone(step):
    world.date_picture = world.pictures[0]

    picture_db = PictureManager.get_picture(world.date_picture["_id"])
    date = date_util.convert_utc_date_to_timezone(picture_db.date)
    date = date_util.get_db_date_from_date(date)

    assert world.date_picture["date"] == date
Esempio n. 4
0
 def get(self, id):
     '''
     Retrieves picture corresponding to id. Returns a 404 response if
     picture is not found.
     '''
     picture = PictureManager.get_picture(id)
     if picture:
         self.on_picture_found(picture, id)
     else:
         self.return_failure("Picture not found.", 404)
Esempio n. 5
0
 def get(self, id):
     '''
     Retrieves picture corresponding to id. Returns a 404 response if
     picture is not found.
     '''
     picture = PictureManager.get_picture(id)
     if picture:
         self.on_picture_found(picture, id)
     else:
         self.return_failure("Picture not found.", 404)
Esempio n. 6
0
    def get(self, id, filename):
        """
        Retrieves picture corresponding to id. Returns a 404 response if
        picture is not found.
        """

        picture = PictureManager.get_picture(id)
        if picture:
            self.filename = filename
            self.on_picture_found(picture, id)
        else:
            self.return_failure("Picture not found.", 404)
Esempio n. 7
0
    def delete(self, id):
        """
        Deletes picture corresponding to id.
        """
        picture = PictureManager.get_picture(id)
        if picture:
            user = UserManager.getUser()

            if picture.authorKey == user.key:
                self.create_owner_deletion_activity(picture, "deletes", "picture")
                self.send_deletion_to_contacts("pictures/contact/", picture)

            picture.delete()
            self.return_success("Picture deleted.")
        else:
            self.return_failure("Picture not found.", 404)
Esempio n. 8
0
    def delete(self, id):
        '''
        Deletes picture corresponding to id.
        '''
        picture = PictureManager.get_picture(id)
        if picture:
            user = UserManager.getUser()

            if picture.authorKey == user.key:
                self.create_owner_deletion_activity(picture, "deletes",
                                                    "picture")
                self.send_deletion_to_contacts("pictures/contact/", picture)

            picture.delete()
            self.return_success("Picture deleted.")
        else:
            self.return_failure("Picture not found.", 404)
Esempio n. 9
0
    def convert(self, data):
        '''
        Expect to have an attachments field in given dict. When dict has some
        attachments, it retrieves corresponding docs and convert them in
        attachment dict (same as usual dict with less fields).
        Then attach docs are returned inside an array.
        '''

        docs = []
        self.fileDocs = []
        for doc in data.get("attachments", []):
            if doc["type"] == "Note":
                note = NoteManager.get_note(doc["id"])
                docs.append(note.toDictForAttachment())
            elif doc["type"] == "Picture":
                picture = PictureManager.get_picture(doc["id"])
                docs.append(picture.toDictForAttachment())
                self.fileDocs.append(picture)

        return docs
Esempio n. 10
0
def when_i_get_first_from_its_id(step):
    world.picture = PictureManager.get_picture(world.pictures[0]._id)