当前位置: 首页>>代码示例>>Python>>正文


Python models.UserManager类代码示例

本文整理汇总了Python中newebe.apps.profile.models.UserManager的典型用法代码示例。如果您正苦于以下问题:Python UserManager类的具体用法?Python UserManager怎么用?Python UserManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了UserManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: createMicropost

def createMicropost(content):
    micropost = MicroPost()
    micropost.author = UserManager.getUser().name
    micropost.authorKey = UserManager.getUser().key
    micropost.content = content
    micropost.isMine = True
    micropost.save()
    return micropost
开发者ID:DopeChicCity,项目名称:newebe,代码行数:8,代码来源:indexing.py

示例2: post

    def post(self):
        '''
        Creates a picture and corresponding activity. Then picture is
        propagated to all trusted contacts.

        Errors are stored inside activity.
        '''

        filebody = self.request.body
        filename = self.get_argument("qqfile")
        try:
            tag = self.get_argument("tag")
        except:
            tag = "all"
        filetype = mimetypes.guess_type(filename)[0] or \
                'application/octet-stream'

        if filebody:

            picture = Picture(
                title="New Picture",
                path=filename,
                contentType=filetype,
                authorKey=UserManager.getUser().key,
                author=UserManager.getUser().name,
                isMine=True,
                isFile=True,
                tags=[tag]
            )
            picture.save()

            picture.put_attachment(content=filebody, name=filename)
            thumbnail = self.get_thumbnail(filebody, filename, (200, 200))
            thbuffer = thumbnail.read()
            picture.put_attachment(thbuffer, "th_" + filename)
            thpath = os.path.join(CONFIG.main.path, "th_" + filename)

            os.remove(thpath)
            preview = self.get_thumbnail(filebody, filename, (1000, 1000))
            picture.put_attachment(preview.read(), "prev_" + filename)
            os.remove(thpath)
            picture.save()

            self.create_owner_creation_activity(
                    picture, "publishes", "picture")

            self.send_files_to_contacts("pictures/contact/",
                        fields={"json": str(picture.toJson(localized=False))},
                        files=[("picture", str(picture.path), thbuffer)],
                        tag=tag)

            logger.info("Picture %s successfuly posted." % filename)
            self.return_json(picture.toJson(), 201)

        else:
            self.return_failure("No picture posted.", 400)
开发者ID:mpmedia,项目名称:newebe,代码行数:56,代码来源:handlers.py

示例3: post

    def post(self):
        """
        Creates a picture and corresponding activity. Then picture is
        propagated to all trusted contacts.

        Errors are stored inside activity.
        """

        file = self.request.files["picture"][0]

        if file:
            filebody = file["body"]

            picture = Picture(
                title="New Picture",
                contentType=file["content_type"],
                authorKey=UserManager.getUser().key,
                author=UserManager.getUser().name,
                isFile=True,
            )
            picture.save()

            filename = "%s.jpg" % picture._id
            picture.path = filename
            picture.put_attachment(filebody, filename)
            thumbnail = self.get_thumbnail(filebody, filename, (200, 200))
            thbuffer = thumbnail.read()
            picture.put_attachment(thbuffer, "th_" + filename)
            thpath = os.path.join(CONFIG.main.path, "th_" + filename)
            os.remove(thpath)
            preview = self.get_thumbnail(filebody, filename, (1000, 1000))
            picture.put_attachment(preview.read(), "prev_" + filename)
            os.remove(thpath)
            picture.save()

            self.create_owner_creation_activity(picture, "publishes", "picture")

            self.send_files_to_contacts(
                "pictures/contact/",
                fields={"json": str(picture.toJson(localized=False))},
                files=[("picture", str(picture.path), thbuffer)],
            )

            logger.info("Picture %s successfuly posted." % filename)
            self.return_json(picture.toJson(), 201)

        else:
            self.return_failure("No picture posted.", 400)
开发者ID:WentaoXu,项目名称:newebe,代码行数:48,代码来源:handlers.py

示例4: delete

    def delete(self, id):
        '''
        Deletes the post of which id is equal to postId, add an activity and
        forwards the delete request to each trusted contact.

        put instead of delete because tornado does not support body in DELETE
        requests...
        '''

        micropost = MicroPostManager.get_micropost(id)

        if micropost:
            user = UserManager.getUser()

            if micropost.authorKey == user.key:
                self.create_owner_deletion_activity(
                    micropost, "deletes", "micropost")
                self.send_deletion_to_contacts(CONTACT_PATH, micropost)
            postIndexer = indexer.Indexer()
            postIndexer.remove_doc(micropost)
            micropost.delete()
            self.return_success("Micropost deletion succeeds.")

        else:
            self.return_failure("Micropost not found.", 404)
开发者ID:mpmedia,项目名称:newebe,代码行数:25,代码来源:handlers.py

示例5: put

    def put(self, key):
        '''
        Resend deletion of micropost 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"}
        '''

        data = self.get_body_as_dict(
                expectedFields=["contactId", "activityId", "extra"])

        if data:

            contactId = data["contactId"]
            activityId = data["activityId"]
            date = data["extra"]

            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:

                user = UserManager.getUser()
                micropost = MicroPost(
                    authorKey=user.key,
                    date=date_util.get_date_from_db_date(date)
                )

                logger.info(
                    "Attempt to resend a post deletion to contact: {}.".format(
                        contact.name))
                httpClient = ContactClient()
                body = micropost.toJson(localized=False)

                try:
                    httpClient.put(contact, CONTACT_PATH, body,
                                   callback=(yield gen.Callback("retry")))
                    response = yield gen.Wait("retry")

                    if response.error:
                        self.return_failure(
                                "Deleting micropost to contact failed.")

                    else:
                        for error in activity.errors:
                            if error["contactKey"] == contact.key:
                                activity.errors.remove(error)
                                activity.save()
                                self.return_success(
                                        "Micropost correctly redeleted.")

                except:
                    self.return_failure("Deleting micropost to contact failed.")

        else:
            self.return_failure("Micropost not found", 404)
开发者ID:mpmedia,项目名称:newebe,代码行数:60,代码来源:handlers.py

示例6: get_current_user

    def get_current_user(self):
        '''
        With tornado, authentication is handled in this method.
        '''

        user = UserManager.getUser()

        if user:

            if user.password is None:
                logger.error("User has no password registered")
                self.redirect("/#register/password/")

            else:
                #password = self.get_secure_cookie("password")

                # if not password or  \
                #   user.password != hashlib.sha224(password).hexdigest():
                #     logger.error("User is not authenticated")
                #     self.redirect("/#login/")

                #else:
                return user

        else:
            logger.error("User is not registered")
            self.redirect("/#register")
开发者ID:WentaoXu,项目名称:newebe,代码行数:27,代码来源:handlers.py

示例7: on_picture_found

    def on_picture_found(self, picture, id):
        '''
        '''
        self.picture = picture

        data = dict()
        data["picture"] = picture.toDict(localized=False)
        data["contact"] = UserManager.getUser().asContact().toDict()

        print CURRENT_DOWNLOADS
        print "data picture id %s" % data["picture"]["_id"]
        for download in CURRENT_DOWNLOADS:
            print "download %s " % download

            if download == data["picture"]["_id"]:
                return self.return_success('already downloading')

        CURRENT_DOWNLOADS.append(data["picture"]["_id"])

        contact = ContactManager.getTrustedContact(picture.authorKey)

        client = ContactClient()
        body = json_encode(data)

        try:
            client.post(contact,  u"pictures/contact/download/",
                        body, self.on_download_finished)
        except HTTPError:
            self.return_failure("Cannot download picture from contact.")
开发者ID:DopeChicCity,项目名称:newebe,代码行数:29,代码来源:handlers.py

示例8: put

    def put(self, key):
        """
        Resend deletion of micropost 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"}
        """
        data = self.get_body_as_dict(expectedFields=["contactId", "activityId", "extra"])

        if data:

            contactId = data["contactId"]
            activityId = data["activityId"]
            date = data["extra"]

            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:
                user = UserManager.getUser()
                picture = Picture(authorKey=user.key, date=date_util.get_date_from_db_date(date))

                info = "Attempt to resend a picture deletion to contact: {}."
                logger.info(info.format(contact.name))

                self.forward_to_contact(picture, contact, activity, method="PUT")

        else:
            self.return_failure("Micropost not found", 404)
开发者ID:WentaoXu,项目名称:newebe,代码行数:35,代码来源:handlers.py

示例9: post

    def post(self, postId):
        """
        Grab from contact the file corresponding to given path and given post
        (post of which ID is equal to *postId*).
        """

        data = self.get_body_as_dict(expectedFields=["path"])

        micropost = MicroPostManager.get_micropost(postId)
        contact = ContactManager.getTrustedContact(micropost.authorKey)
        user = UserManager.getUser()
        if micropost and data and contact:
            path = data["path"]
            client = ContactClient()
            body = {"date": date_util.get_db_date_from_date(micropost.date), "contactKey": user.key, "path": path}

            client.post(
                contact, "microposts/contacts/attach/", json_encode(body), callback=(yield gen.Callback("getattach"))
            )
            response = yield gen.Wait("getattach")

            if response.error:
                self.return_failure("An error occured while retrieving picture.")
            else:
                micropost.put_attachment(response.body, data["path"])
                self.return_success("Download succeeds.")

        else:
            if not data:
                self.return_failure("Wrong data.", 400)
            elif not contact:
                self.return_failure("Contact no more available.", 400)
            else:
                self.return_failure("Micropost not found.", 404)
开发者ID:prologic,项目名称:newebe,代码行数:34,代码来源:handlers.py

示例10: get

 def get(self):
     '''
     Retrieves current user (newebe owner) data at JSON format.
     '''
     user = UserManager.getUser()
     userDict = user.toDict()
     del userDict["password"]
     self.return_json(userDict)
开发者ID:DopeChicCity,项目名称:newebe,代码行数:8,代码来源:handlers.py

示例11: send_picture_to_contact

 def send_picture_to_contact(self, contact):
     user = UserManager.getUser()
     picture = user.fetch_attachment("small_picture.jpg")
     self.send_files_to_contact(
         contact,
         "contact/update-profile/picture/",
         fields={"key": user.key},
         files=[("smallpicture", "smallpicture.jpg", picture)]
     )
开发者ID:WentaoXu,项目名称:newebe,代码行数:9,代码来源:handlers.py

示例12: post

    def post(self):
        '''
        Creates a common and corresponding activity. Then common is
        propagated to all trusted contacts.

        Errors are stored inside activity.
        '''

        filebody = self.request.body
        filename = self.get_argument("qqfile")
        try:
            tag = self.get_argument("tag")
        except:
            tag = "all"
        filetype = mimetypes.guess_type(filename)[0] or \
                'application/octet-stream'

        if filebody:

            common = Common(
                title="New Common",
                path=filename,
                contentType=filetype,
                authorKey=UserManager.getUser().key,
                author=UserManager.getUser().name,
                isMine=True,
                isFile=True,
                tags=[tag]
            )
            common.save()

            common.put_attachment(content=filebody, name=filename)
            common.save()

            self.create_owner_creation_activity(
                    common, "publishes", "common")

            self.send_creation_to_contacts(CONTACT_PATH, common)

            logger.info("Common %s successfuly posted." % filename)
            self.return_json(common.toJson(), 201)

        else:
            self.return_failure("No common posted.", 400)
开发者ID:DopeChicCity,项目名称:newebe,代码行数:44,代码来源:handlers.py

示例13: get

 def get(self):
     '''
     Returns current profile picture as a jpeg file.
     '''
     try:
         user = UserManager.getUser()
         file = user.fetch_attachment("picture.jpg")
         self.return_file("picture.jpg", file)
     except ResourceNotFound:
         self.return_failure("Picture not found.", 404)
开发者ID:WentaoXu,项目名称:newebe,代码行数:10,代码来源:handlers.py

示例14: get

    def get(self, key):
        '''
        Returns an HTML representation of contact corresponding to given
        ID. If ID is equal to null Newebe owner representation is returned.
        '''

        if key == "null" or key == UserManager.getUser().key:
            contact = UserManager.getUser().asContact()
        else:
            contact = ContactManager.getTrustedContact(key)

        if contact:
            #if contact.description:
            #    contact.description = markdown.markdown(contact.description)

            self.render("templates/contact_render.html",
                            contact=contact)
        else:
            return self.return_failure("Contact not found.", 404)
开发者ID:mpmedia,项目名称:newebe,代码行数:19,代码来源:handlers.py

示例15: create_owner_deletion_activity

    def create_owner_deletion_activity(self, doc, verb, docType):
        '''
        Creates a new activity corresponding to a document deletion made
        by owner.

        * doc: The deleted document.
        * verb: verb linked to this activity.
        * docType: Type of the deleted document.
        '''

        self.create_deletion_activity(
            UserManager.getUser().asContact(), doc, verb, docType, True)
开发者ID:WentaoXu,项目名称:newebe,代码行数:12,代码来源:handlers.py


注:本文中的newebe.apps.profile.models.UserManager类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。