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 professional history template bit
25 str_profession
= self
._get
_profession
()
27 # fill the short term objective and long term goals template bit
28 str_shorttermobjectives
, str_longtermgoals
= self
._get
_career
()
30 # fill the skills template bit
31 str_skills
= self
._get
_skills
()
33 # fill the language template bit
34 str_languages
= self
._get
_languages
()
36 # fill the main template
37 str_main
= self
._get
_main
(
40 str_shorttermobjectives
,
45 # write to export file
46 codecs
.open (self
.file_output
, "w", "utf-8").write (str_main
)
48 # fill up the main template
49 def _get_main (self
, education
, profession
, shortterm
, longterm
, skills
, languages
):
51 tpl_main
= string
.Template (codecs
.open (self
.fil_main
, "r", "utf-8").read ())
53 if self
.data
["maritalstatus"] is True:
54 str_marital
= self
.lang_strings
[3]
55 elif self
.data
["maritalstatus"] is False:
56 str_marital
= self
.lang_strings
[4]
58 str_marital
= self
.lang_strings
[5]
60 str_main
= tpl_main
.safe_substitute (
61 title
= self
.data
["title"],
62 nametitle
= self
.data
["nametitle"],
63 firstname
= self
.data
["firstname"],
64 lastname
= self
.data
["lastname"],
65 dateofbirth
= self
.data
["dateofbirth"],
66 maritalstatus
= str_marital
,
67 shortterm
= shortterm
,
70 education
= education
,
71 profession
= profession
,
72 languages
= languages
,
73 street
= self
.data
["street"],
74 area
= self
.data
["area"],
75 city
= self
.data
["city"],
76 areacode
= self
.data
["areacode"],
77 country
= self
.data
["country"],
78 countrycode_landline
= self
.data
["countrycode_landline"],
79 landline
= self
.data
["landline"],
80 countrycode_mobile
= self
.data
["countrycode_mobile"],
81 mobile
= self
.data
["mobile"],
82 email
= self
.data
["email"],
83 additionalinformation
= self
.data
["additionalinformation"]
88 # get the language list
89 def _get_languages (self
):
90 tpl_language
= string
.Template (codecs
.open (self
.fil_language
, "r", "utf-8").read ())
93 # loop through each item
94 for item
in self
.data
["languagesknown"]:
98 if item
["canspeak"] is True: str_canspeak
= self
.lang_strings
[0]
99 if item
["canreadwrite"] is True: str_canreadwrite
= self
.lang_strings
[1]
100 if item
["isproficient"] is True: str_proficient
= self
.lang_strings
[2]
101 str_lang
= tpl_language
.safe_substitute (
102 language
= item
["language"],
103 canspeak
= str_canspeak
,
104 canreadwrite
= str_canreadwrite
,
105 proficient
= str_proficient
107 lst_languages
.append (str_lang
)
109 return "\n".join (lst_languages
)
112 def _get_skills (self
):
114 tpl_skill
= string
.Template (codecs
.open (self
.fil_skills
, "r", "utf-8").read ())
117 # loop through each item
118 for item
in self
.data
["skillsets"]:
119 str_skill
= tpl_skill
.safe_substitute (
120 skilltitle
= item
["skilltitle"],
121 skilldesc
= item
["skilldesc"]
123 lst_skills
.append (str_skill
)
125 return "\n".join (lst_skills
)
127 # get short term career objectives
128 def _get_career (self
):
130 tpl_career
= string
.Template (codecs
.open (self
.fil_career
, "r", "utf-8").read ())
132 lst_shorttermcareer
= []
133 lst_longtermgoals
= []
134 # loop through each item
135 for item
in self
.data
["shorttermobjectives"]:
136 str_career
= tpl_career
.safe_substitute (
137 careerobjective_item
= item
139 lst_shorttermcareer
.append (str_career
)
141 for item
in self
.data
["longtermgoals"]:
142 str_career
= tpl_career
.safe_substitute (
143 careerobjective_item
= item
145 lst_longtermgoals
.append (str_career
)
147 return "\n".join (lst_shorttermcareer
), "\n".join (lst_longtermgoals
)
149 # fill the professional history template
150 def _get_profession (self
):
152 tpl_profession
= string
.Template (codecs
.open (self
.fil_profession
, "r", "utf-8").read ())
155 # loop through each item
156 for item
in self
.data
["professionalhistory"]:
157 if item
["leavedate"] == "":
158 leavedate_str
= self
.lang_strings
[6]
160 leavedate_str
= item
["leavedate"]
161 str_profession
= tpl_profession
.safe_substitute (
162 joindate
= item
["joindate"],
163 leavedate
= leavedate_str
,
164 organization
= item
["organization"],
165 jobtitle
= item
["jobtitle"],
166 additionalinfo
= item
["additionalinfo"]
168 lst_profession
.append (str_profession
)
170 return "\n".join (lst_profession
)
172 # fill the education template
173 def _get_education (self
):
175 tpl_education
= string
.Template (codecs
.open (self
.fil_education
, "r", "utf-8").read ())
178 # loop through each item
179 for item
in self
.data
["educationalqualifications"]:
180 str_education
= tpl_education
.safe_substitute (
181 degree
= item
["degree"],
182 graduation
= item
["graduation"],
183 institution
= item
["institution"],
184 university
= item
["university"],
185 grade
= item
["grade"],
186 percentage
= item
["percentage"]
188 lst_education
.append (str_education
)
190 return "\n".join (lst_education
)
192 # set the template directory and the files within
193 def set_template_directory (self
, templatedir
):
194 # set the template file names
196 # main document template
197 self
.fil_main
= os
.path
.join (templatedir
, "main.tpl")
198 # education qualification bit
199 self
.fil_education
= os
.path
.join (templatedir
, "education_bit.tpl")
200 # profession history bit
201 self
.fil_profession
= os
.path
.join (templatedir
, "profession_bit.tpl")
203 self
.fil_career
= os
.path
.join (templatedir
, "career_bit.tpl")
205 self
.fil_skills
= os
.path
.join (templatedir
, "skill_bit.tpl")
206 # languages learned bit
207 self
.fil_language
= os
.path
.join (templatedir
, "language_bit.tpl")
209 # load language strings
210 lang_str
= codecs
.open (os
.path
.join (templatedir
, "misc_strings.txt"), "r", "utf-8").read ()
212 self
.lang_strings
= lang_str
.splitlines ()
214 # set the output file
215 def set_output (self
, output
):
216 self
.file_output
= output