• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python models.UserManager类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: save

    def save(self):
        '''
        When document is saved, the last modified field is updated to
        make sure it is always correct.
        '''

        if not self.authorKey:
            user = UserManager.getUser()
            self.authorKey = user.key
            self.author = user.name

        self.lastModified = datetime.datetime.utcnow()
        NewebeDocument.save(self)
开发者ID:DopeChicCity,项目名称:newebe,代码行数:13,代码来源:models.py


示例17: send_profile_to_contacts

    def send_profile_to_contacts(self):
        '''
        External methods to not send too much times the changed profile.
        A timer is set to wait for other modifications before running this
        function that sends modification requests to every contacts.
        '''
        client = HTTPClient()
        self.sending_data = False

        user = UserManager.getUser()
        jsonbody = user.toJson()

        activity = Activity(
            authorKey=user.key,
            author=user.name,
            verb="modifies",
            docType="profile",
            method="PUT",
            docId="none",
            isMine=True
        )
        activity.save()

        for contact in ContactManager.getTrustedContacts():

            try:
                request = HTTPRequest(
                    "%scontacts/update-profile/" % contact.url,
                    method="PUT",
                    body=jsonbody,
                    validate_cert=False)

                response = client.fetch(request)

                if response.error:
                    logger.error("""
                        Profile sending to a contact failed, error infos are
                        stored inside activity.
                    """)
                    activity.add_error(contact)
                    activity.save()
            except:
                logger.error("""
                    Profile sending to a contact failed, error infos are
                    stored inside activity.
                """)
                activity.add_error(contact)
                activity.save()

            logger.info("Profile update sent to all contacts.")
开发者ID:mpmedia,项目名称:newebe,代码行数:50,代码来源:handlers.py


示例18: given_there_are_3_posts_of_and_3_posts_of_my_contacts

def given_there_are_3_posts_of_and_3_posts_of_my_contacts(step,
                                                          nbposts,
                                                          nbcontactposts):
    nbposts = int(nbposts)
    nbcontactposts = int(nbcontactposts)

    for i in range(1, nbposts + 1):
        micropost = MicroPost()
        micropost.author = UserManager.getUser().name
        micropost.authorKey = UserManager.getUser().key
        micropost.content = "my content {}".format(i)
        micropost.date = datetime.datetime(2011, i, 01, 11, 05, 12)
        micropost.isMine = True
        micropost.save()

    for i in range(1, nbcontactposts + 1):
        micropost = MicroPost()
        micropost.author = world.user2.name
        micropost.authorKey = world.user2.key
        micropost.content = "contact content {}".format(i)
        micropost.date = datetime.datetime(2011, i, 10, 11, 05, 12)
        micropost.isMine = False
        micropost.save()
开发者ID:DopeChicCity,项目名称:newebe,代码行数:23,代码来源:steps.py


示例19: get

    def get(self):
        '''
        Asks for all contacts to resend their data from last month.
        As answer contacts send their profile. So contact data are updated,
        then contacts resend all their from their last month just like they
        were posted now.
        Current newebe has to check himself if he already has these data.
        '''
        client = ContactClient()
        user = UserManager.getUser()

        self.contacts = dict()
        for contact in ContactManager.getTrustedContacts():
            self.ask_to_contact_for_sync(client, user, contact)

        self.return_success("", 200)
开发者ID:DopeChicCity,项目名称:newebe,代码行数:16,代码来源:handlers.py


示例20: 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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python models.ContactManager类代码示例发布时间:2022-05-27
下一篇:
Python models.PictureManager类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap