Changes to templates to include e-mail as a link
[biacv.git] / biacv_exporter.py
index d027e71..1edb0e0 100644 (file)
@@ -4,11 +4,14 @@
 # document fields.
 
 import string
+import codecs
 import os.path
 
 class BiaCVExporter:
        def __init__ (self):
                self.data = {}
+               self.exporter_name = ""
+               self.export_filter = ""
 
        # set the document data
        def set_data (self, data):
@@ -20,6 +23,9 @@ class BiaCVExporter:
                # fill education data template bit
                str_education = self._get_education ()
 
+               # fill the profile highlight template bit
+               str_profile = self._get_profile ()
+
                # fill the professional history template bit
                str_profession = self._get_profession ()
 
@@ -34,6 +40,7 @@ class BiaCVExporter:
 
                # fill the main template
                str_main = self._get_main (
+                                               str_profile,
                                                str_education,
                                                str_profession,
                                                str_shorttermobjectives,
@@ -42,12 +49,12 @@ class BiaCVExporter:
                                                str_languages)
 
                # write to export file
-               file (self.file_output, "w").write (str_main)
+               codecs.open (self.file_output, "w", "utf-8").write (str_main)
 
        # fill up the main template
-       def _get_main (self, education, profession, shortterm, longterm, skills, languages):
+       def _get_main (self, profile, education, profession, shortterm, longterm, skills, languages):
                # main template
-               tpl_main = string.Template (file (self.fil_main, "r").read ())
+               tpl_main = string.Template (codecs.open (self.fil_main, "r", "utf-8").read ())
 
                if self.data["maritalstatus"] is True:
                        str_marital = self.lang_strings[3]
@@ -63,6 +70,7 @@ class BiaCVExporter:
                                                        lastname = self.data["lastname"],
                                                        dateofbirth = self.data["dateofbirth"],
                                                        maritalstatus = str_marital,
+                                                       profile = profile,
                                                        shortterm = shortterm,
                                                        longterm = longterm,
                                                        skills = skills,
@@ -84,9 +92,23 @@ class BiaCVExporter:
 
                return str_main
 
+       # get the profile highlights list
+       def _get_profile (self):
+               tpl_profile = string.Template (codecs.open (self.fil_profile, "r", "utf-8").read ())
+
+               lst_profile = []
+               # loop through each item
+               for item in self.data["profile"]:
+                       str_profile = tpl_profile.safe_substitute (
+                                               profile_item = item
+                                       )
+                       lst_profile.append (str_profile)
+
+               return u'\n'.join (lst_profile)
+
        # get the language list
        def _get_languages (self):
-               tpl_language = string.Template (file (self.fil_language, "r").read ())
+               tpl_language = string.Template (codecs.open (self.fil_language, "r", "utf-8").read ())
 
                lst_languages = []
                # loop through each item
@@ -105,12 +127,12 @@ class BiaCVExporter:
                                        )
                        lst_languages.append (str_lang)
 
-               return "\n".join (lst_languages)
+               return u'\n'.join (lst_languages)
 
        # get the skills
        def _get_skills (self):
                # load the template
-               tpl_skill = string.Template (file (self.fil_skills, "r").read ())
+               tpl_skill = string.Template (codecs.open (self.fil_skills, "r", "utf-8").read ())
 
                lst_skills = []
                # loop through each item
@@ -121,12 +143,12 @@ class BiaCVExporter:
                                        )
                        lst_skills.append (str_skill)
 
-               return "\n".join (lst_skills)
+               return u'\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 ())
+               tpl_career = string.Template (codecs.open (self.fil_career, "r", "utf-8").read ())
 
                lst_shorttermcareer = []
                lst_longtermgoals = []
@@ -143,31 +165,35 @@ class BiaCVExporter:
                                        )
                        lst_longtermgoals.append (str_career)
 
-               return "\n".join (lst_shorttermcareer), "\n".join (lst_longtermgoals)
+               return u'\n'.join (lst_shorttermcareer), u'\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 ())
+               tpl_profession = string.Template (codecs.open (self.fil_profession, "r", "utf-8").read ())
 
                lst_profession = []
                # loop through each item
                for item in self.data["professionalhistory"]:
+                       if item["leavedate"] == "":
+                               leavedate_str = self.lang_strings[6]
+                       else:
+                               leavedate_str = item["leavedate"]
                        str_profession = tpl_profession.safe_substitute (
                                        joindate = item["joindate"],
-                                       leavedate= item["leavedate"],
+                                       leavedate = leavedate_str,
                                        organization = item["organization"],
                                        jobtitle = item["jobtitle"],
                                        additionalinfo = item["additionalinfo"]
                                )
                        lst_profession.append (str_profession)
 
-               return "\n".join (lst_profession)
+               return u'\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 ())
+               tpl_education = string.Template (codecs.open (self.fil_education, "r", "utf-8").read ())
 
                lst_education = []
                # loop through each item
@@ -182,10 +208,16 @@ class BiaCVExporter:
                                )
                        lst_education.append (str_education)
 
-               return "\n".join (lst_education)
+               return u'\n'.join (lst_education)
 
        # set the template directory and the files within
        def set_template_directory (self, templatedir):
+               # load the meta file for exporter title and name
+               file_meta = os.path.join (templatedir, "META-INFO")
+               lst_file_meta = (codecs.open (file_meta, 'r', "utf-8").read ()).splitlines ()
+               self.exporter_name = lst_file_meta[0]
+               self.export_filter = lst_file_meta[1]
+
                # set the template file names
 
                # main document template
@@ -200,9 +232,14 @@ class BiaCVExporter:
                self.fil_skills = os.path.join (templatedir, "skill_bit.tpl")
                # languages learned bit
                self.fil_language = os.path.join (templatedir, "language_bit.tpl")
+               # profile bit
+               self.fil_profile = os.path.join (templatedir, "profile_bit.tpl")
 
                # load language strings
-               self.lang_strings = file (os.path.join (templatedir, "misc_strings.txt"), "r").readlines ()
+               lang_str = codecs.open (os.path.join (templatedir, "misc_strings.txt"), "r", "utf-8").read ()
+
+               self.lang_strings = lang_str.splitlines ()
+
 
        # set the output file
        def set_output (self, output):