Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Django - 3 - Sessions (Life Pro Tips)

A single cumulative Django project (turn-in directory ex/) implementing the whole "Sessions" day, ex00 → ex06. Each exercise builds on the previous one, so the final project is the most advanced state and covers all of them.

Map

module map

Generated with lsphere.

Stack

  • Python 3 / Django 5.2 LTS
  • django-bootstrap5 for form rendering and styling
  • SQLite database
  • Custom user model tips.User (set from the start so AUTH_USER_MODEL is correct before the first migration)

Run

docker compose up --build
# open http://localhost:8000

The container runs entrypoint.sh, which builds and applies migrations and creates a default superuser admin / adminadmin for the admin interface.

Useful commands:

docker compose exec web python ex/manage.py createsuperuser
docker compose exec web python ex/manage.py shell

What each exercise maps to

  • ex00 – Anonymous sessions: tips/context_processors.py:anonymous_name picks one of settings.RANDOM_NAMES (10 names), stored in the session with a settings.RANDOM_NAME_VALIDITY (42 s) expiry. Computed and shown within the same request, so it appears instantly. Displayed in the <nav> as "Hello !".
  • ex01 – User creation: RegisterForm (username + 2 password fields, validates uniqueness and matching passwords) and LoginForm (AuthenticationForm). Logged-in users are redirected away from the register/login pages; nav swaps to the username + a logout link.
  • ex02 – Tips: Tip model (content, author, date) and the TipForm ModelForm, shown on the homepage only to logged-in users.
  • ex03 – Votes: Tip.upvotes / Tip.downvotes ManyToMany fields (no counters). Voting toggles, is mutually exclusive, and each action reloads the page (POST → redirect). Counts derived from the relations.
  • ex04 – Authorizations (delete): uses the default tips.delete_tip permission; the admin interface is enabled. The tip's author is always allowed (the only exception).
  • ex05 – Personalized authorization (downvote): custom permission tips.can_downvote (declared in Tip.Meta.permissions) restrains downvoting; authors can always downvote their own tips.
  • ex06 – Reputation: the custom User exposes a reputation property computed from the votes on the user's tips (+5 per upvote, −2 per downvote; deleting a tip removes its influence automatically). can_downvote() unlocks at 15 rep and can_delete_tips() at 30 rep (also satisfied by the permissions above / superuser). The username is shown with its reputation in brackets, e.g. alice [15].

Note

Migrations and db.sqlite3 are git-ignored and regenerated on container start, as the evaluation does.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages