Example #1
0
def new(request):

    db = connect_blog_database(request)

    # 普通访问
    if request.method == 'GET':
        return render_admin_and_back(request, 'edit-link.html', {
            'page': u'新链接',
        })

    elif request.method == 'POST':

        d = request.POST
        order = int(d['link-order']) if d['link-order'] else 0
        update = {
            'Title': d['link-title'],
            'Address': d['link-address'],
            'Description': d['link-description'],
            'Order': order,
        }
        # 插入新的Link
        db.links.insert(update)

        # 对链接重新排序
        links = list(db.links.find(sort=[('Order', pymongo.ASCENDING)]))
        for i in xrange(0, len(links)):
            if links[i]['Order'] != i:
                db.links.update(links[i], {"$set": {'Order': i}})

        return redirect(request, '新建链接成功', 'admin/show-links/')
Example #2
0
def showPlugins(request):

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

    if request.method == 'GET':#'POST'
        return render_admin_and_back(request, 'blog-plugins.html', {
            'page': u'管理 - 插件',
            'weiboCode': info.get('WeiboCode'),
            'commentCode': info.get('CommentCode'),
            'latestCommentsCode': info.get('LatestCommentsCode'),
            'statisticsCode': info.get('StatisticsCode'),
            'statisticsCodeInHead': info.get('StatisticsCodeInHead'),
            'selection': 'blog-plugins',
            })

    elif request.method == 'POST':

        d = request.POST
        update = {
            'WeiboCode': d['weibo-code'],
            'CommentCode': d['blog-comment-code'],
            'LatestCommentsCode': d['blog-latest-comments-code'],
            'StatisticsCode': d['blog-statistics-code'],
            'StatisticsCodeInHead': d.get('blog-statistics-code-in-head')==u'on',
        }

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

        return redirect(request, '插件保存成功', 'admin/')
Example #3
0
def new(request):

    db = connect_blog_database(request)

    # 普通访问
    if request.method == 'GET':
        return render_admin_and_back(request, 'edit-category.html', {
            'page':u'新分类',
        })

    elif request.method == 'POST':

        d = request.POST
        order = int(d['category-order']) if d['category-order'] else 0
        update = {
            'Title':d['category-title'],
            'Description':d['category-description'],
            'Order': order,
            }
        # 插入新的Category
        db.categories.insert(update)

        # 对链接重新排序
        categories = list(db.categories.find(sort=[('Order', pymongo.ASCENDING)]))
        for i in xrange(0, len(categories)):
            if categories[i]['Order'] != i:
                db.categories.update(categories[i],  {"$set":{'Order': i}})

        return redirect(request, '新建分类成功', 'admin/show-categories/')
Example #4
0
def new(request):

    db = connect_blog_database(request)

    # 普通访问
    if request.method == 'GET':
        return render_admin_and_back(request, 'edit-link.html', {
            'page': u'新链接',
        })

    elif request.method == 'POST':

        d = request.POST
        order = int(d['link-order']) if d['link-order'] else 0
        update = {
            'Title':d['link-title'],
            'Address':d['link-address'],
            'Description':d['link-description'],
            'Order': order,
            }
        # 插入新的Link
        db.links.insert(update)

        # 对链接重新排序
        links = list(db.links.find(sort=[('Order', pymongo.ASCENDING)]))
        for i in xrange(0, len(links)):
            if links[i]['Order'] != i:
                db.links.update(links[i],  {"$set":{'Order': i}})

        return redirect(request, '新建链接成功', 'admin/show-links/')
Example #5
0
def new(request):

    db = connect_blog_database(request)

    # 普通访问
    if request.method == 'GET':
        return render_admin_and_back(request, 'edit-category.html', {
            'page': u'新分类',
        })

    elif request.method == 'POST':

        d = request.POST
        order = int(d['category-order']) if d['category-order'] else 0
        update = {
            'Title': d['category-title'],
            'Description': d['category-description'],
            'Order': order,
        }
        # 插入新的Category
        db.categories.insert(update)

        # 对链接重新排序
        categories = list(
            db.categories.find(sort=[('Order', pymongo.ASCENDING)]))
        for i in xrange(0, len(categories)):
            if categories[i]['Order'] != i:
                db.categories.update(categories[i], {"$set": {'Order': i}})

        return redirect(request, '新建分类成功', 'admin/show-categories/')
Example #6
0
def show_all(request):
    db = connect_blog_database(request)
    info = db.infos.find_one()
    categories = list(db.categories.find(sort=[('Order', pymongo.ASCENDING)]))
    for category in categories:
        category['Id'] = str(category['_id'])

    return render_admin_and_back(request, 'show-categories.html', {
        'page':u'分类',
        'categories':categories,
        'selection':'categories',
        })
Example #7
0
def show_all(request):
    db = connect_blog_database(request)
    info = db.infos.find_one()
    categories = list(db.categories.find(sort=[('Order', pymongo.ASCENDING)]))
    for category in categories:
        category['Id'] = str(category['_id'])

    return render_admin_and_back(request, 'show-categories.html', {
        'page': u'分类',
        'categories': categories,
        'selection': 'categories',
    })
Example #8
0
def show_all(request):

    db = connect_blog_database(request)
    info = db.infos.find_one()
    links = list(db.links.find(sort=[('Order', pymongo.ASCENDING)]))
    for link in links:
        link['Id'] = str(link['_id'])

    return render_admin_and_back(request, 'show-links.html', {
        'page': u'链接',
        'links': links,
        'selection': 'links',
    })
Example #9
0
def show_all(request):

    db = connect_blog_database(request)
    info = db.infos.find_one()
    links = list(db.links.find(sort=[('Order', pymongo.ASCENDING)]))
    for link in links:
        link['Id'] = str(link['_id'])

    return render_admin_and_back(request, 'show-links.html', {
        'page': u'链接',
        'links':links,
        'selection':'links',
        })
Example #10
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/')
Example #11
0
def edit(request, objectId):

    db = connect_blog_database(request)
    id = ObjectId(objectId)

    # 普通访问
    if request.method == 'GET':

        category = db.categories.find_one({'_id': id})
        return render_admin_and_back(request, 'edit-category.html', {
            'page': u'编辑分类',
            'category': category,
        })

    elif request.method == 'POST':

        d = request.POST
        order = int(d['category-order']) if d['category-order'] else 0
        update = {
            'Title': d['category-title'],
            'Description': d['category-description'],
            'Order': order,
        }
        # 取得所有Category
        categories = list(
            db.categories.find(sort=[('Order', pymongo.ASCENDING)]))

        # 创建或取得编辑中的Category
        category = filter(lambda i: i['_id'] == id, categories)[0]
        db.categories.update(category, {'$set': update})
        categories.remove(category)
        categories.insert(order, category)

        # 对所有链接重新排序
        for i in xrange(0, len(categories)):
            if categories[i]['Order'] != i:
                db.categories.update(categories[i], {"$set": {'Order': i}})

        # 更新所有文章的分类
        update_category_of_articles(db.articles, category, update)
        update_category_of_articles(db.hidden_articles, category, update)

        return redirect(request, '编辑分类成功', 'admin/show-categories/')
Example #12
0
def edit(request, objectId):

    db = connect_blog_database(request)
    id = ObjectId(objectId)

    # 普通访问
    if request.method == 'GET':

        category = db.categories.find_one({'_id':id})
        return render_admin_and_back(request, 'edit-category.html', {
            'page':u'编辑分类',
            'category': category,
            })

    elif request.method == 'POST':

        d = request.POST
        order = int(d['category-order']) if d['category-order'] else 0
        update = {
            'Title':d['category-title'],
            'Description':d['category-description'],
            'Order':order,
            }
        # 取得所有Category
        categories = list(db.categories.find(sort=[('Order', pymongo.ASCENDING)]))

        # 创建或取得编辑中的Category
        category = filter(lambda i: i['_id'] == id, categories)[0]
        db.categories.update(category, {'$set': update})
        categories.remove(category)
        categories.insert(order, category)

        # 对所有链接重新排序
        for i in xrange(0, len(categories)):
            if categories[i]['Order'] != i:
                db.categories.update(categories[i],  {"$set":{'Order': i}})

        # 更新所有文章的分类
        update_category_of_articles(db.articles, category, update)
        update_category_of_articles(db.hidden_articles, category, update)

        return redirect(request, '编辑分类成功', 'admin/show-categories/')
Example #13
0
def edit(request, objectId):

    db = connect_blog_database(request)
    id = ObjectId(objectId)

    # 普通访问
    if request.method == 'GET':
        link = db.links.find_one({'_id': id})
        return render_admin_and_back(request, 'edit-link.html', {
            'page': u'编辑链接',
            'link': link
        })

    elif request.method == 'POST':

        d = request.POST
        order = int(d['link-order']) if d['link-order'] else 0
        update = {
            'Title': d['link-title'],
            'Address': d['link-address'],
            'Description': d['link-description'],
            'Order': order,
        }
        # 取得所有链接
        links = list(db.links.find(sort=[('Order', pymongo.ASCENDING)]))

        # 创建或取得编辑中的Link
        link = filter(lambda i: i['_id'] == id, links)[0]
        db.links.update(link, {'$set': update})
        links.remove(link)
        links.insert(order, link)

        # 对所有链接重新排序
        for i in xrange(0, len(links)):
            if links[i]['Order'] != i:
                db.links.update(links[i], {"$set": {'Order': i}})

        return redirect(request, '编辑链接成功', 'admin/show-links/')
Example #14
0
def edit(request, objectId):

    db = connect_blog_database(request)
    id = ObjectId(objectId)

    # 普通访问
    if request.method == 'GET':
        link = db.links.find_one({'_id':id})
        return render_admin_and_back(request, 'edit-link.html', {
            'page': u'编辑链接',
            'link': link
        })

    elif request.method == 'POST':

        d = request.POST
        order = int(d['link-order']) if d['link-order'] else 0
        update = {
            'Title':d['link-title'],
            'Address':d['link-address'],
            'Description':d['link-description'],
            'Order':order,
            }
        # 取得所有链接
        links = list(db.links.find(sort=[('Order', pymongo.ASCENDING)]))

        # 创建或取得编辑中的Link
        link = filter(lambda i: i['_id'] == id, links)[0]
        db.links.update(link, {'$set': update})
        links.remove(link)
        links.insert(order, link)

        # 对所有链接重新排序
        for i in xrange(0, len(links)):
            if links[i]['Order'] != i:
                db.links.update(links[i],  {"$set":{'Order': i}})

        return redirect(request, '编辑链接成功', 'admin/show-links/')
Example #15
0
def import_and_output(request):
    return render_admin_and_back(request, 'import-and-output.html', {'selection': 'import-and-output',})