Skip to main content

BaseApp Pages

Project description

BaseApp Pages

Reusable app to handle pages, URL's paths and metadata. It provides useful models and GraphQL Interfaces.

Whats missing

  • Allow for custom settings.LANGUAGES per project
  • Make create migration work with TranslatedField

Currenly if you have a different set of languages in your projects it will create a new migration changing the fields. So if you have a migration check test it will fail because the settings.LANGUAGES are different.

How to install:

This package requires to following packages to be installed:

And install the package with pip install baseapp-pages.

If you want to develop, install using this other guide.

How to use

Add baseapp_pages and django_quill to your project's INSTALLED_APPS and run ./manage.py migrate as any other django model:

INSTALLED_APPS = [
    'baseapp_pages',
    'django_quill',
]

Add django.middleware.locale.LocaleMiddleware to the MIDDLEWARE list in your django settings file. Check django's documentation for more information.

Add baseapp_pages.permissions.PagesPermissionsBackend to the AUTHENTICATION_BACKENDS list in your django settings file.

Expose PagesMutations and PagesQuery in your GraphQL/graphene endpoint, like:

from baseapp_pages.graphql.mutations import PagesMutations
from baseapp_pages.graphql.queries import PagesQuery

class Query(graphene.ObjectType, PagesQuery):
    pass

class Mutation(graphene.ObjectType, PagesMutations):
    pass

schema = graphene.Schema(query=Query, mutation=Mutation)

This will expose urlPath and page query.

urlPath query:

Example:

{
    urlPath(path: '/about') {
        path
        language
        target {
            metadata {
                metaTitle
            }

            ... on Page {
                title
            }
        }
    }
}

PageInterface

PageInterface is a GraphQL interface that can be used to query for pages. It has the following fields:

  • urlPath return the active URLPath
  • urlPaths return all URLPath for the object, including inactive ones and in other languages
  • metadata return the Metadata for the object

ObjectTypes that implements PageInterface is required to implement a resolve for metadata like this:

from django.utils.translation import get_language
from baseapp_core.graphql import DjangoObjectType
from baseapp_pages.graphql import PageInterface, MetadataObjectType


class MyModelObjectType(DjangoObjectType):
    class Meta:
        model = MyModel
        interfaces = (relay.Node, PageInterface)

    @classmethod
    def resolve_metadata(cls, instance, info, **kwargs):
        return MetadataObjectType(
            meta_title=instance.title,
            meta_description=instance.body[:160],
            meta_og_image=instance.image.url,
            meta_robots='noindex,nofollow'
        )

If you want to support Metadata being manually set or overriden in the admin you can use the following code:

class MyModelObjectType(DjangoObjectType):
    # ...

    @classmethod
    def resolve_metadata(cls, instance, info, **kwargs):
        target_content_type = ContentType.objects.get_for_model(instance)
        metadata = MetadataObjectType._model.objects.filter(
            target_content_type=target_content_type,
            target_object_id=self.id,
            language=get_language(),
        ).first()
        if not metadata:
            return MetadataObjectType(
                meta_title=instance.title,
                # ...
            )
        return metadata

How to develop

General development instructions can be found in main README.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

baseapp_pages-0.2.7.tar.gz (19.4 kB view details)

Uploaded Source

File details

Details for the file baseapp_pages-0.2.7.tar.gz.

File metadata

  • Download URL: baseapp_pages-0.2.7.tar.gz
  • Upload date:
  • Size: 19.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for baseapp_pages-0.2.7.tar.gz
Algorithm Hash digest
SHA256 5390d3fc330a33aaa51ab320d86d528b53799c1f7423c8549abe33f394bf8fb8
MD5 f5dad3351c661348b0498b471658b9c4
BLAKE2b-256 1860e66a014c866bd228ef2b6b9044816a5422976c2285c3cb49488964dabcf1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page