def __init__(self, *args, **kwargs): self.event = kwargs.pop('event') self.abstract = kwargs.pop('abstract', None) management = kwargs.pop('management', False) description_settings = abstracts_settings.get(self.event, 'description_settings') description_validators = self._get_description_validators(description_settings) if description_validators: inject_validators(self, 'description', description_validators) if abstracts_settings.get(self.event, 'contrib_type_required'): inject_validators(self, 'submitted_contrib_type', [DataRequired()]) super(AbstractForm, self).__init__(*args, **kwargs) if management: self.submitted_contrib_type.query = (self.event.contribution_types .order_by(db.func.lower(ContributionType.name))) else: criteria = [~ContributionType.is_private] if self.abstract and self.abstract.submitted_contrib_type: criteria.append(ContributionType.id == self.abstract.submitted_contrib_type.id) self.submitted_contrib_type.query = (self.event.contribution_types .filter(db.or_(*criteria)) .order_by(db.func.lower(ContributionType.name))) if not self.submitted_contrib_type.query.count(): del self.submitted_contrib_type if not self.event.cfa.allow_attachments: del self.attachments if not description_settings['is_active']: del self.description self.person_links.require_speaker_author = abstracts_settings.get(self.event, 'speakers_required') self.person_links.allow_speakers = abstracts_settings.get(self.event, 'allow_speakers')
def __init__(self, *args, **kwargs): self.event = kwargs.pop('event') self.abstract = kwargs.pop('abstract', None) management = kwargs.pop('management', False) description_settings = abstracts_settings.get(self.event, 'description_settings') description_validators = self._get_description_validators( description_settings) if description_validators: inject_validators(self, 'description', description_validators) if abstracts_settings.get(self.event, 'contrib_type_required'): inject_validators(self, 'submitted_contrib_type', [DataRequired()]) super(AbstractForm, self).__init__(*args, **kwargs) if management: self.submitted_contrib_type.query = self.event.contribution_types else: criteria = [~ContributionType.is_private] if self.abstract and self.abstract.submitted_contrib_type: criteria.append(ContributionType.id == self.abstract.submitted_contrib_type.id) self.submitted_contrib_type.query = self.event.contribution_types.filter( db.or_(*criteria)) if not self.submitted_contrib_type.query.count(): del self.submitted_contrib_type if not self.event.cfa.allow_attachments: del self.attachments if not description_settings['is_active']: del self.description self.person_links.require_speaker_author = abstracts_settings.get( self.event, 'speakers_required') self.person_links.allow_speakers = abstracts_settings.get( self.event, 'allow_speakers')
def __init__(self, *args, **kwargs): event = kwargs['event'] self.track_field_disabled = (kwargs.get('abstract') and kwargs['abstract'].edit_track_mode != EditTrackMode.both) if abstracts_settings.get(event, 'tracks_required') and not self.track_field_disabled: inject_validators(self, 'submitted_for_tracks', [DataRequired()]) super(SingleTrackMixin, self).__init__(*args, **kwargs) if not abstracts_settings.get(event, 'tracks_required'): self.submitted_for_tracks.blank_text = _('No track selected') self.submitted_for_tracks.query = Track.query.with_parent(event).order_by(Track.position)
def field_data(self): settings = abstracts_settings.get(self.event, 'description_settings') return { 'max_words': settings.get('max_words', 0), 'max_length': settings.get('max_length', 0), 'multiline': True }
def make_abstract_form(event, notification_option=False, management=False): """Extends the abstract WTForm to add the extra fields. Each extra field will use a field named ``custom_ID``. :param event: The `Event` for which to create the abstract form. :param notification_option: Whether to add a field to the form to disable triggering notifications for the abstract submission. :param management Whether it's a manager using the abstract form :return: An `AbstractForm` subclass. """ from indico.modules.events.abstracts.forms import (AbstractForm, MultiTrackMixin, SingleTrackMixin, NoTrackMixin, SendNotificationsMixin) mixins = [] if not event.tracks: mixins.append(NoTrackMixin) elif abstracts_settings.get(event, 'allow_multiple_tracks'): mixins.append(MultiTrackMixin) else: mixins.append(SingleTrackMixin) if notification_option: mixins.append(SendNotificationsMixin) form_class = type(b'_AbstractForm', tuple(mixins) + (AbstractForm,), {}) for custom_field in event.contribution_fields: field_impl = custom_field.mgmt_field if management else custom_field.field if field_impl is None: # field definition is not available anymore continue name = 'custom_{}'.format(custom_field.id) setattr(form_class, name, field_impl.create_wtf_field()) return form_class
def _process(self): description_settings = abstracts_settings.get(self.event, 'description_settings') form = AbstractContentSettingsForm(obj=FormDefaults(description_settings)) if form.validate_on_submit(): abstracts_settings.set(self.event, 'description_settings', form.data) return jsonify_data(flash=False) return jsonify_form(form)
def __init__(self, *args, **kwargs): self.event = kwargs.pop('event') self.abstract = kwargs.pop('abstract', None) description_settings = abstracts_settings.get(self.event, 'description_settings') description_validators = self._get_description_validators(description_settings) if description_validators: inject_validators(self, 'description', description_validators) if abstracts_settings.get(self.event, 'contrib_type_required'): inject_validators(self, 'submitted_contrib_type', [DataRequired()]) super(AbstractForm, self).__init__(*args, **kwargs) self.submitted_contrib_type.query = self.event.contribution_types if not self.submitted_contrib_type.query.count(): del self.submitted_contrib_type if not self.event.cfa.allow_attachments: del self.attachments if not description_settings['is_active']: del self.description self.person_links.require_speaker_author = abstracts_settings.get(self.event, 'speakers_required') self.person_links.allow_speakers = abstracts_settings.get(self.event, 'allow_speakers')
def __init__(self, *args, **kwargs): self.event = kwargs.pop('event') self.abstract = kwargs.pop('abstract', None) is_invited = kwargs.pop('invited', False) management = kwargs.pop('management', False) description_settings = abstracts_settings.get(self.event, 'description_settings') description_validators = self._get_description_validators( description_settings, invited=is_invited) if description_validators: inject_validators(self, 'description', description_validators) if not is_invited: inject_validators(self, 'person_links', [DataRequired()]) if abstracts_settings.get(self.event, 'contrib_type_required'): inject_validators(self, 'submitted_contrib_type', [DataRequired()]) super().__init__(*args, **kwargs) if management: self.submitted_contrib_type.query = ( self.event.contribution_types.order_by( db.func.lower(ContributionType.name))) else: criteria = [~ContributionType.is_private] if self.abstract and self.abstract.submitted_contrib_type: criteria.append(ContributionType.id == self.abstract.submitted_contrib_type.id) self.submitted_contrib_type.query = ( self.event.contribution_types.filter(db.or_( *criteria)).order_by(db.func.lower(ContributionType.name))) if not self.submitted_contrib_type.query.count(): del self.submitted_contrib_type if not self.event.cfa.allow_attachments: del self.attachments if not description_settings['is_active']: del self.description if not is_invited: self.person_links.require_speaker_author = abstracts_settings.get( self.event, 'speakers_required') self.person_links.allow_speakers = abstracts_settings.get( self.event, 'allow_speakers') self.person_links.disable_user_search = session.user is None else: self.person_links.require_primary_author = False
def create_contribution_from_abstract(abstract, contrib_session=None): from indico.modules.events.abstracts.settings import abstracts_settings event = abstract.event contrib_person_links = set() author_submission_rights = ( event.cfa.contribution_submitters == SubmissionRightsType.all) person_link_attrs = { '_title', 'address', 'affiliation', 'first_name', 'last_name', 'phone', 'author_type', 'is_speaker', 'display_order' } for abstract_person_link in abstract.person_links: link = ContributionPersonLink(person=abstract_person_link.person) link.populate_from_attrs(abstract_person_link, person_link_attrs) contrib_person_links.add(link) if contrib_session: duration = contrib_session.default_contribution_duration else: duration = contribution_settings.get(event, 'default_duration') custom_fields_data = { f'custom_{field_value.contribution_field.id}': field_value.data for field_value in abstract.field_values } contrib = create_contribution(event, { 'friendly_id': abstract.friendly_id, 'title': abstract.title, 'duration': duration, 'description': abstract.description, 'type': abstract.accepted_contrib_type, 'track': abstract.accepted_track, 'session': contrib_session, 'person_link_data': { link: (author_submission_rights or link.is_speaker) for link in contrib_person_links } }, custom_fields_data=custom_fields_data) if abstracts_settings.get(event, 'copy_attachments') and abstract.files: folder = AttachmentFolder.get_or_create_default(contrib) for abstract_file in abstract.files: attachment = Attachment(user=abstract.submitter, type=AttachmentType.file, folder=folder, title=abstract_file.filename) attachment.file = AttachmentFile( user=abstract.submitter, filename=abstract_file.filename, content_type=abstract_file.content_type) with abstract_file.open() as fd: attachment.file.save(fd) db.session.flush() return contrib
def __init__(self, *args, **kwargs): self.event = kwargs.pop('event') self.abstract = kwargs.pop('abstract', None) description_settings = abstracts_settings.get(self.event, 'description_settings') description_validators = self._get_description_validators( description_settings) if description_validators: inject_validators(self, 'description', description_validators) if abstracts_settings.get(self.event, 'contrib_type_required'): inject_validators(self, 'submitted_contrib_type', [DataRequired()]) super(AbstractForm, self).__init__(*args, **kwargs) self.submitted_contrib_type.query = self.event.contribution_types if not self.submitted_contrib_type.query.count(): del self.submitted_contrib_type if not self.event.cfa.allow_attachments: del self.attachments if not description_settings['is_active']: del self.description self.person_links.require_speaker_author = abstracts_settings.get( self.event, 'speakers_required') self.person_links.allow_speakers = abstracts_settings.get( self.event, 'allow_speakers')
def make_abstract_form(event, user, notification_option=False, management=False, invited=False): """Extend the abstract WTForm to add the extra fields. Each extra field will use a field named ``custom_ID``. :param event: The `Event` for which to create the abstract form. :param user: The user who is going to use the form. :param notification_option: Whether to add a field to the form to disable triggering notifications for the abstract submission. :param management: Whether the form is used in the management area :param invited: Whether the form is used to create an invited abstract :return: An `AbstractForm` subclass. """ from indico.modules.events.abstracts.forms import (AbstractForm, MultiTrackMixin, NoTrackMixin, SendNotificationsMixin, SingleTrackMixin) mixins = [] if not event.tracks: mixins.append(NoTrackMixin) elif abstracts_settings.get(event, 'allow_multiple_tracks'): mixins.append(MultiTrackMixin) else: mixins.append(SingleTrackMixin) if notification_option: mixins.append(SendNotificationsMixin) if invited: mixins.append(InvitedAbstractMixin) form_class = type('_AbstractForm', tuple(mixins) + (AbstractForm, ), {}) for custom_field in event.contribution_fields: field_impl = custom_field.mgmt_field if management else custom_field.field if field_impl is None: # field definition is not available anymore continue if custom_field.is_active and (custom_field.is_user_editable or event.can_manage( user, permission='abstracts')): name = f'custom_{custom_field.id}' setattr(form_class, name, field_impl.create_wtf_field()) return form_class
def create_contribution_from_abstract(abstract, contrib_session=None): from indico.modules.events.abstracts.settings import abstracts_settings event = abstract.event contrib_person_links = set() person_link_attrs = {'_title', 'address', 'affiliation', 'first_name', 'last_name', 'phone', 'author_type', 'is_speaker', 'display_order'} for abstract_person_link in abstract.person_links: link = ContributionPersonLink(person=abstract_person_link.person) link.populate_from_attrs(abstract_person_link, person_link_attrs) contrib_person_links.add(link) if contrib_session: duration = contrib_session.default_contribution_duration else: duration = contribution_settings.get(event, 'default_duration') custom_fields_data = {'custom_{}'.format(field_value.contribution_field.id): field_value.data for field_value in abstract.field_values} contrib = create_contribution(event, {'friendly_id': abstract.friendly_id, 'title': abstract.title, 'duration': duration, 'description': abstract.description, 'type': abstract.accepted_contrib_type, 'track': abstract.accepted_track, 'session': contrib_session, 'person_link_data': {link: True for link in contrib_person_links}}, custom_fields_data=custom_fields_data) if abstracts_settings.get(event, 'copy_attachments') and abstract.files: folder = AttachmentFolder.get_or_create_default(contrib) for abstract_file in abstract.files: attachment = Attachment(user=abstract.submitter, type=AttachmentType.file, folder=folder, title=abstract_file.filename) attachment.file = AttachmentFile(user=abstract.submitter, filename=abstract_file.filename, content_type=abstract_file.content_type) with abstract_file.open() as fd: attachment.file.save(fd) db.session.flush() return contrib
def announcement(self): announcement = abstracts_settings.get(self.event, 'announcement') render_mode = abstracts_settings.get(self.event, 'announcement_render_mode') return RENDER_MODE_WRAPPER_MAP[render_mode](announcement)
def is_required(self): return abstracts_settings.get(self.event, 'description_settings')['is_required']
def is_active(self): return abstracts_settings.get(self.event, 'description_settings')['is_active']
def announcement(self): announcement = abstracts_settings.get(self.event, "announcement") render_mode = abstracts_settings.get(self.event, "announcement_render_mode") return RENDER_MODE_WRAPPER_MAP[render_mode](announcement)