def display(self, **params): from indico.modules.admin import RHAdminBase from indico.modules.core.settings import core_settings, social_settings title_parts = [self.title] if self.MANAGEMENT: title_parts.insert(0, _('Management')) elif isinstance(self._rh, RHAdminBase): title_parts.insert(0, _('Administration')) injected_bundles = values_from_signal(signals.plugin.inject_bundle.send(self.__class__), as_list=True, multi_value_types=list) custom_js = list(current_app.manifest['__custom.js']) custom_css = list(current_app.manifest['__custom.css']) css_files = map(self._fix_path, self.get_extra_css_files() + custom_css) js_files = map(self._fix_path, custom_js) body = to_unicode(self._display(params)) bundles = itertools.chain((current_app.manifest[x] for x in self._resolve_bundles() if x in current_app.manifest._entries), self.additional_bundles['screen'], injected_bundles) print_bundles = itertools.chain((current_app.manifest[x] for x in self.print_bundles), self.additional_bundles['print']) return render_template('indico_base.html', css_files=css_files, js_files=js_files, bundles=bundles, print_bundles=print_bundles, site_name=core_settings.get('site_title'), social=social_settings.get_all(), page_title=' - '.join(unicode(x) for x in title_parts if x), head_content=to_unicode(self._getHeadContent()), body=body)
def display(cls, template_name, **params): from indico.modules.admin import RHAdminBase from indico.modules.core.settings import core_settings, social_settings title_parts = [cls.title] if cls.MANAGEMENT: title_parts.insert(0, _('Management')) elif isinstance(g.rh, RHAdminBase): title_parts.insert(0, _('Administration')) injected_bundles = values_from_signal(signals.plugin.inject_bundle.send(cls), as_list=True, multi_value_types=list) custom_js = list(current_app.manifest['__custom.js']) custom_css = list(current_app.manifest['__custom.css']) css_files = map(cls._fix_path, custom_css) js_files = map(cls._fix_path, custom_js) bundles = itertools.chain((current_app.manifest[x] for x in cls._resolve_bundles() if x in current_app.manifest._entries), cls.additional_bundles['screen'], injected_bundles) print_bundles = itertools.chain((current_app.manifest[x] for x in cls.print_bundles), cls.additional_bundles['print']) template = cls._prefix_template(template_name) return render_template(template, css_files=css_files, js_files=js_files, bundles=bundles, print_bundles=print_bundles, site_name=core_settings.get('site_title'), social=social_settings.get_all(), page_title=' - '.join(unicode(x) for x in title_parts if x), **params)
def register_instance(contact, email): payload = {'url': config.BASE_URL, 'contact': contact, 'email': email, 'organization': core_settings.get('site_organization')} response = requests.post(_get_url(), data=json.dumps(payload), headers=HEADERS, timeout=TIMEOUT, verify=(not config.DEBUG)) try: response.raise_for_status() except HTTPError as err: logger.error('failed to register the server to the community hub, got: %s', err) cephalopod_settings.set('joined', False) raise except Timeout: logger.error('failed to register: timeout while contacting the community hub') cephalopod_settings.set('joined', False) raise except RequestException as err: logger.error('unexpected exception while registering the server with the Community Hub: %s', err) raise json_response = response.json() if 'uuid' not in json_response: logger.error('invalid json reply from the community hub: uuid missing') cephalopod_settings.set('joined', False) raise ValueError('invalid json reply from the community hub: uuid missing') cephalopod_settings.set_multi({ 'joined': True, 'uuid': json_response['uuid'], 'contact_name': payload['contact'], 'contact_email': payload['email'] }) logger.info('successfully registered the server to the community hub')
def display(self, **params): from indico.modules.admin import RHAdminBase from indico.modules.core.settings import core_settings, social_settings title_parts = [to_unicode(self._getTitle())] if self.MANAGEMENT: title_parts.append(_('Management area')) elif isinstance(self._rh, RHAdminBase): title_parts.append(_('Administration area')) plugin_css = values_from_signal(signals.plugin.inject_css.send(self.__class__), as_list=True, multi_value_types=list) plugin_js = values_from_signal(signals.plugin.inject_js.send(self.__class__), as_list=True, multi_value_types=list) custom_js = self._asset_env['custom_js'].urls() if 'custom_js' in self._asset_env else [] custom_css = self._asset_env['custom_sass'].urls() if 'custom_sass' in self._asset_env else [] css_files = map(self._fix_path, self.getCSSFiles() + plugin_css + self.get_extra_css_files() + custom_css) print_css_files = map(self._fix_path, self.getPrintCSSFiles()) js_files = map(self._fix_path, self.getJSFiles() + plugin_js + custom_js) body = to_unicode(self._display(params)) return render_template('indico_base.html', css_files=css_files, print_css_files=print_css_files, js_files=js_files, site_name=core_settings.get('site_title'), social=social_settings.get_all(), page_title=' - '.join(title_parts), head_content=to_unicode(self._getHeadContent()), body=body)
def display(self, **params): from indico.modules.admin import RHAdminBase from indico.modules.core.settings import core_settings, social_settings title_parts = [*self._extra_title_parts, self.title] if self.MANAGEMENT: title_parts.insert(0, _('Management')) elif isinstance(self._rh, RHAdminBase): title_parts.insert(0, _('Administration')) injected_bundles = values_from_signal(signals.plugin.inject_bundle.send(self.__class__), as_list=True, multi_value_types=list) custom_js = list(current_app.manifest['__custom.js']) custom_css = list(current_app.manifest['__custom.css']) css_files = list(map(self._fix_path, self.get_extra_css_files() + custom_css)) js_files = list(map(self._fix_path, custom_js)) body = self._display(params) bundles = itertools.chain((current_app.manifest[x] for x in self._resolve_bundles() if x in current_app.manifest._entries), self.additional_bundles['screen'], injected_bundles) print_bundles = itertools.chain((current_app.manifest[x] for x in self.print_bundles), self.additional_bundles['print']) return render_template('indico_base.html', css_files=css_files, js_files=js_files, bundles=bundles, print_bundles=print_bundles, site_name=core_settings.get('site_title'), social=social_settings.get_all(), page_metadata=self.page_metadata, page_title=' - '.join(str(x) for x in title_parts if x), head_content=self._get_head_content(), body=body)
def register_instance(contact, email): payload = {'url': config.BASE_URL, 'contact': contact, 'email': email, 'organization': core_settings.get('site_organization')} response = requests.post(_get_url(), data=json.dumps(payload), headers=HEADERS, timeout=TIMEOUT, verify=(not config.DEBUG)) try: response.raise_for_status() except HTTPError as err: logger.error('failed to register the server to the community hub, got: %s', err.message) cephalopod_settings.set('joined', False) raise except Timeout: logger.error('failed to register: timeout while contacting the community hub') cephalopod_settings.set('joined', False) raise except RequestException as err: logger.error('unexpected exception while registering the server with the Community Hub: %s', err.message) raise json_response = response.json() if 'uuid' not in json_response: logger.error('invalid json reply from the community hub: uuid missing') cephalopod_settings.set('joined', False) raise ValueError('invalid json reply from the community hub: uuid missing') cephalopod_settings.set_multi({ 'joined': True, 'uuid': json_response['uuid'], 'contact_name': payload['contact'], 'contact_email': payload['email'] }) logger.info('successfully registered the server to the community hub')
def display(cls, template_name, **params): from indico.modules.admin import RHAdminBase from indico.modules.core.settings import core_settings, social_settings title_parts = [cls.title] if cls.MANAGEMENT: title_parts.insert(0, _('Management')) elif isinstance(g.rh, RHAdminBase): title_parts.insert(0, _('Administration')) injected_bundles = values_from_signal(signals.plugin.inject_bundle.send(cls), as_list=True, multi_value_types=list) custom_js = list(current_app.manifest['__custom.js']) custom_css = list(current_app.manifest['__custom.css']) css_files = list(map(cls._fix_path, custom_css)) js_files = list(map(cls._fix_path, custom_js)) bundles = itertools.chain((current_app.manifest[x] for x in cls._resolve_bundles() if x in current_app.manifest._entries), cls.additional_bundles['screen'], injected_bundles) print_bundles = itertools.chain((current_app.manifest[x] for x in cls.print_bundles), cls.additional_bundles['print']) template = cls._prefix_template(template_name) return render_template(template, css_files=css_files, js_files=js_files, page_metadata=cls.page_metadata, bundles=bundles, print_bundles=print_bundles, site_name=core_settings.get('site_title'), social=social_settings.get_all(), page_title=' - '.join(str(x) for x in title_parts if x), **params)
def _get_head_content(self): site_name = core_settings.get('site_title') meta = render_template('events/meta.html', event=self.event, site_name=site_name, json_ld=serialize_event_for_json_ld(self.event, full=True)) return WPDecorated._get_head_content(self) + meta
def page_metadata(self): site_name = core_settings.get('site_title') return { 'og': { 'site_name': (site_name + ' (Indico)') if site_name != 'Indico' else site_name, 'image': url_for('assets.image', filename='indico_square.png', _external=True) } }
def getVars(self): v = wcomponents.WTemplated.getVars( self ) v['site_name'] = core_settings.get('site_title') v['social'] = social_settings.get_all() event = self._conf.as_event v['image'] = event.logo_url if event.has_logo else (config.IMAGES_BASE_URL + '/logo_indico.png') v['description'] = strip_ml_tags(self._conf.as_event.description[:500].encode('utf-8')) return v
def getVars(self): v = wcomponents.WTemplated.getVars( self ) v['site_name'] = core_settings.get('site_title') v['social'] = social_settings.get_all() event = self._conf.as_event v['image'] = event.logo_url if event.has_logo else Config.getInstance().getSystemIconURL("logo_indico") v['description'] = strip_ml_tags(self._conf.as_event.description[:500].encode('utf-8')) return v
def sync_instance(contact, email): contact = contact or cephalopod_settings.get('contact_name') email = email or cephalopod_settings.get('contact_email') # registration needed if the instance does not have a uuid if not cephalopod_settings.get('uuid'): logger.warning( 'unable to synchronize: missing uuid, registering the server instead' ) register_instance(contact, email) return payload = { 'enabled': True, 'url': config.BASE_URL, 'contact': contact, 'email': email, 'organization': core_settings.get('site_organization') } url = url_join(_get_url(), cephalopod_settings.get('uuid')) response = requests.patch(url, data=json.dumps(payload), headers=HEADERS, timeout=TIMEOUT, verify=(not config.DEBUG)) try: response.raise_for_status() except HTTPError as err: if err.response.status_code == 404: logger.warning( 'unable to synchronize: the server was not registered, registering the server now' ) register_instance(contact, email) else: logger.error( 'failed to synchronize the server with the community hub, got: %s', err) raise except Timeout: logger.error( 'failed to synchronize: timeout while contacting the community hub' ) raise except RequestException as err: logger.error( 'unexpected exception while synchronizing the server with the Community Hub: %s', err) raise else: cephalopod_settings.set_multi({ 'joined': True, 'contact_name': payload['contact'], 'contact_email': payload['email'] }) logger.info( 'successfully synchronized the server with the community hub')
def _get_cephalopod_data(self): if not cephalopod_settings.get('joined'): return None, {'enabled': False} url = url_join(Config.getInstance().getTrackerURL(), 'api/instance/{}'.format(cephalopod_settings.get('uuid'))) data = {'enabled': cephalopod_settings.get('joined'), 'contact': cephalopod_settings.get('contact_name'), 'email': cephalopod_settings.get('contact_email'), 'url': Config.getInstance().getBaseURL(), 'organisation': core_settings.get('site_organization')} return url, data
def _get_cephalopod_data(self): if not cephalopod_settings.get('joined'): return None, {'enabled': False} url = url_join(config.COMMUNITY_HUB_URL, 'api/instance/{}'.format(cephalopod_settings.get('uuid'))) data = {'enabled': cephalopod_settings.get('joined'), 'contact': cephalopod_settings.get('contact_name'), 'email': cephalopod_settings.get('contact_email'), 'url': config.BASE_URL, 'organization': core_settings.get('site_organization')} return url, data
def _get_cephalopod_data(self): if not cephalopod_settings.get('joined'): return None, {'enabled': False} url = url_join(config.COMMUNITY_HUB_URL, 'api/instance/{}'.format(cephalopod_settings.get('uuid'))) data = {'enabled': cephalopod_settings.get('joined'), 'contact': cephalopod_settings.get('contact_name'), 'email': cephalopod_settings.get('contact_email'), 'url': config.BASE_URL, 'organization': core_settings.get('site_organization')} return url, data
def _process(self): form = CephalopodForm(obj=FormDefaults(**cephalopod_settings.get_all())) if form.validate_on_submit(): return self._process_form(form) hub_url = url_join(config.COMMUNITY_HUB_URL, 'api/instance/{}'.format(cephalopod_settings.get('uuid'))) cephalopod_settings.set('show_migration_message', False) return WPCephalopod.render_template('cephalopod.html', 'cephalopod', affiliation=core_settings.get('site_organization'), enabled=cephalopod_settings.get('joined'), form=form, indico_version=indico.__version__, instance_url=config.BASE_URL, language=config.DEFAULT_LOCALE, operating_system=get_os(), postgres_version=get_postgres_version(), python_version=platform.python_version(), hub_url=hub_url)
def send(self): """Send the reminder to its recipients.""" self.is_sent = True recipients = self.all_recipients if not recipients: logger.info('Notification %s has no recipients; not sending anything', self) return email_tpl = make_reminder_email(self.event, self.include_summary, self.include_description, self.message) attachments = [] if self.attach_ical: event_ical = event_to_ical(self.event, skip_access_check=True, method='REQUEST', organizer=(core_settings.get('site_title'), config.NO_REPLY_EMAIL)) attachments.append(MIMECalendar('event.ics', event_ical)) for recipient in recipients: email = self._make_email(recipient, email_tpl, attachments) send_email(email, self.event, 'Reminder', self.creator, log_metadata={'reminder_id': self.id})
def _notify_registration(registration, template_name, to_managers=False, attach_rejection_reason=False, diff=None, old_price=None): from indico.modules.events.registration.util import get_ticket_attachments attachments = [] regform = registration.registration_form tickets_handled = values_from_signal( signals.event.is_ticketing_handled.send(regform), single_value=True) if (not to_managers and regform.tickets_enabled and regform.ticket_on_email and not any(tickets_handled) and registration.state == RegistrationState.complete): attachments += get_ticket_attachments(registration) if not to_managers and registration.registration_form.attach_ical: event_ical = event_to_ical(registration.event, method='REQUEST', organizer=(core_settings.get('site_title'), config.NO_REPLY_EMAIL)) attachments.append(MIMECalendar('event.ics', event_ical)) tpl = get_template_module(f'events/registration/emails/{template_name}', registration=registration, attach_rejection_reason=attach_rejection_reason, diff=diff, old_price=old_price) to_list = registration.email if not to_managers else registration.registration_form.manager_notification_recipients from_address = registration.registration_form.notification_sender_address if not to_managers else None mail = make_email(to_list=to_list, template=tpl, html=True, from_address=from_address, attachments=attachments) user = session.user if session else None signals.core.before_notification_send.send( 'notify-registration', email=mail, registration=registration, template_name=template_name, attach_rejection_reason=attach_rejection_reason) send_email(mail, event=registration.registration_form.event, module='Registration', user=user, log_metadata={'registration_id': registration.id})
def _process(self): form = CephalopodForm(obj=FormDefaults(**cephalopod_settings.get_all())) if form.validate_on_submit(): return self._process_form(form) hub_url = url_join(config.COMMUNITY_HUB_URL, 'api/instance/{}'.format(cephalopod_settings.get('uuid'))) cephalopod_settings.set('show_migration_message', False) return WPCephalopod.render_template('cephalopod.html', 'cephalopod', affiliation=core_settings.get('site_organization'), enabled=cephalopod_settings.get('joined'), form=form, indico_version=indico.__version__, instance_url=config.BASE_URL, language=config.DEFAULT_LOCALE, operating_system=get_os(), postgres_version=get_postgres_version(), python_version=platform.python_version(), hub_url=hub_url, show_local_warning=(config.DEBUG or is_private_url(request.url_root)))
def display(self, **params): from indico.modules.admin import RHAdminBase from indico.modules.core.settings import core_settings, social_settings title_parts = [self.title] if self.MANAGEMENT: title_parts.insert(0, _('Management')) elif isinstance(self._rh, RHAdminBase): title_parts.insert(0, _('Administration')) plugin_css = values_from_signal(signals.plugin.inject_css.send( self.__class__), as_list=True, multi_value_types=list) plugin_js = values_from_signal(signals.plugin.inject_js.send( self.__class__), as_list=True, multi_value_types=list) custom_js = self._asset_env['custom_js'].urls( ) if 'custom_js' in self._asset_env else [] custom_css = self._asset_env['custom_sass'].urls( ) if 'custom_sass' in self._asset_env else [] css_files = map( self._fix_path, self.getCSSFiles() + plugin_css + self.get_extra_css_files() + custom_css) print_css_files = map(self._fix_path, self.getPrintCSSFiles()) js_files = map(self._fix_path, self.getJSFiles() + plugin_js + custom_js) body = to_unicode(self._display(params)) return render_template('indico_base.html', css_files=css_files, print_css_files=print_css_files, js_files=js_files, site_name=core_settings.get('site_title'), social=social_settings.get_all(), page_title=' - '.join( unicode(x) for x in title_parts if x), head_content=to_unicode(self._getHeadContent()), body=body)
def sync_instance(contact, email): contact = contact or cephalopod_settings.get('contact_name') email = email or cephalopod_settings.get('contact_email') # registration needed if the instance does not have a uuid if not cephalopod_settings.get('uuid'): logger.warn('unable to synchronize: missing uuid, registering the server instead') register_instance(contact, email) return payload = {'enabled': True, 'url': config.BASE_URL, 'contact': contact, 'email': email, 'organization': core_settings.get('site_organization')} url = url_join(_get_url(), cephalopod_settings.get('uuid')) response = requests.patch(url, data=json.dumps(payload), headers=HEADERS, timeout=TIMEOUT, verify=(not config.DEBUG)) try: response.raise_for_status() except HTTPError as err: if err.response.status_code == 404: logger.warn('unable to synchronize: the server was not registered, registering the server now') register_instance(contact, email) else: logger.error('failed to synchronize the server with the community hub, got: %s', err.message) raise except Timeout: logger.error('failed to synchronize: timeout while contacting the community hub') raise except RequestException as err: logger.error('unexpected exception while synchronizing the server with the Community Hub: %s', err.message) raise else: cephalopod_settings.set_multi({ 'joined': True, 'contact_name': payload['contact'], 'contact_email': payload['email']}) logger.info('successfully synchronized the server with the community hub')
def _process_GET(self): defaults = FormDefaults(**cephalopod_settings.get_all()) form = CephalopodForm(request.form, obj=defaults) enabled = cephalopod_settings.get('joined') config = Config.getInstance() instance_url = config.getBaseURL() language = config.getDefaultLocale() tracker_url = urljoin( config.getTrackerURL(), 'api/instance/{}'.format(cephalopod_settings.get('uuid'))) return WPCephalopod.render_template( 'cephalopod.html', affiliation=core_settings.get('site_organization'), enabled=enabled, form=form, indico_version=indico.__version__, instance_url=instance_url, language=language, operating_system=get_os(), postgres_version=get_postgres_version(), python_version=platform.python_version(), tracker_url=tracker_url)
def _process(self): form = CephalopodForm(obj=FormDefaults( **cephalopod_settings.get_all())) if form.validate_on_submit(): return self._process_form(form) config = Config.getInstance() hub_url = url_join( config.getCommunityHubURL(), 'api/instance/{}'.format(cephalopod_settings.get('uuid'))) cephalopod_settings.set('show_migration_message', False) return WPCephalopod.render_template( 'cephalopod.html', 'cephalopod', affiliation=core_settings.get('site_organization'), enabled=cephalopod_settings.get('joined'), form=form, indico_version=indico.__version__, instance_url=config.getBaseURL(), language=config.getDefaultLocale(), operating_system=get_os(), postgres_version=get_postgres_version(), python_version=platform.python_version(), hub_url=hub_url)
def _getHeadContent(self): site_name = core_settings.get('site_title') meta = render_template('events/meta.html', event=self.event, site_name=site_name) return WPDecorated._getHeadContent(self) + meta
def _getHeadContent(self): site_name = core_settings.get('site_title') meta = render_template('events/meta.html', event=self.event, site_name=site_name) return WPDecorated._getHeadContent(self) + meta
def _getHeadContent(self): site_name = core_settings.get('site_title') meta = render_template('events/meta.html', event=self.event, site_name=site_name, json_ld=serialize_event_for_json_ld(self.event, full=True)) return WPDecorated._getHeadContent(self) + meta