python学习
This commit is contained in:
@@ -57,4 +57,11 @@ def iPagination( params ):
|
||||
def ops_render( template,context = {} ):
|
||||
if 'current_user' in g:
|
||||
context['current_user'] = g.current_user
|
||||
return render_template( template,**context )
|
||||
return render_template( template,**context )
|
||||
|
||||
'''
|
||||
获取当前时间
|
||||
'''
|
||||
def getCurrentDate( format = "%Y-%m-%d %H:%M:%S"):
|
||||
#return datetime.datetime.now().strftime( format )
|
||||
return datetime.datetime.now()
|
||||
|
||||
37
common/libs/LogService.py
Normal file
37
common/libs/LogService.py
Normal file
@@ -0,0 +1,37 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from flask import request,g
|
||||
from application import app,db
|
||||
import json
|
||||
from common.libs.Helper import getCurrentDate
|
||||
from common.models.log.AppAccessLog import AppAccessLog
|
||||
from common.models.log.AppErrorLog import AppErrorLog
|
||||
|
||||
class LogService():
|
||||
@staticmethod
|
||||
def addAccessLog():
|
||||
target = AppAccessLog()
|
||||
target.target_url = request.url
|
||||
target.referer_url = request.referrer
|
||||
target.ip = request.remote_addr
|
||||
target.query_params = json.dumps( request.values.to_dict() )
|
||||
if 'current_user' in g and g.current_user is not None:
|
||||
target.uid = g.current_user.uid
|
||||
target.ua = request.headers.get( "User-Agent" )
|
||||
target.created_time = getCurrentDate()
|
||||
db.session.add( target )
|
||||
db.session.commit( )
|
||||
return True
|
||||
|
||||
@staticmethod
|
||||
def addErrorLog( content ):
|
||||
if 'favicon.ico' in request.url:
|
||||
return
|
||||
target = AppErrorLog()
|
||||
target.target_url = request.url
|
||||
target.referer_url = request.referrer
|
||||
target.query_params = json.dumps(request.values.to_dict())
|
||||
target.content = content
|
||||
target.created_time = getCurrentDate()
|
||||
db.session.add(target)
|
||||
db.session.commit()
|
||||
return True
|
||||
@@ -1,5 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import time
|
||||
from application import app
|
||||
class UrlManager(object):
|
||||
def __init__(self):
|
||||
pass
|
||||
@@ -10,6 +11,7 @@ class UrlManager(object):
|
||||
|
||||
@staticmethod
|
||||
def buildStaticUrl(path):
|
||||
ver = "%s"%( 22222222 )
|
||||
release_version = app.config.get('RELEASE_VERSION')
|
||||
ver = "%s" % (int(time.time())) if not release_version else release_version
|
||||
path = "/static" + path + "?ver=" + ver
|
||||
return UrlManager.buildUrl( path )
|
||||
@@ -1,8 +1,7 @@
|
||||
# coding: utf-8
|
||||
from sqlalchemy import BigInteger, Column, DateTime, Integer, String, Text
|
||||
from sqlalchemy.schema import FetchedValue
|
||||
from application import db
|
||||
|
||||
from application import db
|
||||
|
||||
|
||||
class AppAccessLog(db.Model):
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
# coding: utf-8
|
||||
from sqlalchemy import Column, DateTime, Integer, String, Text
|
||||
from sqlalchemy.schema import FetchedValue
|
||||
from application import db
|
||||
|
||||
|
||||
|
||||
from application import db
|
||||
|
||||
|
||||
|
||||
class AppErrorLog(db.Model):
|
||||
|
||||
Reference in New Issue
Block a user