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
14 # set the document data
15 def set_data (self
, data
):
21 # fill education data template bit
22 str_education
= self
._get
_education
()
24 # fill the profile highlight template bit
25 str_profile
= self
._get
_profile
()
27 # fill the professional history template bit
28 str_profession
= self
._get
_profession
()
30 # fill the short term objective and long term goals template bit
31 str_shorttermobjectives
, str_longtermgoals
= self
._get
_career
()
33 # fill the skills template bit
34 str_skills
= self
._get
_skills
()
36 # fill the language template bit
37 str_languages
= self
._get
_languages
()
39 # fill the main template
40 str_main
= self
._get
_main
(
44 str_shorttermobjectives
,
49 # write to export file
50 codecs
.open (self
.file_output
, "w", "utf-8").write (str_main
)
52 # fill up the main template
53 def _get_main (self
, profile
, education
, profession
, shortterm
, longterm
, skills
, languages
):
55 tpl_main
= string
.Template (codecs
.open (self
.fil_main
, "r", "utf-8").read ())
57 if self
.data
["maritalstatus"] is True:
58 str_marital
= self
.lang_strings
[3]
59 elif self
.data
["maritalstatus"] is False:
60 str_marital
= self
.lang_strings
[4]
62 str_marital
= self
.lang_strings
[5]
64 str_main
= tpl_main
.safe_substitute (
65 title
= self
.data
["title"],
66 nametitle
= self
.data
["nametitle"],
67 firstname
= self
.data
["firstname"],
68 lastname
= self
.data
["lastname"],
69 dateofbirth
= self
.data
["dateofbirth"],
70 maritalstatus
= str_marital
,
72 shortterm
= shortterm
,
75 education
= education
,
76 profession
= profession
,
77 languages
= languages
,
78 street
= self
.data
["street"],
79 area
= self
.data
["area"],
80 city
= self
.data
["city"],
81 areacode
= self
.data
["areacode"],
82 country
= self
.data
["country"],
83 countrycode_landline
= self
.data
["countrycode_landline"],
84 landline
= self
.data
["landline"],
85 countrycode_mobile
= self
.data
["countrycode_mobile"],
86 mobile
= self
.data
["mobile"],
87 email
= self
.data
["email"],
88 additionalinformation
= self
.data
["additionalinformation"]
93 # get the profile highlights list
94 def _get_profile (self
):
95 tpl_profile
= string
.Template (codecs
.open (self
.fil_profile
, "r", "utf-8").read ())
98 # loop through each item
99 for item
in self
.data
["profile"]:
100 str_profile
= tpl_profile
.safe_substitute (
103 lst_profile
.append (str_profile
)
105 return u
'\n'.join (lst_profile
)
107 # get the language list
108 def _get_languages (self
):
109 tpl_language
= string
.Template (codecs
.open (self
.fil_language
, "r", "utf-8").read ())
112 # loop through each item
113 for item
in self
.data
["languagesknown"]:
115 str_canreadwrite
= ""
117 if item
["canspeak"] is True: str_canspeak
= self
.lang_strings
[0]
118 if item
["canreadwrite"] is True: str_canreadwrite
= self
.lang_strings
[1]
119 if item
["isproficient"] is True: str_proficient
= self
.lang_strings
[2]
120 str_lang
= tpl_language
.safe_substitute (
121 language
= item
["language"],
122 canspeak
= str_canspeak
,
123 canreadwrite
= str_canreadwrite
,
124 proficient
= str_proficient
126 lst_languages
.append (str_lang
)
128 return u
'\n'.join (lst_languages
)
131 def _get_skills (self
):
133 tpl_skill
= string
.Template (codecs
.open (self
.fil_skills
, "r", "utf-8").read ())
136 # loop through each item
137 for item
in self
.data
["skillsets"]:
138 str_skill
= tpl_skill
.safe_substitute (
139 skilltitle
= item
["skilltitle"],
140 skilldesc
= item
["skilldesc"]
142 lst_skills
.append (str_skill
)
144 return u
'\n'.join (lst_skills
)
146 # get short term career objectives
147 def _get_career (self
):
149 tpl_career
= string
.Template (codecs
.open (self
.fil_career
, "r", "utf-8").read ())
151 lst_shorttermcareer
= []
152 lst_longtermgoals
= []
153 # loop through each item
154 for item
in self
.data
["shorttermobjectives"]:
155 str_career
= tpl_career
.safe_substitute (
156 careerobjective_item
= item
158 lst_shorttermcareer
.append (str_career
)
160 for item
in self
.data
["longtermgoals"]:
161 str_career
= tpl_career
.safe_substitute (
162 careerobjective_item
= item
164 lst_longtermgoals
.append (str_career
)
166 return u
'\n'.join (lst_shorttermcareer
), u
'\n'.join (lst_longtermgoals
)
168 # fill the professional history template
169 def _get_profession (self
):
171 tpl_profession
= string
.Template (codecs
.open (self
.fil_profession
, "r", "utf-8").read ())
174 # loop through each item
175 for item
in self
.data
["professionalhistory"]:
176 if item
["leavedate"] == "":
177 leavedate_str
= self
.lang_strings
[6]
179 leavedate_str
= item
["leavedate"]
180 str_profession
= tpl_profession
.safe_substitute (
181 joindate
= item
["joindate"],
182 leavedate
= leavedate_str
,
183 organization
= item
["organization"],
184 jobtitle
= item
["jobtitle"],
185 additionalinfo
= item
["additionalinfo"]
187 lst_profession
.append (str_profession
)
189 return u
'\n'.join (lst_profession
)
191 # fill the education template
192 def _get_education (self
):
194 tpl_education
= string
.Template (codecs
.open (self
.fil_education
, "r", "utf-8").read ())
197 # loop through each item
198 for item
in self
.data
["educationalqualifications"]:
199 str_education
= tpl_education
.safe_substitute (
200 degree
= item
["degree"],
201 graduation
= item
["graduation"],
202 institution
= item
["institution"],
203 university
= item
["university"],
204 grade
= item
["grade"],
205 percentage
= item
["percentage"]
207 lst_education
.append (str_education
)
209 return u
'\n'.join (lst_education
)
211 # set the template directory and the files within
212 def set_template_directory (self
, templatedir
):
213 # set the template file names
215 # main document template
216 self
.fil_main
= os
.path
.join (templatedir
, "main.tpl")
217 # education qualification bit
218 self
.fil_education
= os
.path
.join (templatedir
, "education_bit.tpl")
219 # profession history bit
220 self
.fil_profession
= os
.path
.join (templatedir
, "profession_bit.tpl")
222 self
.fil_career
= os
.path
.join (templatedir
, "career_bit.tpl")
224 self
.fil_skills
= os
.path
.join (templatedir
, "skill_bit.tpl")
225 # languages learned bit
226 self
.fil_language
= os
.path
.join (templatedir
, "language_bit.tpl")
228 self
.fil_profile
= os
.path
.join (templatedir
, "profile_bit.tpl")
230 # load language strings
231 lang_str
= codecs
.open (os
.path
.join (templatedir
, "misc_strings.txt"), "r", "utf-8").read ()
233 self
.lang_strings
= lang_str
.splitlines ()
235 # set the output file
236 def set_output (self
, output
):
237 self
.file_output
= output