diff --git a/asuzr/tables.py b/asuzr/tables.py index f14b83d..74b464e 100644 --- a/asuzr/tables.py +++ b/asuzr/tables.py @@ -119,10 +119,9 @@ class VisitTable(tables.Table): designer = tables.Column(verbose_name = 'Дизайнеры') summary = ['Всего','',0,0,0,0,''] - def set_summaries(self, summaries): - indexes = {'calls': 2, 'visits': 3, 'orders': 4, 'cost': 5} - for s in summaries: + indexes = {'calls': 2, 'visits': 3, 'orders': 4, 'cost': 5} + for s in summaries: idx = indexes[s] self.summary[idx] = summaries[s] @@ -141,6 +140,12 @@ class VisitTable(tables.Table): class DayOrdersTable(OrdersTable): designer = tables.Column(verbose_name = 'Дизайнер') + + summary = ['Всего', 0, '', '', '',] + + def set_summary(self, price): + self.summary[1] = price + class Meta: attrs = {'class': 'paleblue'} exclude = ('date', @@ -159,3 +164,4 @@ class DayOrdersTable(OrdersTable): 'designer', 'deadline', ) + template = 'asuzr/totals_table.html' diff --git a/asuzr/views.py b/asuzr/views.py index 07ad73b..d381f39 100644 --- a/asuzr/views.py +++ b/asuzr/views.py @@ -82,17 +82,25 @@ def get_attendance_table(year, month, prefix): return table +def get_day_orders_table(date, prefix): + orders = Order.objects.filter(date = date) + orders_price = orders.aggregate(Sum('price')) + table = DayOrdersTable(orders, prefix = prefix) + table.verbose_name = 'Заказы на %s' % date.strftime('%d %B %Y г') + table.set_summary(orders_price['price__sum']) + + return table + @login_required def visit_view(request): curr_date = datetime.strptime(request.GET.get('date', date.today().strftime('%d.%m.%Y')), '%d.%m.%Y') attendance_table = get_attendance_table(curr_date.year, curr_date.month, 'attendance-') RequestConfig(request, paginate={'per_page': 32}).configure(attendance_table) - orders_table = DayOrdersTable(Order.objects.filter(date = curr_date)) - orders_table.verbose_name = 'Заказы на %s г' % curr_date.strftime('%d %B %Y') + orders_table = get_day_orders_table(curr_date, 'orders-') RequestConfig(request).configure(orders_table) - title = 'Таблица посещаемости на %s г.' % curr_date.strftime('%B %Y') + title = 'Таблица посещаемости на %s' % curr_date.strftime('%B %Y г') return render(request, 'asuzr/table3.html', { 'table1': attendance_table, 'table2': orders_table, diff --git a/templates/asuzr/totals_table.html b/templates/asuzr/totals_table.html new file mode 100644 index 0000000..d33a002 --- /dev/null +++ b/templates/asuzr/totals_table.html @@ -0,0 +1,15 @@ +{% extends "django_tables2/table.html" %} +{% load django_tables2 %} +{% load i18n %} +{% block table.tfoot %} + + {% if table.summary %} + + {% for summary in table.summary %} + {{ summary }} + {% endfor %} + + {% endif %} + +{% endblock table.tfoot %} + diff --git a/templates/asuzr/weekend_table.html b/templates/asuzr/weekend_table.html index 88d2dab..ddacc7d 100644 --- a/templates/asuzr/weekend_table.html +++ b/templates/asuzr/weekend_table.html @@ -1,63 +1,14 @@ -{% spaceless %} +{% extends "asuzr/totals_table.html" %} {% load django_tables2 %} {% load i18n %} -{% if table.page %} -
-{% endif %} -{% block table %} - - {% nospaceless %} - {% block table.thead %} - - - {% for column in table.columns %} - {% if column.orderable %} - {{ column.header }} - {% else %} - {{ column.header }} - {% endif %} - {% endfor %} - - - {% endblock table.thead %} - {% block table.tbody %} - - {% for row in table.page.object_list|default:table.rows %} {# support pagination #} - {% block table.tbody.row %} - {# avoid cycle for Django 1.2-1.6 compatibility #} - {% for column, cell in row.items %} - {% if column.localize == None %}{{ cell }}{% else %}{% if column.localize %}{{ cell|localize }}{% else %}{{ cell|unlocalize }}{% endif %}{% endif %} - {% endfor %} - - {% endblock table.tbody.row %} - {% empty %} - {% if table.empty_text %} - {% block table.tbody.empty_text %} - {{ table.empty_text }} - {% endblock table.tbody.empty_text %} - {% endif %} - {% endfor %} - - {% endblock table.tbody %} - {% block table.tfoot %} - - {% if table.summary %} - - {% for summary in table.summary %} - {{ summary }} +{% block table.tbody.row %} + {# avoid cycle for Django 1.2-1.6 compatibility #} + {% for column, cell in row.items %} + {% if column.localize == None %}{{ cell }}{% else %}{% if column.localize %}{{ cell|localize }}{% else %}{{ cell|unlocalize }}{% endif %}{% endif %} {% endfor %} - - {% endif %} - - {% endblock table.tfoot %} - {% endnospaceless %} - -{% endblock table %} -{% if table.page %} -
-{% endif %} + +{% endblock table.tbody.row %} -{% endspaceless %}