Esempio n. 1
0
File: views.py Progetto: tisobe/Ocat
    def remove_entry_from_approve_list(self,  form):
        """
        removed "Remove"d obsid from the list and recreate basic info lists
        input:  form        --- form passed
        output: self.entry_list     --- [obsid, seqno, propno, target, title, note, pname, sind], 
                self.obsidentry 
                seof.ostatus
        """
#
#--- form['obsidentry'] is a string with format of e.g, 17234:17235;17236
#
        obsidentry  = re.split(':', form['obsidentry'])

        obsid_list  = []
        for obsid in obsidentry:
    
            try:
                if form[str(obsid)] == 'Remove':
                    continue
            except:
                pass

            if ocf.chkNumeric(obsid):
                obsid_list.append(obsid)
#
#--- create approve table lists (returning self.entry_list, self.obsidentry, self.ostatus)
#
        self.create_approve_table_list(obsid_list)

        self.approved_list = ''
        self.rejected_list = ''
Esempio n. 2
0
File: views.py Progetto: tisobe/Ocat
    def approve_the_list(self, form):
        """
        select which observations are approvable and approve them
        input:  form        --- from parameters
                submitter   --- poc/submitter
        outpu: [approved_list, rejected_list]
               this also callsadd_to_approved_database, and add the approved
                obsids to the sql database.
        """

        obsidentry = re.split(':',form['obsidentry'])
        ostatus    = re.split(':',form['ostatus'])

        approved_list = []
        rejected_list = []
        for i in range(0, len(obsidentry)):
            obsid = obsidentry[i]
            if ocf.chkNumeric(obsid) == False:
                continue

            if ostatus[i] == 'y':
                approved_list.append(obsid)
            else:
                rejected_list.append(obsid)

        if len(approved_list) == 0:
            approved_list = 'na'
        if len(rejected_list) == 0:
            rejected_list = 'na'
#
#--- update all databases
#
        add_to_approved_database(approved_list, self.submitter)
#
#--- send out notification email
#
        cle.send_out_email_for_express_approval(approved_list, self.submitter)

        self.entry_list    = ''
        self.obsidentry    = ''
        self.ostatus       = ''
        self.approved_list = approved_list
        self.rejected_list = rejected_list
Esempio n. 3
0
File: views.py Progetto: tisobe/Ocat
def make_obsid_list(input_list):
    """
    convert a string list of obsid into a list
    input:  input_list  --- a string list of obsid
    output: obsid_list  --- a list of obsid
    """
#
#--- split the obsid list entries to a list
#
    chk = 0
    mc = re.search('-', input_list)
    if mc is not None:
        chk = 1

    test_list  = re.split('\,|\;|\/|\s+|\t+', input_list)

    obsid_list  = []
#
#--- drop none numeric entries (such as blank space)
#
    for ent in test_list:
        mc = re.search('-', ent)
        if mc is not None:
            atemp = re.split('-', ent)
            try:
                begin = int(float(atemp[0]))
                end   = int(float(atemp[-1])) + 1
                for i in range(begin, end):
                    obsid_list.append(str(i))
            except:
                pass

        if ocf.chkNumeric(ent):
            obsid_list.append(ent)

    return obsid_list
Esempio n. 4
0
    def update_db(self, form):
        """
        update data dictionary based of submitted changes
        input:  form             --- submitted parameters from GET
                self.dat_dict    --- the current data dictionary
        output: self.dat_dict    --- updated data dictionary
        """

        self.dat_dict = {}
        for key in self.org_dict.keys():
            self.dat_dict[key] = self.org_dict[key]

        fx = open(
            '/proj/web-r2d2-v/lib/python2.7/site-packages/r2d2-v/TEST/zzz',
            'w')
        for key in form.keys():
            #
            #---  check the value is numeric. if so change back to float or int
            #---  before saving in dat_dict
            #
            nval = form[key]
            line = str(key) + '<--->' + str(nval) + '\n'
            fx.write(line)
            if ocf.chkNumeric(nval):
                nval = float(nval)
                #
                #--- check the original value is float or int
                #
                try:
                    mc = re.search('\.', self.org_dict[key])
                    if mc is not None:
                        oval = float(self.org_dict[key])
                        fchk = 1
                    else:
                        fchk = 0
                except:
                    fchk = 0

                if fchk == 0:
                    test = int(
                        nval)  #--- checking whether the value is integer
                    if nval == test:
                        nval = test
                else:
                    if oval == nval:
                        nval = oval
#
#--- if the value is in non_list (e.g., None), make sure original and submitted values
#--- take the same format
#
            try:
                oval = self.org_dict[key]
                #fx = open('/proj/web-r2d2-v/lib/python2.7/site-packages/r2d2-v/TEST/zzz', 'a')
                #line = str(key) +'<--->' + str(oval) + '<---->' + str(nval) + str(non_list) +  '\n'
                #fx.write(line)
                #fx.close()
                if oval in non_list:
                    if nval in non_list:
                        nval = oval
            except:
                pass
#
#--- save the updated value
#
            self.dat_dict[key] = nval
#
#---------- special cases start here   -----------
#
        fx.close()

        #
        #--- update dra and ddec (ra/dec are in HMS/DMS)
        #
        [dra, ddec] = ocf.convert_ra_dec_decimal(self.dat_dict['ra'],
                                                 self.dat_dict['dec'])
        self.dat_dict['dra'] = dra
        self.dat_dict['ddec'] = ddec
        #
        #--- check order flags and then set ordr to 1 if the ordr was originally 0
        #
        f_list = ['window_flag', 'roll_flag', 'spwindow_flag']
        o_list = ['time_ordr', 'roll_ordr', 'ordr']
        for i in range(0, 3):
            try:
                if form[f_list[i]] == 'Y':
                    if self.dat_dict[o_list[i]] == 0:
                        self.dat_dict[o_list[i]] = 1
            except:
                pass
#
#--- if asked increase the order from the current one, increase ordr by 1
#
        if form['check'] == "Add Another Time Constraint":
            self.add_new_ordr_list('time_ordr', 'window_constraint',
                                   self.spwindow_list)

        if form['check'] == "Add Another Roll Constraint":
            self.add_new_ordr_list('roll_ordr', 'roll_constraint',
                                   self.roll_list)

        if form['check'] == "Add Another ACIS Window Constraint":
            self.add_new_ordr_list('ordr', 'chip', self.spwindow_list)
#
#--- remove null rows from the ordered cases
#
        if form['check'] == "Remove Null Time Constraint":
            self.remove_null_from_ordr_list('time_ordr', 'window_constraint',
                                            'window_flag', self.window_list)

        if form['check'] == "Remove Null Roll Constraint":
            self.remove_null_from_ordr_list('roll_ordr', 'roll_constraint',
                                            'roll_flag', self.roll_list)

        if form['check'] == "Remove Null ACIS Window Constraint":
            self.remove_null_from_ordr_list('ordr', 'chip', 'spwindow_flag',
                                            self.spwindow_list)
#
#--- set si_mode to 'New Value Requsted', if any of the following parameters are modified
#
        for param in [
                'est_cnt_rate', 'forder_cnt_rate', 'raster_scan', 'grating',
                'instrument', 'dither_flag'
        ]:
            try:
                oval = self.org_dict[param]
            except:
                oval = None
            try:
                nval = self.dat_dict[param]
            except:
                nval = None

            if oval != nval:
                self.dat_dict['si_mode'] = 'New Value Requsted'
                break
Esempio n. 5
0
def adjust_display_value(name, org_val, req_val, dat_val):
    """
    clean up the display values
    input:  name    --- parameter name
            org_val --- original value
            req_val --- requested value
            dat_val --- database value
    output: org_val --- modified original value
            req_val --- modified requested value
            dat_val --- modified database value
    """
    #
    #-- if the value is None (or something like that), set to <blank>
    #
    if org_val in non_list:
        org_val = ''
    if str(org_val).lower() == '<blank>':
        org_val = ''
    if req_val in non_list:
        req_val = ''
#
#--- if req_val and dat_val in non_list, make them <blank>
#
    if (req_val in non_list) and (dat_val in non_list):
        dat_val = req_val
#
#--- if they are numeric, adjust digit (round to 6 digits) and compare
#
    elif ocf.chkNumeric(dat_val):
        #
        #--- special treatment for pre_id/observatories
        #
        mc = re.search('pre_id', name)

        try:
            val0 = float(org_val)
            org_val = round(val0, 6)
            if mc is not None:
                org_val = int(org_val)
        except:
            pass
        try:
            val1 = float(req_val)
            req_val = round(val1, 6)
            if mc is not None:
                req_val = int(req_val)
        except:
            pass
        try:
            val2 = float(dat_val)
            dat_val = round(val2, 6)
            if mc is not None:
                dat_val = int(dat_val)
        except:
            pass
#
#--- if order = 0, replace them to <blank>
#
    mc = re.search('ordr', name)
    if mc is not None:
        if org_val in [0, '0']:
            org_val = ''
        if req_val in [0, '0']:
            req_val = ''
        if dat_val in [0, '0']:
            dat_val = ''

    return [org_val, req_val, dat_val]
Esempio n. 6
0
    def update_db(self, form):
        """
        update data dictionary based of submitted changes
        input:  form             --- submitted parameters from GET
                dat_dict    --- the current data dictionary
        output: dat_dict    --- updated data dictionary
        """
        #
        #--- get db values again
        #
        [org_dict,
         nc_dict] = self.initialize_dat_dicts(form['obsid'], self.submitter)
        dat_dict = {}
        for key in org_dict.keys():
            dat_dict[key] = org_dict[key]

        for key in form.keys():
            #
            #---  check the value is numeric. if so change back to float or int
            #---  before saving in dat_dict
            #
            nval = form[key]

            if ocf.chkNumeric(nval):
                nval = float(nval)
                #
                #--- check the original value is float or int
                #
                try:
                    mc = re.search('\.', org_dict[key])
                    if mc is not None:
                        oval = float(org_dict[key])
                        fchk = 1
                    else:
                        fchk = 0
                except:
                    fchk = 0

                if fchk == 0:
                    test = int(
                        nval)  #--- checking whether the value is integer
                    if nval == test:
                        nval = test
                else:
                    if oval == nval:
                        nval = oval
#
#--- if the value is in non_list (e.g., None), make sure original and submitted values
#--- take the same format
#
            try:
                oval = org_dict[key]
                if oval in self.non_list:
                    if nval in self.non_list:
                        nval = oval
            except:
                pass
#
#--- save the updated value
#
            dat_dict[key] = nval
#
#---------- special cases start here   -----------
#

#
#--- update dra and ddec (ra/dec are in HMS/DMS)
#
        [dra, ddec] = ocf.convert_ra_dec_decimal(dat_dict['ra'],
                                                 dat_dict['dec'])
        dat_dict['dra'] = dra
        dat_dict['ddec'] = ddec
        #
        #--- check order flags and then set ordr to 1 if the ordr was originally 0
        #
        f_list = ['window_flag', 'roll_flag', 'spwindow_flag']
        o_list = ['time_ordr', 'roll_ordr', 'ordr']
        for i in range(0, 3):
            try:
                if form[f_list[i]] == 'Y':
                    if dat_dict[o_list[i]] == 0:
                        dat_dict[o_list[i]] = 1
            except:
                pass
#
#--- if asked increase the order from the current one, increase ordr by 1
#
        if form['check'] == "Add Another Time Constraint":
            self.add_new_ordr_list('time_ordr', 'window_constraint',
                                   self.spwindow_list)

        if form['check'] == "Add Another Roll Constraint":
            self.add_new_ordr_list('roll_ordr', 'roll_constraint',
                                   self.roll_list)

        if form['check'] == "Add Another ACIS Window Constraint":
            self.add_new_ordr_list('ordr', 'chip', self.spwindow_list)
#
#--- remove null rows from the ordered cases
#
        if form['check'] == "Remove Null Time Constraint":
            self.remove_null_from_ordr_list('time_ordr', 'window_constraint',
                                            'window_flag', self.window_list)

        if form['check'] == "Remove Null Roll Constraint":
            self.remove_null_from_ordr_list('roll_ordr', 'roll_constraint',
                                            'roll_flag', self.roll_list)

        if form['check'] == "Remove Null ACIS Window Constraint":
            self.remove_null_from_ordr_list('ordr', 'chip', 'spwindow_flag',
                                            self.spwindow_list)
#
#--- set si_mode to 'New Value Requsted', if any of the following parameters are modified
#
        for param in [
                'est_cnt_rate', 'forder_cnt_rate', 'raster_scan', 'grating',
                'instrument', 'dither_flag'
        ]:
            try:
                oval = org_dict[param]
            except:
                oval = None
            try:
                nval = dat_dict[param]
            except:
                nval = None

            if oval != nval:
                dat_dict['si_mode'] = 'New Value Requsted'
                break

        return [org_dict, nc_dict, dat_dict]