comparison Generic/base.py @ 22:7bd4ca56607d

bug fix: Mutable default arguments
author Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es>
date Tue, 30 Sep 2014 17:16:50 +0200
parents a7b9f7e7dfa4
children 65e7ae0d0e63
comparison
equal deleted inserted replaced
21:f7e0cc58737f 22:7bd4ca56607d
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # -*- coding: utf-8 -*- 2 # -*- coding: utf-8 -*-
3 ## File base.py 3 ## File base.py
4 ## This file is part of pyArq-Presupuestos. 4 ## This file is part of pyArq-Presupuestos.
5 ## 5 ##
6 ## Copyright (C) 2010-2013 Miguel Ángel Bárcena Rodríguez 6 ## Copyright (C) 2010-2014 Miguel Ángel Bárcena Rodríguez
7 ## <miguelangel@obraencurso.es> 7 ## <miguelangel@obraencurso.es>
8 ## 8 ##
9 ## pyArq-Presupuestos is free software: you can redistribute it and/or modify 9 ## pyArq-Presupuestos is free software: you can redistribute it and/or modify
10 ## it under the terms of the GNU General Public License as published by 10 ## it under the terms of the GNU General Public License as published by
11 ## the Free Software Foundation, either version 3 of the License, or 11 ## the Free Software Foundation, either version 3 of the License, or
257 """base.Record: 257 """base.Record:
258 258
259 Description: 259 Description:
260 Record object 260 Record object
261 Constructor: 261 Constructor:
262 base.Record(code, synonyms, hierarchy, unit, summary, prices, type, 262 base.Record(decimals, code, synonyms, hierarchy, unit, summary,
263 subtype, text="") 263 prices, type_, subtype, parents=None, text=None)
264 Ancestry: 264 Ancestry:
265 +-- object 265 +-- object
266 +-- Record 266 +-- Record
267 Atributes: 267 Atributes:
268 "code": Code string 268 "code": Code string
331 self.__sheet = tuple[9] 331 self.__sheet = tuple[9]
332 self.__files = tuple[10] 332 self.__files = tuple[10]
333 self.__labels = tuple[11] 333 self.__labels = tuple[11]
334 334
335 def __init__(self, decimals, code, synonyms, hierarchy, unit, summary, 335 def __init__(self, decimals, code, synonyms, hierarchy, unit, summary,
336 prices, type_, subtype, parents=[], text=""): 336 prices, type_, subtype, parents=None, text=None):
337 self.code = code 337 self.code = code
338 self.synonyms = synonyms 338 self.synonyms = synonyms
339 self.recordType = (hierarchy, type_, subtype) 339 self.recordType = (hierarchy, type_, subtype)
340 self.unit = unit 340 self.unit = unit
341 self.summary = summary 341 self.summary = summary
342 self.setPrices(prices, decimals) 342 self.setPrices(prices, decimals)
343 if parents is None:
344 parents = []
343 self.parents = parents 345 self.parents = parents
344 self.children = [] 346 self.children = []
347 if text is None:
348 text = ""
345 self.text = text 349 self.text = text
346 self.sheet = Sheet() 350 self.sheet = Sheet()
347 self.files = [] 351 self.files = []
348 self.labels = [] 352 self.labels = []
349 353
541 for _measure in _measure_list: 545 for _measure in _measure_list:
542 _measurerecordCode = _record_code 546 _measurerecordCode = _record_code
543 self.__children = children 547 self.__children = children
544 548
545 def appendChild(self, child_code, decimals, factor=0.0, yield_=0.0, 549 def appendChild(self, child_code, decimals, factor=0.0, yield_=0.0,
546 measure=0.0, measure_list=[], type_ ="", label=""): 550 measure=0.0, measure_list=None, type_=None, label=None):
547 """appendChildren(self, child_code, factor=0.0, yield_=0.0, 551 """appendChildren(self, child_code, factor=0.0, yield_=0.0,
548 measure=0.0, measure_list=[], type_ ="", label="")) 552 measure=0.0, measure_list=None, type_=None, label=None))
549 553
550 position: 554 position:
551 child_code: 555 child_code:
552 factor: 556 factor:
553 yield_: 557 yield_:
556 type_: 560 type_:
557 label: 561 label:
558 562
559 Append a child to the list of children 563 Append a child to the list of children
560 """ 564 """
565 if measure_list is None:
566 measure_list = []
567 if type_ is None:
568 type_ = ""
569 if label is None:
570 label = ""
561 _measure = Measure(decimals, self.recordType, 571 _measure = Measure(decimals, self.recordType,
562 measure, [], label, factor, yield_) 572 measure, [], label, factor, yield_)
563 if len(measure_list) > 0: 573 if len(measure_list) > 0:
564 _measure.buildMeasure( measure_list, type_, decimals, 574 _measure.buildMeasure( measure_list, type_, decimals,
565 self.recordType) 575 self.recordType)
717 """base.ParametricRecord: 727 """base.ParametricRecord:
718 728
719 Description: 729 Description:
720 Parametric Record object 730 Parametric Record object
721 Constructor: 731 Constructor:
722 base.ParametricRecord(code, synonyms, hierarchy, unit, summary, prices, 732 base.ParametricRecord(budget, code, synonyms, hierarchy, unit, summary,
723 type_, subtype, text="") 733 prices, type_, subtype, parents=None, text=None)
724 Ancestry: 734 Ancestry:
725 +-- object 735 +-- object
726 +-- Record 736 +-- Record
727 +-- ParametricRecord 737 +-- ParametricRecord
728 Atributes: 738 Atributes:
774 self.__vars = tuple[17] 784 self.__vars = tuple[17]
775 self.__parametric_summary = tuple[18] 785 self.__parametric_summary = tuple[18]
776 self.__parametric_text = tuple[19] 786 self.__parametric_text = tuple[19]
777 787
778 def __init__(self, budget, code, synonyms, hierarchy, unit, summary, 788 def __init__(self, budget, code, synonyms, hierarchy, unit, summary,
779 prices, type_, subtype, parents=[], text=""): 789 prices, type_, subtype, parents=None, text=None):
790 if parents is None:
791 parents = []
792 if text is None:
793 text = ""
780 Record.__init__(self, budget, code, synonyms, hierarchy, unit, summary, 794 Record.__init__(self, budget, code, synonyms, hierarchy, unit, summary,
781 prices, type_, subtype, parents=[], text="") 795 prices, type_, subtype, parents, text)
782 self.__parameters = {} 796 self.__parameters = {}
783 self.__select_comment = "" 797 self.__select_comment = ""
784 self.__vars = {} 798 self.__vars = {}
785 self.parametric_summary = "" 799 self.parametric_summary = ""
786 self.parametric_text = "" 800 self.parametric_text = ""
1103 fixed = property(getFixed, setFixed,None, 1117 fixed = property(getFixed, setFixed,None,
1104 """If fixed is True the yield is not calculated from measure 1118 """If fixed is True the yield is not calculated from measure
1105 """) 1119 """)
1106 1120
1107 def buildMeasure(self, list_lines, type_, decimals, recordType): 1121 def buildMeasure(self, list_lines, type_, decimals, recordType):
1108 """setMeasure(self, list_lines, type_, decimals) 1122 """setMeasure(list_lines, type_, decimals, recordType)
1109 1123
1110 list_lines: list of measure lines 1124 list_lines: list of measure lines
1111 [ [linetype, comment, units, length, width, height, formula], ... ] 1125 [ [linetype, comment, units, length, width, height, formula], ... ]
1112 linetype: 1126 linetype:
1113 #-#empty string -> Normal 1127 #-#empty string -> Normal
1948 self.__labels = tuple[13] 1962 self.__labels = tuple[13]
1949 1963
1950 def iter(self): 1964 def iter(self):
1951 for record in self.__records: 1965 for record in self.__records:
1952 yield record 1966 yield record
1953 def iterPreOrder(self, recordCode, codes=[]): 1967 def iterPreOrder(self, recordCode, codes=None):
1968 if codes is None:
1969 codes = []
1954 _children = self.getchildren(recordCode) 1970 _children = self.getchildren(recordCode)
1955 for _child in _children: 1971 for _child in _children:
1956 if not _child in codes: 1972 if not _child in codes:
1957 codes.append(_child) 1973 codes.append(_child)
1958 self.iterPreOrder(_child, codes) 1974 self.iterPreOrder(_child, codes)
1959 return codes 1975 return codes
1960 def iterPostOrder(self, recordCode, codes=[]): 1976 def iterPostOrder(self, recordCode, codes=None):
1977 if codes is None:
1978 codes = []
1961 _children = self.getchildren(recordCode) 1979 _children = self.getchildren(recordCode)
1962 for _child in _children: 1980 for _child in _children:
1963 if not _child in codes: 1981 if not _child in codes:
1964 self.iterPreOrder(_child, codes) 1982 self.iterPreOrder(_child, codes)
1965 codes.append(_child) 1983 codes.append(_child)
2131 dictionary["DUO"], dictionary["DEA"], 2149 dictionary["DUO"], dictionary["DEA"],
2132 dictionary["DES"], dictionary["DIR"], 2150 dictionary["DES"], dictionary["DIR"],
2133 dictionary["DIRC"], dictionary["DCD"], 2151 dictionary["DIRC"], dictionary["DCD"],
2134 dictionary["DIVISA"]) 2152 dictionary["DIVISA"])
2135 self.__decimals[N] = decimals 2153 self.__decimals[N] = decimals
2136 def getDecimals(self, decimal="All", N=None): 2154 def getDecimals(self, decimal=None, N=None):
2137 """getDecimals(self,decimal="All",N=None) 2155 """getDecimals(self,decimal="All",N=None)
2138 2156
2139 decimal: 2157 decimal:
2140 "All": Return a Decimals objet for a price group 2158 "All": Return a Decimals objet for a price group
2141 "keys": Return the keys of a Decimal object 2159 "keys": Return the keys of a Decimal object
2142 key: Return a Decimal value for a price group 2160 key: Return a Decimal value for a price group
2143 N: the price group None,1,2,.. 2161 N: the price group None,1,2,..
2144 None: Return the active price group 2162 None: Return the active price group
2145 """ 2163 """
2164 if decimal is None: decimal = "All"
2146 if N is None: N = self.getActiveTitle() 2165 if N is None: N = self.getActiveTitle()
2147 if decimal == "All": 2166 if decimal == "All":
2148 return self.__decimals[N+1] 2167 return self.__decimals[N+1]
2149 elif decimal == "keys": 2168 elif decimal == "keys":
2150 return self.__decimals[N+1].keys 2169 return self.__decimals[N+1].keys
2170 "BI": dictionary["BI"], 2189 "BI": dictionary["BI"],
2171 "BAJA": dictionary["BAJA"], 2190 "BAJA": dictionary["BAJA"],
2172 "IVA" : dictionary["IVA"]} 2191 "IVA" : dictionary["IVA"]}
2173 self.__percentages = _percentages 2192 self.__percentages = _percentages
2174 2193
2175 def getPercentages(self, key="All"): 2194 def getPercentages(self, key=None):
2176 """getPercentages(self, percentage="All") 2195 """getPercentages(self, key=None)
2177 2196
2178 key: 2197 key:
2179 "All": Return the Percentages dictionary 2198 "All": Return the Percentages dictionary
2180 "keys": Return the keys of a Percentages object 2199 "keys": Return the keys of a Percentages object
2181 key: Return a Percentages value for the key 2200 key: Return a Percentages value for the key
2182 """ 2201 """
2202 if Key is None:
2203 key = "All"
2183 if key == "All": 2204 if key == "All":
2184 return self.__percentages 2205 return self.__percentages
2185 elif key == "keys": 2206 elif key == "keys":
2186 return self.__percentages.keys 2207 return self.__percentages.keys
2187 elif key in self.__percentages: 2208 elif key in self.__percentages: