# together the template "bits" into a single document and filling in the
# document fields.
-import string.Template
+import string
+import os.path
class BiaCVExporter:
def __init__ (self):
# document data
self.data = data
+ # export function
+ def export (self):
+ # fill education data template bit
+ str_education = self._get_education ()
+
+ # fill the professional history template bit
+ str_profession = self._get_profession ()
+
+ # fill the short term objective and long term goals template bit
+ str_shorttermobjectives, str_longtermgoals = self._get_career ()
+
+ # fill the skills template bit
+ str_skills = self._get_skills ()
+
+ # fill the language template bit
+ str_languages = self._get_languages ()
+
+ # fill the main template
+ str_main = self._get_main (
+ str_education,
+ str_profession,
+ str_shorttermobjectives,
+ str_longtermgoals,
+ str_skills,
+ str_languages)
+
+ # write to export file
+ file (self.file_output, "w").write (str_main)
+
+ # fill up the main template
+ def _get_main (self, education, profession, shortterm, longterm, skills, languages):
+ # main template
+ tpl_main = string.Template (file (self.fil_main, "r").read ())
+
+ if self.data["maritalstatus"] is True:
+ str_marital = self.lang_strings[3]
+ elif self.data["maritalstatus"] is False:
+ str_marital = self.lang_strings[4]
+ else:
+ str_marital = self.lang_strings[5]
+
+ str_main = tpl_main.safe_substitute (
+ title = self.data["title"],
+ nametitle = self.data["nametitle"],
+ firstname = self.data["firstname"],
+ lastname = self.data["lastname"],
+ dateofbirth = self.data["dateofbirth"],
+ maritalstatus = str_marital,
+ shortterm = shortterm,
+ longterm = longterm,
+ skills = skills,
+ education = education,
+ profession = profession,
+ languages = languages,
+ street = self.data["street"],
+ area = self.data["area"],
+ city = self.data["city"],
+ areacode = self.data["areacode"],
+ countrycode_landline = self.data["countrycode_landline"],
+ landline = self.data["landline"],
+ countrycode_mobile = self.data["countrycode_mobile"],
+ mobile = self.data["mobile"],
+ email = self.data["email"],
+ additionalinformation = self.data["additionalinformation"]
+ )
+
+ return str_main
+
+ # get the language list
+ def _get_languages (self):
+ tpl_language = string.Template (file (self.fil_language, "r").read ())
+
+ lst_languages = []
+ # loop through each item
+ for item in self.data["languagesknown"]:
+ str_canspeak = ""
+ str_canreadwrite = ""
+ str_proficient = ""
+ if item["canspeak"] is True: str_canspeak = self.lang_strings[0]
+ if item["canreadwrite"] is True: str_canreadwrite = self.lang_strings[1]
+ if item["isproficient"] is True: str_proficient = self.lang_strings[2]
+ str_lang = tpl_language.safe_substitute (
+ language = item["language"],
+ canspeak = str_canspeak,
+ canreadwrite = str_canreadwrite,
+ proficient = str_proficient
+ )
+ lst_languages.append (str_lang)
+
+ return "\n".join (lst_languages)
+
+ # get the skills
+ def _get_skills (self):
+ # load the template
+ tpl_skill = string.Template (file (self.fil_skills, "r").read ())
+
+ lst_skills = []
+ # loop through each item
+ for item in self.data["skillsets"]:
+ str_skill = tpl_skill.safe_substitute (
+ skilltitle = item["skilltitle"],
+ skilldesc = item["skilldesc"]
+ )
+ lst_skills.append (str_skill)
+
+ return "\n".join (lst_skills)
+
+ # get short term career objectives
+ def _get_career (self):
+ # load the template
+ tpl_career = string.Template (file (self.fil_career, "r").read ())
+
+ lst_shorttermcareer = []
+ lst_longtermgoals = []
+ # loop through each item
+ for item in self.data["shorttermobjectives"]:
+ str_career = tpl_career.safe_substitute (
+ careerobjective_item = item
+ )
+ lst_shorttermcareer.append (str_career)
+
+ for item in self.data["longtermgoals"]:
+ str_career = tpl_career.safe_substitute (
+ careerobjective_item = item
+ )
+ lst_longtermgoals.append (str_career)
+
+ return "\n".join (lst_shorttermcareer), "\n".join (lst_longtermgoals)
+
+ # fill the professional history template
+ def _get_profession (self):
+ # load the template
+ tpl_profession = string.Template (file (self.fil_profession, "r").read ())
+
+ lst_profession = []
+ # loop through each item
+ for item in self.data["professionalhistory"]:
+ str_profession = tpl_profession.safe_substitute (
+ joindate = item["joindate"],
+ leavedate= item["leavedate"],
+ organization = item["organization"],
+ jobtitle = item["jobtitle"],
+ additionalinfo = item["additionalinfo"]
+ )
+ lst_profession.append (str_profession)
+
+ return "\n".join (lst_profession)
+
+ # fill the education template
+ def _get_education (self):
+ # load the template
+ tpl_education = string.Template (file (self.fil_education, "r").read ())
+
+ lst_education = []
+ # loop through each item
+ for item in self.data["educationalqualifications"]:
+ str_education = tpl_education.safe_substitute (
+ degree = item["degree"],
+ graduation = item["graduation"],
+ institution = item["institution"],
+ university = item["university"],
+ grade = item["grade"],
+ percentage = item["percentage"]
+ )
+ lst_education.append (str_education)
+
+ return "\n".join (lst_education)
+
# set the template directory and the files within
def set_template_directory (self, templatedir):
# set the template file names
# languages learned bit
self.fil_language = os.path.join (templatedir, "language_bit.tpl")
+ # load language strings
+ self.lang_strings = file (os.path.join (templatedir, "misc_strings.txt"), "r").readlines ()
+
# set the output file
def set_output (self, output):
self.file_output = output