コード例 #1
0
ファイル: ScheduleTools.py プロジェクト: mmccarty/nell
 def reinitScore(self, period):
     now = TimeAgent.quarter(datetime.utcnow())
     if now < period.start:
         period.reinit_score()
コード例 #2
0
ファイル: PeriodHttpAdapter.py プロジェクト: mmccarty/nell
    def from_post(self, fdata, tz):
        # only update the score if something in the period has changed
        update_score = False
        if not update_score:
            update_score = self.period.id is None
        # if newly created then start with a default 
        if update_score:
            self.period.reinit_score()
        handle = fdata.get("handle", "")
        if handle:
            new_session = Sesshun.handle2session(handle)
            if not update_score:
                update_score = self.period.session != new_session
            self.period.session = new_session
        else:
            try:
                maintenance = Project.objects.get(pcode='Maintenance')
                self.period.session = Sesshun.objects.get(project=maintenance)
            except:
                self.period.session  = Sesshun.objects.get(id=fdata.get("session", 1))
        now           = TimeAgent.quarter(datetime.utcnow())
        date          = fdata.get("date", None)
        time          = fdata.get("time", "00:00")
        if date is None:
            self.period.start = now
        else:
            new_start = TimeAgent.quarter(strStr2dt(date, time + ':00'))
            if tz == 'ET':
                new_start = TimeAgent.est2utc(self.period.start)
            if not update_score:
                update_score = self.period.start != new_start
            self.period.start = new_start
        new_duration = TimeAgent.rndHr2Qtr(float(fdata.get("duration", "1.0")))
        if not update_score:
            update_score = self.period.duration != new_duration
        self.period.duration = new_duration
        
        # if the score needs to be updated, then prepare it for this
        if update_score and now < self.period.start:
            self.period.reinit_score()
        self.period.backup   = True if fdata.get("backup", None) == 'true' else False
        stateAbbr = fdata.get("state", "P")
        self.period.state = Period_State.objects.get(abbreviation=stateAbbr)
        self.period.moc_ack = fdata.get("moc_ack", self.period.moc_ack)

        # elective? 
        eId = fdata.get("elective_id", None)
        if eId is not None:
            self.period.elective_id = eId

        # window?    
        wId = fdata.get("window_id", None)
        if wId is not None:
            self.period.window_id = wId
            try:
                win = Window.objects.get(id = wId)
            except Window.DoesNotExist:
                pass
            else:
                end = win.last_date()
                if end and date is None:
                    self.period.start = datetime(end.year, end.month, end.day)
                    self.period.duration = 1
                    
        elif self.period.session.isWindowed() and self.period.window_id is None:
            # just because the window id wasn't specified doesn't mean
            # we don't want to assign this a window:
            # for instance, if this period was created outside of the 
            # Windowed Period Explorer, we'll have to assign a window
            self.period.assign_a_window()

        # is this period a default period for a window?
        default = fdata.get("wdefault", None)
        if default is not None: #
            if default == "true" and self.period.window is not None:
                # assign this period as a default
                self.period.window.default_period = self.period
                self.period.window.save()
            elif default == "false" and self.period.window is not None:
                # unassign this period as a default
                self.period.window.default_period = None
                self.period.window.save()
            
        # how to initialize scheduled time? when they get published!
        # so, only create an accounting object if it needs it.
        if self.period.accounting is None:
            schd = self.period.duration if self.period.isScheduled() else 0.0 
            pa = Period_Accounting(scheduled = schd)
            pa.save()
            self.period.accounting = pa

        self.period.accounting.update_from_post(fdata)

        self.period.save()

        # now that we have an id (from saving), we can specify the relation
        # between this period and assocaited rcvrs
        self.update_rcvrs_from_post(fdata)