Packages

Below are auto-generated docs mostly covering each of the packages contained within Mezzanine that are added to settings.INSTALLED_APPS.

mezzanine.boot

An app that is forced to the top of the list in INSTALLED_APPS for the purpose of hooking into Django’s class_prepared signal and adding custom fields as defined by the EXTRA_MODEL_FIELDS setting. Also patches django.contrib.admin.site to use LazyAdminSite that defers certains register/unregister calls until admin.autodiscover to avoid some timing issues around custom fields not being available when custom admin classes are registered.

mezzanine.core

Provides abstract models and admin features used throughout the various Mezzanine apps.

mezzanine.core.models

class mezzanine.core.models.Displayable(*args, **kwargs)

Abstract model that provides features of a visible page on the website such as publishing fields. Basis of Mezzanine pages, blog posts, and Cartridge products.

save(*args, **kwargs)

Set default for publish_date. We can’t use auto_add on the field as it will be blank when a blog post is created from the quick blog form in the admin dashboard.

class mezzanine.core.models.MetaData(*args, **kwargs)

Abstract model that provides meta data for content.

description_from_content()

Returns the first block or sentence of the first content-like field.

save(*args, **kwargs)

Set the description field on save.

class mezzanine.core.models.Orderable(*args, **kwargs)

Abstract model that provides a custom ordering integer field similar to using Meta’s order_with_respect_to, since to date (Django 1.2) this doesn’t work with ForeignKey("self"), or with Generic Relations. We may also want this feature for models that aren’t ordered with respect to a particular field.

delete(*args, **kwargs)

Update the ordering values for siblings.

save(*args, **kwargs)

Set the initial ordering value.

with_respect_to()

Returns a dict to use as a filter for ordering operations containing the original Meta.order_with_respect_to value if provided. If the field is a Generic Relation, the dict returned contains names and values for looking up the relation’s ct_field and fk_field attributes.

class mezzanine.core.models.OrderableBase

Checks for order_with_respect_to on the model’s inner Meta class and if found, copies it to a custom attribute and deletes it since it will cause errors when used with ForeignKey("self"). Also creates the ordering attribute on the Meta class if not yet provided.

class mezzanine.core.models.Ownable(*args, **kwargs)

Abstract model that provides ownership of an object for a user.

is_editable(request)

Restrict in-line editing to the objects’s owner and superusers.

class mezzanine.core.models.RichText(*args, **kwargs)

Provides a Rich Text field for managing general content and making it searchable.

class mezzanine.core.models.Slugged(*args, **kwargs)

Abstract model that handles auto-generating slugs. Each slugged object is also affiliated with a specific site object.

get_slug()

Allows subclasses to implement their own slug creation logic.

save(update_site=False, *args, **kwargs)

Create a unique slug by appending an index. Set the site to the current site when the record is first created, unless the update_site argument is explicitly set to True.

mezzanine.core.managers

class mezzanine.core.managers.DisplayableManager(field_name=None)

Manually combines CurrentSiteManager, PublishedManager and SearchableManager for the Displayable model.

class mezzanine.core.managers.PublishedManager

Provides filter for restricting items returned by status and publish date when the given user is not a staff member.

published(for_user=None)

For non-staff users, return items with a published status and whose publish and expiry dates fall before and after the current date when specified.

class mezzanine.core.managers.SearchableManager(*args, **kwargs)

Manager providing a chainable queryset. Adapted from http://www.djangosnippets.org/snippets/562/ search method supports spanning across models that subclass the model being used to search.

search(*args, **kwargs)

Proxy to queryset’s search method for the manager’s model and any models that subclass from this manager’s model if the model is abstract.

class mezzanine.core.managers.SearchableQuerySet(*args, **kwargs)

QuerySet providing main search functionality for SearchableManager.

iterator()

If search has occurred and no ordering has occurred, decorate each result with the number of search terms so that it can be sorted by the number of occurrence of terms.

order_by(*field_names)

Mark the filter as being ordered if search has occurred.

search(query, search_fields=None)

Build a queryset matching words in the given search query, treating quoted terms as exact phrases and taking into account + and - symbols as modifiers controlling which terms to require and exclude.

mezzanine.core.views

mezzanine.core.views.account(request, template='account.html')

Display and handle both the login and signup forms.

mezzanine.core.views.direct_to_template(request, template, extra_context=None, **kwargs)

Replacement for Django’s direct_to_template that uses TemplateResponse via mezzanine.utils.views.render.

mezzanine.core.views.edit(request)

Process the inline editing form.

mezzanine.core.views.logout(request)

Log the user out.

mezzanine.core.views.search(request, template='search_results.html')

Display search results.

mezzanine.core.views.server_error(request, template_name='500.html')

Mimics Django’s error handler but adds STATIC_URL to the context.

mezzanine.core.views.set_device(request, device='')

Sets a device name in a cookie when a user explicitly wants to go to the site for a particular device (eg mobile).

mezzanine.core.views.verify_account(request, uidb36=None, token=None)

View for the link in the verification email sent to a new user when they create an account and ACCOUNTS_VERIFICATION_REQUIRED is set to True. Activates the user and logs them in, redirecting to the URL they tried to access when signing up.

mezzanine.core.forms

class mezzanine.core.forms.DynamicInlineAdminForm(*args, **kwargs)

Form for DynamicInlineAdmin that can be collapsed and sorted with drag and drop using OrderWidget.

class mezzanine.core.forms.OrderWidget(attrs=None)

Add up and down arrows for ordering controls next to a hidden form field.

class mezzanine.core.forms.SplitSelectDateTimeWidget(attrs=None, date_format=None, time_format=None)

Combines Django’s SelectDateTimeWidget and SelectDateWidget.

class mezzanine.core.forms.TinyMceWidget(*args, **kwargs)

Setup the JS files and targetting CSS class for a textarea to use TinyMCE.

class mezzanine.core.forms.UserForm(request, *args, **kwargs)

Fields for signup & login.

authenticate()

Validate email and password as well as setting the user for login.

login(request)

Log the user in.

mezzanine.core.forms.get_edit_form(obj, field_names, data=None, files=None)

Returns the in-line editing form for editing a single model field.

mezzanine.core.admin

class mezzanine.core.admin.BaseDynamicInlineAdmin(*args, **kwargs)

Admin inline that uses JS to inject an “Add another” link which when clicked, dynamically reveals another fieldset. Also handles adding the _order field and its widget for models that subclass Orderable.

form

alias of DynamicInlineAdminForm

class mezzanine.core.admin.DisplayableAdmin(model, admin_site)

Admin class for subclasses of the abstract Displayable model.

class mezzanine.core.admin.OwnableAdmin(model, admin_site)

Admin class for models that subclass the abstract Ownable model. Handles limiting the change list to objects owned by the logged in user, as well as setting the owner of newly created objects to the logged in user.

queryset(request)

Filter the change list by currently logged in user if not a superuser.

save_form(request, form, change)

Set the object’s owner as the logged in user.

class mezzanine.core.admin.SingletonAdmin(model, admin_site)

Admin class for models that should only contain a single instance in the database. Redirect all views to the change view when the instance exists, and to the add view when it doesn’t.

add_view(*args, **kwargs)

Redirect to the change view if the singleton instance exists.

change_view(request, object_id, extra_context=None)

If only the singleton instance exists, pass True for singleton into the template which will use CSS to hide the “save and add another” button.

changelist_view(*args, **kwargs)

Redirect to the add view if no records exist or the change view if the singleton instance exists.

mezzanine.core.middleware

class mezzanine.core.middleware.AdminLoginInterfaceSelectorMiddleware

Checks for a POST from the admin login view and if authentication is successful and the “site” interface is selected, redirect to the site.

class mezzanine.core.middleware.DeviceAwareCacheMiddleware

Mixin for device-aware cache middleware that provides the method for prefixing the cache key with a device.

class mezzanine.core.middleware.DeviceAwareFetchFromCacheMiddleware

Device-aware version of Django’s FetchFromCacheMiddleware - prefixes the internal cache key with the device for the request for each request.

class mezzanine.core.middleware.DeviceAwareUpdateCacheMiddleware

Device-aware version of Django’s UpdateCacheMiddleware - prefixes the internal cache key with the device for the request for each response.

class mezzanine.core.middleware.SSLRedirectMiddleware

Handles redirections required for SSL when SSL_ENABLED is True.

If SSL_FORCE_HOST is True, and is not the current host, redirect to it.

Also ensure URLs defined by SSL_FORCE_URL_PREFIXES are redirect to HTTPS, and redirect all other URLs to HTTP if on HTTPS.

mezzanine.core.templatetags.mezzanine_tags

mezzanine.core.templatetags.mezzanine_tags.admin_app_list(request)

Adopted from django.contrib.admin.sites.AdminSite.index. Returns a list of lists of models grouped and ordered according to mezzanine.conf.ADMIN_MENU_ORDER. Called from the admin_dropdown_menu template tag as well as the app_list dashboard widget.

mezzanine.core.templatetags.mezzanine_tags.admin_dropdown_menu(parser, token)

Renders the app list for the admin dropdown menu navigation.

mezzanine.core.templatetags.mezzanine_tags.app_list(parser, token)

Renders the app list for the admin dashboard widget.

mezzanine.core.templatetags.mezzanine_tags.dashboard_column(parser, token)

Takes an index for retrieving the sequence of template tags from mezzanine.conf.DASHBOARD_TAGS to render into the admin dashboard.

mezzanine.core.templatetags.mezzanine_tags.editable(parser, token)

Add the required HTML to the parsed content for in-line editing, such as the icon and edit form if the object is deemed to be editable - either it has an editable method which returns True, or the logged in user has change permissions for the model.

mezzanine.core.templatetags.mezzanine_tags.editable_loader(parser, token)

Set up the required JS/CSS for the in-line editing toolbar and controls.

mezzanine.core.templatetags.mezzanine_tags.fields_for(parser, token)

Renders fields for a form.

mezzanine.core.templatetags.mezzanine_tags.is_installed(app_name)

Returns True if the given app name is in the INSTALLED_APPS setting.

mezzanine.core.templatetags.mezzanine_tags.metablock(parser, token)

Remove HTML tags, entities and superfluous characters from meta blocks.

mezzanine.core.templatetags.mezzanine_tags.pagination_for(parser, token)

Include the pagination template and data for persisting querystring in pagination links.

mezzanine.core.templatetags.mezzanine_tags.recent_actions(parser, token)

Renders the recent actions list for the admin dashboard widget.

mezzanine.core.templatetags.mezzanine_tags.richtext_filter(content)

This template filter takes a string value and passes it through the function specified by the RICHTEXT_FILTER setting.

mezzanine.core.templatetags.mezzanine_tags.set_short_url_for(parser, token)

Sets the short_url attribute of the given model using the bit.ly credentials if they have been specified and saves it.

mezzanine.core.templatetags.mezzanine_tags.thumbnail(image_url, width, height)

Given the URL to an image, resizes the image using the given width and height on the first time it is requested, and returns the URL to the new resized image. if width or height are zero then original ratio is maintained.

mezzanine.core.templatetags.mezzanine_tags.try_url(url_name)

Mimics Django’s url template tag but fails silently. Used for url names in admin templates as these won’t resolve when admin tests are running.

mezzanine.core.management.commands

mezzanine.core.tests

class mezzanine.core.tests.Tests(methodName='runTest')

Mezzanine tests.

create_recursive_objects(model, parent_field, **kwargs)

Create multiple levels of recursive objects.

queries_used_for_template(template, **context)

Return the number of queries used when rendering a template string.

setUp()

Create an admin user.

test_account()

Test account creation.

test_blog_views()

Basic status code test for blog views.

test_comments()

Test that rendering comments executes the same number of queries, regardless of the number of nested replies.

test_description()

Test generated description is text version of the first line of content.

test_device_specific_template()

Test that an alternate template is rendered when a mobile device is used.

test_draft_page()

Test a draft page as only being viewable by a staff member.

test_forms()

Simple 200 status check against rendering and posting to forms with both optional and required fields.

Test that a gallery creates images when given a zip file to import, and that descriptions are created.

test_keywords()

Test that the keywords_string field is correctly populated.

test_overridden_page()

Test that a page with a slug matching a non-page urlpattern return True for its overridden property.

test_page_menu()

Test that rendering a page menu executes the same number of queries regardless of the number of pages or levels of children.

test_rating()

Test that ratings can be posted and avarage/count are calculated.

Test search.

test_settings()

Test that an editable setting can be overridden with a DB value and that the data type is preserved when the value is returned back out of the DB. Also checks to ensure no unsupported types are defined for editable settings.

test_syntax()

Run pyflakes/pep8 across the code base to check for potential errors.

test_thumbnail_generation()

Test that a thumbnail is created and resized.

test_utils()

Miscellanous tests for the mezzanine.utils package.

mezzanine.pages

Provides the main structure of a Mezzanine site with a hierarchical tree of pages, each subclassing the Page model to create a content structure.

mezzanine.pages.models

class mezzanine.pages.models.Page(*args, **kwargs)

A page in the page tree. This is the base class that custom content types need to subclass.

can_add(request)

Dynamic add permission for content types to override.

can_change(request)

Dynamic change permission for content types to override.

can_delete(request)

Dynamic change permission for content types to override.

get_content_model()

Provies a generic method of retrieving the instance of the custom content type’s model for this page.

get_slug()

Recursively build the slug from the chain of parents.

overridden()

Returns True if the page’s slug has an explicitly defined urlpattern and is therefore considered to be overridden.

reset_slugs()

Called when the parent page is changed in the admin and the slug plus all child slugs need to be recreated given the new parent.

save(*args, **kwargs)

Create the titles field using the titles up the parent chain and set the initial value for ordering.

set_menu_helpers(slug)

Called from the page_menu template tag and assigns a handful of properties based on the current URL that are used within the various types of menus.

class mezzanine.pages.models.RichTextPage(*args, **kwargs)

Implements the default type of page with a single Rich Text content field.

mezzanine.pages.views

mezzanine.pages.views.admin_page_ordering(request, *args, **kwargs)

Updates the ordering of pages via AJAX from within the admin.

mezzanine.pages.views.page(request, slug, template='pages/page.html', extra_context=None)

Display content for a page. First check for any matching page processors and handle them. Secondly, build the list of template names to choose from given the slug and type of page being viewed.

mezzanine.pages.admin

class mezzanine.pages.admin.PageAdmin(*args, **kwargs)

Admin class for the Page model and all subclasses of Page. Handles redirections between admin interfaces for the Page model and its subclasses.

add_view(request, extra_context=None, **kwargs)

For the Page model, redirect to the add view for the RichText model.

change_view(request, object_id, extra_context=None)

For the Page model, check page.get_content_model() for a subclass and redirect to its admin change view. Also enforce custom change permissions for the page instance.

changelist_view(request, extra_context=None)

Redirect to the Page changelist view for Page subclasses.

delete_view(request, object_id, extra_context=None)

Enforce custom delete permissions for the page instance.

in_menu()

Hide subclasses from the admin menu.

response_add(request, obj)

Enforce page permissions and maintain the parent ID in the querystring.

response_change(request, obj)

Enforce page permissions and maintain the parent ID in the querystring.

save_model(request, obj, form, change)

Set the ID of the parent page if passed in via querystring.

mezzanine.pages.templatetags.pages_tags

mezzanine.pages.templatetags.pages_tags.models_for_pages(parser, token)

Create a select list containing each of the models that subclass the Page model.

mezzanine.pages.templatetags.pages_tags.page_menu(parser, token)

Return a list of child pages for the given parent, storing all pages in a dict in the context when first called using parents as keys for retrieval on subsequent recursive calls from the menu template.

mezzanine.pages.templatetags.pages_tags.set_model_permissions(parser, token)

Assigns a permissions dict to the given model, much like Django does with its dashboard app list.

Used within the change list for pages, to implement permission checks for the navigation tree.

mezzanine.pages.templatetags.pages_tags.set_page_permissions(parser, token)

Assigns a permissions dict to the given page instance, combining Django’s permission for the page’s model and a permission check against the instance itself calling the page’s can_add, can_change and can_delete custom methods.

Used within the change list for pages, to implement permission checks for the navigation tree.

mezzanine.pages.page_processors

mezzanine.pages.page_processors.autodiscover()

Taken from django.contrib.admin.autodiscover and used to run any calls to the processor_for decorator.

mezzanine.pages.page_processors.processor_for(content_model_or_slug)

Decorator that registers the decorated function as a page processor for the given content model or slug.

mezzanine.generic

Provides various models and associated functionality, that can be related to any other model using generic relationshipswith Django’s contenttypes framework, such as comments, keywords/tags and voting.

mezzanine.generic.models

class mezzanine.generic.models.AssignedKeyword(*args, **kwargs)

A Keyword assigned to a model instance.

class mezzanine.generic.models.Keyword(*args, **kwargs)

Keywords/tags which are managed via a custom Javascript based widget in the admin.

class mezzanine.generic.models.Rating(*args, **kwargs)

A rating that can be given to a piece of content.

save(*args, **kwargs)

Validate that the rating falls between the min and max values.

class mezzanine.generic.models.ThreadedComment(*args, **kwargs)

Extend the Comment model from django.contrib.comments to add comment threading.

get_absolute_url(*moreargs, **morekwargs)

Use the URL for the comment’s content object, with a URL hash appended that references the individual comment.

save(*args, **kwargs)

Store the email hash of the comment for using with Gravatar.com, and set is_public based on the setting COMMENTS_DEFAULT_APPROVED.

mezzanine.generic.managers

class mezzanine.generic.managers.CommentManager

Provides filter for restricting comments that are not approved if COMMENTS_UNAPPROVED_VISIBLE is set to False.

count_queryset()

Called from CommentsField.related_items_changed to store the comment count against an item each time a comment is saved.

visible()

Return the comments that are visible based on the COMMENTS_XXX_VISIBLE settings. When these settings are set to True, the relevant comments are returned that shouldn’t be shown, and are given placeholders in the template generic/includes/comment.html.

class mezzanine.generic.managers.KeywordManager(field_name=None)

Provides natural key method.

mezzanine.generic.fields

class mezzanine.generic.fields.BaseGenericRelation(*args, **kwargs)

Extends GenericRelation to:

  • Add a consistent default value for object_id_field and check for a related_model attribute which can be defined on subclasses as a default for the to argument.
  • Add one or more custom fields to the model that the relation field is applied to, and then call a related_items_changed method each time related items are saved or deleted, so that a calculated value can be stored against the custom fields since aggregates aren’t available for GenericRelation instances.
contribute_to_class(cls, name)

Add each of the names and fields in the fields attribute to the model the relationship field is applied to, and set up the related item save and delete signals for calling related_items_changed.

related_items_changed(instance, related_manager)

Can be implemented by subclasses - called whenever the state of related items change, eg they’re saved or deleted. The instance for this field and the related manager for the field are passed as arguments.

class mezzanine.generic.fields.CommentsField(*args, **kwargs)

Stores the number of comments against the COMMENTS_FIELD_NAME_count field when a comment is saved or deleted.

related_items_changed(instance, related_manager)

Stores the number of comments. A custom count_filter queryset gets checked for, allowing managers to implement custom count logic.

class mezzanine.generic.fields.KeywordsField(*args, **kwargs)

Stores the keywords as a single string into the KEYWORDS_FIELD_NAME_string field for convenient access when searching.

contribute_to_class(cls, name)

Swap out any reference to KeywordsField with the KEYWORDS_FIELD_string field in search_fields.

formfield(**kwargs)

Provide the custom form widget for the admin, since there isn’t a form field mapped to GenericRelation model fields.

related_items_changed(instance, related_manager)

Stores the keywords as a single string for searching.

save_form_data(instance, data)

The KeywordsWidget field will return data as a string of comma separated IDs for the Keyword model - convert these into actual AssignedKeyword instances. Also delete Keyword instances if their last related AssignedKeyword instance is being removed.

class mezzanine.generic.fields.RatingField(*args, **kwargs)

Stores the rating count and average against the RATING_FIELD_NAME_count and RATING_FIELD_NAME_average fields when a rating is saved or deleted.

related_items_changed(instance, related_manager)

Calculates and saves the average rating.

mezzanine.generic.views

mezzanine.generic.views.admin_keywords_submit(request, *args, **kwargs)

Adds any new given keywords from the custom keywords field in the admin, and returns their IDs for use when saving a model with a keywords field.

mezzanine.generic.views.comment(request, template='generic/comments.html')

Handle a ThreadedCommentForm submission and redirect back to its related object.

mezzanine.generic.views.rating(request)

Handle a RatingForm submission and redirect back to its related object.

mezzanine.generic.forms

class mezzanine.generic.forms.KeywordsWidget(attrs=None)

Form field for the KeywordsField generic relation field. Since the admin with model forms has no form field for generic relations, this form field provides a single field for managing the keywords. It contains two actual widgets, a text input for entering keywords, and a hidden input that stores the ID of each Keyword instance.

The attached JavaScript adds behaviour so that when the form is submitted, an AJAX post is made that passes the list of keywords in the text input, and returns a list of keyword IDs which are then entered into the hidden input before the form submits. The list of IDs in the hidden input is what is used when retrieving an actual value from the field for the form.

decompress(value)

Takes the sequence of AssignedKeyword instances and splits them into lists of keyword IDs and titles each mapping to one of the form field widgets.

format_output(rendered_widgets)

Wraps the output HTML with a list of all available Keyword instances that can be clicked on to toggle a keyword.

value_from_datadict(data, files, name)

Return the comma separated list of keyword IDs for use in KeywordsField.save_form_data().

class mezzanine.generic.forms.RatingForm(target_object, data=None, initial=None)

Form for a rating. Subclasses CommentSecurityForm to make use of its easy setup for generic relations.

mezzanine.generic.admin

class mezzanine.generic.admin.ThreadedCommentAdmin(model, admin_site)

Admin class for comments.

mezzanine.generic.templatetags.comment_tags

mezzanine.generic.templatetags.comment_tags.comment_thread(parser, token)

Return a list of child comments for the given parent, storing all comments in a dict in the context when first called, using parents as keys for retrieval on subsequent recursive calls from the comments template.

mezzanine.generic.templatetags.comment_tags.comments_for(parser, token)

Provides a generic context variable name for the object that comments are being rendered for.

mezzanine.generic.templatetags.comment_tags.gravatar_url(email_hash, size=32)

Return the full URL for a Gravatar given an email hash.

mezzanine.generic.templatetags.comment_tags.recent_comments(parser, token)

Dashboard widget for displaying recent comments.

mezzanine.generic.templatetags.disqus_tags

mezzanine.generic.templatetags.disqus_tags.disqus_id_for(obj)

Returns a unique identifier for the object to be used in DISQUS JavaScript.

mezzanine.generic.templatetags.disqus_tags.disqus_sso_script(parser, token)

Provides a generic context variable which adds single-sign-on support to DISQUS if COMMENTS_DISQUS_API_PUBLIC_KEY and COMMENTS_DISQUS_API_SECRET_KEY are specified.

mezzanine.generic.templatetags.keyword_tags

mezzanine.generic.templatetags.keyword_tags.keywords_for(parser, token)

Return a list of Keyword objects for the given model instance or a model class. In the case of a model class, retrieve all keywords for all instances of the model and apply a weight attribute that can be used to create a tag cloud.

mezzanine.generic.templatetags.rating_tags

mezzanine.generic.templatetags.rating_tags.rating_for(parser, token)

Provides a generic context variable name for the object that ratings are being rendered for, and the rating form.

mezzanine.blog

Provides a blogging app with posts, keywords, categories and comments. Posts can be listed by month, keyword, category or author.

mezzanine.blog.models

class mezzanine.blog.models.BlogCategory(*args, **kwargs)

A category for grouping blog posts into a series.

class mezzanine.blog.models.BlogPost(*args, **kwargs)

A blog post.

mezzanine.blog.views

mezzanine.blog.views.blog_page()

Return the Blog page from the pages app.

mezzanine.blog.views.blog_post_detail(request, slug, year=None, month=None, template='blog/blog_post_detail.html')

. Custom templates are checked for using the name blog/blog_post_detail_XXX.html where XXX is the blog posts’s slug.

mezzanine.blog.views.blog_post_list(request, tag=None, year=None, month=None, username=None, category=None, template='blog/blog_post_list.html')

Display a list of blog posts that are filtered by tag, year, month, author or category. Custom templates are checked for using the name blog/blog_post_list_XXX.html where XXX is either the category slug or author’s username if given.

mezzanine.blog.forms

class mezzanine.blog.forms.BlogPostForm

Model form for BlogPost that provides the quick blog panel in the admin dashboard.

mezzanine.blog.admin

class mezzanine.blog.admin.BlogCategoryAdmin(model, admin_site)

Admin class for blog categories. Hides itself from the admin menu unless explicitly specified.

in_menu()

Hide from the admin menu unless explicitly set in ADMIN_MENU_ORDER.

class mezzanine.blog.admin.BlogPostAdmin(model, admin_site)

Admin class for blog posts.

save_form(request, form, change)

Super class ordering is important here - user must get saved first.

mezzanine.blog.feeds

class mezzanine.blog.feeds.PostsAtom(*args, **kwargs)

Atom feed for all blog posts.

class mezzanine.blog.feeds.PostsRSS(*args, **kwargs)

RSS feed for all blog posts.

mezzanine.blog.templatetags.blog_tags

mezzanine.blog.templatetags.blog_tags.blog_authors(parser, token)

Put a list of authors (users) for blog posts into the template context.

mezzanine.blog.templatetags.blog_tags.blog_categories(parser, token)

Put a list of categories for blog posts into the template context.

mezzanine.blog.templatetags.blog_tags.blog_months(parser, token)

Put a list of dates for blog posts into the template context.

mezzanine.blog.templatetags.blog_tags.blog_recent_posts(parser, token)

Put a list of recently published blog posts into the template context.

mezzanine.blog.templatetags.blog_tags.quick_blog(parser, token)

Admin dashboard tag for the quick blog form.

mezzanine.blog.management.base

class mezzanine.blog.management.base.BaseImporterCommand(**kwargs)

Base importer command for blogging platform specific management commands to subclass when importing blog posts into Mezzanine. The handle_import method should be overridden to provide the import mechanism specific to the blogging platform being dealt with.

add_comment(post=None, name=None, email=None, pub_date=None, website=None, body=None)

Adds a comment to the post provided.

Attributes:
pub_date is assumed to be a date time object.
add_post(title=None, pub_date=None, tags=None, content=None, comments=None, old_url=None, categories=None)

Adds a post to the post list for processing.

Attributes:
pub_date is assumed to be a datetime object.
handle(*args, **options)

Processes the converted data into the Mezzanine database correctly.

Attributes:
mezzanine_user: the user to put this data in against date_format: the format the dates are in for posts and comments
handle_import(options)

Should be overridden by subclasses - performs the conversion from the originating data source into the lists of posts and comments ready for processing.

mezzanine.blog.management.commands

class mezzanine.blog.management.commands.import_blogger.Command(**kwargs)

Implements a Blogger importer. Takes a Blogger ID in order to be able to determine which blog it should point to and harvest the XML from.

handle_import(options)

Gets posts from Blogger.

class mezzanine.blog.management.commands.import_wordpress.Command(**kwargs)

Implements a Wordpress importer. Takes a file path or a URL for the Wordpress Extended RSS file.

get_text(xml, element, nodetype)

Gets the element’s text value from the XML object provided.

handle_import(options)

Gets the posts from either the provided URL or the path if it is local.

class mezzanine.blog.management.commands.import_tumblr.Command(**kwargs)

Import Tumblr blog posts into the blog app.

mezzanine.blog.management.commands.import_tumblr.title_from_content(content)

Try and extract the first sentence from a block of test to use as a title.

mezzanine.forms

A port of django-forms-builder for Mezzanine. Allows admin users to create their own HTML5 forms and export form submissions as CSV.

mezzanine.forms.models

class mezzanine.forms.models.Field(*args, **kwargs)

A field for a user-built form.

get_choices()

Parse a comma separated choice string into a list of choices taking into account quoted choices.

is_a(*args)

Helper that returns True if the field’s type is given in any arg.

class mezzanine.forms.models.FieldEntry(*args, **kwargs)

A single field value for a form entry submitted via a user-built form.

class mezzanine.forms.models.FieldManager

Only show visible fields when displaying actual form..

class mezzanine.forms.models.Form(*args, **kwargs)

A user-built form.

class mezzanine.forms.models.FormEntry(*args, **kwargs)

An entry submitted via a user-built form.

mezzanine.forms.forms

class mezzanine.forms.forms.EntriesForm(form, request, *args, **kwargs)

Form with a set of fields dynamically assigned that can be used to filter entries for the given forms.models.Form instance.

columns()

Returns the list of selected column names.

rows(csv=False)

Returns each row based on the selected criteria.

class mezzanine.forms.forms.FormForForm(form, *args, **kwargs)

Form with a set of fields dynamically assigned, directly based on the given forms.models.Form instance.

email_to()

Return the value entered for the first field of type forms.fields.EMAIL.

save(**kwargs)

Create a FormEntry instance and related FieldEntry instances for each form field.

mezzanine.forms.page_processors

mezzanine.forms.page_processors.form_processor(request, page)

Display a built form and handle submission.

mezzanine.forms.page_processors.format_value(value)

Convert a list into a comma separated string, for displaying select multiple values in emails.

mezzanine.forms.admin

class mezzanine.forms.admin.FieldAdmin(*args, **kwargs)

Admin class for the form field. Inherits from TabularDynamicInlineAdmin to add dynamic “Add another” link and drag/drop ordering.

model

alias of Field

class mezzanine.forms.admin.FormAdmin(*args, **kwargs)

Admin class for the Form model. Includes the urls & views for exporting form entries as CSV and downloading files uploaded via the forms app.

entries_view(request, form_id)

Displays the form entries in a HTML table with option to export as CSV file.

file_view(request, field_entry_id)

Output the file for the requested field entry.

get_urls()

Add the entries view to urls.

mezzanine.galleries

Implements a photo gallery content type.

mezzanine.galleries.models

class mezzanine.galleries.models.Gallery(*args, **kwargs)

Page bucket for gallery photos.

save(delete_zip_import=True, *args, **kwargs)

If a zip file is uploaded, extract any images from it and add them to the gallery, before removing the zip file.

class mezzanine.galleries.models.GalleryImage(*args, **kwargs)

GalleryImage(id, _order, gallery_id, file, description)

save(*args, **kwargs)

If no description is given when created, create one from the file name.

mezzanine.galleries.admin

mezzanine.conf

Drop-in replacement for django.conf.settings that provides a consistent access method for settings defined in applications, the project or Django itself. Settings can also be made editable via the admin.

class mezzanine.conf.Settings

An object that provides settings via dynamic attribute access. Settings that are registered as editable and can therefore be stored in the database are all loaded once only, the first time any editable setting is accessed. When accessing uneditable settings their default values are used. The Settings object also provides access to Django settings via django.conf.settings in order to provide a consistent method of access for all settings.

use_editable()

Empty the editable settings cache and set the loaded flag to False so that settings will be loaded from the DB on next access. If the conf app is not installed then set the loaded flag to True in order to bypass DB lookup entirely.

mezzanine.conf.register_setting(name='', label='', editable=False, description='', default=None, append=False)

Registers a setting that can be edited via the admin.

mezzanine.conf.models

class mezzanine.conf.models.Setting(*args, **kwargs)

Stores values for mezzanine.conf that can be edited via the admin.

save(*args, **kwargs)

Set the site to the current site.

mezzanine.conf.forms

class mezzanine.conf.forms.SettingsForm(*args, **kwargs)

Form for settings - creates a field for each setting in mezzanine.conf that is marked as editable.

mezzanine.conf.admin

class mezzanine.conf.admin.SettingsAdmin(model, admin_site)

Admin class for settings model. Redirect add/change views to the list view where a single form is rendered for editing all settings.

mezzanine.conf.context_processors

mezzanine.conf.context_processors.settings(request)

Add the settings object to the template context.

mezzanine.template

class mezzanine.template.Library

Extends django.template.Library providing several shortcuts that attempt to take the leg-work out of creating different types of template tags.

as_tag(tag_func)

Creates a tag expecting the format: {% tag_name as var_name %} The decorated func returns the value that is given to var_name in the template.

inclusion_tag(name, context_class=<class 'django.template.context.Context'>, takes_context=False)

Replacement for Django’s inclusion_tag which looks up device specific templates at render time.

render_tag(tag_func)

Creates a tag using the decorated func as the render function for the template tag node. The render function takes two arguments - the template context and the tag token.

to_end_tag(tag_func)

Creates a tag that parses until it finds the corresponding end tag, eg: for a tag named mytag it will parse until endmytag. The decorated func’s return value is used to render the parsed content and takes three arguments - the parsed content between the start and end tags, the template context and the tag token.

mezzanine.twitter

Provides models and utilities for displaying different types of Twitter feeds.

mezzanine.twitter.models

class mezzanine.twitter.models.Query(*args, **kwargs)

Query(id, type, value, interested)

run()

Request new tweets from the Twitter API.

class mezzanine.twitter.models.Tweet(*args, **kwargs)

Tweet(id, remote_id, created_at, text, profile_image_url, user_name, full_name, retweeter_profile_image_url, retweeter_user_name, retweeter_full_name, query_id)

mezzanine.twitter.managers

class mezzanine.twitter.managers.TweetManager

Manager that handles generating the initial Query instance for a user, list or search term.

get_for(user_name=None, list_name=None, search_term=None)

Create a query and run it for the given arg if it doesn’t exist, and return the tweets for the query.

mezzanine.twitter.templatetags.twitter_tags

mezzanine.twitter.templatetags.twitter_tags.tweets_for(type, args, per_user=None)

Retrieve tweets for a user, list or search term. The optional per_user arg limits the number of tweets per user, for example to allow a fair spread of tweets per user for a list.

mezzanine.twitter.templatetags.twitter_tags.tweets_for_list(parser, token)

Tweets for a user’s list.

Tweets for a search query.

mezzanine.twitter.templatetags.twitter_tags.tweets_for_user(parser, token)

Tweets for a user.

mezzanine.twitter.management.commands

class mezzanine.twitter.management.commands.poll_twitter.Command

Polls the Twitter API for tweets associated to the queries in templates.

mezzanine.utils

Various utility functions used throughout the different Mezzanine apps.

mezzanine.utils.conf.set_dynamic_settings(s)

Called at the end of the project’s settings module and is passed its globals dict for updating with some final tweaks for settings that generally aren’t specified but can be given some better defaults based on other settings that have been specified. Broken out into its own function so that the code need not be replicated in the settings modules of other project-based apps that leverage Mezzanine’s settings module.

class mezzanine.utils.html.TagCloser(html)

HTMLParser that closes open tags. Takes a HTML string as its first arg, and populate a html attribute on the parser with the original HTML arg and any required closing tags.

mezzanine.utils.html.decode_entities(html)

Remove HTML entities from a string. Adapted from http://effbot.org/zone/re-sub.htm#unescape-html

Utils called from project_root/docs/conf.py when Sphinx documentation is generated.

mezzanine.utils.docs.build_changelog(docs_path, package_name='mezzanine')

Converts Mercurial commits into a changelog in RST format.

mezzanine.utils.docs.build_modelgraph(docs_path, package_name='mezzanine')

Creates a diagram of all the models for mezzanine and the given package name, generates a smaller version and add it to the docs directory for use in model-graph.rst

mezzanine.utils.docs.build_requirements(docs_path, package_name='mezzanine')

Updates the requirements file with Mezzanine’s version number.

mezzanine.utils.docs.build_settings_docs(docs_path, prefix=None)

Converts names, descriptions and defaults for settings in mezzanine.conf.registry into RST format for use in docs, optionally filtered by setting names with the given prefix.

mezzanine.utils.importing.import_dotted_path(path)

Takes a dotted path to a member name in a module, and returns the member after importing it.

mezzanine.utils.importing.path_for_import(name)

Returns the directory path for the given package or module.

class mezzanine.utils.models.ModelMixin

Used as a subclass for mixin models that inject their behaviour onto models defined outside of a project. The subclass should define an inner Meta class with a mixin_for attribute containing the model that will be mixed into.

class mezzanine.utils.models.ModelMixinBase

Metaclass for ModelMixin which is ued for injecting model fields and methods into models defined outside of a project.

mezzanine.utils.models.base_concrete_model(abstract, instance)

Used in methods of abstract models to find the super-most concrete (non abstract) model in the inheritance chain that inherits from the given abstract model. This is so the methods in the abstract model can query data consistently across the correct concrete model.

Consider the following:

class Abstract(models.Model)

    class Meta:
        abstract = True

    def concrete(self):
        return base_concrete_model(Abstract, self)

class Super(Abstract):
    pass

class Sub(Super):
    pass

sub = Sub.objects.create()
sub.concrete() # returns Super

In actual Mezzanine usage, this allows methods in the Displayable and Orderable abstract models to access the Page instance when instances of custom content types, (eg: models that inherit from Page) need to query the Page model to determine correct values for slug and _order which are only relevant in the context of the Page model and not the model of the custom content type.

mezzanine.utils.tests.copy_test_to_media(module, name)

Copies a file from Mezzanine’s test data path to MEDIA_ROOT. Used in tests and demo fixtures.

mezzanine.utils.tests.run_pep8_for_package(package_name)

If pep8 is installed, run it across the given package name returning any warnings or errors found.

mezzanine.utils.tests.run_pyflakes_for_package(package_name, extra_ignore=None)

If pyflakes is installed, run it across the given package name returning any warnings found.

mezzanine.utils.urls.admin_url(model, url, object_id=None)

Returns the URL for the given model and admin url name.

mezzanine.utils.urls.slugify(s)

Loads the callable defined by the SLUGIFY setting, which defaults to the slugify_unicode function.

mezzanine.utils.urls.slugify_unicode(s)

Replacement for Django’s slugify which allows unicode chars in slugs, for URLs in Chinese, Russian, etc. Adopted from https://github.com/mozilla/unicode-slugify/

mezzanine.utils.views.is_editable(obj, request)

Returns True if the object is editable for the request. First check for a custom editable handler on the object, otherwise use the logged in user and check change permissions for the object’s model.

mezzanine.utils.views.is_spam(request, form, url)

Identifies form data as being spam, using the http://akismet.com service. The Akismet API key should be specified in the AKISMET_API_KEY setting.

The name, email, url and comment fields are all guessed from the form fields:

  • name: First field labelled “Name”, also taking i18n into account.
  • email: First EmailField field.
  • url: First URLField field.
  • comment: First field with a Textarea widget.

If the actual comment can’t be extracted, spam checking is passed.

The referrer field expects a hidden form field to pass the referrer through, since the HTTP_REFERER will be the URL the form is posted from. The hidden referrer field is made available by default with the {% fields_for %} templatetag used for rendering form fields.

mezzanine.utils.views.paginate(objects, page_num, per_page, max_paging_links)

Return a paginated page for the given objects, giving it a custom visible_page_range attribute calculated from max_paging_links.

mezzanine.utils.views.render(request, templates, dictionary=None, context_instance=None, **kwargs)

Mimics django.shortcuts.render but uses a TemplateResponse for mezzanine.core.middleware.TemplateForDeviceMiddleware

Set cookie wrapper that allows number of seconds to be given as the expiry time, and ensures values are correctly encoded.

Table Of Contents

Previous topic

Importing External Blogs

Next topic

Colophon

This Page