Ejemplo n.º 1
0
	def post(self,request):
		form_helper = FormHelper(request)
		address_form = form_helper.get_address_form()
		profile_form = form_helper.get_profile_form()

		if address_form.is_valid() and profile_form.is_valid():
			
			address,created = Address.objects.get_or_create(
				title=address_form.cleaned_data['title'],
				street=address_form.cleaned_data['street'],
				city=address_form.cleaned_data['city'],
				state=address_form.cleaned_data['state'],
				zip_code=address_form.cleaned_data['zip']
			)

			profile,created = Profile.objects.get_or_create(
				organization=profile_form.cleaned_data['organization'],
				first_name=profile_form.cleaned_data['firstName'],
				last_name=profile_form.cleaned_data['lastName'],
				phone_number=profile_form.cleaned_data['phoneNumber'],
				email=profile_form.cleaned_data['email'],
				address=address
			)
			
			serializer_class = ProfileSerializer
			serialized_profile = ProfileSerializer(profile).data

			return Response(serialized_profile,status=status.HTTP_200_OK)

		else:

			return Response({
				'profile_errors' : profile_form.errors,
				'address_errors' : address_form.errors
			},status=status.HTTP_404_NOT_FOUND)
		

		return Response('nothing to report')
Ejemplo n.º 2
0
	def post(self,request,id):
		id = int(id)
		form_helper = FormHelper(request)
		address_form = form_helper.get_address_form()
		profile_form = form_helper.get_profile_form()
		
		if address_form.is_valid() and profile_form.is_valid():

			profile,updated = form_helper.update_profile(id)
			
			if updated:
				serializer_class = ProfileSerializer
				serialized_profile = ProfileSerializer(profile).data
				return Response(serialized_profile,status=status.HTTP_200_OK)
			else:
				return Response('Failure to update',status=status.HTTP_404_NOT_FOUND)
		else:
			return Response({
				'profile_errors' : profile_form.errors,
				'address_errors' : address_form.errors
			},status=status.HTTP_404_NOT_FOUND)
			
		return Response('there are errors')