Export ISO timestamp for history (#57)

This commit is contained in:
2018-11-06 23:23:44 -05:00
parent fa2c5f7008
commit d15717490d
3 changed files with 9 additions and 10 deletions

View File

@@ -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()
# }}} #

View File

@@ -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):

View File

@@ -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),