This is a simple web-based system via Django for movie/film ratings.
I suppose that python3
and Django
are available in your machine and properly configured (standard configuration).
To run this app, simply:
- Clone this repo
- Start the server: in the main folder, open a shell and type
python3 manage.py runserver
- By default, the web service will be hosted in
http://127.0.0.1:8000/
and the app can be accessed thruhttp://127.0.0.1:8000/cinema
Since this app is based on Django framwork, in this example, I consider three layers distributed in three files, each one with a responability:
urls.py
: defines the navigation rules regarding GET and POST HTTP requests.views.py
: defines the actions to take regarding urlsmethods.py
: is an additional layer for handling communication with the persistence layer (database), this employs thedjango.db
module.
In this manner, I don't mix code from the persistence layer (database access) with that from the views one, for example. Databases queries are encapsulated thru the django.db
into the methods.py
module so there are no explicit sql statements in this project. A template
folder is provided as templates of dynamical websites. Across all methods, the session
object is employed to handle sessions, and to check whether the session is active or not.`
The view define the following methods:
def index(request)
: route requests to the index page.def register_owner(request)
: allows users to register. The following validations are performed prior to any registration:
- Validate email is a valid email address.
- Validate email is not already registered in the database.
- Validate password contains at least 10 characters, one lowercase letter, one uppercase letter and one of the following characters: !, @, #, ? or ].
- If any of the above is not valid, send back a meaningful response.
def main_menu(request)
: this method validates whether a valid user tries to access the system. This is done by satisfying the following requirements:
- Validate email and password matches for a previous registered user.
- If any of the above is not valid send back a meaningful response.
- If all of the above are valid send back a payload including some way for users to identify themselves for subsequent requests. That way to identify users should be invalid after 20 minutes and the user must login again to continue communication with the server. This is done by setting the session expiration as follows:
request.session.set_expiry(1200)
(1200 seconds). At each request, the system validates whether the session is still valid. You can change this parameter value at your convenience.
def register_movie_form(request)
: routes the request towardscinema/register_movie_form.html
.def register_movie_action(request)
: register a movie in the database.def list_of_movies(request)
: employs the templatecinema/list_of_movies.html
to show all movies with the following constraints:
- Users should be able to read all public elements in the table/collection.
- Users should be able to read all elements created by themselves.
- Users should be able to edit at least one field in one of their private items. In this context, users can update the scope of their item from
public
toprivate
. Here, I employ aselect
element from HTML. - Validate that users are trying to read or update their private elements, otherwise send a meaningful response. To acomplish this, the private list is separated from the public one. The private one can be edited while the public one not.
def delete_movie_action(request, movie_id)
: this deletes a given movie_id.def update_movie_action(request, movie_id, publicp)
: this updates the scope of a movie item from public to private or vice versa.def restart_database(request)
: this function is for testing purposes; this restarts the database (delete all entries) and creates some dummy records.
The methods from the view.py
methods in the methods.py
file as follows:
views.py/methods.py | is_valid_password |
is_valid_email |
register_user |
validate_user |
validate_login |
register_movie |
get_public_movies |
get_owned_movies |
delete_movie |
update_movie |
---|---|---|---|---|---|---|---|---|---|---|
register_owner |
😊 | 😊 | 😊 | 😊 | ||||||
main_menu |
😊 | |||||||||
register_movie_action |
😊 | |||||||||
list_of_movies |
😊 | 😊 | ||||||||
delete_movie_action |
😊 | |||||||||
update_movie_action |
😊 |
Additionally, the program consider:
- A git repository with the code and a README.md explaining how to run the code in the reviewer computer with very clear steps (this one).
- Create the models for the selected topic with at least 5 meaningful fields.
- Prefill the public elements with a list you built previously. you can do this by choosing the option
Click here to populate/restart database
in the main site. - Read requests must support pagination.