Export ISO timestamp for history (#57)
This commit is contained in:
@@ -103,15 +103,12 @@ class History(models.Model):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return " - ".join((str(self.user), str(self.timestamp), str(self.track)))
|
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):
|
def get_artists(self):
|
||||||
artist_names = [artist.name for artist in self.track.artists.all()]
|
artist_names = [artist.name for artist in self.track.artists.all()]
|
||||||
return ', '.join(artist_names)
|
return ', '.join(artist_names)
|
||||||
|
|
||||||
|
def get_iso_timestamp(self):
|
||||||
|
return self.timestamp.isoformat()
|
||||||
|
|
||||||
# }}} #
|
# }}} #
|
||||||
|
|
||||||
|
|||||||
@@ -9,8 +9,9 @@ class HistoryTable(tables.Table):
|
|||||||
model = History
|
model = History
|
||||||
template_name = 'django_tables2/bootstrap.html'
|
template_name = 'django_tables2/bootstrap.html'
|
||||||
|
|
||||||
track_name = tables.Column(accessor='get_track_name', orderable=False)
|
iso_timestamp = tables.Column(accessor='get_iso_timestamp', orderable=False)
|
||||||
track_id = tables.Column(accessor='get_track_id', 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)
|
artists = tables.Column(accessor='get_artists', orderable=False)
|
||||||
|
|
||||||
def get_secret_context(user_secret):
|
def get_secret_context(user_secret):
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ class HistoryList(ExportMixin, SingleTableView):
|
|||||||
template_name = 'graphs/user_history.html'
|
template_name = 'graphs/user_history.html'
|
||||||
|
|
||||||
def get_table_kwargs(self):
|
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):
|
def get_table_data(self):
|
||||||
return History.objects.filter(user__exact=self.request.session['user_id']).order_by('-timestamp')
|
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)
|
return "{}.{}".format(self.request.session['user_id'], export_format)
|
||||||
|
|
||||||
def create_export(self, 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(
|
exporter = TableExport(
|
||||||
export_format=export_format,
|
export_format=export_format,
|
||||||
table=self.get_table(exclude=export_exclude),
|
table=self.get_table(exclude=export_exclude),
|
||||||
|
|||||||
Reference in New Issue
Block a user