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 # set the document data
14 def set_data (self
, data
):
20 # fill education data template bit
21 str_education
= self
._get
_education
()
23 # fill the professional history template bit
24 str_profession
= self
._get
_profession
()
26 # fill the short term objective and long term goals template bit
27 str_shorttermobjectives
, str_longtermgoals
= self
._get
_career
()
29 # fill the skills template bit
30 str_skills
= self
._get
_skills
()
32 # fill the language template bit
33 str_languages
= self
._get
_languages
()
35 # fill the main template
36 str_main
= self
._get
_main
(
39 str_shorttermobjectives
,
44 # write to export file
45 file (self
.file_output
, "w").write (str_main
)
47 # fill up the main template
48 def _get_main (self
, education
, profession
, shortterm
, longterm
, skills
, languages
):
50 tpl_main
= string
.Template (file (self
.fil_main
, "r").read ())
52 if self
.data
["maritalstatus"] is True:
53 str_marital
= self
.lang_strings
[3]
54 elif self
.data
["maritalstatus"] is False:
55 str_marital
= self
.lang_strings
[4]
57 str_marital
= self
.lang_strings
[5]
59 str_main
= tpl_main
.safe_substitute (
60 title
= self
.data
["title"],
61 nametitle
= self
.data
["nametitle"],
62 firstname
= self
.data
["firstname"],
63 lastname
= self
.data
["lastname"],
64 dateofbirth
= self
.data
["dateofbirth"],
65 maritalstatus
= str_marital
,
66 shortterm
= shortterm
,
69 education
= education
,
70 profession
= profession
,
71 languages
= languages
,
72 street
= self
.data
["street"],
73 area
= self
.data
["area"],
74 city
= self
.data
["city"],
75 areacode
= self
.data
["areacode"],
76 countrycode_landline
= self
.data
["countrycode_landline"],
77 landline
= self
.data
["landline"],
78 countrycode_mobile
= self
.data
["countrycode_mobile"],
79 mobile
= self
.data
["mobile"],
80 email
= self
.data
["email"],
81 additionalinformation
= self
.data
["additionalinformation"]
86 # get the language list
87 def _get_languages (self
):
88 tpl_language
= string
.Template (file (self
.fil_language
, "r").read ())
91 # loop through each item
92 for item
in self
.data
["languagesknown"]:
96 if item
["canspeak"] is True: str_canspeak
= self
.lang_strings
[0]
97 if item
["canreadwrite"] is True: str_canreadwrite
= self
.lang_strings
[1]
98 if item
["isproficient"] is True: str_proficient
= self
.lang_strings
[2]
99 str_lang
= tpl_language
.safe_substitute (
100 language
= item
["language"],
101 canspeak
= str_canspeak
,
102 canreadwrite
= str_canreadwrite
,
103 proficient
= str_proficient
105 lst_languages
.append (str_lang
)
107 return "\n".join (lst_languages
)
110 def _get_skills (self
):
112 tpl_skill
= string
.Template (file (self
.fil_skills
, "r").read ())
115 # loop through each item
116 for item
in self
.data
["skillsets"]:
117 str_skill
= tpl_skill
.safe_substitute (
118 skilltitle
= item
["skilltitle"],
119 skilldesc
= item
["skilldesc"]
121 lst_skills
.append (str_skill
)
123 return "\n".join (lst_skills
)
125 # get short term career objectives
126 def _get_career (self
):
128 tpl_career
= string
.Template (file (self
.fil_career
, "r").read ())
130 lst_shorttermcareer
= []
131 lst_longtermgoals
= []
132 # loop through each item
133 for item
in self
.data
["shorttermobjectives"]:
134 str_career
= tpl_career
.safe_substitute (
135 careerobjective_item
= item
137 lst_shorttermcareer
.append (str_career
)
139 for item
in self
.data
["longtermgoals"]:
140 str_career
= tpl_career
.safe_substitute (
141 careerobjective_item
= item
143 lst_longtermgoals
.append (str_career
)
145 return "\n".join (lst_shorttermcareer
), "\n".join (lst_longtermgoals
)
147 # fill the professional history template
148 def _get_profession (self
):
150 tpl_profession
= string
.Template (file (self
.fil_profession
, "r").read ())
153 # loop through each item
154 for item
in self
.data
["professionalhistory"]:
155 str_profession
= tpl_profession
.safe_substitute (
156 joindate
= item
["joindate"],
157 leavedate
= item
["leavedate"],
158 organization
= item
["organization"],
159 jobtitle
= item
["jobtitle"],
160 additionalinfo
= item
["additionalinfo"]
162 lst_profession
.append (str_profession
)
164 return "\n".join (lst_profession
)
166 # fill the education template
167 def _get_education (self
):
169 tpl_education
= string
.Template (file (self
.fil_education
, "r").read ())
172 # loop through each item
173 for item
in self
.data
["educationalqualifications"]:
174 str_education
= tpl_education
.safe_substitute (
175 degree
= item
["degree"],
176 graduation
= item
["graduation"],
177 institution
= item
["institution"],
178 university
= item
["university"],
179 grade
= item
["grade"],
180 percentage
= item
["percentage"]
182 lst_education
.append (str_education
)
184 return "\n".join (lst_education
)
186 # set the template directory and the files within
187 def set_template_directory (self
, templatedir
):
188 # set the template file names
190 # main document template
191 self
.fil_main
= os
.path
.join (templatedir
, "main.tpl")
192 # education qualification bit
193 self
.fil_education
= os
.path
.join (templatedir
, "education_bit.tpl")
194 # profession history bit
195 self
.fil_profession
= os
.path
.join (templatedir
, "profession_bit.tpl")
197 self
.fil_career
= os
.path
.join (templatedir
, "career_bit.tpl")
199 self
.fil_skills
= os
.path
.join (templatedir
, "skill_bit.tpl")
200 # languages learned bit
201 self
.fil_language
= os
.path
.join (templatedir
, "language_bit.tpl")
203 # load language strings
204 self
.lang_strings
= file (os
.path
.join (templatedir
, "misc_strings.txt"), "r").readlines ()
206 # set the output file
207 def set_output (self
, output
):
208 self
.file_output
= output