diff --git a/asuzr/models.py b/asuzr/models.py
index c0a4d26..d16e5d7 100644
--- a/asuzr/models.py
+++ b/asuzr/models.py
@@ -19,7 +19,7 @@ class Schedule(models.Model):
designer = models.ForeignKey(User)
def __unicode__(self):
- return ', '.join((self.date.strftime('%d %b %Y'), self.designer.first_name,))
+ return ' '.join((self.designer.first_name, self.designer.last_name))
#Таблица посещаемости
class Attendance(models.Model):
diff --git a/asuzr/tables.py b/asuzr/tables.py
index ba83360..0fc5ae6 100644
--- a/asuzr/tables.py
+++ b/asuzr/tables.py
@@ -1,23 +1,44 @@
# -*- coding: utf-8 -*-
+from django.core.urlresolvers import reverse
from django.utils.safestring import mark_safe
+from django.utils.html import escape
import django_tables2 as tables
from models import *
-def editable(field_name):
- return '{{% load inplace_edit %}}\n\n{{% inplace_edit "record.{field}" auto_height = 1 %}}'.format(field = field_name)
-
-
class EditableColumn(tables.TemplateColumn):
- def __init__(self, field_name, *args, **kwargs):
+ def __init__(self, field_name, object_name = '', *args, **kwargs):
super(tables.TemplateColumn, self).__init__(*args, **kwargs)
- template = '{{% load inplace_edit %}}\n\n{{% inplace_edit "record.{field}" auto_height = 1 %}}'.format(field = field_name)
- self.template_code = template
+ template = '''
+ {{{{% load inplace_edit %}}}}
+
+ {main_part}
+ '''
+ main_part = ''
+ if object_name == '':
+ main_part = '''
+ {{% inplace_edit "record.{field}" auto_height = 1 %}}
+ '''
+ else:
+ main_part = '''
+ {{% if record.{object_name} %}}
+ {{% inplace_edit "record.{object_name}.{field}" auto_height = 1 %}}
+ {{% endif %}}
+ '''
+ template = template.format(main_part = main_part)
+
+ self.template_code = template.format(field = field_name, object_name = object_name)
class ThumbnailColumn(tables.TemplateColumn):
def __init__(self, field_name, *args, **kwargs):
super(tables.TemplateColumn, self).__init__(*args, **kwargs)
- template = '{{% load thumbnail %}}\n\n{{% thumbnail record.{field} "100x100" as im %}}
{{% endthumbnail %}}'.format(field = field_name)
+ template = '''
+ {{% load thumbnail %}}
+
+ {{% thumbnail record.{field} "100x100" as im %}}
+
+ {{% endthumbnail %}}
+ '''.format(field = field_name)
self.template_code = template
class OrdersTable(tables.Table):
@@ -77,3 +98,22 @@ class SketchesTable(tables.Table):
class Meta:
attrs = {'class': 'paleblue'}
+
+class VisitTable(tables.Table):
+ date = tables.Column(verbose_name = 'Дата')
+ week_day = tables.Column(verbose_name = 'День недели', accessor = 'date.weekday_name')
+ calls = EditableColumn('calls', 'attend' ,verbose_name = 'Звонки', accessor = 'attend.calls')
+ visits = EditableColumn('visits','attend', verbose_name = 'Посещения', accessor = 'attend.visits')
+ orders = tables.Column(verbose_name = 'Заказы', accessor = 'order.product__count')
+ cost = tables.Column(verbose_name = 'Стоимость', accessor = 'order.price__sum')
+ designer = tables.Column(verbose_name = 'Дизайнеры')
+
+ def render_orders(self, value, record):
+ return mark_safe('%s' % (
+ reverse('asuzr.views.visit_view'),
+ record['date'].strftime('%d.%m.%Y'),
+ escape(value),
+ ))
+
+ class Meta:
+ attrs = {'class': 'paleblue'}
diff --git a/asuzr/views.py b/asuzr/views.py
index 6268cd0..085492f 100644
--- a/asuzr/views.py
+++ b/asuzr/views.py
@@ -42,6 +42,42 @@ 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)
+
+ attend_list = Attendance.objects.filter(date__range = (sdate,edate))
+ for attend in attend_list:
+ month_days[attend.date.day]['attend'] = attend
+
+ order_list = Order.objects.filter(date__range = (sdate,edate))
+ order_list = order_list.values('date')
+ order_list = order_list.annotate(Count('product'), Sum('price'))
+
+ for order in order_list:
+ month_days[order['date'].day]['order'] = order
+
+ schedule = Schedule.objects.filter(date__range = (sdate,edate))
+
+ for designer in schedule:
+ day = designer.date.day
+ if 'designer' in month_days[day]:
+ month_days[day]['designer'] = '%s, %s' % (month_days[day]['designer'], designer)
+ else:
+ month_days[day]['designer'] = designer
+
+ print month_days
+
+ table = VisitTable(month_days.values())
+ RequestConfig(request, paginate={'per_page': 32}).configure(table)
+ title = 'Таблица посещаемости на %s г.' % curr_date.strftime('%B %Y')
+ return render(request, 'asuzr/table.html', {'table': table, 'title': title})
+
@login_required
def main(request, day, month, year):
d,m,y=int(day),int(month), int(year)
diff --git a/record/urls.py b/record/urls.py
index fabedd0..8de3484 100644
--- a/record/urls.py
+++ b/record/urls.py
@@ -15,6 +15,7 @@ urlpatterns = patterns('',
url(r'^product/$', 'asuzr.views.prod_list'),
url(r'^product/(?P\d+)/$', 'asuzr.views.prod_detail'),
url(r'^main/(?P\d+)/(?P\d+)/(?P\d+)/$', 'asuzr.views.main', name='asuzr-main'),
+ url(r'^visits/$', 'asuzr.views.visit_view'),
url(r'^orders/(?P\d+)/$', 'asuzr.views.orders',name='asuzr-orders'),
url(r'^desreport/$', 'asuzr.views.desreport'),
url(r'^production_table/(?P\d+)/$', 'asuzr.views.production_table'),