contact-person-profile-csv-imp-local 0.0.39__py3-none-any.whl → 0.0.43__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,10 +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
- 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,
177
196
  # TODO Add support to criteria_set_id
178
197
  directory_name: str = None, csv_path: str = None, start_index: int = 0, end_index: int = None,
179
- groups_dicts: list[dict] = None, profile_id: int = None) -> dict:
198
+ list_of_group_dicts: list[dict] = None) -> dict:
180
199
  """
181
200
  Insert contacts from CSV file to the database
182
201
  :param data_source_type_id: The data source id
@@ -193,14 +212,23 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
193
212
  :return:
194
213
  """
195
214
  data_source_type_name = DataSources().get_data_source_name_by_id(data_source_type_id)
196
- profile_id_by_email_address = ProfilesLocal().select_one_value_by_column_and_value(
197
- schema_name="profile", view_table_name="profile_view",
198
- select_clause_value="profile_id", column_name="profile.main_email_address",
199
- 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)
226
+ if profile_id is None:
227
+ self.logger.error("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.")
200
229
  system_id = system_id or CONTACT_PERSON_PROFILE_CSV_SYSTEM_ID
201
230
  self.set_schema(schema_name="field")
202
- profile_id = profile_id or profile_id_by_email_address
203
- 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 []
204
232
  '''
205
233
  profile_id = ProfilesLocal().select_one_value_by_column_and_value(
206
234
  schema_name="profile", view_table_name="profile_view",
@@ -219,7 +247,6 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
219
247
  csv_file_path = os.path.join(script_dir, '..', directory_name or '', file_name)
220
248
  if not os.path.exists(csv_file_path):
221
249
  raise FileNotFoundError(f"File {csv_file_path} not found")
222
-
223
250
  # TODO Why do we need it? - Those fields will be added to the contact_dict
224
251
  contact_fields_to_keep = (
225
252
  'name_prefix', 'additional_name', 'name_suffix', 'nickname', 'full_name', 'title', 'department', 'notes',
@@ -229,13 +256,13 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
229
256
  'address1_country', 'address2_street', 'address2_city', 'address2_state', 'address2_postal_code',
230
257
  'address2_country', 'job_title', 'organization', 'display_as')
231
258
 
232
- 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,
233
260
  profile_id=profile_id, system_id=system_id)
234
261
  # We create a new data_source_instance_id everytime we import a new csv file
235
262
  data_source_instance_id = self.__get_data_source_instance_id(
236
263
  data_source_type_id=data_source_type_id, csv_file_path=csv_file_path,
237
264
  user_external_id=user_external_id, file_name=file_name,
238
- user_external_username=username,
265
+ user_external_username=user_external_username,
239
266
  start_index=start_index, end_index=end_index
240
267
  )
241
268
  fields_dictonary = self.data_sources.get_fields_name_from_csv(data_source_type_id)
@@ -509,9 +536,8 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
509
536
 
510
537
  def __insert_link_contact_groups(self, contact_dict: dict) -> list:
511
538
  contact_id = contact_dict.get("contact_id")
512
- # TODO groups_dicts_list
513
- groups = []
514
- linked_groups_results_list = None
539
+ groups_dicts_list = []
540
+ linked_groups_results_list = []
515
541
  organization = contact_dict.get("organization")
516
542
  if organization:
517
543
  organization_group_dict = {
@@ -524,7 +550,8 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
524
550
  "is_main_title": False,
525
551
  "title": organization,
526
552
  }
527
- groups.append(organization_group_dict)
553
+ # TODO Lvalue group Rvalue organization?
554
+ groups_dicts_list.append(organization_group_dict)
528
555
  job_title = contact_dict.get("job_title")
529
556
  if job_title:
530
557
  job_title_group_dict = {
@@ -537,7 +564,7 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
537
564
  "is_main_title": False,
538
565
  "title": job_title,
539
566
  }
540
- groups.append(job_title_group_dict)
567
+ groups_dicts_list.append(job_title_group_dict)
541
568
  if contact_dict.get("groups"):
542
569
  # TODO _contacts_groups_names_list?
543
570
  _groups = contact_dict.get("groups").split(", ")
@@ -552,12 +579,12 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
552
579
  "is_main_title": False,
553
580
  "title": group,
554
581
  }
555
- groups.append(group_dict)
556
- for group in self.groups_list:
557
- groups.append(group)
558
- if len(groups) > 0:
582
+ groups_dicts_list.append(group_dict)
583
+ for group in self.list_of_group_dicts:
584
+ groups_dicts_list.append(group)
585
+ if len(groups_dicts_list) > 0:
559
586
  linked_groups_results_list = self.contact_groups.insert_link_contact_group_with_group_local(
560
- contact_id=contact_id, groups_list_of_dicts=groups)
587
+ contact_id=contact_id, groups_list_of_dicts=groups_dicts_list)
561
588
  contact_dict["linked_group_results_list"] = linked_groups_results_list
562
589
 
563
590
  return linked_groups_results_list
@@ -797,6 +824,8 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
797
824
  proccessed_location_dicts.append(current_location_dict)
798
825
  for email_address in email_addresses_list:
799
826
  country = Country.get_country_name_by_email_address(email_address)
827
+ if country is None:
828
+ continue
800
829
  current_location_dict = {
801
830
  "address_local_language": None,
802
831
  "city": None,
@@ -863,9 +892,20 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
863
892
  system_id=system_id,
864
893
  access_token=""
865
894
  )
895
+ # TODO There can be the same username in multiple user_external_id, we should add more fields system_id, end_timestamp ...
866
896
  user_external_id = self.user_externals_local.select_one_value_by_column_and_value(
867
897
  select_clause_value="user_external_id", column_name="username",
868
898
  column_value=user_external_username, order_by="user_external_id DESC")
899
+ if user_external_id is None:
900
+ self.logger.error("Couldn't find user_external_id in user_external by username.")
901
+ raise Exception("Couldn't find user_external_id in user_external by username.")
902
+ # TODO: Why do we have profile_user_external schema? user_external_table already has profile_id
903
+ profile_user_external_data_dict = {"profile_id": profile_id, "user_external_id": user_external_id}
904
+ profile_user_external_id = self.insert_if_not_exists(
905
+ schema_name="profile_user_external", table_name="profile_user_external_table",
906
+ view_table_name="profile_user_external_view", data_dict=profile_user_external_data_dict,
907
+ data_dict_compare=profile_user_external_data_dict
908
+ )
869
909
 
870
910
  return user_external_id
871
911
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: contact-person-profile-csv-imp-local
3
- Version: 0.0.39
3
+ Version: 0.0.43
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.43.dist-info/METADATA,sha256=wqXf3K-Ibpr5SdGsrOMHbWh7A2rWJwVTljKnRl6htRc,1481
5
+ contact_person_profile_csv_imp_local-0.0.43.dist-info/WHEEL,sha256=R0nc6qTxuoLk7ShA2_Y-UWkN8ZdfDBG2B6Eqpz2WXbs,91
6
+ contact_person_profile_csv_imp_local-0.0.43.dist-info/top_level.txt,sha256=at6BnVzULDB109KZx9Cl9ClCHU4c0ykfV38WX-QR71U,37
7
+ contact_person_profile_csv_imp_local-0.0.43.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (70.1.0)
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=XSwqB1laIT-XdA6CJJMadAiZYXGNWcEWm_B7y9SEJLU,50658
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.39.dist-info/METADATA,sha256=6F0QWD0J7pooK3YZUtLPqW5RWGkcLKauaq8uKZRPCJQ,1481
5
- contact_person_profile_csv_imp_local-0.0.39.dist-info/WHEEL,sha256=cpQTJ5IWu9CdaPViMhC9YzF8gZuS5-vlfoFihTBC86A,91
6
- contact_person_profile_csv_imp_local-0.0.39.dist-info/top_level.txt,sha256=at6BnVzULDB109KZx9Cl9ClCHU4c0ykfV38WX-QR71U,37
7
- contact_person_profile_csv_imp_local-0.0.39.dist-info/RECORD,,