source: WAeUP_SRP/trunk/WAeUPTool.py @ 1176

Last change on this file since 1176 was 1174, checked in by Henrik Bettermann, 18 years ago

sessional result view and slip added
names imported into application object

  • Property svn:keywords set to Id
File size: 10.9 KB
RevLine 
[197]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 1174 2007-01-02 11:03:16Z henrik $
[1174]20"""The WAeUP Tool Box.
[197]21"""
22
23from AccessControl import ClassSecurityInfo
[828]24from Acquisition import aq_inner
25from Acquisition import aq_parent
26from Globals import DTMLFile
27from Globals import InitializeClass
28from OFS.SimpleItem import SimpleItem
[197]29
[828]30from Products.CMFCore.ActionProviderBase import ActionProviderBase
31from Products.CMFCore.permissions import View
32from Products.ZCatalog.ZCatalog import ZCatalog
33from Products.CMFCore.permissions import ModifyPortalContent
[197]34from Products.CMFCore.utils import UniqueObject
[1151]35from Students import makeCertificateCode
36import logging
[1170]37import transaction
[197]38
[1151]39
[1171]40
41
[828]42class WAeUPTool(UniqueObject, SimpleItem, ActionProviderBase):
[197]43    """WAeUP tool"""
44
[828]45    id = 'waeup_tool'
[197]46    meta_type = 'WAeUP Tool'
[828]47    _actions = ()
[197]48
49    security = ClassSecurityInfo()
[828]50    security.declareObjectProtected(View)
[197]51
[828]52    manage_options = ( ActionProviderBase.manage_options
53                     + SimpleItem.manage_options
54                     )
55
[1174]56
57
[1151]58    def generateStudentId(self,letter): ###(
59        import random
60        r = random
61        if letter not in ('ABCDEFGIHKLMNOPQRSTUVWXY'):
62            letter= r.choice('ABCDEFGHKLMNPQRSTUVWXY')
63        students = self.portal_url.getPortalObject().campus.students
64        sid = "%c%d" % (letter,r.randint(99999,1000000))
65        while hasattr(students, sid):
66            sid = "%c%d" % (letter,r.randint(99999,1000000))
67        return sid
68    ###)
[828]69
[1170]70    security.declareProtected(ModifyPortalContent,'createOne') ###(
[1171]71    def createOne(self,student_brain,commit=False):
[1170]72        students_folder = self.portal_url.getPortalObject().campus.students
73        sid = self.waeup_tool.generateStudentId('?')
74        students_folder.invokeFactory('Student', sid)
75        student = getattr(students_folder,sid)
76        self.portal_workflow.doActionFor(student,'return')
77        student.manage_setLocalRoles(sid, ['Owner',])
78        matric_no = student_brain.matric_no
79        jamb_reg_no = student_brain.Entryregno
80        self.students_catalog.addRecord(id = sid,
81                                           matric_no = matric_no,
82                                           jamb_reg_no = jamb_reg_no,
83                                           sex = student_brain.Sex == "F",
84                                           name = "%s %s %s" % (student_brain.Firstname,
85                                                                student_brain.Middlename,
86                                                                student_brain.Lastname)
87                                        )
88        if commit:
89            transaction.commit()
90        return sid,jamb_reg_no
91    ###)
92
[1151]93    security.declarePublic('getCertificateBrain') ###(
94    def getCertificateBrain(self,cert_id):
95        "do it"
96        res = ZCatalog.searchResults(self.portal_catalog,
97                                {'portal_type':"Certificate",
98                                      'id': cert_id})
99        if res:
100            return res[0]
101        return None
102    ###)
[1160]103
[1151]104    security.declarePublic('findStudentByMatricelNo') ###(
105    def findStudentByMatricelNo(self,matric_no):
106        "do it"
107        res = ZCatalog.searchResults(self.portal_catalog,
108                                {'portal_type':"StudentClearance",
109                                 'SearchableText': matric_no})
110        if res:
111            return res[0]
112        return None
113    ###)
114
115    security.declarePublic('makeStudentMember') ###(
116    def makeStudentMember(self,sid,password='uNsEt'):
117        """make the student a member"""
118        membership = self.portal_membership
119        membership.addMember(sid,
120                             password ,
121                             roles=('Member',
122                                     'Student',
123                                     ),
124                             domains='',
125                             properties = {'memberareaCreationFlag': False,
126                                           'homeless': True},)
127        member = membership.getMemberById(sid)
128        self.portal_registration.afterAdd(member, sid, password, None)
129        self.manage_setLocalRoles(sid, ['Owner',])
130    ###)
[1160]131
[1151]132    security.declarePublic('makeStudentData') ###(
[1158]133    def makeStudentData(self,student_id,email=None,phone_nr=None):
[1151]134        "create Datastructure for a returning Student"
135        #import pdb;pdb.set_trace()
136        logger = logging.getLogger('Student.CreateData')
137        students_folder = self.portal_url.getPortalObject().campus.students
138        res = self.students_catalog(id=student_id)
139        if res:
140            st = res[0]
141        res = self.returning_import(matric_no = st.matric_no)
142        if res:
[1160]143            student = res[0]
[1158]144        logger.info('"%s", "creating Datastructure"' % student_id)
[1171]145
146        #student should not be allowed to perform this transition
[1174]147        #wftool = self.portal_workflow
148        #wftool.doActionFor(student,'return')
[1171]149
[1151]150        certcode_org = student.Coursemajorcode
151        certcode = makeCertificateCode(certcode_org)
152        certificate_brain = self.getCertificateBrain(certcode)
153        if not certificate_brain:
154            em = 'Certificate %s org-code %s not found\n' % (certcode, certcode_org)
155            logger.info(em)
156        level = student.Level
157        try:
158            int(level)
159        except:
160            em = '"%(matric_no)s","invalid Level","%(Level)s"' % student
161            logger.info(em)
162        matric_no = student.matric_no
163        sid = student_id
164        student_obj = getattr(students_folder,sid)
165        student_obj.invokeFactory('StudentApplication','application')
166        application = student_obj.application
[1169]167        self.portal_workflow.doActionFor(application,'open',dest_container=application)
[1151]168        da = {'Title': 'Application Data'}
169        student_obj.invokeFactory('StudentPersonal','personal')
170        da['jamb_reg_no'] = student.Entryregno
171        da['entry_mode'] = student.Mode_of_Entry
172        personal = student_obj.personal
173        self.portal_workflow.doActionFor(personal,'open',dest_container=personal)
174        dp = {'Title': 'Personal Data'}
175        student_obj.invokeFactory('StudentClearance','clearance')
176        clearance = student_obj.clearance
[1169]177        self.portal_workflow.doActionFor(clearance,'open',dest_container=clearance)
[1151]178        dc = {'Title': 'Clearance/Eligibility Record'}
179        dc['matric_no'] = matric_no
180        state = student.State
181        lga = student.LGA
182        if state and lga:
183            lga =  state + ' / ' + lga
184        else:
185            lga = "None"
[1174]186        da['jamb_lga'] = dc['lga'] = lga
[1173]187        da['app_email'] = dp['email'] = email
188        da['app_mobile'] = dp['phone'] = phone_nr
[1174]189        da['jamb_firstname'] = dp['firstname'] = student.Firstname
190        da['jamb_middlename'] = dp['middlename'] = student.Middlename
191        da['jamb_lastname'] = dp['lastname'] = student.Lastname
192        da['jamb_sex'] = student.Sex
[1151]193        dp['sex'] = student.Sex == 'F'
194        dp['perm_address'] = student.Permanent_Address
195        application.getContent().edit(mapping=da)
[1169]196        self.portal_workflow.doActionFor(application,'close',dest_container=application)
[1151]197        personal.getContent().edit(mapping=dp)
198        clearance.getContent().edit(mapping=dc)
[1169]199        self.portal_workflow.doActionFor(clearance,'close',dest_container=clearance)
[1158]200        catd = {}
201        catd['id'] = sid
202        catd['entry_mode']= da['entry_mode']
203        catd['matric_no'] = matric_no
[1171]204        catd['jamb_reg_no'] = da['jamb_reg_no']
205        catd['name'] = "%(firstname)s %(middlename)s %(lastname)s" % dp
206        catd['sex'] = dp['sex']
207        catd['level'] = level
[1158]208        if certificate_brain:
209            cpath = certificate_brain.getPath().split('/')
[1171]210            catd['faculty'] = cpath[-4]
211            catd['department'] = cpath[-3]
[1158]212            catd['course'] = certcode
213        self.students_catalog.modifyRecord(**catd)
[1151]214        #
215        # Study Course
216        #
217        student_obj.invokeFactory('StudentStudyCourse','study_course')
218        studycourse = student_obj.study_course
219        self.portal_workflow.doActionFor(studycourse,'open',dest_container=studycourse)
220        dsc = {}
221        dsc['study_course'] = certcode
222        studycourse.getContent().edit(mapping=dsc)
223        #
224        # Level
225        #
226##        l = getattr(studycourse,level,None)
227##        if l is None:
228##            studycourse.invokeFactory('StudentStudyLevel', level)
229##            l = getattr(studycourse, level)
230##            self.portal_workflow.doActionFor(l,'open',dest_container=l)
231##            l.getContent().edit(mapping={'Title': "Level %s" % level})
[1160]232
[1151]233    security.declarePublic('getAccommodationInfo') ###(
[828]234    def getAccommodationInfo(self,bed):
235        """return Accommodation Info"""
236        info = {}
237        hall,block,room,letter = bed.split('_')
238        res = ZCatalog.searchResults(self.portal_catalog,portal_type="AccoHall",id=hall)
239        if res and len(res) == 1:
240            hall_brain = res[0]
241            hall_doc = hall_brain.getObject().getContent()
242        else:
243            return info
244        info['hall_title'] = hall_brain.Title
245        info['maintenance_code'] = hall_doc.maintenance_code
246        res = ZCatalog.searchResults(self.portal_catalog,portal_type="ScratchCardBatch")
247        batch_doc = None
248        for brain in res:
249            if brain.id.startswith(info['maintenance_code']):
250                batch_doc = brain.getObject().getContent()
251                break
252        if batch_doc is None:
253            info['maintenance_fee'] = None
254        else:
255            info['maintenance_fee'] = batch_doc.cost
256        return info
[1151]257    ###)
[828]258
[1151]259    security.declareProtected(ModifyPortalContent,'deleteAllCourses') ###(
260    def deleteAllCourses(self,department="All"):
261        ''' delete the courses'''
262        pm = self.portal_membership
263        member = pm.getAuthenticatedMember()
[1160]264
[1151]265        if str(member) not in ("henrik","joachim"):
266            return "not possible"
267        if department == "All":
268            res = self.portal_catalog({'meta_type': 'Department'})
269        if len(res) < 1:
270            return "No Departments found"
[1160]271
[1151]272        deleted = []
273        for dep in res:
274            cf = dep.getObject().courses
275            if cf:
276                cf.manage_delObjects(ids=cf.objectIds())
277                deleted.append("deleted Courses in %s" % dep.getId)
278        return "\r".join(deleted)
[1160]279    ###)
[1151]280
[1160]281
[828]282InitializeClass(WAeUPTool)
Note: See TracBrowser for help on using the repository browser.