feat: Add date range filtering to mood status view
Enhances `StatusListView` to support filtering based on a date range by adding 'from' and 'to' query parameters. This enables users to view status updates within a specified date range, improving data accessibility. Implements click event on calendar heatmap to redirect to filtered mood page, supporting targeted data exploration.
This commit is contained in:
parent
1b494429fb
commit
5b56eef878
2 changed files with 21 additions and 1 deletions
|
@ -1,5 +1,10 @@
|
||||||
const cal = new CalHeatmap();
|
const cal = new CalHeatmap();
|
||||||
|
|
||||||
|
cal.on("click", (event, timestamp, value) => {
|
||||||
|
const date_str = dayjs(timestamp).format("YYYY-MM-DD");
|
||||||
|
window.location.href = "/mood/?from=" + date_str + "&to=" + date_str;
|
||||||
|
});
|
||||||
|
|
||||||
fetch("/mood/statistics/heatmap/values/")
|
fetch("/mood/statistics/heatmap/values/")
|
||||||
.then((response) => response.json())
|
.then((response) => response.json())
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
|
|
|
@ -45,7 +45,22 @@ class StatusListView(LoginRequiredMixin, ListView):
|
||||||
return context
|
return context
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
return Status.objects.filter(user=self.request.user).order_by("timestamp")
|
status_list = Status.objects.filter(user=self.request.user).order_by("timestamp")
|
||||||
|
|
||||||
|
if "from" in self.request.GET:
|
||||||
|
from_timestamp = datetime.strptime(self.request.GET["from"], "%Y-%m-%d")
|
||||||
|
status_list = status_list.filter(
|
||||||
|
timestamp__gte=from_timestamp
|
||||||
|
)
|
||||||
|
|
||||||
|
if "to" in self.request.GET:
|
||||||
|
to_timestamp = datetime.strptime(self.request.GET["to"], "%Y-%m-%d")
|
||||||
|
to_timestamp = to_timestamp.replace(hour=23, minute=59, second=59)
|
||||||
|
status_list = status_list.filter(
|
||||||
|
timestamp__lte=self.request.GET["to"]
|
||||||
|
)
|
||||||
|
|
||||||
|
return status_list
|
||||||
|
|
||||||
|
|
||||||
class StatusViewView(LoginRequiredMixin, DetailView):
|
class StatusViewView(LoginRequiredMixin, DetailView):
|
||||||
|
|
Loading…
Reference in a new issue