class RegistrationForm(Form): "Simple Registration form" name = TextField(_('Name'), [validators.DataRequired(), ]) email = TextField(_('e-mail'), [validators.DataRequired(), validators.Email()]) # noqa password = PasswordField(_('New Password'), [ validators.DataRequired(), validators.EqualTo('confirm', message=_('Passwords must match'))]) confirm = PasswordField(_('Confirm Password')) if config.has_option('nereid', 're_captcha_public_key') and \ config.has_option('nereid', 're_captcha_private_key'): captcha = RecaptchaField( public_key=config.get('nereid', 're_captcha_public_key'), private_key=config.get('nereid', 're_captcha_private_key'), secure=True )
def send_sms(text, to): assert len(text) <= 160, text if config.has_option('authentication_sms', 'function'): func = resolve(config.get('authentication_sms', 'function')) if func: from_ = config.get('authentication_sms', 'from', default=None) return func(text, to, from_) logger.error('Could not send SMS to %s: "%s"', to, text)
def get_registration_form(): """ Returns a registration form for use in the site .. tip:: Configuration of re_captcha Remember to forward X-Real-IP in the case of Proxy servers """ # Add re_captcha if the configuration has such an option if config.has_option("nereid", "re_captcha_public_key"): registration_form = RegistrationForm(captcha={"ip_address": request.remote_addr}) else: registration_form = RegistrationForm() return registration_form
def test_xml_files(self): "Test validity of the xml files of the module" config = ConfigParser() with file_open('%s/tryton.cfg' % self.module, subdir='modules', mode='r', encoding='utf-8') as fp: config.read_file(fp) if not config.has_option('tryton', 'xml'): return with file_open('tryton.rng', subdir='', mode='rb') as fp: rng = etree.parse(fp) validator = etree.RelaxNG(etree=rng) for xml_file in filter(None, config.get('tryton', 'xml').splitlines()): with file_open('%s/%s' % (self.module, xml_file), subdir='modules', mode='rb') as fp: tree = etree.parse(fp) validator.assertValid(tree)
def get_registration_form(): """ Returns a registration form for use in the site .. tip:: Configuration of re_captcha Remember to forward X-Real-IP in the case of Proxy servers """ # Add re_captcha if the configuration has such an option if config.has_option('nereid', 're_captcha_public_key'): registration_form = RegistrationForm( captcha={'ip_address': request.remote_addr}) else: registration_form = RegistrationForm() return registration_form
return None, None return loader app = TrytondWSGI() if config.get('web', 'root'): static_files = { '/': config.get('web', 'root'), } app.wsgi_app = SharedDataMiddlewareIndex( app.wsgi_app, static_files, cache_timeout=config.getint('web', 'cache_timeout')) num_proxies = config.getint('web', 'num_proxies') if num_proxies: app.wsgi_app = NumProxyFix(app.wsgi_app, num_proxies) if config.has_section('wsgi middleware'): for middleware in config.options('wsgi middleware'): Middleware = resolve(config.get('wsgi middleware', middleware)) args, kwargs = (), {} section = 'wsgi %s' % middleware if config.has_section(section): if config.has_option(section, 'args'): args = eval(config.get(section, 'args')) if config.has_option(section, 'kwargs'): kwargs = eval(config.get(section, 'kwargs')) app.wsgi_app = Middleware(app.wsgi_app, *args, **kwargs) import trytond.protocols.dispatcher # noqa: E402,F401 import trytond.bus # noqa: E402,F401
def new_opportunity(cls): """ Web handler to create a new sale opportunity """ if config.has_option('nereid', 're_captcha_public_key'): contact_form = ContactUsForm( request.form, captcha={'ip_address': request.remote_addr} ) else: contact_form = ContactUsForm(request.form) if request.method == 'POST': if not contact_form.validate(): return jsonify({ "success": False, "message": "Field validation error", "errors": contact_form.errors, }) ContactMech = Pool().get('party.contact_mechanism') Party = Pool().get('party.party') Config = Pool().get('sale.configuration') sale_config = Config(1) contact_data = contact_form.data # Create Party company = request.nereid_website.company.id if request.remote_addr and geoip: detected_country = geoip.country_name_by_addr( request.remote_addr ) else: detected_country = None party, = Party.create([{ 'name': contact_data.get('company') or contact_data['name'], 'addresses': [ ('create', [{ 'name': contact_data['name'], }]) ], }]) if contact_data.get('website'): # Create website as contact mech ContactMech.create([{ 'type': 'website', 'party': party.id, 'website': contact_data['website'], }]) if contact_data.get('phone'): # Create phone as contact mech and assign as phone ContactMech.create([{ 'type': 'phone', 'party': party.id, 'other_value': contact_data['phone'], }]) # Create email as contact mech and assign as email ContactMech.create([{ 'type': 'email', 'party': party.id, 'email': contact_data['email'], }]) # Create sale opportunity if not current_user.is_anonymous() and current_user.employee: employee = current_user.employee.id description = 'Created by %s' % \ current_user.display_name else: employee = sale_config.website_employee.id description = 'Created from website' lead, = cls.create([{ 'party': party.id, 'company': company, 'employee': employee, 'address': party.addresses[0].id, 'description': description, 'comment': contact_data['comment'], 'ip_address': request.remote_addr, 'detected_country': detected_country, }]) lead.send_notification_mail() if request.is_xhr or request.is_json: return jsonify({ "success": True, "message": "Contact saved", "lead_id": lead.id, }) return redirect(request.args.get( 'next', url_for('sale.opportunity.admin_lead', active_id=lead.id) )) return render_template('crm/sale_form.jinja', form=contact_form)