diff --git a/asuzr/models.py b/asuzr/models.py
index 386ef89..900078b 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 995687e..5a57d58 100644
--- a/asuzr/tables.py
+++ b/asuzr/tables.py
@@ -1,34 +1,46 @@
# -*- 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)
- print 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 TestTable(tables.Table):
- name = EditableColumn('name', "Наименование")
- prod_period = EditableColumn('prod_period', "Время производства")
-
- class Meta:
- model = Product
- attrs = {"class": "paleblue"}
-
class OrdersTable(tables.Table):
date = tables.DateColumn('d/m/Y', verbose_name = 'Дата')
deadline = tables.DateColumn('d/m/Y/', verbose_name = 'Срок сдачи')
@@ -78,6 +90,7 @@ class ArchiveOrdersTable(OrdersTable):
class Meta:
attrs = {'class': 'paleblue'}
+ empty_text = 'Архивных заказов нет'
class DesignerTable(tables.Table):
full_name = tables.Column(empty_values=(), verbose_name = 'Дизайнер')
@@ -93,9 +106,31 @@ class DesignerTable(tables.Table):
class Meta:
attrs = {'class': 'paleblue'}
+ class Meta:
+ attrs = {'class': 'paleblue'}
+
class SketchesTable(tables.Table):
sketch_file = tables.FileColumn(verbose_name = 'Имя файла')
sketch_image = ThumbnailColumn('sketch_file', verbose_name = 'Эскиз', orderable = False)
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 6d35b40..6647c6a 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):
if day == None:
diff --git a/record/settings.py b/record/settings.py
index f44e9bc..f0d872e 100644
--- a/record/settings.py
+++ b/record/settings.py
@@ -69,7 +69,7 @@ DATABASES = {
# Internationalization
# https://docs.djangoproject.com/en/1.6/topics/i18n/
-LANGUAGE_CODE = 'en-us'
+LANGUAGE_CODE = 'ru-ru'
TIME_ZONE = 'Asia/Yekaterinburg'
diff --git a/record/urls.py b/record/urls.py
index 24d1c3a..3159aab 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'),