Ignore:
Timestamp:
17 Oct 2006, 11:20:25 (18 years ago)
Author:
joachim
Message:

implemented new reserved room procedure as described in ticket #50
also made a WAeUPReservedRoomsWidget, to check the validity of the reserved
rooms form entry.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • WAeUP_SRP/trunk/Students.py

    r710 r714  
    2323MAX_TRANS = 1000
    2424
    25 def generateStudentId(letter):
    26     import random
    27     r = random
    28     if letter not in ('ABCDEFGIHKLMNOPQRSTUVWXY'):
    29         letter= r.choice('ABCDEFGHKLMNPQRSTUVWXY')
    30     students = context.portal_catalog(meta_type = "StudentsFolder")[-1]
    31     sid = "%c%d" % (letter,r.randint(99999,1000000))
    32     while hasattr(students, sid):
    33         sid = "%c%d" % (letter,r.randint(99999,1000000))
    34     return sid
    35     #return "%c%d" % (r.choice('ABCDEFGHKLMNPQRSTUVWXY'),r.randint(99999,1000000))
    36 
    37 def getStudentByRegNo(self,reg_no):
     25
     26def getStudentByRegNo(self,reg_no): ###(
    3827    """search student by JAMB Reg No and return StudentFolder"""
    3928    search = ZCatalog.searchResults(self.portal_catalog,{'meta_type': 'StudentApplication',
     
    4332        return None
    4433    return search[0].getObject().aq_parent
     34
     35###)
    4536
    4637class StudentsFolder(CPSDocument): ###(
     
    111102            if matric_no not in matrics:
    112103                matrics.append(matric_no)
    113                 sid = generateStudentId(student.get('Lastname')[0])
     104                sid = self.generateStudentId(student.get('Lastname')[0])
    114105                #self.log('Creating Faculty %(id)s = %(Title)s' % faculty)
     106                students_folder.invokeFactory('Student', sid)
    115107                logger.info('%(tr_count)s: Creating Student with ID %(sid)s Matric_no %(matric_no)s ' % vars())
    116                 not_created = True
    117                 while not_created:
    118                     try:
    119                         students_folder.invokeFactory('Student', sid)
    120                         not_created = False
    121                     except BadRequest:
    122                         sid = generateStudentId()
    123                 logger.info('%(tr_count)s: Creating Student with ID %(sid)s Matric_no %(matric_no)s ' % vars())
    124                 s = getattr(self,sid)
     108                student_obj = getattr(self,sid)
    125109                access_code = "%d" % random.randint(1000000000,9999999999)
    126110                self.portal_registration.addMember(sid,
     
    129113                                                          'Student',))
    130114                pwl_dict = {'student_id': sid,'access_code':access_code}
    131                 s.invokeFactory('StudentApplication','application')
     115                student_obj.invokeFactory('StudentApplication','application')
     116                application = student_obj.application
    132117                da = {'Title': 'Application Data'}
    133                 s.invokeFactory('StudentPersonal','personal')
     118                student_obj.invokeFactory('StudentPersonal','personal')
    134119                da['jamb_reg_no'] = student.get('EntryRegNo')
    135                 sp = s.personal
     120                personal = student_obj.personal
    136121                dp = {'Title': 'Personal Data'}
    137                 s.invokeFactory('StudentClearance','clearance')
    138                 sc = s.clearance
     122                student_obj.invokeFactory('StudentClearance','clearance')
     123                clearance = student_obj.clearance
    139124                dc = {'Title': 'Clearance Data'}
    140125                dc['matric_no'] = matric_no
    141                 lga = student.get('State') + ' / ' + student.get('LGA')
     126                state = student.get('State')
     127                lga = student.get('LGA')
     128                if state and lga:
     129                    lga =  state + ' / ' + lga
     130                else:
     131                    lga = "None"
    142132                dc['lga'] = lga
    143133                dc['nationality'] = student.get('Nationality')
     
    152142                dp['campus_address'] = student.get('CampusAddress')
    153143                dp['phone'] = student.get('PhoneNumber')
    154                 s.application.getContent().edit(mapping=da)
    155                 sp.getContent().edit(mapping=dp)
    156                 sc.getContent().edit(mapping=dc)
     144                application.getContent().edit(mapping=da)
     145                personal.getContent().edit(mapping=dp)
     146                clearance.getContent().edit(mapping=dc)
    157147                #
    158148                # Study Course
    159149                #
    160                 s.invokeFactory('StudentStudyCourse','study_course')
    161                 sc = s.study_course
     150                student_obj.invokeFactory('StudentStudyCourse','study_course')
     151                studycourse = student_obj.study_course
    162152                dsc = {}
    163153                dsc['study_course'] = certcode
    164154                css = student.get('CurrentSession') or '2004-2005'
    165155                cs = int(css.split('-')[0]) - 2000
    166                 cl = int(student.get('StudentLevel'))/100
     156                cl = int(student.get('StudentLevel') or '100')/100
    167157                dsc['entry_session'] = "200%s" % (cs - cl)
    168158                dsc['clr_ac_pin'] = access_code
    169                 sc.getContent().edit(mapping=dsc)
     159                studycourse.getContent().edit(mapping=dsc)
    170160                #
    171161                # Level
    172162                #
    173                 l = getattr(sc,level,None)
     163                l = getattr(studycourse,level,None)
    174164                if l is None:
    175165                    #self.log('Creating Department %(DeptCode)s = %(Description)s' % dep)
    176166                    logger.info('Creating Level %(StudentLevel)s for %(fullname)s' % student)
    177                     sc.invokeFactory('StudentStudyLevel', level)
    178                     l = getattr(sc, level)
     167                    studycourse.invokeFactory('StudentStudyLevel', level)
     168                    l = getattr(studycourse, level)
    179169                    certificate = certs[certcode]
    180170                    cert_level = getattr(certificate,level,None)
     
    193183                no_import.write(em)
    194184                no_import.write('"%(MatricNo)s","%(EntryRegNo)s","%(CurrentSession)s","%(StudentLevel)s","%(fullname)s","%(FirstName)s","%(MiddleName)s","%(Lastname)s","%(FormerSurname)s","%(Sex)s","%(Nationality)s","%(State)s","%(LGA)s","%(PermanentAddress)s","%(PermanentAddressCity)s","%(CampusAddress)s","%(PhoneNumber)s","%(Emailaddress)s","%(Mode)s","%(CourseMajor)s","%(Faculty)s","%(Dept)s"\n' % student)
     185                continue
    195186            if tr_count > MAX_TRANS:
    196187                transaction.commit()
     
    202193            pwl_dict.update(da)
    203194            pwl_dict.update(dp)
     195            wftool = self.portal_workflow
    204196            pwlist.append(pwl_template.substitute(pwl_dict))
     197            wftool.doActionFor(student_obj,'clear_and_validate')
     198            wftool.doActionFor(application,'close')
     199            wftool.doActionFor(clearance,'close')
     200            wftool.doActionFor(personal,'close')
     201        open("%s/import/pwlist-%s.csv" % (i_home,name),"w+").write('\n'.join(pwlist))
    205202        return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1'))
    206203    ###)
     
    335332            names = jamb_name.split()
    336333            letter = names[-1][0].upper()
    337             sid = generateStudentId(letter)
    338             #self.log('Creating Faculty %(id)s = %(Title)s' % faculty)
     334            sid = self.generateStudentId(letter)
    339335            not_created = True
    340336            while not_created:
     
    343339                    not_created = False
    344340                except BadRequest:
    345                     sid = generateStudentId(letter)
     341                    sid = self.generateStudentId(letter)
    346342            logger.info('%(tr_count)s: Creating Student with ID %(sid)s REG-NO %(jamb_reg_no)s ' % vars())
    347343            student = getattr(self,sid)
     
    383379        """compose title"""
    384380        return "Student Section"
     381
     382    def generateStudentId(self,letter): ###(
     383        import random
     384        r = random
     385        if letter not in ('ABCDEFGIHKLMNOPQRSTUVWXY'):
     386            letter= r.choice('ABCDEFGHKLMNPQRSTUVWXY')
     387        students = self.portal_catalog(meta_type = "StudentsFolder")[-1]
     388        sid = "%c%d" % (letter,r.randint(99999,1000000))
     389        while hasattr(students, sid):
     390            sid = "%c%d" % (letter,r.randint(99999,1000000))
     391        return sid
     392        #return "%c%d" % (r.choice('ABCDEFGHKLMNPQRSTUVWXY'),r.randint(99999,1000000))
     393    ###)
    385394
    386395InitializeClass(StudentsFolder)
Note: See TracChangeset for help on using the changeset viewer.