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/')
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/')
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/')
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/')
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', })
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', })
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', })
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', })
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/')
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/')
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/')
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/')