Explorar el Código

Исправлены конфликты

Anastasia hace 10 años
padre
commit
4abe7bbd92
Se han modificado 5 ficheros con 91 adiciones y 19 borrados
  1. 1 1
      asuzr/models.py
  2. 52 17
      asuzr/tables.py
  3. 36 0
      asuzr/views.py
  4. 1 1
      record/settings.py
  5. 1 0
      record/urls.py

+ 1 - 1
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):

+ 52 - 17
asuzr/tables.py

@@ -1,33 +1,45 @@
 # -*- 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 %}}<img src="{{{{ im.url }}}}">{{% endthumbnail %}}'.format(field = field_name)
-    self.template_code = template
+    template = '''
+                 {{% load thumbnail %}}
 
-class TestTable(tables.Table):
-    name = EditableColumn('name', "Наименование")
-    prod_period = EditableColumn('prod_period', "Время производства")
-
-    class Meta:
-        model = Product
-        attrs = {"class": "paleblue"}
+                 {{% thumbnail record.{field} "100x100" as im %}}
+                   <img src="{{{{ im.url }}}}">
+                 {{% endthumbnail %}}
+               '''.format(field = field_name)
+    self.template_code = template
 
 class OrdersTable(tables.Table):
   date = 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('<a href="%s?date=%s">%s</a>' % (
+			reverse('asuzr.views.visit_view'), 
+			record['date'].strftime('%d.%m.%Y'), 
+			escape(value),
+			))
+
+  class Meta:
+    attrs = {'class': 'paleblue'}

+ 36 - 0
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:

+ 1 - 1
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'
 

+ 1 - 0
record/urls.py

@@ -15,6 +15,7 @@ urlpatterns = patterns('',
     url(r'^product/$', 'asuzr.views.prod_list'),
     url(r'^product/(?P<prod_id>\d+)/$', 'asuzr.views.prod_detail'),
     url(r'^main/?(?P<day>\d+)?/?(?P<month>\d+)?/?(?P<year>\d+)?/$', 'asuzr.views.main', name='asuzr-main'),
+    url(r'^visits/$', 'asuzr.views.visit_view'),
     url(r'^orders/(?P<archive>\d+)/$', 'asuzr.views.orders',name='asuzr-orders'),
     url(r'^desreport/$', 'asuzr.views.desreport'),
     url(r'^production_table/(?P<order_id>\d+)/$', 'asuzr.views.production_table'),