d027e71e2725d29d6b7d61a9ba4f1adf61a4c3d9
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 country
= self
.data
["country"],
77 countrycode_landline
= self
.data
["countrycode_landline"],
78 landline
= self
.data
["landline"],
79 countrycode_mobile
= self
.data
["countrycode_mobile"],
80 mobile
= self
.data
["mobile"],
81 email
= self
.data
["email"],
82 additionalinformation
= self
.data
["additionalinformation"]
87 # get the language list
88 def _get_languages (self
):
89 tpl_language
= string
.Template (file (self
.fil_language
, "r").read ())
92 # loop through each item
93 for item
in self
.data
["languagesknown"]:
97 if item
["canspeak"] is True: str_canspeak
= self
.lang_strings
[0]
98 if item
["canreadwrite"] is True: str_canreadwrite
= self
.lang_strings
[1]
99 if item
["isproficient"] is True: str_proficient
= self
.lang_strings
[2]
100 str_lang
= tpl_language
.safe_substitute (
101 language
= item
["language"],
102 canspeak
= str_canspeak
,
103 canreadwrite
= str_canreadwrite
,
104 proficient
= str_proficient
106 lst_languages
.append (str_lang
)
108 return "\n".join (lst_languages
)
111 def _get_skills (self
):
113 tpl_skill
= string
.Template (file (self
.fil_skills
, "r").read ())
116 # loop through each item
117 for item
in self
.data
["skillsets"]:
118 str_skill
= tpl_skill
.safe_substitute (
119 skilltitle
= item
["skilltitle"],
120 skilldesc
= item
["skilldesc"]
122 lst_skills
.append (str_skill
)
124 return "\n".join (lst_skills
)
126 # get short term career objectives
127 def _get_career (self
):
129 tpl_career
= string
.Template (file (self
.fil_career
, "r").read ())
131 lst_shorttermcareer
= []
132 lst_longtermgoals
= []
133 # loop through each item
134 for item
in self
.data
["shorttermobjectives"]:
135 str_career
= tpl_career
.safe_substitute (
136 careerobjective_item
= item
138 lst_shorttermcareer
.append (str_career
)
140 for item
in self
.data
["longtermgoals"]:
141 str_career
= tpl_career
.safe_substitute (
142 careerobjective_item
= item
144 lst_longtermgoals
.append (str_career
)
146 return "\n".join (lst_shorttermcareer
), "\n".join (lst_longtermgoals
)
148 # fill the professional history template
149 def _get_profession (self
):
151 tpl_profession
= string
.Template (file (self
.fil_profession
, "r").read ())
154 # loop through each item
155 for item
in self
.data
["professionalhistory"]:
156 str_profession
= tpl_profession
.safe_substitute (
157 joindate
= item
["joindate"],
158 leavedate
= item
["leavedate"],
159 organization
= item
["organization"],
160 jobtitle
= item
["jobtitle"],
161 additionalinfo
= item
["additionalinfo"]
163 lst_profession
.append (str_profession
)
165 return "\n".join (lst_profession
)
167 # fill the education template
168 def _get_education (self
):
170 tpl_education
= string
.Template (file (self
.fil_education
, "r").read ())
173 # loop through each item
174 for item
in self
.data
["educationalqualifications"]:
175 str_education
= tpl_education
.safe_substitute (
176 degree
= item
["degree"],
177 graduation
= item
["graduation"],
178 institution
= item
["institution"],
179 university
= item
["university"],
180 grade
= item
["grade"],
181 percentage
= item
["percentage"]
183 lst_education
.append (str_education
)
185 return "\n".join (lst_education
)
187 # set the template directory and the files within
188 def set_template_directory (self
, templatedir
):
189 # set the template file names
191 # main document template
192 self
.fil_main
= os
.path
.join (templatedir
, "main.tpl")
193 # education qualification bit
194 self
.fil_education
= os
.path
.join (templatedir
, "education_bit.tpl")
195 # profession history bit
196 self
.fil_profession
= os
.path
.join (templatedir
, "profession_bit.tpl")
198 self
.fil_career
= os
.path
.join (templatedir
, "career_bit.tpl")
200 self
.fil_skills
= os
.path
.join (templatedir
, "skill_bit.tpl")
201 # languages learned bit
202 self
.fil_language
= os
.path
.join (templatedir
, "language_bit.tpl")
204 # load language strings
205 self
.lang_strings
= file (os
.path
.join (templatedir
, "misc_strings.txt"), "r").readlines ()
207 # set the output file
208 def set_output (self
, output
):
209 self
.file_output
= output