organizations-local 0.0.48__py3-none-any.whl → 0.0.50__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- organizations_local/organizations_local.py +84 -128
- {organizations_local-0.0.48.dist-info → organizations_local-0.0.50.dist-info}/METADATA +1 -2
- organizations_local-0.0.50.dist-info/RECORD +7 -0
- {organizations_local-0.0.48.dist-info → organizations_local-0.0.50.dist-info}/WHEEL +1 -1
- organizations_local-0.0.48.dist-info/RECORD +0 -7
- {organizations_local-0.0.48.dist-info → organizations_local-0.0.50.dist-info}/top_level.txt +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
from database_mysql_local.generic_crud_ml import GenericCRUDML
|
|
2
|
-
from database_mysql_local.
|
|
2
|
+
from database_mysql_local.constants_src import UpdateStatus
|
|
3
3
|
from database_mysql_local.sync_conflict_resolution import SyncConflictResolution
|
|
4
4
|
from language_remote.lang_code import LangCode
|
|
5
5
|
from logger_local.MetaLogger import MetaLogger
|
|
@@ -74,19 +74,11 @@ class OrganizationsLocal(
|
|
|
74
74
|
|
|
75
75
|
@staticmethod
|
|
76
76
|
def _clean_organization_dict(organization_dict: dict) -> dict:
|
|
77
|
-
columns = (
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
"location_id",
|
|
83
|
-
"profile_id",
|
|
84
|
-
"parent_organization_id",
|
|
85
|
-
"non_members_visibility_scope_id",
|
|
86
|
-
"members_visibility_scope_id",
|
|
87
|
-
"Non_members_visibility_profile_id",
|
|
88
|
-
"main_group_id",
|
|
89
|
-
)
|
|
77
|
+
columns = ("name", "is_approved", "is_main", "point", "location_id",
|
|
78
|
+
"profile_id", "parent_organization_id",
|
|
79
|
+
"non_members_visibility_scope_id",
|
|
80
|
+
"members_visibility_scope_id",
|
|
81
|
+
"Non_members_visibility_profile_id", "main_group_id")
|
|
90
82
|
organization_dict = {key: organization_dict.get(key) for key in columns}
|
|
91
83
|
return organization_dict
|
|
92
84
|
|
|
@@ -106,55 +98,48 @@ class OrganizationsLocal(
|
|
|
106
98
|
# TODO: rename to insert? same for all
|
|
107
99
|
def insert_organization(self, organization_dict: dict) -> tuple[int, int]:
|
|
108
100
|
# This should be before chaning the organization_dict
|
|
109
|
-
organization_ml_data_dict =
|
|
101
|
+
organization_ml_data_dict = \
|
|
102
|
+
self._clean_organization_ml_dict(organization_dict)
|
|
110
103
|
|
|
111
104
|
organization_dict = self._clean_organization_dict(organization_dict)
|
|
112
|
-
organization_id = GenericCRUDML.insert(self,
|
|
105
|
+
organization_id = GenericCRUDML.insert(self,
|
|
106
|
+
data_dict=organization_dict)
|
|
113
107
|
organization_ml_data_dict["organization_id"] = organization_id
|
|
114
108
|
organization_ml_id = GenericCRUDML.insert(
|
|
115
|
-
self,
|
|
116
|
-
|
|
117
|
-
data_dict=organization_ml_data_dict,
|
|
118
|
-
)
|
|
109
|
+
self, table_name="organization_ml_table",
|
|
110
|
+
data_dict=organization_ml_data_dict)
|
|
119
111
|
|
|
120
112
|
return organization_id, organization_ml_id
|
|
121
113
|
|
|
122
|
-
def upsert_organization(
|
|
123
|
-
|
|
124
|
-
) -> dict:
|
|
114
|
+
def upsert_organization(self, organization_dict: dict,
|
|
115
|
+
order_by: str = None) -> dict:
|
|
125
116
|
lang_code = LangCode.detect_lang_code_restricted(
|
|
126
|
-
text=organization_dict.get(
|
|
127
|
-
# TODO the lang code can be in the organization_dict or in the
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
organization_ml_dict = self._clean_organization_ml_dict(
|
|
117
|
+
text=organization_dict.get('title'),
|
|
118
|
+
# TODO the lang code can be in the organization_dict or in the
|
|
119
|
+
# UserContext, I'm not sure English as default is correct
|
|
120
|
+
default_lang_code=LangCode.ENGLISH)
|
|
121
|
+
organization_ml_dict = self._clean_organization_ml_dict(
|
|
122
|
+
organization_dict)
|
|
131
123
|
organization_dict = self._clean_organization_dict(organization_dict)
|
|
132
124
|
|
|
133
|
-
# TODO Why do we need to do this if outside of GenericCrud in every
|
|
134
|
-
|
|
135
|
-
|
|
125
|
+
# TODO Why do we need to do this if outside of GenericCrud in every
|
|
126
|
+
# entity, can we move this "if" into the Generic Crud method? Can we
|
|
127
|
+
# avoid two methods? The parameters of the two methods are the same?
|
|
128
|
+
if "(" and ")" in organization_dict.get('title', ''):
|
|
129
|
+
organization_id, organzation_ml_ids_list =\
|
|
136
130
|
GenericCRUDML.upsert_value_with_abbreviations(
|
|
137
|
-
self,
|
|
138
|
-
data_ml_dict=organization_ml_dict,
|
|
131
|
+
self, data_ml_dict=organization_ml_dict,
|
|
139
132
|
lang_code=lang_code,
|
|
140
133
|
data_dict=organization_dict,
|
|
141
134
|
schema_name=DEFAULT_SCHEMA_NAME,
|
|
142
135
|
table_name=DEFAULT_TABLE_NAME,
|
|
143
|
-
ml_table_name=DEFAULT_ML_TABLE_NAME,
|
|
144
|
-
order_by=order_by,
|
|
145
|
-
)
|
|
146
|
-
)
|
|
136
|
+
ml_table_name=DEFAULT_ML_TABLE_NAME, order_by=order_by)
|
|
147
137
|
else:
|
|
148
138
|
organization_id, organzation_ml_id = GenericCRUDML.upsert_value(
|
|
149
|
-
self,
|
|
150
|
-
|
|
151
|
-
lang_code=lang_code,
|
|
152
|
-
data_dict=organization_dict,
|
|
153
|
-
schema_name=DEFAULT_SCHEMA_NAME,
|
|
139
|
+
self, data_ml_dict=organization_ml_dict, lang_code=lang_code,
|
|
140
|
+
data_dict=organization_dict, schema_name=DEFAULT_SCHEMA_NAME,
|
|
154
141
|
table_name=DEFAULT_TABLE_NAME,
|
|
155
|
-
ml_table_name=DEFAULT_ML_TABLE_NAME,
|
|
156
|
-
order_by=order_by,
|
|
157
|
-
)
|
|
142
|
+
ml_table_name=DEFAULT_ML_TABLE_NAME, order_by=order_by)
|
|
158
143
|
organzation_ml_ids_list = [organzation_ml_id]
|
|
159
144
|
|
|
160
145
|
# TODO upsert_result_dict
|
|
@@ -169,35 +154,28 @@ class OrganizationsLocal(
|
|
|
169
154
|
self, *, organization_id: int, organization_ml_id: int, organization_dict: dict
|
|
170
155
|
) -> None:
|
|
171
156
|
# TODO: should we have such a method in CRUD ML? Same for delete
|
|
172
|
-
organization_ml_dict = self._clean_organization_ml_dict(
|
|
157
|
+
organization_ml_dict = self._clean_organization_ml_dict(
|
|
158
|
+
organization_dict)
|
|
173
159
|
organization_ml_dict["organization_id"] = organization_id
|
|
174
160
|
organization_dict = self._clean_organization_dict(organization_dict)
|
|
161
|
+
GenericCRUDML.update_by_column_and_value(self,
|
|
162
|
+
column_value=organization_id,
|
|
163
|
+
data_dict=organization_dict)
|
|
175
164
|
GenericCRUDML.update_by_column_and_value(
|
|
176
|
-
self,
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
self,
|
|
180
|
-
table_name="organization_ml_table",
|
|
181
|
-
column_value=organization_ml_id,
|
|
182
|
-
data_dict=organization_ml_dict,
|
|
183
|
-
column_name="organization_ml_id",
|
|
184
|
-
)
|
|
165
|
+
self, table_name="organization_ml_table",
|
|
166
|
+
column_value=organization_ml_id, data_dict=organization_ml_dict,
|
|
167
|
+
column_name="organization_ml_id")
|
|
185
168
|
|
|
186
169
|
def get_organization_dict_by_organization_id(
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
organization_id: int,
|
|
190
|
-
organization_ml_id: int = None,
|
|
191
|
-
view_table_name: str = None,
|
|
192
|
-
) -> dict:
|
|
170
|
+
self, *, organization_id: int, organization_ml_id: int = None,
|
|
171
|
+
view_table_name: str = None) -> dict:
|
|
193
172
|
view_table_name = view_table_name or self.default_view_table_name
|
|
194
173
|
organization_ml_dict = {}
|
|
195
174
|
if organization_ml_id:
|
|
196
175
|
organization_ml_dict = self.select_one_dict_by_column_and_value(
|
|
197
176
|
view_table_name="organization_ml_view",
|
|
198
177
|
column_value=organization_ml_id,
|
|
199
|
-
column_name="organization_ml_id"
|
|
200
|
-
)
|
|
178
|
+
column_name="organization_ml_id")
|
|
201
179
|
organization_dict = self.select_one_dict_by_column_and_value(
|
|
202
180
|
view_table_name=view_table_name,
|
|
203
181
|
column_value=organization_id,
|
|
@@ -207,45 +185,36 @@ class OrganizationsLocal(
|
|
|
207
185
|
return {**organization_dict, **organization_ml_dict}
|
|
208
186
|
|
|
209
187
|
def get_organizations_names_list_by_organizations_ids(
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
lang_codes_list: list[LangCode] = None,
|
|
214
|
-
view_table_name: str = None,
|
|
215
|
-
) -> list[str]:
|
|
188
|
+
self, *, organizations_ids_list: list[int],
|
|
189
|
+
lang_codes_list: list[LangCode] = None,
|
|
190
|
+
view_table_name: str = None) -> list[str]:
|
|
216
191
|
lang_codes_list = lang_codes_list or [LangCode.ENGLISH]
|
|
217
192
|
view_table_name = view_table_name or DEFAULT_ML_VIEW_NAME
|
|
218
193
|
organizations_names_list = []
|
|
219
194
|
for organization_id in organizations_ids_list:
|
|
220
|
-
organization_name_dicts
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
195
|
+
organization_name_dicts =\
|
|
196
|
+
self.select_multi_dict_by_column_and_value(
|
|
197
|
+
view_table_name=view_table_name,
|
|
198
|
+
select_clause_value="title, lang_code",
|
|
199
|
+
column_name="organization_id",
|
|
200
|
+
column_value=organization_id)
|
|
226
201
|
|
|
227
202
|
# filter by lang_codes_list
|
|
228
203
|
# TODO: improve performance
|
|
229
204
|
for lang_code in lang_codes_list:
|
|
230
205
|
for organization_name_dict in organization_name_dicts:
|
|
231
|
-
if organization_name_dict.get(
|
|
206
|
+
if organization_name_dict.get('lang_code') ==\
|
|
207
|
+
lang_code.value:
|
|
232
208
|
organizations_names_list.append(
|
|
233
|
-
organization_name_dict.get(
|
|
234
|
-
)
|
|
209
|
+
organization_name_dict.get('title'))
|
|
235
210
|
|
|
236
211
|
return organizations_names_list
|
|
237
212
|
|
|
238
213
|
# Edited by Tal Goodman on 12.7.24
|
|
239
214
|
def get_organizations_ids_and_names_list_by_organizations_ids(
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
lang_codes_list: list[LangCode] = None,
|
|
244
|
-
view_table_name: str = None,
|
|
245
|
-
) -> list[tuple[int, str]]:
|
|
246
|
-
if not organizations_ids_list:
|
|
247
|
-
return []
|
|
248
|
-
|
|
215
|
+
self, *, organizations_ids_list: list[int],
|
|
216
|
+
lang_codes_list: list[LangCode] = None,
|
|
217
|
+
view_table_name: str = None) -> list[tuple[int, str]]:
|
|
249
218
|
lang_codes_list = lang_codes_list or [LangCode.ENGLISH]
|
|
250
219
|
view_table_name = view_table_name or DEFAULT_ML_VIEW_NAME
|
|
251
220
|
organizations_ids_and_names_list = []
|
|
@@ -255,40 +224,34 @@ class OrganizationsLocal(
|
|
|
255
224
|
organizations_ids_and_names_list = self.select_multi_tuple_by_where(
|
|
256
225
|
view_table_name=view_table_name,
|
|
257
226
|
select_clause_value=select_clause_value,
|
|
258
|
-
where=where_clause_value,
|
|
259
|
-
params=organizations_ids_list,
|
|
227
|
+
where=where_clause_value, params=organizations_ids_list
|
|
260
228
|
)
|
|
261
229
|
return organizations_ids_and_names_list
|
|
262
230
|
|
|
263
|
-
def delete_by_organization_id(
|
|
264
|
-
|
|
265
|
-
) -> None:
|
|
231
|
+
def delete_by_organization_id(self, organization_id: int,
|
|
232
|
+
organization_ml_id: int = None) -> None:
|
|
266
233
|
# Delete from organization_table
|
|
267
|
-
self.delete_by_column_and_value(
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
column_value=organization_id,
|
|
271
|
-
)
|
|
234
|
+
self.delete_by_column_and_value(table_name="organization_table",
|
|
235
|
+
column_name="organization_id",
|
|
236
|
+
column_value=organization_id)
|
|
272
237
|
|
|
273
238
|
# Delete from organization_ml_table
|
|
274
239
|
if organization_ml_id:
|
|
275
|
-
self.delete_by_column_and_value(
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
column_value=organization_ml_id,
|
|
279
|
-
)
|
|
240
|
+
self.delete_by_column_and_value(table_name="organization_ml_table",
|
|
241
|
+
column_name="organization_ml_id",
|
|
242
|
+
column_value=organization_ml_id)
|
|
280
243
|
|
|
281
244
|
def get_test_organization_id(self) -> int:
|
|
282
245
|
test_organization_id = self.get_test_entity_id(
|
|
283
|
-
entity_name="organization",
|
|
284
|
-
|
|
246
|
+
entity_name="organization",
|
|
247
|
+
insert_function=self.insert_organization)
|
|
285
248
|
return test_organization_id
|
|
286
249
|
|
|
287
250
|
# TODO Add support of multiple organizations per contact
|
|
288
251
|
# Was def get_update_status(self, *, last_modified_timestamp: str, main_profile_id: int) -> UpdateStatus:
|
|
289
|
-
def get_update_status_and_information_list(
|
|
290
|
-
|
|
291
|
-
|
|
252
|
+
def get_update_status_and_information_list(self, *,
|
|
253
|
+
last_modified_timestamp: str,
|
|
254
|
+
main_profile_id: int | None) -> list[dict]:
|
|
292
255
|
if main_profile_id is None:
|
|
293
256
|
update_status_and_information_list = [
|
|
294
257
|
{"update_status": UpdateStatus.UPDATE_CIRCLEZ}
|
|
@@ -296,16 +259,13 @@ class OrganizationsLocal(
|
|
|
296
259
|
return update_status_and_information_list
|
|
297
260
|
sync_conflict_resolution = SyncConflictResolution()
|
|
298
261
|
# TODO: Shall we also check update_timestamp in organization_table to see if the name was changed?
|
|
299
|
-
update_status_and_information_list: list[dict] =
|
|
262
|
+
update_status_and_information_list: list[dict] = \
|
|
300
263
|
sync_conflict_resolution.get_update_status_and_information_list_by_where(
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
remote_last_modified_timestamp=last_modified_timestamp,
|
|
307
|
-
)
|
|
308
|
-
)
|
|
264
|
+
schema_name="organization_profile",
|
|
265
|
+
view_table_name="organization_profile_view",
|
|
266
|
+
where="profile_id = %s", params=(main_profile_id,),
|
|
267
|
+
local_last_modified_column_name="updated_timestamp",
|
|
268
|
+
remote_last_modified_timestamp=last_modified_timestamp)
|
|
309
269
|
# Add organization_names to update_status_and_information_list
|
|
310
270
|
# TODO: Can we use a list of only the updated organization since the last sync?
|
|
311
271
|
organizations_ids_list = []
|
|
@@ -329,21 +289,17 @@ class OrganizationsLocal(
|
|
|
329
289
|
for update_status_and_information in update_status_and_information_list:
|
|
330
290
|
organization_id = update_status_and_information.get("organization_id")
|
|
331
291
|
if organization_id is not None:
|
|
332
|
-
update_status_and_information["organization_name"] = (
|
|
333
|
-
organizations_ids_and_names_dict.get(organization_id)
|
|
334
|
-
)
|
|
292
|
+
update_status_and_information["organization_name"] = organizations_ids_and_names_dict.get(organization_id)
|
|
335
293
|
|
|
336
294
|
return update_status_and_information_list
|
|
337
295
|
|
|
338
|
-
def get_organization_name_by_organization_identifier(
|
|
339
|
-
self, organization_identifier: str
|
|
340
|
-
) -> str | None:
|
|
296
|
+
def get_organization_name_by_organization_identifier(self, organization_identifier: str) -> str | None:
|
|
341
297
|
organization_name = self.select_one_value_by_column_and_value(
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
298
|
+
select_clause_value="name",
|
|
299
|
+
schema_name="organization",
|
|
300
|
+
view_table_name="organization_view",
|
|
301
|
+
column_name="identifier",
|
|
302
|
+
column_value=organization_identifier,
|
|
303
|
+
)
|
|
348
304
|
|
|
349
305
|
return organization_name
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: organizations-local
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.50
|
|
4
4
|
Summary: PyPI Package for Circles organizations-local Python
|
|
5
5
|
Home-page: https://github.com/circles-zone/organizations-local-python-package
|
|
6
6
|
Author: Circles
|
|
7
7
|
Author-email: info@circlez.ai
|
|
8
8
|
Classifier: Programming Language :: Python :: 3
|
|
9
|
-
Classifier: License :: Other/Proprietary License
|
|
10
9
|
Classifier: Operating System :: OS Independent
|
|
11
10
|
Description-Content-Type: text/markdown
|
|
12
11
|
Requires-Dist: database-mysql-local>=0.0.290
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
organizations_local/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
organizations_local/organizations_constants.py,sha256=mh_XncG0Q8-k_VUCHWVQRdlMXNnf_GCiCcL-rn7R3lw,902
|
|
3
|
+
organizations_local/organizations_local.py,sha256=Ynxtqf_8a4VK42iFbEUM7fIlLwD9AM1xldX7X7SUrXQ,14103
|
|
4
|
+
organizations_local-0.0.50.dist-info/METADATA,sha256=B6aSAUbcy9fKwBaIQ_xw10Top8WFAiQ_0SFwfogGNq4,773
|
|
5
|
+
organizations_local-0.0.50.dist-info/WHEEL,sha256=zaaOINJESkSfm_4HQVc5ssNzHCPXhJm0kEUakpsEHaU,91
|
|
6
|
+
organizations_local-0.0.50.dist-info/top_level.txt,sha256=Y8wRcm3jFTyMdysBub_P8iqX1VOMS0ohUxA1GQdngFU,20
|
|
7
|
+
organizations_local-0.0.50.dist-info/RECORD,,
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
organizations_local/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
-
organizations_local/organizations_constants.py,sha256=mh_XncG0Q8-k_VUCHWVQRdlMXNnf_GCiCcL-rn7R3lw,902
|
|
3
|
-
organizations_local/organizations_local.py,sha256=DYDrEElmPm9Pdn7-q4OkFYueYB5yjcyATXRLAO7d1yM,13904
|
|
4
|
-
organizations_local-0.0.48.dist-info/METADATA,sha256=jB42bYpjsLRGlviQvbXdgZSEOJ_UeM9WxishIImtTXQ,822
|
|
5
|
-
organizations_local-0.0.48.dist-info/WHEEL,sha256=SmOxYU7pzNKBqASvQJ7DjX3XGUF92lrGhMb3R6_iiqI,91
|
|
6
|
-
organizations_local-0.0.48.dist-info/top_level.txt,sha256=Y8wRcm3jFTyMdysBub_P8iqX1VOMS0ohUxA1GQdngFU,20
|
|
7
|
-
organizations_local-0.0.48.dist-info/RECORD,,
|
|
File without changes
|