diff Generic/base.py @ 25:189f8274aecd

gui. switch navigation menu on switch page
author Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
date Mon, 20 May 2019 13:18:33 +0200
parents 65e7ae0d0e63
children 16f91684686b
line wrap: on
line diff
--- a/Generic/base.py	Fri May 03 11:11:00 2019 +0200
+++ b/Generic/base.py	Mon May 20 13:18:33 2019 +0200
@@ -418,7 +418,7 @@
         Sets the code, must be a valid code
         """
         if not utils.is_valid_code(code)[0]:
-            raise ValueError( utils.mapping(_("Invalid code: $1"),(str(code),)) )
+            raise ValueError(utils.mapping(_("Invalid code: $1"),(str(code),)))
         self.__code = code
 
     def getSynonyms(self):
@@ -1004,7 +1004,7 @@
 
     def setCertification(self, certification):
         if not (certification is None or isinstance(certification, list)):
-            raise ValueError( _("Certification atribute must be a list or None") )
+            raise ValueError(_("Certification atribute must be a list or None"))
         self.__certification = certification
 
     def getRealCost(self):
@@ -1028,7 +1028,7 @@
 
     def setCostPlanned(self, cost_planned):
         if not (cost_planned is None or  isinstance(cost_planned, list)):
-            raise ValueError( _("Cost Planned atribute must be a list or None") )
+            raise ValueError(_("Cost Planned atribute must be a list or None"))
         self.__cost_planned = cost_planned
 
     position = property(getPosition, setPosition, None,
@@ -1661,7 +1661,7 @@
         "DRA": Number of decimal places of the yield in a decompositon of a
             auxiliar element.
             Number of decimal places of the result of the multiplication of 
-            the yield and the factor in a descomposition of a auxilar element.Decimales
+            the yield and the factor in a descomposition of a auxilar element.
             Default: 3 decimal places.
         "DP": Number of decimal places of the price of a budget.
             Default: 2 decimal places.
@@ -1926,7 +1926,8 @@
             The records can have diferent prices for diferent ages, geografical
             places, ...
         +-- __title_index: A integer. The active group of Prices and Decimals.
-        +-- __sheet_sections: sheet sections dictionary { sheet_code : sheet_title }
+        +-- __sheet_sections: sheet sections dictionary
+                   { sheet_code : sheet_title }
         +-- __sheet_fields: sheet fields dictionary { field_code : field_title }
         +-- __sheet_paragraphs: sheet paragraphs dictionary 
                            { paragraph_code : paragraph_text}
@@ -2190,7 +2191,7 @@
                 datetime.date(*date)
             self.__date = date
         else:
-            raise  TypeError( utils.mapping(_("Invalid Date: $1"),(str(date),)) )
+            raise  TypeError(utils.mapping(_("Invalid Date: $1"),(str(date),)))
 
     def setComment(self, comment):
         """setOwner(self, comment)
@@ -2244,7 +2245,8 @@
             datetime.date(*certificate_date)
             self.__budgetCerficateDate = certificate_date
         else:
-            raise  ValueError( _("Budget certificate Date must be a valid Date.") )
+            _str = _("Budget certificate Date must be a valid Date.")
+            raise  ValueError(_str)
 
     def setTitleList(self, title_list):
         """setTitleList(self, title_list)
@@ -2481,7 +2483,7 @@
             if code == None: # No root
                 print( "No-estructured measures. Adding root record " +  
                 str(self.setRecord("root", [], 0, "", "", [0.0,], [(1,1,1970)],
-                                     0, "") ))
+                                     0, "") ).encode("utf8"))
                 code = self.getRoot()
 
         if not utils.is_valid_code(code)[0]:
@@ -2499,9 +2501,10 @@
         for _parent_code in _all_parent_list:
             if _parent_code in _all_child_list:
                 # TODO: change return to except
-                print(utils.mapping(_("Circular Decomposition, parent code: "\
-                      "$1, child code: $2, repeated code: $3"),
-                      (str(code), str(child_code), str(_parent_code))) )
+                _str = _("Circular Decomposition, parent code: "\
+                         "$1, child code: $2, repeated code: $3")
+                print(utils.mapping(_str, (str(code), str(child_code),
+                                           str(_parent_code))).encode("utf8") )
                 return
 
         # Creating reference to parent code in child record
@@ -2520,19 +2523,24 @@
             _child_number = len(_record.children)
             if position == -1: # New child
                 position = _child_number
-            if position == -2: # No-estructured measures or empty position (error in FIEBDC file)
+            # No-estructured measures or empty position (error in FIEBDC file)
+            if position == -2: 
                 positions = _record.getChildPositions(child_code)
                 if len(positions) == 1:
                     position = positions[0]
-                    print(utils.mapping(_("No-estructured measure or empty position. Parent Code: "\
-                          "$1, Child code: $2, Position: $3"),(str(code), str(child_code), str(position))) )
+                    _str = _("No-estructured measure or empty position. " \
+                             "Parent Code: $1, Child code: $2, Position: $3")
+                    print(utils.mapping(_str,(str(code), str(child_code),
+                                        str(position))).encode("utf8") )
                 else:
                     position = _child_number
-                    print(utils.mapping(_("No-estructured measure or empty position. "\
-                          "Repeated child in unspecified position. "\
-                          "It is impossible to determine the position. "\
-                          "New child is added in the decomposition. "\
-                          "Parent code: $1, Child code: $2, Position: $3"),(str(code), str(child_code), str(position))) )
+                    _str = _("No-estructured measure or empty position. "\
+                             "Repeated child in unspecified position. "\
+                             "It is impossible to determine the position. "\
+                             "New child is added in the decomposition. "\
+                             "Parent code: $1, Child code: $2, Position: $3")
+                    print(utils.mapping(_str,(str(code), str(child_code),
+                                        str(position))).encode("utf8") )
             if position == _child_number:
                 # The record do not have the child
                 if not isinstance(factor, float): factor = 1.0
@@ -2568,21 +2576,27 @@
                     _measure.label = label
             else:
                 # TODO: change return for except
-                print(utils.mapping(_("Error: Invalid child position in "
-                      "decomposition. Parent code: $1 Child code: $2 "\
-                      "Position: $3"), (str(code), str(child_code), str(position))) )
+                _str = _("Error: Invalid child position in "
+                         "decomposition. Parent code: $1 Child code: $2 "\
+                         "Position: $3")
+                print(utils.mapping(_str, (str(code), str(child_code),
+                                    str(position))).encode("utf8") )
                 return
         else:
-            if child_code == "" : 
-                print(utils.mapping(_("Error: Empty child code. Parent code: "\
-                      "$1 Position: $2"), (str(code), str(position))) )
+            if child_code == "" :
+                _str = _("Error: Empty child code. Parent code: "\
+                         "$1 Position: $2")
+                print(utils.mapping(_str, (str(code),
+                                           str(position))).encode("utf8") )
                 return
             if position == -1:
                 position = 0
             elif position != 0:
-                print(utils.mapping(_("Error: Invalid child position in "\
-                      "decomposition. Parent code: $1 Child code: $2 "\
-                      "Position: $3"), (str(code), str(child_code), str(position))) )
+                _str = _("Error: Invalid child position in "\
+                         "decomposition. Parent code: $1 Child code: $2 "\
+                         "Position: $3")
+                print(utils.mapping(_str, (str(code), str(child_code),
+                                    str(position))).encode("utf8") )
                 return
             if not isinstance(factor, float):
                 factor = 1.0
@@ -2676,7 +2690,8 @@
         Sests the description text of a record
         """
         if not utils.is_valid_code(code)[0]:
-            raise ValueError( utils.mapping(_("Invalid record: $1"), (str(code),)) )
+            _str = _("Invalid record: $1")
+            raise ValueError( utils.mapping(_str, (str(code),)) )
         if not code in self.__records:
             _record = self.setRecord(code, [], "", "", "", [], [],
                                      "", "")
@@ -2739,9 +2754,10 @@
             if self.__root is None:
                 self.__root = code
             else:
-                print(_("Only can be one root record") )
+                print(_("Only can be one root record").encode("utf8") )
                 return
-                # TODO: If the root is created in settree. No-estructured measures
+                # TODO: If the root is created in settree.
+                #       No-estructured measures
                 # TODO  Rewrite root values
         # retake previous values.
         # TODO: test synonyms
@@ -2976,7 +2992,8 @@
         if not isinstance(paragraph_dict, dict):
             raise ValueError( _("The paragraph dict must be a dictionary") )
         for paragraph_code in paragraph_dict.keys():
-            self.setSheetParagraph( paragraph_code, paragraph_dict[paragraph_code])
+            self.setSheetParagraph(paragraph_code,
+                                   paragraph_dict[paragraph_code])
 
     def setSheetRecord(self, record_code, field, section_dict):
         if not isinstance(record_code, str):
@@ -2988,9 +3005,11 @@
         #-#
         # TODO: Add a empty record?
         if not self.hasRecord(record_code):
-            print(utils.mapping(_("Error: The budget do not have this record "\
-                "code and can not be added the sheet text in the field $1. "\
-                "Record Code: $2"), ( str(field), str(record_code))) )
+            _str = _("Error: The budget do not have this record "\
+                   "code and can not be added the sheet text in the field $1. "\
+                   "Record Code: $2")
+            print(utils.mapping(_str, ( str(field),
+                                str(record_code))).encode("utf8") )
             return
         #-#
         if not self.hasSheetField(field):
@@ -3014,7 +3033,7 @@
         if not self.hasRecord(record_code):
             print(utils.mapping(_("Error: The budget do not have the record "\
                 "code $1 and can not be added the file: $2"),
-                (str(record_code), str(filepath))) )
+                (str(record_code), str(filepath))).encode("utf8") )
             return
         #-#
         _record = self.getRecord(record_code)
@@ -3152,13 +3171,13 @@
             print(utils.mapping(_("Error: The budget do not have the record "\
                 "code $1 and can not be added the Parametric select comment: "\
                 "$2"),
-                (str(record_code), str(comment))) )
+                (str(record_code), str(comment))).encode("utf8") )
             return
         _record = self.getRecord(record_code)
         if not isinstance(_record, ParametricRecord):
             print(utils.mapping(_("Error: The Record $1 is not a "\
                 "Parametric Record and can not have Parametric comment"),
-                (str(record_code),)) )
+                (str(record_code),)).encode("utf8") )
         else:
             _record.select_comment = comment
 
@@ -3174,13 +3193,13 @@
         if not self.hasRecord(record_code):
             print(utils.mapping(_("Error: The budget do not have the record "\
                 "code $1 and can not be seted the summary: $2"),
-                (str(record_code), str(summary))) )
+                (str(record_code), str(summary))).encode("utf8") )
             return
         _record = self.getRecord(record_code)
         if not isinstance(_record, ParametricRecord):
             print(utils.mapping(_("Error: The Record $1 is not a "\
                 "Parametric Record and can not have Parametric summary"),
-                (str(record_code),)) )
+                (str(record_code),)).encode("utf8") )
         else:
             self.getRecord(record_code).parametric_summary = summary
 
@@ -3196,13 +3215,13 @@
         if not self.hasRecord(record_code):
             print(utils.mapping(_("Error: The budget do not have the record "\
                 "code $1 and can not be seted the text: $2"),
-                (str(record_code), str(text))) )
+                (str(record_code), str(text))).encode("utf8") )
             return
         _record = self.getRecord(record_code)
         if not isinstance(_record, ParametricRecord):
             print(utils.mapping(_("Error: The Record $1 is not a "\
                 "Parametric Record and can not have Parametric text"),
-                (str(record_code),)) )
+                (str(record_code),)).encode("utf8") )
         else:
             self.getRecord(record_code).parametric_text = text
 
@@ -3726,7 +3745,7 @@
             raise ValueError( utils.mapping(_("Invalid Hierarchy ($1) "\
                   "The hierarchy must be -1, 0, 1, 2"), (str(hierarchy),)) )
         elif hierarchy == "":
-            print("Hierarchy temporarily set to an empty string")
+            print("Hierarchy temporarily set to an empty string".encode("utf8"))
         #TODO Check empty Hierarchy in Generic.fiebdc.Read._testBudget
         self.__hierarchy = hierarchy