Browse Source

Export ISO timestamp for history (#57)

master
Kevin Mok 6 years ago
parent
commit
d15717490d
  1. 9
      api/models.py
  2. 5
      graphs/utils.py
  3. 5
      graphs/views.py

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

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

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

Loading…
Cancel
Save