Skip to main content

Render context into template.

Project description

DjangoCMS Render Context

The plugin for the Django CMS content management system. The plugin displays the context in the template. The context can be specified directly in JSON format. Or the context can be used as a media file. Or the context can be loaded from a URL. The template can be entered directly or selected from a list defined in the settings in the DJANGOCMS_RENDER_CONTEXT_TEMPLATES constant.

Supported source data formats (mimetype):

  • csv (text/csv)
  • json (application/json)
  • yaml (application/yaml)
  • xml (application/xml)
  • ods (application/vnd.oasis.opendocument.spreadsheet)

Install

Install the package from pypi.org.

pip install djangocms-render-context

Add into INSTALLED_APPS in your site settings.py:

INSTALLED_APPS = [
    ...
    "easy_thumbnails",
    "filer",
    "djangocms_render_context",
]

Optional urls

The following urls are not required. JavaScriptCatalog makes translations available for javascript. rcdata/ then detail from the list in context.

Add into site urls.py:

from django.conf.urls.i18n import i18n_patterns
from django.views.i18n import JavaScriptCatalog
from django.urls import path, register_converter
from django.urls.converters import StringConverter


class PackagesConverter(StringConverter):
    """JavaScriptCatalog packages converter."""
    # Same as SlugConverter, but with extra '+', that is used in JavaScriptCatalog as a sepearator in list of packages.
    regex = "[-a-zA-Z0-9_+]+"


register_converter(PackagesConverter, "pkg")

urlpatterns = [
    ...
] + i18n_patterns(
    path('jsi18n/<pkg:packages>/', JavaScriptCatalog.as_view(), name='jsi18n'),
    path('rcdata/', include(('djangocms_render_context.urls', 'djangocms_render_context'))),
)

The path name jsi18n can be redefined with the DJANGOCMS_RENDER_CONTEXT_JSI18N constant.

Extra settings

This value can be defined in settings.

  • DJANGOCMS_RENDER_CONTEXT_TEMPLATES - List of templates that the plugin can use.
  • DJANGOCMS_RENDER_CONTEXT_DETAIL_TEMPLATES - List of templates that the detail can use.

For example:

DJANGOCMS_RENDER_CONTEXT_TEMPLATES = (
    ("", ""),
    ("plugin.html", "Plugin"),
    ("schedule.html", "Schedule"),
)
DJANGOCMS_RENDER_CONTEXT_DETAIL_TEMPLATES = (
    ("", ""),
    ("detail.html", "Plugin detail"),
)
  • DJANGOCMS_RENDER_CONTEXT_PROCESSORS - List of functions that can work with plugin context.
  • DJANGOCMS_RENDER_CONTEXT_DETAIL_PROCESSORS - List of functions that can work with detail context.

For example:

DJANGOCMS_RENDER_CONTEXT_PROCESSORS = (
    ("", ""),
    ("mysite.utils.process_plugin", "Process plugin"),
)
DJANGOCMS_RENDER_CONTEXT_DETAIL_PROCESSORS = (
    ("", ""),
    ("mysite.utils.process_plugin_detail", "Process plugin detail"),
)

The function in mysite/utils.py:

from django.template.context import RequestContext


def process_plugin(instance: RenderContext, context: dict) -> dict:
    """Process plugin context."""
    context["data"]["extra"] = "content"
    return context


def process_plugin_detail(instance: RenderContext, context: RequestContext) -> RequestContext:
    """Process plugin context."""
    context["detail"]["extra"] = "content"
    return context

License

BSD-3-Clause

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

djangocms_render_context-1.3.4.tar.gz (317.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

djangocms_render_context-1.3.4-py3-none-any.whl (331.0 kB view details)

Uploaded Python 3

File details

Details for the file djangocms_render_context-1.3.4.tar.gz.

File metadata

  • Download URL: djangocms_render_context-1.3.4.tar.gz
  • Upload date:
  • Size: 317.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.3

File hashes

Hashes for djangocms_render_context-1.3.4.tar.gz
Algorithm Hash digest
SHA256 87216030f5479c7aad6fc4cc03e09233da4e8ab59c11ede9c0169182c1f1c352
MD5 ee580bd648d4b6598311830d912aa238
BLAKE2b-256 16c2b7f3b65f9eb488ea01a41986ee101b7676133092cd3582cf6d8f124df54b

See more details on using hashes here.

File details

Details for the file djangocms_render_context-1.3.4-py3-none-any.whl.

File metadata

File hashes

Hashes for djangocms_render_context-1.3.4-py3-none-any.whl
Algorithm Hash digest
SHA256 ed6754c2a19fae4b49e8e0c7a5559c6cb9773083b01ae79c6e43a655f8474cb9
MD5 a6293f3dbb08b093ede55d5f92dc69a4
BLAKE2b-256 523028ae5f2b12c0b464a7d270f0e9140f69071cccb2a91338fa1c2221cf2799

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page