[widgets] Add date filtering to widgets
This commit is contained in:
@ -911,10 +911,28 @@ class BaseEmbeddableWidget(TemplateView):
|
|||||||
return user, profile
|
return user, profile
|
||||||
|
|
||||||
def get_date_range(self, user):
|
def get_date_range(self, user):
|
||||||
now = timezone.now()
|
date_param = self.request.GET.get("date")
|
||||||
if user.is_authenticated:
|
|
||||||
now = now_user_timezone(user.profile)
|
if date_param:
|
||||||
now = now.date()
|
try:
|
||||||
|
if "W" in date_param and date_param[4] == "-":
|
||||||
|
parsed_date = datetime.strptime(date_param, "%Y-W%W").date()
|
||||||
|
elif "-" in date_param and len(date_param) > 4:
|
||||||
|
parsed_date = datetime.strptime(date_param, "%Y-%m-%d").date()
|
||||||
|
else:
|
||||||
|
parsed_date = datetime.strptime(date_param, "%Y").date()
|
||||||
|
except ValueError:
|
||||||
|
parsed_date = None
|
||||||
|
|
||||||
|
if parsed_date:
|
||||||
|
now = parsed_date
|
||||||
|
else:
|
||||||
|
now = timezone.now().date()
|
||||||
|
else:
|
||||||
|
now = timezone.now()
|
||||||
|
if user.is_authenticated:
|
||||||
|
now = now_user_timezone(user.profile)
|
||||||
|
now = now.date()
|
||||||
|
|
||||||
period = self.kwargs.get("period", "week")
|
period = self.kwargs.get("period", "week")
|
||||||
if period == "month":
|
if period == "month":
|
||||||
@ -925,7 +943,7 @@ class BaseEmbeddableWidget(TemplateView):
|
|||||||
label = now.strftime("%Y")
|
label = now.strftime("%Y")
|
||||||
else:
|
else:
|
||||||
start = now - timedelta(days=now.isoweekday() % 7)
|
start = now - timedelta(days=now.isoweekday() % 7)
|
||||||
label = "This Week"
|
label = f"Week {now.isocalendar()[1]}"
|
||||||
|
|
||||||
return start, label
|
return start, label
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user