def create(interest_id):
    form = ConversationCreateForm(request, url={'interest_id': interest_id})
    if not form.validate():
        return json({'message': 'Validation Failed', 'errors': form.errors}, 422)

    data = Conversation.create(Conversation.parse(form.data, user_id=app.auth.user.id))
    if data is False:
        return json({'message': 'An error ocurred while creating the conversation'}, 400)

    return json(data, 201)
Exemple #2
0
    def testCreate(self):
        # create without location data
        obj = Conversation.parse({
                'interest_id' : 1,
                'user_id'                       : 1,
                'message'                       : "Hello there, this is just a test, ok?"
        })
        obj = Conversation.create(obj)
        self.assertTrue(is_integer(obj.id))

        # create a reply to the conversation above
        obj2 = Conversation.parse({
                'interest_id'   : 1,
                'user_id'                       : 2,
                'message'                       : "And this is a reply.",
                'lat'                                   : -27.8738,
                'lon'                                   : -54.4761,
                'parent_id'             : obj.id
        })
        obj2 = Conversation.create(obj2)
        self.assertTrue(is_integer(obj2.id))
def create(interest_id):
    form = ConversationCreateForm(request, url={'interest_id': interest_id})
    if not form.validate():
        return json({
            'message': 'Validation Failed',
            'errors': form.errors
        }, 422)

    data = Conversation.create(
        Conversation.parse(form.data, user_id=app.auth.user.id))
    if data is False:
        return json(
            {'message': 'An error ocurred while creating the conversation'},
            400)

    return json(data, 201)