예제 #1
0
 def _process(self):
     data = request.json
     required_keys = {'contribution_ids', 'day'}
     allowed_keys = required_keys | {'session_block_id'}
     if set(data.viewkeys()) > allowed_keys:
         raise BadRequest('Invalid keys found')
     elif required_keys > set(data.viewkeys()):
         raise BadRequest('Required keys missing')
     entries = []
     day = dateutil.parser.parse(data['day']).date()
     query = Contribution.query.with_parent(self.event_new).filter(
         Contribution.id.in_(data['contribution_ids']))
     with track_time_changes(auto_extend='end',
                             user=session.user) as changes:
         for contribution in query:
             start_dt = find_next_start_dt(
                 contribution.duration,
                 obj=self.session_block or self.event_new,
                 day=None if self.session_block else day,
                 force=True)
             entry = self._schedule(contribution, start_dt)
             if entry.end_dt.astimezone(
                     entry.event_new.tzinfo).date() > day:
                 raise UserValueError(
                     _("Contribution '{}' could not be scheduled since it doesn't fit on this day."
                       ).format(contribution.title))
             entries.append(entry)
     notifications = get_time_changes_notifications(
         changes, tzinfo=self.event_new.tzinfo)
     return jsonify_data(update=serialize_entry_update(
         entries[0], session_=self.session) if entries else None,
                         notifications=notifications,
                         flash=False)
예제 #2
0
파일: legacy.py 프로젝트: florv/indico
 def _process(self):
     data = request.json
     required_keys = {'contribution_ids', 'day'}
     allowed_keys = required_keys | {'session_block_id'}
     if data.viewkeys() > allowed_keys:
         raise BadRequest('Invalid keys found')
     elif required_keys > data.viewkeys():
         raise BadRequest('Required keys missing')
     entries = []
     day = dateutil.parser.parse(data['day']).date()
     query = Contribution.query.with_parent(self.event_new).filter(Contribution.id.in_(data['contribution_ids']))
     with track_time_changes(auto_extend='end', user=session.user) as changes:
         for contribution in query:
             start_dt = find_next_start_dt(contribution.duration,
                                           obj=self.session_block or self.event_new,
                                           day=None if self.session_block else day,
                                           force=True)
             entry = self._schedule(contribution, start_dt)
             if entry.end_dt.astimezone(entry.event_new.tzinfo).date() > day:
                 raise UserValueError(_("Contribution '{}' could not be scheduled since it doesn't fit on this day.")
                                      .format(contribution.title))
             entries.append(entry)
     notifications = get_time_changes_notifications(changes, tzinfo=self.event_new.tzinfo)
     return jsonify_data(update=serialize_entry_update(entries[0], session_=self.session) if entries else None,
                         notifications=notifications, flash=False)
예제 #3
0
 def _get_default_time(self):
     start_dt = find_next_start_dt(
         self._default_duration,
         obj=self.session_block or self.event,
         day=None if self.session_block else self.day)
     return start_dt.astimezone(
         self.event.tzinfo).time() if start_dt else None
예제 #4
0
파일: forms.py 프로젝트: bkolobara/indico
 def _get_default_time(self):
     if self.session_block:
         # inside a block we suggest right after the latest contribution
         # or fall back to the block start time if it's empty
         entry = self.session_block.timetable_entry
         start_dt = max(x.end_dt for x in entry.children) if entry.children else entry.start_dt
     else:
         # outside a block we find the first slot where a contribution would fit
         start_dt = find_next_start_dt(self._default_duration,
                                       obj=self.session_block or self.event,
                                       day=None if self.session_block else self.day)
     return start_dt.astimezone(self.event.tzinfo).time() if start_dt else None
예제 #5
0
 def _get_default_time(self):
     if self.session_block:
         # inside a block we suggest right after the latest contribution
         # or fall back to the block start time if it's empty
         entry = self.session_block.timetable_entry
         start_dt = max(x.end_dt for x in entry.children) if entry.children else entry.start_dt
     else:
         # outside a block we find the first slot where a contribution would fit
         start_dt = find_next_start_dt(self._default_duration,
                                       obj=self.session_block or self.event,
                                       day=None if self.session_block else self.day)
     return start_dt.astimezone(self.event.tzinfo).time() if start_dt else None
예제 #6
0
 def _process(self):
     data = request.json
     required_keys = {'contribution_ids', 'day'}
     allowed_keys = required_keys | {'session_block_id'}
     if data.viewkeys() > allowed_keys:
         raise BadRequest('Invalid keys found')
     elif required_keys > data.viewkeys():
         raise BadRequest('Required keys missing')
     entries = []
     day = dateutil.parser.parse(data['day']).date()
     query = Contribution.query.with_parent(self.event_new).filter(Contribution.id.in_(data['contribution_ids']))
     for contribution in query:
         start_dt = find_next_start_dt(contribution.duration,
                                       obj=self.session_block or self.event_new,
                                       day=None if self.session_block else day)
         # TODO: handle scheduling not-fitting contributions
         #       can only happen within session blocks that are shorter than contribution's duration
         if start_dt:
             entries.append(self._schedule(contribution, start_dt))
     return jsonify(entries=[serialize_entry_update(x) for x in entries])
예제 #7
0
 def _process(self):
     data = request.json
     required_keys = {'contribution_ids', 'day'}
     allowed_keys = required_keys | {'session_block_id'}
     if data.viewkeys() > allowed_keys:
         raise BadRequest('Invalid keys found')
     elif required_keys > data.viewkeys():
         raise BadRequest('Required keys missing')
     entries = []
     day = dateutil.parser.parse(data['day']).date()
     query = Contribution.query.with_parent(self.event_new).filter(
         Contribution.id.in_(data['contribution_ids']))
     for contribution in query:
         start_dt = find_next_start_dt(
             contribution.duration,
             obj=self.session_block or self.event_new,
             day=None if self.session_block else day)
         # TODO: handle scheduling not-fitting contributions
         #       can only happen within session blocks that are shorter than contribution's duration
         if start_dt:
             entries.append(self._schedule(contribution, start_dt))
     return jsonify(entries=[serialize_entry_update(x) for x in entries])
예제 #8
0
 def _get_default_time(self):
     start_dt = find_next_start_dt(self._default_duration,
                                   obj=self.session_block or self.event,
                                   day=None if self.session_block else self.day)
     return start_dt.astimezone(self.event.tzinfo).time() if start_dt else None