Beispiel #1
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/')
Beispiel #2
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/')
Beispiel #3
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/')
Beispiel #4
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/')
Beispiel #5
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',
    })
Beispiel #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',
        })
Beispiel #7
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',
        })
Beispiel #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',
    })
Beispiel #9
0
def delete(request, objectId):

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

    # 普通访问
    if request.method == 'GET':
        db.links.remove({'_id':id})

        # 取得所有链接
        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/')
Beispiel #10
0
def delete(request, objectId):

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

    # 普通访问
    if request.method == 'GET':
        db.links.remove({'_id': id})

        # 取得所有链接
        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/')
Beispiel #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/')
Beispiel #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/')
Beispiel #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/')
Beispiel #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/')