cache.py 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119
  1. # Copyright (c) 2010-2019 openpyxl
  2. from openpyxl.descriptors.serialisable import Serialisable
  3. from openpyxl.descriptors import (
  4. Typed,
  5. Bool,
  6. Float,
  7. Set,
  8. NoneSet,
  9. String,
  10. Integer,
  11. DateTime,
  12. Sequence,
  13. )
  14. from openpyxl.descriptors.excel import (
  15. HexBinary,
  16. ExtensionList,
  17. Relation,
  18. )
  19. from openpyxl.descriptors.nested import NestedInteger
  20. from openpyxl.descriptors.sequence import (
  21. NestedSequence,
  22. MultiSequence,
  23. MultiSequencePart,
  24. )
  25. from openpyxl.xml.constants import SHEET_MAIN_NS
  26. from openpyxl.xml.functions import tostring
  27. from openpyxl.packaging.relationship import (
  28. RelationshipList,
  29. Relationship,
  30. get_rels_path
  31. )
  32. from .table import (
  33. PivotArea,
  34. Reference,
  35. )
  36. from .fields import (
  37. Boolean,
  38. Error,
  39. Missing,
  40. Number,
  41. Text,
  42. TupleList,
  43. DateTimeField,
  44. )
  45. class MeasureDimensionMap(Serialisable):
  46. tagname = "map"
  47. measureGroup = Integer(allow_none=True)
  48. dimension = Integer(allow_none=True)
  49. def __init__(self,
  50. measureGroup=None,
  51. dimension=None,
  52. ):
  53. self.measureGroup = measureGroup
  54. self.dimension = dimension
  55. class MeasureGroup(Serialisable):
  56. tagname = "measureGroup"
  57. name = String()
  58. caption = String()
  59. def __init__(self,
  60. name=None,
  61. caption=None,
  62. ):
  63. self.name = name
  64. self.caption = caption
  65. class PivotDimension(Serialisable):
  66. tagname = "dimension"
  67. measure = Bool()
  68. name = String()
  69. uniqueName = String()
  70. caption = String()
  71. def __init__(self,
  72. measure=None,
  73. name=None,
  74. uniqueName=None,
  75. caption=None,
  76. ):
  77. self.measure = measure
  78. self.name = name
  79. self.uniqueName = uniqueName
  80. self.caption = caption
  81. class CalculatedMember(Serialisable):
  82. tagname = "calculatedMember"
  83. name = String()
  84. mdx = String()
  85. memberName = String()
  86. hierarchy = String()
  87. parent = String()
  88. solveOrder = Integer()
  89. set = Bool()
  90. extLst = Typed(expected_type=ExtensionList, allow_none=True)
  91. __elements__ = ()
  92. def __init__(self,
  93. name=None,
  94. mdx=None,
  95. memberName=None,
  96. hierarchy=None,
  97. parent=None,
  98. solveOrder=None,
  99. set=None,
  100. extLst=None,
  101. ):
  102. self.name = name
  103. self.mdx = mdx
  104. self.memberName = memberName
  105. self.hierarchy = hierarchy
  106. self.parent = parent
  107. self.solveOrder = solveOrder
  108. self.set = set
  109. #self.extLst = extLst
  110. class CalculatedItem(Serialisable):
  111. tagname = "calculatedItem"
  112. field = Integer(allow_none=True)
  113. formula = String()
  114. pivotArea = Typed(expected_type=PivotArea, )
  115. extLst = Typed(expected_type=ExtensionList, allow_none=True)
  116. __elements__ = ('pivotArea', 'extLst')
  117. def __init__(self,
  118. field=None,
  119. formula=None,
  120. pivotArea=None,
  121. extLst=None,
  122. ):
  123. self.field = field
  124. self.formula = formula
  125. self.pivotArea = pivotArea
  126. self.extLst = extLst
  127. class ServerFormat(Serialisable):
  128. tagname = "serverFormat"
  129. culture = String(allow_none=True)
  130. format = String(allow_none=True)
  131. def __init__(self,
  132. culture=None,
  133. format=None,
  134. ):
  135. self.culture = culture
  136. self.format = format
  137. class ServerFormatList(Serialisable):
  138. tagname = "serverFormats"
  139. serverFormat = Sequence(expected_type=ServerFormat, allow_none=True)
  140. __elements__ = ('serverFormat',)
  141. __attrs__ = ('count',)
  142. def __init__(self,
  143. count=None,
  144. serverFormat=None,
  145. ):
  146. self.serverFormat = serverFormat
  147. @property
  148. def count(self):
  149. return len(self.serverFormat)
  150. class Query(Serialisable):
  151. tagname = "query"
  152. mdx = String()
  153. tpls = Typed(expected_type=TupleList, allow_none=True)
  154. __elements__ = ('tpls',)
  155. def __init__(self,
  156. mdx=None,
  157. tpls=None,
  158. ):
  159. self.mdx = mdx
  160. self.tpls = tpls
  161. class QueryCache(Serialisable):
  162. tagname = "queryCache"
  163. count = Integer()
  164. query = Typed(expected_type=Query, )
  165. __elements__ = ('query',)
  166. def __init__(self,
  167. count=None,
  168. query=None,
  169. ):
  170. self.count = count
  171. self.query = query
  172. class OLAPSet(Serialisable):
  173. tagname = "set"
  174. count = Integer()
  175. maxRank = Integer()
  176. setDefinition = String()
  177. sortType = NoneSet(values=(['ascending', 'descending', 'ascendingAlpha',
  178. 'descendingAlpha', 'ascendingNatural', 'descendingNatural']))
  179. queryFailed = Bool()
  180. tpls = Typed(expected_type=TupleList, allow_none=True)
  181. sortByTuple = Typed(expected_type=TupleList, allow_none=True)
  182. __elements__ = ('tpls', 'sortByTuple')
  183. def __init__(self,
  184. count=None,
  185. maxRank=None,
  186. setDefinition=None,
  187. sortType=None,
  188. queryFailed=None,
  189. tpls=None,
  190. sortByTuple=None,
  191. ):
  192. self.count = count
  193. self.maxRank = maxRank
  194. self.setDefinition = setDefinition
  195. self.sortType = sortType
  196. self.queryFailed = queryFailed
  197. self.tpls = tpls
  198. self.sortByTuple = sortByTuple
  199. class OLAPSets(Serialisable):
  200. count = Integer()
  201. set = Typed(expected_type=OLAPSet, )
  202. __elements__ = ('set',)
  203. def __init__(self,
  204. count=None,
  205. set=None,
  206. ):
  207. self.count = count
  208. self.set = set
  209. class PCDSDTCEntries(Serialisable):
  210. tagname = "pCDSDTCEntries"
  211. count = Integer()
  212. # some elements are choice
  213. m = Typed(expected_type=Missing, )
  214. n = Typed(expected_type=Number, )
  215. e = Typed(expected_type=Error, )
  216. s = Typed(expected_type=Text)
  217. __elements__ = ('m', 'n', 'e', 's')
  218. def __init__(self,
  219. count=None,
  220. m=None,
  221. n=None,
  222. e=None,
  223. s=None,
  224. ):
  225. self.count = count
  226. self.m = m
  227. self.n = n
  228. self.e = e
  229. self.s = s
  230. class TupleCache(Serialisable):
  231. tagname = "tupleCache"
  232. entries = Typed(expected_type=PCDSDTCEntries, allow_none=True)
  233. sets = Typed(expected_type=OLAPSets, allow_none=True)
  234. queryCache = Typed(expected_type=QueryCache, allow_none=True)
  235. serverFormats = Typed(expected_type=ServerFormatList, allow_none=True)
  236. extLst = Typed(expected_type=ExtensionList, allow_none=True)
  237. __elements__ = ('entries', 'sets', 'queryCache', 'serverFormats', 'extLst')
  238. def __init__(self,
  239. entries=None,
  240. sets=None,
  241. queryCache=None,
  242. serverFormats=None,
  243. extLst=None,
  244. ):
  245. self.entries = entries
  246. self.sets = sets
  247. self.queryCache = queryCache
  248. self.serverFormats = serverFormats
  249. self.extLst = extLst
  250. class PCDKPI(Serialisable):
  251. tagname = "pCDKPI"
  252. uniqueName = String()
  253. caption = String(allow_none=True)
  254. displayFolder = String()
  255. measureGroup = String()
  256. parent = String()
  257. value = String()
  258. goal = String()
  259. status = String()
  260. trend = String()
  261. weight = String()
  262. time = String()
  263. def __init__(self,
  264. uniqueName=None,
  265. caption=None,
  266. displayFolder=None,
  267. measureGroup=None,
  268. parent=None,
  269. value=None,
  270. goal=None,
  271. status=None,
  272. trend=None,
  273. weight=None,
  274. time=None,
  275. ):
  276. self.uniqueName = uniqueName
  277. self.caption = caption
  278. self.displayFolder = displayFolder
  279. self.measureGroup = measureGroup
  280. self.parent = parent
  281. self.value = value
  282. self.goal = goal
  283. self.status = status
  284. self.trend = trend
  285. self.weight = weight
  286. self.time = time
  287. class GroupMember(Serialisable):
  288. tagname = "groupMember"
  289. uniqueName = String()
  290. group = Bool()
  291. def __init__(self,
  292. uniqueName=None,
  293. group=None,
  294. ):
  295. self.uniqueName = uniqueName
  296. self.group = group
  297. class GroupMembers(Serialisable):
  298. count = Integer()
  299. groupMember = Typed(expected_type=GroupMember, )
  300. __elements__ = ('groupMember',)
  301. def __init__(self,
  302. count=None,
  303. groupMember=None,
  304. ):
  305. self.count = count
  306. self.groupMember = groupMember
  307. class LevelGroup(Serialisable):
  308. tagname = "levelGroup"
  309. name = String()
  310. uniqueName = String()
  311. caption = String()
  312. uniqueParent = String()
  313. id = Integer()
  314. groupMembers = Typed(expected_type=GroupMembers, )
  315. __elements__ = ('groupMembers',)
  316. def __init__(self,
  317. name=None,
  318. uniqueName=None,
  319. caption=None,
  320. uniqueParent=None,
  321. id=None,
  322. groupMembers=None,
  323. ):
  324. self.name = name
  325. self.uniqueName = uniqueName
  326. self.caption = caption
  327. self.uniqueParent = uniqueParent
  328. self.id = id
  329. self.groupMembers = groupMembers
  330. class Groups(Serialisable):
  331. tagname = "groups"
  332. count = Integer()
  333. group = Typed(expected_type=LevelGroup, )
  334. __elements__ = ('group',)
  335. def __init__(self,
  336. count=None,
  337. group=None,
  338. ):
  339. self.count = count
  340. self.group = group
  341. class GroupLevel(Serialisable):
  342. tagname = "groupLevel"
  343. uniqueName = String()
  344. caption = String()
  345. user = Bool()
  346. customRollUp = Bool()
  347. groups = Typed(expected_type=Groups, allow_none=True)
  348. extLst = Typed(expected_type=ExtensionList, allow_none=True)
  349. __elements__ = ('groups', 'extLst')
  350. def __init__(self,
  351. uniqueName=None,
  352. caption=None,
  353. user=None,
  354. customRollUp=None,
  355. groups=None,
  356. extLst=None,
  357. ):
  358. self.uniqueName = uniqueName
  359. self.caption = caption
  360. self.user = user
  361. self.customRollUp = customRollUp
  362. self.groups = groups
  363. self.extLst = extLst
  364. class GroupLevels(Serialisable):
  365. count = Integer()
  366. groupLevel = Typed(expected_type=GroupLevel, )
  367. __elements__ = ('groupLevel',)
  368. def __init__(self,
  369. count=None,
  370. groupLevel=None,
  371. ):
  372. self.count = count
  373. self.groupLevel = groupLevel
  374. class FieldUsage(Serialisable):
  375. tagname = "fieldUsage"
  376. x = Integer()
  377. def __init__(self,
  378. x=None,
  379. ):
  380. self.x = x
  381. class FieldsUsage(Serialisable):
  382. count = Integer()
  383. fieldUsage = Typed(expected_type=FieldUsage, allow_none=True)
  384. __elements__ = ('fieldUsage',)
  385. def __init__(self,
  386. count=None,
  387. fieldUsage=None,
  388. ):
  389. self.count = count
  390. self.fieldUsage = fieldUsage
  391. class CacheHierarchy(Serialisable):
  392. tagname = "cacheHierarchy"
  393. uniqueName = String()
  394. caption = String(allow_none=True)
  395. measure = Bool()
  396. set = Bool()
  397. parentSet = Integer(allow_none=True)
  398. iconSet = Integer()
  399. attribute = Bool()
  400. time = Bool()
  401. keyAttribute = Bool()
  402. defaultMemberUniqueName = String(allow_none=True)
  403. allUniqueName = String(allow_none=True)
  404. allCaption = String(allow_none=True)
  405. dimensionUniqueName = String(allow_none=True)
  406. displayFolder = String(allow_none=True)
  407. measureGroup = String(allow_none=True)
  408. measures = Bool()
  409. count = Integer()
  410. oneField = Bool()
  411. memberValueDatatype = Integer(allow_none=True)
  412. unbalanced = Bool(allow_none=True)
  413. unbalancedGroup = Bool(allow_none=True)
  414. hidden = Bool()
  415. fieldsUsage = Typed(expected_type=FieldsUsage, allow_none=True)
  416. groupLevels = Typed(expected_type=GroupLevels, allow_none=True)
  417. extLst = Typed(expected_type=ExtensionList, allow_none=True)
  418. __elements__ = ('fieldsUsage', 'groupLevels')
  419. def __init__(self,
  420. uniqueName="",
  421. caption=None,
  422. measure=None,
  423. set=None,
  424. parentSet=None,
  425. iconSet=0,
  426. attribute=None,
  427. time=None,
  428. keyAttribute=None,
  429. defaultMemberUniqueName=None,
  430. allUniqueName=None,
  431. allCaption=None,
  432. dimensionUniqueName=None,
  433. displayFolder=None,
  434. measureGroup=None,
  435. measures=None,
  436. count=None,
  437. oneField=None,
  438. memberValueDatatype=None,
  439. unbalanced=None,
  440. unbalancedGroup=None,
  441. hidden=None,
  442. fieldsUsage=None,
  443. groupLevels=None,
  444. extLst=None,
  445. ):
  446. self.uniqueName = uniqueName
  447. self.caption = caption
  448. self.measure = measure
  449. self.set = set
  450. self.parentSet = parentSet
  451. self.iconSet = iconSet
  452. self.attribute = attribute
  453. self.time = time
  454. self.keyAttribute = keyAttribute
  455. self.defaultMemberUniqueName = defaultMemberUniqueName
  456. self.allUniqueName = allUniqueName
  457. self.allCaption = allCaption
  458. self.dimensionUniqueName = dimensionUniqueName
  459. self.displayFolder = displayFolder
  460. self.measureGroup = measureGroup
  461. self.measures = measures
  462. self.count = count
  463. self.oneField = oneField
  464. self.memberValueDatatype = memberValueDatatype
  465. self.unbalanced = unbalanced
  466. self.unbalancedGroup = unbalancedGroup
  467. self.hidden = hidden
  468. self.fieldsUsage = fieldsUsage
  469. self.groupLevels = groupLevels
  470. self.extLst = extLst
  471. class GroupItems(Serialisable):
  472. tagname = "groupItems"
  473. m = Sequence(expected_type=Missing)
  474. n = Sequence(expected_type=Number)
  475. b = Sequence(expected_type=Boolean)
  476. e = Sequence(expected_type=Error)
  477. s = Sequence(expected_type=Text)
  478. d = Sequence(expected_type=DateTimeField,)
  479. __elements__ = ('m', 'n', 'b', 'e', 's', 'd')
  480. __attrs__ = ("count", )
  481. def __init__(self,
  482. count=None,
  483. m=(),
  484. n=(),
  485. b=(),
  486. e=(),
  487. s=(),
  488. d=(),
  489. ):
  490. self.m = m
  491. self.n = n
  492. self.b = b
  493. self.e = e
  494. self.s = s
  495. self.d = d
  496. @property
  497. def count(self):
  498. return len(self.m + self.n + self.b + self.e + self.s + self.d)
  499. class DiscretePr(Serialisable):
  500. tagname = "discretePr"
  501. count = Integer()
  502. x = NestedInteger(allow_none=True)
  503. __elements__ = ('x',)
  504. def __init__(self,
  505. count=None,
  506. x=None,
  507. ):
  508. self.count = count
  509. self.x = x
  510. class RangePr(Serialisable):
  511. tagname = "rangePr"
  512. autoStart = Bool(allow_none=True)
  513. autoEnd = Bool(allow_none=True)
  514. groupBy = Set(values=(['range', 'seconds', 'minutes', 'hours', 'days',
  515. 'months', 'quarters', 'years']))
  516. startNum = Float(allow_none=True)
  517. endNum = Float(allow_none=True)
  518. startDate = DateTime(allow_none=True)
  519. endDate = DateTime(allow_none=True)
  520. groupInterval = Float(allow_none=True)
  521. def __init__(self,
  522. autoStart=True,
  523. autoEnd=True,
  524. groupBy=range,
  525. startNum=None,
  526. endNum=None,
  527. startDate=None,
  528. endDate=None,
  529. groupInterval=1,
  530. ):
  531. self.autoStart = autoStart
  532. self.autoEnd = autoEnd
  533. self.groupBy = groupBy
  534. self.startNum = startNum
  535. self.endNum = endNum
  536. self.startDate = startDate
  537. self.endDate = endDate
  538. self.groupInterval = groupInterval
  539. class FieldGroup(Serialisable):
  540. tagname = "fieldGroup"
  541. par = Integer(allow_none=True)
  542. base = Integer(allow_none=True)
  543. rangePr = Typed(expected_type=RangePr, allow_none=True)
  544. discretePr = Typed(expected_type=DiscretePr, allow_none=True)
  545. groupItems = Typed(expected_type=GroupItems, allow_none=True)
  546. __elements__ = ('rangePr', 'discretePr', 'groupItems')
  547. def __init__(self,
  548. par=None,
  549. base=None,
  550. rangePr=None,
  551. discretePr=None,
  552. groupItems=None,
  553. ):
  554. self.par = par
  555. self.base = base
  556. self.rangePr = rangePr
  557. self.discretePr = discretePr
  558. self.groupItems = groupItems
  559. class SharedItems(Serialisable):
  560. tagname = "sharedItems"
  561. _fields = MultiSequence()
  562. m = MultiSequencePart(expected_type=Missing, store="_fields")
  563. n = MultiSequencePart(expected_type=Number, store="_fields")
  564. b = MultiSequencePart(expected_type=Boolean, store="_fields")
  565. e = MultiSequencePart(expected_type=Error, store="_fields")
  566. s = MultiSequencePart(expected_type=Text, store="_fields")
  567. d = MultiSequencePart(expected_type=DateTimeField, store="_fields")
  568. # attributes are optional and must be derived from associated cache records
  569. containsSemiMixedTypes = Bool(allow_none=True)
  570. containsNonDate = Bool(allow_none=True)
  571. containsDate = Bool(allow_none=True)
  572. containsString = Bool(allow_none=True)
  573. containsBlank = Bool(allow_none=True)
  574. containsMixedTypes = Bool(allow_none=True)
  575. containsNumber = Bool(allow_none=True)
  576. containsInteger = Bool(allow_none=True)
  577. minValue = Float(allow_none=True)
  578. maxValue = Float(allow_none=True)
  579. minDate = DateTime(allow_none=True)
  580. maxDate = DateTime(allow_none=True)
  581. longText = Bool(allow_none=True)
  582. __attrs__ = ('count', 'containsBlank', 'containsDate', 'containsInteger',
  583. 'containsMixedTypes', 'containsNonDate', 'containsNumber',
  584. 'containsSemiMixedTypes', 'containsString', 'minValue', 'maxValue',
  585. 'minDate', 'maxDate', 'longText')
  586. def __init__(self,
  587. _fields=(),
  588. containsSemiMixedTypes=None,
  589. containsNonDate=None,
  590. containsDate=None,
  591. containsString=None,
  592. containsBlank=None,
  593. containsMixedTypes=None,
  594. containsNumber=None,
  595. containsInteger=None,
  596. minValue=None,
  597. maxValue=None,
  598. minDate=None,
  599. maxDate=None,
  600. count=None,
  601. longText=None,
  602. ):
  603. self._fields = _fields
  604. self.containsBlank = containsBlank
  605. self.containsDate = containsDate
  606. self.containsNonDate = containsNonDate
  607. self.containsString = containsString
  608. self.containsMixedTypes = containsMixedTypes
  609. self.containsSemiMixedTypes = containsSemiMixedTypes
  610. self.containsNumber = containsNumber
  611. self.containsInteger = containsInteger
  612. self.minValue = minValue
  613. self.maxValue = maxValue
  614. self.minDate = minDate
  615. self.maxDate = maxDate
  616. self.longText = longText
  617. @property
  618. def count(self):
  619. return len(self._fields)
  620. class CacheField(Serialisable):
  621. tagname = "cacheField"
  622. sharedItems = Typed(expected_type=SharedItems, allow_none=True)
  623. fieldGroup = Typed(expected_type=FieldGroup, allow_none=True)
  624. mpMap = NestedInteger(allow_none=True, attribute="v")
  625. extLst = Typed(expected_type=ExtensionList, allow_none=True)
  626. name = String()
  627. caption = String(allow_none=True)
  628. propertyName = String(allow_none=True)
  629. serverField = Bool(allow_none=True)
  630. uniqueList = Bool(allow_none=True)
  631. numFmtId = Integer(allow_none=True)
  632. formula = String(allow_none=True)
  633. sqlType = Integer(allow_none=True)
  634. hierarchy = Integer(allow_none=True)
  635. level = Integer(allow_none=True)
  636. databaseField = Bool(allow_none=True)
  637. mappingCount = Integer(allow_none=True)
  638. memberPropertyField = Bool(allow_none=True)
  639. __elements__ = ('sharedItems', 'fieldGroup', 'mpMap')
  640. def __init__(self,
  641. sharedItems=None,
  642. fieldGroup=None,
  643. mpMap=None,
  644. extLst=None,
  645. name=None,
  646. caption=None,
  647. propertyName=None,
  648. serverField=None,
  649. uniqueList=True,
  650. numFmtId=None,
  651. formula=None,
  652. sqlType=0,
  653. hierarchy=0,
  654. level=0,
  655. databaseField=True,
  656. mappingCount=None,
  657. memberPropertyField=None,
  658. ):
  659. self.sharedItems = sharedItems
  660. self.fieldGroup = fieldGroup
  661. self.mpMap = mpMap
  662. self.extLst = extLst
  663. self.name = name
  664. self.caption = caption
  665. self.propertyName = propertyName
  666. self.serverField = serverField
  667. self.uniqueList = uniqueList
  668. self.numFmtId = numFmtId
  669. self.formula = formula
  670. self.sqlType = sqlType
  671. self.hierarchy = hierarchy
  672. self.level = level
  673. self.databaseField = databaseField
  674. self.mappingCount = mappingCount
  675. self.memberPropertyField = memberPropertyField
  676. class RangeSet(Serialisable):
  677. tagname = "rangeSet"
  678. i1 = Integer(allow_none=True)
  679. i2 = Integer(allow_none=True)
  680. i3 = Integer(allow_none=True)
  681. i4 = Integer(allow_none=True)
  682. ref = String()
  683. name = String(allow_none=True)
  684. sheet = String(allow_none=True)
  685. def __init__(self,
  686. i1=None,
  687. i2=None,
  688. i3=None,
  689. i4=None,
  690. ref=None,
  691. name=None,
  692. sheet=None,
  693. ):
  694. self.i1 = i1
  695. self.i2 = i2
  696. self.i3 = i3
  697. self.i4 = i4
  698. self.ref = ref
  699. self.name = name
  700. self.sheet = sheet
  701. class PageItem(Serialisable):
  702. tagname = "pageItem"
  703. name = String()
  704. def __init__(self,
  705. name=None,
  706. ):
  707. self.name = name
  708. class Page(Serialisable):
  709. # PCDSCPage
  710. tagname = "PCDSCPage"
  711. pageItem = Sequence(expected_type=PageItem)
  712. __elements__ = ('pageItem',)
  713. def __init__(self,
  714. count=None,
  715. pageItem=None,
  716. ):
  717. self.pageItem = pageItem
  718. @property
  719. def count(self):
  720. return len(self.pageItem)
  721. class Consolidation(Serialisable):
  722. tagname = "consolidation"
  723. autoPage = Bool(allow_none=True)
  724. pages = NestedSequence(expected_type=Page, count=True)
  725. rangeSets = NestedSequence(expected_type=RangeSet, count=True)
  726. __elements__ = ('pages', 'rangeSets')
  727. def __init__(self,
  728. autoPage=None,
  729. pages=(),
  730. rangeSets=(),
  731. ):
  732. self.autoPage = autoPage
  733. self.pages = pages
  734. self.rangeSets = rangeSets
  735. class WorksheetSource(Serialisable):
  736. tagname = "worksheetSource"
  737. ref = String(allow_none=True)
  738. name = String(allow_none=True)
  739. sheet = String(allow_none=True)
  740. def __init__(self,
  741. ref=None,
  742. name=None,
  743. sheet=None,
  744. ):
  745. self.ref = ref
  746. self.name = name
  747. self.sheet = sheet
  748. class CacheSource(Serialisable):
  749. tagname = "cacheSource"
  750. type = Set(values=(['worksheet', 'external', 'consolidation', 'scenario']))
  751. connectionId = Integer(allow_none=True)
  752. # some elements are choice
  753. worksheetSource = Typed(expected_type=WorksheetSource, allow_none=True)
  754. consolidation = Typed(expected_type=Consolidation, allow_none=True)
  755. extLst = Typed(expected_type=ExtensionList, allow_none=True)
  756. __elements__ = ('worksheetSource', 'consolidation',)
  757. def __init__(self,
  758. type=None,
  759. connectionId=None,
  760. worksheetSource=None,
  761. consolidation=None,
  762. extLst=None,
  763. ):
  764. self.type = type
  765. self.connectionId = connectionId
  766. self.worksheetSource = worksheetSource
  767. self.consolidation = consolidation
  768. class CacheDefinition(Serialisable):
  769. mime_type = "application/vnd.openxmlformats-officedocument.spreadsheetml.pivotCacheDefinition+xml"
  770. rel_type = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/pivotCacheDefinition"
  771. _id = 1
  772. _path = "/xl/pivotCache/pivotCacheDefinition{0}.xml"
  773. records = None
  774. tagname = "pivotCacheDefinition"
  775. invalid = Bool(allow_none=True)
  776. saveData = Bool(allow_none=True)
  777. refreshOnLoad = Bool(allow_none=True)
  778. optimizeMemory = Bool(allow_none=True)
  779. enableRefresh = Bool(allow_none=True)
  780. refreshedBy = String(allow_none=True)
  781. refreshedDate = Float(allow_none=True)
  782. refreshedDateIso = DateTime(allow_none=True)
  783. backgroundQuery = Bool(allow_none=True)
  784. missingItemsLimit = Integer(allow_none=True)
  785. createdVersion = Integer(allow_none=True)
  786. refreshedVersion = Integer(allow_none=True)
  787. minRefreshableVersion = Integer(allow_none=True)
  788. recordCount = Integer(allow_none=True)
  789. upgradeOnRefresh = Bool(allow_none=True)
  790. tupleCache = Bool(allow_none=True)
  791. supportSubquery = Bool(allow_none=True)
  792. supportAdvancedDrill = Bool(allow_none=True)
  793. cacheSource = Typed(expected_type=CacheSource)
  794. cacheFields = NestedSequence(expected_type=CacheField, count=True)
  795. cacheHierarchies = NestedSequence(expected_type=CacheHierarchy, allow_none=True)
  796. kpis = NestedSequence(expected_type=PCDKPI, allow_none=True)
  797. tupleCache = Typed(expected_type=TupleCache, allow_none=True)
  798. calculatedItems = NestedSequence(expected_type=CalculatedItem, count=True)
  799. calculatedMembers = NestedSequence(expected_type=CalculatedMember, count=True)
  800. dimensions = NestedSequence(expected_type=PivotDimension, allow_none=True)
  801. measureGroups = NestedSequence(expected_type=MeasureGroup, count=True)
  802. maps = NestedSequence(expected_type=MeasureDimensionMap, count=True)
  803. extLst = Typed(expected_type=ExtensionList, allow_none=True)
  804. id = Relation()
  805. __elements__ = ('cacheSource', 'cacheFields', 'cacheHierarchies', 'kpis',
  806. 'tupleCache', 'calculatedItems', 'calculatedMembers', 'dimensions',
  807. 'measureGroups', 'maps',)
  808. def __init__(self,
  809. invalid=None,
  810. saveData=None,
  811. refreshOnLoad=None,
  812. optimizeMemory=None,
  813. enableRefresh=None,
  814. refreshedBy=None,
  815. refreshedDate=None,
  816. refreshedDateIso=None,
  817. backgroundQuery=None,
  818. missingItemsLimit=None,
  819. createdVersion=None,
  820. refreshedVersion=None,
  821. minRefreshableVersion=None,
  822. recordCount=None,
  823. upgradeOnRefresh=None,
  824. tupleCache=None,
  825. supportSubquery=None,
  826. supportAdvancedDrill=None,
  827. cacheSource=None,
  828. cacheFields=(),
  829. cacheHierarchies=(),
  830. kpis=(),
  831. calculatedItems=(),
  832. calculatedMembers=(),
  833. dimensions=(),
  834. measureGroups=(),
  835. maps=(),
  836. extLst=None,
  837. id = None,
  838. ):
  839. self.invalid = invalid
  840. self.saveData = saveData
  841. self.refreshOnLoad = refreshOnLoad
  842. self.optimizeMemory = optimizeMemory
  843. self.enableRefresh = enableRefresh
  844. self.refreshedBy = refreshedBy
  845. self.refreshedDate = refreshedDate
  846. self.refreshedDateIso = refreshedDateIso
  847. self.backgroundQuery = backgroundQuery
  848. self.missingItemsLimit = missingItemsLimit
  849. self.createdVersion = createdVersion
  850. self.refreshedVersion = refreshedVersion
  851. self.minRefreshableVersion = minRefreshableVersion
  852. self.recordCount = recordCount
  853. self.upgradeOnRefresh = upgradeOnRefresh
  854. self.tupleCache = tupleCache
  855. self.supportSubquery = supportSubquery
  856. self.supportAdvancedDrill = supportAdvancedDrill
  857. self.cacheSource = cacheSource
  858. self.cacheFields = cacheFields
  859. self.cacheHierarchies = cacheHierarchies
  860. self.kpis = kpis
  861. self.tupleCache = tupleCache
  862. self.calculatedItems = calculatedItems
  863. self.calculatedMembers = calculatedMembers
  864. self.dimensions = dimensions
  865. self.measureGroups = measureGroups
  866. self.maps = maps
  867. self.id = id
  868. def to_tree(self):
  869. node = super(CacheDefinition, self).to_tree()
  870. node.set("xmlns", SHEET_MAIN_NS)
  871. return node
  872. @property
  873. def path(self):
  874. return self._path.format(self._id)
  875. def _write(self, archive, manifest):
  876. """
  877. Add to zipfile and update manifest
  878. """
  879. self._write_rels(archive, manifest)
  880. xml = tostring(self.to_tree())
  881. archive.writestr(self.path[1:], xml)
  882. manifest.append(self)
  883. def _write_rels(self, archive, manifest):
  884. """
  885. Write the relevant child objects and add links
  886. """
  887. if self.records is None:
  888. return
  889. rels = RelationshipList()
  890. r = Relationship(Type=self.records.rel_type, Target=self.records.path)
  891. rels.append(r)
  892. self.id = r.id
  893. self.records._id = self._id
  894. self.records._write(archive, manifest)
  895. path = get_rels_path(self.path)
  896. xml = tostring(rels.to_tree())
  897. archive.writestr(path[1:], xml)