123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246 |
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- """
- demeter web page
- name:main.py
- author:rabin
- """
- from .__load__ import *
- class Farm(object):
- @staticmethod
- def init(self, search={}):
- if 'edit' in self.request.uri:
- self.data['farm_cur'] = 'edit'
- elif 'product' in self.request.uri:
- self.data['farm_cur'] = 'product'
- elif 'env' in self.request.uri:
- self.data['farm_cur'] = 'env'
- else:
- self.data['farm_cur'] = 'index'
- self.data['url'] = Farm.url()
- @staticmethod
- def url():
- config = {}
- config['info'] = '/'
- config['edit'] = '/main/edit'
- config['product'] = '/main/product'
- config['env'] = '/main/env'
- 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
- Farm.init(self)
- self.view("farm/index.html")
- @Web.auth
- @Web.setting
- def post(self):
- id = self.data['setting']['farm']
- update = {}
- update['info'] = self.input('update_info')
- if not update['info']:
- self.out(u'请输入农场介绍')
- return
- state = self.service('common').update('farm', id, update)
- self.out('修改成功')
- class edit_path(Load):
- @Web.auth
- @Web.setting
- def get(self):
- Farm.init(self)
- self.view("farm/edit.html")
- @Web.auth
- @Web.setting
- def post(self):
- id = self.data['setting']['farm']
- update = {}
- update['name'] = self.input('update_name')
- update['pic'] = self.input('update_pic')
- update['location'] = self.input('update_location')
- update['master_name'] = self.input('update_master_name')
- update['master_pic'] = self.input('update_master_pic')
- update['tel'] = self.input('update_tel')
- update['address'] = self.input('update_address')
- update['welcome'] = self.input('update_welcome')
- if not update['name']:
- self.out(u'请输入名称')
- return
- if not update['pic']:
- self.out(u'请选择图片')
- return
- if not update['location']:
- self.out(u'请输入位置')
- return
- if not update['master_name']:
- self.out(u'请输入姓名')
- return
- if not update['master_pic']:
- self.out(u'请选择图片')
- return
- if not update['tel']:
- self.out(u'请输入联系电话')
- return
- if not update['address']:
- self.out(u'请输入联系地址')
- return
- state = self.service('common').update('farm', id, update)
- self.out('修改成功')
- @Web.auth
- @Web.setting
- def delete(self):
- id = self.input('id')
- if not id:
- self.out('no')
- return
- state = self.service('common').rDelete('farm', id)
- self.out('yes', {'state':state})
- class product_path(Load):
- @Web.auth
- @Web.setting
- def get(self):
- Farm.init(self)
- self.data['list'] = self.service('common').list('farm_product', search={'farm_id':self.data['setting']['farm']})
- self.view("farm/product.html")
- class product_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_product', id=id)
- self.view("farm/product_update.html")
- @Web.auth
- @Web.setting
- def post(self):
- id = self.input('id')
- update = {}
- update['name'] = self.input('update_name')
- update['pic'] = self.input('update_pic')
- update['area'] = self.input('update_area')
- update['yields'] = self.input('update_yields')
- update['charact'] = self.input('update_charact')
- update['notice'] = self.input('update_notice')
- if not update['name']:
- self.out(u'请输入名称')
- return
- if not update['area']:
- self.out(u'请输入种植面积')
- return
- if not update['yields']:
- self.out(u'请输入平均亩产')
- return
- """
- if not update['charact']:
- self.out(u'请输入特点')
- return
- if not update['notice']:
- self.out(u'请输入使用须知')
- return
- """
- if not update['pic']:
- self.out(u'请选择图片')
- return
- state = self.service('common').update('farm_product', 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', '1')
- update = {}
- if state == '1':
- update['status'] = True
- else:
- update['status'] = False
- state = self.service('common').update('farm_product', id, update)
- self.out('yes', {'state':state})
- class env_path(Load):
- @Web.auth
- @Web.setting
- def get(self):
- Farm.init(self)
- self.data['list'] = self.service('common').list('farm_env', order='inorder asc,cdate desc', search={'farm_id':self.data['setting']['farm']})
- if self.data['list']:
- for key, value in enumerate(self.data['list']):
- info = self.service('common').one('device_info', id=value['device_id'])
- self.data['list'][key]['device'] = info
- info = self.service('common').one('device_type', id=value['type_id'])
- self.data['list'][key]['type'] = info
- self.view("farm/env.html")
- class env_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_env', id=id)
- self.data['gateway'] = self.service('common').list('device_gateway', search={'farm_id':self.data['setting']['farm']})
- self.data['device'] = Device.getByGateway(self, search={'hardware_type' : 2,'farm_id':self.data['setting']['farm']})
- self.view("farm/env_update.html")
- @Web.auth
- @Web.setting
- def post(self):
- id = self.input('id')
- update = {}
- update['name'] = self.input('update_name')
- update['device_id'] = self.input('update_device_id')
- update['inorder'] = self.input('update_inorder', 0)
- if not update['name']:
- self.out(u'请输入环境名称')
- return
- if not update['device_id']:
- self.out(u'请选择设备')
- return
- if not update['inorder']:
- update['inorder'] = 0
- """
- if update['inorder'] and not Check.number(update['inorder']):
- self.out(u'排序必须是数字')
- return
- """
- device = self.service('common').one('device_info', id=update['device_id'])
- if not device:
- self.out(u'请选择设备')
- return
- update['type_id'] = device['type_id']
- state = self.service('common').update('farm_env', 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').rDelete('farm_env', id)
- self.out('yes', {'state':state})
|