Ejemplo n.º 1
0
    def from_post(self, fdata):

        # most likely, we'll be specifying sessions for windows in the same
        # manner as we do for periods
        handle = fdata.get("handle", "")
        if handle:
            self.elective.session = Sesshun.handle2session(handle)
        else:
            try:
                maintenance = Project.objects.get(pcode='Maintenance')
                self.elective.session = Sesshun.objects.get(project=maintenance)
            except:
                self.elective.session  = Sesshun.objects.get(id=fdata.get("session", 1))


        self.elective.setComplete(fdata.get("complete", "false") == "true")

        self.elective.save()                
Ejemplo n.º 2
0
 def setUp(self):
     super(TestReceiver, self).setUp()
     s = Sesshun()
     adapter = SessionHttpAdapter(s)
     adapter.init_from_post({})
     s.save()
Ejemplo n.º 3
0
    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)