Exemple #1
0
def create_job(request, **kwargs):
    """
    job creation
    """
    template_name = kwargs.get("template_name", "djobs/job_form.html")
    
    if request.method == 'POST':
        location_form = LocationForm(request.POST)
        
        if location_form.is_valid():
            location = location_form.save()
        
        contact_form = ContactForm(request.POST)
        
        if contact_form.is_valid():
            contact = contact_form.save()
        
        job_form = JobForm(request.POST)
        job_form.fields['employer'].queryset = job_form.fields['employer'].queryset.filter(administrator=request.user)
        
        if job_form.is_valid():
            title = job_form.cleaned_data['title']
            description = job_form.cleaned_data['description']
            category = job_form.cleaned_data['category']
            employment_type = job_form.cleaned_data['employment_type']
            employment_level = job_form.cleaned_data['employment_level']
            employer = job_form.cleaned_data['employer']
            
            new_job = Job.objects.create(title=title,
                description=description,
                category=category,
                employment_type=employment_type,
                employment_level=employment_level,
                employer=employer,
                location=location,
                contact=contact
            )
            
            return HttpResponseRedirect(reverse('djobs_job_detail',
                args=[new_job.id]
            ))
    else:
        job_form = JobForm()
        job_form.fields['employer'].queryset = job_form.fields['employer'].queryset.filter(administrator=request.user)
        
        location_form = LocationForm()
        contact_form = ContactForm()

    return render_to_response(template_name, {
            'job_form': job_form,
            'location_form': location_form,
            'contact_form': contact_form,
            'add': True,
        }, context_instance=RequestContext(request)
    )
Exemple #2
0
def edit_job(request, job_id, **kwargs):
    """
    job editing
    """
    template_name = kwargs.get("template_name", "djobs/job_form.html")
    job = get_object_or_404(Job, pk=job_id)

    if request.user != job.employer.administrator:
        httpresponse_kwargs = {'mimetype': kwargs.pop('mimetype', None)}
        return HttpResponseForbidden(loader.render_to_string('403.html', 
            context_instance=RequestContext(request), **kwargs), 
            **httpresponse_kwargs
        )
    
    if request.method == 'POST':
        location_form = LocationForm(request.POST)
        
        if location_form.is_valid():
            job.location = location_form.save()
        
        contact_form = ContactForm(request.POST)
        
        if contact_form.is_valid():
            job.contact = contact_form.save()
        
        job_form = JobForm(request.POST)
        job_form.fields['employer'].queryset = job_form.fields['employer'].queryset.filter(administrator=request.user)
        
        if job_form.is_valid():
            job.title = job_form.cleaned_data['title']
            job.description = job_form.cleaned_data['description']
            job.category = job_form.cleaned_data['category']
            job.employment_type = job_form.cleaned_data['employment_type']
            job.employment_level = job_form.cleaned_data['employment_level']
            job.employer = job_form.cleaned_data['employer']
            
            job.save()
            
            return HttpResponseRedirect(reverse('djobs_job_detail',
                args=[job.id]
            ))
    else:
        job_form = JobForm({'title': job.title, 'description': job.description,
            'category': job.category.id,
            'employment_type': job.employment_type,
            'employment_level': job.employment_level,
            'employer': job.employer.id,
        })
        job_form.fields['employer'].queryset = job_form.fields['employer'].queryset.filter(administrator=request.user)
        
        location_form = LocationForm({'address': job.location.address,
            'city': job.location.city,
            'state': job.location.state,
            'zip': job.location.zip,
        })
        contact_form = ContactForm({'name': job.contact.name,
            'email': job.contact.email,
            'phone': job.contact.phone,
            'fax': job.contact.fax,
            'url': job.contact.url,
        })
        
    return render_to_response(template_name, {
            'job_form': job_form,
            'location_form': location_form,
            'contact_form': contact_form,
            'add': False,
        }, context_instance=RequestContext(request)
    )