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


Python ContactManager.getContact方法代码示例

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


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

示例1: post

# 需要导入模块: from newebe.apps.contacts.models import ContactManager [as 别名]
# 或者: from newebe.apps.contacts.models.ContactManager import getContact [as 别名]
    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:mpmedia,项目名称:newebe,代码行数:33,代码来源:handlers.py

示例2: get

# 需要导入模块: from newebe.apps.contacts.models import ContactManager [as 别名]
# 或者: from newebe.apps.contacts.models.ContactManager import getContact [as 别名]
    def get(self, slug):
        '''
        Retrieves contact corresponding to slug at JSON format.
        '''

        contact = ContactManager.getContact(slug)

        self.return_one_document_or_404(contact, "Contact does not exist.")
开发者ID:mpmedia,项目名称:newebe,代码行数:10,代码来源:handlers.py

示例3: delete

# 需要导入模块: from newebe.apps.contacts.models import ContactManager [as 别名]
# 或者: from newebe.apps.contacts.models.ContactManager import getContact [as 别名]
    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:mpmedia,项目名称:newebe,代码行数:13,代码来源:handlers.py

示例4: put

# 需要导入模块: from newebe.apps.contacts.models import ContactManager [as 别名]
# 或者: from newebe.apps.contacts.models.ContactManager import getContact [as 别名]
    def put(self, slug):
        '''
        Grab tags sent inside request to set is on contact matching slug.
        '''

        contact = ContactManager.getContact(slug)
        data = self.get_body_as_dict(["tags"])

        if contact:
            if data:
                contact.tags = data["tags"]
                contact.save()
            else:
                self.return_failure("No tags were sent")
        else:
            self.return_failure("Contact to modify does not exist.", 404)
开发者ID:mpmedia,项目名称:newebe,代码行数:18,代码来源:handlers.py

示例5: post

# 需要导入模块: from newebe.apps.contacts.models import ContactManager [as 别名]
# 或者: from newebe.apps.contacts.models.ContactManager import getContact [as 别名]
    def post(self):
        '''
        Create a new contact from sent data (contact object at JSON format).
        Sets its status to Wait For Approval
        '''
        data = self.get_body_as_dict(expectedFields=["url"])

        if data:
            url = data["url"]
            owner = UserManager.getUser()

            if owner.url != url:
                slug = slugify(url)

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

                if contact is None:
                    contact = Contact(
                        name=data["name"],
                        url=url,
                        slug=slug,
                        key=data["key"],
                        state=STATE_WAIT_APPROVAL,
                        requestDate=datetime.datetime.utcnow(),
                        description=data["description"]
                    )
                    contact.save()

                contact.state = STATE_WAIT_APPROVAL
                contact.save()

                for websocket_client in websocket_clients:
                    websocket_client.write_message(contact.toJson())

                self.return_success("Request received.")

            else:
                self.return_failure("Contact and owner have same url.")

        else:
            self.return_failure("Sent data are incorrects.")
开发者ID:WentaoXu,项目名称:newebe,代码行数:44,代码来源:handlers.py

示例6: put

# 需要导入模块: from newebe.apps.contacts.models import ContactManager [as 别名]
# 或者: from newebe.apps.contacts.models.ContactManager import getContact [as 别名]
    def put(self, slug):
        '''
        Confirm contact request or update tag data.
        '''

        data = self.get_body_as_dict(["tags", "state"])
        state = data["state"]
        tags = data.get("tags", None)
        self.contact = ContactManager.getContact(slug)

        if self.contact:
            if self.contact.state != STATE_TRUSTED and state == STATE_TRUSTED:
                self.contact.state = STATE_TRUSTED
                self.contact.save()

                user = UserManager.getUser()
                data = user.asContact().toJson(localized=False)

                try:
                    client = ContactClient()
                    client.post(self.contact, "contacts/confirm/", data,
                                self.on_contact_response)
                except:
                    self.contact.state = STATE_ERROR
                    self.contact.save()
                    self.return_failure(
                        "Error occurs while confirming contact.")

            elif tags != None:
                self.contact.tags = tags
                self.contact.save()
                self.return_success("Contact tags updated.")

            else:
                self.return_success("Nothing to change.")

        else:
            self.return_failure("Contact to confirm does not exist.")
开发者ID:WentaoXu,项目名称:newebe,代码行数:40,代码来源:handlers.py

示例7: checks_that_default_contact_data_are_updated

# 需要导入模块: from newebe.apps.contacts.models import ContactManager [as 别名]
# 或者: from newebe.apps.contacts.models.ContactManager import getContact [as 别名]
def checks_that_default_contact_data_are_updated(step):
    contact = ContactManager.getContact(slugify(u"http://default:8000/"))
    assert "http://default:8010/" == contact.url
    assert "default contact 2" == contact.name
    assert "desc 2" == contact.description
开发者ID:mpmedia,项目名称:newebe,代码行数:7,代码来源:steps.py

示例8: change_default_contact_data_through_handlers

# 需要导入模块: from newebe.apps.contacts.models import ContactManager [as 别名]
# 或者: from newebe.apps.contacts.models.ContactManager import getContact [as 别名]
def change_default_contact_data_through_handlers(step):
    contact = ContactManager.getContact(slugify(u"http://default:8000/"))
    contact.description = "desc 2"
    contact.url = u"http://default:8010/"
    contact.name = "default contact 2"
    world.browser.put("contacts/update-profile/", contact.toJson())
开发者ID:mpmedia,项目名称:newebe,代码行数:8,代码来源:steps.py

示例9: get_contact_with_slug

# 需要导入模块: from newebe.apps.contacts.models import ContactManager [as 别名]
# 或者: from newebe.apps.contacts.models.ContactManager import getContact [as 别名]
def get_contact_with_slug(step, slug):
    world.contact = ContactManager.getContact(slug)
开发者ID:mpmedia,项目名称:newebe,代码行数:4,代码来源:steps.py


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