Unicode support added for export
[biacv.git] / biacv_exporter.py
index 795deac..8ba3c24 100644 (file)
@@ -4,6 +4,7 @@
 # document fields.
 
 import string
+import codecs
 import os.path
 
 class BiaCVExporter:
@@ -42,12 +43,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):
                # 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]
@@ -73,6 +74,7 @@ class BiaCVExporter:
                                                        area = self.data["area"],
                                                        city = self.data["city"],
                                                        areacode = self.data["areacode"],
+                                                       country = self.data["country"],
                                                        countrycode_landline = self.data["countrycode_landline"],
                                                        landline = self.data["landline"],
                                                        countrycode_mobile = self.data["countrycode_mobile"],
@@ -85,7 +87,7 @@ class BiaCVExporter:
 
        # 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
@@ -109,7 +111,7 @@ class BiaCVExporter:
        # 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
@@ -125,7 +127,7 @@ class BiaCVExporter:
        # 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 = []
@@ -147,14 +149,18 @@ class BiaCVExporter:
        # 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"]
@@ -166,7 +172,7 @@ class BiaCVExporter:
        # 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
@@ -201,7 +207,9 @@ class BiaCVExporter:
                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 ()
+               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):