Ejemplo n.º 1
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())
Ejemplo n.º 2
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)
Ejemplo n.º 3
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)
Ejemplo n.º 4
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)