Skip to content

Commit

Permalink
Fix some pydocstyle
Browse files Browse the repository at this point in the history
  • Loading branch information
KiOui committed Sep 6, 2023
1 parent c59524c commit def7eba
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions website/fridges/api/v1/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@


class FridgeUnlockAPIView(ClientProtectedResourceMixin, APIView):
"""API view for testing whether a Fridge is allowed to be unlocked."""

def post(self, request, *args, **kwargs):
"""
Process a request to unlock.
Expand Down
14 changes: 14 additions & 0 deletions website/fridges/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class Fridge(models.Model):
)

def __str__(self):
"""Convert this object to string."""
return self.name

@property
Expand All @@ -49,6 +50,7 @@ def last_opened_by(self):

@property
def current_opening_hours(self):
"""Get the current opening hours."""
current_time = timezone.now().astimezone()
weekday = current_time.weekday()
opening_hours = self.generalopeninghours_set.filter(
Expand All @@ -58,6 +60,7 @@ def current_opening_hours(self):

@property
def can_be_opened(self):
"""Whether the Fridge can be opened."""
return self.current_opening_hours.filter(
restrict_to_groups__isnull=True,
).exists()
Expand All @@ -84,6 +87,8 @@ def opens_today_at(self):
return None

class Meta:
"""Meta class."""

verbose_name = "fridge"
verbose_name_plural = "fridges"
ordering = ["name"]
Expand Down Expand Up @@ -117,9 +122,12 @@ class GeneralOpeningHours(models.Model):
)

def __str__(self):
"""Convert this object to string."""
return f"{self.DAY_CHOICES[self.weekday][1]} {self.start_time} - {self.end_time}"

class Meta:
"""Meta class."""

verbose_name = "general opening hours"
verbose_name_plural = "general opening hours"
ordering = ["weekday", "start_time"]
Expand All @@ -133,9 +141,12 @@ class BlacklistEntry(models.Model):
fridge = models.ForeignKey(Fridge, on_delete=models.CASCADE)

def __str__(self):
"""Convert this object to string."""
return f"{self.user} blacklisted from {self.fridge}"

class Meta:
"""Meta class."""

verbose_name = "blacklist entry"
verbose_name_plural = "blacklist entries"

Expand All @@ -148,9 +159,12 @@ class AccessLog(models.Model):
timestamp = models.DateTimeField(auto_now_add=True)

def __str__(self):
"""Convert this object to string."""
return f"{self.user} accessed {self.fridge} at {self.timestamp:%Y-%m-%d %H:%M}"

class Meta:
"""Meta class."""

verbose_name = "access log"
verbose_name_plural = "access logs"
ordering = ["-timestamp"]
Expand Down
1 change: 1 addition & 0 deletions website/fridges/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ class IndexView(ListView):
context_object_name = "fridges"

def get_queryset(self):
"""Get the queryset."""
return Fridge.objects.filter(is_active=True).order_by("name")

0 comments on commit def7eba

Please sign in to comment.