Ignore:
Timestamp:
29 Dec 2006, 22:05:53 (18 years ago)
Author:
joachim
Message:

ask for email and password

File:
1 edited

Legend:

Unmodified
Added
Removed
  • WAeUP_SRP/trunk/WAeUPTool.py

    r828 r1151  
    3535from Products.CMFCore.permissions import ModifyPortalContent
    3636from Products.CMFCore.utils import UniqueObject
     37from Students import makeCertificateCode
     38import logging
     39
    3740
    3841class WAeUPTool(UniqueObject, SimpleItem, ActionProviderBase):
     
    5053                     )
    5154
    52 ##    security.declarePublic('getHallTitle')
    53 ##    def getHallTitle(self,hall):
    54 ##        """get the Hall Title"""
    55 ##        res = ZCatalog.searchResults(self.portal_catalog,portal_type="AccoHall",id=hall)
    56 ##        if res and len(res) == 1:
    57 ##            return res[0].Title
    58 ##        return hall
    59 
    60     security.declarePublic('getAccommodationInfo')
     55    def generateStudentId(self,letter): ###(
     56        import random
     57        r = random
     58        if letter not in ('ABCDEFGIHKLMNOPQRSTUVWXY'):
     59            letter= r.choice('ABCDEFGHKLMNPQRSTUVWXY')
     60        students = self.portal_url.getPortalObject().campus.students
     61        sid = "%c%d" % (letter,r.randint(99999,1000000))
     62        while hasattr(students, sid):
     63            sid = "%c%d" % (letter,r.randint(99999,1000000))
     64        return sid
     65    ###)
     66
     67    security.declarePublic('getCertificateBrain') ###(
     68    def getCertificateBrain(self,cert_id):
     69        "do it"
     70        res = ZCatalog.searchResults(self.portal_catalog,
     71                                {'portal_type':"Certificate",
     72                                      'id': cert_id})
     73        if res:
     74            return res[0]
     75        return None
     76    ###)
     77   
     78    security.declarePublic('findStudentByMatricelNo') ###(
     79    def findStudentByMatricelNo(self,matric_no):
     80        "do it"
     81        res = ZCatalog.searchResults(self.portal_catalog,
     82                                {'portal_type':"StudentClearance",
     83                                 'SearchableText': matric_no})
     84        if res:
     85            return res[0]
     86        return None
     87    ###)
     88
     89    security.declarePublic('makeStudentMember') ###(
     90    def makeStudentMember(self,sid,password='uNsEt'):
     91        """make the student a member"""
     92        membership = self.portal_membership
     93        membership.addMember(sid,
     94                             password ,
     95                             roles=('Member',
     96                                     'Student',
     97                                     ),
     98                             domains='',
     99                             properties = {'memberareaCreationFlag': False,
     100                                           'homeless': True},)
     101        member = membership.getMemberById(sid)
     102        self.portal_registration.afterAdd(member, sid, password, None)
     103        self.manage_setLocalRoles(sid, ['Owner',])
     104    ###)
     105       
     106    security.declarePublic('makeStudentData') ###(
     107    def makeStudentData(self,student_id,email=None):
     108        "create Datastructure for a returning Student"
     109        #import pdb;pdb.set_trace()
     110        logger = logging.getLogger('Student.CreateData')
     111        students_folder = self.portal_url.getPortalObject().campus.students
     112        res = self.students_catalog(id=student_id)
     113        if res:
     114            st = res[0]
     115        res = self.returning_import(matric_no = st.matric_no)
     116        if res:
     117            student = res[0]
     118        logger.info('"%s", "creating Datastructure"')
     119        certcode_org = student.Coursemajorcode
     120        certcode = makeCertificateCode(certcode_org)
     121        certificate_brain = self.getCertificateBrain(certcode)
     122        if not certificate_brain:
     123            em = 'Certificate %s org-code %s not found\n' % (certcode, certcode_org)
     124            logger.info(em)
     125        level = student.Level
     126        try:
     127            int(level)
     128        except:
     129            em = '"%(matric_no)s","invalid Level","%(Level)s"' % student
     130            logger.info(em)
     131        matric_no = student.matric_no
     132        sid = student_id
     133        student_obj = getattr(students_folder,sid)
     134        student_obj.invokeFactory('StudentApplication','application')
     135        application = student_obj.application
     136        self.portal_workflow.doActionFor(application,'open',dest_container=application)
     137        da = {'Title': 'Application Data'}
     138        student_obj.invokeFactory('StudentPersonal','personal')
     139        da['jamb_reg_no'] = student.Entryregno
     140        da['entry_mode'] = student.Mode_of_Entry
     141        personal = student_obj.personal
     142        self.portal_workflow.doActionFor(personal,'open',dest_container=personal)
     143        dp = {'Title': 'Personal Data'}
     144        student_obj.invokeFactory('StudentClearance','clearance')
     145        clearance = student_obj.clearance
     146        self.portal_workflow.doActionFor(clearance,'open',dest_container=clearance)
     147        dc = {'Title': 'Clearance/Eligibility Record'}
     148        dc['matric_no'] = matric_no
     149        state = student.State
     150        lga = student.LGA
     151        if state and lga:
     152            lga =  state + ' / ' + lga
     153        else:
     154            lga = "None"
     155        dc['lga'] = lga
     156        dc['email'] = email
     157        dp['firstname'] = student.Firstname
     158        dp['middlename'] = student.Middlename
     159        dp['lastname'] = student.Lastname
     160        dp['sex'] = student.Sex == 'F'
     161        dp['perm_address'] = student.Permanent_Address
     162        application.getContent().edit(mapping=da)
     163        personal.getContent().edit(mapping=dp)
     164        clearance.getContent().edit(mapping=dc)
     165        #
     166        # Study Course
     167        #
     168        student_obj.invokeFactory('StudentStudyCourse','study_course')
     169        studycourse = student_obj.study_course
     170        self.portal_workflow.doActionFor(studycourse,'open',dest_container=studycourse)
     171        dsc = {}
     172        dsc['study_course'] = certcode
     173        studycourse.getContent().edit(mapping=dsc)
     174        #
     175        # Level
     176        #
     177##        l = getattr(studycourse,level,None)
     178##        if l is None:
     179##            studycourse.invokeFactory('StudentStudyLevel', level)
     180##            l = getattr(studycourse, level)
     181##            self.portal_workflow.doActionFor(l,'open',dest_container=l)
     182##            l.getContent().edit(mapping={'Title': "Level %s" % level})
     183       
     184    security.declarePublic('getAccommodationInfo') ###(
    61185    def getAccommodationInfo(self,bed):
    62186        """return Accommodation Info"""
     
    82206            info['maintenance_fee'] = batch_doc.cost
    83207        return info
     208    ###)
     209
     210    security.declareProtected(ModifyPortalContent,'deleteAllCourses') ###(
     211    def deleteAllCourses(self,department="All"):
     212        ''' delete the courses'''
     213        pm = self.portal_membership
     214        member = pm.getAuthenticatedMember()
     215       
     216        if str(member) not in ("henrik","joachim"):
     217            return "not possible"
     218        if department == "All":
     219            res = self.portal_catalog({'meta_type': 'Department'})
     220        if len(res) < 1:
     221            return "No Departments found"
     222       
     223        deleted = []
     224        for dep in res:
     225            cf = dep.getObject().courses
     226            if cf:
     227                cf.manage_delObjects(ids=cf.objectIds())
     228                deleted.append("deleted Courses in %s" % dep.getId)
     229        return "\r".join(deleted)
     230    ###)   
     231   
    84232
    85233InitializeClass(WAeUPTool)
Note: See TracChangeset for help on using the changeset viewer.