|
|
@ -13,6 +13,8 @@ from datetime import datetime |
|
|
|
from django.shortcuts import render, redirect |
|
|
|
from .utils import * |
|
|
|
from django_tables2 import RequestConfig, SingleTableView |
|
|
|
from django_tables2.export.views import ExportMixin |
|
|
|
from django_tables2.export import TableExport |
|
|
|
from api.models import History |
|
|
|
|
|
|
|
# }}} imports # |
|
|
@ -43,27 +45,33 @@ def display_features_graphs(request, user_secret): |
|
|
|
return render(request, "graphs/features_graphs.html", |
|
|
|
get_secret_context(user_secret)) |
|
|
|
|
|
|
|
def display_history_table(request): |
|
|
|
"""Renders the user history page |
|
|
|
class HistoryList(ExportMixin, SingleTableView): |
|
|
|
"""Create table with list of song history.""" |
|
|
|
model = History |
|
|
|
table_class = HistoryTable |
|
|
|
context_table_name = 'user_history_table' |
|
|
|
template_name = 'graphs/user_history.html' |
|
|
|
|
|
|
|
:param request: the HTTP request |
|
|
|
:param user_secret: user secret used for identification |
|
|
|
:return: renders the user history page |
|
|
|
""" |
|
|
|
user_id = request.session['user_id'] |
|
|
|
user_history = History.objects.filter(user__exact=user_id).order_by('-timestamp') |
|
|
|
history_table = HistoryTable(user_history) |
|
|
|
history_table.exclude = ('id', 'user', 'track', ) |
|
|
|
RequestConfig(request).configure(history_table) |
|
|
|
def get_table_kwargs(self): |
|
|
|
return { 'exclude': ('id', 'user', 'track', 'track_id', ) } |
|
|
|
|
|
|
|
context = { 'user_history_table': history_table, |
|
|
|
'user_id': user_id, } |
|
|
|
def get_table_data(self): |
|
|
|
return History.objects.filter(user__exact=self.request.session['user_id']).order_by('-timestamp') |
|
|
|
|
|
|
|
return render(request, "graphs/user_history.html", context) |
|
|
|
def get_context_data(self, **kwargs): |
|
|
|
context = super().get_context_data(**kwargs) |
|
|
|
context['user_id'] = self.request.session['user_id'] |
|
|
|
return context |
|
|
|
|
|
|
|
class HistoryList(SingleTableView): |
|
|
|
"""Create table with list of song history.""" |
|
|
|
model = History |
|
|
|
table_class = HistoryTable |
|
|
|
# table_data = |
|
|
|
def get_export_filename(self, export_format): |
|
|
|
return "{}.{}".format(self.request.session['user_id'], export_format) |
|
|
|
|
|
|
|
def create_export(self, export_format): |
|
|
|
export_exclude = ('id', 'user', 'track', 'track_name', 'artists', ) |
|
|
|
exporter = TableExport( |
|
|
|
export_format=export_format, |
|
|
|
table=self.get_table(exclude=export_exclude), |
|
|
|
exclude_columns=self.exclude_columns, |
|
|
|
) |
|
|
|
|
|
|
|
return exporter.response(filename=self.get_export_filename(export_format)) |