示例#1
0
 def initialize(self):
     self.mdb = MVeglib()
     self.tmpl_name="tplite"
示例#2
0
class VeglibHandler(BaseHandler):
    def initialize(self):
        self.mdb = MVeglib()
        self.tmpl_name="tplite"

    def get(self, input=''):
        if len(input) > 0:
            ip_arr = input.split(r'/')
        if input == '':
            self.viewall()
        elif (input == 'find'):
            self.to_find()
        elif ( input == 'add'):
            self.to_add()
        elif (ip_arr[0] == 'modify'):
            self.to_modify(ip_arr[1])
        elif (ip_arr[0] == 'delete'):
            self.delete(ip_arr[1])
        else:
            self.viewit(input)

    def post(self, input=''):

        if len(input) > 0:
            ip_arr = input.split(r'/')
        if input == 'add':
            uuid = self.add()
        elif ip_arr[0] == 'modify':
            self.modifyit(ip_arr[1])
        elif input == 'find_sheng':
            self.find_sheng()
        elif input == 'find_ke':
            self.find_ke()
        elif input == 'find_shu':
            self.find_shu()
        elif input == 'find_zhong':
            self.find_zhong()
        self.viewit(uuid)

    def find_sheng(self):
        b = self.get_argument('province')
        c = self.mdb.find_data('province', b)
        kwd = {
            'pager': '',
        }
        self.render('{0}/veglib/list.html'.format(self.tmpl_name), recs=c, kwd=kwd)


    def find_ke(self):


        b = self.get_argument('name')
        c = self.mdb.find_data('Ke_cn', b)
        kwd = {
            'pager': '',

        }
        self.render('{0}/veglib/list.html'.format(self.tmpl_name), recs=c, kwd=kwd)

    def find_shu(self):

        b = self.get_argument('shuname')
        c = self.mdb.find_data('Shu_cn', b)
        kwd = {
            'pager': '',

        }
        self.render('{0}/veglib/list.html'.format(self.tmpl_name), recs=c, kwd=kwd)

    def find_zhong(self):

        a = self.request.arguments
        b = self.get_argument('zhongname')
        c = self.mdb.find_data('Zhong_cn', b)
        kwd = {
            'pager': '',

        }
        self.render('{0}/veglib/list.html'.format(self.tmpl_name), recs=c, kwd=kwd)

    @tornado.web.authenticated
    def delete(self, del_id):
        self.mdb.delete(del_id)
        self.redirect('/veglib/')

    @tornado.web.authenticated
    def to_modify(self, par):
        self.render('{0}/veglib/modify.html'.format(self.tmpl_name),
                    rec=self.mdb.get_by_id(par))

    def viewall(self):
        recs = self.mdb.get_all()
        kwd = {'pager': '', }
        self.render('{0}/veglib/list.html'.format(self.tmpl_name),
                    recs=recs,
                    wd=kwd)


    def viewit(self, input):
        a = self.mdb.get_by_id(input)
        kwd = {
            'pager': '',
        }
        self.render('{0}/veglib/viewone.html'.format(self.tmpl_name), view=a, kwd=kwd)

    @tornado.web.authenticated
    def modifyit(self, uid):
        post_data = {}
        for key in self.request.arguments:
            post_data[key] = self.get_arguments(key)

        uu = self.mdb.modify(uid, post_data)
        self.viewit(uid)

    def to_find(self):
        kwd = {
            'pager': '',
        }
        self.render('{0}/veglib/find.html'.format(self.tmpl_name), kwd=kwd)

    @tornado.web.authenticated
    def to_add(self):
        kwd = {
            'pager': '',
        }
        self.render('{0}/veglib/add.html'.format(self.tmpl_name), kwd=kwd)

    @tornado.web.authenticated
    def add(self):
        post_data = {}
        for key in self.request.arguments:
            post_data[key] = self.get_arguments(key)

        uid = self.mdb.addata(post_data)
        self.viewit(uid)