#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
    demeter web page
    name:main.py
    author:rabin
"""
from __load__ import *

class index_path(Load):
	def get(self):
		id = self.input('id')
		if not id:
			self.redirect('/')
		self.data['info'] = self.service('common').one('farm', id=id)
		self.data['product'] = self.service('common').list('farm_product', search={'farm_id':id, 'status':True}, limit='0,8')
		self.data['env'] = self.service('common').list('farm_env', search={'farm_id':id}, order='inorder asc,cdate desc', limit='0,5')
		if self.data['env']:
			for key, value in enumerate(self.data['env']):
				info = self.service('common').one('device_info', id=value['device_id'])
				#info['value'] = Demeter.exp(info['out_exp'], info['value'])
				self.data['env'][key]['device'] = info
				info = self.service('common').one('device_type', id=value['type_id'])
				self.data['env'][key]['type'] = info

		mobile = Demeter.checkMobile(self.request)
		if mobile:
			path = 'mobile/'
		else:
			path = ''
		self.view(path + "farm.html")