Skip to content

Commit

Permalink
feat(ruff): move from black and co to ruff and fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
zyv committed Oct 29, 2023
1 parent 5366445 commit ac9f671
Show file tree
Hide file tree
Showing 8 changed files with 185 additions and 436 deletions.
28 changes: 4 additions & 24 deletions .idea/watcherTasks.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@
"""

import os
from pathlib import Path

from django.contrib.messages import constants as message_constants

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
BASE_DIR = Path(__file__).resolve().parent.parent

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/
Expand Down Expand Up @@ -99,7 +100,7 @@
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": os.path.join(BASE_DIR, "db.sqlite3"),
"NAME": BASE_DIR / "db.sqlite3",
},
}

Expand Down
2 changes: 1 addition & 1 deletion logbook/fixtures/import_aerodromes.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
def load_reference_icao_codes():
icao_codes = set()

with open("logbook/fixtures/data/airports.csv", newline="") as fp:
with Path("logbook/fixtures/data/airports.csv").open(newline="") as fp:
reader = csv.DictReader(fp)
for row in reader:
icao_codes.add(row["ident"])
Expand Down
3 changes: 2 additions & 1 deletion logbook/management/commands/import_flightlog.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import csv
import enum
from datetime import UTC, datetime
from pathlib import Path

from django.core.management.base import BaseCommand

Expand Down Expand Up @@ -43,7 +44,7 @@ def handle(self, *args, **options):

self.stdout.write(self.style.SUCCESS("Importing FlightLog records..."))

with open(options["filename"], newline="") as fp:
with Path(options["filename"]).open(newline="") as fp:
reader = csv.DictReader(fp)
for row in reader:
day, month, year = [int(value) for value in row[Fields.DATE].split("/")]
Expand Down
60 changes: 30 additions & 30 deletions logbook/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import date
from datetime import UTC, datetime
from enum import Enum

from django.core.exceptions import ValidationError
Expand Down Expand Up @@ -34,12 +34,12 @@ class Aerodrome(models.Model):
elevation = models.IntegerField()
priority = models.IntegerField()

def __str__(self):
return f"{self.icao_code} ({self.name})"

class Meta:
ordering = ("priority",)

def __str__(self):
return f"{self.icao_code} ({self.name})"


class Aircraft(models.Model):
type = models.CharField(max_length=3, choices=[(at.name, at.value) for at in AircraftType])
Expand All @@ -53,27 +53,27 @@ class Aircraft(models.Model):

currency_required = models.BooleanField(default=False)

def __str__(self):
return f"{self.registration} ({self.maker} {self.model})"

class Meta:
ordering = ("registration",)
verbose_name_plural = "aircraft"

def __str__(self):
return f"{self.registration} ({self.maker} {self.model})"


class Pilot(models.Model):
first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=150)

self = models.BooleanField(default=False)

def __str__(self):
return f"{self.first_name} {self.last_name}"

class Meta:
ordering = ("last_name",)
unique_together = ("first_name", "last_name")

def __str__(self):
return f"{self.first_name} {self.last_name}"


class LogEntry(models.Model):
aircraft = models.ForeignKey(Aircraft, on_delete=models.PROTECT)
Expand All @@ -100,6 +100,21 @@ class LogEntry(models.Model):

slots = models.PositiveSmallIntegerField(default=1, help_text="Number of logbook slots for this entry.")

class Meta:
constraints = (
CheckConstraint(check=Q(arrival_time__gt=F("departure_time")), name="arrival_after_departure"),
CheckConstraint(check=~Q(copilot=F("pilot")), name="copilot_not_pilot"),
CheckConstraint(
check=(
Q(time_function=FunctionType.PIC.name) # PIC time may be XC or not XC
| ~Q(time_function=FunctionType.PIC.name) & Q(cross_country=False) # non-PIC time must be non-XC
),
name="no_pic_no_xc",
),
)
ordering = ("-arrival_time",)
verbose_name_plural = "Log entries"

def __str__(self):
duration = (self.arrival_time - self.departure_time).total_seconds()
duration_hours = int(duration // 3600)
Expand All @@ -125,21 +140,6 @@ def clean(self):
):
raise ValidationError("Launch type is required for gliders!")

class Meta:
constraints = (
CheckConstraint(check=Q(arrival_time__gt=F("departure_time")), name="arrival_after_departure"),
CheckConstraint(check=~Q(copilot=F("pilot")), name="copilot_not_pilot"),
CheckConstraint(
check=(
Q(time_function=FunctionType.PIC.name) # PIC time may be XC or not XC
| ~Q(time_function=FunctionType.PIC.name) & Q(cross_country=False) # non-PIC time must be non-XC
),
name="no_pic_no_xc",
),
)
ordering = ("-arrival_time",)
verbose_name_plural = "Log entries"


class Certificate(models.Model):
name = models.CharField(max_length=255)
Expand All @@ -150,12 +150,12 @@ class Certificate(models.Model):
remarks = models.CharField(max_length=255, blank=True)
relinquished = models.BooleanField(default=False)

@property
def is_valid(self) -> bool:
return (self.valid_until is None or self.valid_until >= date.today()) and not self.relinquished
class Meta:
ordering = ("name", "-valid_until")

def __str__(self):
return f"{self.name}{' ({})'.format(self.number) if self.number else ''}"

class Meta:
ordering = ("name", "-valid_until")
@property
def is_valid(self) -> bool:
return (self.valid_until is None or self.valid_until >= datetime.now(tz=UTC).today()) and not self.relinquished
Loading

0 comments on commit ac9f671

Please sign in to comment.