Skip to content

Commit

Permalink
add duration to visit model and export
Browse files Browse the repository at this point in the history
  • Loading branch information
calellowitz committed Dec 15, 2024
1 parent afea4f6 commit 3501703
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
13 changes: 13 additions & 0 deletions commcare_connect/opportunity/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from django.conf import settings
from django.db import models
from django.db.models import Count, F, Max, Q, Sum
from django.utils.dateparse import parse_datetime
from django.utils.functional import cached_property
from django.utils.timezone import now
from django.utils.translation import gettext
Expand Down Expand Up @@ -586,6 +587,18 @@ def __setattr__(self, name, value):
def images(self):
return BlobMeta.objects.filter(parent_id=self.xform_id, content_type__startswith="image/")

@property
def duration(self):
duration = None
start = self.form_json["metadata"].get("timeStart")
end = self.form_json["metatdata"].get("timeEnd")
if start and end:
try:
duration = parse_datetime(end) - parse_datetime(start)
except (TypeError, ValueError):
pass
return duration


class OpportunityClaim(models.Model):
opportunity_access = models.OneToOneField(OpportunityAccess, on_delete=models.CASCADE)
Expand Down
1 change: 1 addition & 0 deletions commcare_connect/opportunity/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class UserVisitTable(OrgContextTable):
)
reason = columns.Column("Rejected Reason", accessor="reason", visible=False)
justification = columns.Column("Justification", accessor="justification", visible=False)
duration = columns.Column("Duration", accessor="duration", visible=False)

deliver_unit = columns.Column("Unit Name", accessor="deliver_unit__name")
entity_id = columns.Column("Entity ID", accessor="entity_id", visible=False)
Expand Down

0 comments on commit 3501703

Please sign in to comment.