def change_company(request, customer_id): # FIXME: Make this view honor the returned_url if any for other apps that # will call it customer = get_object_or_404(Clients, pk=customer_id) return_url = request.GET.get('return_url', None) form = EnterpriseForm(request.POST or None, instance=customer) if form.is_valid(): customer = form.save(commit=False) customer.id_user = Users.objects.get(email=request.user.email) with reversion.create_revision(): customer.save() reversion.set_user(request.user) reversion.set_comment("Company altered from %s" % request.META.get('REMOTE_ADDR', None)) messages.add_message(request, messages.INFO, _('Company info saved')) if return_url: return redirect(return_url) return redirect('home') return render( request, fo_get_template(request.get_host(), 'enterprise/add_company.html'), { 'form': form, 'title': _("Change company") })
def add_company(request): # FIXME: Make this view honor the returned_url if any for other apps that # will call it return_url = request.GET.get('return_url', None) form = EnterpriseForm(request.POST or None) if form.is_valid(): customer = form.save(commit=False) try: customer.id_user = Users.objects.get(login=request.user.email) except Users.DoesNotExist: try: # FIXME: Remove these and do it just when the connection is first made user = Users.objects.create(email=request.user.email, login=request.user.email) customer.id_user = user except: # The login is not the email ('admin'), if this fail then crash. customer.id_user = Users.objects.get(email=request.user.email) #Cyril wants this to be always 1 customer.company_type = CompanyTypes.objects.get(pk=1) with reversion.create_revision(): customer.save() reversion.set_user(request.user) reversion.set_comment("Company added from %s" % request.META.get('REMOTE_ADDR', None)) manager = Roles.objects.get(name='manager') Clients2Users.objects.create(user=customer.id_user, client=customer, role=manager) if return_url: return redirect(return_url) return redirect('home') return render(request, fo_get_template(request.get_host(), 'enterprise/add_company.html'), {'form':form, 'title':_("Add company")})
def change_company(request, customer_id): # FIXME: Make this view honor the returned_url if any for other apps that # will call it customer = get_object_or_404(Clients, pk=customer_id) return_url = request.GET.get('return_url', None) form = EnterpriseForm(request.POST or None, instance=customer) if form.is_valid(): customer = form.save(commit=False) customer.id_user = Users.objects.get(email=request.user.email) with reversion.create_revision(): customer.save() reversion.set_user(request.user) reversion.set_comment("Company altered from %s" % request.META.get('REMOTE_ADDR', None)) messages.add_message(request, messages.INFO, _('Company info saved')) if return_url: return redirect(return_url) return redirect('home') return render(request, fo_get_template(request.get_host(),'enterprise/add_company.html'), {'form':form, 'title':_("Change company")})
def add_company(request): # FIXME: Make this view honor the returned_url if any for other apps that # will call it return_url = request.GET.get('return_url', None) form = EnterpriseForm(request.POST or None) if form.is_valid(): customer = form.save(commit=False) try: customer.id_user = Users.objects.get(login=request.user.email) except Users.DoesNotExist: try: # FIXME: Remove these and do it just when the connection is first made user = Users.objects.create(email=request.user.email, login=request.user.email) customer.id_user = user except: # The login is not the email ('admin'), if this fail then crash. customer.id_user = Users.objects.get(email=request.user.email) #Cyril wants this to be always 1 customer.company_type = CompanyTypes.objects.get(pk=1) with reversion.create_revision(): customer.save() reversion.set_user(request.user) reversion.set_comment("Company added from %s" % request.META.get('REMOTE_ADDR', None)) manager = Roles.objects.get(name='manager') Clients2Users.objects.create(user=customer.id_user, client=customer, role=manager) if return_url: return redirect(return_url) return redirect('home') return render( request, fo_get_template(request.get_host(), 'enterprise/add_company.html'), { 'form': form, 'title': _("Add company") })