Example #1
0
def conversations():
    form = ConversationListForm(request)
    if not form.validate():
        return json({
            'message': 'Validation Failed',
            'errors': form.errors
        }, 422)

    total = Conversation.countAll(order_by=form.order,
                                  location=form.location,
                                  radius=form.radius,
                                  after=form.after)
    pg = paginate(form, total)

    if total > 0:
        if pg.page_valid:
            data = Conversation.findAll(order_by=form.order,
                                        location=form.location,
                                        radius=form.radius,
                                        offset=pg.offset,
                                        limit=pg.per_page,
                                        after=form.after)
        else:
            return json({'message': "Invalid interest or end of page list"},
                        404)
    else:
        data = []

    return json(dict(conversations=data, **pg.info))
Example #2
0
def list_replies(interest_id, id):
    form = ConversationRepliesForm(request,
                                   url={
                                       'interest_id': interest_id,
                                       'id': id
                                   })
    if not form.validate():
        return json({
            'message': 'Validation Failed',
            'errors': form.errors
        }, 422)

    total = Conversation.countReplies(form.interest_id, form.id, form.after)
    pg = paginate(form, total)

    if total > 0:
        if pg.page_valid:
            data = Conversation.replies(form.interest_id, form.id, form.after,
                                        pg.offset, pg.per_page)
        else:
            return json({'message': "Invalid interest or end of page list"},
                        404)
    else:
        data = []

    return json(dict(replies=data, **pg.info))
Example #3
0
def followers(id):
    form = InterestFollowersForm(request, url={'id': id})
    if not form.validate():
        return json({'message': 'Validation Failed', 'errors': form.errors}, 422)

    total = Interest.countFollowers(form.id)
    pg = paginate(form, total)

    if total > 0:
        if pg.page_valid:
            data = Interest.followers(form.id, pg.offset, pg.per_page)
        else:
            return json({'message': "This is the end of the list"}, 404)
    else:
        data = []

    return json(dict(followers=data, **pg.info))
Example #4
0
def show_conversations():
    form = UserActivityForm(request)
    if not form.validate():
        return json({'message': 'Validation Failed', 'errors': form.errors}, 422)

    user_id = app.auth.user.id
    total = Conversation.countAllBySubscription(user_id, form.after)
    pg = paginate(form, total)

    if total > 0:
        if pg.page_valid:
            data = Conversation.findAllBySubscription(user_id, pg.offset, pg.per_page, form.after)
        else:
            return json({'message': "This is the end of the list"}, 404)
    else:
        data = []

    return json(dict(conversations=data, **pg.info))
Example #5
0
def show_interests():
    form = UserListForm(request)
    if not form.validate():
        return json({'message': 'Validation Failed', 'errors': form.errors}, 422)

    user = app.auth.user
    total = Interest.countAllByUser(user.id)
    pg = paginate(form, total)

    if total > 0:
        if pg.page_valid:
            data = Interest.findAllByUser(user.id, pg.offset, pg.per_page)
        else:
            return json({'message': "This is the end of the list"}, 404)
    else:
        data = []

    return json(dict(interests=data, **pg.info))
Example #6
0
def list_replies(interest_id, id):
    form = ConversationRepliesForm(request, url={'interest_id':interest_id, 'id':id})
    if not form.validate():
        return json({'message': 'Validation Failed', 'errors': form.errors}, 422)

    total = Conversation.countReplies(form.interest_id, form.id, form.after)
    pg = paginate(form, total)

    if total > 0:
        if pg.page_valid:
            data = Conversation.replies(form.interest_id, form.id, form.after,
                                        pg.offset, pg.per_page)
        else:
            return json({'message': "Invalid interest or end of page list"}, 404)
    else:
        data = []

    return json(dict(replies=data, **pg.info))
Example #7
0
def index():
    form = InterestIndexForm(request)
    if not form.validate():
        return json({'message': 'Validation Failed', 'errors': form.errors}, 422)

    total = Interest.countAll(form.location, form.radius)
    pg = paginate(form, total)

    if total > 0:
        if pg.page_valid:
            data = Interest.findAll(form.order, form.location, form.radius, pg.offset,
                                    pg.per_page, app.auth.user.id)
        else:
            return json({'message': "This is the end of the list"}, 404)
    else:
        data = []

    return json(dict(interests=data, **pg.info))
Example #8
0
def index(interest_id):
    form = ConversationIndexForm(request, url={'interest_id': interest_id})
    if not form.validate():
        return json({'message': 'Validation Failed', 'errors': form.errors}, 422)

    total = Conversation.countAll(form.interest_id, form.order, form.location,
                                  form.radius, None, form.after)
    pg = paginate(form, total)

    if total > 0:
        if pg.page_valid:
            data = Conversation.findAll(form.interest_id, form.order, form.location,
                                        form.radius, pg.offset, pg.per_page, None, form.after)
        else:
            return json({'message': "Invalid interest or end of page list"}, 404)
    else:
        data = []

    return json(dict(conversations=data, **pg.info))
Example #9
0
def show_user_conversations(name):
    form = UserNameListForm(request, url={'name': name})
    if not form.validate():
        return json({'message': 'Validation Failed', 'errors': form.errors}, 422)

    if not User.nameExists(form.name):
        return json({'message': 'User with given name not found'}, 404)

    total = Conversation.countAllByUserName(form.name)
    pg = paginate(form, total)

    if total > 0:
        if pg.page_valid:
            data = Conversation.findAllByUserName(form.name, pg.offset, pg.per_page)
        else:
            return json({'message': "This is the end of the list"}, 404)
    else:
        data = []

    return json(dict(conversations=data, **pg.info))
Example #10
0
def conversations():
    form = ConversationListForm(request)
    if not form.validate():
        return json({'message': 'Validation Failed', 'errors': form.errors}, 422)

    total = Conversation.countAll(order_by=form.order, location=form.location,
                                  radius=form.radius, after=form.after)
    pg = paginate(form, total)

    if total > 0:
        if pg.page_valid:
            data = Conversation.findAll(order_by=form.order, location=form.location,
                                        radius=form.radius, offset=pg.offset,
                                        limit=pg.per_page, after=form.after)
        else:
            return json({'message': "Invalid interest or end of page list"}, 404)
    else:
        data = []

    return json(dict(conversations=data, **pg.info))
Example #11
0
def followers(id):
    form = InterestFollowersForm(request, url={'id': id})
    if not form.validate():
        return json({
            'message': 'Validation Failed',
            'errors': form.errors
        }, 422)

    total = Interest.countFollowers(form.id)
    pg = paginate(form, total)

    if total > 0:
        if pg.page_valid:
            data = Interest.followers(form.id, pg.offset, pg.per_page)
        else:
            return json({'message': "This is the end of the list"}, 404)
    else:
        data = []

    return json(dict(followers=data, **pg.info))
Example #12
0
def show_conversations():
    form = UserListForm(request)
    if not form.validate():
        return json({
            'message': 'Validation Failed',
            'errors': form.errors
        }, 422)

    user = app.auth.user
    total = Conversation.countAllByUser(user.id)
    pg = paginate(form, total)

    if total > 0:
        if pg.page_valid:
            data = Conversation.findAllByUser(user.id, pg.offset, pg.per_page)
        else:
            return json({'message': "This is the end of the list"}, 404)
    else:
        data = []

    return json(dict(conversations=data, **pg.info))
Example #13
0
def index():
    form = InterestIndexForm(request)
    if not form.validate():
        return json({
            'message': 'Validation Failed',
            'errors': form.errors
        }, 422)

    total = Interest.countAll(form.location, form.radius)
    pg = paginate(form, total)

    if total > 0:
        if pg.page_valid:
            data = Interest.findAll(form.order, form.location, form.radius,
                                    pg.offset, pg.per_page, app.auth.user.id)
        else:
            return json({'message': "This is the end of the list"}, 404)
    else:
        data = []

    return json(dict(interests=data, **pg.info))
Example #14
0
def show_user_interests(name):
    form = UserNameListForm(request, url={'name': name})
    if not form.validate():
        return json({
            'message': 'Validation Failed',
            'errors': form.errors
        }, 422)

    if not User.nameExists(form.name):
        return json({'message': 'User with given name not found'}, 404)

    total = Interest.countAllByUserName(form.name)
    pg = paginate(form, total)

    if total > 0:
        if pg.page_valid:
            data = Interest.findAllByUserName(form.name, pg.offset,
                                              pg.per_page)
        else:
            return json({'message': "This is the end of the list"}, 404)
    else:
        data = []

    return json(dict(interests=data, **pg.info))
Example #15
0
def index(interest_id):
    form = ConversationIndexForm(request, url={'interest_id': interest_id})
    if not form.validate():
        return json({
            'message': 'Validation Failed',
            'errors': form.errors
        }, 422)

    total = Conversation.countAll(form.interest_id, form.order, form.location,
                                  form.radius, None, form.after)
    pg = paginate(form, total)

    if total > 0:
        if pg.page_valid:
            data = Conversation.findAll(form.interest_id, form.order,
                                        form.location, form.radius, pg.offset,
                                        pg.per_page, None, form.after)
        else:
            return json({'message': "Invalid interest or end of page list"},
                        404)
    else:
        data = []

    return json(dict(conversations=data, **pg.info))