Beispiel #1
0
def article_list(request):
    '文章管理'
    order = "id desc"
    category_id = func.get_int_param_from_get(request,'category')
    start = func.get_int_param_from_get(request,'start')
    count = 10
    state = -1
    category_facade = facade.factory.create_category_facade()
    category_list = category_facade.get_child_category_list(0)
    article_facade = facade.factory.create_article_facade()
    articles = article_facade.search(category_id=category_id,order=order,state=state,start=start,count=count)
    article_list = articles.get('list',[])
    total_count = articles.get('total_count',0)
    pager = Pager(request,start,count,total_count)
    total_hits = article_facade.get_total_hits()
    total_download = article_facade.get_total_download()
    output = {
        'category_id':category_id,
        'category_list':category_list,
        'article_list':article_list,
        'pager':pager,
        'total_hits':total_hits,
        'total_download':total_download,
    }
    return render_to_response('admin/article_list.html',output)
Beispiel #2
0
def search(request,list_type='text'):
    start = func.get_int_param_from_get(request,'start')
    count = 20
    keyword = request.GET.get('wd','')
    article_facade = facade.factory.create_article_facade()
    articles = article_facade.search(keyword=keyword,start=start,count=count)
    article_list = articles['list']
    total_count = int(articles['total_count'])
    pager = Pager(request,start,page_size=count,total_count=total_count)


    #推荐文章
    recommend_article_list = article_facade.search(recommend=1)['list']
    #热门文章
    hot_article_list = article_facade.search(order='hits desc')['list']

    #专题
    topic_facade = facade.factory.create_topic_facade()
    topic_list = topic_facade.get_all_topic()

    output = {
        'article_list' : article_list,
        'recommend_article_list':recommend_article_list,
        'hot_article_list' : hot_article_list,
        'pager' : pager,
        'topic_list':topic_list,
        'keyword':keyword,
    }
    template_file = 'search_text.html'
    if list_type=='pic':
        template_file = 'search.html'
    return render_to_response(settings.DEFAULT_SKIN + '/' + template_file,output)
Beispiel #3
0
def topic(request,topic_id):
    '专题文章'
    start = func.get_int_param_from_get(request,'start')
    count = 20
    article_facade = facade.factory.create_article_facade()
    articles = article_facade.search(topic_id=topic_id,start=start,count=count)
    article_list = articles['list']
    total_count = int(articles['total_count'])
    pager = Pager(request,start,page_size=count,total_count=total_count)

    #为article_list添加广告代码
    ad_list = (random.randint(0,10),random.randint(0,10))
    for ad in ad_list:
        article_list.insert(ad,None)

    #热门文章
    hot_article_list = article_facade.search(topic_id=topic_id,order='hits desc')['list']
    #推荐文章
    recommend_article_list = article_facade.search(topic_id=topic_id,recommend=1)['list']

    #专题
    topic_facade = facade.factory.create_topic_facade()
    topic_list = topic_facade.get_all_topic()
    topic = topic_facade.get_data(topic_id)

    output = {
        'article_list' : article_list,
        'hot_article_list' : hot_article_list,
        'recommend_article_list':recommend_article_list,
        'topic':topic,
        'pager' : pager,
        'topic_list':topic_list,
    }
    return render_to_response(settings.DEFAULT_SKIN+'/topic.html',output)
Beispiel #4
0
def book_chapter_del(request):
    '删除'
    id = func.get_int_param_from_get(request,'id')
    book_chapter_facade = BookChapterFacade()
    book_chapter_facade.remove(id)
    return_url = func.get_referer(request,'book_chapter_list')
    return HttpResponseRedirect(return_url)
Beispiel #5
0
def edit(request):
    category_facade = facade.factory.create_category_facade()

    if request.method =="POST":
        category_id = func.get_int_param_from_post(request,'category_id')
        old_category = category_facade.get_data(category_id)
        category = Category()
        if old_category:
            category = old_category
        category.category_id = func.get_int_param_from_post(request,'category_id')
        category.category_name = func.get_str_param_from_post(request,'category_name')
        category.parent_category_id = func.get_int_param_from_post(request,'parent_category_id')
        category.root_category_id = func.get_int_param_from_post(request,'root_category_id')
        category.article_type = func.get_int_param_from_post(request,'article_type')
        category.description = func.get_str_param_from_post(request,'description')

        if old_category:
            category_facade.update(category)
        else:
            category_facade.insert(category)
        return HttpResponseRedirect('category?parent_category_id=%s'%category.parent_category_id)


    category_id = func.get_int_param_from_get(request,'category_id')
    category = category_facade.get_data(category_id)

    parent_category_id = func.get_int_param_from_get(request,'parent_category_id')
    parent_category = category_facade.get_data(parent_category_id)
    if category:
        parent_category = category_facade.get_data(category.parent_category_id)
    
    root_category_id = 0
    if parent_category:
        root_category_id = parent_category.root_category_id
    root_category = category_facade.get_data(root_category_id)

    if not category:
        category = Category()
        category.root_category_id = root_category_id
        category.parent_category_id = parent_category_id

    
    return render_to_response('admin/category_edit.html',locals())
Beispiel #6
0
def book_chapter_edit(request):
    book_facade = BookFacade()
    book_chapter_facade = BookChapterFacade()
    id = func.get_int_param_from_get(request,'id')
    book_id = func.get_int_param_from_get(request,'book_id')
    book = book_facade.get_data(book_id)
    output = {'book_id':book_id,'book':book,}

    if request.method=="POST":
        book_chapter = BookChaper()
        book_chapter.book_id = func.get_int_param_from_post(request,'book_id')
        book_chapter.title = request.POST.get('title','')
        book_chapter.content = request.POST.get('content','')
        if id:#修改
            book_chapter.id = id
            messages = book_chapter.validate()
            if not messages:
                book_chapter_facade.update(book_chapter)
                return_url = 'book_chapter_list?book_id=%s'%book_chapter.book_id
                return HttpResponseRedirect(return_url)
            else:
                output['messages'] = messages
                return render_to_response('admin/book_chapter_edit.html',output)
        else:#插入
            book_chapter.id = func.create_new_id()
            messages = book_chapter.validate()
            if not messages:
                book_chapter_facade.insert(book_chapter)
                return_url = 'book_chapter_list?book_id=%s'%book_chapter.book_id
                return HttpResponseRedirect(return_url)
            else:
                output['messages'] = messages
                return render_to_response('admin/book_chapter_edit.html',output)

    #get 页面
    if id>0:
        book_chapter = book_chapter_facade.get_data(id)
        output['book_chapter'] = book_chapter

    return render_to_response('admin/book_chapter_edit.html',output)
Beispiel #7
0
def book_list(request):
    '图书管理'
    sort = "id"
    start = func.get_int_param_from_get(request,'start')
    count = settings.DEFAULT_PAGE_SIZE
    book_facade = BookFacade()
    books = book_facade.search(sort=sort,start=start,count=count)
    book_list = books.get('list',[])
    total_count = books.get('total_count',0)
    pager = Pager(request,start,count,total_count)
    output = {
        'book_list':book_list,
        'pager':pager,
    }
    return render_to_response('admin/book_list.html',output)
Beispiel #8
0
def book_chapter_list(request):
    '章节管理'
    book_id = func.get_int_param_from_get(request,'book_id')
    book_chapter_facade = BookChapterFacade()
    book_facade = BookFacade();
    book = book_facade.get_data(book_id)
    book_chapters = book_chapter_facade.search(book_id)
    book_chapter_list = book_chapters['list']
    total_count = book_chapters['total_count']
    output = {
        'book':book,
        'book_chapter_list':book_chapter_list,
        'book_id':book_id,
    }
    return render_to_response('admin/book_chapter_list.html',output)
Beispiel #9
0
def category(request,category_id,list_type='pic'):
    '分类浏览文章'
    start = func.get_int_param_from_get(request,'start')
    count = 20
    article_facade = facade.factory.create_article_facade()
    articles = article_facade.search(category_id=category_id,start=start,count=count)
    article_list = articles['list']
    total_count = int(articles['total_count'])
    pager = Pager(request,start,page_size=count,total_count=total_count)
    #为article_list添加广告代码
    ad_list = (random.randint(0,10),random.randint(0,10))
    for ad in ad_list:
        article_list.insert(ad,None)

    #热门文章
    hot_article_list = article_facade.search(category_id=category_id,order='hits desc')['list']
    recommend_article_list = article_facade.search(category_id=category_id,recommend=1)['list']

    #类别列表
    category_facade = facade.factory.create_category_facade()
    category = category_facade.get_data(category_id)
    category_list = category_facade.get_child_category_list(category.root_category_id)

    #专题
    topic_facade = facade.factory.create_topic_facade()
    topic_list = topic_facade.get_all_topic()

    output = {
        'article_list' : article_list,
        'hot_article_list' : hot_article_list,
        'recommend_article_list':recommend_article_list,
        'category_list' : category_list,
        'category':category,
        'pager' : pager,
        'topic_list':topic_list,
    }
    template_file = 'category.html'
    if list_type=='text':
        template_file = 'category_text.html'
    return render_to_response(settings.DEFAULT_SKIN + '/' + template_file,output)
Beispiel #10
0
def tag(request,tag):
    start = func.get_int_param_from_get(request,'start')
    count = 20
    list_type='text'
    tag_facade = facade.factory.create_tag_facade()
    article_facade = facade.factory.create_article_facade()
    taghot_facade = facade.factory.create_taghot_facade()

    articles = tag_facade.search(tag=tag,start=start,count=count)
    article_list = articles['list']
    total_count = int(articles['total_count'])
    pager = Pager(request,start,page_size=count,total_count=total_count)


    #推荐文章
    recommend_article_list = article_facade.search(recommend=1)['list']
    #热门文章
    hot_article_list = article_facade.search(order='hits desc')['list']

    #专题
    topic_facade = facade.factory.create_topic_facade()
    topic_list = topic_facade.get_all_topic()

    tag_hot_list = taghot_facade.get_hot_list(count=20)


    output = {
        'article_list' : article_list,
        'recommend_article_list':recommend_article_list,
        'hot_article_list' : hot_article_list,
        'pager' : pager,
        'topic_list':topic_list,
        'tag':tag,
        'tag_hot_list':tag_hot_list
        }
    template_file = 'tag.html'
    if list_type=='pic':
        template_file = 'tag.html'
    return render_to_response(settings.DEFAULT_SKIN + '/' + template_file,output)
Beispiel #11
0
def remove(request):
    category_id = func.get_int_param_from_get(request,'category_id')
    category_facade = facade.factory.create_category_facade()
    category = category_facade.get_data(category_id)
    category_facade.remove(category_id)
    return HttpResponseRedirect('category?parent_category_id=%s'%category.parent_category_id)
Beispiel #12
0
def index(request):
    parent_category_id = func.get_int_param_from_get(request,'parent_category_id')
    category_facade = facade.factory.create_category_facade()
    parent_category = category_facade.get_data(parent_category_id)
    category_list = category_facade.get_child_category_list(parent_category_id)
    return render_to_response('admin/category_list.html',locals())
Beispiel #13
0
def article_edit(request):
    '文章编辑'
    article_facade = facade.factory.create_article_facade()
    topic_facade = facade.factory.create_topic_facade()
    category_facade = facade.factory.create_category_facade()
    tag_facade = facade.factory.create_tag_facade()

    #如果是提交信息
    if request.method =="POST":
        article = Article()
        id = func.get_int_param_from_post(request,'id')
        article.id=id
        article.title = func.get_str_param_from_post(request,'title')
        article.root_category_id = func.get_int_param_from_post(request,'root_category')
        article.category_id = func.get_int_param_from_post(request,'category1')
        article.category_id2 = func.get_int_param_from_post(request,'category2')
        article.category_id3 = func.get_int_param_from_post(request,'category3')
        article.author = func.get_str_param_from_post(request,'author')
        article.source = func.get_str_param_from_post(request,'source')
        article.short_description = func.get_str_param_from_post(request,'short_description')
        article.description = func.get_str_param_from_post(request,'description')
        article.demo_code = func.get_str_param_from_post(request,'demo_code')
        article.demo_url = func.get_str_param_from_post(request,'demo_url')
        article.dev_view_code = func.get_str_param_from_post(request,'dev_view_code')
        article.full_download_url = func.get_str_param_from_post(request,'full_download_url')
        article.head_code = func.get_str_param_from_post(request,'head_code')
        article.body_code = func.get_str_param_from_post(request,'body_code')
        article.compatibility = func.get_str_param_from_post(request,'compatibility')
        article.pic = func.get_str_param_from_post(request,'pic')
        article.small_pic = func.get_str_param_from_post(request,'small_pic')
        article.recommend = func.get_str_param_from_post(request,'recommend')=='on'
        article.topic_id = func.get_str_param_from_post(request,'topic_id')
        article.state = 0
        article.isrtdate = func.format_date_time(func.str_to_datetime(func.get_str_param_from_post(request,'isrtdate')))
        article.last_hit_date=func.format_date_time(func.str_to_datetime(func.get_str_param_from_post(request,'last_hit_date')))
        article.hits = func.get_int_param_from_post(request,'hits')

        id = article_facade.post_data(article)
        #添加Tags
        tag_facade.insert_tags(id,func.get_str_param_from_post(request,'tags'))

        refer_url = func.get_str_param_from_post(request,'refer_url')
        if not refer_url:
            refer_url = "article_list"

        return HttpResponseRedirect(refer_url)
        

    id = func.get_int_param_from_get(request,'id')
    output = {}

    if id>0:
        article = article_facade.get_data(id)
        article.tags = tag_facade.get_tags_str(id)
        output['article'] = article

    topic_list = topic_facade.get_all_topic()
    root_category_list = category_facade.get_child_category_list(0)
    output['topic_list'] = topic_list
    output['root_category_list'] = root_category_list
    output['refer_url'] = func.get_referer(request,'article_list')
    

    return render_to_response('admin/article_edit.html',output)
Beispiel #14
0
def book_edit(request):
    '图书编辑'

    book_facade = BookFacade()

    #如果是提交信息
    if request.method =="POST":
        book = Book()
        id = func.get_int_param_from_post(request,'id')
        book.authors =  map(lambda x:x.strip(),request.POST.get('authors','').split('/'))
        book.translators = map(lambda x:x.strip(),request.POST.get('translators','').split('/'))
        book.authors_intro = request.POST.get('authors_intro','')
        book.binding = request.POST.get('binding','')
        book.dir = request.POST.get('dir','')
        book.spic = request.POST.get('spic','')
        book.mpic = request.POST.get('mpic','')
        book.bpic = request.POST.get('bpic','')
        book.isbn10 = request.POST.get('isbn10','')
        book.isbn13 = request.POST.get('isbn13','')
        book.pages = request.POST.get('pages','')
        book.price = request.POST.get('price','')
        book.pubdate = request.POST.get('pubdate','')
        book.publisher = request.POST.get('publisher','')
        book.summary = request.POST.get('summary','')
        book.title = request.POST.get('title','')
        book.sub_title = request.POST.get('sub_title','')
        book.tags = map(lambda x:x.strip(),request.POST.get('tags','').split('/'))


        #修改
        if id>0:
            book.id = id
            messages = book.validate()
            if not messages:
                book_facade.update(book)
                return_url = 'book_list'
                return HttpResponseRedirect(return_url)
            else:
                message=''
                if messages:
                    message = messages[0]
                output = {'message' :message}
                return render_to_response('admin/book_edit.html',output)
        else: #插入
            book.id = func.create_new_id()
            messages = book.validate()
            if not messages:
                book_facade.insert(book)
                return_url = 'book_list'
                return HttpResponseRedirect(return_url)
            else:
                message=''
                if messages:
                    message = messages[0]
                output = {'message' :message}
                return render_to_response('admin/book_edit.html',output)

    id = func.get_int_param_from_get(request,'id')
    output = {}

    if id>0:
        book = book_facade.get_data(id)
        output['book'] = book

    return render_to_response('admin/book_edit.html',output)