organizations-local 0.0.47__tar.gz → 0.0.48__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: organizations-local
3
- Version: 0.0.47
3
+ Version: 0.0.48
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
@@ -0,0 +1,19 @@
1
+ from logger_local.LoggerComponentEnum import LoggerComponentEnum
2
+
3
+ ORGANIZATIONS_LOCAL_PYTHON_COMPONENT_ID = 286
4
+ ORGANIZATIONS_LOCAL_PYTHON_COMPONENT_NAME = "organization-local-python-package"
5
+ DEVELOPER_EMAIL = "tal.g@circ.zone"
6
+ ORGANIZATIONS_PYTHON_PACKAGE_CODE_LOGGER_OBJECT = {
7
+ "component_id": ORGANIZATIONS_LOCAL_PYTHON_COMPONENT_ID,
8
+ "component_name": ORGANIZATIONS_LOCAL_PYTHON_COMPONENT_NAME,
9
+ "component_category": LoggerComponentEnum.ComponentCategory.Code.value,
10
+ "developer_email": DEVELOPER_EMAIL,
11
+ }
12
+
13
+ ORGANIZATIONS_PYTHON_PACKAGE_TEST_LOGGER_OBJECT = {
14
+ "component_id": ORGANIZATIONS_LOCAL_PYTHON_COMPONENT_ID,
15
+ "component_name": ORGANIZATIONS_LOCAL_PYTHON_COMPONENT_NAME,
16
+ "component_category": LoggerComponentEnum.ComponentCategory.Unit_Test.value,
17
+ "testing_framework": LoggerComponentEnum.testingFramework.pytest.value,
18
+ "developer_email": DEVELOPER_EMAIL,
19
+ }
@@ -45,7 +45,7 @@ DEFAULT_NOT_DELETED_ML_VIEW_NAME = "organization_ml_not_deleted_view"
45
45
  # "start_timestamp",
46
46
  # "end_timestamp",
47
47
  # "main_group_id"
48
- #
48
+ #
49
49
  # organization_ml_table fields:
50
50
  # "organization_ml_id",
51
51
  # "organization_id",
@@ -57,27 +57,49 @@ DEFAULT_NOT_DELETED_ML_VIEW_NAME = "organization_ml_not_deleted_view"
57
57
  # "description"
58
58
 
59
59
 
60
- class OrganizationsLocal(GenericCRUDML, metaclass=MetaLogger,
61
- object=ORGANIZATIONS_PYTHON_PACKAGE_CODE_LOGGER_OBJECT):
60
+ class OrganizationsLocal(
61
+ GenericCRUDML,
62
+ metaclass=MetaLogger,
63
+ object=ORGANIZATIONS_PYTHON_PACKAGE_CODE_LOGGER_OBJECT,
64
+ ):
62
65
  def __init__(self, is_test_data=False) -> None:
63
- GenericCRUDML.__init__(self, default_schema_name=DEFAULT_SCHEMA_NAME,
64
- default_table_name=DEFAULT_TABLE_NAME,
65
- default_column_name=DEFAULT_ID_COLUMN_NAME,
66
- is_test_data=is_test_data)
66
+ GenericCRUDML.__init__(
67
+ self,
68
+ default_schema_name=DEFAULT_SCHEMA_NAME,
69
+ default_table_name=DEFAULT_TABLE_NAME,
70
+ default_column_name=DEFAULT_ID_COLUMN_NAME,
71
+ is_test_data=is_test_data,
72
+ )
67
73
  self.default_view_table_name = DEFAULT_VIEW_NAME
68
74
 
69
75
  @staticmethod
70
76
  def _clean_organization_dict(organization_dict: dict) -> dict:
71
- columns = ("name", "is_approved", "is_main", "point", "location_id", "profile_id", "parent_organization_id",
72
- "non_members_visibility_scope_id", "members_visibility_scope_id",
73
- "Non_members_visibility_profile_id", "main_group_id")
77
+ columns = (
78
+ "name",
79
+ "is_approved",
80
+ "is_main",
81
+ "point",
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
+ )
74
90
  organization_dict = {key: organization_dict.get(key) for key in columns}
75
91
  return organization_dict
76
92
 
77
93
  @staticmethod
78
94
  def _clean_organization_ml_dict(organization_dict: dict) -> dict:
79
- columns = ("lang_code", "is_main", "title", "is_title_approved",
80
- "is_description_approved", "description")
95
+ columns = (
96
+ "lang_code",
97
+ "is_main",
98
+ "title",
99
+ "is_title_approved",
100
+ "is_description_approved",
101
+ "description",
102
+ )
81
103
  organization_ml_dict = {key: organization_dict.get(key) for key in columns}
82
104
  return organization_ml_dict
83
105
 
@@ -89,130 +111,201 @@ class OrganizationsLocal(GenericCRUDML, metaclass=MetaLogger,
89
111
  organization_dict = self._clean_organization_dict(organization_dict)
90
112
  organization_id = GenericCRUDML.insert(self, data_dict=organization_dict)
91
113
  organization_ml_data_dict["organization_id"] = organization_id
92
- organization_ml_id = GenericCRUDML.insert(self, table_name="organization_ml_table",
93
- data_dict=organization_ml_data_dict)
114
+ organization_ml_id = GenericCRUDML.insert(
115
+ self,
116
+ table_name="organization_ml_table",
117
+ data_dict=organization_ml_data_dict,
118
+ )
94
119
 
95
120
  return organization_id, organization_ml_id
96
121
 
97
- def upsert_organization(self, organization_dict: dict, order_by: str = None) -> dict:
98
- lang_code = LangCode.detect_lang_code_restricted(text=organization_dict.get('title'),
99
- #TODO the lang code can be in the organization_dict or in the UserContext, I'm not sure English as default is correct
100
- default_lang_code=LangCode.ENGLISH)
122
+ def upsert_organization(
123
+ self, organization_dict: dict, order_by: str = None
124
+ ) -> dict:
125
+ lang_code = LangCode.detect_lang_code_restricted(
126
+ text=organization_dict.get("title"),
127
+ # TODO the lang code can be in the organization_dict or in the UserContext, I'm not sure English as default is correct
128
+ default_lang_code=LangCode.ENGLISH,
129
+ )
101
130
  organization_ml_dict = self._clean_organization_ml_dict(organization_dict)
102
131
  organization_dict = self._clean_organization_dict(organization_dict)
103
132
 
104
- # TODO Why do we need to do this if outside of GenericCrud in every entity, can we move this "if" into the Generic Crud method? Can we avoid two methods? The parameters of the two methods are the same?
105
- if "(" and ")" in organization_dict.get('title', ''):
106
- organization_id, organzation_ml_ids_list = GenericCRUDML.upsert_value_with_abbreviations(
107
- self, data_ml_dict=organization_ml_dict, lang_code=lang_code,
108
- data_dict=organization_dict, schema_name=DEFAULT_SCHEMA_NAME, table_name=DEFAULT_TABLE_NAME,
109
- ml_table_name=DEFAULT_ML_TABLE_NAME, order_by=order_by)
133
+ # TODO Why do we need to do this if outside of GenericCrud in every entity, can we move this "if" into the Generic Crud method? Can we avoid two methods? The parameters of the two methods are the same? # noqa
134
+ if "(" and ")" in organization_dict.get("title", ""):
135
+ organization_id, organzation_ml_ids_list = (
136
+ GenericCRUDML.upsert_value_with_abbreviations(
137
+ self,
138
+ data_ml_dict=organization_ml_dict,
139
+ lang_code=lang_code,
140
+ data_dict=organization_dict,
141
+ schema_name=DEFAULT_SCHEMA_NAME,
142
+ table_name=DEFAULT_TABLE_NAME,
143
+ ml_table_name=DEFAULT_ML_TABLE_NAME,
144
+ order_by=order_by,
145
+ )
146
+ )
110
147
  else:
111
148
  organization_id, organzation_ml_id = GenericCRUDML.upsert_value(
112
- self, data_ml_dict=organization_ml_dict, lang_code=lang_code,
113
- data_dict=organization_dict, schema_name=DEFAULT_SCHEMA_NAME, table_name=DEFAULT_TABLE_NAME,
114
- ml_table_name=DEFAULT_ML_TABLE_NAME, order_by=order_by)
149
+ self,
150
+ data_ml_dict=organization_ml_dict,
151
+ lang_code=lang_code,
152
+ data_dict=organization_dict,
153
+ schema_name=DEFAULT_SCHEMA_NAME,
154
+ table_name=DEFAULT_TABLE_NAME,
155
+ ml_table_name=DEFAULT_ML_TABLE_NAME,
156
+ order_by=order_by,
157
+ )
115
158
  organzation_ml_ids_list = [organzation_ml_id]
116
159
 
117
- #TODO upsert_result_dict
160
+ # TODO upsert_result_dict
118
161
  upsert_information = {
119
162
  "organization_id": organization_id,
120
- "organization_ml_ids_list": organzation_ml_ids_list
163
+ "organization_ml_ids_list": organzation_ml_ids_list,
121
164
  }
122
165
 
123
166
  return upsert_information
124
167
 
125
- def update_organization(self, *, organization_id: int, organization_ml_id: int, organization_dict: dict) -> None:
168
+ def update_organization(
169
+ self, *, organization_id: int, organization_ml_id: int, organization_dict: dict
170
+ ) -> None:
126
171
  # TODO: should we have such a method in CRUD ML? Same for delete
127
172
  organization_ml_dict = self._clean_organization_ml_dict(organization_dict)
128
173
  organization_ml_dict["organization_id"] = organization_id
129
174
  organization_dict = self._clean_organization_dict(organization_dict)
130
- GenericCRUDML.update_by_column_and_value(self, column_value=organization_id,
131
- data_dict=organization_dict)
132
- GenericCRUDML.update_by_column_and_value(self, table_name="organization_ml_table",
133
- column_value=organization_ml_id, data_dict=organization_ml_dict,
134
- column_name="organization_ml_id")
175
+ GenericCRUDML.update_by_column_and_value(
176
+ self, column_value=organization_id, data_dict=organization_dict
177
+ )
178
+ GenericCRUDML.update_by_column_and_value(
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
+ )
135
185
 
136
186
  def get_organization_dict_by_organization_id(
137
- self, *, organization_id: int, organization_ml_id: int = None, view_table_name: str = None) -> dict:
187
+ self,
188
+ *,
189
+ organization_id: int,
190
+ organization_ml_id: int = None,
191
+ view_table_name: str = None,
192
+ ) -> dict:
138
193
  view_table_name = view_table_name or self.default_view_table_name
139
194
  organization_ml_dict = {}
140
195
  if organization_ml_id:
141
196
  organization_ml_dict = self.select_one_dict_by_column_and_value(
142
197
  view_table_name="organization_ml_view",
143
- column_value=organization_ml_id, column_name="organization_ml_id")
198
+ column_value=organization_ml_id,
199
+ column_name="organization_ml_id",
200
+ )
144
201
  organization_dict = self.select_one_dict_by_column_and_value(
145
202
  view_table_name=view_table_name,
146
- column_value=organization_id, column_name="organization_id")
203
+ column_value=organization_id,
204
+ column_name="organization_id",
205
+ )
147
206
 
148
207
  return {**organization_dict, **organization_ml_dict}
149
208
 
150
209
  def get_organizations_names_list_by_organizations_ids(
151
- self, *, organizations_ids_list: list[int], lang_codes_list: list[LangCode] = None,
152
- view_table_name: str = None) -> list[str]:
210
+ self,
211
+ *,
212
+ organizations_ids_list: list[int],
213
+ lang_codes_list: list[LangCode] = None,
214
+ view_table_name: str = None,
215
+ ) -> list[str]:
153
216
  lang_codes_list = lang_codes_list or [LangCode.ENGLISH]
154
217
  view_table_name = view_table_name or DEFAULT_ML_VIEW_NAME
155
218
  organizations_names_list = []
156
219
  for organization_id in organizations_ids_list:
157
220
  organization_name_dicts = self.select_multi_dict_by_column_and_value(
158
- view_table_name=view_table_name, select_clause_value="title, lang_code",
159
- column_name="organization_id", column_value=organization_id)
221
+ view_table_name=view_table_name,
222
+ select_clause_value="title, lang_code",
223
+ column_name="organization_id",
224
+ column_value=organization_id,
225
+ )
160
226
 
161
227
  # filter by lang_codes_list
162
228
  # TODO: improve performance
163
229
  for lang_code in lang_codes_list:
164
230
  for organization_name_dict in organization_name_dicts:
165
- if organization_name_dict.get('lang_code') == lang_code.value:
166
- organizations_names_list.append(organization_name_dict.get('title'))
231
+ if organization_name_dict.get("lang_code") == lang_code.value:
232
+ organizations_names_list.append(
233
+ organization_name_dict.get("title")
234
+ )
167
235
 
168
236
  return organizations_names_list
169
237
 
170
238
  # Edited by Tal Goodman on 12.7.24
171
239
  def get_organizations_ids_and_names_list_by_organizations_ids(
172
- self, *, organizations_ids_list: list[int], lang_codes_list: list[LangCode] = None,
173
- view_table_name: str = None) -> list[tuple[int, str]]:
240
+ self,
241
+ *,
242
+ organizations_ids_list: list[int],
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
+
174
249
  lang_codes_list = lang_codes_list or [LangCode.ENGLISH]
175
250
  view_table_name = view_table_name or DEFAULT_ML_VIEW_NAME
176
251
  organizations_ids_and_names_list = []
177
252
  select_clause_value = "organization_id, title"
178
- placeholders = ', '.join(['%s'] * len(organizations_ids_list))
253
+ placeholders = ", ".join(["%s"] * len(organizations_ids_list))
179
254
  where_clause_value = f"organization_id in ({placeholders})"
180
255
  organizations_ids_and_names_list = self.select_multi_tuple_by_where(
181
- view_table_name=view_table_name, select_clause_value=select_clause_value,
182
- where=where_clause_value, params=organizations_ids_list
256
+ view_table_name=view_table_name,
257
+ select_clause_value=select_clause_value,
258
+ where=where_clause_value,
259
+ params=organizations_ids_list,
183
260
  )
184
261
  return organizations_ids_and_names_list
185
262
 
186
-
187
- def delete_by_organization_id(self, organization_id: int, organization_ml_id: int = None) -> None:
263
+ def delete_by_organization_id(
264
+ self, organization_id: int, organization_ml_id: int = None
265
+ ) -> None:
188
266
  # Delete from organization_table
189
- self.delete_by_column_and_value(table_name="organization_table",
190
- column_name="organization_id", column_value=organization_id)
267
+ self.delete_by_column_and_value(
268
+ table_name="organization_table",
269
+ column_name="organization_id",
270
+ column_value=organization_id,
271
+ )
191
272
 
192
273
  # Delete from organization_ml_table
193
274
  if organization_ml_id:
194
- self.delete_by_column_and_value(table_name="organization_ml_table",
195
- column_name="organization_ml_id", column_value=organization_ml_id)
196
-
275
+ self.delete_by_column_and_value(
276
+ table_name="organization_ml_table",
277
+ column_name="organization_ml_id",
278
+ column_value=organization_ml_id,
279
+ )
197
280
 
198
281
  def get_test_organization_id(self) -> int:
199
282
  test_organization_id = self.get_test_entity_id(
200
- entity_name="organization", insert_function=self.insert_organization)
283
+ entity_name="organization", insert_function=self.insert_organization
284
+ )
201
285
  return test_organization_id
202
286
 
203
-
204
287
  # TODO Add support of multiple organizations per contact
205
288
  # Was def get_update_status(self, *, last_modified_timestamp: str, main_profile_id: int) -> UpdateStatus:
206
- def get_update_status_and_information_list(self, *, last_modified_timestamp: str, main_profile_id: int or None) -> list[dict]:
289
+ def get_update_status_and_information_list(
290
+ self, *, last_modified_timestamp: str, main_profile_id: int | None
291
+ ) -> list[dict]:
207
292
  if main_profile_id is None:
208
- update_status_and_information_list = [{"update_status": UpdateStatus.UPDATE_CIRCLEZ}]
293
+ update_status_and_information_list = [
294
+ {"update_status": UpdateStatus.UPDATE_CIRCLEZ}
295
+ ]
209
296
  return update_status_and_information_list
210
297
  sync_conflict_resolution = SyncConflictResolution()
211
298
  # TODO: Shall we also check update_timestamp in organization_table to see if the name was changed?
212
- update_status_and_information_list: list[dict] = sync_conflict_resolution.get_update_status_and_information_list_by_where(
213
- schema_name="organization_profile", view_table_name="organization_profile_view",
214
- where="profile_id = %s", params=(main_profile_id,), local_last_modified_column_name="updated_timestamp",
215
- remote_last_modified_timestamp=last_modified_timestamp)
299
+ update_status_and_information_list: list[dict] = (
300
+ sync_conflict_resolution.get_update_status_and_information_list_by_where(
301
+ schema_name="organization_profile",
302
+ view_table_name="organization_profile_view",
303
+ where="profile_id = %s",
304
+ params=(main_profile_id,),
305
+ local_last_modified_column_name="updated_timestamp",
306
+ remote_last_modified_timestamp=last_modified_timestamp,
307
+ )
308
+ )
216
309
  # Add organization_names to update_status_and_information_list
217
310
  # TODO: Can we use a list of only the updated organization since the last sync?
218
311
  organizations_ids_list = []
@@ -221,28 +314,36 @@ class OrganizationsLocal(GenericCRUDML, metaclass=MetaLogger,
221
314
  if organization_id is not None:
222
315
  organizations_ids_list.append(organization_id)
223
316
 
224
- organizations_ids_and_names_list = self.get_organizations_ids_and_names_list_by_organizations_ids(
225
- organizations_ids_list=organizations_ids_list,
226
- view_table_name="organization_ml_view")
317
+ organizations_ids_and_names_list = (
318
+ self.get_organizations_ids_and_names_list_by_organizations_ids(
319
+ organizations_ids_list=organizations_ids_list,
320
+ view_table_name="organization_ml_view",
321
+ )
322
+ )
227
323
 
228
324
  # Convert organizations_ids_and_names_list to a dictionary
229
- organizations_ids_and_names_dict = {item[0]: item[1] for item in organizations_ids_and_names_list}
325
+ organizations_ids_and_names_dict = {
326
+ item[0]: item[1] for item in organizations_ids_and_names_list
327
+ }
230
328
 
231
329
  for update_status_and_information in update_status_and_information_list:
232
330
  organization_id = update_status_and_information.get("organization_id")
233
331
  if organization_id is not None:
234
- update_status_and_information["organization_name"] = organizations_ids_and_names_dict.get(organization_id)
235
-
236
- return update_status_and_information_list
332
+ update_status_and_information["organization_name"] = (
333
+ organizations_ids_and_names_dict.get(organization_id)
334
+ )
237
335
 
336
+ return update_status_and_information_list
238
337
 
239
- def get_organization_name_by_organization_identifier(self, organization_identifier: str) -> str or None:
240
- organization_name=self.select_one_value_by_column_and_value(
241
- select_clause_value="name",
242
- schema_name="organization",
243
- view_table_name="organization_view",
244
- column_name="identifier",
245
- column_value=organization_identifier,
246
- )
338
+ def get_organization_name_by_organization_identifier(
339
+ self, organization_identifier: str
340
+ ) -> str | None:
341
+ organization_name = self.select_one_value_by_column_and_value(
342
+ select_clause_value="name",
343
+ schema_name="organization",
344
+ view_table_name="organization_view",
345
+ column_name="identifier",
346
+ column_value=organization_identifier,
347
+ )
247
348
 
248
- return organization_name
349
+ return organization_name
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: organizations-local
3
- Version: 0.0.47
3
+ Version: 0.0.48
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
@@ -5,25 +5,25 @@ package_dir = PACKAGE_NAME.replace("-", "_")
5
5
 
6
6
  setuptools.setup(
7
7
  name=PACKAGE_NAME,
8
- version='0.0.47', # https://pypi.org/project/organizations-local/
8
+ version="0.0.48", # https://pypi.org/project/organizations-local/
9
9
  author="Circles",
10
10
  author_email="info@circlez.ai",
11
11
  description="PyPI Package for Circles organizations-local Python",
12
12
  long_description="PyPI Package for Circles organizations-local Python",
13
- long_description_content_type='text/markdown',
13
+ long_description_content_type="text/markdown",
14
14
  url=f"https://github.com/circles-zone/{PACKAGE_NAME}-python-package",
15
15
  packages=[package_dir],
16
- package_dir={package_dir: f'{package_dir}/src'},
17
- package_data={package_dir: ['*.py']},
16
+ package_dir={package_dir: f"{package_dir}/src"},
17
+ package_data={package_dir: ["*.py"]},
18
18
  classifiers=[
19
19
  "Programming Language :: Python :: 3",
20
20
  "License :: Other/Proprietary License",
21
21
  "Operating System :: OS Independent",
22
22
  ],
23
23
  install_requires=[
24
- 'database-mysql-local>=0.0.290',
25
- 'language-remote>=0.0.20',
26
- 'location-local>=0.0.8',
27
- 'user-context-remote>=0.0.58',
24
+ "database-mysql-local>=0.0.290",
25
+ "language-remote>=0.0.20",
26
+ "location-local>=0.0.8",
27
+ "user-context-remote>=0.0.58",
28
28
  ],
29
29
  )
@@ -1,19 +0,0 @@
1
- from logger_local.LoggerComponentEnum import LoggerComponentEnum
2
-
3
- ORGANIZATIONS_LOCAL_PYTHON_COMPONENT_ID = 286
4
- ORGANIZATIONS_LOCAL_PYTHON_COMPONENT_NAME = "organization-local-python-package"
5
- DEVELOPER_EMAIL = "tal.g@circ.zone"
6
- ORGANIZATIONS_PYTHON_PACKAGE_CODE_LOGGER_OBJECT = {
7
- 'component_id': ORGANIZATIONS_LOCAL_PYTHON_COMPONENT_ID,
8
- 'component_name': ORGANIZATIONS_LOCAL_PYTHON_COMPONENT_NAME,
9
- 'component_category': LoggerComponentEnum.ComponentCategory.Code.value,
10
- 'developer_email': DEVELOPER_EMAIL
11
- }
12
-
13
- ORGANIZATIONS_PYTHON_PACKAGE_TEST_LOGGER_OBJECT = {
14
- 'component_id': ORGANIZATIONS_LOCAL_PYTHON_COMPONENT_ID,
15
- 'component_name': ORGANIZATIONS_LOCAL_PYTHON_COMPONENT_NAME,
16
- 'component_category': LoggerComponentEnum.ComponentCategory.Unit_Test.value,
17
- 'testing_framework': LoggerComponentEnum.testingFramework.pytest.value,
18
- 'developer_email': DEVELOPER_EMAIL
19
- }