88import pathlib
99import zipfile
1010
11+ from pyocf .files import documentsfile
12+ from pyocf .files import financingsfile
1113from pyocf .files import ocfmanifestfile
1214from pyocf .files import stakeholdersfile
1315from pyocf .files import stockclassesfile
1618from pyocf .files import transactionsfile
1719from pyocf .files import valuationsfile
1820from pyocf .files import vestingtermsfile
21+ from pyocf .objects .document import Document
22+ from pyocf .objects .financing import Financing
1923from pyocf .objects .stakeholder import Stakeholder
2024from pyocf .objects .stockclass import StockClass
2125from pyocf .objects .stocklegendtemplate import StockLegendTemplate
2630from pyocf .types import file
2731
2832FILEMAP = [
29- ("stock_plans" , stockplansfile .StockPlansFile ),
30- ("stock_legend_templates" , stocklegendtemplatesfile .StockLegendTemplatesFile ),
33+ ("documents" , documentsfile .DocumentsFile ),
34+ ("financings" , financingsfile .FinancingsFile ),
35+ ("stakeholders" , stakeholdersfile .StakeholdersFile ),
3136 ("stock_classes" , stockclassesfile .StockClassesFile ),
32- ("vesting_terms " , vestingtermsfile . VestingTermsFile ),
33- ("valuations " , valuationsfile . ValuationsFile ),
37+ ("stock_legend_templates " , stocklegendtemplatesfile . StockLegendTemplatesFile ),
38+ ("stock_plans " , stockplansfile . StockPlansFile ),
3439 ("transactions" , transactionsfile .TransactionsFile ),
35- ("stakeholders" , stakeholdersfile .StakeholdersFile ),
40+ ("valuations" , valuationsfile .ValuationsFile ),
41+ ("vesting_terms" , vestingtermsfile .VestingTermsFile ),
3642]
3743
3844
3945class Captable :
40- manifest : ocfmanifestfile .OCFManifestFile = None
41- stock_plans : list [StockPlan ] = []
42- stock_legend_templates : list [StockLegendTemplate ] = []
43- stock_classes : list [StockClass ] = []
44- vesting_terms : list [VestingTerms ] = []
45- valuations : list [Valuation ] = []
46- transactions : list [Transaction ] = []
47- stakeholders : list [Stakeholder ] = []
46+ manifest : ocfmanifestfile .OCFManifestFile
47+ documents : list [Document ]
48+ financings : list [Financing ]
49+ stakeholders : list [Stakeholder ]
50+ stock_classes : list [StockClass ]
51+ stock_legend_templates : list [StockLegendTemplate ]
52+ stock_plans : list [StockPlan ]
53+ transactions : list [Transaction ]
54+ valuations : list [Valuation ]
55+ vesting_terms : list [VestingTerms ]
56+
57+ def __init__ (
58+ self ,
59+ manifest : ocfmanifestfile .OCFManifestFile = None ,
60+ documents : list [Document ] = None ,
61+ financings : list [Financing ] = None ,
62+ stakeholders : list [Stakeholder ] = None ,
63+ stock_classes : list [StockClass ] = None ,
64+ stock_legend_templates : list [StockLegendTemplate ] = None ,
65+ stock_plans : list [StockPlan ] = None ,
66+ transactions : list [Transaction ] = None ,
67+ valuations : list [Valuation ] = None ,
68+ vesting_terms : list [VestingTerms ] = None ,
69+ ):
70+ self .manifest = manifest
71+ self .documents = documents or []
72+ self .financings = financings or []
73+ self .stakeholders = stakeholders or []
74+ self .stock_classes = stock_classes or []
75+ self .stock_legend_templates = stock_legend_templates or []
76+ self .stock_plans = stock_plans or []
77+ self .transactions = transactions or []
78+ self .valuations = valuations or []
79+ self .vesting_terms = vesting_terms or []
4880
4981 @classmethod
5082 def load (cls , location ):
@@ -82,7 +114,10 @@ def file_factory(p):
82114 return open (pathlib .Path (basedir , p ))
83115
84116 for filetype , filecls in FILEMAP :
85- for fileob in getattr (captable .manifest , filetype + "_files" ):
117+ fileobjs = getattr (captable .manifest , filetype + "_files" )
118+ if fileobjs is None :
119+ continue
120+ for fileob in fileobjs :
86121 infile = file_factory (fileob .filepath )
87122 items = filecls (** json .load (infile )).items
88123 getattr (captable , filetype ).extend (items )
@@ -92,7 +127,7 @@ def file_factory(p):
92127 def _save_ocf_files (self , manifest_path , issuer , file_factory , pretty ):
93128 if issuer is None and self .manifest is None :
94129 raise ValueError (
95- "You must specify an issuer, either by passing the value to the"
130+ "You must specify an issuer, either by passing the value to the "
96131 "save method, or by creating a Manifest."
97132 )
98133
@@ -104,6 +139,8 @@ def _save_ocf_files(self, manifest_path, issuer, file_factory, pretty):
104139 if self .manifest :
105140 # Check if there is a different filename in the manifest:
106141 ocffilename = getattr (self .manifest , filetype + "_files" , [])
142+ if ocffilename is None :
143+ continue
107144 if len (ocffilename ) >= 1 :
108145 ocffilename = ocffilename [0 ].filepath
109146
@@ -112,7 +149,7 @@ def _save_ocf_files(self, manifest_path, issuer, file_factory, pretty):
112149
113150 with file_factory (ocffilename ) as ocffile :
114151 itemfile = fileob (items = getattr (self , filetype ))
115- jsonstr = itemfile .json ( exclude_unset = True )
152+ jsonstr = itemfile .model_dump_json ( )
116153 if pretty :
117154 jsonstr = json .dumps (json .loads (jsonstr ), indent = 4 )
118155 jsonstr = jsonstr .encode ("UTF-8" )
@@ -143,7 +180,7 @@ def _save_ocf_files(self, manifest_path, issuer, file_factory, pretty):
143180 self .manifest = ocfmanifestfile .OCFManifestFile (** manifest_data )
144181
145182 with file_factory (manifest_path ) as ocffile :
146- jsonstr = self .manifest .json ()
183+ jsonstr = self .manifest .model_dump_json ()
147184 if pretty :
148185 jsonstr = json .dumps (json .loads (jsonstr ), indent = 4 )
149186 ocffile .write (jsonstr .encode ("UTF-8" ))
0 commit comments