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

Python models.ContactManager类代码示例

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

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



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

示例1: post

    def post(self, slug):
        '''
        When post request is received, contact of which slug is equal to
        slug is retrieved. If its state is Pending or Error, the contact
        request is send again.
        '''

        logger = logging.getLogger("newebe.contact")

        self.contact = ContactManager.getContact(slug)
        owner = UserManager.getUser()

        if self.contact and self.contact.url != owner.url:
            try:
                data = owner.asContact().toJson()

                client = ContactClient()
                client.post(self.contact, "contacts/request/", data, 
                            self.on_contact_response)

            except Exception:
                import traceback
                logger.error("Error on adding contact:\n %s" % 
                        traceback.format_exc())

                self.contact.state = STATE_ERROR
                self.contact.save()

            self.return_one_document(self.contact)
        else:
            self.return_failure("Contact does not exist", 404)
开发者ID:mike-perdide,项目名称:newebe,代码行数:31,代码来源:handlers.py


示例2: 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:mike-perdide,项目名称:newebe,代码行数:31,代码来源:handlers.py


示例3: get

    def get(self):
        '''
        Retrieves whole contact list at JSON format.
        '''
        contacts = ContactManager.getContacts()

        self.return_documents(contacts)
开发者ID:mike-perdide,项目名称:newebe,代码行数:7,代码来源:handlers.py


示例4: delete

    def delete(self, slug):
        '''
        Deletes contact corresponding to slug.
        '''

        contact = ContactManager.getContact(slug)
        if contact:
            contact.delete()
            return self.return_success("Contact has been deleted.")
        else:
            self.return_failure("Contact does not exist.")
开发者ID:mike-perdide,项目名称:newebe,代码行数:11,代码来源:handlers.py


示例5: check_that_request_date_is_set_to_europe_paris_timezone

def check_that_request_date_is_set_to_europe_paris_timezone(step, timezone):
    Contact._db = db2
    contact = ContactManager.getRequestedContacts().first()
    Contact._db = db

    date = date_util.get_date_from_db_date(world.contacts[0]["requestDate"])
    tz = pytz.timezone(timezone)
    date = date.replace(tzinfo=tz)
    assert_equals(
            date_util.convert_utc_date_to_timezone(contact.requestDate, tz),
            date)
开发者ID:mike-perdide,项目名称:newebe,代码行数:11,代码来源:steps.py


示例6: send_creation_to_contacts

    def send_creation_to_contacts(self, path, doc):
        '''
        Sends a POST request to all trusted contacts.

        Request body contains object to post at JSON format.
        '''

        contacts = ContactManager.getTrustedContacts()
        client = ContactClient(self.activity)
        for contact in contacts:
            try:
                client.post(contact, path, doc.toJson(localized=False))
            except HTTPError:
                self.activity.add_error(contact)
                self.activity.save()
开发者ID:rakoo,项目名称:newebe,代码行数:15,代码来源:handlers.py


示例7: 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:mike-perdide,项目名称:newebe,代码行数:48,代码来源:handlers.py


示例8: send_files_to_contacts

    def send_files_to_contacts(self, path, fields, files):
        '''
        Sends in a form given file and fields to all trusted contacts (at given
        path).

        If any error occurs, it is stored in linked activity.
        '''

        contacts = ContactManager.getTrustedContacts()
        client = ContactClient(self.activity)
        for contact in contacts:
            try:
                client.post_files(contact, path, fields = fields, files = files)
            except HTTPError:
                self.activity.add_error(contact)
                self.activity.save()
开发者ID:rakoo,项目名称:newebe,代码行数:16,代码来源:handlers.py


示例9: 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:mike-perdide,项目名称:newebe,代码行数:17,代码来源:handlers.py


示例10: send_deletion_to_contacts

    def send_deletion_to_contacts(self, path, doc):
        '''
        Send a delete request (PUT because Tornado don't handle DELETE request
        with a body) to all trusted contacts.

        Request body contains object to delete at JSON format.
        '''

        contacts = ContactManager.getTrustedContacts()
        client = ContactClient(self.activity)
        date = date_util.get_db_date_from_date(doc.date)

        for contact in contacts:
            try:
                client.delete(contact, path, doc.toJson(localized=False), date)
            except HTTPError:
                import pdb
                pdb.set_trace()
                self.activity.add_error(contact, extra=date)
                self.activity.save()
开发者ID:rakoo,项目名称:newebe,代码行数:20,代码来源:handlers.py


示例11: 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()

        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:mike-perdide,项目名称:newebe,代码行数:20,代码来源:handlers.py


示例12: post

    def post(self):
        '''
        When sync request is received, if contact is a trusted contact, it
        sends again all posts from last month to contact.
        '''
            
        client = ContactClient()
        now = datetime.datetime.utcnow() 
        date = now - datetime.timedelta(365/12)

        contact = self.get_body_as_dict()
        localContact = ContactManager.getTrustedContact(contact.get("key", ""))

        if localContact:
            self.send_posts_to_contact(client, localContact, now, date)
            self.send_pictures_to_contact(client, localContact, now, date)

            self.return_document(UserManager.getUser().asContact())
        else:
            self.return_failure("Contact does not exist.")
开发者ID:mike-perdide,项目名称:newebe,代码行数:20,代码来源:handlers.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python date_util.get_date_from_db_date函数代码示例发布时间:2022-05-27
下一篇:
Python models.UserManager类代码示例发布时间: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