-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* tabular exports time series #23 * added site filter on resource #23 * fix #23 * update README #23 * small mods README #23
- Loading branch information
1 parent
0ab0bac
commit bd24226
Showing
7 changed files
with
118 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .time_series import TimeSeriesResource |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
"""resources file for tabular downloads of TimeSeries model. """ | ||
from import_export import resources | ||
from api.models import TimeSeries | ||
|
||
|
||
class TimeSeriesResource(resources.ModelResource): | ||
|
||
class Meta: | ||
model = TimeSeries | ||
fields = ('id', 'site__name','timestamp', 'h', 'q_05', 'q_25', 'q_50', 'q_75', 'q_95', 'fraction_velocimetry') | ||
export_order = ('id', 'site__name', 'timestamp', 'h', 'q_05', 'q_25', 'q_50', 'q_75', 'q_95', 'fraction_velocimetry') | ||
|
||
@classmethod | ||
def get_display_name(cls): | ||
return "Time series" # Customize this display name as needed | ||
|
||
def get_export_headers(self, fields=None): | ||
headers = super().get_export_headers(fields=fields) | ||
header_mapping = {"site__name": "site"} | ||
# Replace the original headers with custom headers | ||
custom_headers = [header_mapping.get(header, header) for header in headers] | ||
return custom_headers | ||
|
||
def export(self, queryset=None, *args, **kwargs): | ||
data = kwargs["export_form"].data | ||
start_date = data.get("start_date", None) | ||
end_date = data.get("end_date", None) | ||
site = data.get("site", None) | ||
if not queryset: | ||
queryset = self.get_queryset() | ||
|
||
queryset = queryset.filter(site=site) | ||
if start_date and end_date: | ||
queryset = queryset.filter(timestamp__range=(start_date, end_date)) | ||
elif start_date: | ||
queryset = queryset.filter(timestamp__gte=start_date) | ||
elif end_date: | ||
queryset = queryset.filter(timestamp__lte=end_date) | ||
return super().export(queryset, *args, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters