tgshops-integrations 3.7__py3-none-any.whl → 4.0__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
@@ -27,7 +27,6 @@ from tgshops_integrations.nocodb_connector.categories_management import Category
27
27
  from tgshops_integrations.nocodb_connector.products_management import ProductManager
28
28
  from loguru import logger
29
29
 
30
-
31
30
  def custom_key_builder(func, *args, **kwargs):
32
31
  """
33
32
  Key builder function for caching.
@@ -120,7 +119,7 @@ class Gateway(NocodbClient):
120
119
  self.products_meta = {product.external_id: product for product in self.actual_products}
121
120
 
122
121
  for product in external_products:
123
- if product.external_id in self.ids_mapping:
122
+ if (product.external_id in self.ids_mapping and product.external_id !=''):
124
123
  product.id = self.ids_mapping[product.external_id]
125
124
  current_hash = self.product_manager.hash_product(product, special_attributes=self.special_attributes)
126
125
  existing_hash = self.product_manager.hash_product(
@@ -1,10 +1,10 @@
1
1
  from typing import List
2
2
  from loguru import logger
3
3
  from aiocache import cached
4
- from tgshops_integrations.models.categories import CategoryModel, CategoryResponseModel, CategoryListResponseModel
5
- from tgshops_integrations.models.products import ProductModel
6
- from tgshops_integrations.nocodb_connector.client import custom_key_builder, NocodbClient
7
- from tgshops_integrations.nocodb_connector.model_mapping import (
4
+ from models.categories import CategoryModel, CategoryResponseModel, CategoryListResponseModel
5
+ from models.products import ProductModel
6
+ from services.nocodb_connector.client import custom_key_builder, NocodbClient
7
+ from services.nocodb_connector.model_mapping import (
8
8
  CATEGORY_IMAGE_FIELD,
9
9
  CATEGORY_NAME_FIELD,
10
10
  CATEGORY_PARENT_FIELD,
@@ -83,23 +83,34 @@ class CategoryManager(NocodbClient):
83
83
  )
84
84
  return [parse_category_data(record) for record in records]
85
85
 
86
- async def update_categories(self, external_products: List[ProductModel]) -> None:
86
+ async def update_categories(self, external_products: List[ProductModel],with_properties: bool = False) -> None:
87
87
  self.categories = await self.get_product_categories(table_id=self.categories_table, table_name=PRODUCT_NAME_FIELD)
88
88
  categories_list = list(self.categories.keys())
89
89
  properties_to_create = []
90
+ parent_id=0
90
91
 
91
- for product in external_products:
92
- for num, product_property in enumerate(product.product_properties[:len(self.filter_buttons)]):
93
- if product_property not in categories_list:
94
- # TODO: Needs restructuring
95
- # parent_id = (
96
- # self.categories[self.filter_buttons[num]]
97
- # if self.filter_buttons
98
- # else self.categories[product.category_I_name[0]]
99
- # )
100
- parent_id=0
101
- properties_to_create.append([product_property, parent_id])
102
- categories_list.append(product_property)
92
+ if with_properties:
93
+ for product in external_products:
94
+ for num, product_property in enumerate(product.product_properties[:len(self.filter_buttons)]):
95
+ if product_property not in categories_list:
96
+ # TODO: Needs restructuring
97
+ # parent_id = (
98
+ # self.categories[self.filter_buttons[num]]
99
+ # if self.filter_buttons
100
+ # else self.categories[product.category_I_name[0]]
101
+ # )
102
+
103
+ properties_to_create.append([product_property, parent_id])
104
+ categories_list.append(product_property)
105
+
106
+ else:
107
+ for product in external_products:
108
+ # for item in product.categories_structure.values():
109
+ # if item not in categories_list:
110
+ for product_property in product.product_properties:
111
+ if product_property not in categories_list:
112
+ properties_to_create.append([product_property, parent_id])
113
+ categories_list.append(product_property)
103
114
 
104
115
  if properties_to_create:
105
116
  properties_to_create.sort(key=lambda x: x[0])
@@ -108,13 +119,15 @@ class CategoryManager(NocodbClient):
108
119
  for product_property, parent_id in properties_to_create:
109
120
  new_property = await self.create_product_category(
110
121
  table_id=self.categories_table,
111
- property_name=product_property,
122
+ category_name=product_property,
112
123
  category_id=new_id,
113
124
  table_name=PRODUCT_NAME_FIELD,
114
125
  )
115
126
  if self.logging:
116
127
  logger.info(f"New Category: {new_property}")
117
128
  new_id += 1
129
+
130
+ self.categories = await self.get_product_categories(table_id=self.categories_table, table_name=PRODUCT_NAME_FIELD)
118
131
 
119
132
  async def link_categories(self, parent_id: int, child_id: int):
120
133
  metadata = await self.get_table_meta(self.categories_table)
@@ -18,7 +18,6 @@ from tgshops_integrations.nocodb_connector.model_mapping import (
18
18
  PRODUCT_IMAGES_LOOKUP_FIELD,
19
19
  )
20
20
 
21
-
22
21
  class ProductManager(NocodbClient):
23
22
  def __init__(self, table_id=None, logging=False, NOCODB_HOST=None, NOCODB_API_KEY=None, SOURCE=None):
24
23
  super().__init__(NOCODB_HOST=NOCODB_HOST, NOCODB_API_KEY=NOCODB_API_KEY, SOURCE=SOURCE)
@@ -111,7 +110,7 @@ class ProductManager(NocodbClient):
111
110
  )
112
111
  logger.info(f"Updated product {product.external_id}")
113
112
 
114
- async def create_product(self, checked_data: dict, product: ProductModel) -> ProductModel:
113
+ async def create_product(self, checked_data: dict, product: ProductModel,store_images_at_nocodb: bool=True) -> ProductModel:
115
114
  """
116
115
  Creates a new product in the table.
117
116
  """
@@ -125,14 +124,15 @@ class ProductManager(NocodbClient):
125
124
 
126
125
  checked_data[PRODUCT_IMAGES_LOOKUP_FIELD] = [image['title'] for image in checked_data['Images']]
127
126
 
128
- for num, item in enumerate(checked_data['Images']):
129
- item['url'] = await self.save_image_to_nocodb(
130
- source_column_id=self.SOURCE,
131
- image_url=item['url'],
132
- image_name=item['title'],
133
- product_table_name=self.products_table,
134
- images_column_id=images_column,
135
- )
127
+ if store_images_at_nocodb:
128
+ for num, item in enumerate(checked_data['Images']):
129
+ item['url'] = await self.save_image_to_nocodb(
130
+ source_column_id=self.SOURCE,
131
+ image_url=item['url'],
132
+ image_name=item['title'],
133
+ product_table_name=self.products_table,
134
+ images_column_id=images_column,
135
+ )
136
136
 
137
137
  record = await self.create_table_record(table_name=self.products_table, record=checked_data)
138
138
  logger.info(f"Created product {external_id}")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: tgshops-integrations
3
- Version: 3.7
3
+ Version: 4.0
4
4
  Summary: Library is intended to provide the integration of the external service or CRM system with the TelegramShops/It allows to configure the relationship between NocoDB list of the products used further to display in the shop/As a resultss the products can be synchronized and updated uppon the request.
5
5
  Home-page: https://git.the-devs.com/virtual-shops/shop-system/shop-backend-integrations/integration-library/integration-library
6
6
  Author: Dimi Latoff
@@ -1,16 +1,16 @@
1
1
  tgshops_integrations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
2
  tgshops_integrations/middlewares/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
- tgshops_integrations/middlewares/gateway.py,sha256=s6W2-O8BaAGlbNurl1_zbtbzCECN_E1n1Y3Cs57gLDg,6269
3
+ tgshops_integrations/middlewares/gateway.py,sha256=aysw55ZUxBLq46hNfkRGsnJirL2CZLw0ipS0w3Gc6mY,6299
4
4
  tgshops_integrations/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
5
  tgshops_integrations/models/categories.py,sha256=EG6C8g5dOfXB2MH-vtqH13aqB7_VyOobY2FHpDb-fsY,977
6
6
  tgshops_integrations/models/products.py,sha256=4XC6fyC91TAWj5oaX0A26kT_UizZIGaf4qyrVv9lPpQ,1403
7
7
  tgshops_integrations/nocodb_connector/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
- tgshops_integrations/nocodb_connector/categories_management.py,sha256=czDL9o-cy4w28BsTqJD3Jug3mJL75TiH0rtC99KJ9bc,6748
8
+ tgshops_integrations/nocodb_connector/categories_management.py,sha256=aC1YuMhJerLNiqe9Cv1NHQWZ9pJbsMzvEhtDyJwt284,7413
9
9
  tgshops_integrations/nocodb_connector/client.py,sha256=U2rNozjluWVul-VZroQW-8b2j6nEtKrhOkFMz1L8KmI,12022
10
10
  tgshops_integrations/nocodb_connector/model_mapping.py,sha256=UY6QHCba8o8J28duCgAzx95agGlE1pLagkNdZLV5nro,8719
11
- tgshops_integrations/nocodb_connector/products_management.py,sha256=uo0b3azbO7is4PUXuQJ1Ode7T9IVnUaAFk9gXcVOZHI,6068
11
+ tgshops_integrations/nocodb_connector/products_management.py.py,sha256=zP6Y7BSUFm_M30GXxagjr2Y6NbgLhaT640lhid2mooQ,6168
12
12
  tgshops_integrations/nocodb_connector/tables.py,sha256=ha_QXZXd93mht0fR5E1nM0wUpz1ePon-pIdO2HI67l8,356
13
- tgshops_integrations-3.7.dist-info/METADATA,sha256=4T3ijjv0Hhl2o8e3MqlkXCb9eeVQdx0O6InkDxdlF2s,2844
14
- tgshops_integrations-3.7.dist-info/WHEEL,sha256=pkctZYzUS4AYVn6dJ-7367OJZivF2e8RA9b_ZBjif18,92
15
- tgshops_integrations-3.7.dist-info/top_level.txt,sha256=HFNtxqDpzmlF4ZLnMiwhbU7pOa_YozxU2zBl0bnUmcY,21
16
- tgshops_integrations-3.7.dist-info/RECORD,,
13
+ tgshops_integrations-4.0.dist-info/METADATA,sha256=RQ8WD6hsOQVXoDgbU6pCpTjlcpmU-FaWNZVsH6WrA_M,2844
14
+ tgshops_integrations-4.0.dist-info/WHEEL,sha256=pkctZYzUS4AYVn6dJ-7367OJZivF2e8RA9b_ZBjif18,92
15
+ tgshops_integrations-4.0.dist-info/top_level.txt,sha256=HFNtxqDpzmlF4ZLnMiwhbU7pOa_YozxU2zBl0bnUmcY,21
16
+ tgshops_integrations-4.0.dist-info/RECORD,,