@@ -28,12 +28,12 @@ class Profile:
2828 id [str] id of the profile and file name
2929 errors [collections.defaultdict] contains all errors if profile is not correct
3030 """
31-
31+
3232 def __init__ (self , profile_data , client_id , profile_id = None , is_default_profile : bool = False ):
3333 self .isDisabled = profile_data .get ('isDisabled' , False )
3434 self .data = profile_data
3535 self .client_id = client_id
36- self .id = profile_id
36+ self ._id = profile_id
3737 self .errors = defaultdict (list )
3838 self ._is_default_profile = is_default_profile
3939
@@ -112,13 +112,6 @@ def save(self):
112112 profiles_path = Path (current_app .config ['PROFILES_DIR' ]).joinpath (self .client_id )
113113 profiles_path .mkdir (parents = True , exist_ok = True )
114114
115- if self .id is None :
116- if 'id' in self .data :
117- self .id = self .data ['id' ]
118- else :
119- # create a uuid for new profiles
120- self .data ['id' ] = self .id = str (uuid .uuid4 ())
121-
122115 file_path = profiles_path .joinpath (self .id ).with_suffix ('.json' )
123116 if 'isDefaultProfile' in self .data :
124117 del self .data ['isDefaultProfile' ]
@@ -147,6 +140,20 @@ def as_dict(self):
147140 'isDefaultProfile' : self ._is_default_profile
148141 }
149142
143+ @property
144+ def id (self ):
145+ if self ._id is None :
146+ if 'id' in self .data :
147+ self ._id = self .data ['id' ]
148+ else :
149+ # create a uuid for new profiles
150+ self .id = str (uuid .uuid4 ())
151+ return self ._id
152+
153+ @id .setter
154+ def id (self , new_id ):
155+ self .data ['id' ] = self ._id = new_id
156+
150157 @classmethod
151158 def load (cls , file_path : pathlib .PurePath ):
152159 """
@@ -180,7 +187,6 @@ def profile_from_file_path(cls, file_path: Path, client_id: str = ''):
180187 profile_data = cls .load (file_path )
181188 return cls (profile_data , client_id , profile_id )
182189
183-
184190 @classmethod
185191 def list (cls , client_id ):
186192 """
0 commit comments