# -*- coding: utf-8 -*-
"""
    demeter web page
    name:msg.py
    author:rabin
"""
from .__load__ import *

class index_path(Load):
	@Web.auth
	@Web.setting
	def get(self):
		self.data['list'] = self.service('common').list('msg', search={'farm_id':self.data['setting']['farm']}, page=True, order='status asc, cdate desc')
		if self.data['list']:
			for key, value in enumerate(self.data['list']):
				type_info = self.service('common').one('msg_type', id=value['type_id'])
				self.data['list'][key]['type'] = type_info['name']
				self.data['list'][key]['cdates'] = Demeter.date(value['cdate'])
				id = value['id']
				update = {}
				update['status'] = True
				self.service('common').update('msg', id, update, cdate=False)
		self.view("msg/index.html")