This repository contains the solution for a particular challenge using Python + Flask to create a web platform with several functionalities.
The whole challenge specs could be listed as follows:
- Create a new Python project using Flask 1.1.x.1
- Create a
Usermodel with properties:Integer ID PK(self-increasing)String Name (30)String First_Last_Name (30)String Second_Last_Name (30)(optional)String Email (80)DateTime BirthDateString Gender(AcceptsM,F,O)String Password(Must be encrypted)
- Create needed methods for CRUD operations in the user model, using REST.2
- CREATE
- READ
- UPDATE
- DELETE
- Create a login view with route
'/login'asking forEmailandPassword(this field must have a mask). In case of correct login, the app must generate a session for the user.- Login view
- Generate a session
- Create a view with route
'/users'which should show a table with all registered users. It must contain an action button to delete the user, and a column with an icon for the gender. - Create a view with route
'/users?filter={name}'(namecould be only text), which must show a table with registered users whose full name includes the sent characters by thenameparameter. - Create a view with route
'/user/{id}'(idcould be only a number), which should show the detailed user corresponding to theidvariable, in case it exists. Otherwise, return a404screen for that route.3 - Create a
Rolemodel with properties:Integer ID PK(self-increasing)String Name (30)String Description (20)(optional)
- Create two roles,
AdministratorandClient, directly in the database.4 - Add relation of
UserwithRole1-1. - Create view of creation/edition of a user. The user could only access this view if the user is logged in and the user session must be validated.
- Date must be in format
DD/MM/YYY. - The name must appear concatenated as follows:
{ Name } { First_Last_Name } { Second_Last_Name }. - The gender option must show the tags
MaleforM,FemaleforFandOtherforO(must use filter tag). - If the logged user has type
Administrator, the user should be able to see a button to delete the user.
In this section I'll list all the additional features developed in the project.
- 1 The project has been Dockerized. To test the utility files with Docker up, you must change the base url from
http://0.0.0.0:5000/<endpoint>tohttp://localhost:5000/<endpoint>and so on. - 2 An extra script (
crud_utils.py) has been added. It uses therequestsmodule to test CRUD via REST. To use the script and test CRUD, while the app is up and running, simply run:This will create a sample table in the database.(docker-flask)$ python crud_utils.py
- 3 For each query, a variable named
usernamehas been added, which contains the concatenated name. - 4 An extra script (
roles_utils.py) has been added. This directly writes theAdministratorandClientroles to the database. To use the script, while the app is up and running, simply execute:This will create two roles in the database.(docker-flask)$ python roles_utils.py
- Since the 1-1 relationship has not been specified in more detail, the code for this section has been added, but it has been commented to avoid any possible malfunction inside the code. You can find this in the
models.pyscript (lines 15 and 24). - NOT A SINGLE LINTER HAS BEEN USED. All the code structure is mainly based on my own practices trying to follow Python's philosophy.
- THE WHOLE CODE HAS BEEN DEVELOPED USING ONLY ATOM, without any packages nor extra tools that may help during the development.
- Since I'm the only developer for this project, ANY OTHER POSSIBLE BRANCHES WERE NOT CREATED. It is recommended to work using branches, but for this particular exercise I preferred to work directly (and only) with the
masterbranch, as I wanted to finish the challenge ASAP.
Before you begin, ensure you have met the following requirements:
- You have a Windows/Linux/Mac machine with the latest version of Docker installed.
- You have a Windows/Linux/Mac machine running Python 3.6+.
- You have installed the latest versions of
pipandvirtualenvorconda(Anaconda).
For general purposes, why not installing prerequisites for both cases?
If you want to install the dependencies and work locally using only Python, you can simply follow this steps. If you want to directly work using Docker, jump to the "Install/Run with Docker" section.
Clone the project repository:
git clone https://github.com/RodolfoFerro/technical-test-w-flask.git
cd technical-test-w-flaskTo create and activate the virtual environment, follow these steps:
Using conda:
$ conda create -n docker-flask python=3.7
# Activate the virtual environment:
$ conda activate docker-flask
# To deactivate:
(docker-flask)$ conda deactivateUsing virtualenv:
# In this case I'm supposing that your latest python3 version is +3.6
$ virtualenv docker-flask --python=python3
# Activate the virtual environment:
$ source docker-flask/bin/activate
# To deactivate:
(docker-flask)$ deactivateTo install the requirements using pip, once the virtual environment is active:
(docker-flask)$ pip install -r requirements.txtFinally, if you want to run the app locally, simply run:
(docker-flask)$ python app.pyNow you should be able to test the API at http://0.0.0.0:5000/.
If you want to install the dependencies and work using Docker, you can simply follow this steps. If you want to simply work locally using only Python, jump back to the "Install/Run with only Python" section.
Clone the project repository:
git clone https://github.com/RodolfoFerro/technical-test-w-flask.git
cd technical-test-w-flaskTo build the Docker image, simply run:
$ docker build -t technical-test-w-flask .To run the Docker image, run the following:
$ docker run -it -d -p 5000:5000 -v $(pwd):/app technical-test-w-flaskNow you should be able to test the API at http://localhost:5000/.
To stop the Docker container:
$ docker ps
$ docker stop <container-id>If you want to contact me you can reach me at rodolfoferroperez@gmail.com. There, or through any other of my social profiles your can find at: https://rodolfoferro.glitch.me/
This project uses an MIT License.