# -*- coding: utf-8 -*-
"""
    demeter web page
    name:origin.py 溯源相关页面
    author:rabin
"""
from .__load__ import *

class batch_path(Load):
	@Web.auth
	@Web.setting
	def get(self):
		self.set(
			name = u'溯源批次'
			,path = '/origin/batch'
			,width = '600'
			,height = '600'
			,add = False
			,edit = False
			,search = (('farm_id-select-','land_id-select-'), (u'选择农场',u'地块'))
			,thead = (u'所属农场', u'产品名称', u'种植时间', u'采收时间', u'地块')
			,tbody = ('farm','name', 'zzdate', 'csdate', 'land')
			,state = False
		)
		self.data['common']['search_farm_id-select-'] = Demeter.config['setting']['farmList']
		self.data['common']['search_land_id-select-'] = self.service('common').list('farm_work_land')
		self.list('origin_batch')
		if self.data['list']:
			for key, value in enumerate(self.data['list']):
				farm = self.service('common').one('farm', id=value['farm_id'])
				self.data['list'][key]['farm'] = farm['name']
				land = self.service('common').one('farm_work_land', id=value['land_id'])
				self.data['list'][key]['land'] = land['name']
		self.show('list')

class batch_update_path(Load):
	@Web.auth
	@Web.setting
	def get(self):
		self.set(
			path = '/origin/batch'
			,label = (u'所属农场',u'产品名称', u'种植时间',u'采收时间',u'设备网关',u'地块',u'图像记录')
			,update = ('farm_id-select-required','name-input-required', 'zzdate-date-required', 'csdate-date-required','gateway_id-select-required','land_id-select-required','pic-pic-required')
			,update_gateway_id = self.service('common').list('device_gateway', order='hardware_id asc')
			,update_land_id = self.service('common').list('farm_work_land')
			,update_farm_id = self.service('common').list('farm', search={'eros_status':2})
		)
		self.one('origin_batch')
		self.show('update')
	@Web.auth
	@Web.setting
	def post(self):
		self.update('origin_batch')
	@Web.auth
	@Web.setting
	def delete(self):
		self.drop('origin_batch')