Added Profile highlights as an additional field
[biacv.git] / biacv_exporter.py
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
4 # document fields.
5
6 import string
7 import codecs
8 import os.path
9
10 class BiaCVExporter:
11 def __init__ (self):
12 self.data = {}
13
14 # set the document data
15 def set_data (self, data):
16 # document data
17 self.data = data
18
19 # export function
20 def export (self):
21 # fill education data template bit
22 str_education = self._get_education ()
23
24 # fill the profile highlight template bit
25 str_profile = self._get_profile ()
26
27 # fill the professional history template bit
28 str_profession = self._get_profession ()
29
30 # fill the short term objective and long term goals template bit
31 str_shorttermobjectives, str_longtermgoals = self._get_career ()
32
33 # fill the skills template bit
34 str_skills = self._get_skills ()
35
36 # fill the language template bit
37 str_languages = self._get_languages ()
38
39 # fill the main template
40 str_main = self._get_main (
41 str_profile,
42 str_education,
43 str_profession,
44 str_shorttermobjectives,
45 str_longtermgoals,
46 str_skills,
47 str_languages)
48
49 # write to export file
50 codecs.open (self.file_output, "w", "utf-8").write (str_main)
51
52 # fill up the main template
53 def _get_main (self, profile, education, profession, shortterm, longterm, skills, languages):
54 # main template
55 tpl_main = string.Template (codecs.open (self.fil_main, "r", "utf-8").read ())
56
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]
61 else:
62 str_marital = self.lang_strings[5]
63
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,
71 profile = profile,
72 shortterm = shortterm,
73 longterm = longterm,
74 skills = skills,
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"]
89 )
90
91 return str_main
92
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 ())
96
97 lst_profile = []
98 # loop through each item
99 for item in self.data["profile"]:
100 str_profile = tpl_profile.safe_substitute (
101 profile_item = item
102 )
103 lst_profile.append (str_profile)
104
105 return u'\n'.join (lst_profile)
106
107 # get the language list
108 def _get_languages (self):
109 tpl_language = string.Template (codecs.open (self.fil_language, "r", "utf-8").read ())
110
111 lst_languages = []
112 # loop through each item
113 for item in self.data["languagesknown"]:
114 str_canspeak = ""
115 str_canreadwrite = ""
116 str_proficient = ""
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
125 )
126 lst_languages.append (str_lang)
127
128 return u'\n'.join (lst_languages)
129
130 # get the skills
131 def _get_skills (self):
132 # load the template
133 tpl_skill = string.Template (codecs.open (self.fil_skills, "r", "utf-8").read ())
134
135 lst_skills = []
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"]
141 )
142 lst_skills.append (str_skill)
143
144 return u'\n'.join (lst_skills)
145
146 # get short term career objectives
147 def _get_career (self):
148 # load the template
149 tpl_career = string.Template (codecs.open (self.fil_career, "r", "utf-8").read ())
150
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
157 )
158 lst_shorttermcareer.append (str_career)
159
160 for item in self.data["longtermgoals"]:
161 str_career = tpl_career.safe_substitute (
162 careerobjective_item = item
163 )
164 lst_longtermgoals.append (str_career)
165
166 return u'\n'.join (lst_shorttermcareer), u'\n'.join (lst_longtermgoals)
167
168 # fill the professional history template
169 def _get_profession (self):
170 # load the template
171 tpl_profession = string.Template (codecs.open (self.fil_profession, "r", "utf-8").read ())
172
173 lst_profession = []
174 # loop through each item
175 for item in self.data["professionalhistory"]:
176 if item["leavedate"] == "":
177 leavedate_str = self.lang_strings[6]
178 else:
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"]
186 )
187 lst_profession.append (str_profession)
188
189 return u'\n'.join (lst_profession)
190
191 # fill the education template
192 def _get_education (self):
193 # load the template
194 tpl_education = string.Template (codecs.open (self.fil_education, "r", "utf-8").read ())
195
196 lst_education = []
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"]
206 )
207 lst_education.append (str_education)
208
209 return u'\n'.join (lst_education)
210
211 # set the template directory and the files within
212 def set_template_directory (self, templatedir):
213 # set the template file names
214
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")
221 # career list bit
222 self.fil_career = os.path.join (templatedir, "career_bit.tpl")
223 # skills bit
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")
227 # profile bit
228 self.fil_profile = os.path.join (templatedir, "profile_bit.tpl")
229
230 # load language strings
231 lang_str = codecs.open (os.path.join (templatedir, "misc_strings.txt"), "r", "utf-8").read ()
232
233 self.lang_strings = lang_str.splitlines ()
234
235 # set the output file
236 def set_output (self, output):
237 self.file_output = output