Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Aug 20, 2025

This PR adds comprehensive documentation for the get_object and set_object methods in the CMSToolbarBase class, which were previously undocumented. Fixes #8311

Changes Made

Toolbar Method Documentation

Added detailed docstrings for both methods in cms/toolbar/toolbar.py:

  • set_object(obj): Documents how this method associates a Django model instance with the toolbar, explaining that it only sets the object if one hasn't already been set
  • get_object(): Documents how this method retrieves the currently associated object, returning None if no object has been set

Enhanced Documentation Features

  • Uses proper Sphinx cross-references with :class: syntax for PageContent and PlaceholderRelationField
  • Includes detailed parameter typing (:param and :type) and return value documentation (:returns and :rtype)
  • References related toolbar methods like get_object_edit_url, get_object_preview_url, and get_object_structure_url
  • Provides specific examples of supported model types

Comprehensive User Guide Documentation

Added an enhanced "Setting and getting the placeholder-enabled object from the toolbar" section to docs/how_to/01-placeholders.rst that includes:

  • Formal documentation of both set_object() and get_object() methods with proper Sphinx cross-references
  • Usage in Views: Comprehensive examples showing how to use both methods in function-based and class-based views
  • Usage in Templates: Template examples demonstrating direct access and {% with %} tag patterns:
# In views
my_content = request.toolbar.get_object()  # Can be PageContent, PostContent, etc.
request.toolbar.set_object(obj)  # Associate object with toolbar
{# In templates #}
{{ request.toolbar.get_object.title }}

{% with my_obj=request.toolbar.get_object %}
    <h2>{{ my_obj.title }}</h2>
    <p><strong>{{ my_obj.description }}</strong></p>
{% endwith %}

Impact

The documentation will automatically appear in the generated Sphinx documentation under the CMSToolbar class reference. The comprehensive user guide provides practical context for developers working with placeholders outside the CMS, showing real-world usage patterns for both server-side views and frontend templates.

These methods are fundamental to the toolbar's object association functionality and enable proper integration of custom models with django CMS's frontend editing capabilities.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@Copilot Copilot AI changed the title [WIP] Create documentation for the toolbar's get_object and set_object methods. Add documentation for toolbar get_object and set_object methods Aug 20, 2025
@Copilot Copilot AI requested a review from fsbraun August 20, 2025 09:54
Copilot finished work on behalf of fsbraun August 20, 2025 09:54
Copy link
Member

@fsbraun fsbraun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Can you reference the PageContent and PlaceholderRelationshipField docs using sphinx' :class: syntax

@fsbraun
Copy link
Member

fsbraun commented Aug 20, 2025

@copilot Pleas consider the changes above. Also, add a description of both methods get_object and set_object to the documentation in chapter docs/how_to/01-placeholders.html

…lder documentation

- Changed references to be more specific (PageContent instead of Page)
- Added Sphinx cross-references for PageContent and PlaceholderRelationField
- Added comprehensive documentation section for get_object and set_object methods in docs/how_to/01-placeholders.rst

Co-authored-by: fsbraun <[email protected]>
Copy link
Contributor Author

Copilot AI commented Aug 20, 2025

@copilot Can you reference the PageContent and PlaceholderRelationshipField docs using sphinx' :class: syntax

Added Sphinx :class: syntax for both PageContent and PlaceholderRelationField references. Updated in commit f6dab9d.

@copilot Pleas consider the changes above. Also, add a description of both methods get_object and set_object to the documentation in chapter docs/how_to/01-placeholders.html

Applied all the suggested changes and added a new "Toolbar Object Management" section to docs/how_to/01-placeholders.rst that documents both get_object and set_object methods with proper Sphinx cross-references. Updated in commit f6dab9d.

@Copilot Copilot AI changed the title Add documentation for toolbar get_object and set_object methods Add comprehensive documentation for toolbar get_object and set_object methods Aug 20, 2025
Copilot finished work on behalf of fsbraun August 20, 2025 10:07
@Copilot Copilot AI requested a review from fsbraun August 20, 2025 10:07
@fsbraun
Copy link
Member

fsbraun commented Aug 20, 2025

@copilot Include the content of lines 133ff into the new documentation section "Toolbar object management". Add examples for usage in views and templates along the line:

In views sse the toolbar's get_object() method:

my_post_content = request.toolbar.get_object()  # Can by anything: PageContent, PostContent, AliasContent, ...
my_post = my_post_content.post  # only works for PostContent, of course

It works similarly inside a template: {{ request.toolbar.get_object.title }} or

{% with my_obj=request.get_toolbar %}
   <h2>{{ my_obj.title }}</h2>
   <p><strong>{{ my_obj.description }}</strong></p>
{% endwith %}

Adjust the examples to the context.

Improve the new section's title to something along "Setting and getting the placeholder-enabled object from the toolbar"

Copy link
Contributor Author

Copilot AI commented Aug 20, 2025

@copilot Include the content of lines 133ff into the new documentation section "Toolbar object management". Add examples for usage in views and templates along the line:

In views sse the toolbar'...

Updated the documentation section as requested:

  1. Enhanced section title: Changed to "Setting and getting the placeholder-enabled object from the toolbar"
  2. Incorporated existing content: Merged the content from lines 133ff with the new documentation section
  3. Added comprehensive examples:
    • View examples showing both set_object() and get_object() usage
    • Template examples with direct access ({{ request.toolbar.get_object.title }}) and {% with %} tag patterns
  4. Improved structure: Organized into "Usage in Views" and "Usage in Templates" subsections for better clarity

The documentation now provides a complete guide for developers working with toolbar object management, including practical examples for both server-side and template usage. Updated in commit 1841dbb.

@Copilot Copilot AI changed the title Add comprehensive documentation for toolbar get_object and set_object methods Add comprehensive documentation for toolbar get_object and set_object methods with usage examples Aug 20, 2025
Copilot finished work on behalf of fsbraun August 20, 2025 10:19
@fsbraun fsbraun marked this pull request as ready for review August 20, 2025 16:54
@fsbraun fsbraun changed the title Add comprehensive documentation for toolbar get_object and set_object methods with usage examples docs: Add documentation for toolbar get_object and set_object methods Aug 21, 2025
@fsbraun fsbraun requested a review from vinitkumar August 21, 2025 06:11
Copy link

codecov bot commented Aug 21, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.60%. Comparing base (54d305b) to head (a930812).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #8312   +/-   ##
=======================================
  Coverage   89.60%   89.60%           
=======================================
  Files         129      129           
  Lines       12710    12710           
=======================================
  Hits        11389    11389           
  Misses       1321     1321           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@fsbraun fsbraun added the needs to be backported Commits need to be backported label Aug 21, 2025
Copy link
Member

@vinitkumar vinitkumar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Let's get this merged and released 🚢 🚀

@vinitkumar vinitkumar merged commit b0b6e51 into main Aug 21, 2025
67 of 69 checks passed
@fsbraun fsbraun deleted the copilot/fix-7f68cb76-c4e2-4a00-b2b5-b2ca749ddff0 branch August 21, 2025 09:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs to be backported Commits need to be backported
Projects
None yet
Development

Successfully merging this pull request may close these issues.

How to access "current object" from apphook models
3 participants