# -*- coding: utf-8 # Copyright 2005 by Meelis Mets from Products.Archetypes.public import BaseSchema, Schema from Products.Archetypes.public import StringField, LinesField from Products.Archetypes.public import LinesWidget, TextAreaWidget, IdWidget, StringWidget, SelectionWidget from Products.Archetypes.public import OrderedBaseFolder, registerType from Globals import InitializeClass from Products.CMFCore.utils import getToolByName from Permissions import * from types import UnicodeType from AccessControl import ClassSecurityInfo, Unauthorized from config import PROJECT_NAME, SUBJECTS schema = BaseSchema class SchoolDataBase(OrderedBaseFolder): """ SchoolDataBase product """ meta_type = "SchoolDataBase" archetype_name = "SchoolDataBase" global_allow = 0 filter_content_types = True allowed_content_types = ('School',) security = ClassSecurityInfo() schema = schema actions = ( { 'id':'view', 'name':'View', 'action':'string:${object_url}/schooldatabase_view', 'permissions': ('View SchoolDataBase',), }, ) def manage_afterAdd(self,item,container): """sets permissions""" self.manage_permission('Manage Portal', ('Manager','School') ,1) self.manage_permission('View', ('Manager','School') ,1) security.declareProtected('Manage Portal', 'viewSchoolDataBase') def viewSchoolDataBase(self): """view School Database permission""" pass def updateSchoolDataBase(self): """ gets data from ehis """ import urllib2 new_list = ['aaa'] school_list = [] id_list = [] count=0 c=0 size='50' #school list for value in ['1', '51','101','151','201','251','301','351','401','451','501','551','601','651','701','751','801','851']: if count>16: size='34' count=count+1 url='https://eh-jas.hm.ee/avalik/oas/Otsing.uix?event=goto&source=tabel&value='+value+'&size='+size f = urllib2.urlopen(url) html = f.read() list = html.split('') list.pop(0) for item in list: name='' id='' reg='' splitter=item.split('') reg=splitter[0] if reg not in ['','0']: if len(splitter)>1: splitter=splitter[1].split('') id=splitter[0] if len(splitter)>1: splitter=splitter[1].split('<') name=splitter[0] print name if name!='' and id!='': id_list.append({'name':name,'id':id,'reg':reg}) #school data for info in id_list: c=c+1 if c>110 and c<130: print info['name'] url='https://eh-jas.hm.ee'+info['id'] f = urllib2.urlopen(url) html = f.read() html = html.replace('','') html = html.replace('','') html = html.replace('','') html = html.replace('','') html = html.replace('','') html = html.replace('','') html = html.replace('','') data = html.split('') if len(data)>1: data.pop(0) data.pop(0) new_data = [] for d in data: d=d.split('') da=d[0].split('">') if len(da)>1: da=da[1] else: da=da[0] db=d[1].split('') if len(db)>1: db=db[1].split('') db=db[0] else: db='Tyhi' if da!='': new_data.append({'name':da,'value':db}) school_list.append(new_data) #school abjects for schoolInfo in school_list: typestool = getToolByName(self, 'portal_types') puf_type = getattr(typestool, 'School', None) if not puf_type: return 0 puf_type.global_allow = 1 id = schoolInfo[0]['value'] if hasattr(self, id): pass #this school object is already in database else: id = self.invokeFactory("School", id=id, title=schoolInfo[1]['value'], schooltype=schoolInfo[4]['value'], address=schoolInfo[12]['value'], location=schoolInfo[11]['value'], email=schoolInfo[9]['value'], www=schoolInfo[10]['value'], phone=schoolInfo[7]['value'], ) puf_type.global_allow = 0 registerType(SchoolDataBase, PROJECT_NAME) class School(OrderedBaseFolder): """ School """ meta_type = "School" archetype_name = "School" exclude_from_nav = True global_allow = 0 filter_content_types = True allowed_content_types = () security = ClassSecurityInfo() schema = schema + Schema(( StringField('title', widget=StringWidget( label="School name", description="", label_msgid='label_school_name', description_msgid='description_school_name', i18n_domain="eportfolio"), ), StringField('schooltype', widget=StringWidget( label="School type", description="", label_msgid='label_school_type', description_msgid='description_school_type', i18n_domain="eportfolio"), ), StringField('address', widget=StringWidget( label="Address", description="", label_msgid='label_school_address', description_msgid='description_school_address', i18n_domain="eportfolio"), ), StringField('location', widget=StringWidget( label="Location", description="", label_msgid='label_school_location', description_msgid='description_school_location', i18n_domain="eportfolio"), ), StringField('headmaster', widget=StringWidget( label="Headmaster", description="", label_msgid='label_school_headmaster', description_msgid='description_school_headmaster', i18n_domain="eportfolio"), ), StringField('email', widget=StringWidget( label="E-mail", description="", label_msgid='label_school_email', description_msgid='description_school_email', i18n_domain="eportfolio"), ), StringField('www', widget=StringWidget( label="WWW", description="", label_msgid='label_school_www', description_msgid='description_school_www', i18n_domain="eportfolio"), ), StringField('phone', widget=StringWidget( label="Phone", description="", label_msgid='label_school_phone', description_msgid='description_school_phone', i18n_domain="eportfolio"), ), StringField('studinglanguage', widget=StringWidget( label="Language", description="", label_msgid='label_school_language', description_msgid='description_school_language', i18n_domain="eportfolio"), ), StringField('nrofstudents', widget=StringWidget( label="Number of students", description="", label_msgid='label_school_nrofstudents', description_msgid='description_school_nrofstudents', i18n_domain="eportfolio"), ), )) actions = ( { 'id':'view', 'name':'View', 'action':'string:${object_url}/base_view', 'permissions': ('View',), }, { 'id':'owner', 'name':'Owner', 'action':'string:${object_url}/school_owner', 'permissions': ('Manage Portal',), }, { 'id':'subjects', 'name':'Subjects', 'action':'string:${object_url}/school_subjects', 'permissions': ('Manage Portal',), }, ) def __init__(self, id): self.id = id self.subjects = [] self.setSubjects() def manage_afterAdd(self,item,container): """sets permissions""" self.manage_permission('Manage Portal', ('Manager','School') ,1) self.manage_permission('View', ('Manager','School') ,1) def setMasterUserForSchool(self, REQUEST): """ sets master user for school """ user = REQUEST.get('school_owner') school = self.id pm = getToolByName(self, 'portal_membership') member = pm.getMemberById(user) member.school = school def setSubjects(self): """subjects""" self.subjects = [] for subject in SUBJECTS: self.subjects.append({'name':subject,'nr':0}) self._p_changed = 1 def getSubjects(self): """get subjects""" return self.subjects def saveSubjects(self, REQUEST): """save subjects""" i = 0 for subject in self.subjects: nr=REQUEST.get('subject_'+str(i)) self.subjects[i]['nr'] = nr i = i + 1 self._p_changed = 1 return 1 registerType(School, PROJECT_NAME)