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 = []
_normalize_media_url(url)[source]
_obj = None

Linked ModelMeta instance (if Meta is generated from a ModelMeta object)

_schema = {}

Base schema.org types definition.

It’s a dictionary containing all the schema.org properties for the described objects.

See a sample implementation.

_url = None
as_json_ld()[source]

Convert the schema to json-ld

Returns:

json

get_full_url(url)[source]
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 schema

  • dates 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_context_data(**kwargs)[source]
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_meta(context=None)[source]
get_meta_class()[source]
get_meta_custom_namespace(context=None)[source]
get_meta_description(context=None)[source]
get_meta_extra_custom_props(context=None)[source]
get_meta_extra_props(context=None)[source]
get_meta_facebook_app_id(context=None)[source]
get_meta_image(context=None)[source]
get_meta_image_object(context=None)[source]
get_meta_keywords(context=None)[source]
get_meta_locale(context=None)[source]
get_meta_object_type(context=None)[source]
get_meta_og_title(context=None)[source]
get_meta_schemaorg_description(context=None)[source]
get_meta_schemaorg_title(context=None)[source]
get_meta_schemaorg_type(context=None)[source]
get_meta_site_name(context=None)[source]
get_meta_title(context=None)[source]
get_meta_twitter_card(context=None)[source]
get_meta_twitter_creator(context=None)[source]
get_meta_twitter_site(context=None)[source]
get_meta_twitter_title(context=None)[source]
get_meta_twitter_type(context=None)[source]
get_meta_url(context=None)[source]
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
meta_class

alias of Meta

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 or Meta instance its schema is set in the schema.org dataset.

See a sample implementation.

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

build_absolute_uri(url)[source]

Return the full url for the provided url argument

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).

get_author_name()[source]

Sample method to return the author full name

get_author_schemaorg()[source]

Sample method to return the author Schema.org URL

get_author_twitter()[source]

Sample method to return the author twitter account

get_author_url()[source]

Sample method to return the author facebook URL

get_meta(request=None)[source]

Retrieve the meta data configuration

get_meta_protocol()[source]

Current http protocol

get_request()[source]

Retrieve request from current instance

mainEntityOfPage()[source]
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.googleplus_html_scope(value)[source]

Legacy Google+ scope

meta.templatetags.meta.googleplus_prop(name, value)[source]

Legacy Google+ property

meta.templatetags.meta.googleplus_scope(value)[source]

Legacy Google+ scope

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_gplus(context)[source]

Legacy Google+ attributes.

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

meta.templatetags.meta.schemaorg_scope(value)[source]

Alias for googleplus_html_scope

Parameters:

value – declared scope

meta.templatetags.meta.title_prop(value)[source]

Title tag

Parameters:

value – title value

meta.templatetags.meta.twitter_prop(name, value)[source]

Generic Twitter property

Parameters:
  • name – property name (without ‘twitter:’ namespace)

  • value – property value