Esempio n. 1
0
def update(request, pk_masked):
	pk = mask_toggle(pk_masked)
	try:
		applicant = Applicant.objects.filter(user=request.user).get(pk=pk) # make sure user can edit only own package that has not yet reached U.S. warehouse
	except:
		raise Http404

	HouseholdmemberInlineFormSet = inlineformset_factory(Applicant, Householdmember, form=HouseholdmemberForm, 
														extra=settings.APPLICANTS_EXTRA_HOUSEHOLDMEMBER_FIELD, 
														can_order=False,
														max_num=settings.INLINEFORMSET_MAXNUM
		)
	if request.method == "POST":
		formset_householdmember = HouseholdmemberInlineFormSet(request.POST, request.FILES, instance=applicant)
		form_applicant = ApplicantForm(request.POST)
		if formset_householdmember.is_valid():
			formset_householdmember.save()
			if "saveandaddmore" in request.POST:
				#return HttpResponseRedirect(reverse('pkgs:update', kwargs={'pk':pk}))
				return HttpResponseRedirect(reverse('applicants:update', kwargs={'pk_masked':pk_masked}))
			else:
				#return HttpResponseRedirect(reverse('pkgs:detail', kwargs={'pk':pk}))
				return HttpResponseRedirect(reverse('applicants:detail', kwargs={'pk_masked':pk_masked}))
		else:
			pass
	else:
		formset_householdmember = HouseholdmemberInlineFormSet(instance=applicant)
		form_applicant = ApplicantForm()
	return render_to_response("applicants/update.html", { "formset_householdmember": formset_householdmember, "applicant": applicant, "pk_masked": pk_masked,}, context_instance=RequestContext(request))
Esempio n. 2
0
def update_applicant(request, pk_masked):
	pk = mask_toggle(pk_masked)
	try:
		applicant = Applicant.objects.filter(user=request.user).get(pk=pk)
	except:
		raise Http404

	if request.method == "POST":
		form = ApplicantForm(request.POST, instance=applicant) 
		if form.is_valid():
			form.save()
			return HttpResponseRedirect(reverse('applicants:detail', kwargs={'pk_masked':pk_masked}))
	else:
		form = ApplicantForm(instance=applicant)
	return render_to_response('applicants/update_applicant.html', {'form': form, 'pk_masked': pk_masked,}, context_instance=RequestContext(request)) 
Esempio n. 3
0
def create(request):
	
	# check to see that user has not exceeded daily limit
	"""
	if Pkg.packages_created_since_X_hours_classmethod(request.user, settings.PKGS_X_HOURS) > settings.PKGS_MAX_PACKAGES_REGISTER_PER_X_HOURS:
		#return HttpResponse("packages created in last 24 hours too many!: %s" % Pkg.packages_created_since_X_hours_classmethod(request.user))
		context = { 'PKGS_MAX_PACKAGES_REGISTER_PER_X_HOURS': settings.PKGS_MAX_PACKAGES_REGISTER_PER_X_HOURS,
					'PKGS_X_HOURS': settings.PKGS_X_HOURS,}
		return render(request, "pkgs/toomany.html", context)
	"""

	if request.method == 'POST': 
		form = ApplicantForm(request.POST) # A form bound to the POST data
		if form.is_valid(): # All validation rules pass
			form.instance.user = request.user
			form.save() 
			return HttpResponseRedirect(reverse('applicants:update', kwargs={'pk_masked':mask_toggle(form.instance.pk)}))
	else:
		form = ApplicantForm() # An unbound form
	return render(request, 'applicants/create.html', { 'form': form,})