diff --git a/asuzr/common.py b/asuzr/common.py index 9dcd28f..c63dcb1 100644 --- a/asuzr/common.py +++ b/asuzr/common.py @@ -16,4 +16,8 @@ class custom_date(date): @property def date_dd_mm_yy(self): - return self.strftime("%d/%m/%Y") \ No newline at end of file + return self.strftime("%d/%m/%Y") + + @property + def is_weekend(self): + return self.weekday() >= 5 diff --git a/asuzr/tables.py b/asuzr/tables.py index 2ae7fec..61bbcbb 100644 --- a/asuzr/tables.py +++ b/asuzr/tables.py @@ -124,8 +124,17 @@ class VisitTable(tables.Table): orders = tables.Column(verbose_name = 'Заказы', accessor = 'order.product__count') cost = tables.Column(verbose_name = 'Стоимость', accessor = 'order.price__sum') designer = tables.Column(verbose_name = 'Дизайнеры') + + summary = ['Итого:','',0,0,0,0,''] - def render_orders(self, value, record): + def set_summaries(self, summaries): + indexes = {'calls': 2, 'visits': 3, 'orders': 4, 'cost': 5} + for s in summaries: + idx = indexes[s] + self.summary[idx] = summaries[s] + + def render_orders(self, value, record, column): + value = 0 if value == None else value return mark_safe('%s' % ( reverse('asuzr.views.visit_view'), record['date'].strftime('%d.%m.%Y'), @@ -134,6 +143,8 @@ class VisitTable(tables.Table): class Meta: attrs = {'class': 'paleblue'} + orderable = False + template = 'asuzr/weekend_table.html' class ProdPlanTable(tables.Table): date = tables.Column(verbose_name = 'Дата') diff --git a/asuzr/views.py b/asuzr/views.py index bf5d491..896a050 100644 --- a/asuzr/views.py +++ b/asuzr/views.py @@ -53,13 +53,17 @@ def visit_view(request): edate = date(y,m,day_in_month) attend_list = Attendance.objects.filter(date__range = (sdate,edate)) + attend_sum = attend_list.aggregate(Sum('calls'), Sum('visits')) for attend in attend_list: month_days[attend.date.day]['attend'] = attend order_list = Order.objects.filter(date__range = (sdate,edate)) + order_sum = order_list.aggregate(Count('product'), Sum('price')) order_list = order_list.values('date') order_list = order_list.annotate(Count('product'), Sum('price')) + print order_sum + for order in order_list: month_days[order['date'].day]['order'] = order @@ -71,9 +75,15 @@ def visit_view(request): month_days[day]['designer'] = '%s, %s' % (month_days[day]['designer'], designer) else: month_days[day]['designer'] = designer - + table = VisitTable(month_days.values()) RequestConfig(request, paginate={'per_page': 32}).configure(table) + table.set_summaries({ + 'calls': attend_sum['calls__sum'], + 'visits': attend_sum['visits__sum'], + 'orders': order_sum['product__count'], + 'cost': order_sum['price__sum'], + }) title = 'Таблица посещаемости на %s г.' % curr_date.strftime('%B %Y') return render(request, 'asuzr/table.html', {'table': table, 'title': title}) diff --git a/templates/asuzr/base.html b/templates/asuzr/base.html index c691282..5f6b81f 100644 --- a/templates/asuzr/base.html +++ b/templates/asuzr/base.html @@ -7,6 +7,7 @@ {% inplace_static %} + - + + {% endblock %} + +

{% block title %}{{ title }}{% endblock %}

{% block page %} Тело страницы {% endblock %} - +
{% block footer %}
{% endblock %} diff --git a/templates/asuzr/weekend_table.html b/templates/asuzr/weekend_table.html new file mode 100644 index 0000000..0b167f9 --- /dev/null +++ b/templates/asuzr/weekend_table.html @@ -0,0 +1,60 @@ +{% spaceless %} +{% 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 }} + {% endfor %} + + {% endif %} + + {% endblock table.tfoot %} + {% endnospaceless %} + +{% endblock table %} + +{% endspaceless %}