예제 #1
0
파일: views.py 프로젝트: kpx13/libfic
def funfic_main_page(request, funfic_id):
    c = get_common_context(request)
    if request.method == 'POST':
        if request.POST.get('action') == 'rating':
            if request.user.is_authenticated():
                try:
                    mark = int(request.POST.get('mark'))
                    mark_st = int(request.POST.get('mark_st'))
                    mark_sz = int(request.POST.get('mark_sz'))
                    mark_pr = int(request.POST.get('mark_pr'))
                    Rating.add(request.user, Work.get_by_id(funfic_id), mark, mark_st, mark_sz, mark_pr)
                    messages.success(request, u'Рейтинг успешно изменен.')
                except:
                    messages.error(request, u'Введите корректные значения.')
                return HttpResponseRedirect('/funfic/%s/' % funfic_id)
            else:
                messages.error(request, u'Голосовать могут только авторизованные пользователи.')

    c['f'] = Work.get_by_id(funfic_id)
    c['funart'] = FunArt.get_by_work(c['f'])[:2]
    c['content'] = WorkPart.get_work_content(c['f'])
    c['f'].inc_vizits()
    c['its_mine'] = (c['f'].author == request.user) or (c['f'].is_collaborator(request.user)) if request.user.is_authenticated() else False
    c['recommend'] = Work.objects.all().order_by('-mark')[0:5]
    return render_to_response('funfic_main.html', c, context_instance=RequestContext(request))
예제 #2
0
파일: views.py 프로젝트: kpx13/libfic
def funfic_part_page(request, funfic_id, part_id):
    c = get_common_context(request)
    c['f'] = Work.get_by_id(funfic_id)
    c['f'].inc_vizits()
    if request.method == 'POST':
        comment = request.POST.get('comment', None)
        if comment:
            if request.user.is_authenticated():
                Comment(user=request.user,
                        work_part=WorkPart.get_by_id(part_id),
                        text=comment).save()
                messages.success(request, u'Ваш комментарий успешно добавлен.')
                return HttpResponseRedirect('/funfic/%s/%s/' % (funfic_id, part_id))
            else:
                messages.error(request, u'Для выполнения этого действия необходимо авторизироваться.')

    c['funart'] = FunArt.get_by_work(c['f'])[:2]
    c['content'] = WorkPart.get_work_content(c['f'])
    c['part'] = WorkPart.get_by_id(part_id)
    c['its_mine'] = (c['f'].author == request.user) or (c['f'].is_collaborator(request.user))
    return render_to_response('funfic_part.html', c, context_instance=RequestContext(request))
예제 #3
0
파일: views.py 프로젝트: kpx13/libfic
def edit_part_page(request, funfic_id, part_id):
    c = get_common_context(request)
    c['title'] = u'Редактирование части фанфика'
    work = Work.get_by_id(funfic_id)
    if not ((work.author == request.user) or (work.is_collaborator(request.user))):
        return HttpResponseRedirect('/funfic/%s/' % funfic_id)
    if request.method=='POST':
        form = AddPartForm(request.POST, instance=WorkPart.get_by_id(part_id))
        if form.is_valid():
            ff = form.save(commit=False)
            ff.public_on = request.POST.get('public_on', False)
            ff.save()
            work.last_editing_time = datetime.datetime.now()
            messages.success(request, u'Часть успешно изменена.')
            History.add_record(request.user, ff)
            return HttpResponseRedirect('/cabinet/edit_part/%s/%s/' % (funfic_id, part_id))
        else:
            messages.error(request, u'Часть не добавлен. Исправьте ошибки ниже.')
    else:
        form = AddPartForm(instance=WorkPart.get_by_id(part_id))
    c['form'] = form
    return render_to_response('cabinet/add_part.html', c, context_instance=RequestContext(request))