Ejemplo n.º 1
0
def videoPage(request):
    kwParams = {
        'MEDIA_URL':
        MEDIA_URL,
        'homeURL': (isLocalEnvironment() and ECC.LOCAL_ROOT_URL
                    or ECC.SAE_ROOT_URL)
    }
    return HttpResponse(render_to_response("video.html", kwParams))
Ejemplo n.º 2
0
def homePage(request):
    addPageView()  # 页面访问量+1
    sysTime = getSysTime("%Y-%m-%d %H:%M:%S")  # 获取当前系统时间
    send_email_cnt = 10

    kwParams = {
        'MEDIA_URL':
        MEDIA_URL,
        'title':
        'Welcome to Exp\'s Home',
        'url_album':
        (isLocalEnvironment() and ECC.LOCAL_ROOT_URL or ECC.SAE_ROOT_URL) +
        "album",
        'url_blog':
        (isLocalEnvironment() and ECC.LOCAL_ROOT_URL or ECC.SAE_ROOT_URL) +
        "blog",
        'ip':
        getRemoteIp(request),
        'pageview':
        getPageView(),
        'datetime':
        sysTime,
        'email_cnt':
        send_email_cnt - getPageView() % send_email_cnt,
        'email_msg':
        sendNotifyMail(send_email_cnt) and '发送 [通知邮件] 成功!' or '',
    }

    # 访问记录入库
    db_msg = '访问记录入库失败'
    mysqlDB = UseMysqlDB()
    if mysqlDB.connect(ECC.CHAARSET_DB, **getDbParams(ECC.DB_TYPE_MYSQL)):
        insertSql = "".join([
            "insert into t_visit_log(c_ip, d_time, c_remark) values('",
            " -> ".join(str(getTrueRemoteIp(request)).split(", ")), "', '",
            sysTime, "', '",
            kwParams.get('email_msg') and '触发邮件发送' or '一般网页浏览', "')"
        ])

        if mysqlDB.insert(insertSql):
            mysqlDB.close()
            db_msg = '访问记录入库成功'

    kwParams['db_msg'] = db_msg
    return HttpResponse(render_to_response("index.html", kwParams))
Ejemplo n.º 3
0
def getDbParams(DBType='mysql'):
    from ExpPH.utils.BaseUtils import isLocalEnvironment
    import ExpPH.conf.Keys as ECK
    import ExpPH.conf.Consts as ECC

    # 数据库参数字典
    dbPms = {}

    # LOCAL 本地环境数据库
    if isLocalEnvironment():
        if DBType == ECC.DB_TYPE_MYSQL:
            dbPms = {
                ECK.DB_ENGINE: ECC.DB_ENGINE_MYSQL,  # 数据库引擎
                ECK.DB_NAME: 'ExpPH',  # 数据库名称
                ECK.DB_USER: '******',  # 账户
                ECK.DB_PSWD: 'root',  # 密码
                ECK.DB_IP_M: '127.0.0.1',  # 主服务器IP
                ECK.DB_IP_S: '127.0.0.1',  # 从服务器IP
                ECK.DB_PORT: '3306',  # 端口
            }

        elif DBType == ECC.DB_TYPE_SQLITE:
            dbPms = {
                ECK.DB_ENGINE: ECC.DB_ENGINE_SQLITE,  # 数据库引擎
                ECK.DB_NAME: './static/data/expphDB.sqlite3',  # 数据库名称
                ECK.DB_USER: '',  # 账户
                ECK.DB_PSWD: '',  # 密码
                ECK.DB_IP_M: '',  # 主服务器IP
                ECK.DB_IP_S: '',  # 从服务器IP
                ECK.DB_PORT: '',  # 端口
            }

        elif DBType == ECC.DB_TYPE_ORACLE:
            pass

        else:
            pass

    # SAE 环境,暂时只支持mysql数据库
    else:
        import sae.const
        dbPms = {
            ECK.DB_ENGINE: ECC.DB_ENGINE_MYSQL,  # 数据库引擎
            ECK.DB_NAME: sae.const.MYSQL_DB,  # 数据库名称
            ECK.DB_USER: sae.const.MYSQL_USER,  # 账户
            ECK.DB_PSWD: sae.const.MYSQL_PASS,  # 密码
            ECK.DB_IP_M: sae.const.MYSQL_HOST,  # 主服务器IP
            ECK.DB_IP_S: sae.const.MYSQL_HOST_S,  # 从服务器IP
            ECK.DB_PORT: sae.const.MYSQL_PORT,  # 端口
        }

    return dbPms
Ejemplo n.º 4
0
def getPageView():
    # SAE环境,通过 KVDB 获取页面访问量
    if not isLocalEnvironment():
        kv = sae.kvdb.KVClient()
    # 本地环境,通过 本地kv.conf配置文件 获取页面访问量
    else:
        kv = LocalKVDB()

    pvv = kv.get(PAGE_VIEW)
    if not pvv:
        pvv = 0

    return int(str(pvv).strip())
Ejemplo n.º 5
0
def bolgPage(request):
    blogs = BlogPost.objects  # 从数据库提取所有blog记录
    posts = blogs.all()
    
    # 提取需要显示的页面模板
    template = loader.get_template("BlogPage.html")
    
    # 把从数据库提取页面请求的记录,响应到页面显示
    title = "Welcome to Exp's Blog (Version:1.0.187.20140518 Beta)"
    
    # 首页地址
    homeURL = (isLocalEnvironment() and ECC.LOCAL_ROOT_URL or ECC.SAE_ROOT_URL)
    
    content = Context({'posts': posts, 'title': title, 'homeURL': homeURL})
    return HttpResponse(template.render(content))
Ejemplo n.º 6
0
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
BASE_DIR = os.path.dirname(os.path.dirname(__file__))

    
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/dev/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'gm(w6+h2wf$ngzs6a^1(7x86bqqah9@#9u*vtxk&27v2$3!i(p'

# SECURITY WARNING: don't run with debug turned on in production!

# 当搭建到服务器上时,为了安全需要关闭DEBUG模式,此时需要指定可以访问的主机和文件路径
from ExpPH.utils.BaseUtils import isLocalEnvironment
if isLocalEnvironment():
    DEBUG = True
    TEMPLATE_DEBUG = True
else:
    DEBUG = False
    TEMPLATE_DEBUG = False


ALLOWED_HOSTS = ['expph.sinaapp.com', 'localhost', '127.0.0.1']

# 添加模板搜索路径
TEMPLATE_DIRS = (
    # SAE后台管理站点的模板目录
    # '/usr/local/sae/python/lib/python2.7/site-packages/django/contrib/admin/templates/admin',
            
    # 根目录下的 templates