Skip to content

Commit

Permalink
Merge pull request #4 from jizhouli/master
Browse files Browse the repository at this point in the history
Modify: #3 add index page in handlers and handlers in templates

thanx to @jizhouli
  • Loading branch information
Ethan-Zhang committed Mar 18, 2016
2 parents 7507fb0 + 9b2a1bd commit 99a4f13
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 0 deletions.
2 changes: 2 additions & 0 deletions mownfish/handlers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@


import statinfo_handler
import index_handler

ROUTES = { 'mownfish':
[(r'/statinfo', statinfo_handler.StatInfoHandler),
(r'/', index_handler.IndexHandler),
],

}
54 changes: 54 additions & 0 deletions mownfish/handlers/index_handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright 2012 Ethan Zhang<http://github.com/Ethan-Zhang>
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.


import os
import time

import tornado.web
from tornado.web import HTTPError
from tornado.httpclient import AsyncHTTPClient

from mownfish.util.log import LOG

from base_handler import BaseHandler
from mownfish.error import ErrorCode as ECODE
from mownfish.error import ErrorMessage as EMSG
from mownfish.error import BaseError


class IndexHandler(BaseHandler):

def get(self):
try:
result = ('<h2>Hello Mownfish</h2>'
' It has never been so easy to create a tornado project')
self.finish(result)
self.set_accesslog_item('status', 'SUCCESS')

except BaseError as e:
LOG.error(e, exc_info=True)
self.finish({'code':e.e_code, 'msg': '%s' % e})
except Exception as e:
LOG.error(e, exc_info=True)
self.finish({'code':ECODE.DEFAULT, 'msg':
'Unknown'})

finally:
self.write_accesslog()


2 changes: 2 additions & 0 deletions mownfish/templates/module/handlers/__init__.py.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@


import statinfo_handler
import index_handler

ROUTES = { '$project_name':
[(r'/statinfo', statinfo_handler.StatInfoHandler),
(r'/', index_handler.IndexHandler),
],

}
54 changes: 54 additions & 0 deletions mownfish/templates/module/handlers/index_handler.py.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright 2012 Ethan Zhang<http://github.com/Ethan-Zhang>
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.


import os
import time

import tornado.web
from tornado.web import HTTPError
from tornado.httpclient import AsyncHTTPClient

from $project_name.util.log import LOG

from base_handler import BaseHandler
from $project_name.error import ErrorCode as ECODE
from $project_name.error import ErrorMessage as EMSG
from $project_name.error import BaseError


class IndexHandler(BaseHandler):

def get(self):
try:
result = ('<h2>Hello Mownfish</h2>'
' It has never been so easy to create a tornado project')
self.finish(result)
self.set_accesslog_item('status', 'SUCCESS')

except BaseError as e:
LOG.error(e, exc_info=True)
self.finish({'code':e.e_code, 'msg': '%s' % e})
except Exception as e:
LOG.error(e, exc_info=True)
self.finish({'code':ECODE.DEFAULT, 'msg':
'Unknown'})

finally:
self.write_accesslog()


0 comments on commit 99a4f13

Please sign in to comment.