Exemple #1
0
def add_important(request):
    '''
    添加精选
    '''
    img = request.FILES.get('importantImg')
    flag, img_name = qiniu_client.upload_img(img, img_type='important')

    qb = QuestionBase()
    question_id = request.REQUEST.get('questionId')
    question = qb.get_question_by_id(question_id)

    img_alt = request.REQUEST.get('imgAlt', '')
    sort_num = request.REQUEST.get('sort', 0)
    title = request.REQUEST.get('title')
    summary = request.REQUEST.get('summary')
    author = request.REQUEST.get('author')
    author_id = None

    # 作者
    if author:
        author = UserBase().get_user_by_nick(author)
        if author:
            author_id = author.id

    code, msg = qb.set_important(question, request.user, title, summary, author_id, '%s/%s' % (settings.IMG0_DOMAIN, img_name), img_alt, sort_num)

    url = ''
    if code == 0:
        iq = qb.get_important_question_by_question_id(question_id)
        url = '/admin/question/important_question#modify/%s' % iq.question.id
    else:
        url = request.META['HTTP_REFERER']
    return HttpResponseRedirect(url)
Exemple #2
0
def modify_important(request):
    '''
    修改精选
    '''
    qb = QuestionBase()
    img_alt = request.REQUEST.get('imgAlt', '')
    sort_num = request.REQUEST.get('sort', 0)
    question_id = request.REQUEST.get('questionId')
    question = qb.get_question_by_id(question_id)

    img = request.FILES.get('importantImg')

    iq = qb.get_important_question_by_question_id(question_id)
    img_name = iq.img
    # 如果有上传图片
    if img:
        flag, img_name = qiniu_client.upload_img(img, img_type='important')
        img_name = '%s/%s' % (settings.IMG0_DOMAIN, img_name)

    title = request.REQUEST.get('title')
    summary = request.REQUEST.get('summary')
    author = request.REQUEST.get('author')
    author_id = None

    # 作者
    if author:
        author = UserBase().get_user_by_nick(author)
        if author:
            author_id = author.id

    code, msg = qb.set_important(question, request.user, title, summary, author_id, img_name, img_alt, sort_num)

    url = '/admin/question/important_question#modify/%s' % iq.question.id

    return HttpResponseRedirect(url)
Exemple #3
0
def cancel_important(request):
    question_id = request.REQUEST.get('question_id')

    qb = QuestionBase()
    question = qb.get_question_by_id(question_id)
    return qb.cancel_important(question, request.user)