Its time to put your newly acquired Flask skills to use! Your next big task will be to implement a crowdsourced Q&A site, like Stack Overflow.
The initial version of the site should be able to handle questions and answers, there is no need for other functionality like user management or comments for questions/answers.
The management was very interested in the agile development methodologies that they just recently hear about, thus they are handing out a prioritized list of user stories called a product backlog. Try to estimate how many of these stories your team can finish until the demo. As the order is important, you should choose from the beginning of the list as much as you can, the first four stories are the most important.
- create a Flask project
- use routes with Flask
- use HTML and the Jinja templating engine
- CSV handling
-
Implement the
/listpage that displays all questions.- The page is available under
/list - Load and display the data from
question.csv - Sort the questions by the latest question on top
- The page is available under
-
Create the
/question/<question_id>page that displays a question and the answers for it.- The page is available under
/question/<question_id> - There are links to the question pages from the list page
- The page displays the question title and message
- The page displays all the answers to a question
- The page is available under
-
Implement a form that allows you to add a question.
- There is an
/add-questionpage with a form - The page is linked from the list page
- There is a POST form with at least
titleandmessagefields - After submitting, you are redirected to "Display a question" page of this new question
- There is an
-
Implement posting a new answer.
- The page URL is
/question/<question_id>/new-answer - The question detail page links to this page
- The page has a POST form with a form field called
message - Posting an answer redirects you back to the question detail page, and the new answer is there
- The page URL is
-
Implement sorting for the question list.
- The question list can be sorted by title, submission time, message, number of views, and number of votes
- You can choose the direction: ascending or descending
- The order is passed as query string parameters, for example
/list?order_by=title&order_direction=desc
-
Implement deleting a question.
- Deleting is implemented by the
/question/<question_id>/deleteendpoint - There should be a deletion link on the question page
- Deleting redirects you back to the list of questions
- Deleting is implemented by the
-
Allow the user to upload an image for a question or answer.
- The forms for adding question and answer contain an "image" file field
- You can attach an image (.jpg, .png)
- The image is saved on server and displayed next to question / answer
- When you delete the question / answer, the file gets deleted as well
-
Implement editing an existing question.
- There is a
/question/<question_id>/editpage - The page is linked from the question's page
- There is a POST form with at least
titleandmessagefields - The fields are pre-filled with existing question's data
- After submitting, you are redirected back to "Display a question" page and you see the changed data
- There is a
-
Implement deleting an answer.
- Deleting is implemented by
/answer/<answer_id>/deleteendpoint - There should be a deletion link on the question page, next to an answer
- Deleting redirects you back to the question detail page
- Deleting is implemented by
-
Implement voting on questions.
- Vote numbers are displayed next to questions on the question list page
- There are "vote up/down" links next to questions on the question list page
- Voting uses
/question/<question_id>/vote_upand/question/<question_id>/vote_downendpoints - Voting up increases, voting down decreases the
vote_numberof the question by one - Voting redirects you back to the question list
-
Implement voting on answers.
- Vote numbers are displayed next to answers on the question detail page
- There are "vote up/down" links next to answers
- Voting uses
/answer/<answer_id>/vote_upand/answer/<answer_id>/vote_downendpoints - Voting up increases, voting down decreases the
vote_numberof the answer by one - Voting redirects you back to the question detail page
- All data should be persisted to
.csvfiles. You will need aquestions.csvfor storing all questions and ananswers.csvfor storing all answers.
We recommend that you split the code into modules according to clean code principles: Do not put more than 100-150 lines of code into a single file, files should contain logically the same things, etc.
For example, you could split it up to these 3+1 parts:
| Layer | Example filename | What should it do/contain? |
|---|---|---|
| Routing layer | server.py |
Flask stuff (server, routes, request handling, session, etc.) This layer should consist of logic that is related to Flask. (with other words: this should be the only file importing from Flask) |
| Persistence layer | data_manager.py |
Layer between the server and the data. Functions here should be called from the server.py and these should use generic functions from the connection.py |
| CSV (later SQL) connection layer | `connection.py | Common functions to read/write/append CSV files without feature specific knowledge. The layer that have access to any kind of long term data storage. In this case, we use CSV files, but later on we'll change this to SQL database. |
| Utility "layer" | util.py | Helper functions which can be called from any other layer. (but mainly from the business logic layer) |
This is just one way to structure your code, you don't have to follow it strictly.
In the sample_data folder you'll see two sample files for questions and answers.
These look like the following (you can ignore data in the not implemented fields):
question.csv
id: A unique identifier for the question
submission_time: The UNIX timestamp when the question was posted
view_number: How many times this question was displayed in the single question view
vote_number: The sum of votes this question has received
title: The title of the question
message: The question text
image: The path to the image for this question
answer.csv
id: A unique identifier for the answer
submission_time: The UNIX timestamp when the answer was posted
vote_number: The sum of votes this answer has received
question_id: The id of the question this answer belongs to.
message: The answer text
image: the path to the image for this answer