Skip to content

Commit

Permalink
Rename the download file to be more verbose
Browse files Browse the repository at this point in the history
  • Loading branch information
ezkat committed Dec 19, 2023
1 parent 113b6f9 commit 163603a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
3 changes: 2 additions & 1 deletion resources/api/reservation.py
Original file line number Diff line number Diff line change
Expand Up @@ -777,12 +777,13 @@ def render(self, data, media_type=None, renderer_context=None):
elif renderer_context['view'].action == 'list':
weekdays = request.GET.get('weekdays', '').split(',')
weekdays = [int(day) for day in weekdays if day]
include_block_reservations = bool(int(request.GET.get('include_block_reservations', '0')))
reservations = data['results']
for reservation in reservations.copy():
begin = reservation['begin']
if weekdays and begin.weekday() not in weekdays:
reservations.remove(reservation)
return generate_reservation_xlsx(reservations, request=request, weekdays=weekdays)
return generate_reservation_xlsx(reservations, request=request, weekdays=weekdays, include_block_reservations=include_block_reservations)
else:
return NotAcceptable()

Expand Down
3 changes: 2 additions & 1 deletion resources/models/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ def clean(string):

request = kwargs.get('request', None)
weekdays = kwargs.get('weekdays', None)
include_block_reservations = kwargs.get('include_block_reservations', False)
output = io.BytesIO()
workbook = xlsxwriter.Workbook(output)
sheet_name = format_lazy('{} {}', _('Reservation'), _('Reports'))
Expand Down Expand Up @@ -301,7 +302,7 @@ def set_title(title, *, headers = [], use_extra_fields = True):
worksheet.write(row_cursor, 1, gettext('%(hours)s hours') % ({'hours': int((total_normal_reservation_hours / 60) / 60)}), col_format)
row_cursor += 2

if block_reservations:
if block_reservations and include_block_reservations:
set_title(gettext('Block reservations'))

Check warning on line 306 in resources/models/utils.py

View check run for this annotation

Codecov / codecov/patch

resources/models/utils.py#L306

Added line #L306 was not covered by tests
for row, reservation in enumerate(block_reservations, row_cursor):
for key in reservation: reservation[key] = clean(reservation[key])
Expand Down
8 changes: 6 additions & 2 deletions respa_admin/static_src/js/reportForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function buildUrl(resources, start, end, selectedDays, page_size = 50000, format
return `${window.location.origin}/v1/reservation/` +
`?format=${format}&resource=${resources.join()}` +
`&start=${start}&end=${end}&page_size=${page_size}` +
`&weekdays=${selectedDays.join()}&state=confirmed`;
`&weekdays=${selectedDays.join()}&state=confirmed&include_block_reservations=1`;
}


Expand Down Expand Up @@ -172,7 +172,11 @@ function bindGenerateButton() {
var url = window.URL.createObjectURL(http.response);
let dl = document.createElement('a');
dl.href = url;
dl.download = 'report.xlsx';
dl.download = {
'fi': `Varaus raportti ${begin} - ${end}.xlsx`,
'sv': `Bokning rapport ${begin} - ${end}.xlsx`,
'en': `Reservations report ${begin} - ${end}.xlsx`
}[SELECTED_LANGUAGE];
dl.click();
$("body").css("cursor", "default");
removeLoader($(btn).parent());
Expand Down

0 comments on commit 163603a

Please sign in to comment.