示例#1
0
def edit_job(request, object_id):
    entry = get_object_or_404(Entry,pk=object_id)
    if request.user.id != entry.author.id:
        return HttpResponseForbidden('<strong>Access Forbidden. You do not have permission to access this page. </strong>') # fix me 403 must be returned
    if request.method == 'POST':
        formset = EntryForm(instance=entry, data=request.POST, user=request.user)
        if formset.is_valid():
            entry.pk = object_id
            entry.save()
            if entry.status == Entry.DRAFT_STATUS:
               return HttpResponseRedirect(reverse('job_preview_detail', kwargs = {'object_id':entry.id,}))
            else:
               # if live or expired just display them
               return HttpResponseRedirect(reverse('job_entry_detail', kwargs = {'slug':entry.slug, 'object_id':entry.id,})) 
    else:
        formset = EntryForm(instance=entry, user=request.user)

    variables = RequestContext(request, {
        'formset': formset,
        'object_id': object_id,
            })
    return render_to_response("jobs/edit_job.html", variables)
示例#2
0
def post_job(request):
    if request.method == 'POST':
        formset = EntryForm(request.POST, user=request.user)
        if formset.is_valid():
            formset.save(commit=False)
            formset.pub_date = datetime.datetime.now
            formset.save()
            return HttpResponseRedirect('/')
    else:
        formset = EntryForm(user=request.user)

    variables = RequestContext(request, {
        'formset': formset,
            })
    return render_to_response("jobs/post_entry.html", variables)