# -*- 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 BaseContent, registerType from Globals import InitializeClass from Products.CMFCore.utils import getToolByName #from Products.reportlab.pdfgen import canvas #from Products.reportlab.lib.units import cm from AccessControl import ClassSecurityInfo, Unauthorized from config import PROJECT_NAME schema = BaseSchema class Profile(BaseContent): """ Profile product """ meta_type = "Profile" archetype_name = "Profile" global_allow = 0 exclude_from_nav = True allowed_content_types = [] security = ClassSecurityInfo() schema = schema actions = ( { 'id':'view', 'name':'View', 'action':'string:${object_url}/cv_view', 'permissions': ('View',), }, { 'id':'desired_employment', 'name':'Desired employment', 'action':'string:${object_url}/desired_edit', 'permissions': ('Modify portal content',), }, { 'id':'workexperience', 'name':'Work experience', 'action':'string:${object_url}/workexp_edit', 'permissions': ('Modify portal content',), }, { 'id':'education', 'name':'Education', 'action':'string:${object_url}/education_edit', 'permissions': ('Modify portal content',), }, { 'id':'languages', 'name':'Languages', 'action':'string:${object_url}/languages_edit', 'permissions': ('Modify portal content',), }, { 'id':'skills', 'name':'Skills', 'action':'string:${object_url}/skills_edit', 'permissions': ('Modify portal content',), }, { 'id':'additional', 'name':'Additional', 'action':'string:${object_url}/additional_edit', 'permissions': ('Modify portal content',), }, { 'id':'edit', 'name':'Edit', 'action':'string:${object_url}/profile_view', 'permissions': ('Modify portal content',), }, { 'id':'metadata', 'name':'Properties', 'action':'string:${object_url}/base_metadata', 'permissions': ('Manage Portal',), }, ) def __init__(self, id): self.id = id self.desired = '' self.workExperiences = [] self.education = [] self.languages = {'mothertongue': '', 'other': []} self.skills = {'social' : '', 'organisational' : '', 'qualification' : '', 'technical' : '', 'computer' : '', 'artistic' : '', 'other' : '', 'driving' : ''} self.additional = {'information' : '', 'annexes' : ''} self.largeIcon = "profile.gif" def getLargeIcon(self): """ returns large icon name """ return self.largeIcon security.declarePublic('getMemberInfo') def getMemberInfo(self, memberId=None): """ Return 'harmless' Memberinfo of any member, such as Full name, Location, etc """ mt = getToolByName(self, "portal_membership") if not memberId: member = self.getAuthenticatedMember() else: member = mt.getMemberById(memberId) if member is None: return None #print mt.getPersonalPortrait(memberId) try: photodata = mt.getPersonalPortrait(memberId).data except AttributeError: photodata='' memberinfo = { 'fullname' : member.getProperty('fullname'), 'description' : member.getProperty('description'), 'location' : member.getProperty('location'), 'language' : member.getProperty('language'), 'home_page' : member.getProperty('home_page'), 'address1' : member.getProperty('address1'), 'town' : member.getProperty('town'), 'county' : member.getProperty('county'), 'country' :member.getProperty('country'), 'tel' : member.getProperty('tel'), 'mobile' : member.getProperty('mobile'), 'nationality' : member.getProperty('nationality'), 'email' : member.getProperty('email'), 'birthday' : member.getProperty('birthday'), 'gender' : member.getProperty('gender'), 'postcode' : member.getProperty('postcode'), 'username' : member.getUserName(), 'photodata' : photodata } return memberinfo security.declareProtected('Modify portal content', 'showContent') def showContent(self): """ permission to show content """ return 1 security.declareProtected('Modify portal content', 'saveWorkExperience') def saveWorkExperience(self, REQUEST): """ Save Work Experience """ dateBegin = {'day': REQUEST.get('from_d', ''), 'month': REQUEST.get('from_m', ''), 'year': REQUEST.get('from_y', '')} dateEnd = {'day': REQUEST.get('to_d', ''), 'month': REQUEST.get('to_m', ''), 'year': REQUEST.get('to_y', '')} position = REQUEST.get('position') activities = REQUEST.get('activities') employer = REQUEST.get('employer') sector = REQUEST.get('sector') workExperience = {'dateBegin' : dateBegin, 'dateEnd' : dateEnd, 'position' : position, 'activities' : activities, 'employer' : employer, 'sector' : sector} i = int(REQUEST.get('edit')) if(i==0): self.workExperiences.append(workExperience) else: self.workExperiences[i-1]=workExperience self._p_changed = 1 security.declareProtected('Modify portal content', 'removeWorkExperiences') def removeWorkExperiences(self, REQUEST): """ Remove WorkExperiences """ delete = int(REQUEST.get('id'))-1 self.workExperiences.pop(delete) self._p_changed = 1 security.declareProtected('View', 'getWorkExperiences') def getWorkExperiences(self): """ get work experiences """ return self.workExperiences security.declareProtected('View', 'getEducation') def getEducation(self): """ get education """ return self.education security.declareProtected('Modify portal content', 'saveEducation') def saveEducation(self, REQUEST): """ Save Education """ dateBegin = {'day': REQUEST.get('from_d', ''), 'month': REQUEST.get('from_m', ''), 'year': REQUEST.get('from_y', '')} dateEnd = {'day': REQUEST.get('to_d', ''), 'month': REQUEST.get('to_m', ''), 'year': REQUEST.get('to_y', '')} qualification = REQUEST.get('qualification') skills = REQUEST.get('skills') organisation = REQUEST.get('organisation') level = REQUEST.get('level') edu = {'dateBegin' : dateBegin, 'dateEnd' : dateEnd, 'qualification' : qualification, 'skills' : skills, 'organisation' : organisation, 'level' : level} i = int(REQUEST.get('edit')) if(i==0): self.education.append(edu) else: self.education[i-1]=edu self._p_changed = 1 security.declareProtected('Modify portal content', 'removeEducation') def removeEducation(self, REQUEST): """ Remove Education """ delete = int(REQUEST.get('id'))-1 self.education.pop(delete) self._p_changed = 1 security.declareProtected('View', 'getLanguages') def getLanguages(self): """ get Languages """ return self.languages security.declareProtected('Modify portal content', 'saveLanguages') def saveLanguages(self, REQUEST): """ Save Languages """ mothertongue = REQUEST.get('mothertongue') language = REQUEST.get('language', '') listening = REQUEST.get('listening', '') reading = REQUEST.get('reading', '') interaction = REQUEST.get('interaction', '') production = REQUEST.get('production', '') writing = REQUEST.get('writing', '') lan = {'language' : language, 'listening' : listening, 'reading' : reading, 'interaction' : interaction, 'production' : production, 'writing' : writing} i = int(REQUEST.get('edit')) if(i==0): if(language!=''): self.languages['other'].append(lan) else: self.languages['other'][i-1] = lan self.languages['mothertongue'] = mothertongue self._p_changed = 1 security.declareProtected('Modify portal content', 'removeLanguages') def removeLanguages(self, REQUEST): """ Remove Languages """ delete = int(REQUEST.get('id'))-1 self.languages['other'].pop(delete) self._p_changed = 1 security.declareProtected('View', 'getSkills') def getSkills(self): """ get skills """ return self.skills security.declareProtected('Modify portal content', 'saveSkills') def saveSkills(self, REQUEST): """ Save Skills """ self.skills['social'] = REQUEST.get('social') self.skills['organisational'] = REQUEST.get('organisational') self.skills['technical'] = REQUEST.get('technical') self.skills['computer'] = REQUEST.get('computer') self.skills['artistic'] = REQUEST.get('artistic') self.skills['other'] = REQUEST.get('other') self.skills['driving'] = REQUEST.get('driving') self._p_changed = 1 security.declareProtected('View', 'getAdditional') def getAdditional(self): """ get additional """ return self.additional security.declareProtected('Modify portal content', 'saveAdditional') def saveAdditional(self, REQUEST): """ Save Additional """ self.additional['information'] = REQUEST.get('information') self.additional['annexes'] = REQUEST.get('annexes') self._p_changed = 1 security.declareProtected('View', 'getDesired') def getDesired(self): """ get Desired employment """ return self.desired security.declareProtected('Modify portal content', 'saveDesired') def saveDesired(self, REQUEST): """ Save Desired employment """ self.desired = REQUEST.get('desired') self._p_changed = 1 def arrayToString(self, array): """ array to string splittable by \n """ string = '' for value in array: string = string+value+'\n' return string def arrayToBr(self, array): """ array to string splittable by
""" string = '' for value in array: string = string+value+'
' return string def getHTML(self): """ HTML """ a = str(self.cv_view()) b = a.split("") begin = "\n\n\nCV\n\n\n\n" end = "\n" html = begin + b[1] + end return html def getPDF(self): html = self.getHTML() return html # def hello(c): # """ hello """ # c = canvas.Canvas("hello.pdf") # c.drawString(9*cm, 22*cm, "Hello World!") # c.showPage() # c.save() def arrayToStr(self, array): """ array to string for xml""" string = '' array_len = len(array) for i in range(0, array_len): if i != array_len - 1: string += array[i]+'\n' else: string += array[i] return string def createXML(self, REQUEST): import time xml = '\n' xml += '\n' xml += '\n' if len(name) > 1: xml += '' for i in range(0, len(name)-1): xml += name[i] xml += '\n' xml += ''+name[-1]+'\n' xml += '\n' xml += '
' if owner['address1'] != '': xml += owner['address1']+' ' if owner['town'] != '': xml += owner['town']+' ' if owner['county'] != '': xml += owner['county']+' ' if owner['country'] != '': xml += owner['country']+' ' if owner['postcode'] != '': xml += owner['postcode'] xml += '
\n' if owner['tel'] != '': xml += ''+owner['tel']+'\n' #xml += '\n' if owner['mobile'] != '': xml += ''+owner['mobile']+'\n' if owner['email'] != '': xml += ''+owner['email']+'\n' xml += '
\n' xml += '\n' bdate = owner['birthday'] try: bdate = time.strptime(bdate, "%d/%m/%Y") xml += ''+str(bdate[0])+'-'+str(bdate[1])+'-'+str(bdate[2])+'\n' except ValueError: pass if owner['gender'] != '': xml += ''+owner['gender'][:1]+'\n' if owner['nationality'] != '': xml += ''+owner['nationality']+'\n' xml += '\n' data = str(owner['photodata']) if data != '': import binascii xml += ''+binascii.b2a_base64(data)+'\n' xml += '\n' if self.getDesired() != []: xml += ''+self.arrayToStr(self.getDesired())+'\n' workExperiences = self.getWorkExperiences() if workExperiences != []: xml += '\n' #print self.getWorkExperiences() for work in workExperiences: xml += '\n' wbegin = work['dateBegin'] wEnd = work['dateEnd'] xml += '\n' xml += '\n' if wbegin['year'] != '' and wbegin['year'] != None: xml += ''+wbegin['year']+'\n' if wbegin['month'] != '' and wbegin['month'] != None: xml += '--'+wbegin['month']+'\n' if wbegin['day'] != '' and wbegin['day'] != None: xml += '---'+wbegin['day']+'\n' xml += '\n' xml += '\n' if wEnd['year'] != '' and wEnd['year'] != None: xml += ''+wEnd['year']+'\n' if wEnd['month'] != '' and wEnd['month'] != None: xml += '--'+wEnd['month']+'\n' if wEnd['day'] != '' and wEnd['day'] != None: xml += '---'+wEnd['day']+'\n' xml += '\n' xml += '\n' if work['position'] != '': xml += ''+work['position']+'\n' if work['activities'] != []: xml += ''+self.arrayToStr(work['activities'])+'\n' if work['employer'] != []: xml += ''+self.arrayToStr(work['employer'])+'\n' if work['sector'] != '': xml += ''+work['sector']+'\n' xml += '\n' xml += '\n' education = self.getEducation() if education != []: xml += '\n' for e in education: xml += '\n' begin = e['dateBegin'] end = e['dateEnd'] xml += '\n' xml += '\n' if begin['year'] != '': xml += ''+e['dateBegin']['year']+'\n' if begin['month'] != '': xml += '--'+e['dateBegin']['month']+'\n' if begin['day'] != '': xml += '---'+e['dateBegin']['day']+'\n' xml += '\n' xml += '\n' if end['year'] != '': xml += ''+e['dateEnd']['year']+'\n' if end['month'] != '': xml += '--'+e['dateEnd']['month']+'\n' if end['day'] != '': xml += '---'+e['dateEnd']['day']+'\n' xml += '\n' xml += '\n' if e['qualification'] != '': xml += ''+e['qualification']+'\n' if e['skills'] != []: xml += ''+self.arrayToStr(e['skills'])+'\n' if e['organisation'] != '': xml += ''+self.arrayToStr(e['organisation'])+'\n' if e['level'] != '': xml += ''+e['level']+'\n' xml += '\n' xml += '\n' #print self.getLanguages() if self.getLanguages != {}: xml += '\n' if self.getLanguages()['mothertongue'] != '': xml += '\n' xml += ''+self.getLanguages()['mothertongue']+'\n' xml += '\n' languages = self.getLanguages()['other'] if languages != []: for lang in languages: if lang['language'] != '': xml += '\n' xml += ''+lang['language']+'\n' xml += '\n' if lang['listening'] != '' and lang['listening'] != None: xml += ''+lang['listening']+'\n' if lang['reading'] != '' and lang['reading'] != None: xml += ''+lang['reading']+'\n' if lang['interaction'] != '' and lang['interaction'] != None: xml += ''+lang['interaction']+'\n' if lang['production'] != '' and lang['production'] != None: xml += ''+lang['production']+'\n' if lang['writing'] != '' and lang['writing'] != None: xml += ''+lang['writing']+'\n' xml += '\n' xml += '\n' xml += '\n' skills = self.getSkills() #print 'skills:', skills if self.getSkills() != {}: xml += '\n' if skills['social'] != '': xml += ''+self.arrayToStr(skills['social'])+'\n' if skills['organisational'] != '': xml += ''+self.arrayToStr(skills['organisational'])+'\n' if skills['technical'] != '': xml += ''+self.arrayToStr(skills['technical'])+'\n' if skills['computer'] != '': xml += ''+self.arrayToStr(skills['computer'])+'\n' if skills['artistic'] != '': xml += ''+self.arrayToStr(skills['artistic'])+'\n' if skills['other'] != '': xml += ''+self.arrayToStr(skills['other'])+'\n' if skills['driving'] != '': xml += ''+self.arrayToStr(skills['driving'])+'\n' xml += '\n' adds = self.getAdditional() #print 'adds:', adds if adds != {}: xml += '\n' if adds['information'] != '': xml += ''+self.arrayToStr(adds['information'])+'\n' if adds['annexes'] != '': xml += ''+self.arrayToStr(adds['annexes'])+'\n' xml += '\n' xml += '
\n' return xml def saveDocument(self, REQUEST): """ """ xml = self.createXML(REQUEST) from SOAPpy import SOAPProxy import binascii from SOAPpy import faultType import re url = "http://europass.cedefop.europa.eu/instrumentssrv/services/Instruments" server = SOAPProxy(url) namespace="urn:instruments" filetype = REQUEST.get('doc_type', '') if filetype == '': return REQUEST.RESPONSE.redirect('save_document') locale = REQUEST.get('lang', 'et_EE') if filetype == 'xml': self.REQUEST.RESPONSE.setHeader('content-type', 'text/xml') self.REQUEST.RESPONSE.setHeader('Content-disposition','attachment; filename=cv.xml') return xml xml = xml.decode('utf-8') try: base64res = server._ns(namespace).getDocumentFromCV(document=xml,filetype=filetype,locale=locale) except faultType: cm = re.compile('(.*?)', re.S) photo = cm.search(xml).group(1) xml = xml.replace(photo, '') base64res = server._ns(namespace).getDocumentFromCV(document=xml,filetype=filetype,locale=locale) self.REQUEST.RESPONSE.setHeader('content-type', 'text/'+filetype) self.REQUEST.RESPONSE.setHeader('Content-disposition','attachment; filename=cv.'+filetype) return binascii.unhexlify(base64res) registerType(Profile, PROJECT_NAME)