From cb541b4d71d0e35448dfbd4e1cb6498e9cf876b7 Mon Sep 17 00:00:00 2001 From: Harishankar Date: Wed, 7 Dec 2011 14:37:45 +0530 Subject: [PATCH] Export functionality completed Export functionality is completed. Also default XHTML export template is completed. --- biacv_exporter.py | 174 ++++++++++++++++++++- biacv_lang.py | 2 + biacv_mainwindow.py | 29 +++- templates/default_xhtml/education_bit.tpl | 2 +- templates/default_xhtml/language_bit.tpl | 2 +- templates/default_xhtml/main.tpl | 7 +- templates/default_xhtml/misc_strings.txt | 6 + templates/default_xhtml/profession_bit.tpl | 4 +- 8 files changed, 217 insertions(+), 9 deletions(-) create mode 100644 templates/default_xhtml/misc_strings.txt diff --git a/biacv_exporter.py b/biacv_exporter.py index 43bc635..795deac 100644 --- a/biacv_exporter.py +++ b/biacv_exporter.py @@ -3,7 +3,8 @@ # 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): @@ -14,6 +15,174 @@ class BiaCVExporter: # 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 @@ -31,6 +200,9 @@ class BiaCVExporter: # 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 diff --git a/biacv_lang.py b/biacv_lang.py index 769ceb1..cbac4ac 100644 --- a/biacv_lang.py +++ b/biacv_lang.py @@ -11,6 +11,8 @@ CONFIRM_DISCARD_SAVE = "There are unsaved changes in current document. Do you wi ERROR_DATE = "There is a problem with the date range selected." SAVE_TITLE = "Save File As" OPEN_TITLE = "Open File" +EXPORT_TITLE = "Export As" +OPEN_TEMPLATE_TITLE = "Choose Export Template directory" ABOUT_TITLE = "About BiaCV" ABOUT_TEXT = """BiaCV - A resume creator/editor diff --git a/biacv_mainwindow.py b/biacv_mainwindow.py index 65ed3fe..0ceebde 100644 --- a/biacv_mainwindow.py +++ b/biacv_mainwindow.py @@ -7,6 +7,7 @@ import sys import biacv_mainwindow_ui as bui import biacv_lang as lang import biacv_data as data +import biacv_exporter as exporter class Biacv_mainwindow (PyQt4.QtGui.QMainWindow, bui.Ui_biacv_mainwindow): def __init__ (self): @@ -37,7 +38,33 @@ class Biacv_mainwindow (PyQt4.QtGui.QMainWindow, bui.Ui_biacv_mainwindow): # on file export - export current document to any external format based on # a template def on_file_export (self): - pass + # get the template directory + templatedir = PyQt4.QtGui.QFileDialog.getExistingDirectory (self, + lang.OPEN_TEMPLATE_TITLE) + if templatedir == "": + return + + # get the output file path + outputfile = PyQt4.QtGui.QFileDialog.getSaveFileName (self, + lang.EXPORT_TITLE) + + if outputfile == "": + return + + # create a new exporter object + exp = exporter.BiaCVExporter () + + # set the document data + exp.set_data (self.get_document_data ().data) + + # set the template directory + exp.set_template_directory (unicode (templatedir.toUtf8(), "utf-8")) + + # set the output file + exp.set_output (unicode (outputfile.toUtf8(), "utf-8")) + + # carry out the export function + exp.export () # function to open a file def on_file_open (self): diff --git a/templates/default_xhtml/education_bit.tpl b/templates/default_xhtml/education_bit.tpl index 8ed3b10..93d3edc 100644 --- a/templates/default_xhtml/education_bit.tpl +++ b/templates/default_xhtml/education_bit.tpl @@ -1,6 +1,6 @@ ${degree} - ${dateofpassing} + ${graduation} ${institution} ${university} ${grade} diff --git a/templates/default_xhtml/language_bit.tpl b/templates/default_xhtml/language_bit.tpl index e633267..4052dbd 100644 --- a/templates/default_xhtml/language_bit.tpl +++ b/templates/default_xhtml/language_bit.tpl @@ -1 +1 @@ -
  • ${language} - ${languagedesc}
  • \ No newline at end of file +
  • ${language}: ${canspeak} ${canreadwrite} ${proficient}
  • \ No newline at end of file diff --git a/templates/default_xhtml/main.tpl b/templates/default_xhtml/main.tpl index 65eda93..09c2aed 100644 --- a/templates/default_xhtml/main.tpl +++ b/templates/default_xhtml/main.tpl @@ -11,13 +11,14 @@ table.education { width: 100% } .education thead { background-color: #eeeeee; } ul { list-style-type: square; } - h1 { text-align: center; font-family: sans-serif; font-size: 210%; color: darkblue; } - h2 { border-bottom: solid; font-family: sans-serif; font-size: 140% } - h3 { font-family: sans-serif; font-size: 120% } + h1 { text-align: center; font-family: sans-serif; font-size: 210%; color: darkblue; font-variant: small-caps; } + h2 { border-bottom: solid; font-family: sans-serif; font-size: 140%; font-variant: small-caps; } + h3 { font-family: sans-serif; font-size: 110%; } td { vertical-align: top; } .miscinfo { text-align: center; font-size: 110%; font-style: italic; } .signature { font-size: 120%; font-variant: small-caps; } .designation {font-size: 110%; font-variant: small-caps; } + dt { font-weight: bold; } diff --git a/templates/default_xhtml/misc_strings.txt b/templates/default_xhtml/misc_strings.txt new file mode 100644 index 0000000..97014f7 --- /dev/null +++ b/templates/default_xhtml/misc_strings.txt @@ -0,0 +1,6 @@ +good verbal skills; +can read/write; +proficient; +Married +Single +Unspecified \ No newline at end of file diff --git a/templates/default_xhtml/profession_bit.tpl b/templates/default_xhtml/profession_bit.tpl index 341c80a..eb2c713 100644 --- a/templates/default_xhtml/profession_bit.tpl +++ b/templates/default_xhtml/profession_bit.tpl @@ -1,3 +1,3 @@ -

    ${dateofjoining} - ${dateofleaving} (with ${organization}) -

    Worked as ${designation}.

    +

    ${joindate} - ${leavedate} (with ${organization}) +

    Worked as ${jobtitle}.

    ${additionalinfo}

    \ No newline at end of file -- 2.20.1