[widgets] Add date filtering to widgets
This commit is contained in:
@ -911,10 +911,28 @@ class BaseEmbeddableWidget(TemplateView):
|
||||
return user, profile
|
||||
|
||||
def get_date_range(self, user):
|
||||
now = timezone.now()
|
||||
if user.is_authenticated:
|
||||
now = now_user_timezone(user.profile)
|
||||
now = now.date()
|
||||
date_param = self.request.GET.get("date")
|
||||
|
||||
if date_param:
|
||||
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")
|
||||
if period == "month":
|
||||
@ -925,7 +943,7 @@ class BaseEmbeddableWidget(TemplateView):
|
||||
label = now.strftime("%Y")
|
||||
else:
|
||||
start = now - timedelta(days=now.isoweekday() % 7)
|
||||
label = "This Week"
|
||||
label = f"Week {now.isocalendar()[1]}"
|
||||
|
||||
return start, label
|
||||
|
||||
|
||||
Reference in New Issue
Block a user