예제 #1
0
def showSettings(request):

    db = connectBlogDatabase(request)
    info = db.infos.find_one()

    if request.method == 'GET':#'POST'
        return render_admin_and_back(request, 'blog-settings.html', {
            'page': u'管理 - 设置',
            'theme': info.get('Theme'),
            'themes': getThemes(),
            'subtitle': info.get('Subtitle'),
            'description': info.get('Description'),
            'customRss': info.get('CustomRss'),
            'articlesPerPage': info.get('ArticlesPerPage'),
            'defaultTimezone': info.get('DefaultTimezone'),
            'defaultTimezoneOffset': info.get('DefaultTimezoneOffset'),
            'selection': 'blog-settings',
            })

    elif request.method == 'POST':

        d = request.POST

        update = {
            'Theme': d['blog-theme'],
            'Title': d['blog-title'],
            'Subtitle': d['blog-subtitle'],
            'Description': d['blog-description'],
            'CustomRss': d['blog-customRss'],
            'ArticlesPerPage': int(d['blog-articles-per-page']),
            'DefaultTimezone': d['blog-default-timezone'],
            'DefaultTimezoneOffset': d['blog-default-timezone-offset'],
        }

        # 时区和其与UTC的偏差
        timezone = d['blog-default-timezone']
        offset = d['blog-default-timezone-offset']
        if getTimezoneObject(timezone, offset):
            update['Timezone'] = timezone
            update['TimezoneOffset'] = offset

        db.infos.update(info, {'$set':update})

        return redirect(request, '设置保存成功', 'admin/')
예제 #2
0
def getArticleContent(d, postOn=None):
    """
    取得表单中文章的内容
    """
    if d["title"] is None or d["content"] is None:
        return None, "标题与正文都不能为空"

    a = {"Title": d["title"], "Content": d["content"]}

    def split_and_strip(s):
        return [i.strip() for i in s.split(",") if i != ""]

    a["Categories"] = split_and_strip(d["categories"])
    a["Tags"] = split_and_strip(d["tags"])

    postOn = postOn or datetime.utcnow()
    a["PostOn"] = postOn

    # 时区相关
    if d["use-default-timezone"] == "false":
        timezone = d.get("timezone")
        offset = d.get("timezone-offset")

        # 验证时区是否有效
        tz = getTimezoneObject(timezone, offset)
        if tz is not None:
            a["Timezone"] = timezone
            a["TimezoneOffset"] = offset
            a["IsDst"] = isDaylightSavingTime(tz, postOn)
        else:
            return None, "无效的时区"
    else:
        a["Timezone"] = None
        a["TimezoneOffset"] = None
        a["IsDst"] = None

    return a, None