You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are some functions and tasks in each of our hubspot-enabled applications that are almost identical but that reference the application's specific functions for handling its object models. Some of these could be made more generic (via adding the app_label and model name as input parameters) and centralized here instead, reducing code duplication.
For example, sync_contact_with_hubspot, sync_deal_with_hubspot, and sync_product_with_hubspot exist in xpro, mitxonline, and bootcamps, but could potentially be replaced by something like this in ol-django/hubspot_api:
defget_hubspot_function(func_name: str) ->Callable:
"""Given a string like my_app.api.do_something, return that function"""func_parts=func_name.split(".")
func=apps.get_app_config(func_parts[0]).moduleforiinrange(1, len(func_parts)):
func=getattr(func, func_parts[i])
returnfuncdefsync_object_with_hubspot(
object_id: int,
msg_func: str,
app_label: str,
model_name: str,
hubspot_type: str
) ->SimplePublicObject:
""" Sync a django object with a hubspot object Args: object_id(int): The django object id msg_func(str): The name of function that will generate the request message body (<app>.<module>.<function>) app_label(str): The app label for the object model model_name(str): The object model name hubspot_type(str): The hubspot object type (contact, deal, etc) Returns: SimplePublicObject: The hubspot object """body=get_hubspot_function(msg_func)(object_id)
content_type=ContentType.objects.get_by_natural_key(app_label, model_name)
returnupsert_object_request(
content_type, hubspot_type, object_id=object_id, body=body
)
The text was updated successfully, but these errors were encountered:
There are some functions and tasks in each of our hubspot-enabled applications that are almost identical but that reference the application's specific functions for handling its object models. Some of these could be made more generic (via adding the app_label and model name as input parameters) and centralized here instead, reducing code duplication.
For example,
sync_contact_with_hubspot
,sync_deal_with_hubspot
, andsync_product_with_hubspot
exist in xpro, mitxonline, and bootcamps, but could potentially be replaced by something like this in ol-django/hubspot_api:The text was updated successfully, but these errors were encountered: