Exemplo n.º 1
0
	def post(self, request, *args, **kwargs):
		u = request.user
		p = UserProfile.objects.get(user=u)
		c = UserCompany.objects.get(user=u)

		self.context['p'] = p
		self.context['u'] = u
		self.context['c'] = c

		profile_data = profileDataDict(profile=p, user=u)
		company_data = companyDataDict(company=c)

		contact_form = UserContactForm(profile_data, label_suffix='')
		company_form = UserCompanyForm(company_data, label_suffix='')

		if 'contact_form' in request.POST:
			contact_form = UserContactForm(request.POST, request.FILES)
			if contact_form.is_valid():
				contact_form.save(u)
				return redirect(reverse('dashboard:settings'))
		if 'company_form' in request.POST:
			company_form = UserCompanyForm(request.POST, request.FILES)
			if company_form.is_valid():
				company_form.save(u)
				return redirect(reverse('dashboard:settings'))

		self.context['form'] = contact_form
		self.context['f2'] = company_form

		return render(request, self.template_name, self.context)
Exemplo n.º 2
0
	def get(self, request, *args, **kwargs):
		if isLoggedIn(request):
			u = request.user
			p = UserProfile.objects.get(user=u)
			c = UserCompany.objects.get(user=u)

			self.context['p'] = p
			self.context['u'] = u
			self.context['c'] = c

			profile_data = profileDataDict(profile=p, user=u)
			company_data = companyDataDict(company=c)

			contact_form = UserContactForm(profile_data, label_suffix='')
			company_form = UserCompanyForm(company_data, label_suffix='')

			self.context['form'] = contact_form
			self.context['f2'] = company_form
			return render(request, self.template_name, self.context)
		else:
			return redirect(reverse('index:login'))