Exemplo n.º 1
0
def emailaddress_delete(request,emailaddress_id):
	emailaddress = get_object_or_404(EmailAddress.objects.select_related(),id=emailaddress_id)
	
	if user_can_access_company(request.user,emailaddress.contact.company_id):
		contact_id = emailaddress.contact_id
		emailaddress.delete()
		if request.is_ajax():
			return HttpResponse(status=200)
		else:
			return HttpResponseRedirect(reverse('contacts.views.contact_single',args=[contact_id]))
	else:
		return HttpResponse("You are not allowed to access this",status=403)
Exemplo n.º 2
0
def website_delete(request,website_id):
	website = get_object_or_404(Website.objects.select_related(),id=website_id)
	
	if user_can_access_company(request.user,website.contact.company_id):
		contact_id = website.contact_id
		website.delete()
		if request.is_ajax():
			return HttpResponse(status=200)
		else:
			return HttpResponseRedirect(reverse('contacts.views.contact_single',args=[contact_id]))
	else:
		return HttpResponse("You are not allowed to access this",status=403)
Exemplo n.º 3
0
def phonenumber_delete(request,phonenumber_id):
	phonenumber = get_object_or_404(PhoneNumber.objects.select_related(),id=phonenumber_id)
	
	if user_can_access_company(request.user,phonenumber.contact.company_id):
		contact_id = phonenumber.contact_id
		phonenumber.delete()
		if request.is_ajax():
			return HttpResponse(status=200)
		else:
			return HttpResponseRedirect(reverse('contacts.views.contact_single',args=[contact_id]))
	else:
		return HttpResponse("You are not allowed to access this",status=403)
Exemplo n.º 4
0
def contact_delete(request,document_id):
	contact = get_object_or_404(Contact,id=document_id)
	company_id = contact.company_id
	if user_can_access_company(request.user,company_id):
		if (contact.picture):
			contact.picture.delete()
		contact.delete()
		if request.is_ajax():
			return HttpResponse(status=200)
		else:
			return HttpResponseRedirect(reverse('contact_list'))
	else:
		return HttpResponse("You are not allowed to access this",status=403)
Exemplo n.º 5
0
def contact_single(request,contact_id):
	contact = get_object_or_404(Contact,id=contact_id)
	
	if not user_can_access_company(request.user,contact.company_id):
		return HttpResponse("You are not allowed to access this",status=403)
	
	PhoneNumberFormSet = inlineformset_factory(Contact, PhoneNumber, can_delete=True)
	EmailAddressFormSet = inlineformset_factory(Contact, EmailAddress, can_delete=True)    
	WebsiteFormSet = inlineformset_factory(Contact, Website, can_delete=True)    
	
	if request.POST:
		contact_form = ContactForm(request.POST,request.FILES,instance=contact)
		phonenumber_formset = PhoneNumberFormSet(request.POST,prefix='phone',instance=contact)
		emailaddress_formset = EmailAddressFormSet(request.POST,prefix='email',instance=contact)
		website_formset = WebsiteFormSet(request.POST,prefix='website',instance=contact)

		if contact_form.is_valid() and phonenumber_formset.is_valid() and emailaddress_formset.is_valid() and website_formset.is_valid():
			contact_form.save()
			phonenumber_formset.save()
			emailaddress_formset.save()
			website_formset.save()
			return HttpResponseRedirect(reverse('contacts.views.contact_single',args=[contact_id]))
	else:
		contact_form = ContactForm(instance=contact)
		phonenumber_formset = PhoneNumberFormSet(instance=contact,prefix='phone')
		emailaddress_formset = EmailAddressFormSet(instance=contact,prefix='email')
		website_formset = WebsiteFormSet(instance=contact,prefix='website')
	
	formset = PhoneNumberFormSet()
	return render(request,"contact_single.html",{
		'contact' : contact,
		'contact_form' : contact_form,
		'phonenumber_formset' : phonenumber_formset,
		'emailaddress_formset' : emailaddress_formset,
		'website_formset' : website_formset,
		'formset' : formset,
	})