def _process_POST(self): if User.query.has_rows(): return redirect(url_for_index()) setup_form = BootstrapForm(request.form) if not setup_form.validate(): flash(_("Some fields are invalid. Please, correct them and submit the form again."), 'error') return redirect(url_for('bootstrap.index')) # Creating new user user = User() user.first_name = to_unicode(setup_form.first_name.data) user.last_name = to_unicode(setup_form.last_name.data) user.affiliation = to_unicode(setup_form.affiliation.data) user.email = to_unicode(setup_form.email.data) user.is_admin = True identity = Identity(provider='indico', identifier=setup_form.username.data, password=setup_form.password.data) user.identities.add(identity) db.session.add(user) db.session.flush() user.settings.set('timezone', Config.getInstance().getDefaultTimezone()) user.settings.set('lang', session.lang or Config.getInstance().getDefaultLocale()) login_user(user, identity) full_name = user.full_name # needed after the session closes transaction.commit() # Configuring server's settings minfo = HelperMaKaCInfo.getMaKaCInfoInstance() minfo.setOrganisation(setup_form.affiliation.data) message = get_template_module('bootstrap/flash_messages.html').bootstrap_success(name=full_name) flash(Markup(message), 'success') # Activate instance tracking if setup_form.enable_tracking.data: contact_name = setup_form.contact_name.data contact_email = setup_form.contact_email.data try: register_instance(contact_name, contact_email) except (HTTPError, ValueError) as err: message = get_template_module('bootstrap/flash_messages.html').community_error(err=err) category = 'error' except Timeout: message = get_template_module('bootstrap/flash_messages.html').community_timeout() category = 'error' except RequestException as exc: message = get_template_module('bootstrap/flash_messages.html').community_exception(exc=exc) category = 'error' else: message = get_template_module('bootstrap/flash_messages.html').community_success() category = 'success' flash(Markup(message), category) return redirect(url_for_index())
def _process(self): if not request.is_xhr: return redirect( url_for_index( _anchor='create-event:{}'.format(self.event_type.name))) form_cls = LectureCreationForm if self.event_type == EventType.lecture else EventCreationForm form = form_cls(obj=self._get_form_defaults(), prefix='event-creation-') if form.validate_on_submit(): if self.event_type == EventType.lecture: events = self._create_series(form.data) event = events[0] if len(events) > 1: flash( Markup( render_template('events/series_created_msg.html', events=events)), 'info') notify_event_creation(event, occurrences=events) else: event = self._create_event(form.data) notify_event_creation(event) return jsonify_data(flash=False, redirect=url_for('event_management.settings', event)) return jsonify_template('events/forms/event_creation_form.html', form=form, fields=form._field_order, event_type=self.event_type.name, single_category=self.single_category)
def render_breadcrumbs(*titles, **kwargs): """Render the breadcrumb navigation :param titles: A list of plain text titles. If present, these will simply create a unlinked trail of breadcrumbs. A 'Home' element is inserted automatically. :param event: Generate the event/category breadcrumb trail starting at the specified event. :param category: Generate the category breadcrumb trail starting at the specified category. :param management: Whether the event/category breadcrumb trail should link to management pages. """ category = kwargs.get('category', None) event = kwargs.get('event', None) management = kwargs.get('management', False) assert bool(titles) + bool(event) + bool(category) == 1 if not category and not event: items = [(_('Home'), url_for_index())] items += [(x, None) if isinstance(x, basestring) else x for x in titles] else: items = [] if event: items.append((event.title, url_for('event_management.settings', event) if management else event.url)) category = event.category for cat in category.chain_query[::-1]: items.append((cat.title, url_for('categories.manage_content', cat) if management else cat.url)) items.reverse() return render_template('breadcrumbs.html', items=items, management=management)
def _handle_submit(self, setup_form): # Creating new user user = User() user.first_name = setup_form.first_name.data user.last_name = setup_form.last_name.data user.affiliation = setup_form.affiliation.data user.email = setup_form.email.data user.is_admin = True identity = Identity(provider='indico', identifier=setup_form.username.data, password=setup_form.password.data) user.identities.add(identity) db.session.add(user) db.session.flush() user.settings.set('timezone', config.DEFAULT_TIMEZONE) user.settings.set('lang', session.lang or config.DEFAULT_LOCALE) login_user(user, identity) full_name = user.full_name # needed after the session closes db.session.commit() # Configuring server's settings core_settings.set('site_organization', setup_form.affiliation.data) message = get_template_module( 'bootstrap/flash_messages.html').bootstrap_success(name=full_name) flash(Markup(message), 'success') # Activate instance tracking if setup_form.enable_tracking.data: contact_name = setup_form.contact_name.data contact_email = setup_form.contact_email.data try: register_instance(contact_name, contact_email) except (HTTPError, ValueError) as err: message = get_template_module('bootstrap/flash_messages.html' ).community_error(err=str(err)) category = 'error' except Timeout: message = get_template_module( 'bootstrap/flash_messages.html').community_timeout() category = 'error' except RequestException as exc: message = get_template_module( 'bootstrap/flash_messages.html').community_exception( err=str(exc)) category = 'error' else: message = get_template_module( 'bootstrap/flash_messages.html').community_success() category = 'success' flash(Markup(message), category) return redirect(url_for_index())
def _process_GET(self): if User.query.has_rows(): return redirect(url_for_index()) return render_template('bootstrap/bootstrap.html', form=BootstrapForm(), timezone=Config.getInstance().getDefaultTimezone(), indico_version=MaKaC.__version__, python_version=python_version())
def _process_GET(self): if User.query.filter_by(is_system=False).has_rows(): return redirect(url_for_index()) return render_template('bootstrap/bootstrap.html', form=BootstrapForm(), timezone=Config.getInstance().getDefaultTimezone(), languages=get_all_locales(), indico_version=indico.__version__, python_version=python_version())
def _process_GET(self): if User.query.filter_by(is_system=False).has_rows(): return redirect(url_for_index()) return render_template('bootstrap/bootstrap.html', form=BootstrapForm(), timezone=config.DEFAULT_TIMEZONE, languages=get_all_locales(), operating_system=get_os(), postgres_version=get_postgres_version(), indico_version=indico.__version__, python_version=python_version())
def _process_POST(self): self.event.delete('Deleted by user', session.user) flash(_('Event "{}" successfully deleted.').format(self.event.title), 'success') category = self.event.category if category.can_manage(session.user): redirect_url = url_for('categories.manage_content', category) elif category.can_access(session.user): redirect_url = url_for('categories.display', category) else: redirect_url = url_for_index() return jsonify_data(flash=False, redirect=redirect_url)
def _process(self): if session.user: return redirect(url_for_index()) handler = MultipassRegistrationHandler( self) if self.identity_info else LocalRegistrationHandler(self) verified_email, prevalidated = self._get_verified_email() if verified_email is not None: handler.email_verified(verified_email) if prevalidated: flash( _("You may change your email address after finishing the registration process." ), 'info') else: flash( _('You have successfully validated your email address and can now proceeed with the ' 'registration.'), 'success') return redirect(url_for('.register', provider=self.provider_name)) form = handler.create_form() if not handler.moderate_registrations and not handler.must_verify_email: del form.comment # Check for pending users if we have verified emails pending = None if not handler.must_verify_email: pending = User.find_first( ~User.is_deleted, User.is_pending, User.all_emails.contains( db.func.any(list(handler.get_all_emails(form))))) if form.validate_on_submit(): if handler.must_verify_email: return self._send_confirmation(form.email.data) elif handler.moderate_registrations: return self._create_registration_request(form, handler) else: return self._create_user(form, handler) elif not form.is_submitted() and pending: # If we have a pending user, populate empty fields with data from that user for field in form: value = getattr(pending, field.short_name, '') if value and not field.data: field.data = value if pending: flash( _("There is already some information in Indico that concerns you. " "We are going to link it automatically."), 'info') return WPAuth.render_template( 'register.html', form=form, local=(not self.identity_info), must_verify_email=handler.must_verify_email, widget_attrs=handler.widget_attrs, email_sent=session.pop('register_verification_email_sent', False), moderate_accounts=handler.moderate_registrations)
def _process(self, title, start_dt, tz, duration, event_type): event_key = str(uuid4()) start_dt = timezone(tz).localize(start_dt) prepared_event_data_store.set( event_key, { 'title': title, 'start_dt': start_dt, 'duration': duration, 'event_type': event_type, }, 3600) return jsonify(url=url_for_index( _external=True, _anchor=f'create-event:meeting::{event_key}'))
def _topmenu_items(sender, **kwargs): yield TopMenuItem('home', _('Home'), url_for_index(), 100) yield TopMenuItem('help', _('Indico help'), None, 30, section='help') if Config.getInstance().getPublicSupportEmail(): yield TopMenuItem('contact', _('Contact'), url_for('misc.contact'), 20, section='help') yield TopMenuItem('about', _('More about Indico'), 'http://indico-software.org', 10, section='help')
def _process(self): if self.category.is_root: raise BadRequest('The root category cannot be deleted') if not self.category.is_empty: raise BadRequest('Cannot delete a non-empty category') delete_category(self.category) parent = self.category.parent if parent.can_manage(session.user): url = url_for('.manage_content', parent) elif parent.can_access(session.user): url = url_for('.display', parent) else: url = url_for_index() if request.is_xhr: return jsonify_data(flash=False, redirect=url, is_parent_empty=parent.is_empty) else: flash(_('Category "{}" has been deleted.').format(self.category.title), 'success') return redirect(url)
def _process(self): if 'activeTimezone' not in request.values or request.values[ 'activeTimezone'] == 'My': tz = Config.getInstance().getDefaultTimezone() if session.user: tz = session.user.settings.get('timezone', tz) else: tz = request.values['activeTimezone'] if request.values.get('saveToProfile') == 'on' and session.user: if tz == 'LOCAL': session.user.settings.set('force_timezone', False) else: session.user.settings.set('force_timezone', True) session.user.settings.set('timezone', to_unicode(tz)) session.timezone = tz return redirect(request.referrer or url_for_index())
def _process(self): if not request.is_xhr: return redirect( url_for_index(_anchor=f'create-event:{self.event_type.name}')) form_cls = LectureCreationForm if self.event_type == EventType.lecture else EventCreationForm form = form_cls(obj=self._get_form_defaults(), prefix='event-creation-') if form.validate_on_submit(): data = form.data listing = data.pop('listing') if not listing and can_create_unlisted_events(session.user): del data['category'] if self.event_type == EventType.lecture: events = self._create_series(data) event = events[0] if len(events) > 1: flash( Markup( render_template('events/series_created_msg.html', events=events)), 'info') notify_event_creation(event, occurrences=events) else: event = self._create_event(data) notify_event_creation(event) return jsonify_data(flash=False, redirect=url_for('event_management.settings', event)) check_room_availability = rb_check_user_access( session.user) and config.ENABLE_ROOMBOOKING rb_excluded_categories = [ c.id for c in rb_settings.get('excluded_categories') ] return jsonify_template( 'events/forms/event_creation_form.html', form=form, fields=form._field_order, event_type=self.event_type.name, single_category=(not self.root_category.has_children), check_room_availability=check_room_availability, rb_excluded_categories=rb_excluded_categories, can_create_unlisted_events=can_create_unlisted_events( session.user))
def _process(self): if User.query.filter_by(is_system=False).has_rows(): return redirect(url_for_index()) form = BootstrapForm() if form.validate_on_submit(): return self._handle_submit(form) return render_template( 'bootstrap/bootstrap.html', form=form, timezone=config.DEFAULT_TIMEZONE, languages=get_all_locales(), operating_system=get_os(), postgres_version=get_postgres_version(), indico_version=indico.__version__, python_version=python_version(), show_local_warning=(config.DEBUG or is_private_url(request.url_root)))
def render_breadcrumbs(*titles, category=None, event=None, management=False, category_url_factory=None): """Render the breadcrumb navigation. :param titles: A list of plain text titles. If present, these will simply create a unlinked trail of breadcrumbs. A 'Home' element is inserted automatically. :param event: Generate the event/category breadcrumb trail starting at the specified event. :param category: Generate the category breadcrumb trail starting at the specified category. :param category_url_factory: Function to get the URL for a category breadcrumb. If missing, the standard category url will be used. :param management: Whether the event/category breadcrumb trail should link to management pages. """ assert titles or event or category if not category and not event: items = [(_('Home'), url_for_index())] else: items = [] if event: items.append( (event.title, url_for('event_management.settings', event) if management else event.url)) category = event.category if category_url_factory is None: category_url_factory = lambda cat, management: ( url_for('categories.manage_content', cat) if management and cat.can_manage(session.user) else cat.url) for cat in category.chain_query[::-1]: items.append( (cat.title, category_url_factory(cat, management=management))) items.reverse() items += [(x, None) if isinstance(x, str) else x for x in titles] return render_template('breadcrumbs.html', items=items, management=management)
def _process(self): return multipass.logout(request.args.get('next') or url_for_index(), clear_session=True)
def _topmenu_items(sender, **kwargs): yield TopMenuItem('home', _('Home'), url_for_index(), 100)
def _process(self): next_url = request.args.get('next') if not next_url or not multipass.validate_next_url(next_url): next_url = url_for_index() return multipass.logout(next_url, clear_session=True)
def redirect_success(self): return redirect(session.pop('register_next_url', url_for_index()))
def _topmenu_items(sender, **kwargs): yield TopMenuItem('home', _('Home'), url_for_index(), 100) yield TopMenuItem('help', _('Indico help'), None, 30, section='help') if config.PUBLIC_SUPPORT_EMAIL: yield TopMenuItem('contact', _('Contact'), url_for('misc.contact'), 20, section='help') yield TopMenuItem('about', _('More about Indico'), 'https://getindico.io', 10, section='help')