Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
6ad7050
Add Dockerfile for containerized application setup
Dec 7, 2025
2249dd5
Add docker-compose.yml for application services setup
Dec 7, 2025
c16ecd3
Refactor settings.py for PostgreSQL database configuration and add st…
Dec 7, 2025
5267701
Add entrypoint script for application initialization and setup
Dec 7, 2025
9ca5e37
Implement BusShift and BusStop admin interfaces with automatic shift …
Dec 7, 2025
ca522cc
Add initial migration for BusShift and BusStop models with constraints
Dec 7, 2025
d856773
Refactor imports and formatting in management commands and models; ad…
Dec 7, 2025
a1e46d7
Implement update_shift_times function for BusShift to calculate start…
Dec 7, 2025
6d22bea
Add TripsConfig class for transport app configuration
Dec 7, 2025
0451b55
Add BusShiftForm for managing bus shift data with validation for stops
Dec 7, 2025
e4ed105
Add BusShift and BusStop models for managing bus shifts and stops wit…
Dec 7, 2025
392e9c3
Add a blank line for improved readability in UserAdmin class
Dec 7, 2025
87edbd3
Add a blank line for improved readability in User model
Dec 7, 2025
78f8f2e
Fix missing newline at end of file in Dockerfile and entrypoint.sh
Dec 7, 2025
12d268f
Add .dockerignore and update .gitignore for improved file management
Dec 7, 2025
80e1e4c
Update requirements.txt to include additional dependencies for Django…
Dec 7, 2025
a411fe0
Add pre-commit configuration and update linting tools in requirements
Dec 7, 2025
45fb864
Add management command to create a test user with a known password
Dec 7, 2025
f08cd83
Add management command to update non-driver users with BusShift permi…
Dec 7, 2025
ee8c008
Add README_SOLUTION.md with Docker setup and management commands
Dec 7, 2025
48a3557
Refactor Makefile to include Docker commands for container management…
Dec 7, 2025
0623154
Add unit tests for BusShift update_shift_times functionality
Dec 7, 2025
55acb06
Remove unused BusShift model retrieval from update_non_drivers manage…
Dec 7, 2025
ce40aa6
Update README_SOLUTION.md to enhance Docker setup instructions and ad…
Dec 7, 2025
62c0c5a
Update requirements.txt to include necessary dependencies for testing
Dec 7, 2025
d86f93a
Clean up Makefile by removing commented-out docker-run target and fix…
Dec 7, 2025
d951f1b
Add .env file with environment configuration for development
Dec 7, 2025
1d700d5
Update README_SOLUTION.md to modify test user details and reorder com…
Dec 8, 2025
84250ee
Update create_test_user.py to change test username to 'andreechretien'
Dec 8, 2025
1e3e756
Add development tools section to README_SOLUTION.md for code quality
Dec 9, 2025
cb12679
Update README_SOLUTION.md to clarify automatic corrections in pre-com…
Dec 9, 2025
3a4ace7
Refactor BusShiftForm to remove unused BusStop import and clean metho…
Dec 9, 2025
9021c8a
Refactor BusShiftForm to remove unused methods and clean up code
Dec 10, 2025
7e26ec8
Remove unused inline_formset attribute from BusShiftForm
Dec 10, 2025
aff5efe
Refactor BusShiftAdmin to improve save_formset method documentation
Dec 10, 2025
7acab28
refactor: add transaction.atomic
Dec 10, 2025
b21fc9e
refactor: add transaction.atomic and select_for_update in update_shif…
Dec 10, 2025
524da0a
Update : tests
Dec 10, 2025
6726776
Feat: rm status filed and upply migrations
Dec 10, 2025
26f1e57
fix make target 'docker-user-test'
Dec 10, 2025
4d6abdd
fix(bus_shift_service): prevent zero-duration shifts
Dec 10, 2025
a97cac6
test(bus_shift): add test to prevent zero-duration shifts
Dec 10, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.venv
.git
.gitignore
7 changes: 7 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
DEBUG=1
DJANGO_ALLOWED_HOSTS=localhost
DB_NAME=
DB_USERNAME=
DB_PASSWORD=
DB_HOSTNAME=
DB_PORT=
138 changes: 138 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.idea/
*.iml
# Byte-compiled / optimized / DLL files
__pycache__/
.pytest_cache/
Expand All @@ -20,3 +22,139 @@ ENV/
# Editors stuff
.idea
.vscode
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments

.venv
env/
venv/
ENV/
env.bak/
venv.bak/
.venv-dev

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

/data

media/
mediafiles/
staticfiles/
40 changes: 40 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
repos:
- repo: 'https://github.com/pre-commit/pre-commit-hooks'
rev: 'v4.6.0'
hooks:
- id: 'check-yaml'
- id: 'end-of-file-fixer'
- id: 'trailing-whitespace'

- repo: 'https://github.com/psf/black'
rev: '24.3.0'
hooks:
- id: 'black'
language_version: 'python3.11'
files: '\.py$'
exclude: 'migrations/'

- repo: 'https://github.com/PyCQA/isort'
rev: '5.13.2'
hooks:
- id: 'isort'
language_version: 'python3.11'
files: '\.py$'
exclude: 'migrations/'

- repo: 'https://github.com/PyCQA/flake8'
rev: '7.0.0'
hooks:
- id: 'flake8'
language_version: 'python3.11'
files: '\.py$'
exclude: 'migrations/'

- repo: 'https://github.com/pre-commit/mirrors-pylint'
rev: 'main'
hooks:
- id: 'pylint'
language_version: 'python3.11'
files: '\.py$'
exclude: 'migrations/'
args: ['--disable=E0401']
21 changes: 21 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM python:3.11-slim

ENV PIP_DISABLE_PIP_VERSION_CHECK 1
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

WORKDIR /code

COPY ./requirements.txt .

RUN apt-get update -y && \
apt-get install -y netcat-openbsd && \
pip install --upgrade pip && \
pip install -r requirements.txt

COPY ./entrypoint.sh .
RUN chmod +x /code/entrypoint.sh

COPY . .

ENTRYPOINT ["/code/entrypoint.sh"]
38 changes: 34 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,35 @@
run: ## Run the test server.
python manage.py runserver_plus
# Start the docker containers
docker-up: ## Start the docker containers
docker-compose up --build

# Stop the docker containers
docker-down: ## Stop the docker containers
docker-compose down

# Access the web container shell
docker-sh: ## Access the docker container shell
docker exec -it padam-web sh

dokcer-migrate: ## Apply database migrations inside the container
docker exec -it padam-web python manage.py migrate

# Create a Django superuser inside the container
docker-superuser: ## Create a superuser for the Django admin
docker exec -it padam-web python manage.py createsuperuser

# Create sample data inside the container
docker-create-data: ## Create sample data
docker exec -it padam-web python manage.py create_data

# Assign permissions to non-driver users inside the container
docker-assign-perms: ## Make non-driver users staff and assign BusShift & BusStop permissions
docker exec -it padam-web python manage.py update_non_drivers

# Assign permissions to non-driver users inside the container
docker-user-test: ##
docker exec -it padam-web python manage.py create_test_user

# Run tests inside the container
docker-test: ## Run tests inside the container
docker exec -it padam-web python manage.py test

install: ## Install the python requirements.
pip install -r requirements.txt
114 changes: 114 additions & 0 deletions README_SOLUTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# Solution: Lancer et tester le projet Django avec Docker

## Table des matières

1. [Lancer le projet avec Docker et Makefile](#lancer-le-projet-avec-docker-et-makefile)
2. [Management commands utiles](#management-commands-utiles)
3. [Tests unitaires](#tests-unitaires)
4. [Remarques](#remarques-importantes)
5. [Résumé des workflows](#résumé-des-workflows)
6. [Outils de développement](#outils-de-développement)


---

## 1. Lancer le projet avec Docker et Makefile

Le projet est configuré pour s’exécuter avec **Docker** et une base **PostgreSQL**.
Des scripts `Makefile` facilitent les opérations courantes pour le développement et les tests.

### Commandes à exécuter:

1 - **Démarrer les conteneurs Docker**
`make docker-up`

2 - **Accéder à l’interface Django admin**
[Django admin](http://127.0.0.1:8001/admin)

3 - **Créer des données d’exemple**
`make docker-create-data`

4 - **Créer un superutilisateur Django**
`make docker-superuser`

5 - **Update un utilisateur de test**
`make docker-user-test`

6 - **Assigner les permissions aux utilisateurs non-driver**
`make docker-assign-perms`

7 - **Se connecter avec l’utilisateur de test** :

- `username = "andreechretien"`
- `password = "test12356"`

8 - **Faire les tests sur l'interface admin Django `Add bus shift`**

9 - **Exécuter les tests unitaires**
`make docker-test`

---

## 2. Management commands utiles

- **Arrêter les conteneurs Docker**
`make docker-down`

- **Accéder au shell du conteneur web**
`make docker-sh`

- **Appliquer les migrations de la base de données**
`make docker-migrate`

---

## 3. Tests unitaires

- Les tests sont contenus dans `test_bus_shift_service.py`.
- Ils couvrent la validation métier et la logique de calcul des temps pour BusShift et BusStop.
- Les tests sont isolés et utilisent `setUp` pour créer des entités réutilisables (Bus, Driver, Place).
- Représente un exemple clair de tests unitaires pour un service métier.

---

## 4. Remarques

### create_test_user.py

- Permet de créer ou modifier le mot de passe d’un utilisateur de test.
- Utilisation: choisir un utilisateur de la base de donnée **non driver** par exemple :
- `username = "andreechretien"`
- `password = "test12356"`

---

## 5. Résumé des workflows

1. Démarrer les conteneurs Docker → `make docker-up`
2. Créer les données et superutilisateur → `make docker-create-data` + `make docker-superuser`
3. Assigner les permissions → `make docker-assign-perms`
4. Créer et utiliser l’utilisateur de test
5. Exécuter les tests → `make docker-test`
6. Accéder à l’admin Django → [Django admin](http://127.0.0.1:8001/admin)

---

# 6 Outils de développement : formatage et linting

Le projet inclut des outils pour garantir la qualité et la cohérence du code :

- **black** : formatage automatique du code Python
- **isort** : tri cohérent des imports
- **flake8** : vérification du style et détection d’erreurs courantes
- **pre-commit** : exécution automatique des hooks avant chaque commit

## Installation

```bash
pip install -r dev-requirements.txt
pre-commit install
```

## Utilisation
- Chaque commit exécutera automatiquement les outils configurés dans .pre-commit-config.yaml.
- Les corrections automatiques seront appliquées.
5 changes: 5 additions & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Outils de formatage et linting
black==24.3.0
flake8==7.0.0
isort==5.13.2
pre-commit
Loading