Skip to content

Commit 414837c

Browse files
committed
refactor(enrichment): address PR feedback
1 parent c9ebd54 commit 414837c

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

intranet/apps/enrichment/views.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,29 @@ def is_weekday(date):
3636
return date.isoweekday() in range(1, 6)
3737

3838

39-
def enrichment_context(request, date=None):
39+
def get_default_enrichment_date(request):
40+
"""Return next week's date on weekends unless enrichments still exist this weekend."""
4041
local_time = timezone.localtime()
4142

43+
if is_weekday(local_time):
44+
return local_time
45+
46+
days_until_next_week = 8 - local_time.isoweekday()
47+
next_week_date = local_time + timedelta(days=days_until_next_week)
48+
49+
weekend_enrichments = EnrichmentActivity.objects.visible_to_user(request.user).filter(
50+
time__range=[local_time, next_week_date],
51+
)
52+
53+
if weekend_enrichments.exists():
54+
return local_time
55+
56+
return next_week_date
57+
58+
59+
def enrichment_context(request, date=None):
4260
if date is None:
43-
date = local_time
61+
date = get_default_enrichment_date(request)
4462

4563
date_today = date.replace(hour=0, minute=0, second=0, microsecond=0)
4664

0 commit comments

Comments
 (0)