Exemple #1
0
def create_job_listing(request):
	if request.method == 'POST':
		request.POST.owner = request.user

		form = JobListingForm(request.POST)

		if form.is_valid(): # All validation rules pass

			form.save()

			return HttpResponseRedirect('/accounts/')

		else:
			return render_to_response('job_listings/create_listing.html', {
			'form': form,
			}, context_instance=RequestContext(request))


	initial = {
		'owner': request.user,
		}
	form = JobListingForm(initial)

	return render_to_response('job_listings/create_listing.html', {
		'form': form,
		}, context_instance=RequestContext(request))
Exemple #2
0
def edit_job_listing(request, listing_id):

	if request.method == 'POST':
		request.POST.owner = request.user

		form = JobListingForm(request.POST)

		if form.is_valid(): # All validation rules pass

			job_object = JobListing.objects.get(pk=listing_id)

			degree_program = form.cleaned_data['degree_program']
			title = form.cleaned_data['title']
			description = form.cleaned_data['description']
			contact_name = form.cleaned_data['contact_name']
			contact_email = form.cleaned_data['contact_email']
			contact_phone = form.cleaned_data['contact_phone']

			job_object.degree_program = degree_program
			job_object.title = title
			job_object.description = description
			job_object.contact_name = contact_name
			job_object.contact_email = contact_email
			job_object.contact_phone = contact_phone

			job_object.save()

			return HttpResponseRedirect('/jobs/view_listing/' + listing_id + '/')

		else:
			return render_to_response('job_listings/edit_listing.html', {
			'form': form,
			}, context_instance=RequestContext(request))

	owner = request.user
	job_object = JobListing.objects.get(pk=listing_id)

	if job_object.owner == owner:

		degree_program = job_object.degree_program
		title = job_object.title
		description = job_object.description
		contact_name = job_object.contact_name
		contact_email = job_object.contact_email
		contact_phone = job_object.contact_phone

		initial = {
			'owner': owner,
			'degree_program': degree_program,
			'title': title,
			'description': description,
			'contact_name': contact_name,
			'contact_email': contact_email,
			'contact_phone': contact_phone,
			}

		form = JobListingForm(initial)
		action_url = '/jobs/edit_listing/' + str(listing_id) + '/'

	else:
		return HttpResponseRedirect('/accounts/')


	return render_to_response('job_listings/edit_listing.html', {
		'action_url': action_url,
		'job_object': job_object,
		'form': form,
		}, context_instance=RequestContext(request))