def _save(self, customer_id=None, do_redir=True): user_id = None if self.request.ctx.user: user_id = self.request.ctx.user.user_id cust = Customer.load(customer_id) if not cust: cust = Customer() cust.user_created = cust.user_assigned = user_id else: self.forbid_if(cust.campaign.company.enterprise_id != self.enterprise_id) cust.bind(self.request.POST) cust.save() cust.flush() cust.clear_attributes() for i in range(10): attr_name = self.request.POST.get('attr_name[%d]' % i) attr_value = self.request.POST.get('attr_value[%d]' % i) if attr_name and attr_value: cust.set_attr(attr_name, attr_value) self.flash('Successfully saved %s %s.' % (cust.fname, cust.lname)) if do_redir: redir = self.request.POST.get('redir') return HTTPFound(redir if redir else '/crm/customer/edit/%s' % cust.customer_id) else: return cust
def _signup(self): """ KB: [2011-04-26]: Customer can't exist. Fail if there is a customer_id param The customer should never be able to get here if he's logged in. Forbid if there is a self.session open. Try to find the customer by the email provided. - If found by email, redirect back to the calling page (POST['url_path'] with msg = already_exists Save the customer object and store in the self.session as though the customer has logged in. If something goes wrong, redirect back to the calling page with msg = signup_failed """ self.forbid_if(self.request.POST.get('customer_id') or self.request.ctx.customer or not self.request.ctx.campaign) campaign = self.request.ctx.campaign cust = Customer.find(self.request.POST.get('email'), campaign) if cust: self.flash('Email %s already in use' % cust.email) self.raise_redirect(self.request.referrer) cust = Customer() cust.campaign_id = campaign.campaign_id cust.bind(self.request.POST) cust.save() cust.flush() self.session['customer_id'] = cust.customer_id cust.invalidate_caches() return cust