1 # class to export data in BiaCV native format to any external format as
2 # specified by a template set. The final document is produced by putting
3 # together the template "bits" into a single document and filling in the
13 self
.exporter_name
= ""
14 self
.export_filter
= ""
16 # set the document data
17 def set_data (self
, data
):
23 # fill education data template bit
24 str_education
= self
._get
_education
()
26 # fill the profile highlight template bit
27 str_profile
= self
._get
_profile
()
29 # fill the professional history template bit
30 str_profession
= self
._get
_profession
()
32 # fill the short term objective and long term goals template bit
33 str_shorttermobjectives
, str_longtermgoals
= self
._get
_career
()
35 # fill the skills template bit
36 str_skills
= self
._get
_skills
()
38 # fill the language template bit
39 str_languages
= self
._get
_languages
()
41 # fill the main template
42 str_main
= self
._get
_main
(
46 str_shorttermobjectives
,
51 # write to export file
52 codecs
.open (self
.file_output
, "w", "utf-8").write (str_main
)
54 # fill up the main template
55 def _get_main (self
, profile
, education
, profession
, shortterm
, longterm
, skills
, languages
):
57 tpl_main
= string
.Template (codecs
.open (self
.fil_main
, "r", "utf-8").read ())
59 if self
.data
["maritalstatus"] is True:
60 str_marital
= self
.lang_strings
[3]
61 elif self
.data
["maritalstatus"] is False:
62 str_marital
= self
.lang_strings
[4]
64 str_marital
= self
.lang_strings
[5]
66 str_main
= tpl_main
.safe_substitute (
67 title
= self
.data
["title"],
68 nametitle
= self
.data
["nametitle"],
69 firstname
= self
.data
["firstname"],
70 lastname
= self
.data
["lastname"],
71 dateofbirth
= self
.data
["dateofbirth"],
72 maritalstatus
= str_marital
,
74 shortterm
= shortterm
,
77 education
= education
,
78 profession
= profession
,
79 languages
= languages
,
80 street
= self
.data
["street"],
81 area
= self
.data
["area"],
82 city
= self
.data
["city"],
83 areacode
= self
.data
["areacode"],
84 country
= self
.data
["country"],
85 countrycode_landline
= self
.data
["countrycode_landline"],
86 landline
= self
.data
["landline"],
87 countrycode_mobile
= self
.data
["countrycode_mobile"],
88 mobile
= self
.data
["mobile"],
89 email
= self
.data
["email"],
90 additionalinformation
= self
.data
["additionalinformation"]
95 # get the profile highlights list
96 def _get_profile (self
):
97 tpl_profile
= string
.Template (codecs
.open (self
.fil_profile
, "r", "utf-8").read ())
100 # loop through each item
101 for item
in self
.data
["profile"]:
102 str_profile
= tpl_profile
.safe_substitute (
105 lst_profile
.append (str_profile
)
107 return u
'\n'.join (lst_profile
)
109 # get the language list
110 def _get_languages (self
):
111 tpl_language
= string
.Template (codecs
.open (self
.fil_language
, "r", "utf-8").read ())
114 # loop through each item
115 for item
in self
.data
["languagesknown"]:
117 str_canreadwrite
= ""
119 if item
["canspeak"] is True: str_canspeak
= self
.lang_strings
[0]
120 if item
["canreadwrite"] is True: str_canreadwrite
= self
.lang_strings
[1]
121 if item
["isproficient"] is True: str_proficient
= self
.lang_strings
[2]
122 str_lang
= tpl_language
.safe_substitute (
123 language
= item
["language"],
124 canspeak
= str_canspeak
,
125 canreadwrite
= str_canreadwrite
,
126 proficient
= str_proficient
128 lst_languages
.append (str_lang
)
130 return u
'\n'.join (lst_languages
)
133 def _get_skills (self
):
135 tpl_skill
= string
.Template (codecs
.open (self
.fil_skills
, "r", "utf-8").read ())
138 # loop through each item
139 for item
in self
.data
["skillsets"]:
140 str_skill
= tpl_skill
.safe_substitute (
141 skilltitle
= item
["skilltitle"],
142 skilldesc
= item
["skilldesc"]
144 lst_skills
.append (str_skill
)
146 return u
'\n'.join (lst_skills
)
148 # get short term career objectives
149 def _get_career (self
):
151 tpl_career
= string
.Template (codecs
.open (self
.fil_career
, "r", "utf-8").read ())
153 lst_shorttermcareer
= []
154 lst_longtermgoals
= []
155 # loop through each item
156 for item
in self
.data
["shorttermobjectives"]:
157 str_career
= tpl_career
.safe_substitute (
158 careerobjective_item
= item
160 lst_shorttermcareer
.append (str_career
)
162 for item
in self
.data
["longtermgoals"]:
163 str_career
= tpl_career
.safe_substitute (
164 careerobjective_item
= item
166 lst_longtermgoals
.append (str_career
)
168 return u
'\n'.join (lst_shorttermcareer
), u
'\n'.join (lst_longtermgoals
)
170 # fill the professional history template
171 def _get_profession (self
):
173 tpl_profession
= string
.Template (codecs
.open (self
.fil_profession
, "r", "utf-8").read ())
176 # loop through each item
177 for item
in self
.data
["professionalhistory"]:
178 if item
["leavedate"] == "":
179 leavedate_str
= self
.lang_strings
[6]
181 leavedate_str
= item
["leavedate"]
182 str_profession
= tpl_profession
.safe_substitute (
183 joindate
= item
["joindate"],
184 leavedate
= leavedate_str
,
185 organization
= item
["organization"],
186 jobtitle
= item
["jobtitle"],
187 additionalinfo
= item
["additionalinfo"]
189 lst_profession
.append (str_profession
)
191 return u
'\n'.join (lst_profession
)
193 # fill the education template
194 def _get_education (self
):
196 tpl_education
= string
.Template (codecs
.open (self
.fil_education
, "r", "utf-8").read ())
199 # loop through each item
200 for item
in self
.data
["educationalqualifications"]:
201 str_education
= tpl_education
.safe_substitute (
202 degree
= item
["degree"],
203 graduation
= item
["graduation"],
204 institution
= item
["institution"],
205 university
= item
["university"],
206 grade
= item
["grade"],
207 percentage
= item
["percentage"]
209 lst_education
.append (str_education
)
211 return u
'\n'.join (lst_education
)
213 # set the template directory and the files within
214 def set_template_directory (self
, templatedir
):
215 # load the meta file for exporter title and name
216 file_meta
= os
.path
.join (templatedir
, "META-INFO")
217 lst_file_meta
= (codecs
.open (file_meta
, 'r', "utf-8").read ()).splitlines ()
218 self
.exporter_name
= lst_file_meta
[0]
219 self
.export_filter
= lst_file_meta
[1]
221 # set the template file names
223 # main document template
224 self
.fil_main
= os
.path
.join (templatedir
, "main.tpl")
225 # education qualification bit
226 self
.fil_education
= os
.path
.join (templatedir
, "education_bit.tpl")
227 # profession history bit
228 self
.fil_profession
= os
.path
.join (templatedir
, "profession_bit.tpl")
230 self
.fil_career
= os
.path
.join (templatedir
, "career_bit.tpl")
232 self
.fil_skills
= os
.path
.join (templatedir
, "skill_bit.tpl")
233 # languages learned bit
234 self
.fil_language
= os
.path
.join (templatedir
, "language_bit.tpl")
236 self
.fil_profile
= os
.path
.join (templatedir
, "profile_bit.tpl")
238 # load language strings
239 lang_str
= codecs
.open (os
.path
.join (templatedir
, "misc_strings.txt"), "r", "utf-8").read ()
241 self
.lang_strings
= lang_str
.splitlines ()
244 # set the output file
245 def set_output (self
, output
):
246 self
.file_output
= output