The Provides system
The Provides system is Shuup’s mechanism for discovering and loading components, both first-party and third-party. Shuup apps use the provides system in various ways.
The core itself uses Provides for discovering method and supplier modules.
shuup.adminuses Provides to load admin modules, form customizations etc.shuup.frontuses it for URLconf overrides etc.
The provide categories used by Shuup are listed in Provide Categories, but you can also define your own categories as you wish.
Todo
Document the various ways better.
Provides are grouped under different categories, such as admin_module,
xtheme_plugin, front_urls, etc.
Declaring Provides
Shuup uses the Django 1.7+ AppConfig system to declare provides.
Quite simply, a developer needs only include a dict with provide categories as the keys and lists of loading specs as values for new provides to be discovered.
class PigeonAppConfig(AppConfig):
provides = {
'service_provider_admin_form': [
'pigeon.admin_forms:PigeonShippingAdminForm',
],
}
Note
Some provides also require the class named by the spec string to include
an identifier field. Refer to the implementation guides for particular
functionalities for details.
Blacklisting Provides
Shuup also supports blacklisting unwanted provides. This is useful when one want to disable
some features like shipping and payment methods provided by a single app. This way,
it is easy to select which provides should be loaded by Shuup.
To blacklist provides, you need to set a special Django setting named SHUUP_PROVIDES_BLACKLIST:
SHUUP_PROVIDES_BLACKLIST = {
'service_provider_admin_form': [
'pigeon.admin_forms:PigeonShippingAdminForm'
]
}
This will allow the spec pigeon.admin_forms:PigeonShippingAdminForm from category
service_provider_admin_form to be loaded.
Using Provides
Provide management functions are found in the shuup.apps.provides module.
In general, the shuup.apps.provides.get_provide_objects method is your most useful
entry point.
Provide Categories
Core
admin_category_form_partAdditional
FormPartclasses for Category editing. See example.admin_contact_form_partAdditional
FormPartclasses for Contact editing. See example.admin_contact_group_form_partAdditional
FormPartclasses for ContactGroup editing. See example.admin_contact_toolbar_action_itemAdditional
DropdownItemsubclass for Contact detail action buttons.admin_contact_edit_toolbar_buttonAdditional
BaseActionButtonsubclasses for Contact edit. Subclass init should take current contact as a parameter.admin_contact_sectionAdditional
Sectionsubclasses for Contact detail sections.admin_extend_create_shipment_formAllows providing extension for shipment creation in admin. Should implement the
FormModifierinterface.admin_main_menu_updaterAllows updating the Admin Main Menu with new elements. The objects offered through this provide should inherit from
~shuup.core.utils.menu.MainMenuUpdaterclass.admin_mass_actions_provider`Object that provides mass actions to all views. Providers must subclass from
shuup.admin.utils.picotable.PicotableMassActionProviderand implement theget_mass_actions_for_viewmethod.admin_moduleAdmin module classes. Practically all of the functionality in the admin is built via admin modules.
admin_object_selectorObject selector classes for filtering models in select2 objects. Providers must subclass from
BaseAdminObjectSelectorclass.admin_order_informationAdditional information rows for Order detail page. Provide objects should inherit from
OrderInformationclass.admin_product_form_partAdditional
FormPartclasses for Product editing. (This is used by pricing modules, for instance.) See example.admin_product_sectionAdditional
Sectionsubclasses for Product edit sections.admin_product_validatorProvide an AdminProductValidator class, which validates a product according to some criteria.
admin_product_toolbar_action_itemAdditional
DropdownItemsubclass for Product edit action buttons.admin_template_injectorAllow snippet injection inside admin templates. The classes must inherit from the
~shuup.admin.base.AdminTemplateInjectorclass.admin_shop_edit_toolbar_buttonAdditional
BaseActionButtonsubclasses for Shop edit. Subclass init should take current shop as a parameter. Current shop is passed to static methodvisible_for_objectto check whether to actually show the item.admin_shop_form_partAdditional
FormPartclasses for Shop editing. See example.admin_toolbar_button_providerObject that provides buttons to all toolbars. Providers must subclass from
shuup.admin.toolbar.BaseToolbarButtonProviderand implement theget_buttons_for_viewmethod.basket_command_middlewareInjects a middleware in the basket command dispatcher that can be used to mutate the basket kwargs and response and execute additional steps with the basket once a command is invoked.
customer_dashboard_itemsClasses to parse customer dashboard items from. These are subclasses of
shuup.front.utils.dashboard.DashboardItemdiscount_moduleDiscountModulefor pricing system.front_extend_product_list_formAllows providing extension for product list form. Should implement the
ProductListFormModifierinterface.front_service_checkout_phase_providerAllows providing a custom checkout phase for a service (e.g. payment method or shipping method). Should implement the
ServiceCheckoutPhaseProviderinterface.front_template_helper_namespaceAdditional namespaces to install in the
shuup“package” within template contexts. .. seealso:: Custom Template Helper Functionsadmin_order_toolbar_action_itemAdditional
DropdownItemsubclass for Order detail action buttons. Current order is passed to subclass init and static methodvisible_for_objectis called for the subclass to check whether to actually show the item.admin_order_sectionAdditional
Sectionsubclasses for Order detail sections.front_model_url_resolverList of functions that resolve a model instance into an object URL. The first valid url returned by a provide will be used by the caller.
admin_model_url_resolverList of functions that resolve a model instance into an object URL. The first valid url returned by a provide will be used by the called.
admin_browser_config_provider`List of classes that implements
shuup.admin.browser_config.BaseBrowserConfigProviderclass. It can implement theget_browser_urlsmethod which should returns a dictionary of urls names that should be exported to the browser through thewindow.ShuupAdminConfig.browserUrlsobject. The returned dictionary should have the url name as the value, which will be reversed when rendering the templates. It can also implement theget_gettingsmethod which should returns a dictionary. The returned data will be converted into JSON and exported to the browser through thewindow.ShuupAdminConfig.settingsobject.front_menu_extenderAdditional menu items provided by addons. These should be subclassed from
FrontMenuExtender.front_product_order_formList of order forms which are subclasses of
ProductOrderForm. These forms are shown on product detail page in front as well as previews etc.front_registration_field_providerList of
FormFieldProviderclasses. These classes provideFormFieldDefinitionobjects which extend registration forms accross the Shuup front.checkout_confirm_form_field_providerList of
FormFieldProviderclasses. These classes provideFormFieldDefinitionobjects which extend checkout confirm form.front_auth_form_field_providerList of
FormFieldProviderclasses. These classes provideFormFieldDefinitionobjects which extend authentication forms accross the Shuup front.front_company_registration_form_providerList of
FormDefProviderclasses. These classes provideFormDefinitionobjects which extend theCompanyRegistrationFormwithform_defs.front_urlsLists of frontend URLs to be appended to the usual frontend URLs.
front_urls_postLists of frontend URLs to be appended to the usual frontend URLs, even after
front_urls. Most of the time,front_urlsshould do.front_urls_preLists of frontend URLs to be prepended to the usual frontend URLs. Most of the time,
front_urlsshould do.front_line_properties_descriptorObject that returns properties for order source lines and order lines to be rendered in the basket and order detail views. The objects must inherit from the
BaseLinePropertiesDescriptorbase class.notify_actionNotification framework
Actionclasses.notify_conditionNotification framework
Conditionclasses.notify_eventNotification framework
Eventclasses.notify_script_templateNotification framework
ScriptTemplateclasses.order_printouts_delivery_extra_fieldsAdditional information rows for order delivery printout. Provide objects should inherit from
PrintoutDeliveryExtraInformationclass.order_source_modifier_moduleOrderSourceModifierModulefor modifying order source, e.g. in itsget_final_lines.order_source_validatorList of classes that validate a given
OrderSourceand return an error iterator. The class must have aget_validation_errorsclass method which receives theorder_sourceand returns/yieldsValidationErrorinstances.pricing_modulePricing module classes; the pricing module in use is set with the
SHUUP_PRICING_MODULEsetting.product_kind_specsList of classes that define the product kinds that can be used in the platform. The classes must implement the
ProductKindSpecbase class. It is specially used to control which supplier modules can handle certain types of products and also to hide products from the normal admin product list.service_behavior_component_formForms for creating service behavior components in Shop Admin. When creating a custom
service behavior component, provide a form for it via this provide.service_provider_admin_formForms for creating service providers in Shop Admin. When creating a custom
service provider(e.g.carrierorpayment processor), provide a form for it via this provide.carrier_wizard_form_defFormdefsfor creating carriers (and their service(s)) through the shop setup wizard.payment_processor_wizard_form_defFormdefsfor creating payment processors (and their service(s)) through the shop setup wizard.product_context_extraAdditional context data for the front product views. Provide objects should inherit from
ProductContextExtraclass.product_subscription_option_providerReturns subscription options for a given
ProductSubscriptionContextcontext. The provider must inherit from the base classBaseProductSubscriptionOptionProvider.supplier_moduleSupplier module classes (deriving from
BaseSupplierModule), as used bySupplier.tax_moduleTax module classes; the tax module in use is set with the
SHUUP_TAX_MODULEsetting.xthemeXTheme themes (full theme sets).
xtheme_layoutXTheme layouts (to split placeholders different types of layouts with different visibilities).
xtheme_pluginXTheme plugins (that are placed into layouts within themes).
xtheme_resource_injectionXTheme resources injection function that takes current context and content as parameters.
xtheme_snippet_blockerBlocker classes that can prevent a global snippet from being injected
Campaigns Provide Categories
campaign_catalog_filterFilters that filter product catalog queryset to find the matching campaigns.
campaign_context_conditionContext Conditions that matches against the current context in shop to see if campaign matches.
campaign_product_discount_effect_formForm for handling product discount effects of a catalog campaign. Should be a ModelForm with its model being a subclass of
ProductDiscountEffect.campaign_basket_conditionConditions that matches against the order source or source lines in basket.
campaign_basket_discount_effect_formForm for handling discount effects of a basket campaign. Should be a ModelForm with its model being a subclass of
BasketDiscountEffect.campaign_basket_line_effect_formForm for handling line effects of a basket campaign. Should be a ModelForm with its model being a subclass of
BasketLineEffect.
Reports Provide Categories
reportsClass to handle report data collection. Should be a subclass of
ShuupReportBase.report_writer_populatorList of functions to populate report writers. This allows the creation of custom output formats. Should follow the signature of
populate_default_writers.
Simple CMS Provide Categories
admin_page_form_partAdditional
FormPartclasses for Page editing. See example.simple_cms_templateList of available template objects that can be used to render CMS pages.
List of objects that have provides key as attributes
Some objects have attributes that contain a provide key which are used to load provides dynamically. They are specially used in mixins when they can be attached to some class which overrides the attribute with its own provide key name, making it easier to extend provides related to class. Here is the list of objects that have this attribute which can be overrided on a specialization:
FormPartsViewMixin.form_part_class_provide_keyAdds form parts to a view dynamically. Each view will have a custom provide key value.
View.toolbar_buttons_provider_keyAdds buttons to a view’s toolbar. Each view will have a custom provide key value. Only views that use toolbars can use this attribute, as in
PicotableViewMixin. CheckCategoryListViewfor an example.View.mass_actions_provider_keyAdds mass actions view. Each view will have a custom provide key value. Only views that inherints from
PicotableListVieworPicotableViewMixinwill have mass actions added. All providers must inherit fromPicotableMassActionProviderbase class. CheckCategoryListViewfor an example.