def index(): if request_wants_html(): return render_template('index.html') else: return Response(response=json.dumps("Welcome to reddit clone app!"), status=200, mimetype='application/json')
def home(): topics = get_top_topics() if request_wants_html(): return render_template('home.html', topics=topics) else: return success_list_response(topics)
def get_all_topics(): '''Return all the topics''' topics = datastore.get_all_topics() if request_wants_html(): return topics else: return success_list_response(topics)
def get_topic(topic_id): '''Get topic by topic_id''' topic = datastore.get_topic(topic_id) if request_wants_html(): return topic else: if not topic: return not_found(error_message.TOPIC_DOES_NOT_EXIST%topic_id) return success_dict_response(topic)
def signup(): if request_wants_html(): form = UserForm(request.form) if request.method == 'POST' and form.validate(): new_user = user.create_user_html(form) return render_template("user_created.html", user=new_user) return render_template('signup.html', form=form) else: return user.create_user_json(request)
def upvote(topic_id): if request_wants_html(): if not is_authenticated(): return redirect(url_for('login')) if request.method == 'GET': response = create_upvote_html(topic_id) return redirect(url_for('get_topic', topic_id=topic_id)) else: if request.method == 'POST': response = create_upvote_json(request.json, topic_id) return response
def create_topic(): if request_wants_html(): if not is_authenticated(): return redirect(url_for('login')) form = TopicForm(request.form) if request.method == 'POST' and form.validate(): new_topic = topic.create_topic_html(form) return render_template("topic_created.html", topic=new_topic) return render_template('topic.html', form=form) else: if request.method == 'POST': return topic.create_topic_json(request.json)
def all_topics(): response = topic.get_all_topics() if request_wants_html(): return render_template('all_topics.html', topics=response) else: return response
def get_topic(topic_id): response = topic.get_topic(topic_id) if request_wants_html(): return render_template('single_topic.html', topic=response) else: return response