Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
run: ## Run the test server.
python manage.py runserver_plus

test: ## Run unittests.
python manage.py test

makemigrations: ## Create migration files
python manage.py makemigrations

migrate: ## Run new migrations
python manage.py migrate

install: ## Install the python requirements.
pip install -r requirements.txt

install-dev: ## Install the python requirements as well as some dev specific ones.
pip install -r requirements-dev.txt

lint: ## Run code linter and formatter
black . -S
flake8 .
41 changes: 41 additions & 0 deletions docs/DATAMODEL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Complete data model of the travel app

```mermaid
erDiagram
User||--o{ StartBusStop: waits
User||--o| Driver: is
User {
Charfield username
}
Driver {
}
Bus {
CharField licence_plate
}
Place||--o{ BusStop: stops
Place {
CharField name
DecimalField longitude
DecimalField latitude
}
BusStop}|--|{ StartBusStop: inherits
BusStop}|--|{ EndBusStop: inherits
BusStop{
DateField ts_create
DateField ts_update
DateField ts_requested
DateField ts_estimated
DateField ts_boarded
BooleanField has_boarded
}
StartBusStop||--o| EndBusStop: travels
StartBusStop {
}
EndBusStop {
}
BusShift}o--|| Driver: drives
BusShift}o--|| Bus: books
BusShift|o--|{ EndBusStop: stops
BusShift {
}
```
18 changes: 18 additions & 0 deletions padam_django/apps/common/fields.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from django.db import models


class TsCreateField(models.DateTimeField):
def __init__(self, *args, **kwargs):
kwargs.setdefault("auto_now_add", True)
kwargs.setdefault("auto_now", False)
kwargs.setdefault("verbose_name", "Creation date")
kwargs.setdefault("help_text", "Date at which the object was created.")
super().__init__(*args, **kwargs)


class TsUpdateField(models.DateTimeField):
def __init__(self, *args, **kwargs):
kwargs.setdefault("auto_now", True)
kwargs.setdefault("verbose_name", "Last update date")
kwargs.setdefault("help_text", "Date at which the object was updated.")
super().__init__(*args, **kwargs)
1 change: 0 additions & 1 deletion padam_django/apps/common/management/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@


class CreateDataBaseCommand(BaseCommand):

def __init__(self, *args, **kwargs):
self.number = None
super().__init__(*args, **kwargs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Command(BaseCommand):

help = 'Create test data'

def handle(self, *args, **options):
Expand Down
10 changes: 10 additions & 0 deletions padam_django/apps/common/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from django.db import models
from .fields import TsCreateField, TsUpdateField


class TsCreateUpdateMixin(models.Model):
ts_create = TsCreateField()
ts_update = TsUpdateField()

class Meta:
abstract = True
12 changes: 12 additions & 0 deletions padam_django/apps/common/validators.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import datetime

from django.core.exceptions import ValidationError


def validate_future_date(value: datetime.datetime):
now = datetime.datetime.now(tz=datetime.timezone.utc)
if value < now:
raise ValidationError(
"%(value)s is set before the current date %(now)s",
params={"value": value.isoformat(), "now": now.isoformat()},
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Command(CreateDataBaseCommand):

help = 'Create few buses'

def handle(self, *args, **options):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Command(CreateDataBaseCommand):

help = 'Create few drivers'

def handle(self, *args, **options):
Expand Down
34 changes: 29 additions & 5 deletions padam_django/apps/fleet/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@


class Migration(migrations.Migration):

initial = True

dependencies = [
Expand All @@ -17,8 +16,19 @@ class Migration(migrations.Migration):
migrations.CreateModel(
name='Bus',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('licence_place', models.CharField(max_length=10, verbose_name='Name of the bus')),
(
'id',
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name='ID',
),
),
(
'licence_place',
models.CharField(max_length=10, verbose_name='Name of the bus'),
),
],
options={
'verbose_name_plural': 'Buses',
Expand All @@ -27,8 +37,22 @@ class Migration(migrations.Migration):
migrations.CreateModel(
name='Driver',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
(
'id',
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name='ID',
),
),
(
'user',
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to=settings.AUTH_USER_MODEL,
),
),
],
),
]
7 changes: 5 additions & 2 deletions padam_django/apps/fleet/migrations/0002_auto_20211109_1456.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('fleet', '0001_initial'),
Expand All @@ -21,6 +20,10 @@ class Migration(migrations.Migration):
migrations.AlterField(
model_name='driver',
name='user',
field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='driver', to=settings.AUTH_USER_MODEL),
field=models.OneToOneField(
on_delete=django.db.models.deletion.CASCADE,
related_name='driver',
to=settings.AUTH_USER_MODEL,
),
),
]
4 changes: 3 additions & 1 deletion padam_django/apps/fleet/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@


class Driver(models.Model):
user = models.OneToOneField('users.User', on_delete=models.CASCADE, related_name='driver')
user = models.OneToOneField(
'users.User', on_delete=models.CASCADE, related_name='driver'
)

def __str__(self):
return f"Driver: {self.user.username} (id: {self.pk})"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class Command(CreateDataBaseCommand):

help = 'Create few places'

def handle(self, *args, **options):
Expand Down
33 changes: 26 additions & 7 deletions padam_django/apps/geography/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,39 @@


class Migration(migrations.Migration):

initial = True

dependencies = [
]
dependencies = []

operations = [
migrations.CreateModel(
name='Place',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=50, verbose_name='Name of the place')),
('longitude', models.DecimalField(decimal_places=6, max_digits=9, verbose_name='Longitude')),
('latitude', models.DecimalField(decimal_places=6, max_digits=9, verbose_name='Latitude')),
(
'id',
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name='ID',
),
),
(
'name',
models.CharField(max_length=50, verbose_name='Name of the place'),
),
(
'longitude',
models.DecimalField(
decimal_places=6, max_digits=9, verbose_name='Longitude'
),
),
(
'latitude',
models.DecimalField(
decimal_places=6, max_digits=9, verbose_name='Latitude'
),
),
],
options={
'unique_together': {('longitude', 'latitude')},
Expand Down
2 changes: 1 addition & 1 deletion padam_django/apps/geography/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Place(models.Model):

class Meta:
# Two places cannot be located at the same coordinates.
unique_together = (("longitude", "latitude"), )
unique_together = (("longitude", "latitude"),)

def __str__(self):
return f"Place: {self.name} (id: {self.pk})"
Empty file.
Loading