Skip to content

Commit

Permalink
why ignore base.py ?
Browse files Browse the repository at this point in the history
  • Loading branch information
mailgyc-163 committed Feb 18, 2019
1 parent 96d65db commit 1e5fc9a
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 3 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,3 @@ htmlcov/
nosetests.xml
coverage.xml
*,cover

# personal file
base.py
46 changes: 46 additions & 0 deletions doudizhu/contrib/handlers/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import json
from concurrent.futures import ThreadPoolExecutor

from tornado.escape import json_encode
from tornado.web import RequestHandler

from contrib.db import AsyncConnection


class BaseHandler(RequestHandler):

@property
def db(self) -> AsyncConnection:
return self.application.db

@property
def executor(self) -> ThreadPoolExecutor:
return self.application.executor

@property
def client_ip(self):
headers = self.request.headers
return headers.get('X-Forwarded-For', headers.get('X-Real-Ip', self.request.remote_ip))

def data_received(self, chunk):
pass

def get_query_params(self, name, default=None, strip=True):
if not hasattr(self, 'query_params'):
query_params = json.loads(self.request.body.decode('utf-8'))
setattr(self, 'query_params', query_params)
return self.query_params.get(name, default)

def get_current_user(self):
return self.get_secure_cookie('user')

def set_current_user(self, uid, username):
info = {
'uid': uid,
'username': username,
}
self.set_secure_cookie('user', json_encode(info))

def on_finish(self):
# self.session.flush()
pass
13 changes: 13 additions & 0 deletions doudizhu/settings/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import os

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
PROJECT_DIR = os.path.dirname(BASE_DIR)

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')

TEMPLATE_ROOT = os.path.join(BASE_DIR, 'templates')

DEBUG = True

PORT = 8080

0 comments on commit 1e5fc9a

Please sign in to comment.