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 contact(self): camp = self.request.ctx.campaign message = self.request.POST.get('message') email = self.request.POST.get('email') msg = "%s %s<br>(%s)<br><br>%s<br><br>%s" % (self.request.POST.get('fname'), self.request.POST.get('lname'), email, self.request.POST.get('phone'), message) if util.nvl(self.request.POST.get('save')): cust = Customer.find(email, camp) if not cust: cust = Customer() cust.campaign = camp cust.bind(self.request.POST) cust.phone = cust.phone[:20] if cust.phone else None # prevents people from putting in "904-716-7487 (mobile)" and it barfs cust.save() Status.add(cust, cust, Status.find_event(self.enterprise_id, cust, 'NOTE'), 'NOTE FROM CUSTOMER\n%s' % message) email_info = camp.get_email_info() mail = UserMail(camp) mail.send(email_info.email, 'SITE CONTACT FORM %s' % self.request.host, msg) return self.find_redirect()
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