Added "country" field to personal information tab
[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 os.path
8
9 class BiaCVExporter:
10 def __init__ (self):
11 self.data = {}
12
13 # set the document data
14 def set_data (self, data):
15 # document data
16 self.data = data
17
18 # export function
19 def export (self):
20 # fill education data template bit
21 str_education = self._get_education ()
22
23 # fill the professional history template bit
24 str_profession = self._get_profession ()
25
26 # fill the short term objective and long term goals template bit
27 str_shorttermobjectives, str_longtermgoals = self._get_career ()
28
29 # fill the skills template bit
30 str_skills = self._get_skills ()
31
32 # fill the language template bit
33 str_languages = self._get_languages ()
34
35 # fill the main template
36 str_main = self._get_main (
37 str_education,
38 str_profession,
39 str_shorttermobjectives,
40 str_longtermgoals,
41 str_skills,
42 str_languages)
43
44 # write to export file
45 file (self.file_output, "w").write (str_main)
46
47 # fill up the main template
48 def _get_main (self, education, profession, shortterm, longterm, skills, languages):
49 # main template
50 tpl_main = string.Template (file (self.fil_main, "r").read ())
51
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]
56 else:
57 str_marital = self.lang_strings[5]
58
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,
67 longterm = longterm,
68 skills = skills,
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"]
83 )
84
85 return str_main
86
87 # get the language list
88 def _get_languages (self):
89 tpl_language = string.Template (file (self.fil_language, "r").read ())
90
91 lst_languages = []
92 # loop through each item
93 for item in self.data["languagesknown"]:
94 str_canspeak = ""
95 str_canreadwrite = ""
96 str_proficient = ""
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
105 )
106 lst_languages.append (str_lang)
107
108 return "\n".join (lst_languages)
109
110 # get the skills
111 def _get_skills (self):
112 # load the template
113 tpl_skill = string.Template (file (self.fil_skills, "r").read ())
114
115 lst_skills = []
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"]
121 )
122 lst_skills.append (str_skill)
123
124 return "\n".join (lst_skills)
125
126 # get short term career objectives
127 def _get_career (self):
128 # load the template
129 tpl_career = string.Template (file (self.fil_career, "r").read ())
130
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
137 )
138 lst_shorttermcareer.append (str_career)
139
140 for item in self.data["longtermgoals"]:
141 str_career = tpl_career.safe_substitute (
142 careerobjective_item = item
143 )
144 lst_longtermgoals.append (str_career)
145
146 return "\n".join (lst_shorttermcareer), "\n".join (lst_longtermgoals)
147
148 # fill the professional history template
149 def _get_profession (self):
150 # load the template
151 tpl_profession = string.Template (file (self.fil_profession, "r").read ())
152
153 lst_profession = []
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"]
162 )
163 lst_profession.append (str_profession)
164
165 return "\n".join (lst_profession)
166
167 # fill the education template
168 def _get_education (self):
169 # load the template
170 tpl_education = string.Template (file (self.fil_education, "r").read ())
171
172 lst_education = []
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"]
182 )
183 lst_education.append (str_education)
184
185 return "\n".join (lst_education)
186
187 # set the template directory and the files within
188 def set_template_directory (self, templatedir):
189 # set the template file names
190
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")
197 # career list bit
198 self.fil_career = os.path.join (templatedir, "career_bit.tpl")
199 # skills bit
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")
203
204 # load language strings
205 self.lang_strings = file (os.path.join (templatedir, "misc_strings.txt"), "r").readlines ()
206
207 # set the output file
208 def set_output (self, output):
209 self.file_output = output