Mezzanine Documentation

repository·master·Indexed 26 days ago

https://github.com/stephenmcd/mezzanine

A highly extensible content management platform built on top of the Django framework. Mezzanine provides out-of-the-box features including blogging, e-commerce, and hierarchical navigation. Documentation covers admin customization, blog importing from platforms like WordPress and Blogger, hybrid caching strategies using two-phased rendering, and a flexible settings system via register_setting.

Tokens
23.2K
Snippets
44
Records
145
Agent score
89%

What's inside Mezzanine

  1. Overview of Mezzanine

    master
    Mezzanine is a powerful, consistent, and flexible content management platform built on the Django framework. It provides an integrated architecture for managing pages, blog posts, form data, and store products. Unlike many other platforms that rely heavily on external modules, Mezzanine provides most of its core functionality by default, resulting in a more efficient and integrated platform.
  2. Getting started with Mezzanine

    master

    Mezzanine is a high-level CMS built on top of Django. To use Mezzanine effectively, you must have a working knowledge of Django. The core philosophy is that "Mezzanine Is Just Django."

    Depending on your role, you should focus on the following areas:

    • Front-end developers: Explore inline-editing to learn how to implement features that allow content authors to edit content directly on the page.
    • Back-end developers: Study the content-architecture to understand how to extend Mezzanine with custom content types, or use model-customization and admin-customization for low-level modifications.
    • System administrators: Review deployment requirements and the caching-strategy for production environments.
  3. Understand Mezzanine Multi-Tenancy

    master

    Mezzanine supports multiple sites within a single running instance by leveraging Django's sites app. Unlike standard Django, which typically uses the SITE_ID setting to bind a project to one site, Mezzanine uses a priority-based pipeline to determine the active site for a request. This allows true multi-tenancy where different domains (or subdomains) can serve different content from the same process.

    The site determination pipeline follows this order:

    1. Session variable site_id: Used by the admin to allow users to switch between sites.
    2. Host matching: The domain of the current HTTP request is compared against the domain names in the Site records.
    3. Environment variable MEZZANINE_SITE_ID: Used for contexts outside of HTTP requests (e.g., management commands). Mezzanine's custom manage.py handles the --site=ID argument.
    4. SITE_ID setting: The fallback if no other method identifies a site.
  4. Key Features of Mezzanine

    master

    Mezzanine includes a wide range of built-in features for content management and site administration:

    • Content Management: Hierarchical page navigation, save as draft/preview, scheduled publishing, drag-and-drop page ordering, and WYSIWYG editing.
    • Site Customization: In-line page editing, custom templates per page/post, and configurable dashboard widgets.
    • Forms & SEO: Drag-and-drop HTML5 forms builder (with CSV export) and SEO-friendly URLs/meta data.
    • E-commerce: Includes the Cartridge shopping cart module.
    • Communication & Social: Multi-lingual site support, social sharing (Facebook/Twitter), and integration with Disqus, Gravatar, and Google Analytics.
    • Extensibility: API for custom content types, search engine and API, and seamless integration with third-party Django apps.
    • Other: Blog engine, tagging, Akismet spam filtering, and bit.ly integration.
  5. Understand Mezzanine Content Architecture

    master

    Mezzanine content is built using abstract models from mezzanine.core and mezzanine.pages. The two primary models for building custom content types are:

    • mezzanine.core.models.Displayable: An abstract model for content that has a URL (slug) but is not part of the site's navigation (e.g., blog posts, calendar events). It provides metadata, auto-generated slugs, publishing status, and searchability.
    • mezzanine.pages.models.Page: A concrete model that extends Displayable and implements a hierarchical navigation tree. This is the foundation for most site content.

    Key abstract building blocks include:

    • SiteRelated: Adds a django.contrib.sites.models.Site field.
    • Slugged: Implements title and slug.
    • MetaData: Provides SEO fields (title, description, keywords).
    • TimeStamped: Provides created and updated timestamps.
    • Ownable: Adds a related user field for authorship.
    • RichText: Provides a WYSIWYG editable field.
    • Orderable: Enables drag/drop ordering.
  6. Add Mezzanine to an existing Django project

    master

    To integrate Mezzanine into an existing project, you must configure the necessary settings and urlpatterns. Refer to the project_template directory in the Mezzanine repository for reference. Key configuration areas include:

    • INSTALLED_APPS
    • TEMPLATES
    • MIDDLEWARE
    • PACKAGE_NAME_GRAPPELLI and PACKAGE_NAME_FILEBROWSER (for Grappelli and Filebrowser integration)
    • The call to mezzanine.utils.conf.set_dynamic_settings at the end of settings.py.
  7. Modify Mezzanine templates

    master

    Mezzanine templates are located in the templates directory of each individual Django app. To modify them:

    1. Locate the template in the Mezzanine app directory (e.g., mezzanine/core/templates/base.html).
    2. Copy the template into your project's local templates directory.
    3. Modify the local copy.

    Alternatively, you can use the collecttemplates command to copy templates automatically:

    python manage.py collecttemplates

    Note: Once copied to your project directory, these templates will always override the original Mezzanine templates, even after upgrades.

    python manage.py collecttemplates --help
  8. Implement Page Processors to extend Page logic

    master

    Since all :class:.Pageinstances are handled by the singlemezzanine.pages.views.page` view, you cannot create custom views for specific page types. Instead, use Page Processors.

    Page Processors are functions associated with a custom :class:.Page model that are called during the view process. They receive two arguments: request and the page instance.

    Return values:

    • A dictionary: The keys/values are added to the template context.
    • An HttpResponse (or subclass): This overrides the default mezzanine.pages.views.page view entirely (useful for handling form submissions via redirects).

    Setup:

    1. Create a module named page_processors.py inside one of your INSTALLED_APPS.
    2. Use the @processor_for(Model) decorator to associate the function with a specific model.
    3. Alternatively, use @processor_for(slug='your-slug') to run the processor only when a specific page slug is matched.
    from django import forms
    from django.http import HttpResponseRedirect
    from mezzanine.pages.page_processors import processor_for
    from .models import Author
    
    class AuthorForm(forms.Form):
        name = forms.CharField()
        email = forms.EmailField()
    
    @processor_for(Author)
    def author_form(request, page):
        form = AuthorForm()
        if request.method == "POST":
            form = AuthorForm(request.POST)
            if form.is_valid():
                # Form processing goes here.
                redirect = request.path + "?submitted=true"
                return HttpResponseRedirect(redirect)
        return {"form": form}
  9. Override Mezzanine settings with Django settings

    master

    Mezzanine's settings system integrates with standard Django settings in two ways:

    1. Overriding Defaults: You can override any setting registered via register_setting by defining it as a standard variable in your project's settings.py. This is useful for overriding non-editable settings from third-party apps.
    2. Unified Access: The mezzanine.conf.settings object provides a single access point for both Mezzanine-registered settings and standard Django settings.

    Note: If a setting is marked as editable=True, defining it in your project's settings.py will always override the value stored in the database.

  10. Add your site to the Mezzanine gallery

    master

    If you have built a site using Mezzanine and want to feature it in the project's gallery, you can do so by submitting a pull request to the Mezzanine repository.

    Submission Requirements:

    • Fork the project.
    • Create a pull request adding your site to the list.
    • Important: Omit the trailing slash in your site's URL, as the project manually adds it during the featuring process.
  11. Import blogs from Blogger

    master

    To import from Blogger, you must first obtain your Blogger ID from your Blogger settings (found in the browser URL as BlogID=XXX). Additionally, you must set Allow Blog Feeds to Full in the Site Feed settings to ensure all data is retrieved.

    Limitation: The import is truncated if there are more than 500 blogs or 500 comments per blog.