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))
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))
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))
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))
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))
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))
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))
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))
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))
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))
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))
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))
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))
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))
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))