예제 #1
0
def get_article_content(d, postOn=None):
    """
    取得表单中文章的内容
    """
    title = d.get('title')
    if title is None or title == '':
        return None, ERROR + '标题不能为空'

    content = d.get('content')
    if content is None or content == '':
        return None, ERROR + '正文都不能为空'

    is_public = d.get('is-set-public') == 'true'
    a = {
        'Title': title,
        'IsPublic': is_public,
        'Content': content if is_public else None,
        'HiddenContent': content if not is_public else None,
    }

    # 分类和Tags
    def split_and_strip(s):
        return [i.strip() for i in s.split(',') if i != '']

    categories = d.get('categories') or ''
    a['Categories'] = split_and_strip(d['categories'])

    tags = d.get('tags') or ''
    a['Tags'] = split_and_strip(d['tags'])

    # 发布时间
    if postOn is None or d.get('update-post-on') == 'true':
        postOn = datetime.utcnow()
    a['PostOn'] = postOn

    # 时区相关
    if d.get('use-default-timezone') != 'true':
        timezone = d.get('timezone')
        offset = d.get('timezone-offset')

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

    return a, None
예제 #2
0
def get_article_content(d, postOn = None):
    """
    取得表单中文章的内容
    """
    title = d.get('title')
    if title is None or title == '':
        return None, ERROR + '标题不能为空'

    content = d.get('content')
    if content is None or content == '':
        return None, ERROR + '正文都不能为空'

    is_public = d.get('is-set-public') == 'true'
    a = {
        'Title': title,
        'IsPublic': is_public,
        'Content': content if is_public else None,
        'HiddenContent': content if not is_public else None,
    }

    # 分类和Tags
    def split_and_strip(s):
        return [i.strip() for i in s.split(',') if i!='' ]

    categories = d.get('categories') or ''
    a['Categories'] = split_and_strip(d['categories'])

    tags = d.get('tags') or ''
    a['Tags'] = split_and_strip(d['tags'])

    # 发布时间
    if postOn is None or d.get('update-post-on') == 'true':
        postOn = datetime.utcnow()
    a['PostOn'] = postOn

    # 时区相关
    if d.get('use-default-timezone') != 'true':
        timezone = d.get('timezone')
        offset = d.get('timezone-offset')

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

    return a, None
예제 #3
0
def show_settings(request):
    db = connect_blog_database(request)
    info = db.infos.find_one()

    if request.method == 'GET':
        return render_admin_and_back(
            request, 'blog-settings.html', {
                'page': u'管理 - 设置',
                'theme': info.get('Theme'),
                'themes': get_themes(),
                '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 get_timezone_object(timezone, offset):
            update['Timezone'] = timezone
            update['TimezoneOffset'] = offset

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

        return redirect(request, '设置保存成功', 'admin/')
예제 #4
0
def show_settings(request):
    db = connect_blog_database(request)
    info = db.infos.find_one()

    if request.method == 'GET':
        return render_admin_and_back(request, 'blog-settings.html', {
            'page': u'管理 - 设置',
            'theme': info.get('Theme'),
            'themes': get_themes(),
            '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 get_timezone_object(timezone, offset):
            update['Timezone'] = timezone
            update['TimezoneOffset'] = offset

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

        return redirect(request, '设置保存成功', 'admin/')