source: WAeUP_SRP/trunk/WAeUPTool.py @ 1168

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

session result checking made work on demo server

  • Property svn:keywords set to Id
File size: 9.2 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 1160 2006-12-30 21:39:19Z henrik $
20"""The WAeUPTool.
21
22$Id: WAeUPTool.py 1160 2006-12-30 21:39:19Z henrik $
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,'close',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,'close',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        personal.getContent().edit(mapping=dp)
165        clearance.getContent().edit(mapping=dc)
166        catd = {}
167        catd['id'] = sid
168        catd['entry_mode']= da['entry_mode']
169        catd['matric_no'] = matric_no
170        catd['jamb_reg_no'] = da['jamb_reg_no']
171        catd['name'] = "%(firstname)s %(middlename)s %(lastname)s" % dp 
172        catd['sex'] = dp['sex']
173        catd['level'] = level
174        if certificate_brain:
175            cpath = certificate_brain.getPath().split('/')
176            catd['faculty'] = cpath[-4]
177            catd['department'] = cpath[-3]
178            catd['course'] = certcode
179        self.students_catalog.modifyRecord(**catd)
180        #
181        # Study Course
182        #
183        student_obj.invokeFactory('StudentStudyCourse','study_course')
184        studycourse = student_obj.study_course
185        self.portal_workflow.doActionFor(studycourse,'open',dest_container=studycourse)
186        dsc = {}
187        dsc['study_course'] = certcode
188        studycourse.getContent().edit(mapping=dsc)
189        #
190        # Level
191        #
192##        l = getattr(studycourse,level,None)
193##        if l is None:
194##            studycourse.invokeFactory('StudentStudyLevel', level)
195##            l = getattr(studycourse, level)
196##            self.portal_workflow.doActionFor(l,'open',dest_container=l)
197##            l.getContent().edit(mapping={'Title': "Level %s" % level})
198
199    security.declarePublic('getAccommodationInfo') ###(
200    def getAccommodationInfo(self,bed):
201        """return Accommodation Info"""
202        info = {}
203        hall,block,room,letter = bed.split('_')
204        res = ZCatalog.searchResults(self.portal_catalog,portal_type="AccoHall",id=hall)
205        if res and len(res) == 1:
206            hall_brain = res[0]
207            hall_doc = hall_brain.getObject().getContent()
208        else:
209            return info
210        info['hall_title'] = hall_brain.Title
211        info['maintenance_code'] = hall_doc.maintenance_code
212        res = ZCatalog.searchResults(self.portal_catalog,portal_type="ScratchCardBatch")
213        batch_doc = None
214        for brain in res:
215            if brain.id.startswith(info['maintenance_code']):
216                batch_doc = brain.getObject().getContent()
217                break
218        if batch_doc is None:
219            info['maintenance_fee'] = None
220        else:
221            info['maintenance_fee'] = batch_doc.cost
222        return info
223    ###)
224
225    security.declareProtected(ModifyPortalContent,'deleteAllCourses') ###(
226    def deleteAllCourses(self,department="All"):
227        ''' delete the courses'''
228        pm = self.portal_membership
229        member = pm.getAuthenticatedMember()
230
231        if str(member) not in ("henrik","joachim"):
232            return "not possible"
233        if department == "All":
234            res = self.portal_catalog({'meta_type': 'Department'})
235        if len(res) < 1:
236            return "No Departments found"
237
238        deleted = []
239        for dep in res:
240            cf = dep.getObject().courses
241            if cf:
242                cf.manage_delObjects(ids=cf.objectIds())
243                deleted.append("deleted Courses in %s" % dep.getId)
244        return "\r".join(deleted)
245    ###)
246
247
248InitializeClass(WAeUPTool)
Note: See TracBrowser for help on using the repository browser.