Example #1
0
 def handle_generate_takes(self, action, data):
     session = Session()
     trusted = removeSecurityProxy(self.context)
     takes = session.query(domain.Take).filter(
         domain.Take.sitting_id == trusted.sitting_id)
     for t in takes:
         session.delete(t)
     
     #import pdb; pdb.set_trace()
     sitting = trusted
     current_start_time = sitting.start_date
     sitting_duration = sitting.end_date - sitting.start_date
     take_duration = timedelta(minutes=int(data["duration"]))
     assigned_reporters = get_assigned_staff(self.context, "Reporter")
     assigned_readers = get_assigned_staff(self.context, "Reader")
     assigned_editors = get_assigned_staff(self.context, "Editor")
     c_reporter = 0 
     c_reader = 0
     c_editor = 0
     
     while sitting_duration > timedelta(minutes=0):
         take = domain.Take()
         take.sitting_id = sitting.sitting_id
         if (sitting_duration - take_duration) > timedelta(minutes=0):
             sitting_duration = sitting_duration - take_duration
             take.start_date = current_start_time
             take.end_date = take.start_date + take_duration
             current_start_time = take.end_date
         else:
             take.start_date = current_start_time
             take.end_date = take.start_date + sitting_duration
             sitting_duration = timedelta(minutes=0)
         if c_reporter > len(assigned_reporters)-1:
             c_reporter = 0
             take.reporter_id = assigned_reporters[c_reporter]
         else:
             take.reporter_id = assigned_reporters[c_reporter]
         c_reporter = c_reporter + 1
         
         if c_reader > len(assigned_readers)-1:
             c_reader = 0
             take.reader_id = assigned_readers[c_reader]
         else:
             take.reader_id = assigned_readers[c_reader]
         c_reader = c_reader + 1
         
         if c_editor > len(assigned_editors)-1:
             c_editor = 0
             take.editor_id = assigned_editors[c_editor]
         else:
             take.editor_id = assigned_editors[c_editor]
         c_editor = c_editor + 1
         session.add(take)
     session.commit()
     self.request.response.redirect('./takes')
Example #2
0
    def handle_generate_takes(self, action, data):
        session = Session()
        trusted = removeSecurityProxy(self.context)
        takes = session.query(
            domain.Take).filter(domain.Take.sitting_id == trusted.sitting_id)
        for t in takes:
            session.delete(t)

        #import pdb; pdb.set_trace()
        sitting = trusted
        current_start_time = sitting.start_date
        sitting_duration = sitting.end_date - sitting.start_date
        take_duration = timedelta(minutes=int(data["duration"]))
        assigned_reporters = get_assigned_staff(self.context, "Reporter")
        assigned_readers = get_assigned_staff(self.context, "Reader")
        assigned_editors = get_assigned_staff(self.context, "Editor")
        c_reporter = 0
        c_reader = 0
        c_editor = 0

        while sitting_duration > timedelta(minutes=0):
            take = domain.Take()
            take.sitting_id = sitting.sitting_id
            if (sitting_duration - take_duration) > timedelta(minutes=0):
                sitting_duration = sitting_duration - take_duration
                take.start_date = current_start_time
                take.end_date = take.start_date + take_duration
                current_start_time = take.end_date
            else:
                take.start_date = current_start_time
                take.end_date = take.start_date + sitting_duration
                sitting_duration = timedelta(minutes=0)
            if c_reporter > len(assigned_reporters) - 1:
                c_reporter = 0
                take.reporter_id = assigned_reporters[c_reporter]
            else:
                take.reporter_id = assigned_reporters[c_reporter]
            c_reporter = c_reporter + 1

            if c_reader > len(assigned_readers) - 1:
                c_reader = 0
                take.reader_id = assigned_readers[c_reader]
            else:
                take.reader_id = assigned_readers[c_reader]
            c_reader = c_reader + 1

            if c_editor > len(assigned_editors) - 1:
                c_editor = 0
                take.editor_id = assigned_editors[c_editor]
            else:
                take.editor_id = assigned_editors[c_editor]
            c_editor = c_editor + 1
            session.add(take)
        session.commit()
        self.request.response.redirect('./takes')
Example #3
0
 def validate(self, action, data):
     errors = super(GenerateTakes, self).validate(action, data)
     if ((len(get_assigned_staff(self.context, "Reporter")) == 0)
         or (len(get_assigned_staff(self.context, "Reader")) == 0)
         or (len(get_assigned_staff(self.context, "Editor")) == 0)):
         print "reporters", get_assigned_staff(self.context, "Reporter")
         print "reader", get_assigned_staff(self.context, "Reader")
         print "editors", get_assigned_staff(self.context, "Editor")
         errors.append(interface.Invalid(
             _(u"Staff have not been assigned to work on this sitting yet"),
             "duration"))
     return errors
Example #4
0
 def validate(self, action, data):
     errors = super(GenerateTakes, self).validate(action, data)
     if ((len(get_assigned_staff(self.context, "Reporter")) == 0)
             or (len(get_assigned_staff(self.context, "Reader")) == 0)
             or (len(get_assigned_staff(self.context, "Editor")) == 0)):
         print "reporters", get_assigned_staff(self.context, "Reporter")
         print "reader", get_assigned_staff(self.context, "Reader")
         print "editors", get_assigned_staff(self.context, "Editor")
         errors.append(
             interface.Invalid(
                 _(u"Staff have not been assigned to work on this sitting yet"
                   ), "duration"))
     return errors
Example #5
0
 class context:
     editors = get_assigned_staff(self.context, "Editor")
     readers = get_assigned_staff(self.context, "Reader")
     reporters = get_assigned_staff(self.context, "Reporter")