Example #1
0
def create_post(request):
    form = JobForm(request.POST or None, request.FILES or None)
    if form.is_valid():
        form.save()
        return redirect('dashboard')
    context = {'form': form}
    return render(request, 'create_post.html', context)
Example #2
0
File: views.py Project: veb/oddit
def edit_job(request, job_id):
    popular_categories_list = Job.objects.values("category", "category__name").annotate(num_jobs=Count("id"))
    popular_tags = Tag.objects.usage_for_model(Job, counts=True)[:5]
    popular_tags.sort(key=operator.attrgetter("count"), reverse=True)
    category_list = Category.objects.all()[:10]

    job = get_object_or_404(Job, pk=job_id)

    if job.user != request.user:
        return HttpResponseForbidden()

    if request.POST:
        form = JobForm(request.POST, instance=job, user=request.user)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect("/jobs/my-jobs")
    else:
        form = JobForm(instance=job, user=request.user)

    return render_to_response(
        "jobs/new_job.html",
        {
            "form": form,
            "popular_categories": popular_categories_list,
            "popular_tags": popular_tags,
            "categories": category_list,
        },
        context_instance=RequestContext(request),
    )
Example #3
0
File: views.py Project: veb/oddit
def new_job(request):
    popular_categories_list = Job.objects.values("category", "category__name").annotate(num_jobs=Count("id")).distinct()
    popular_tags = Tag.objects.usage_for_model(Job, counts=True)[:5]
    popular_tags.sort(key=operator.attrgetter("count"), reverse=True)
    category_list = Category.objects.all()[:10]

    job = Job()
    if request.method == "POST":
        form = JobForm(data=request.POST, instance=job, user=request.user)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect("/jobs/")
        else:
            return HttpResponseRedirect("/jobs/")
            print "something f****d!"
    else:
        form = JobForm(instance=job, user=request.user)

    return render_to_response(
        "jobs/new_job.html",
        {
            "form": form,
            "popular_categories": popular_categories_list,
            "popular_tags": popular_tags,
            "categories": category_list,
        },
        context_instance=RequestContext(request),
    )
Example #4
0
def editpost(request, id):
    data = Job.objects.get(pk=id)
    form = JobForm(request.POST or None, request.FILES or None, instance=data)
    if form.is_valid():
        form.save()
        return redirect('dashboard')
    context = {'form': form}
    return render(request, 'edit_post.html', context)
Example #5
0
def create_job(request):
    if request.method == 'POST':
        form = JobForm(request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse('job:manage_jobs'))
        else:
            return render(request, 'job/create_job.html', {'form' : form,})
    else:
        form = JobForm()
        return render(request, 'job/create_job.html', {'form' : form,})
Example #6
0
def edit(request, job_id):

    job = None
    if job_id:
        job = get_job_by_id(job_id)

    event_list = get_events_ordered_by_name()

    if request.method == 'POST':
        form = JobForm(request.POST, instance=job)
        if form.is_valid():
            job_to_edit = form.save(commit=False)
            event_id = request.POST.get('event_id')
            event = get_event_by_id(event_id)
            if event:
                job_to_edit.event = event
            else:
                raise Http404
            job_to_edit.save()
            return HttpResponseRedirect(reverse('job:list'))
        else:
            return render(request, 'job/edit.html', {
                'form': form,
                'event_list': event_list,
                'job': job
            })
    else:
        form = JobForm(instance=job)
        return render(request, 'job/edit.html', {
            'form': form,
            'event_list': event_list,
            'job': job
        })
Example #7
0
def create(request):

    event_list = get_events_ordered_by_name()
    if request.method == 'POST':
        form = JobForm(request.POST)
        if form.is_valid():
            job = form.save(commit=False)
            event_id = request.POST.get('event_id')
            event = get_event_by_id(event_id)
            if event:
                job.event = event
            else:
                raise Http404
            job.save()
            return HttpResponseRedirect(reverse('job:list'))
        else:
            return render(request, 'job/create.html', {
                'form': form,
                'event_list': event_list
            })
    else:
        form = JobForm()
        return render(request, 'job/create.html', {
            'form': form,
            'event_list': event_list
        })
Example #8
0
File: views.py Project: Ads7/vms
def edit(request, job_id):

    job = None
    if job_id:
        job = get_job_by_id(job_id)

    event_list = get_events_ordered_by_name()

    if request.method == 'POST':
        form = JobForm(request.POST, instance=job)
        if form.is_valid():
            job_to_edit = form.save(commit=False)
            event_id = request.POST.get('event_id')
            event = get_event_by_id(event_id)
            if event:
                job_to_edit.event = event
            else:
                raise Http404
            job_to_edit.save()
            return HttpResponseRedirect(reverse('job:list'))
        else:
            return render(request, 'job/edit.html', {'form' : form, 'event_list' : event_list, 'job' : job})
    else:            
        form = JobForm(instance=job)
        return render(request, 'job/edit.html', {'form' : form, 'event_list' : event_list, 'job' : job})
Example #9
0
File: views.py Project: Ads7/vms
def create(request):

    event_list = get_events_ordered_by_name()
    if request.method == 'POST':
        form = JobForm(request.POST)
        if form.is_valid():
            job = form.save(commit=False)
            event_id = request.POST.get('event_id')
            event = get_event_by_id(event_id)
            if event:
                job.event = event
            else:
                raise Http404
            job.save()
            return HttpResponseRedirect(reverse('job:list'))
        else:
            return render(request, 'job/create.html', {'form' : form, 'event_list' : event_list})
    else:
        form = JobForm()
        return render(request, 'job/create.html', {'form' : form, 'event_list' : event_list})