From d15717490d5718259c3c0b5fc9295940a7b03c74 Mon Sep 17 00:00:00 2001 From: Kevin Mok Date: Tue, 6 Nov 2018 23:23:44 -0500 Subject: [PATCH] Export ISO timestamp for history (#57) --- api/models.py | 9 +++------ graphs/utils.py | 5 +++-- graphs/views.py | 5 +++-- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/api/models.py b/api/models.py index be099d0..5d6b4cf 100644 --- a/api/models.py +++ b/api/models.py @@ -103,15 +103,12 @@ class History(models.Model): def __str__(self): return " - ".join((str(self.user), str(self.timestamp), str(self.track))) - def get_track_name(self): - return self.track.name - - def get_track_id(self): - return self.track.id - def get_artists(self): artist_names = [artist.name for artist in self.track.artists.all()] return ', '.join(artist_names) + def get_iso_timestamp(self): + return self.timestamp.isoformat() + # }}} # diff --git a/graphs/utils.py b/graphs/utils.py index 69e262d..25be3b6 100644 --- a/graphs/utils.py +++ b/graphs/utils.py @@ -9,8 +9,9 @@ class HistoryTable(tables.Table): model = History template_name = 'django_tables2/bootstrap.html' - track_name = tables.Column(accessor='get_track_name', orderable=False) - track_id = tables.Column(accessor='get_track_id', orderable=False) + iso_timestamp = tables.Column(accessor='get_iso_timestamp', orderable=False) + track_name = tables.Column(accessor='track.name', orderable=False) + track_id = tables.Column(accessor='track.id', orderable=False) artists = tables.Column(accessor='get_artists', orderable=False) def get_secret_context(user_secret): diff --git a/graphs/views.py b/graphs/views.py index 37b1c5c..ff0bea5 100644 --- a/graphs/views.py +++ b/graphs/views.py @@ -53,7 +53,7 @@ class HistoryList(ExportMixin, SingleTableView): template_name = 'graphs/user_history.html' def get_table_kwargs(self): - return { 'exclude': ('id', 'user', 'track', 'track_id', ) } + return { 'exclude': ('id', 'user', 'track', 'track_id', 'iso_timestamp', ) } def get_table_data(self): return History.objects.filter(user__exact=self.request.session['user_id']).order_by('-timestamp') @@ -67,7 +67,8 @@ class HistoryList(ExportMixin, SingleTableView): return "{}.{}".format(self.request.session['user_id'], export_format) def create_export(self, export_format): - export_exclude = ('id', 'user', 'track', 'track_name', 'artists', ) + export_exclude = ('id', 'user', 'track', 'track_name', 'artists', + 'timestamp', ) exporter = TableExport( export_format=export_format, table=self.get_table(exclude=export_exclude),