示例#1
0
 def _process(self):
     defaults = self._get_form_defaults(location_parent=self.session_block)
     form = ContributionEntryForm(obj=defaults,
                                  to_schedule=True,
                                  **self._get_form_params())
     if form.validate_on_submit():
         contrib = Contribution()
         with track_time_changes(auto_extend=True,
                                 user=session.user) as changes:
             with flash_if_unregistered(self.event_new,
                                        lambda: contrib.person_links):
                 contrib = create_contribution(
                     self.event_new,
                     form.data,
                     session_block=self.session_block,
                     extend_parent=True)
         entry = contrib.timetable_entry
         notifications = get_time_changes_notifications(
             changes, tzinfo=self.event_new.tzinfo, entry=entry)
         return jsonify_data(
             entries=[serialize_entry_update(entry, session_=self.session)],
             notifications=notifications)
     self.commit = False
     return jsonify_template('events/contributions/forms/contribution.html',
                             form=form,
                             fields=form._display_fields)
示例#2
0
 def _process(self):
     inherited_location = self.event.location_data
     inherited_location['inheriting'] = True
     default_duration = contribution_settings.get(self.event,
                                                  'default_duration')
     contrib_form_class = make_contribution_form(self.event)
     form = contrib_form_class(obj=FormDefaults(
         location_data=inherited_location, duration=default_duration),
                               event=self.event)
     if form.validate_on_submit():
         # Create empty contribution so it can be compared to the new one in flash_if_unregistered
         contrib = Contribution()
         with flash_if_unregistered(self.event,
                                    lambda: contrib.person_links):
             contrib = create_contribution(self.event,
                                           *get_field_values(form.data))
         flash(
             _("Contribution '{}' created successfully").format(
                 contrib.title), 'success')
         tpl_components = self.list_generator.render_list(contrib)
         if tpl_components['hide_contrib']:
             self.list_generator.flash_info_message(contrib)
         return jsonify_data(**tpl_components)
     return jsonify_template('events/contributions/forms/contribution.html',
                             form=form)
示例#3
0
文件: legacy.py 项目: stomanin/indico
def contribution_from_abstract(abstract, sess):
    from MaKaC.review import AbstractStatusAccepted

    event = abstract.as_new.event_new
    duration = sess.default_contribution_duration if sess else timedelta(
        minutes=15)
    links = []

    for auth in abstract.getAuthorList():
        author_type = AuthorType.primary if abstract.isPrimaryAuthor(
            auth) else AuthorType.secondary
        person_data = {
            'title': UserTitle.from_legacy(to_unicode(auth.getTitle())),
            'email': to_unicode(auth.getEmail()),
            'address': to_unicode(auth.getAddress()),
            'affiliation': to_unicode(auth.getAffiliation()),
            'first_name': to_unicode(auth.getFirstName()),
            'last_name': to_unicode(auth.getSurName()),
            'phone': to_unicode(auth.getTelephone())
        }

        person = person_from_data(person_data, event)
        person_data.pop('email')
        links.append(
            ContributionPersonLink(author_type=author_type,
                                   person=person,
                                   is_speaker=abstract.isSpeaker(auth),
                                   **person_data))

    custom_fields_data = {
        'custom_{}'.format(field_val.contribution_field.id): field_val.data
        for field_val in abstract.as_new.field_values
    }
    contrib = create_contribution(event, {
        'friendly_id': abstract.as_new.friendly_id,
        'title': to_unicode(abstract.getTitle()),
        'duration': duration,
        'person_link_data': {link: True
                             for link in links}
    },
                                  custom_fields_data=custom_fields_data)
    contrib.abstract = abstract.as_new
    contrib.description = abstract.as_new.description

    # if this is an accepted abstract, set track and type if present
    status = abstract.getCurrentStatus()
    if isinstance(status, AbstractStatusAccepted):
        track = abstract.as_new.accepted_track
        contrib_type = abstract.as_new.accepted_type
        if track:
            contrib.track_id = int(track.getId())
        if contrib_type:
            contrib.type = contrib_type

    if sess:
        contrib.session = sess

    return contrib
示例#4
0
 def _process(self):
     defaults = self._get_form_defaults(location_parent=self.session_block)
     form = ContributionEntryForm(obj=defaults, to_schedule=True, **self._get_form_params())
     if form.validate_on_submit():
         with track_time_changes(auto_extend=True, user=session.user) as changes:
             contrib = create_contribution(self.event_new, form.data, session_block=self.session_block,
                                           extend_parent=True)
         entry = contrib.timetable_entry
         notifications = get_time_changes_notifications(changes, tzinfo=self.event_new.tzinfo, entry=entry)
         return jsonify_data(entries=[serialize_entry_update(entry)], notifications=notifications, flash=False)
     self.commit = False
     return jsonify_template('events/contributions/forms/contribution.html', form=form, fields=form._display_fields)
示例#5
0
文件: management.py 项目: fph/indico
 def _process(self):
     inherited_location = self.event_new.location_data
     inherited_location['inheriting'] = True
     contrib_form_class = make_contribution_form(self.event_new)
     form = contrib_form_class(obj=FormDefaults(location_data=inherited_location), event=self.event_new)
     if form.validate_on_submit():
         contrib = create_contribution(self.event_new, *_get_field_values(form.data))
         flash(_("Contribution '{}' created successfully").format(contrib.title), 'success')
         tpl_components = self.reporter.render_contrib_report(contrib)
         if tpl_components['hide_contrib']:
             self.reporter.flash_info_message(contrib)
         return jsonify_data(**tpl_components)
     return jsonify_template('events/contributions/forms/contribution.html', form=form)
示例#6
0
 def _process(self):
     inherited_location = self.event_new.location_data
     inherited_location['inheriting'] = True
     contrib_form_class = make_contribution_form(self.event_new)
     form = contrib_form_class(obj=FormDefaults(location_data=inherited_location), event=self.event_new)
     if form.validate_on_submit():
         # Create empty contribution so it can be compared to the new one in flash_if_unregistered
         contrib = Contribution()
         with flash_if_unregistered(self.event_new, lambda: contrib.person_links):
             contrib = create_contribution(self.event_new, *get_field_values(form.data))
         flash(_("Contribution '{}' created successfully").format(contrib.title), 'success')
         tpl_components = self.list_generator.render_list(contrib)
         if tpl_components['hide_contrib']:
             self.list_generator.flash_info_message(contrib)
         return jsonify_data(**tpl_components)
     return jsonify_template('events/contributions/forms/contribution.html', form=form)
示例#7
0
def contribution_from_abstract(abstract, sess):
    from MaKaC.review import AbstractStatusAccepted

    event = abstract.as_new.event_new
    duration = sess.default_contribution_duration if sess else timedelta(minutes=15)
    links = []

    for auth in abstract.getAuthorList():
        author_type = AuthorType.primary if abstract.isPrimaryAuthor(auth) else AuthorType.secondary
        person_data = {
            'title': UserTitle.from_legacy(to_unicode(auth.getTitle())),
            'email': to_unicode(auth.getEmail()),
            'address': to_unicode(auth.getAddress()),
            'affiliation': to_unicode(auth.getAffiliation()),
            'first_name': to_unicode(auth.getFirstName()),
            'last_name': to_unicode(auth.getSurName()),
            'phone': to_unicode(auth.getTelephone())
        }

        person = person_from_data(person_data, event)
        person_data.pop('email')
        links.append(ContributionPersonLink(author_type=author_type, person=person,
                                            is_speaker=abstract.isSpeaker(auth), **person_data))

    custom_fields_data = {'custom_{}'.format(field_val.contribution_field.id): field_val.data for
                          field_val in abstract.as_new.field_values}
    contrib = create_contribution(event, {'friendly_id': abstract.as_new.friendly_id,
                                          'title': to_unicode(abstract.getTitle()), 'duration': duration,
                                          'person_link_data': {link: True for link in links}},
                                  custom_fields_data=custom_fields_data)
    contrib.abstract = abstract.as_new
    contrib.description = abstract.as_new.description

    # if this is an accepted abstract, set track and type if present
    status = abstract.getCurrentStatus()
    if isinstance(status, AbstractStatusAccepted):
        track = abstract.as_new.accepted_track
        contrib_type = abstract.as_new.accepted_type
        if track:
            contrib.track_id = int(track.getId())
        if contrib_type:
            contrib.type = contrib_type

    if sess:
        contrib.session = sess

    return contrib
示例#8
0
 def _process(self):
     inherited_location = self.event_new.location_data
     inherited_location['inheriting'] = True
     contrib_form_class = make_contribution_form(self.event_new)
     form = contrib_form_class(
         obj=FormDefaults(location_data=inherited_location),
         event=self.event_new)
     if form.validate_on_submit():
         contrib = create_contribution(self.event_new,
                                       *_get_field_values(form.data))
         flash(
             _("Contribution '{}' created successfully").format(
                 contrib.title), 'success')
         tpl_components = self.reporter.render_contrib_report(contrib)
         if tpl_components['hide_contrib']:
             self.reporter.flash_info_message(contrib)
         return jsonify_data(**tpl_components)
     return jsonify_template('events/contributions/forms/contribution.html',
                             form=form)
示例#9
0
def import_contributions_from_csv(event, f):
    """Import timetable contributions from a CSV file into an event."""
    with csv_text_io_wrapper(f) as ftxt:
        reader = csv.reader(ftxt.read().splitlines())

    contrib_data = []
    for num_row, row in enumerate(reader, 1):
        try:
            start_dt, duration, title, first_name, last_name, affiliation, email = (
                value.strip() for value in row)
            email = email.lower()
        except ValueError:
            raise UserValueError(
                _('Row {}: malformed CSV data - please check that the number of columns is correct'
                  ).format(num_row))
        try:
            parsed_start_dt = event.tzinfo.localize(
                dateutil.parser.parse(start_dt)) if start_dt else None
        except ValueError:
            raise UserValueError(
                _('Row {row}: can\'t parse date: "{date}"').format(
                    row=num_row, date=start_dt))

        try:
            parsed_duration = timedelta(
                minutes=int(duration)) if duration else None
        except ValueError:
            raise UserValueError(
                _("Row {row}: can't parse duration: {duration}").format(
                    row=num_row, duration=duration))

        if not title:
            raise UserValueError(
                _('Row {}: contribution title is required').format(num_row))

        if email and not validate_email(email):
            raise UserValueError(
                _('Row {row}: invalid email address: {email}').format(
                    row=num_row, email=email))

        contrib_data.append({
            'start_dt':
            parsed_start_dt,
            'duration':
            parsed_duration or timedelta(minutes=20),
            'title':
            title,
            'speaker': {
                'first_name': first_name,
                'last_name': last_name,
                'affiliation': affiliation,
                'email': email
            }
        })

    # now that we're sure the data is OK, let's pre-allocate the friendly ids
    # for the contributions in question
    Contribution.allocate_friendly_ids(event, len(contrib_data))
    contributions = []
    all_changes = defaultdict(list)

    for contrib_fields in contrib_data:
        speaker_data = contrib_fields.pop('speaker')

        with track_time_changes() as changes:
            contribution = create_contribution(event,
                                               contrib_fields,
                                               extend_parent=True)

        contributions.append(contribution)
        for key, val in changes[event].items():
            all_changes[key].append(val)

        email = speaker_data['email']
        if not email:
            continue

        # set the information of the speaker
        person = get_event_person(event, speaker_data)
        link = ContributionPersonLink(person=person, is_speaker=True)
        link.populate_from_dict({
            'first_name': speaker_data['first_name'],
            'last_name': speaker_data['last_name'],
            'affiliation': speaker_data['affiliation']
        })
        contribution.person_links.append(link)

    return contributions, all_changes
示例#10
0
文件: util.py 项目: indico/indico
def import_contributions_from_csv(event, f):
    """Import timetable contributions from a CSV file into an event."""
    reader = csv.reader(f.read().splitlines())
    contrib_data = []

    for num_row, row in enumerate(reader, 1):
        try:
            start_dt, duration, title, first_name, last_name, affiliation, email = \
                [to_unicode(value).strip() for value in row]
            email = email.lower()
        except ValueError:
            raise UserValueError(_('Row {}: malformed CSV data - please check that the number of columns is correct')
                                 .format(num_row))
        try:
            parsed_start_dt = event.tzinfo.localize(dateutil.parser.parse(start_dt)) if start_dt else None
        except ValueError:
            raise UserValueError(_("Row {row}: can't parse date: \"{date}\"").format(row=num_row, date=start_dt))

        try:
            parsed_duration = timedelta(minutes=int(duration)) if duration else None
        except ValueError:
            raise UserValueError(_("Row {row}: can't parse duration: {duration}").format(row=num_row,
                                                                                         duration=duration))

        if not title:
            raise UserValueError(_("Row {}: contribution title is required").format(num_row))

        if email and not validate_email(email):
            raise UserValueError(_("Row {row}: invalid email address: {email}").format(row=num_row, email=email))

        contrib_data.append({
            'start_dt': parsed_start_dt,
            'duration': parsed_duration or timedelta(minutes=20),
            'title': title,
            'speaker': {
                'first_name': first_name,
                'last_name': last_name,
                'affiliation': affiliation,
                'email': email
            }
        })

    # now that we're sure the data is OK, let's pre-allocate the friendly ids
    # for the contributions in question
    Contribution.allocate_friendly_ids(event, len(contrib_data))
    contributions = []
    all_changes = defaultdict(list)

    for contrib_fields in contrib_data:
        speaker_data = contrib_fields.pop('speaker')

        with track_time_changes() as changes:
            contribution = create_contribution(event, contrib_fields, extend_parent=True)

        contributions.append(contribution)
        for key, val in changes[event].viewitems():
            all_changes[key].append(val)

        email = speaker_data['email']
        if not email:
            continue

        # set the information of the speaker
        person = get_event_person(event, {
            'firstName': speaker_data['first_name'],
            'familyName': speaker_data['last_name'],
            'affiliation': speaker_data['affiliation'],
            'email': email
        })
        link = ContributionPersonLink(person=person, is_speaker=True)
        link.populate_from_dict({
            'first_name': speaker_data['first_name'],
            'last_name': speaker_data['last_name'],
            'affiliation': speaker_data['affiliation']
        })
        contribution.person_links.append(link)

    return contributions, all_changes
示例#11
0
文件: util.py 项目: www3838438/indico
def import_contributions_from_csv(event, f):
    """Import timetable contributions from a CSV file into an event."""
    reader = csv.reader(f)
    contributions = []
    all_changes = defaultdict(list)
    for num_row, row in enumerate(reader, 1):
        try:
            start_dt, duration, title, first_name, last_name, affiliation, email = row
        except ValueError:
            raise UserValueError(
                _('Row {}: malformed CSV data - please check that the number of columns is correct'
                  ).format(num_row))
        try:
            parsed_start_dt = event.tzinfo.localize(
                dateutil.parser.parse(start_dt)) if start_dt else None
        except ValueError:
            raise UserValueError(
                _("Row {}: can't parse date: \"{}\"").format(
                    num_row, start_dt))

        try:
            parsed_duration = timedelta(
                minutes=int(duration)) if duration else None
        except ValueError:
            raise UserValueError(
                _("Row {}: can't parse duration: {}").format(
                    num_row, duration))

        if not title:
            raise UserValueError(
                _("Row {}: contribution title is required").format(num_row))

        with track_time_changes() as changes:
            contribution = create_contribution(
                event, {
                    'start_dt': parsed_start_dt,
                    'duration': parsed_duration or timedelta(minutes=20),
                    'title': title
                },
                extend_parent=True)

        contributions.append(contribution)
        for key, val in changes[event].viewitems():
            all_changes[key].append(val)

        if not email:
            continue

        # set the information of the speaker
        person = get_event_person(
            event, {
                'firstName': first_name,
                'familyName': last_name,
                'affiliation': affiliation,
                'email': email
            })
        link = ContributionPersonLink(person=person, is_speaker=True)
        link.populate_from_dict({
            'first_name': first_name,
            'last_name': last_name,
            'affiliation': affiliation,
            'email': email
        })
        contribution.person_links.append(link)

    return contributions, all_changes