Beispiel #1
0
def create_a_default_contact(step):
    contact = Contact()
    contact.url = u"http://default:8000/"
    contact.slug = slugify(contact.url)
    contact.state = STATE_TRUSTED
    contact.description = "desc 1"
    contact.name = "default contact 1"
    contact.save()
Beispiel #2
0
def creates_contacts(step):
    contact = Contact()
    contact.url = "http://localhost/1/"
    contact.slug = slugify(contact.url)
    contact.state = STATE_PENDING
    contact.key = "key1"
    contact.save()
    contact2 = Contact()
    contact2.url = "http://localhost/2/"
    contact2.slug = slugify(contact2.url)
    contact2.state = STATE_TRUSTED
    contact2.key = "key2"
    contact2.save()
    contact3 = Contact()
    contact3.url = "http://localhost/3/"
    contact3.slug = slugify(contact3.url)
    contact3.state = STATE_WAIT_APPROVAL
    contact.key = "key3"
    contact3.save()
Beispiel #3
0
    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()

                self.return_success("Request received.")

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

        else:
            self.return_failure("Sent data are incorrects.")