contact-person-profile-csv-imp-local 0.0.40__py3-none-any.whl → 0.0.44__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.
@@ -30,10 +30,10 @@ from contact_local.contact_local import ContactsLocal
30
30
  from contact_group_local.contact_group import ContactGroups
31
31
  from contact_email_address_local.contact_email_addresses_local import ContactEmailAdressesLocal
32
32
 
33
- # import pycountry
34
33
  from phonenumbers import NumberParseException
35
34
  from user_context_remote.user_context import UserContext
36
35
  from user_external_local.user_externals_local import UserExternalsLocal
36
+ from group_local.group_type import group_type
37
37
 
38
38
  # from contact_local.contact_local import ContactsLocal
39
39
  # from database_mysql_local.generic_crud import GenericCRUD
@@ -107,39 +107,58 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
107
107
  object=CSVToContactPersonProfileConstants.CSV_LOCAL_PYTHON_PACKAGE_CODE_LOGGER_OBJECT):
108
108
  # TODO Shall we have the groups_str parameter in the constructor or when running the each import so we can use different groups_str for every import
109
109
  def __init__(self, groups_str: str = None, is_test_data: bool = False) -> None:
110
+ self._instances = {}
111
+ self.classes = [ContactsLocal, OrganizationProfilesLocal, ContactPersonsLocal, ContactUserExternalLocal,
112
+ ContactProfilesLocal, ContactGroups, ContactEmailAdressesLocal, ContactPhoneLocal,
113
+ ContactLocationLocal, UserExternalsLocal, OrganizationsLocal, DomainLocal, ImportersLocal]
114
+ self.instances_names = ['contacts_local', 'organization_profiles', 'contact_persons', 'contact_user_external',
115
+ 'contact_profiles', 'contact_groups', 'contact_email_addresses', 'contact_phone',
116
+ 'contact_location', 'user_externals_local', 'organizations_local', 'domain_local',
117
+ 'importers_local']
110
118
  GenericCRUD.__init__(self, default_schema_name="field", default_column_name="field_id",
111
119
  default_table_name="field_table", default_view_table_name="field_view",
112
120
  is_test_data=is_test_data)
113
121
  self.contact_entity_type_id = self.select_one_value_by_column_and_value(
114
122
  schema_name="entity_type", view_table_name="entity_type_ml_en_view",
115
123
  select_clause_value="entity_type_id", column_name="title", column_value="Contact")
116
- self.groups_list: list[str] = [group.strip() for group in groups_str.split(",")] if groups_str else []
124
+ self.list_of_group_dicts: list[str] = [group.strip() for group in groups_str.split(",")] if groups_str else []
117
125
  self.user_context = UserContext()
118
- self.organization_profiles = OrganizationProfilesLocal(is_test_data=is_test_data)
119
- self.contact_persons = ContactPersonsLocal(is_test_data=is_test_data)
120
- self.contact_user_external = ContactUserExternalLocal(is_test_data=is_test_data)
121
- self.contact_profiles = ContactProfilesLocal(is_test_data=is_test_data)
122
- self.contact_groups = ContactGroups(is_test_data=is_test_data)
123
- self.contact_email_addresses = ContactEmailAdressesLocal(is_test_data=is_test_data)
124
- self.contact_phone = ContactPhoneLocal(is_test_data=is_test_data)
125
- self.contact_location = ContactLocationLocal(is_test_data=is_test_data)
126
- self.contacts_local = ContactsLocal(is_test_data=is_test_data)
127
- self.user_externals_local = UserExternalsLocal(is_test_data=is_test_data)
128
- self.organizations_local = OrganizationsLocal(is_test_data=is_test_data)
129
- self.domain_local = DomainLocal(is_test_data=is_test_data)
130
- self.importers_local = ImportersLocal()
126
+ self.organization_profiles: OrganizationProfilesLocal = None
127
+ self.contact_persons: ContactPersonsLocal = None
128
+ self.contact_user_external: ContactUserExternalLocal = None
129
+ self.contact_profiles: ContactProfilesLocal = None
130
+ self.contact_groups: ContactGroups = None
131
+ self.contact_email_addresses: ContactEmailAdressesLocal = None
132
+ self.contact_phone: ContactPhoneLocal = None
133
+ self.contact_location: ContactLocationLocal = None
134
+ self.contacts_local: ContactsLocal = None
135
+ self.user_externals_local: UserExternalsLocal = None
136
+ self.organizations_local: OrganizationsLocal = None
137
+ self.domain_local: DomainLocal = None
138
+ self.importers_local: ImportersLocal = None
139
+
131
140
  self.data_sources = DataSources()
132
- self.groups_list = None
133
- self.unknown_main_group_type_id = self.select_one_value_by_column_and_value(
134
- schema_name='group', view_table_name='group_type_ml_view',
135
- select_clause_value='group_type_id', column_name='title', column_value='Unknown')
136
- self.organization_main_group_type_id = self.select_one_value_by_column_and_value(
137
- schema_name='group', view_table_name='group_type_ml_view',
138
- select_clause_value='group_type_id', column_name='title', column_value='Organization')
139
- self.job_title_main_group_type_id = self.select_one_value_by_column_and_value(
140
- schema_name='group', view_table_name='group_type_ml_view',
141
- select_clause_value='group_type_id', column_name='title', column_value='Job Title')
142
-
141
+ self.list_of_group_dicts = None
142
+ self.unknown_main_group_type_id = group_type.get('Unknown')
143
+ self.organization_main_group_type_id = group_type.get('Organization')
144
+ self.job_title_main_group_type_id = group_type.get('Job Title')
145
+
146
+ def __getattribute__(self, name):
147
+ # Call the original __getattribute__
148
+ value = super().__getattribute__(name)
149
+
150
+ # If value is None and name is in instances_names, initialize it
151
+ if value is None and name in self.instances_names:
152
+ for index, cls in enumerate(self.classes):
153
+ if self.instances_names[index] == name:
154
+ instance = cls()
155
+ self._instances[name] = instance
156
+ setattr(self, name, instance)
157
+ return instance
158
+
159
+ # Otherwise, return the value
160
+ return value
161
+
143
162
 
144
163
  # # TODO Does this function should be here on in https://github.com/circles-zone/variable-local-python-package/tree/dev/variable_local_python_package/variable_local/src "field/field.py"?
145
164
  # def __get_field_name(self, field_id: int, data_source_type_id: int) -> str:
@@ -173,11 +192,10 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
173
192
  # TODO Align the parameters between import-contact-csv with sync-google-contact
174
193
  # TODO Can we please add groups_str parameter to both sync-google-contact and import-contact-csv where we add all contacts to those groups?
175
194
  def insert_update_contact_from_csv(
176
- # TODO username -> user_external_username
177
- self, *, username: str, email_address: str, data_source_type_id: int, file_name: str = None, system_id: int = None,
195
+ self, *, user_external_username: str, email_address: str, data_source_type_id: int, file_name: str = None, system_id: int = None,
178
196
  # TODO Add support to criteria_set_id
179
197
  directory_name: str = None, csv_path: str = None, start_index: int = 0, end_index: int = None,
180
- groups_dicts: list[dict] = None) -> dict:
198
+ list_of_group_dicts: list[dict] = None) -> dict:
181
199
  """
182
200
  Insert contacts from CSV file to the database
183
201
  :param data_source_type_id: The data source id
@@ -194,16 +212,23 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
194
212
  :return:
195
213
  """
196
214
  data_source_type_name = DataSources().get_data_source_name_by_id(data_source_type_id)
197
- profile_id = ProfilesLocal().select_one_value_by_column_and_value(
198
- schema_name="profile", view_table_name="profile_view",
199
- select_clause_value="profile_id", column_name="profile.main_email_address",
200
- column_value=email_address)
215
+ # TODO There can be multiple profiles with the same email, why not to query `user_external_table`.`main_profile_id`?
216
+ # Answer: first, We can't query tables with GenericCRUD, second, we may not find profile_id in user_external table
217
+ # and may have to insert a new record to user_external_table, in this case we need profile_id from profile_view
218
+ profile_id = self.select_one_value_by_column_and_value(
219
+ schema_name="user_external", view_table_name="user_external_view",
220
+ select_clause_value="main_profile_id", column_name="username", column_value=user_external_username)
221
+ if profile_id is None:
222
+ profile_id = ProfilesLocal().select_one_value_by_column_and_value(
223
+ schema_name="profile", view_table_name="profile_view",
224
+ select_clause_value="profile_id", column_name="profile.main_email_address",
225
+ column_value=email_address)
201
226
  if profile_id is None:
202
227
  self.logger.error("Couldn't find profile_id in profile_view by email_address.")
203
- raise Exception("Couldn't find profile_id in profile_view by email_address.")
228
+ raise Exception("Couldn't find profile_id in user_external or profile_view.")
204
229
  system_id = system_id or CONTACT_PERSON_PROFILE_CSV_SYSTEM_ID
205
230
  self.set_schema(schema_name="field")
206
- self.groups_list = groups_dicts if groups_dicts else []
231
+ self.list_of_group_dicts = list_of_group_dicts if list_of_group_dicts else []
207
232
  '''
208
233
  profile_id = ProfilesLocal().select_one_value_by_column_and_value(
209
234
  schema_name="profile", view_table_name="profile_view",
@@ -222,7 +247,6 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
222
247
  csv_file_path = os.path.join(script_dir, '..', directory_name or '', file_name)
223
248
  if not os.path.exists(csv_file_path):
224
249
  raise FileNotFoundError(f"File {csv_file_path} not found")
225
-
226
250
  # TODO Why do we need it? - Those fields will be added to the contact_dict
227
251
  contact_fields_to_keep = (
228
252
  'name_prefix', 'additional_name', 'name_suffix', 'nickname', 'full_name', 'title', 'department', 'notes',
@@ -232,13 +256,13 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
232
256
  'address1_country', 'address2_street', 'address2_city', 'address2_state', 'address2_postal_code',
233
257
  'address2_country', 'job_title', 'organization', 'display_as')
234
258
 
235
- user_external_id = self.__get_user_external_id(user_external_username=username,
259
+ user_external_id = self.__get_user_external_id(user_external_username=user_external_username,
236
260
  profile_id=profile_id, system_id=system_id)
237
261
  # We create a new data_source_instance_id everytime we import a new csv file
238
262
  data_source_instance_id = self.__get_data_source_instance_id(
239
263
  data_source_type_id=data_source_type_id, csv_file_path=csv_file_path,
240
264
  user_external_id=user_external_id, file_name=file_name,
241
- user_external_username=username,
265
+ user_external_username=user_external_username,
242
266
  start_index=start_index, end_index=end_index
243
267
  )
244
268
  fields_dictonary = self.data_sources.get_fields_name_from_csv(data_source_type_id)
@@ -526,6 +550,7 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
526
550
  "is_main_title": False,
527
551
  "title": organization,
528
552
  }
553
+ # TODO Lvalue group Rvalue organization?
529
554
  groups_dicts_list.append(organization_group_dict)
530
555
  job_title = contact_dict.get("job_title")
531
556
  if job_title:
@@ -555,7 +580,7 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
555
580
  "title": group,
556
581
  }
557
582
  groups_dicts_list.append(group_dict)
558
- for group in self.groups_list:
583
+ for group in self.list_of_group_dicts:
559
584
  groups_dicts_list.append(group)
560
585
  if len(groups_dicts_list) > 0:
561
586
  linked_groups_results_list = self.contact_groups.insert_link_contact_group_with_group_local(
@@ -867,6 +892,7 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
867
892
  system_id=system_id,
868
893
  access_token=""
869
894
  )
895
+ # TODO There can be the same username in multiple user_external_id, we should add more fields system_id, end_timestamp ...
870
896
  user_external_id = self.user_externals_local.select_one_value_by_column_and_value(
871
897
  select_clause_value="user_external_id", column_name="username",
872
898
  column_value=user_external_username, order_by="user_external_id DESC")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: contact-person-profile-csv-imp-local
3
- Version: 0.0.40
3
+ Version: 0.0.44
4
4
  Summary: PyPI Package for Circles CSVToContactPersonProfile-local Local/Remote Python
5
5
  Home-page: https://github.com/circles-zone/contact-person-profile-csv-imp-local-python-package
6
6
  Author: Circles
@@ -14,7 +14,7 @@ Requires-Dist: logger-local >=0.0.135
14
14
  Requires-Dist: database-mysql-local >=0.0.290
15
15
  Requires-Dist: user-context-remote >=0.0.77
16
16
  Requires-Dist: contact-email-address-local >=0.0.8
17
- Requires-Dist: contact-group-local >=0.0.30
17
+ Requires-Dist: contact-group-local >=0.0.68
18
18
  Requires-Dist: contact-location-local >=0.0.14
19
19
  Requires-Dist: contact-notes-local >=0.0.33
20
20
  Requires-Dist: contact-persons-local >=0.0.8
@@ -0,0 +1,7 @@
1
+ contact_person_profile_csv_imp_local/CSVToContactPersonProfile.py,sha256=eRkMHtfPCNHnQoYrpS_dT8e7jQdduutBmsf8ycdbzCU,53218
2
+ contact_person_profile_csv_imp_local/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ contact_person_profile_csv_imp_local/contact_person_profile_csv_imp_local_constants.py,sha256=SsMFKnI7y3P_kQxH21rxKnX7H4MZlemBy5vuv_Ns_a4,1180
4
+ contact_person_profile_csv_imp_local-0.0.44.dist-info/METADATA,sha256=pxPw0TvkefcoW_J3NfEAe73pMdQpiuajs8fAbghn4cU,1481
5
+ contact_person_profile_csv_imp_local-0.0.44.dist-info/WHEEL,sha256=R0nc6qTxuoLk7ShA2_Y-UWkN8ZdfDBG2B6Eqpz2WXbs,91
6
+ contact_person_profile_csv_imp_local-0.0.44.dist-info/top_level.txt,sha256=at6BnVzULDB109KZx9Cl9ClCHU4c0ykfV38WX-QR71U,37
7
+ contact_person_profile_csv_imp_local-0.0.44.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (70.1.1)
2
+ Generator: setuptools (72.1.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,7 +0,0 @@
1
- contact_person_profile_csv_imp_local/CSVToContactPersonProfile.py,sha256=sdXxhOg-jmkp28bPqesrdIez0uD1CIWgRPtTwT2Qr-M,51720
2
- contact_person_profile_csv_imp_local/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
- contact_person_profile_csv_imp_local/contact_person_profile_csv_imp_local_constants.py,sha256=SsMFKnI7y3P_kQxH21rxKnX7H4MZlemBy5vuv_Ns_a4,1180
4
- contact_person_profile_csv_imp_local-0.0.40.dist-info/METADATA,sha256=xVeWFDCjFs2Fp8ur2QNg3TGA_avwh8CdDACABrUJbe4,1481
5
- contact_person_profile_csv_imp_local-0.0.40.dist-info/WHEEL,sha256=mguMlWGMX-VHnMpKOjjQidIo1ssRlCFu4a4mBpz1s2M,91
6
- contact_person_profile_csv_imp_local-0.0.40.dist-info/top_level.txt,sha256=at6BnVzULDB109KZx9Cl9ClCHU4c0ykfV38WX-QR71U,37
7
- contact_person_profile_csv_imp_local-0.0.40.dist-info/RECORD,,