Changeset 714 for WAeUP_SRP/trunk


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.

Location:
WAeUP_SRP/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • WAeUP_SRP/trunk/Accommodation.py

    r650 r714  
    4949            hall_gen['name'] = hall.Title
    5050            count = 0
    51             #reserved = [int(r) for r in h.reserved_rooms.split(',')]
    52             reserved = [int(r) for r in re.split(',|\.| ',h.reserved_rooms)
    53                                      if not re.search(r'\D',r) and r]
     51            reserved = [(int(r.split('/')[0]),int(r.split('/')[1])) for r in re.split(',|\.| ',h.reserved_rooms)
     52                                     if r]
    5453            sex = 'male'
    5554            if h.which_sex:
     
    6160                            room_nr = floor*100 + room
    6261                            bt = 're'
    63                             if room_nr in reserved:
     62                            if (block,room_nr) in reserved:
    6463                                bt = "reserved"
    6564                            elif bed in h.beds_for_fresh:
  • 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)
  • WAeUP_SRP/trunk/Widgets.py

    r710 r714  
    170170
    171171widgetRegistry.register(CourseIdWidget)
     172
     173
     174###)
     175
     176class WAeUPReservedRoomsWidget(CPSStringWidget): ###(
     177    """ WAeUPReservedRooms Widget"""
     178    meta_type = "WAeUPReservedRooms Widget"
     179
     180    def validate(self, datastructure, **kw):
     181        """Validate datastructure and update datamodel."""
     182        import re
     183        valid = CPSStringWidget.validate(self, datastructure, **kw)
     184        if not valid:
     185            return 0
     186        else:
     187            widget_id = self.getWidgetId()
     188            value = datastructure[widget_id]
     189            err = 0
     190            try:
     191                reserved = [(int(r.split('/')[0]),int(r.split('/')[1])) for r in re.split(',|\.| ',value)
     192                                     if r]
     193            except ValueError,msg:
     194                err = str(msg)
     195            if err:
     196                datastructure.setError(widget_id, err)
     197            else:
     198                datamodel = datastructure.getDataModel()
     199                datamodel[self.fields[0]] = value
     200            return not err
     201
     202InitializeClass(WAeUPReservedRoomsWidget)
     203
     204widgetRegistry.register(WAeUPReservedRoomsWidget)
    172205
    173206
  • WAeUP_SRP/trunk/profiles/default/layouts/acco_hall.xml

    r666 r714  
    7979    <property name="max_value">5</property>
    8080 </widget>
    81  <widget name="reserved_rooms" meta_type="String Widget">
     81 <widget name="reserved_rooms" meta_type="WAeUPReservedRooms Widget">
    8282  <property name="title">Reserved Rooms</property>
    8383  <property name="fields">
  • WAeUP_SRP/trunk/profiles/default/schemas/acco_hall.xml

    r638 r714  
    1414  </field>
    1515 <field name="reserved_rooms" meta_type="CPS String List Field">
    16     <property name="default_expr">string:101,102</property>
     16    <property name="default_expr">string:1/101,2/102</property>
    1717  </field>
    1818  <field name="rooms_per_floor" meta_type="CPS Int Field">
Note: See TracChangeset for help on using the changeset viewer.