source: WAeUP_SRP/trunk/WAeUPTool.py @ 1151

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

ask for email and password

  • Property svn:keywords set to Id
File size: 8.7 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 1151 2006-12-29 22:05:53Z joachim $
20"""The WAeUPTool.
[828]21
22$Id: WAeUPTool.py 1151 2006-12-29 22:05:53Z joachim $
[197]23"""
24
25from AccessControl import ClassSecurityInfo
[828]26from Acquisition import aq_inner
27from Acquisition import aq_parent
28from Globals import DTMLFile
29from Globals import InitializeClass
30from OFS.SimpleItem import SimpleItem
[197]31
[828]32from Products.CMFCore.ActionProviderBase import ActionProviderBase
33from Products.CMFCore.permissions import View
34from Products.ZCatalog.ZCatalog import ZCatalog
35from Products.CMFCore.permissions import ModifyPortalContent
[197]36from Products.CMFCore.utils import UniqueObject
[1151]37from Students import makeCertificateCode
38import logging
[197]39
[1151]40
[828]41class WAeUPTool(UniqueObject, SimpleItem, ActionProviderBase):
[197]42    """WAeUP tool"""
43
[828]44    id = 'waeup_tool'
[197]45    meta_type = 'WAeUP Tool'
[828]46    _actions = ()
[197]47
48    security = ClassSecurityInfo()
[828]49    security.declareObjectProtected(View)
[197]50
[828]51    manage_options = ( ActionProviderBase.manage_options
52                     + SimpleItem.manage_options
53                     )
54
[1151]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    ###)
[828]66
[1151]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') ###(
[828]185    def getAccommodationInfo(self,bed):
186        """return Accommodation Info"""
187        info = {}
188        hall,block,room,letter = bed.split('_')
189        res = ZCatalog.searchResults(self.portal_catalog,portal_type="AccoHall",id=hall)
190        if res and len(res) == 1:
191            hall_brain = res[0]
192            hall_doc = hall_brain.getObject().getContent()
193        else:
194            return info
195        info['hall_title'] = hall_brain.Title
196        info['maintenance_code'] = hall_doc.maintenance_code
197        res = ZCatalog.searchResults(self.portal_catalog,portal_type="ScratchCardBatch")
198        batch_doc = None
199        for brain in res:
200            if brain.id.startswith(info['maintenance_code']):
201                batch_doc = brain.getObject().getContent()
202                break
203        if batch_doc is None:
204            info['maintenance_fee'] = None
205        else:
206            info['maintenance_fee'] = batch_doc.cost
207        return info
[1151]208    ###)
[828]209
[1151]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   
232
[828]233InitializeClass(WAeUPTool)
Note: See TracBrowser for help on using the repository browser.