source: WAeUP_SRP/trunk/WAeUPTool.py @ 1169

Last change on this file since 1169 was 1169, checked in by joachim, 18 years ago

display_session_results now asks for jamb_reg_no
set_access_data uses this information
permission mappings for new states in waeup_student_wf added
set_access_data is now called from a form

  • Property svn:keywords set to Id
File size: 9.4 KB
Line 
1#-*- mode: python; mode: fold -*-
2# (C) Copyright 2005 The WAeUP group  <http://www.waeup.org>
3# Author: Joachim Schmitz (js@aixtraware.de)
4#
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License version 2 as published
7# by the Free Software Foundation.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program; if not, write to the Free Software
16# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
17# 02111-1307, USA.
18#
19# $Id: WAeUPTool.py 1169 2007-01-01 16:38:46Z joachim $
20"""The WAeUPTool.
21
22$Id: WAeUPTool.py 1169 2007-01-01 16:38:46Z joachim $
23"""
24
25from AccessControl import ClassSecurityInfo
26from Acquisition import aq_inner
27from Acquisition import aq_parent
28from Globals import DTMLFile
29from Globals import InitializeClass
30from OFS.SimpleItem import SimpleItem
31
32from Products.CMFCore.ActionProviderBase import ActionProviderBase
33from Products.CMFCore.permissions import View
34from Products.ZCatalog.ZCatalog import ZCatalog
35from Products.CMFCore.permissions import ModifyPortalContent
36from Products.CMFCore.utils import UniqueObject
37from Students import makeCertificateCode
38import logging
39
40
41class WAeUPTool(UniqueObject, SimpleItem, ActionProviderBase):
42    """WAeUP tool"""
43
44    id = 'waeup_tool'
45    meta_type = 'WAeUP Tool'
46    _actions = ()
47
48    security = ClassSecurityInfo()
49    security.declareObjectProtected(View)
50
51    manage_options = ( ActionProviderBase.manage_options
52                     + SimpleItem.manage_options
53                     )
54
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,phone_nr=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"' % student_id)
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        dp['email'] = email
157        dp['phone'] = phone_nr
158        dp['firstname'] = student.Firstname
159        dp['middlename'] = student.Middlename
160        dp['lastname'] = student.Lastname
161        dp['sex'] = student.Sex == 'F'
162        dp['perm_address'] = student.Permanent_Address
163        application.getContent().edit(mapping=da)
164        self.portal_workflow.doActionFor(application,'close',dest_container=application)
165        personal.getContent().edit(mapping=dp)
166        clearance.getContent().edit(mapping=dc)
167        self.portal_workflow.doActionFor(clearance,'close',dest_container=clearance)
168        catd = {}
169        catd['id'] = sid
170        catd['entry_mode']= da['entry_mode']
171        catd['matric_no'] = matric_no
172        catd['jamb_reg_no'] = da['jamb_reg_no']
173        catd['name'] = "%(firstname)s %(middlename)s %(lastname)s" % dp 
174        catd['sex'] = dp['sex']
175        catd['level'] = level
176        if certificate_brain:
177            cpath = certificate_brain.getPath().split('/')
178            catd['faculty'] = cpath[-4]
179            catd['department'] = cpath[-3]
180            catd['course'] = certcode
181        self.students_catalog.modifyRecord(**catd)
182        #
183        # Study Course
184        #
185        student_obj.invokeFactory('StudentStudyCourse','study_course')
186        studycourse = student_obj.study_course
187        self.portal_workflow.doActionFor(studycourse,'open',dest_container=studycourse)
188        dsc = {}
189        dsc['study_course'] = certcode
190        studycourse.getContent().edit(mapping=dsc)
191        #
192        # Level
193        #
194##        l = getattr(studycourse,level,None)
195##        if l is None:
196##            studycourse.invokeFactory('StudentStudyLevel', level)
197##            l = getattr(studycourse, level)
198##            self.portal_workflow.doActionFor(l,'open',dest_container=l)
199##            l.getContent().edit(mapping={'Title': "Level %s" % level})
200
201    security.declarePublic('getAccommodationInfo') ###(
202    def getAccommodationInfo(self,bed):
203        """return Accommodation Info"""
204        info = {}
205        hall,block,room,letter = bed.split('_')
206        res = ZCatalog.searchResults(self.portal_catalog,portal_type="AccoHall",id=hall)
207        if res and len(res) == 1:
208            hall_brain = res[0]
209            hall_doc = hall_brain.getObject().getContent()
210        else:
211            return info
212        info['hall_title'] = hall_brain.Title
213        info['maintenance_code'] = hall_doc.maintenance_code
214        res = ZCatalog.searchResults(self.portal_catalog,portal_type="ScratchCardBatch")
215        batch_doc = None
216        for brain in res:
217            if brain.id.startswith(info['maintenance_code']):
218                batch_doc = brain.getObject().getContent()
219                break
220        if batch_doc is None:
221            info['maintenance_fee'] = None
222        else:
223            info['maintenance_fee'] = batch_doc.cost
224        return info
225    ###)
226
227    security.declareProtected(ModifyPortalContent,'deleteAllCourses') ###(
228    def deleteAllCourses(self,department="All"):
229        ''' delete the courses'''
230        pm = self.portal_membership
231        member = pm.getAuthenticatedMember()
232
233        if str(member) not in ("henrik","joachim"):
234            return "not possible"
235        if department == "All":
236            res = self.portal_catalog({'meta_type': 'Department'})
237        if len(res) < 1:
238            return "No Departments found"
239
240        deleted = []
241        for dep in res:
242            cf = dep.getObject().courses
243            if cf:
244                cf.manage_delObjects(ids=cf.objectIds())
245                deleted.append("deleted Courses in %s" % dep.getId)
246        return "\r".join(deleted)
247    ###)
248
249
250InitializeClass(WAeUPTool)
Note: See TracBrowser for help on using the repository browser.