Exemple #1
0
    def put(self):
        '''
        Delete picture of which data are given inside request.
        Picture is found with contact key and creation date.

        If author is not inside trusted contacts, the request is rejected.
        '''

        data = self.get_body_as_dict()

        if data:
            contact = ContactManager.getTrustedContact(
                    data.get("authorKey", ""))
            
            if contact:
                picture = PictureManager.get_contact_picture(
                        contact.key, data.get("date", ""))

                if picture:
                    self.create_deletion_activity(contact, 
                            picture, "deletes", "picture")
                    picture.delete()

                self.return_success("Deletion succeeds")

            else:
                self.return_failure("Author is not trusted.", 400)      


        else:
            self.return_failure("No data sent.", 405)
Exemple #2
0
    def post(self):
        '''
        Extract picture and file linked to the picture from request, then 
        creates a picture in database for the contact who sends it. An 
        activity is created too.

        If author is not inside trusted contacts, the request is rejected.
        '''

        file = self.request.files['picture'][0]
        data = json_decode(self.get_argument("json"))

        if file and data:
            contact = ContactManager.getTrustedContact(
                    data.get("authorKey", ""))
            
            if contact:
                date = date_util.get_date_from_db_date(data.get("date", ""))

                picture = PictureManager.get_contact_picture(
                            contact.key, data.get("date", ""))

                if not picture:
                    picture = Picture(
                        title = data.get("title", ""),
                        path = data.get("path", ""),
                        contentType = data.get("contentType", ""),
                        authorKey = data.get("authorKey", ""),
                        author = data.get("author", ""),
                        tags = contact.tags,
                        date = date,
                        isMine = False,
                        isFile = False
                    )
                    picture.save()
                    picture.put_attachment(content=file["body"], 
                                           name="th_" + file['filename'])
                    picture.save()

                    self.create_creation_activity(contact,
                            picture, "publishes", "picture")

                logger.info("New picture from %s" % contact.name)
                self.return_success("Creation succeeds", 201)

            else:
                self.return_failure("Author is not trusted.", 400)                
        else:
            self.return_failure("No data sent.", 405)
Exemple #3
0
def when_i_get_first_from_its_date_and_author(step):
    picture = world.pictures[0]    
    world.picture = PictureManager.get_contact_picture(picture.authorKey, 
                                date_util.get_db_date_from_date(picture.date))