Skip to content

Commit

Permalink
hotfix - minor tweaks
Browse files Browse the repository at this point in the history
- add **kwargs pass-thru filters to get_*_or_404 shortcuts
- format Stamp timestamp in default str method
  • Loading branch information
powderflask committed Oct 29, 2024
1 parent 23ed500 commit 344a470
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
3 changes: 2 additions & 1 deletion signoffs/core/models/stamps.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from django.core.exceptions import ImproperlyConfigured, ValidationError
from django.db import models
from django.utils import timezone
from django.utils.formats import date_format

from .signets import AbstractSignet

Expand Down Expand Up @@ -107,7 +108,7 @@ class Meta:

def __str__(self):
return (
f"{self.approval_id} at {self.timestamp}"
f"{self.approval_id} at {date_format(self.timestamp, 'SHORT_DATETIME_FORMAT')}"
if self.is_approved()
else f"{self.approval_id} (incomplete)"
)
Expand Down
12 changes: 6 additions & 6 deletions signoffs/shortcuts.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,29 @@
from signoffs import registry


def get_signet_or_404(signoff_type, signet_pk):
def get_signet_or_404(signoff_type, signet_pk, **kwargs):
"""Return Signet with given pk, for the given Signoff Type or id, or raise Http404"""
signoff = registry.get_signoff_type(signoff_type)
if signoff is None:
raise Http404(f"No registered signoff with id: {signoff_type}")
return get_object_or_404(
signoff.get_signetModel(), pk=signet_pk, signoff_id=signoff.id
signoff.get_signetModel(), pk=signet_pk, signoff_id=signoff.id, **kwargs
)


def get_signoff_or_404(signoff_type, signet_pk):
def get_signoff_or_404(signoff_type, signet_pk, **kwargs):
"""Return Signoff of given type or id, backed by Signet with the given pk, or raise Http404"""
signet = get_signet_or_404(signoff_type, signet_pk)
signet = get_signet_or_404(signoff_type, signet_pk, **kwargs)
return signet.signoff


def get_approval_stamp_or_404(approval_type, stamp_pk):
def get_approval_stamp_or_404(approval_type, stamp_pk, **kwargs):
"""Return ApprovalStamp instance with given pk for the given Approval Type or id, or raise Http404"""
approval = registry.get_approval_type(approval_type)
if approval is None:
raise Http404(f"No registered approval with id: {approval_type}")
return get_object_or_404(
approval.get_stampModel(), pk=stamp_pk, approval_id=approval.id
approval.get_stampModel(), pk=stamp_pk, approval_id=approval.id, **kwargs
)


Expand Down

0 comments on commit 344a470

Please sign in to comment.