Skip to content

Commit

Permalink
refactor(settings): move PPL/CPL start dates to settings ATM
Browse files Browse the repository at this point in the history
  • Loading branch information
zyv committed Nov 1, 2023
1 parent f8a0943 commit c3e60b0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
6 changes: 6 additions & 0 deletions config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"""

import os
from datetime import UTC, datetime
from pathlib import Path

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
Expand Down Expand Up @@ -133,3 +134,8 @@
INTERNAL_IPS = ["127.0.0.1"]
INSTALLED_APPS += ["debug_toolbar"]
MIDDLEWARE += ["debug_toolbar.middleware.DebugToolbarMiddleware"]


PPL_START_DATE = datetime(2021, 12, 1, 0, 0, tzinfo=UTC)
PPL_END_DATE = datetime(2022, 1, 29, 0, 0, tzinfo=UTC)
CPL_START_DATE = datetime.now(tz=UTC)
6 changes: 1 addition & 5 deletions logbook/statistics/experience.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import dataclasses
from dataclasses import dataclass
from datetime import UTC, datetime, timedelta
from datetime import timedelta
from typing import TYPE_CHECKING, Iterable, Optional

if TYPE_CHECKING:
from ..models import LogEntry

PPL_START_DATE = datetime(2021, 12, 1, 0, 0, tzinfo=UTC)
PPL_END_DATE = datetime(2022, 1, 29, 0, 0, tzinfo=UTC)
CPL_START_DATE = datetime.now(tz=UTC)


@dataclass(frozen=True, kw_only=True)
class TotalsRecord:
Expand Down
10 changes: 4 additions & 6 deletions logbook/views/experience.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
from datetime import UTC, datetime, time, timedelta

from dateutil.relativedelta import relativedelta
from django.conf import settings
from django.db.models import QuerySet
from django.utils.timezone import make_aware

from ..models import AircraftType, Certificate, FunctionType, LogEntry
from ..statistics.experience import (
CPL_START_DATE,
PPL_END_DATE,
PPL_START_DATE,
ExperienceRecord,
ExperienceRequirements,
TotalsRecord,
Expand All @@ -23,10 +21,10 @@ class ExperienceIndexView(AuthenticatedTemplateView):
template_name = "logbook/experience_list.html"

def get_context_data(self, **kwargs):
log_entries = LogEntry.objects.filter(departure_time__gte=PPL_START_DATE)
log_entries = LogEntry.objects.filter(departure_time__gte=settings.PPL_START_DATE)
return super().get_context_data(**kwargs) | {
"sep_revalidation": get_sep_revalidation_experience(log_entries),
"ppl": get_ppl_experience(log_entries.filter(departure_time__lt=PPL_END_DATE)),
"ppl": get_ppl_experience(log_entries.filter(departure_time__lt=settings.PPL_END_DATE)),
"night": get_night_experience(log_entries.filter(night=True)),
"ir": get_ir_experience(log_entries),
"cpl": get_cpl_experience(log_entries),
Expand Down Expand Up @@ -145,7 +143,7 @@ def get_cpl_experience(log_entries: QuerySet[LogEntry]) -> ExperienceRequirement
"Visual dual instruction": ExperienceRecord(
required=TotalsRecord(time=timedelta(hours=15), landings=0),
accrued=compute_totals(
log_entries.filter(time_function=FunctionType.DUAL, departure_time__gte=CPL_START_DATE),
log_entries.filter(time_function=FunctionType.DUAL, departure_time__gte=settings.CPL_START_DATE),
),
),
"Total hours": ExperienceRecord(
Expand Down

0 comments on commit c3e60b0

Please sign in to comment.