django-opengraph-meta (0.1.2b1)

Published 2024-02-04 13:01:07 +03:00 by pypi

Installation

pip install --index-url  django-opengraph-meta

About this package

Django models for OpenGraph based metadata; Server-side metadata generation

django-opengraph-meta

This package contains models, which implements containing and generating extra part of the page's meta information. It is introduced by the OpenGraph and TwitterCard entities


Package includes

Basic models:

Extra models:

TwitterCard models:


Package struct


Concepts

Database app_label

If OPENGRAPH_META_APP_LABEL would be found in django.conf.settings it will be used as prefix each db model name, exclude TwitterCards models, which use TWITTER_CARD_META_APP_LABEL

Universal page attributes:

Class methods:
  • og_name(cls)
    • Returns the OpenGraph scope name, which was set at the class initialization
  • og_properties(cls)
    • Returns the OpenGraph scope properties, which was set at the class initialization
Methods:
  • og_metadata(self)
    • Returns the Generator[Tuple[str, str]] with collected meta information. Empty fields will not be included to that selection.
  • og_name(self)
    • Return Generator[str] (wrapped metadata), which present as Iterable HTML DOM based meta tags

Universal subpage attributes

Class OGSubpage (source) is a parent of each page class, excluding the OGWebPage. It determines ForeignKey field page, which links to OGWebPage object associated for present data. It proxied two properties of the page

  • url
  • title

, to the main OGSubpage scope

Universal music attributes

Arguments *args and **kwargs will be transfer to selected object instance constructor without any modification.

Class methods:
Database fields:
  • ForeignKey audio: The audio file (source) associated with the page
    • URLField url: Contains video's url. (og:audio)
    • CharField type: Contains MIME type of the video. (og:audio:type)
    • URLField secure_url: Contains video's alternate url to use if the webpage requires HTTPS. (og:audio:secure_url)

Universal video attributes

Arguments *args and **kwargs will be transfer to selected object instance constructor without any modification.

Class methods:
Database fields:

Universal TwitterCard attributes

Class methods:
Database fields:

Product classification

Model OGProductPage uses predefined values of the Google's taxonomy classification. It is a big document (~5.5k lines) with the deep enclosing and inheritance of the categories. So, that module support each element of the taxonomy, but not used all of them by default. Project setting's variable OPENGRAPH_PRODUCT_TAXONOMY_DEPTH defines level of the enclosing, which will be presented by root class Categories (source) (2 by default). It means, that second enclosing of the category (for example: OGProductPage.Categories.AnimalsAndPetSupplies.LiveAnimals) cannot contain any subcategory and would be final. If OPENGRAPH_PRODUCT_TAXONOMY_DEPTH is equal 0, it is means, that there is no any enclosing limits.

Note: List of the categories, which are contained into the current Taxonomy instance (source) can be got by the method of that instance categories(self)

You can use the setting's variable OPENGRAPH_PRODUCT_TAXONOMY_BASE for the defining the root category of your current project. For example, if your project is used for the cloth sale, it can be sensible to set the OPENGRAPH_PRODUCT_TAXONOMY_BASE = 'ApparelAndAccessories.Clothing'. It excludes the non-contextual values from the choices of OGProductPage.category.

Setting's variable OPENGRAPH_PRODUCT_TAXONOMY_FILEPATH can be used for the linking of custom taxonomy file, instead of builtin taxonomy.json, for the categories tree build

Boolean setting's variable OPENGRAPH_PRODUCT_TAXONOMY_FULLNAME (False by default) determines the name of category entity, which would be present at the choices property. fullname reflects the tree, in contrast of the name

Currency code

Model OGPrice (source) uses a part of logic the Product classification in the currency defines. It has support two variables: OPENGRAPH_PRODUCT_CURRENCY_FULLNAME and OPENGRAPH_PRODUCT_CURRENCY_FILEPATH with same logic. So if you want to limit list of currencies in your project, creation project-specific currency.json is a simple way to do it

See:

See also:


Basic models

OGWebPage

Database fields:
Properties
  • locale: Returns result of to_locale(get_language()) (og:locale)
  • locales_alt: Returns nothing, but set the interface to returning Iterable object. User may redefine this property on inheritance (og:locale:alternate)
  • determiner: Returns nothing, but set the interface to returning str. (og:determiner)
  • site_name: Returns value of OPENGRAPH_SITE_NAME (None if not present) which can be set in main project settings file

OGArticlePage

Database fields:
  • CharField section: Contains the global category value of the article (article:section)
  • DateTimeField published_time: Contains date and time of article's publication. Metadata represented as YYYY-MM-DDThh:mm (ISO 8601) string (article:published_time)
  • DateTimeField modified_time: Contains date and time of last article's modification. Metadata represented as YYYY-MM-DDThh:mm (ISO 8601) string (article:modified_time)
  • DateTimeField expiration_time: Contains date and time of article's expiration. Metadata represented as YYYY-MM-DDThh:mm (ISO 8601) string (article:expiration_time)
  • ManyToManyField authors: Contains an array of the author's profiles
    • URLField url: Contains author's page url. (article:author)
  • ManyToManyField tags: Contains an array of the tags associated with this object (article:tag)

OGBookPage

Database fields:

OGProfilePage

Database fields:
  • BooleanField is_male: Is used for handling by gender property
  • CharField first_name: First name of described person (profile:first_name)
  • CharField last_name: Last name of described person (profile:last_name)
  • CharField username: Username of described person (profile:username)
Properties
  • gender: Returns None if field is_male is null. Returns 'male' if is_male is true, 'female' in else (profile:gender)

OGMusicSongPage

Database fields:

OGMusicAlbumPage

Database fields:

OGMusicPlaylistPage

Database fields:

OGMusicRadioStationPage

Database fields:

OGVideoMoviePage


OGVideoEpisodePage


OGVideoTVShowPage


OGVideoOtherPage


Extra models

OGBusinessPage

Database fields:
  • ForeignKey contact_data: Contains link to the OGContactData property (source), which can contain:
    • CharField street_addres: Contains physical address of the object (business:contact_data:stree_addres)
    • CharField locality: Contains locality of the object (business:contact_data:locality)
    • CharField region: Contains region of the object (business:contact_data:region)
    • CharField postal_code: Contains postal_code of the object (business:contact_data:postal_code)
    • CharField country_name: Contains county name of the object (business:contact_data:country_name)
    • EmailField email: Contains email of the object (business:contact_data:email)
    • CharField phone_number: Contains phone number of the object (business:contact_data:phone_number)
    • CharField fax_number: Contains fax number of the object (business:contact_data:fax_number)
    • URLField website: Contains url to website of the object (business:contact_data:website)
  • ForeignKey place: Contains link to the OGContactData property (source), which can contain:

OGProductPage

Database fields:
Properties
  • gender: Returns unisex if field is_male is null. Returns 'male' if is_male is true, 'female' in else (product:gender)

TwitterCard models

TwitterCardApp

Database fields:

TwitterCardSummary

Database fields:
  • ForeignKey image: TwitterCardImage (source) image associated with the page
    • URLField url: Contains image's url. (twitter:image)
    • CharField alt: Contains description of what is in the image. (twitter:image:alt)
  • ForeignKey creator: TwitterCardCreator (source) profile info associated with the page
    • CharField username: @username of the creator (twitter:site)
    • CharField id: creator's Twitter ID (twitter:site:id)

TwitterCardSummaryLargeImage

Database fields:
  • ForeignKey image: TwitterCardImage (source) image associated with the page
    • URLField url: Contains image's url. (twitter:image)
    • CharField alt: Contains description of what is in the image. (twitter:image:alt)
  • ForeignKey creator: TwitterCardCreator (source) profile info associated with the page
    • CharField username: @username of the creator (twitter:site)
    • CharField id: creator's Twitter ID (twitter:site:id)

TwitterCardPlayer

Database fields:

Requirements

Requires Python: >=3.11
Details
PyPI
2024-02-04 13:01:07 +03:00
3
Gregory Lirent
275 KiB
Assets (2)
Versions (4) View all
0.1.2b1 2024-02-04
0.1.2b0 2024-02-04
0.1.1b0 2024-02-04
0.1.0b0 2024-01-31