Skip to content

Commit

Permalink
Add date range from date picker
Browse files Browse the repository at this point in the history
  • Loading branch information
Edouard Bourque committed Apr 19, 2024
1 parent c6514e7 commit b58c54e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
4 changes: 2 additions & 2 deletions clashstats/clanranking/templates/clanranking.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ <h1 class="modal-title fs-5" id="weeklyRankingLabel">Weekly ranking</h1>
<form id="dateForm" class='d-flex justify-content-between align-items-end'>
<div class="mb-3">
<label for="startDateInput" class="form-label">Start date</label>
<input type="date" class="form-control" id="startDate" name="start_date">
<input type="date" class="form-control" id="startDate" name="start_date" min="2024-03-28" max={{today}}>
</div>
<div class="mb-3">
<label for="endDateInput" class="form-label">End date</label>
<input type="date" class="form-control" id="endDate" name="end_date">
<input type="date" class="form-control" id="endDate" name="end_date" min="2024-03-28" max={{today}}>
</div>
<div class='mb-3'>
<button type="submit" class="btn btn-primary">Submit</button>
Expand Down
3 changes: 2 additions & 1 deletion clashstats/clanranking/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ def clanranking(request, clantag):
.all(),
"battles": Battles.objects.all(),
"lastUpdatedMin": round((tn - tu).total_seconds() / 60),
"today": datetime.strftime(timezone.now(), "%Y-%m-%d"),
}

default_start_date = timezone.now() - timedelta(days=7)
Expand All @@ -222,7 +223,7 @@ def clanranking(request, clantag):
end_date_str = request.POST.get('end_date')

start_date = datetime.strptime(start_date_str, '%Y-%m-%d') if start_date_str else default_start_date
end_date = datetime.strptime(end_date_str, '%Y-%m-%d') if end_date_str else default_end_date
end_date = datetime.strptime(end_date_str, '%Y-%m-%d').replace(hour=23, minute=59) if end_date_str else default_end_date

contextDates = {
"start_date": start_date,
Expand Down
Binary file modified clashstats/db.sqlite3
Binary file not shown.
4 changes: 4 additions & 0 deletions tested.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from datetime import datetime
today = datetime.strftime(datetime.now(), "%Y-%m-%d")

print(today)

0 comments on commit b58c54e

Please sign in to comment.