123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223 |
- # -*- coding: utf-8 -*-
- """
- demeter web page
- name:work.py
- author:rabin
- """
- from .__load__ import *
- class Work(object):
- @staticmethod
- def init(self, search={}):
- if 'set' in self.request.uri:
- self.data['work_cur'] = 'set'
- else:
- self.data['work_cur'] = 'index'
- self.data['url'] = Work.url()
- @staticmethod
- def url():
- config = {}
- config['index'] = '/work'
- config['set'] = '/work/set'
- return config
- class index_path(Load):
- @Web.auth
- @Web.setting
- def get(self):
- if 'url' in self.data:
- self.redirect(self.data['url'])
- mobile = Demeter.checkMobile(self.request)
- if mobile:
- self.redirect('/device')
- return
-
- Work.init(self)
- self.data['list'] = self.service('common').list('farm_work', search={'farm_id':self.data['setting']['farm']})
- if self.data['list']:
- for key, value in enumerate(self.data['list']):
- self.data['list'][key]['workdates'] = Demeter.date(value['workdate'], '%Y-%m-%d %H:%M')
- category = self.service('common').one('farm_work_category', id=value['category_id'])
- self.data['list'][key]['category'] = category['name']
- method = self.service('common').one('farm_work_method', id=value['method_id'])
- self.data['list'][key]['method'] = method['name']
- land = self.service('common').one('farm_work_land', id=value['land_id'])
- self.data['list'][key]['land'] = land['name']
- self.view("work/index.html")
- class update_path(Load):
- @Web.auth
- @Web.setting
- def get(self):
- id = self.input('id')
- self.data['category'] = self.service('common').list('farm_work_category', search={'farm_id':self.data['setting']['farm']})
- self.data['method'] = self.service('common').list('farm_work_method', search={'farm_id':self.data['setting']['farm']})
- self.data['land'] = self.service('common').list('farm_work_land', search={'farm_id':self.data['setting']['farm']})
- self.data['info'] = {}
- if id:
- self.data['info'] = self.service('common').one('farm_work', id=id)
- if self.data['info'] and self.data['info']['workdate']:
- self.data['info']['workdate'] = Demeter.date(self.data['info']['workdate'])
- self.view("work/update.html")
- @Web.auth
- @Web.setting
- def post(self):
- id = self.input('id')
- update = {}
- update['amount'] = self.input('update_amount')
- update['category_id'] = self.input('update_category_id')
- update['method_id'] = self.input('update_method_id')
- update['land_id'] = self.input('update_land_id')
- update['pic'] = self.input('update_pic')
- update['workdate'] = self.input('update_workdate')
- if not update['category_id']:
- self.out(u'请选择劳作类别')
- return
- if not update['method_id'] or update['method_id'] == '0' or update['method_id'] == 0:
- self.out(u'请选择劳作方式')
- return
- if not update['land_id']:
- self.out(u'请选择操作地块')
- return
- if not update['workdate']:
- self.out(u'请选择农事日期')
- return
- if not update['amount']:
- self.out(u'请输入劳作用量')
- return
- if not update['pic']:
- self.out(u'请选择图片')
- return
- state = self.service('common').update('farm_work', id, update)
- self.out('yes', {'state':state})
- @Web.auth
- @Web.setting
- def delete(self):
- id = self.input('id')
- if not id:
- self.out('no')
- return
- state = self.input('state', False)
- state = self.service('common').delete('farm_work', id, state)
- self.out('yes', {'state':state})
- class set_path(Load):
- @Web.auth
- @Web.setting
- def get(self):
- Work.init(self)
- self.data['category'] = self.service('common').list('farm_work_category', search={'farm_id':self.data['setting']['farm']})
- self.data['method'] = self.service('common').list('farm_work_method', search={'farm_id':self.data['setting']['farm']})
- self.data['land'] = self.service('common').list('farm_work_land', search={'farm_id':self.data['setting']['farm']})
- self.view("work/set.html")
- class land_update_path(Load):
- @Web.auth
- @Web.setting
- def get(self):
- id = self.input('id')
- self.data['info'] = {}
- if id:
- self.data['info'] = self.service('common').one('farm_work_land', id=id)
- self.view("work/land_update.html")
- @Web.auth
- @Web.setting
- def post(self):
- id = self.input('id')
- update = {}
- update['name'] = self.input('update_name')
- if not update['name']:
- self.out(u'请输入地块名称')
- return
- state = self.service('common').update('farm_work_land', id, update)
- self.out('yes', {'state':state})
- @Web.auth
- @Web.setting
- def delete(self):
- id = self.input('id')
- if not id:
- self.out('no')
- return
- state = self.input('state', False)
- state = self.service('common').delete('farm_work_land', id, state)
- self.out('yes', {'state':state})
- class category_update_path(Load):
- @Web.auth
- @Web.setting
- def get(self):
- id = self.input('id')
- self.data['info'] = {}
- if id:
- self.data['info'] = self.service('common').one('farm_work_category', id=id)
- self.view("work/category_update.html")
- @Web.auth
- @Web.setting
- def post(self):
- id = self.input('id')
- update = {}
- update['name'] = self.input('update_name')
- if not update['name']:
- self.out(u'请输入农事内容分类名称')
- return
- state = self.service('common').update('farm_work_category', id, update)
- self.out('yes', {'state':state})
- @Web.auth
- @Web.setting
- def delete(self):
- id = self.input('id')
- if not id:
- self.out('no')
- return
- state = self.input('state', False)
- state = self.service('common').delete('farm_work_category', id, state)
- self.out('yes', {'state':state})
- class method_update_path(Load):
- @Web.auth
- @Web.setting
- def get(self):
- id = self.input('id')
- self.data['category'] = self.input('category')
- self.data['info'] = {}
- if id:
- self.data['info'] = self.service('common').one('farm_work_method', id=id)
- self.view("work/method_update.html")
- @Web.auth
- @Web.setting
- def post(self):
- id = self.input('id')
- update = {}
- update['name'] = self.input('update_name')
- update['category_id'] = self.input('update_category_id')
- if not update['name']:
- self.out(u'请输入农事内容名称')
- return
- if not update['category_id']:
- self.out(u'请选择农事分类')
- return
- state = self.service('common').update('farm_work_method', id, update)
- self.out('yes', {'state':state})
- @Web.auth
- @Web.setting
- def delete(self):
- id = self.input('id')
- if not id:
- self.out('no')
- return
- state = self.input('state', False)
- state = self.service('common').delete('farm_work_method', id, state)
- self.out('yes', {'state':state})
|