Merge branch 'visitors'
Conflicts: asuzr/tables.py
This commit is contained in:
@@ -17,12 +17,12 @@ class EditableColumn(tables.TemplateColumn):
|
||||
main_part = ''
|
||||
if object_name == '':
|
||||
main_part = '''
|
||||
{{% inplace_edit "record.{field}" auto_height = 1 %}}
|
||||
{{% inplace_edit "record.{field}" auto_height = 1, auto_width = 1 %}}
|
||||
'''
|
||||
else:
|
||||
main_part = '''
|
||||
{{% if record.{object_name} %}}
|
||||
{{% inplace_edit "record.{object_name}.{field}" auto_height = 1 %}}
|
||||
{{% inplace_edit "record.{object_name}.{field}" auto_height = 1, auto_width = 1 %}}
|
||||
{{% endif %}}
|
||||
'''
|
||||
template = template.format(main_part = main_part)
|
||||
@@ -43,7 +43,7 @@ class ThumbnailColumn(tables.TemplateColumn):
|
||||
|
||||
class OrdersTable(tables.Table):
|
||||
date = tables.DateColumn('d/m/Y', verbose_name = 'Дата')
|
||||
deadline = tables.DateColumn('d/m/Y/', verbose_name = 'Срок сдачи')
|
||||
deadline = tables.DateColumn('d/m/Y', verbose_name = 'Срок сдачи')
|
||||
product = tables.Column(verbose_name = 'Наименование')
|
||||
delivery = EditableColumn('delivery', verbose_name = 'Доставка')
|
||||
lifting = EditableColumn('lifting', verbose_name = 'Подъем')
|
||||
@@ -55,18 +55,12 @@ class OrdersTable(tables.Table):
|
||||
sketch = tables.LinkColumn('asuzr.views.sketches', verbose_name = 'Эскизы', args=[tables.utils.A('pk')])
|
||||
executor = EditableColumn('executor', verbose_name = 'Исполнитель')
|
||||
is_done = EditableColumn('is_done', verbose_name = 'Сдан')
|
||||
id = tables.Column(visible = False)
|
||||
designer = tables.Column(visible = False)
|
||||
calls = tables.Column(visible = False)
|
||||
contact = tables.Column(visible = False)
|
||||
phone_num = tables.Column(visible = False)
|
||||
cancelled = tables.Column(visible = False)
|
||||
|
||||
def render_price(self, value):
|
||||
return '%0.1f' % value
|
||||
return '%0.2f' % value
|
||||
|
||||
def render_ostatok(self, value):
|
||||
return '%0.1f' % value
|
||||
return '%0.2f' % value
|
||||
|
||||
class Meta:
|
||||
model = Order
|
||||
@@ -84,6 +78,7 @@ class OrdersTable(tables.Table):
|
||||
'sketch',
|
||||
'executor',
|
||||
'is_done',)
|
||||
exclude = ('id', 'calls', 'contact', 'phone_num', 'cancelled', 'designer', )
|
||||
|
||||
class ArchiveOrdersTable(OrdersTable):
|
||||
calls = EditableColumn('calls', verbose_name = 'Обзвон')
|
||||
@@ -125,8 +120,8 @@ class VisitTable(tables.Table):
|
||||
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]
|
||||
|
||||
@@ -142,3 +137,34 @@ class VisitTable(tables.Table):
|
||||
attrs = {'class': 'paleblue'}
|
||||
orderable = False
|
||||
template = 'asuzr/weekend_table.html'
|
||||
|
||||
class DayOrdersTable(OrdersTable):
|
||||
designer = tables.Column(verbose_name = 'Дизайнер')
|
||||
|
||||
summary = ['Всего', 0, '', '', '',]
|
||||
|
||||
def set_summary(self, price):
|
||||
self.summary[1] = price
|
||||
|
||||
def render_designer(self, value):
|
||||
return ' '.join((value.first_name, value.last_name))
|
||||
|
||||
class Meta:
|
||||
attrs = {'class': 'paleblue'}
|
||||
exclude = ('date',
|
||||
'delivery',
|
||||
'lifting',
|
||||
'paid',
|
||||
'ostatok',
|
||||
'approved',
|
||||
'sketch',
|
||||
'executor',
|
||||
'is_done',
|
||||
)
|
||||
sequence = ('product',
|
||||
'price',
|
||||
'address',
|
||||
'designer',
|
||||
'deadline',
|
||||
)
|
||||
template = 'asuzr/totals_table.html'
|
||||
|
||||
@@ -42,14 +42,12 @@ def get_orders_by_date(dt):
|
||||
order_list = Order.objects.filter(date=dt).order_by('id')
|
||||
return order_list
|
||||
|
||||
@login_required
|
||||
def visit_view(request):
|
||||
curr_date = datetime.strptime(request.GET.get('date', date.today().strftime('%d.%m.%Y')), '%d.%m.%Y')
|
||||
y,m = curr_date.year, curr_date.month
|
||||
day_in_month = calendar.monthrange(y,m)[1]
|
||||
month_days = {i+1: {'date': custom_date(y,m,i+1)} for i in range(day_in_month)}
|
||||
sdate = date(y,m,1)
|
||||
edate = date(y,m,day_in_month)
|
||||
def get_attendance_table(year, month, prefix):
|
||||
day_in_month = calendar.monthrange(year,month)[1]
|
||||
sdate = date(year,month,1)
|
||||
edate = date(year,month,day_in_month)
|
||||
|
||||
month_days = {i+1: {'date': custom_date(year,month,i+1)} for i in range(day_in_month)}
|
||||
|
||||
attend_list = Attendance.objects.filter(date__range = (sdate,edate))
|
||||
attend_sum = attend_list.aggregate(Sum('calls'), Sum('visits'))
|
||||
@@ -61,8 +59,6 @@ def visit_view(request):
|
||||
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
|
||||
|
||||
@@ -75,16 +71,52 @@ def visit_view(request):
|
||||
else:
|
||||
month_days[day]['designer'] = designer
|
||||
|
||||
table = VisitTable(month_days.values())
|
||||
RequestConfig(request, paginate={'per_page': 32}).configure(table)
|
||||
month_plan = OrderPlan.objects.filter(date = sdate).first()
|
||||
month_plan = 0 if month_plan == None else month_plan.plan
|
||||
month_balance = month_plan - (order_sum['price__sum'] or 0)
|
||||
|
||||
additional_info = {'title': 'Справочно',
|
||||
'rows': [
|
||||
{'title': 'ПЛАН', 'value': month_plan},
|
||||
{'title': 'Осталось до выполнения', 'value': month_balance},
|
||||
]
|
||||
}
|
||||
|
||||
table = VisitTable(month_days.values(), prefix = prefix)
|
||||
table.verbose_name = 'Сводная информация'
|
||||
table.set_summaries({
|
||||
'calls': attend_sum['calls__sum'],
|
||||
'visits': attend_sum['visits__sum'],
|
||||
'orders': order_sum['product__count'],
|
||||
'cost': order_sum['price__sum'],
|
||||
'calls': attend_sum['calls__sum'] or 0,
|
||||
'visits': attend_sum['visits__sum'] or 0,
|
||||
'orders': order_sum['product__count'] or 0,
|
||||
'cost': order_sum['price__sum'] or 0,
|
||||
})
|
||||
title = 'Таблица посещаемости на %s г.' % curr_date.strftime('%B %Y')
|
||||
return render(request, 'asuzr/table.html', {'table': table, 'title': title})
|
||||
|
||||
return table, additional_info
|
||||
|
||||
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'] or 0)
|
||||
|
||||
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, add_info = get_attendance_table(curr_date.year, curr_date.month, 'attendance-')
|
||||
RequestConfig(request, paginate={'per_page': 32}).configure(attendance_table)
|
||||
|
||||
orders_table = get_day_orders_table(curr_date, 'orders-')
|
||||
RequestConfig(request).configure(orders_table)
|
||||
|
||||
title = 'Таблица посещаемости на %s' % curr_date.strftime('%B %Y г')
|
||||
return render(request, 'asuzr/table2.html', {
|
||||
'table1': attendance_table,
|
||||
'table2': orders_table,
|
||||
'additional_info': add_info,
|
||||
'title': title})
|
||||
|
||||
@login_required
|
||||
def main(request, day, month, year):
|
||||
|
||||
@@ -30,13 +30,17 @@
|
||||
table.paleblue tr.weekend {
|
||||
background-color: #FFE4E1
|
||||
}
|
||||
.inline {
|
||||
display: inline-block;
|
||||
vertical-align: top;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="breadcrumbs">
|
||||
{% block menu %}
|
||||
<ul id="menu" class="hr">
|
||||
<li><a href={% url 'asuzr-main' 1 5 2015 %}>Таблица посещаемости</a></li>
|
||||
<li><a href={% url 'asuzr.views.visit_view' %}>Таблица посещаемости</a></li>
|
||||
<li><a href={% url 'asuzr.views.orders' 0 %}>Таблица выхода заказов</a></li>
|
||||
<li><a href={% url 'asuzr.views.orders' 1 %}>Архивная таблица</a></li>
|
||||
<li><a href={% url 'asuzr.views.desreport' %}>Отчет по дизайнерам</a></li>
|
||||
|
||||
24
templates/asuzr/table2.html
Normal file
24
templates/asuzr/table2.html
Normal file
@@ -0,0 +1,24 @@
|
||||
{% extends "asuzr/base.html" %}
|
||||
{% load inplace_edit %}
|
||||
{% load render_table from django_tables2 %}
|
||||
|
||||
{% block page %}
|
||||
<div class="inline"><div><h3>{{ table1.verbose_name }}</h3></div>{% render_table table1 %}</div>
|
||||
<div class="inline"><div><h3>{{ table2.verbose_name }}</h3></div>{% render_table table2 %}</div>
|
||||
{% if additional_info %}
|
||||
<div>
|
||||
<hr>
|
||||
<div>
|
||||
<h3>{{ additional_info.title }}</h3>
|
||||
</div>
|
||||
<div class="table-container">
|
||||
<table class="paleblue">
|
||||
{% for row in additional_info.rows %}
|
||||
<tr><td>{{ row.title }}</td><td>{{ row.value }}</td></tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
15
templates/asuzr/totals_table.html
Normal file
15
templates/asuzr/totals_table.html
Normal file
@@ -0,0 +1,15 @@
|
||||
{% extends "django_tables2/table.html" %}
|
||||
{% load django_tables2 %}
|
||||
{% load i18n %}
|
||||
{% block table.tfoot %}
|
||||
<tfoot>
|
||||
{% if table.summary %}
|
||||
<tr>
|
||||
{% for summary in table.summary %}
|
||||
<td> {{ summary }} </td>
|
||||
{% endfor %}
|
||||
</tr>
|
||||
{% endif %}
|
||||
</tfoot>
|
||||
{% endblock table.tfoot %}
|
||||
|
||||
@@ -1,60 +1,14 @@
|
||||
{% spaceless %}
|
||||
{% extends "asuzr/totals_table.html" %}
|
||||
{% load django_tables2 %}
|
||||
{% load i18n %}
|
||||
{% if table.page %}
|
||||
<div class="table-container">
|
||||
{% endif %}
|
||||
{% block table %}
|
||||
<table{% if table.attrs %} {{ table.attrs.as_html }}{% endif %}>
|
||||
{% nospaceless %}
|
||||
{% block table.thead %}
|
||||
<thead>
|
||||
<tr>
|
||||
{% for column in table.columns %}
|
||||
{% if column.orderable %}
|
||||
<th {{ column.attrs.th.as_html }}><a href="{% querystring table.prefixed_order_by_field=column.order_by_alias.next %}">{{ column.header }}</a></th>
|
||||
{% else %}
|
||||
<th {{ column.attrs.th.as_html }}>{{ column.header }}</th>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</tr>
|
||||
</thead>
|
||||
{% endblock table.thead %}
|
||||
{% block table.tbody %}
|
||||
<tbody>
|
||||
{% for row in table.page.object_list|default:table.rows %} {# support pagination #}
|
||||
{% block table.tbody.row %}
|
||||
<tr class="
|
||||
{% if row.date.is_weekend %}weekend{% else %}
|
||||
{{ forloop.counter|divisibleby:2|yesno:"even,odd" }}{% endif %}
|
||||
"> {# avoid cycle for Django 1.2-1.6 compatibility #}
|
||||
{% for column, cell in row.items %}
|
||||
<td {{ column.attrs.td.as_html }}>{% if column.localize == None %}{{ cell }}{% else %}{% if column.localize %}{{ cell|localize }}{% else %}{{ cell|unlocalize }}{% endif %}{% endif %}</td>
|
||||
{% endfor %}
|
||||
</tr>
|
||||
{% endblock table.tbody.row %}
|
||||
{% empty %}
|
||||
{% if table.empty_text %}
|
||||
{% block table.tbody.empty_text %}
|
||||
<tr><td colspan="{{ table.columns|length }}">{{ table.empty_text }}</td></tr>
|
||||
{% endblock table.tbody.empty_text %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
{% endblock table.tbody %}
|
||||
{% block table.tfoot %}
|
||||
<tfoot>
|
||||
{% if table.summary %}
|
||||
<tr>
|
||||
{% for summary in table.summary %}
|
||||
<td> {{ summary }} </td>
|
||||
{% block table.tbody.row %}
|
||||
<tr class="
|
||||
{% if row.date.is_weekend %}weekend{% else %}
|
||||
{{ forloop.counter|divisibleby:2|yesno:"even,odd" }}{% endif %}
|
||||
"> {# avoid cycle for Django 1.2-1.6 compatibility #}
|
||||
{% for column, cell in row.items %}
|
||||
<td {{ column.attrs.td.as_html }}>{% if column.localize == None %}{{ cell }}{% else %}{% if column.localize %}{{ cell|localize }}{% else %}{{ cell|unlocalize }}{% endif %}{% endif %}</td>
|
||||
{% endfor %}
|
||||
</tr>
|
||||
{% endif %}
|
||||
</tfoot>
|
||||
{% endblock table.tfoot %}
|
||||
{% endnospaceless %}
|
||||
</table>
|
||||
{% endblock table %}
|
||||
</tr>
|
||||
{% endblock table.tbody.row %}
|
||||
|
||||
{% endspaceless %}
|
||||
|
||||
Reference in New Issue
Block a user