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.1.tar.gz (17.7 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: baseapp_pages-0.2.1.tar.gz
  • Upload date:
  • Size: 17.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for baseapp_pages-0.2.1.tar.gz
Algorithm Hash digest
SHA256 26601c4a5cf3c8b2d4f25d76c43c94d0b44edd679149a886a9174789d002eb2f
MD5 b1d5d958fef3982fdd9f90d30e026be0
BLAKE2b-256 eb90031ecfd7451289a38c0fd106ecc1b89655b7343fe1b3c2239077d7b56118

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