Package documentation¶
- class meta.views.FullUrlMixin[source]¶
Provides a few convenience methods to retrieve the full URL (which includes protocol and domain) of an object.
If possible,
django.http.request.HttpRequest.build_absolute_uri()
is used- _get_full_url(url)[source]¶
Build the full URL (protocol and domain included) for the URL given as argument
- Parameters:
url – absolute (domain-less) URL
- Returns:
full url
- get_domain()[source]¶
Discover the current website domain
django.contrib.sites.models.Site
and META_SITE_DOMAIN (in this order) are used- Returns:
domain URL
- get_protocol()[source]¶
Discover the current website protocol from META_SITE_PROTOCOL
- Returns:
http or https depending on META_SITE_PROTOCOL
- class meta.views.Meta(**kwargs)[source]¶
Helper for building context meta object
- _image = None¶
- _image_object = None¶
- _keywords = []¶
- _schema = {}¶
Base schema.org types definition.
It’s a dictionary containing all the schema.org properties for the described objects.
- _url = None¶
- property image¶
- property image_object¶
- property keywords¶
- request = None¶
- property schema¶
Schema.org object description.
Items in the schema are converted in a format suitable of json encoding at this stage:
instances of
Meta
as their schemadates as isoformat
iterables and dicts are processed depth-first to process their items
If no type is set
schemaorg_type
is used- Returns:
dict
- property url¶
- class meta.views.MetadataMixin(**kwargs)[source]¶
Django CBV mixin to prepare metadata for the view context
- context_meta_name = 'meta'¶
- custom_namespace = None¶
- description = None¶
- extra_custom_props = None¶
- extra_props = None¶
- facebook_app_id = None¶
- get_domain()[source]¶
Discover the current website domain
django.contrib.sites.models.Site
and META_SITE_DOMAIN (in this order) are used- Returns:
domain URL
- get_protocol()[source]¶
Discover the current website protocol from META_SITE_PROTOCOL
- Returns:
http or https depending on META_SITE_PROTOCOL
- get_schema(context=None)[source]¶
The generic API to retrieve the full schema.org structure for the view.
By default it returns the
schema
. You can reimplement this method to build the schema.org structure at runtime. See a sample implementation.- Parameters:
context – view context
- Returns:
dictionary
- get_schema_property(schema_type, property, context=None)[source]¶
The generic API to retrieve the attribute value for a generic schema type
This is just a stub that must be implemented
- Parameters:
schema_type – name of the schema type
property – name of the property
context – view context
- Returns:
property value
- image = None¶
- image_object = None¶
- keywords = []¶
- locale = None¶
- object_type = None¶
- og_title = None¶
- schema = {}¶
- schemaorg_description = None¶
- schemaorg_title = None¶
- schemaorg_type = None¶
- site_name = None¶
- title = None¶
- property twitter_card¶
- twitter_creator = None¶
- twitter_site = None¶
- twitter_title = None¶
- twitter_type = None¶
- url = None¶
- use_og = False¶
- use_sites = False¶
- use_title_tag = False¶
- class meta.models.ModelMeta[source]¶
Meta information mixin.
- _metadata = {}¶
Metadata configuration dictionary
_metadata dict values can be:
name of object method taking the field name as parameter
name of object method taking no parameters
name of object attribute
name of callable taking the field name as parameter
name of callable taking no parameters
literal value
They are checked in the given order: the first that matches is returned.
Callable must be available in the module (i.e.: imported if not defined in the module itself)
- _schema = {}¶
schema.org properties dictionary
_metadata dict values can be:
name of object method taking the field name as parameter
name of object method taking no parameters
name of object attribute
name of callable taking the field name as parameter
name of callable taking no parameters
literal value
They are checked in the given order: the first that matches is returned.
Callable must be available in the module (i.e.: imported if not defined in the module itself)
If the resulting value is a
ModelMeta
orMeta
instance its schema is set in the schema.org dataset.
- as_meta(request=None)[source]¶
Populates the
Meta
object with values from_metadata
- Parameters:
request – optional request object. Used to build the correct URI for linked objects
- Returns:
Meta object
- get_author()[source]¶
Retrieve the author object. This is meant to be overridden in the model to return the actual author instance (e.g.: the user object).
- schema¶
Schema.org object description
- Returns:
dict
- meta.templatetags.meta.custom_meta(attr, name, content)[source]¶
Generates a custom meta tag:
<meta {attr}=”{name}” content=”{content}”>
- Parameters:
attr – meta attribute name
name – meta name
content – content value
- meta.templatetags.meta.custom_meta_extras(extra_custom_props)[source]¶
Generates the markup for a list of custom meta tags
Each tuple is passed to :py:func:custom_meta to generate the markup
- Parameters:
extra_custom_props – list of tuple of additional meta tags
- meta.templatetags.meta.facebook_prop(name, value)[source]¶
Generic Facebook property
- Parameters:
name – property name (without ‘fb:’ namespace)
value – property value
- meta.templatetags.meta.generic_prop(namespace, name, value)[source]¶
Generic property setter that allows to create custom namespaced meta e.g.: fb:profile_id.
- meta.templatetags.meta.meta(name, content)[source]¶
Generates a meta tag according to the following markup:
<meta name=”{name}” content=”{content}”>
- Parameters:
name – meta name
content – content value
- meta.templatetags.meta.meta_extras(extra_props)[source]¶
Generates the markup for a list of meta tags
Each key,value paur is passed to :py:func:meta to generate the markup
- Parameters:
extra_props – dictionary of additional meta tags
- meta.templatetags.meta.meta_list(name, lst)[source]¶
Renders in a single meta a list of values (e.g.: keywords list)
- Parameters:
name – meta name
lst – values
- meta.templatetags.meta.meta_namespaces(context)[source]¶
Include OG namespaces. To be used in the <head> tag.
- meta.templatetags.meta.meta_namespaces_schemaorg(context)[source]¶
Include Schema.org attributes. To be used in the <html> or <body> tag.
- meta.templatetags.meta.og_prop(name, value)[source]¶
Generic OpenGraph property
- Parameters:
name – property name (without ‘og:’ namespace)
value – property value
- meta.templatetags.meta.schemaorg_html_scope(value)[source]¶
This is meant to be used as attribute to html / body or other tags to define schema.org type
- Parameters:
value – declared scope
- meta.templatetags.meta.schemaorg_prop(name, value)[source]¶
Generic Schema.org property
- Parameters:
name – property name
value – property value