contact-person-profile-csv-imp-local 0.0.29__py3-none-any.whl → 0.0.31__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.
@@ -19,6 +19,7 @@ from importer_local.ImportersLocal import ImportersLocal
19
19
  from database_mysql_local.point import Point
20
20
  from database_mysql_local.generic_crud import GenericCRUD
21
21
  from contact_user_external_local.contact_user_external_local import ContactUserExternalLocal
22
+ from profile_local.profiles_local import ProfilesLocal
22
23
  from contact_profile_local.contact_profiles_local import ContactProfilesLocal
23
24
  from contact_phone_local.contact_phone_local import ContactPhoneLocal
24
25
  from phones_local.phones_local import PhonesLocal
@@ -127,6 +128,7 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
127
128
  self.domain_local = DomainLocal(is_test_data=is_test_data)
128
129
  self.importers_local = ImportersLocal()
129
130
  self.data_sources = DataSources()
131
+ self.groups_list = None
130
132
 
131
133
  # # 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"?
132
134
  # def __get_field_name(self, field_id: int, data_source_type_id: int) -> str:
@@ -160,9 +162,10 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
160
162
  # TODO Align the parameters between import-contact-csv with sync-google-contact
161
163
  # 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?
162
164
  def insert_update_contact_from_csv(
163
- self, *, data_source_type_id: int, file_name: str = None, user_external_username: str,
165
+ self, *, data_source_type_id: int, file_name: str = None, user_external_username: str, system_id: int = None,
164
166
  # TODO Add support to criteria_set_id
165
- directory_name: str = None, csv_path: str = None, start_index: int = 0, end_index: int = None) -> dict:
167
+ directory_name: str = None, csv_path: str = None, start_index: int = 0, end_index: int = None,
168
+ groups_str: str = None, profile_id: int = None) -> dict:
166
169
  """
167
170
  Insert contacts from CSV file to the database
168
171
  :param data_source_type_id: The data source ID
@@ -174,7 +177,21 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
174
177
  :param end_index: The end index
175
178
  :return:
176
179
  """
177
-
180
+ '''
181
+ profile_id_by_email_address = ProfilesLocal().select_one_value_by_column_and_value(
182
+ schema_name="profile", view_table_name="profile_view",
183
+ select_clause_value="profile_id", column_name="profile.main_email_address",
184
+ column_value=user_external_username)
185
+ '''
186
+ profile_id = profile_id or self.user_context.get_effective_profile_id()
187
+ self.groups_list = [group.strip() for group in groups_str.split(",")] if groups_str else []
188
+ '''
189
+ profile_id = ProfilesLocal().select_one_value_by_column_and_value(
190
+ schema_name="profile", view_table_name="profile_view",
191
+ select_clause_value="profile_id", column_name="profile.main_email_address",
192
+ column_value=user_external_username)
193
+ '''
194
+ self.logger.info(f"profile_id: {profile_id}")
178
195
  # TODO Please explain
179
196
  # if csv_path is provided then we will use the full path
180
197
  # if csv_path is not provided then we will use the directory_name and file_name to create the full path
@@ -191,12 +208,12 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
191
208
  contact_fields_to_keep = (
192
209
  'name_prefix', 'additional_name', 'name_suffix', 'nickname', 'full_name', 'title', 'department', 'notes',
193
210
  'first_name', 'last_name', 'phone1', 'phone2', 'phone3', 'birthday', 'email1', 'email2', 'email3',
194
- 'hashtag', 'url', 'groups',
211
+ 'hashtag', 'url', 'groups', 'added_timestamp',
195
212
  'website1', 'handle', 'address1_street', 'address1_city', 'address1_state', 'address1_postal_code',
196
213
  'address1_country', 'address2_street', 'address2_city', 'address2_state', 'address2_postal_code',
197
214
  'address2_country', 'job_title', 'organization', 'display_as')
198
215
 
199
- user_external_id = self.__get_user_external_id(user_external_username)
216
+ user_external_id = self.__get_user_external_id(user_external_username=user_external_username, profile_id=profile_id)
200
217
  # We create a new data_source_instance_id everytime we import a new csv file
201
218
  data_source_instance_id = self.__get_data_source_instance_id(
202
219
  data_source_type_id=data_source_type_id, csv_file_path=csv_file_path,
@@ -205,6 +222,7 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
205
222
  start_index=start_index, end_index=end_index
206
223
  )
207
224
  fields_dictonary = self.data_sources.get_fields_name_from_csv(data_source_type_id)
225
+ self.logger.info(f"fields_dictonary: {fields_dictonary}")
208
226
  keys = list(fields_dictonary.keys())
209
227
  contact_data_by_contact_id_dict = {}
210
228
  encoding = CSVToContactPersonProfile.detect_encoding(file_path=csv_file_path, data_source_type_id=data_source_type_id)
@@ -245,6 +263,7 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
245
263
 
246
264
  contact_dict = {key: contact_dict.get(
247
265
  key) or None for key in contact_fields_to_keep}
266
+ self.logger.info(f"contact_dict: {contact_dict}")
248
267
  if (not contact_dict.get('first_name')
249
268
  and not contact_dict.get('last_name')
250
269
  and not contact_dict.get('organization')):
@@ -284,8 +303,10 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
284
303
 
285
304
  # TODO We should take care of situation which the contact already exists and we need to update it
286
305
  contact_dict["data_source_instance_id"] = data_source_instance_id
306
+ contact_dict["data_source_type_id"] = data_source_type_id
287
307
  contact_dict["source"] = "Import"
288
- contact_dict["owner_profile_id"] = self.user_context.get_effective_profile_id()
308
+ contact_dict["owner_profile_id"] = profile_id
309
+ contact_dict["system_id"] = system_id
289
310
  contact_id = self.contacts_local.upsert_contact_dict(contact_dict=contact_dict)
290
311
  contact_dict["contact_id"] = contact_id
291
312
  if contact_id:
@@ -747,7 +768,7 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
747
768
  # TODO use enum const for "email1" ....
748
769
  return emails_list
749
770
 
750
- def __get_user_external_id(self, user_external_username: str) -> int or None:
771
+ def __get_user_external_id(self, user_external_username: str, profile_id: int) -> int or None:
751
772
 
752
773
  user_external_id = self.user_externals_local.select_one_value_by_column_and_value(
753
774
  select_clause_value="user_external_id", column_name="username",
@@ -755,7 +776,7 @@ class CSVToContactPersonProfile(GenericCRUD, metaclass=MetaLogger,
755
776
  if user_external_id is None:
756
777
  self.user_externals_local.insert_or_update_user_external_access_token(
757
778
  username=user_external_username,
758
- profile_id=self.user_context.get_effective_profile_id(),
779
+ profile_id=profile_id,
759
780
  system_id=CONTACT_PERSON_PROFILE_CSV_SYSTEM_ID,
760
781
  access_token=""
761
782
  )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: contact-person-profile-csv-imp-local
3
- Version: 0.0.29
3
+ Version: 0.0.31
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
@@ -1,7 +1,7 @@
1
- contact_person_profile_csv_imp_local/CSVToContactPersonProfile.py,sha256=5Z7Ry0pXftYx5t2c5M-SamiFLdtfHvd7mA9Mf6s11Xg,43690
1
+ contact_person_profile_csv_imp_local/CSVToContactPersonProfile.py,sha256=uXkco79F7ggdPH6SNqjVgxjUf-Fni-1ofXL6mbxUY6A,44990
2
2
  contact_person_profile_csv_imp_local/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
3
  contact_person_profile_csv_imp_local/contact_person_profile_csv_imp_local_constants.py,sha256=eE0Bg2dCPrmG72K20k0_KOckc61C9cGSgH0Zgae_lbk,957
4
- contact_person_profile_csv_imp_local-0.0.29.dist-info/METADATA,sha256=QjTN4mavxPgwRaXO8td-zu5qudljl67ZukaNjmKZqZE,1481
5
- contact_person_profile_csv_imp_local-0.0.29.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
6
- contact_person_profile_csv_imp_local-0.0.29.dist-info/top_level.txt,sha256=at6BnVzULDB109KZx9Cl9ClCHU4c0ykfV38WX-QR71U,37
7
- contact_person_profile_csv_imp_local-0.0.29.dist-info/RECORD,,
4
+ contact_person_profile_csv_imp_local-0.0.31.dist-info/METADATA,sha256=S4Y-y1doSC4jHJ-EnRsixZDswjciT1cPzRiCzYdaqDU,1481
5
+ contact_person_profile_csv_imp_local-0.0.31.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
6
+ contact_person_profile_csv_imp_local-0.0.31.dist-info/top_level.txt,sha256=at6BnVzULDB109KZx9Cl9ClCHU4c0ykfV38WX-QR71U,37
7
+ contact_person_profile_csv_imp_local-0.0.31.dist-info/RECORD,,