當前位置: 首頁>>代碼示例>>Python>>正文


Python models.PictureManager類代碼示例

本文整理匯總了Python中newebe.apps.pictures.models.PictureManager的典型用法代碼示例。如果您正苦於以下問題:Python PictureManager類的具體用法?Python PictureManager怎麽用?Python PictureManager使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了PictureManager類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: put

    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)
開發者ID:mpmedia,項目名稱:newebe,代碼行數:30,代碼來源:handlers.py

示例2: post

    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)
開發者ID:mpmedia,項目名稱:newebe,代碼行數:29,代碼來源:handlers.py

示例3: ensure_that_picture_date_is_ok_with_time_zone

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
開發者ID:DopeChicCity,項目名稱:newebe,代碼行數:8,代碼來源:steps.py

示例4: get

 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)
開發者ID:mpmedia,項目名稱:newebe,代碼行數:10,代碼來源:handlers.py

示例5: get

    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)
開發者ID:WentaoXu,項目名稱:newebe,代碼行數:12,代碼來源:handlers.py

示例6: and_one_activity_for_first_picture_with_one_error_for_my_contact

def and_one_activity_for_first_picture_with_one_error_for_my_contact(step):
    author = world.browser.user
    world.contact = world.browser2.user.asContact()
    world.picture = PictureManager.get_last_pictures().first()

    world.activity = Activity(
        author=author.name,
        verb="posts",
        docType="picture",
        docId=world.picture._id,
    )
    world.activity.add_error(world.contact)
    world.activity.save()
開發者ID:DopeChicCity,項目名稱:newebe,代碼行數:13,代碼來源:steps.py

示例7: post

    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(
                        _id=data.get("_id", ""),
                        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_" + picture._id)
                    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)
開發者ID:DopeChicCity,項目名稱:newebe,代碼行數:50,代碼來源:handlers.py

示例8: and_i_add_one_deletion_activity_for_first_picture_with_one_error

def and_i_add_one_deletion_activity_for_first_picture_with_one_error(step):
    author = world.browser.user
    world.contact = world.browser2.user.asContact()
    world.picture = PictureManager.get_last_pictures().first()

    world.activity = Activity(
        author=author.name,
        verb="deletes",
        docType="picture",
        docId=world.picture._id,
        method="PUT"
    )
    date = date_util.get_db_date_from_date(world.picture.date)
    world.activity.add_error(world.contact, extra=date)
    world.activity.save()
開發者ID:DopeChicCity,項目名稱:newebe,代碼行數:15,代碼來源:steps.py

示例9: delete

    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)
開發者ID:WentaoXu,項目名稱:newebe,代碼行數:16,代碼來源:handlers.py

示例10: send_pictures_to_contact

    def send_pictures_to_contact(self, client, contact, now, date):
        '''
        Send pictures from last month to given contact.
        '''
        pictures = PictureManager.get_owner_last_pictures(
                startKey=date_util.get_db_date_from_date(now),
                endKey=date_util.get_db_date_from_date(date))

        for picture in pictures:
            if tags_match(picture, contact):
                client.post_files(
                    contact,
                    PICTURE_PATH,
                    {"json": str(picture.toJson(localized=False))},
                    [("picture",
                      str(picture.path),
                      picture.fetch_attachment("th_" + picture.path))
                    ],
                    self.onContactResponse)
開發者ID:DopeChicCity,項目名稱:newebe,代碼行數:19,代碼來源:handlers.py

示例11: convert

    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
開發者ID:DopeChicCity,項目名稱:newebe,代碼行數:20,代碼來源:attach.py

示例12: when_i_get_first_from_its_date_and_author

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))
開發者ID:DopeChicCity,項目名稱:newebe,代碼行數:4,代碼來源:steps.py

示例13: when_i_get_owner_pictures_until_november_1

def when_i_get_owner_pictures_until_november_1(step):
    world.pictures = PictureManager.get_owner_last_pictures(
            "2011-11-01T23:59:00Z").all()
開發者ID:DopeChicCity,項目名稱:newebe,代碼行數:3,代碼來源:steps.py

示例14: clear_all_pictures

def clear_all_pictures(step):
    pictures = PictureManager.get_last_pictures()
    while pictures:
        for picture in pictures:
            picture.delete()
        pictures = PictureManager.get_last_pictures()
開發者ID:DopeChicCity,項目名稱:newebe,代碼行數:6,代碼來源:steps.py

示例15: when_i_get_first_from_its_id

def when_i_get_first_from_its_id(step):
    world.picture = PictureManager.get_picture(world.pictures[0]._id)
開發者ID:DopeChicCity,項目名稱:newebe,代碼行數:2,代碼來源:steps.py


注:本文中的newebe.apps.pictures.models.PictureManager類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。