init project tests
This commit is contained in:
parent
d0ff728224
commit
7c9318c778
44 changed files with 4431 additions and 49 deletions
|
@ -1,6 +1,8 @@
|
|||
from uuid import uuid4
|
||||
|
||||
from django.db import models
|
||||
from django.contrib.auth.models import User
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
|
||||
|
@ -13,13 +15,44 @@ CHOICE_AVIARY = [
|
|||
|
||||
class Aviary(models.Model):
|
||||
id = models.UUIDField(primary_key=True, default=uuid4, editable=False)
|
||||
|
||||
# Required fields expected by tests (temporary nullable for migration)
|
||||
name = models.CharField(max_length=256, verbose_name=_("Name"), null=True, blank=True)
|
||||
location = models.CharField(max_length=256, verbose_name=_("Standort"), null=True, blank=True)
|
||||
|
||||
# Optional fields expected by tests
|
||||
description = models.CharField(
|
||||
max_length=256, verbose_name=_("Beschreibung"), unique=True
|
||||
max_length=256, verbose_name=_("Beschreibung"), blank=True, null=True
|
||||
)
|
||||
capacity = models.PositiveIntegerField(
|
||||
verbose_name=_("Kapazität"), default=0
|
||||
)
|
||||
current_occupancy = models.PositiveIntegerField(
|
||||
verbose_name=_("Aktuelle Belegung"), default=0
|
||||
)
|
||||
contact_person = models.CharField(
|
||||
max_length=256, verbose_name=_("Ansprechpartner"), blank=True, null=True
|
||||
)
|
||||
contact_phone = models.CharField(
|
||||
max_length=50, verbose_name=_("Telefon"), blank=True, null=True
|
||||
)
|
||||
contact_email = models.EmailField(
|
||||
verbose_name=_("E-Mail"), blank=True, null=True
|
||||
)
|
||||
notes = models.TextField(
|
||||
verbose_name=_("Notizen"), blank=True, null=True
|
||||
)
|
||||
created_by = models.ForeignKey(
|
||||
User, on_delete=models.CASCADE, verbose_name=_("Erstellt von"),
|
||||
null=True, blank=True
|
||||
)
|
||||
|
||||
# Keep existing fields for backwards compatibility
|
||||
condition = models.CharField(
|
||||
max_length=256, choices=CHOICE_AVIARY, verbose_name=_("Zustand")
|
||||
max_length=256, choices=CHOICE_AVIARY, verbose_name=_("Zustand"),
|
||||
blank=True, null=True
|
||||
)
|
||||
last_ward_round = models.DateField(verbose_name=_("letzte Visite"))
|
||||
last_ward_round = models.DateField(verbose_name=_("letzte Visite"), blank=True, null=True)
|
||||
comment = models.CharField(
|
||||
max_length=512, blank=True, null=True, verbose_name=_("Bemerkungen")
|
||||
)
|
||||
|
@ -29,4 +62,44 @@ class Aviary(models.Model):
|
|||
verbose_name_plural = _("Volieren")
|
||||
|
||||
def __str__(self):
|
||||
return self.description
|
||||
return self.name
|
||||
|
||||
def clean(self):
|
||||
"""Custom validation for the model."""
|
||||
super().clean()
|
||||
|
||||
# Check required fields for test compatibility
|
||||
if not self.name:
|
||||
raise ValidationError({'name': _('This field is required.')})
|
||||
|
||||
if not self.location:
|
||||
raise ValidationError({'location': _('This field is required.')})
|
||||
|
||||
# Validate that occupancy doesn't exceed capacity
|
||||
if self.current_occupancy and self.capacity and self.current_occupancy > self.capacity:
|
||||
raise ValidationError({
|
||||
'current_occupancy': _('Current occupancy cannot exceed capacity.')
|
||||
})
|
||||
|
||||
# Validate positive values
|
||||
if self.capacity is not None and self.capacity < 0:
|
||||
raise ValidationError({
|
||||
'capacity': _('Capacity must be a positive number.')
|
||||
})
|
||||
|
||||
if self.current_occupancy is not None and self.current_occupancy < 0:
|
||||
raise ValidationError({
|
||||
'current_occupancy': _('Current occupancy must be a positive number.')
|
||||
})
|
||||
|
||||
@property
|
||||
def is_full(self):
|
||||
"""Check if aviary is at full capacity."""
|
||||
return self.capacity and self.current_occupancy >= self.capacity
|
||||
|
||||
@property
|
||||
def available_space(self):
|
||||
"""Calculate available space in aviary."""
|
||||
if self.capacity is not None and self.current_occupancy is not None:
|
||||
return max(0, self.capacity - self.current_occupancy)
|
||||
return 0
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue