Ejemplo n.º 1
0
def blogPostAdd(id):
    c = Column.objects(id=id).first()
    if request.method == 'GET':
        return render_template('admin/blogPostAdd.html',c=c)
    if request.method == 'POST':
        title = request.form['title'].strip()
        tags = request.form['tags'].strip()
        video = request.form['video'].strip()
        content = request.form['content']

        if not strLength(title,1,100):
            return jsonify({'status': False, 'info': u'请输入100个字符内的标题'})
        if not strLength(tags,1,60):
            return jsonify({'status': False, 'info': u'请至少输入1个标签,60个字符内'})
        if not strLength(video,0,500):
            return jsonify({'status': False, 'info': u'请至少500个字符内视频嵌入代码'})
        if not strLength(content,1,50000):
            return jsonify({'status': False, 'info': u'请输入50000个字符内的内容'})

        p = Post()
        p.title = title
        p.tags = getTagsFormStrTag(tags)
        p.tagSource = tags
        p.video = video
        p.content = content
        temp = getLeadAndCover(content)
        p.lead = temp[0]
        p.cover = temp[1]
        p.writeTime = getStrTime()
        p.column = c
        p.save()
        c.postCount += 1
        c.save()
        return jsonify({'status': True, 'info': u'文章添加成功'})
Ejemplo n.º 2
0
def creatNewKClass(title, author):
    data = {
        "meta": {
            "name": title,
            "author": author,
            "version": 1.0,
            "saveTime": getStrTime(),
            "backgroundColor": "#ffffff",
            "lineColor": "#555",
            "displayMode": "side",
        },
        "format": "node_tree",
        "data": {
            "id": "root",
            "topic": title,
            "background-color": "#ff2121",
            "foreground-color": "#ffffff",
            "topicType": "ordinary",
            "children": [],
        }
    }
    return data
Ejemplo n.º 3
0
def contact():
    if request.method == 'GET':
        return render_template('%s/contact.html' %
                               current_user.getCustom()['homeTemplate'],
                               mark='contact')
    elif request.method == 'POST':
        name = request.form['name']
        if not strLength(name, 1, 20):
            return jsonify({'status': False, 'info': u'请输入20个字符内的名字'})
        email = request.form['email']
        if not reEmail(email):
            return jsonify({'status': False, 'info': u'请输入正确的邮箱'})
        message = request.form['message']
        if not strLength(message, 1, 1000):
            return jsonify({'status': False, 'info': u'请输入1000个字符内的消息'})
        c = contactMessage()
        c.name = name
        c.email = email
        c.message = message
        c.at = getStrTime()
        c.save()
        return jsonify({'status': True, 'info': u'提交成功!'})
Ejemplo n.º 4
0
# -*- coding: utf-8 -*-
#Statistics article labels: executed at 24 PM per night
import os
from mongoengine import connect

from project.model.blog import Post
from project.model.user import User
from project.config import BaseConfig
from project.common.dataPreprocess import getStrTime
from project.common.filePreprocess import writeLog

info = getStrTime()
try:
    connect(BaseConfig.DBNAME, host=BaseConfig.DBHOST, port=BaseConfig.DBPORT)
    ps = Post.objects
    tags = {}
    for p in ps:
        for t in p.tags:
            if t in tags:
                tags[t] += 1
            else:
                tags[t] = 1
    user = User.objects.first()
    if user:
        user.custom['tags'] = tags
        user.save()
        info += ' | Article tag statistics: success'
    else:
        info += ' | Article label statistics: the system does not exist users'

except Exception as e:
Ejemplo n.º 5
0
# -*- coding: utf-8 -*-
#定时管理日志,如果日志文件大小超过50M清除日志内容


import os
from project.config import BaseConfig
from project.common.dataPreprocess import getStrTime
from project.common.filePreprocess import writeLog

if __name__ == '__main__':
    strTime = getStrTime()
    try:
        logs = os.listdir(BaseConfig.LOGS_PATH)
        for log in logs:
            path = os.path.join(BaseConfig.LOGS_PATH, log)
            #过滤掉crontab_,nginx.pid
            if 'crontab_' in log:continue
            if 'nginx.pid' == log:continue

            if 'mongodb' in log:
                if log != 'mongodb.log':
                    #删除因为重启而多生成的mongodb.log.....文件
                    os.remove(path)
                    continue
            #判断文件大小,如果超过50M,就重写文件为空
            size = os.path.getsize(path)
            if(size / 1000000) > 50.0:
                with open(path, 'w') as wf:
                    wf.write('%s | Logging greater than 50m, reset to empty\n' % strTime)
                writeLog(os.path.join(BaseConfig.LOGS_PATH, 'crontab_log.log'), strTime + ' | "%s":Logging greater than 50m, reset to empty'%log)