From 3c6111e7352ab233c82c6b03a0b9ccc2374c5727 Mon Sep 17 00:00:00 2001 From: "Denis V. Dedkov" Date: Sun, 14 Jun 2015 20:10:14 +0500 Subject: [PATCH 1/7] =?UTF-8?q?=D0=9F=D0=BE=D0=B4=D0=BA=D1=80=D0=B0=D1=81?= =?UTF-8?q?=D0=BA=D0=B0=20=D1=8F=D1=87=D0=B5=D0=B5=D0=BA=20=D0=B2=20=D1=82?= =?UTF-8?q?=D0=B0=D0=B1=D0=BB=D0=B8=D1=86=D0=B5=20=D0=BF=D0=BE=D1=81=D0=B5?= =?UTF-8?q?=D1=89=D0=B5=D0=BD=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Сделал подкраску ячеек в таблице посещений Заодним немного облагородил общий вид страницы --- asuzr/common.py | 6 +++++- asuzr/tables.py | 4 +++- templates/asuzr/base.html | 20 +++++++++++++++----- 3 files changed, 23 insertions(+), 7 deletions(-) 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 0e09ad8..9525ffc 100644 --- a/asuzr/tables.py +++ b/asuzr/tables.py @@ -122,7 +122,8 @@ class VisitTable(tables.Table): cost = tables.Column(verbose_name = 'Стоимость', accessor = 'order.price__sum') designer = tables.Column(verbose_name = 'Дизайнеры') - def render_orders(self, value, record): + 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'), @@ -131,3 +132,4 @@ class VisitTable(tables.Table): class Meta: attrs = {'class': 'paleblue'} + template = 'asuzr/table_templ.html' diff --git a/templates/asuzr/base.html b/templates/asuzr/base.html index 5911fbd..3652da5 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 %} From c8477a0ba4266c8f5d1d5fbc06297600fd911378 Mon Sep 17 00:00:00 2001 From: "Denis V. Dedkov" Date: Sun, 14 Jun 2015 20:13:19 +0500 Subject: [PATCH 2/7] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=B8=D0=BC=D0=B5?= =?UTF-8?q?=D0=BD=D0=BE=D0=B2=D0=B0=D0=BD=20=D1=88=D0=B0=D0=B1=D0=BB=D0=BE?= =?UTF-8?q?=D0=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Переименовал шаблон для таблицы с подкраской выходных дней --- asuzr/tables.py | 2 +- templates/asuzr/weekend_table.html | 77 ++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 templates/asuzr/weekend_table.html diff --git a/asuzr/tables.py b/asuzr/tables.py index 9525ffc..cad42c0 100644 --- a/asuzr/tables.py +++ b/asuzr/tables.py @@ -132,4 +132,4 @@ class VisitTable(tables.Table): class Meta: attrs = {'class': 'paleblue'} - template = 'asuzr/table_templ.html' + template = 'asuzr/weekend_table.html' diff --git a/templates/asuzr/weekend_table.html b/templates/asuzr/weekend_table.html new file mode 100644 index 0000000..e3d4c5d --- /dev/null +++ b/templates/asuzr/weekend_table.html @@ -0,0 +1,77 @@ +{% 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 %} + {% if row.date.is_weekend %} + {# avoid cycle for Django 1.2-1.6 compatibility #} + {% else %} + {# avoid cycle for Django 1.2-1.6 compatibility #} + {% endif %} + {% 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 %} + + {% endblock table.tfoot %} + {% endnospaceless %} + +{% endblock table %} + +{% if table.page %} +{% with table.page.paginator.count as total %} +{% with table.page.object_list|length as count %} +{% block pagination %} +
    + {% if table.page.has_previous %} + {% nospaceless %}{% block pagination.previous %}{% endblock pagination.previous %}{% endnospaceless %} + {% endif %} + + {% if table.page.has_previous or table.page.has_next %} + {% nospaceless %}{% block pagination.current %}
  • {% blocktrans with table.page.number as current and table.paginator.num_pages as total %}Page {{ current }} of {{ total }}{% endblocktrans %}
  • {% endblock pagination.current %}{% endnospaceless %} + {% endif %} + + {% if table.page.has_next %} + {% nospaceless %}{% block pagination.next %}{% endblock pagination.next %}{% endnospaceless %} + {% endif %} + + {% nospaceless %}{% block pagination.cardinality %}
  • {% if total != count %}{% blocktrans %}{{ count }} of {{ total }}{% endblocktrans %}{% else %}{{ total }}{% endif %} {% if total == 1 %}{{ table.data.verbose_name }}{% else %}{{ table.data.verbose_name_plural }}{% endif %}
  • {% endblock pagination.cardinality %}{% endnospaceless %} +
+{% endblock pagination %} +{% endwith %} +{% endwith %} +
+{% endif %} +{% endspaceless %} From 6cc7e8884481a54d7e8d1a84da76a0cab3a5d08d Mon Sep 17 00:00:00 2001 From: "Denis V. Dedkov" Date: Sun, 14 Jun 2015 21:49:27 +0500 Subject: [PATCH 3/7] =?UTF-8?q?=D0=98=D1=82=D0=BE=D0=B3=D0=B8=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=20=D1=82=D0=B0=D0=B1=D0=BB=D0=B8=D1=86=D1=8B=20?= =?UTF-8?q?=D0=BF=D0=BE=D1=81=D0=B5=D1=89=D0=B5=D0=BD=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Добавлен вывод итогов для таблицы посещений --- asuzr/tables.py | 8 ++++++ asuzr/views.py | 12 +++++++-- templates/asuzr/weekend_table.html | 43 +++++++++--------------------- 3 files changed, 31 insertions(+), 32 deletions(-) diff --git a/asuzr/tables.py b/asuzr/tables.py index cad42c0..e46bf4c 100644 --- a/asuzr/tables.py +++ b/asuzr/tables.py @@ -121,7 +121,15 @@ 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 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' % ( diff --git a/asuzr/views.py b/asuzr/views.py index 58d6aea..162497f 100644 --- a/asuzr/views.py +++ b/asuzr/views.py @@ -52,13 +52,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,10 +75,14 @@ def visit_view(request): else: month_days[day]['designer'] = designer - print month_days - 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/weekend_table.html b/templates/asuzr/weekend_table.html index e3d4c5d..0b167f9 100644 --- a/templates/asuzr/weekend_table.html +++ b/templates/asuzr/weekend_table.html @@ -24,11 +24,10 @@ {% for row in table.page.object_list|default:table.rows %} {# support pagination #} {% block table.tbody.row %} - {% if row.date.is_weekend %} - {# avoid cycle for Django 1.2-1.6 compatibility #} - {% else %} - {# avoid cycle for Django 1.2-1.6 compatibility #} - {% endif %} + {# 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 %} @@ -44,34 +43,18 @@ {% endblock table.tbody %} {% block table.tfoot %} - + + {% if table.summary %} + + {% for summary in table.summary %} + {{ summary }} + {% endfor %} + + {% endif %} + {% endblock table.tfoot %} {% endnospaceless %} {% endblock table %} -{% if table.page %} -{% with table.page.paginator.count as total %} -{% with table.page.object_list|length as count %} -{% block pagination %} -
    - {% if table.page.has_previous %} - {% nospaceless %}{% block pagination.previous %}{% endblock pagination.previous %}{% endnospaceless %} - {% endif %} - - {% if table.page.has_previous or table.page.has_next %} - {% nospaceless %}{% block pagination.current %}
  • {% blocktrans with table.page.number as current and table.paginator.num_pages as total %}Page {{ current }} of {{ total }}{% endblocktrans %}
  • {% endblock pagination.current %}{% endnospaceless %} - {% endif %} - - {% if table.page.has_next %} - {% nospaceless %}{% block pagination.next %}{% endblock pagination.next %}{% endnospaceless %} - {% endif %} - - {% nospaceless %}{% block pagination.cardinality %}
  • {% if total != count %}{% blocktrans %}{{ count }} of {{ total }}{% endblocktrans %}{% else %}{{ total }}{% endif %} {% if total == 1 %}{{ table.data.verbose_name }}{% else %}{{ table.data.verbose_name_plural }}{% endif %}
  • {% endblock pagination.cardinality %}{% endnospaceless %} -
-{% endblock pagination %} -{% endwith %} -{% endwith %} - -{% endif %} {% endspaceless %} From 2a6c0be7ff3bf0bb68df5935bb6689aa93af3725 Mon Sep 17 00:00:00 2001 From: "Denis V. Dedkov" Date: Sun, 14 Jun 2015 21:54:23 +0500 Subject: [PATCH 4/7] =?UTF-8?q?=D0=A1=D0=BA=D1=80=D1=83=D0=B3=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=BD=D1=8B=D0=B5=20=D1=83=D0=B3=D0=BB=D1=8B=20=D1=83=20?= =?UTF-8?q?=D0=BA=D0=BD=D0=BE=D0=BF=D0=BE=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Добавил красивое скругление углов у кнопок --- templates/asuzr/base.html | 1 + 1 file changed, 1 insertion(+) diff --git a/templates/asuzr/base.html b/templates/asuzr/base.html index 3652da5..8c2ac26 100644 --- a/templates/asuzr/base.html +++ b/templates/asuzr/base.html @@ -17,6 +17,7 @@ display: inline; /* Отображать как строчный элемент */ margin-right: 5px; /* Отступ слева */ border: 1px solid #000; /* Рамка вокруг текста */ + border-radius: 4px; padding: 3px; /* Поля вокруг текста */ } #user { From a05ecadf0113a03b3314b928b78f4209f91d7d51 Mon Sep 17 00:00:00 2001 From: "Denis V. Dedkov" Date: Sun, 14 Jun 2015 21:57:20 +0500 Subject: [PATCH 5/7] =?UTF-8?q?=D0=A1=D0=BE=D1=80=D1=82=D0=B8=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=BA=D0=B0=20=D0=B2=20=D1=82=D0=B0=D0=B1=D0=BB=D0=B8?= =?UTF-8?q?=D1=86=D0=B5=20=D0=BF=D0=BE=D1=81=D0=B5=D1=89=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Убрал сортировку в таблице посещений, так как она не нужна там --- asuzr/tables.py | 1 + 1 file changed, 1 insertion(+) diff --git a/asuzr/tables.py b/asuzr/tables.py index e46bf4c..0c9ca23 100644 --- a/asuzr/tables.py +++ b/asuzr/tables.py @@ -140,4 +140,5 @@ class VisitTable(tables.Table): class Meta: attrs = {'class': 'paleblue'} + orderable = False template = 'asuzr/weekend_table.html' From 3849c7029ef186aad10336413c5528af0ba63a75 Mon Sep 17 00:00:00 2001 From: "Denis V. Dedkov" Date: Sun, 14 Jun 2015 22:01:20 +0500 Subject: [PATCH 6/7] =?UTF-8?q?=D0=9E=D1=88=D0=B8=D0=B1=D0=BA=D0=B0=20?= =?UTF-8?q?=D1=81=20=D1=8E=D0=BD=D0=B8=D0=BA=D0=BE=D0=B4=D0=BE=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Исправил ошибку с юникодной строкой --- asuzr/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/asuzr/views.py b/asuzr/views.py index 162497f..38c5437 100644 --- a/asuzr/views.py +++ b/asuzr/views.py @@ -173,7 +173,7 @@ def desreport(request): edate = datetime.strptime(end_date, '%d.%m.%y') Table = DesignerTable table = Table(Order.objects.filter(cancelled=False, date__range=(sdate,edate)).values('designer__first_name','designer__last_name').annotate(Sum('price'),Count('designer'))) - title = 'Отчет по дизайнерам за '+' - '.join((start_date, end_date)) + title = u'Отчет по дизайнерам за '+' - '.join((start_date, end_date)) RequestConfig(request).configure(table) return render(request, 'asuzr/table.html', {'table': table, 'title': title}) From 4afb92cecc568dcb7bb1c0977b93468e62c68ea7 Mon Sep 17 00:00:00 2001 From: "Denis V. Dedkov" Date: Mon, 15 Jun 2015 08:20:57 +0500 Subject: [PATCH 7/7] =?UTF-8?q?=D0=92=D1=81=D0=B5=D0=B3=D0=BE=20->=20?= =?UTF-8?q?=D0=98=D1=82=D0=BE=D0=B3=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Заменил Всего на Итого в таблице посещений --- asuzr/tables.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/asuzr/tables.py b/asuzr/tables.py index 0c9ca23..4a2ec23 100644 --- a/asuzr/tables.py +++ b/asuzr/tables.py @@ -122,7 +122,7 @@ class VisitTable(tables.Table): cost = tables.Column(verbose_name = 'Стоимость', accessor = 'order.price__sum') designer = tables.Column(verbose_name = 'Дизайнеры') - summary = ['Всего','',0,0,0,0,''] + summary = ['Итого:','',0,0,0,0,''] def set_summaries(self, summaries): indexes = {'calls': 2, 'visits': 3, 'orders': 4, 'cost': 5}