Skip to content

Commit c7c23e5

Browse files
committed
Clarify which attributes and methods are for the CMSPluginBase and which are for CMSPlugin. Add copy_relations and post_copy methods.
1 parent e0e88b7 commit c7c23e5

File tree

1 file changed

+88
-50
lines changed

1 file changed

+88
-50
lines changed

docs/extending_cms/custom_plugins.rst

Lines changed: 88 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -629,15 +629,15 @@ achieve this functionality:
629629
</div>
630630

631631

632-
***************************************
633-
Plugin Attributes and Methods Reference
634-
***************************************
632+
**********************************************
633+
CMSPluginBase Attributes and Methods Reference
634+
**********************************************
635635

636-
Plugin Attribute Reference
637-
==========================
638-
639-
A list of all attributes a plugin has and that can (or should) be overwritten:
636+
These are a list of attrbibutes and methods that can (or should) be overridden
637+
on your Plugin definition.
640638

639+
Attributes
640+
==========
641641

642642
admin_preview
643643
-------------
@@ -647,7 +647,6 @@ Default: ``False``
647647
Should the plugin be previewed in admin when you click on the plugin or save it?
648648

649649

650-
651650
allow_children
652651
--------------
653652

@@ -739,6 +738,8 @@ Default: ``CMSPlugin``
739738
If the plugin requires per-instance settings, then this setting must be set to
740739
a model that inherits from :class:`CMSPlugin`.
741740

741+
See also: `Storing Configuration`_
742+
742743

743744
page_only
744745
---------
@@ -768,7 +769,7 @@ render_plugin
768769
Default: ``True``
769770

770771
Should the plugin be rendered at all, or doesn't it have any output? If
771-
`render_plugin` is ``True``, then you must also define `render_template`
772+
`render_plugin` is ``True``, then you must also define :meth:`render_template`
772773

773774
See also: `render_template`_
774775

@@ -806,43 +807,8 @@ Can the plugin be inserted inside the text plugin? If this is ``True`` then
806807
See also: `icon_src`_, `icon_alt`_
807808

808809

809-
translatable_content_excluded_fields
810-
------------------------------------
811-
812-
Default: ``[]``
813-
814-
A list of plugin fields which will not be exported while using
815-
:meth:`get_translatable_content`.
816-
817-
See also: `get_translatable_content`_, `set_translatable_content`_
818-
819-
820-
Plugin Method Reference
821-
=======================
822-
823-
A list of all methods a plugin has and that can (or should) be overwritten:
824-
825-
826-
get_translatable_content
827-
------------------------
828-
829-
Get a dictionary of all content fields (field name / field value pairs) from
830-
the plugin.
831-
832-
.. note:: This method not be used on the plugin but rather on the plugin's
833-
instance.
834-
835-
Example::
836-
837-
from djangocms_text_ckeditor.models import Text
838-
839-
plugin = Text.objects.get(pk=1).get_plugin_instance()[0]
840-
plugin.get_translatable_content()
841-
# returns {'body': u'<p>I am text!</p>\n'}
842-
843-
844-
See also: `translatable_content_excluded_fields`_, `set_translatable_content`_
845-
810+
Methods
811+
=======
846812

847813
icon_src
848814
--------
@@ -895,19 +861,91 @@ The default implementation is as follows::
895861
See also: `text_enabled`_, `icon_src`_
896862

897863

864+
******************************************
865+
CMSPlugin Attributes and Methods Reference
866+
******************************************
867+
868+
These are a list of attrbibutes and methods that can (or should) be overridden
869+
on your plugin's `model` definition.
870+
871+
See also: `Storing Configuration`_
872+
873+
874+
Attributes
875+
==========
876+
877+
878+
translatable_content_excluded_fields
879+
------------------------------------
880+
881+
Default: ``[]``
882+
883+
A list of plugin fields which will not be exported while using
884+
:meth:`get_translatable_content`.
885+
886+
See also: `get_translatable_content`_, `set_translatable_content`_
887+
888+
889+
Methods
890+
=======
891+
892+
893+
copy_relations
894+
--------------
895+
896+
Handle copying of any relations attached to this plugin. Custom plugins have
897+
to do this themselves.
898+
899+
``copy_relations`` takes 1 argument:
900+
901+
* ``old_instance``: The source plugin instance
902+
903+
See also: `Handling Relations`_, `post_copy`_
904+
905+
906+
get_translatable_content
907+
------------------------
908+
909+
Get a dictionary of all content fields (field name / field value pairs) from
910+
the plugin.
911+
912+
Example::
913+
914+
from djangocms_text_ckeditor.models import Text
915+
916+
plugin = Text.objects.get(pk=1).get_plugin_instance()[0]
917+
plugin.get_translatable_content()
918+
# returns {'body': u'<p>I am text!</p>\n'}
919+
920+
921+
See also: `translatable_content_excluded_fields`_, `set_translatable_content`_
922+
923+
924+
post_copy
925+
---------
926+
927+
Can be overriden to handle more advanced cases (eg Text Plugins) after the
928+
original has been copied.
929+
930+
``post_copy`` takes 2 arguments:
931+
932+
* ``old_instance``: The old plugin instance instance
933+
* ``new_old_ziplist``: [unclear at time of this edit]
934+
935+
See also: `Handling Relations`_, `copy_relations`_
936+
937+
898938
set_translatable_content
899939
------------------------
900940

901941
Takes a dictionary of plugin fields (field name / field value pairs) and
902942
overwrites the plugin's fields. Returns ``True`` if all fields have been
903943
written successfully, and ``False`` otherwise.
904944

905-
.. note:: This method not be used on the plugin but rather on the plugin's
906-
instance.
907-
908945
set_translatable_content takes 1 argument:
909946

910-
* ``fields``: A dictionary containing the field names and translated content for each.
947+
* ``fields``: A dictionary containing the field names and translated content
948+
for each.
911949

912950
Example::
913951

0 commit comments

Comments
 (0)