Пример #1
0
def add_part_page(request, id):
    c = get_common_context(request)
    c['title'] = u'Добавить часть к фанфику'
    work = Work.get_by_id(id)
    if not ((work.author == request.user) or (work.is_collaborator(request.user))):
        return HttpResponseRedirect('/funfic/%s/' % id)
    c['parts'] = work.get_content()
    if request.method=='POST':
        form = AddPartForm(request.POST)
        if form.is_valid():
            ff = form.save(commit=False)
            ff.work = work
            ff.number = int(request.POST['number']) + 1
            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/' % (id, ff.id))
        else:
            messages.error(request, u'Часть не добавлен. Исправьте ошибки ниже.')
    else:
        form = AddPartForm()
    c['form'] = form
    c['is_adding'] = True
    return render_to_response('cabinet/add_part.html', c, context_instance=RequestContext(request))
Пример #2
0
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))