def get_message(self, context, language=None): """This function must return the tuple (subject, body) """ # Subject subject = MSG(u'[{title}] has been modified') subject = subject.gettext(title=self.get_title(), language=language) # Body message = MSG(u'DO NOT REPLY TO THIS EMAIL. To view modifications ' u'please visit:\n{resource_uri}') uri = context.get_link(self) uri = str(context.uri.resolve(uri)) uri += '/;commit_log' body = message.gettext(resource_uri=uri, language=language) # And return return subject, body
def __call__(self, **kw): if not kw: # Also skipping stl calls raise AttributeError, 'missing variables to substitute' message = MSG.gettext(self, language=None, **kw) # Send a translated copy of this instance return self.__class__(message, domain=self.domain)
def get_before_namespace(self, resource, context): # Set organizer infos in ${before} owner = resource.get_owner() owner = resource.get_resource(owner).get_title() owner_msg = MSG(u'<p id="event-owner">Created by <em>{owner}</em></p>') owner_msg = owner_msg.gettext(owner=owner).encode('utf-8') return XMLParser(owner_msg)
def action(self, resource, context, form): email = form['email'].strip() # 1. Make the user, or get it results = context.database.search(format='user', email=email) if len(results) == 0: # New user user = context.root.make_user() for name in self.fields: field = self.get_field(name) if field and getattr(field, 'persistent', True): self.set_value(user, context, name, form) user.update_pending_key() email_id = 'user-ask-for-confirmation' else: # User already registered user = results.get_resources().next() email_id = 'register-already-registered' # 2. Send email send_email(email_id, context, email, user=user) # 3. Show message message = MSG( u'<div id="registration-end-msg">' u'An email has been sent to you, to finish the registration ' u'process follow the instructions detailed in it.</div>') return message.gettext().encode('utf-8')
def get_form_title(self): param = self.get_param_folder() form_title = None user = self.get_resource('/users/' + self.name, soft=True) if user is not None: form_title = user.get_title() if form_title is None: form_title = self.get_title() msg = MSG(u"{application}: {form}") return msg.gettext(application=param.get_title(), form=form_title)
def get_namespace(self, resource, context): proxy = super(Shop_UserSendConfirmation, self) namespace = proxy.get_namespace(resource, context) confirm_msg = MSG(u"""Fill this form to receive a mail with the link to activate your account""") namespace['required_msg'] = (list(XMLParser(confirm_msg.gettext().encode('utf8'))) + list(XMLParser('<br/>')) + list(namespace['required_msg'])) return namespace
def get_title(self, context): if self.title is not None: return self.title cls = self._resource_class if cls: class_title = cls.class_title.gettext() title = MSG(u'Add {class_title}') return title.gettext(class_title=class_title) return MSG(u'Add resource').gettext()
def get_message(self, context, language=None): # Subject title=self.get_title() subject = MSG(u'The event "{title}" has been modified') subject = subject.gettext(title=title, language=language) # Body message = MSG(u'DO NOT REPLY TO THIS EMAIL.\n\n' u'The user "{last_author}" has made some modifications ' u'to the event "{title}".\n' u'To view these modifications please visit:\n' u'{resource_uri}\n') uri = context.get_link(self) uri = str(context.uri.resolve(uri)) uri += '/;edit' last_author = self.get_value('last_author') last_author = context.root.get_user_title(last_author) body = message.gettext(last_author=last_author, resource_uri=uri, title=title, language=language) # And return return subject, body
def GET(self, resource, context): try: from lpod.rst2odt import rst2odt except ImportError: msg = MSG(u'<p>Please install <a href="{href}">{name}</a> ' u'for Python on the server.</p>') msg = msg.gettext(href='http://lpod-project.org/', name='LpOD') return msg.encode('utf_8') # Just to ignore pyflakes warning rst2odt proxy = super(WikiPage_ToODT, self) return proxy.GET(resource, context)
def get_options(cls): context = get_context() container = context.resource.parent options = [{'name': '', 'value': MSG(u"lpoD default template")}] for resource in container.get_resources(): if not resource.class_id in ALLOWED_FORMATS: continue msg = MSG(u'{title} (<a href="{link}">view</a>)') msg = msg.gettext(title=resource.get_title(), link=context.get_link(resource)).encode('utf_8') options.append({'name': resource.name, 'value': XMLParser(msg)}) return options
def get_items(self, context): unit = self.get_property('unit') criterium = self.get_property('criterium') uri = context.uri options = [] get_record_value = self.handler.get_record_value # Get values values = [(None, None)] for record in self.handler.get_records(): min_value = get_record_value(record, 'min') max_value = get_record_value(record, 'max') values.append((min_value, max_value)) for value in values: min_value, max_value = value min_value_q = int(min_value * 100) if min_value else None max_value_q = int(max_value * 100) if max_value else None value = (min_value_q, max_value_q) name = IntegerRange.encode(value) if min_value is None and max_value: title = MSG(u'Less than {max_value} {unit}') elif min_value and max_value: title = MSG(u'From {min_value} to {max_value} {unit}') elif max_value is None and min_value: title = MSG(u'More than {min_value} {unit}') else: title = MSG(u'All') name = None value = None selected = context.query.get(criterium) == value kw = {criterium: name, 'batch_start': 0} uri = uri.replace(**kw) title = title.gettext(min_value=min_value, max_value=max_value, unit=unit) options.append({ 'name': name, 'criterium': criterium, 'query': RangeQuery(criterium, min_value_q, max_value_q), 'selected': selected, 'uri': uri, 'css': 'selected' if selected else None, 'title': title }) return options
def get_payment_way_description(self, context, total_amount): msg = MSG(u"Pay {percent}% of {original_amount} now ({amount})") percent = self.get_property('percent') if self.get_property('pay_tax'): total_amount = total_amount['with_tax'].split(' ')[0] total_amount = decimal(total_amount) else: total_amount = total_amount['without_tax'].split(' ')[0] total_amount = decimal(total_amount) amount = total_amount * (percent / decimal('100.0')) msg = msg.gettext(percent=percent, original_amount=format_price(total_amount), amount=format_price(amount)) return list(XMLParser(msg.encode('utf-8'))) + self.get_property('data')
def action_postpone(self, resource, context, form): postpone = form['postpone'] alert = datetime.combine(postpone, time(9, 0)) pattern = MSG(u'<a href="{path}">{title}</a>', format='replace') missions = [] for path in form['ids']: mission = resource.get_resource(path) mission.set_property('crm_m_alert', alert) missions.append(pattern.gettext(path=path, title=mission.get_title())) postpone = context.format_date(postpone) missions = u", ".join(missions) context.message = MSG_MISSIONS_POSTPONED(postpone=postpone, missions=missions)
def get_template_title(self, context): here = context.resource # XXX Confidentiality problems if isinstance(here, ShopUser): return here.get_public_title() # In the website site_root = here.get_site_root() if site_root is here: return site_root.get_title() # Somewhere else if site_root.get_property('hide_website_title_on_meta_title'): message = MSG(u"{here_title}") else: message = MSG(u"{here_title} > {root_title}") return message.gettext(root_title=site_root.get_title(), here_title=here.get_title())
def get_linked_resources_message(resource, context, state='public'): # Customize message if webpage uses private/pending resources referenced_resources = list(get_linked_resources(resource)) if len(referenced_resources) == 0: return None message = MSG(u'This {title} uses pending/private resources ' u'please go to ' u'<a href="{path}/;backlinks">backlinks interface</a>.') path = context.get_link(resource) path = XMLContent.encode(path) class_title = resource.class_title.gettext() message = message.gettext(title=class_title, path=path).encode('utf8') message = XHTMLBody.decode(message) # Return custom message return message
def _register(self, resource, context, email): site_root = context.site_root # Add the user users = site_root.get_resource('users') user = users.set_user(email, None) # Set the role to 'Member' default_role = site_root.class_roles[1] site_root.set_user_role(user.name, default_role) # Send confirmation email user.send_confirmation(context, email) # Bring the user to the login form message = MSG( u"An email has been sent to you, to finish the registration " u"process follow the instructions detailed in it.") return message.gettext().encode('utf-8')
def get_items(self, context): unit = self.get_property("unit") criterium = self.get_property("criterium") uri = context.uri options = [] get_record_value = self.handler.get_record_value # Get values values = [(None, None)] for record in self.handler.get_records(): min_value = get_record_value(record, "min") max_value = get_record_value(record, "max") values.append((min_value, max_value)) for value in values: min_value, max_value = value min_value_q = int(min_value * 100) if min_value else None max_value_q = int(max_value * 100) if max_value else None value = (min_value_q, max_value_q) name = IntegerRange.encode(value) if min_value is None and max_value: title = MSG(u"Less than {max_value} {unit}") elif min_value and max_value: title = MSG(u"From {min_value} to {max_value} {unit}") elif max_value is None and min_value: title = MSG(u"More than {min_value} {unit}") else: title = MSG(u"All") name = None value = None selected = context.query.get(criterium) == value kw = {criterium: name, "batch_start": 0} uri = uri.replace(**kw) title = title.gettext(min_value=min_value, max_value=max_value, unit=unit) options.append( { "name": name, "criterium": criterium, "query": RangeQuery(criterium, min_value_q, max_value_q), "selected": selected, "uri": uri, "css": "selected" if selected else None, "title": title, } ) return options
def get_namespace(self, resource, context): proxy = super(Shop_UserConfirmRegistration, self) namespace = proxy.get_namespace(resource, context) confirm_msg = MSG(u""" You have not yet confirmed your registration.<br/> To confirm it, please click on the confirmation link included on the registration confirmation email.<br/> You can also fill your email address and your activation key (received on the mail) in the following form.<br/> If you havn't received your registration key, <a href=";send_confirmation_view"> you can receive it again by clicking here. </a> """) namespace['required_msg'] = (list(XMLParser(confirm_msg.gettext().encode('utf8'))) + list(XMLParser('<br/>')) + list(namespace['required_msg'])) return namespace
def get_template_title(self, context): """Return the title to give to the template document. """ here = context.resource root = context.root root_title = root.get_title() # Choose the template if not root.is_allowed_to_view(context.user, here): return '' elif root is here: template = MSG(u"{view_title} - {root_title}") here_title = None else: template = MSG(u"{here_title} - {view_title} - {root_title}") here_title = here.get_title() # The view view_title = context.view.get_title(context) # Ok return template.gettext(root_title=root_title, here_title=here_title, view_title=view_title)
def get_namespace(self, resource, context): path = context.query['path'] if path is None: path = Path('.') if path.startswith_slash: path.startswith_slash = False # Namespace: the location base = '/%s/;browse_tests' % context.site_root.get_pathto(resource) link = base + '?path=%s' location = [{'name': MSG(u'Test Suite'), 'link': link % '.'}] for i, name in enumerate(path): p = path[:i+1] try: test_suite.get_handler(p) except LookupError: location.append({'name': name, 'link': None}) body = MSG(u'The "{path}" resource has not been found') body = body.gettext(path=p) return {'location': location, 'body': body} else: location.append({'name': name, 'link': link % p}) # Get the handler handler = test_suite.get_handler(path) # (1) View PO file root = context.root if isinstance(handler, POFile): template = root.get_resource('/ui/odf-i18n/view_po.xml') units = handler.get_units() msgs = [ {'id': x.source, 'str': x.target} for x in units ] namespace = {'messages': msgs} body = stl(template, namespace) return {'location': location, 'body': body} # Load setup file if handler.has_handler('setup.conf'): setup = handler.get_handler('setup.conf', cls=ConfigFile) else: setup = None # (2) Browse Folders children = handler.get_handler_names() children.sort() a_handler = handler.get_handler(children[0]) if isinstance(a_handler, Folder): files = [] for child in children: child_handler = handler.get_handler(child) number = 0 for x in test_suite.database.fs.traverse(child_handler.key): if x.endswith('.po'): number += 1 files.append({'child_name': child, 'to_child': link % ('%s/%s' % (path, child)), 'number': number}) namespace = {'content': files} template = root.get_resource('/ui/odf-i18n/browse_folder.xml') body = stl(template, namespace) return {'location': location, 'body': body} # (3) Test Folder if setup is None: title = description = reference = url_reference = None else: title = setup.get_value('title') description = setup.get_value('description') reference = setup.get_value('reference') url_reference = setup.get_value('url_reference') # Format the description (may contain XML) description = XMLParser(description) files = [] for child in children: if child != 'setup.conf': child_path = '%s/%s' % (path, child) view = (link % child_path) if child.endswith('.po') else None files.append({ 'child_name': child, 'view': view, 'to_child': ';download?path=%s' % child_path}) template = root.get_resource('/ui/odf-i18n/browse_test.xml') namespace = { 'title': title, 'description': description, 'reference': reference, 'url_reference': url_reference, 'content': files} body = stl(template, namespace) return {'location': location, 'body': body}
def say_hello(): message = MSG(u'Hello World') print message.gettext()
def get_title(self, context): if self.title is not None: return self.title class_title = self.add_cls.class_title.gettext() title = MSG(u'Add {class_title}') return title.gettext(class_title=class_title)
def gettext(self, language=None): # Gettext calling was defered return MSG.gettext(self, language=language, **self.kw)
def get_namespace(self, resource, context): resource_zones = resource.get_resource('../countries-zones') handler_countries = resource.get_resource('../countries').handler if self.show_inactive: page_title = MSG('Inactives shippings prices') else: page_title = MSG('Shippings price') namespace = { 'zones': [], 'msg_if_no_shipping': resource.get_property('msg_if_no_shipping'), 'page_title': page_title } for zone in resource_zones.handler.get_records_in_order(): countries = [] for country in handler_countries.search(zone=str(zone.id)): title = handler_countries.get_record_value(country, 'title') if handler_countries.get_record_value(country, 'enabled') is False: continue countries.append(title) if len(countries) == 0: continue zone_title = resource_zones.handler.get_record_value(zone, 'title') tarifications = [] for tarification in resource.get_resources(): # We show only active or inactives modes, depending on config if tarification.get_property('enabled') is self.show_inactive: continue mode = tarification.get_property('mode') unit = MSG(u'Kg') if mode == 'weight' else MSG(u'Unit') prices = [] min = old_price = 0 prices_resource = tarification.get_resource('prices') prices_handler = prices_resource.handler tarif_edit = context.get_link(prices_resource) tarif_edit += '/?zone=%i&search=' % zone.id records = prices_handler.search(zone=str(zone.id)) records.sort(key=lambda x: prices_handler.get_record_value( x, 'max-%s' % mode)) for price in records: max = prices_handler.get_record_value( price, 'max-%s' % mode) price = prices_handler.get_record_value(price, 'price') prices.append({ 'title': '%s to %s %s' % (min, max, unit.gettext()), 'price': price, 'error': price <= old_price }) min = max old_price = price if len(prices) == 0: continue kw = { 'name': tarification.name, 'models': [], 'title': tarification.get_title(), 'img': tarification.get_property('logo'), 'is_free': tarification.get_property('is_free'), 'prices': prices, 'description': tarification.get_property('description'), 'tarif_edit': tarif_edit } models = tarification.get_property('only_this_models') for model_abspath in models: model = context.root.get_resource(model_abspath) kw['models'].append(model.get_title()) tarifications.append(kw) zone_edit = '/shop/countries?zone=%i&search=' % zone.id has_tax = resource_zones.handler.get_record_value(zone, 'has_tax') tax_image = list(bool_to_img(has_tax)) namespace['zones'].append({ 'title': zone_title, 'countries': countries, 'tarifications': tarifications, 'zone_edit': zone_edit, 'tax_image': tax_image }) return namespace
def get_namespace(self, resource, context): resource_zones = resource.get_resource('../countries-zones') handler_countries = resource.get_resource('../countries').handler if self.show_inactive: page_title = MSG('Inactives shippings prices') else: page_title = MSG('Shippings price') namespace = { 'zones': [], 'msg_if_no_shipping': resource.get_property('msg_if_no_shipping'), 'page_title': page_title} for zone in resource_zones.handler.get_records_in_order(): countries = [] for country in handler_countries.search(zone=str(zone.id)): title = handler_countries.get_record_value(country, 'title') if handler_countries.get_record_value(country, 'enabled') is False: continue countries.append(title) if len(countries) == 0: continue zone_title = resource_zones.handler.get_record_value(zone, 'title') tarifications = [] for tarification in resource.get_resources(): # We show only active or inactives modes, depending on config if tarification.get_property('enabled') is self.show_inactive: continue mode = tarification.get_property('mode') unit = MSG(u'Kg') if mode == 'weight' else MSG(u'Unit') prices = [] min = old_price = 0 prices_resource = tarification.get_resource('prices') prices_handler = prices_resource.handler tarif_edit = context.get_link(prices_resource) tarif_edit += '/?zone=%i&search=' % zone.id records = prices_handler.search(zone=str(zone.id)) records.sort(key=lambda x: prices_handler.get_record_value(x, 'max-%s' % mode)) for price in records: max = prices_handler.get_record_value(price, 'max-%s' % mode) price = prices_handler.get_record_value(price, 'price') prices.append( {'title': '%s to %s %s' % (min, max, unit.gettext()), 'price': price, 'error': price<=old_price}) min = max old_price = price if len(prices) == 0: continue kw = { 'name': tarification.name, 'models': [], 'title': tarification.get_title(), 'img': tarification.get_property('logo'), 'is_free': tarification.get_property('is_free'), 'prices': prices, 'description': tarification.get_property('description'), 'tarif_edit': tarif_edit} models = tarification.get_property('only_this_models') for model_abspath in models: model = context.root.get_resource(model_abspath) kw['models'].append(model.get_title()) tarifications.append(kw) zone_edit = '/shop/countries?zone=%i&search=' % zone.id has_tax = resource_zones.handler.get_record_value(zone, 'has_tax') tax_image = list(bool_to_img(has_tax)) namespace['zones'].append({'title': zone_title, 'countries': countries, 'tarifications': tarifications, 'zone_edit': zone_edit, 'tax_image': tax_image}) return namespace