pages

package
v1.7.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 8, 2026 License: GPL-2.0 Imports: 76 Imported by: 2

Documentation

Overview

templ: version: v0.3.1020

templ: version: v0.3.1020

Index

Constants

View Source
const (
	AdminPagesAppName   = "pages"
	AdminPagesModelPath = "PageNode"
)
View Source
const (
	// The variable name generally used to refer to the page id in the URL.
	//
	// This is used in the URL patterns for the pages app, as well as javascript code and queries in URLs.
	PageIDVariableName = "page_id"

	CHOOSER_ROOT_PAGES_KEY = "pages.nodes.root"

	CHOOSER_PAGE_REVISIONS_KEY = "pages.page.revisions"
)
View Source
const (
	ErrCodeNoPage   errors.GoCode = "NoPage"
	ErrCodeNoPageID errors.GoCode = "NoPageID"
)
View Source
const (
	STEP_LEN = 3
	ALPHABET = "0123456789"
)
View Source
const (
	APPVAR_OUTDATED_AFTER_DURATION = "pages.outdated_after_duration" // time.Duration
	APPVAR_OUTDATED_LIST_DISPLAY   = "pages.outdated_list_display"   // []string
)
View Source
const DEFAULT_SITE_KEY = "default_site"

Variables

View Source
var (
	ErrNoPage             = errors.New(ErrCodeNoPage, "pages: PageNode has no Page set")
	ErrNoPageID           = errors.New(ErrCodeNoPageID, "pages: PageNode has no PageID set", ErrNoPage)
	ErrInvalidPathLength  = errors.ValueError.Wrap("invalid path length")
	ErrTooLittleAncestors = errors.ValueError.Wrap("too little ancestors provided")
	ErrTooManyAncestors   = errors.ValueError.Wrap("too many ancestors provided")
	ErrPageIsRoot         = errors.ValueError.Wrap("page is root")
)
View Source
var (

	// A signal which is sent when a new root page is created.
	SignalRootCreated = signalRegistry.Get("pages.root_page_created") // Node is the root node, PageID is zero.

	// A signal which is sent when a new child page is created.
	SignalChildCreated = signalRegistry.Get("pages.child_page_created") // Node is the child being created, PageID is the parent node's ID.

	// A signal which is sent when a node is updated.
	SignalNodeUpdated = signalRegistry.Get("pages.node_updated") // Node is the node being updated, PageID is the parent node's ID.

	// A signal which is sent before a node is deleted.
	SignalNodeBeforeDelete = signalRegistry.Get("pages.node_before_delete") // Node is the node being deleted, PageID is the parent node's ID.

	// A signal which is sent after a node is moved.
	SignalNodeMoved = signalMoveRegistry.Get("pages.node_moved") // Node is the node being moved, Parent is the new parent, OldParent is the old parent.
)
View Source
var ErrRouteNotFound = mux.ErrRouteNotFound
View Source
var PagePreviewHandler = &GenericPreviewHandler[Page]{
	Model:            &PageNode{},
	SessionKeyPrefix: "page_preview_",
	URLKey:           PageIDVariableName,
	Expiration:       10 * time.Minute,
	GetFormFunc: func(h *GenericPreviewHandler[Page], r *http.Request, instance Page, oldData url.Values) (forms.Form, error) {
		return PageEditForm(r, instance), nil
	},
	ServePreview: func(h *GenericPreviewHandler[Page], w http.ResponseWriter, original, previewReq *http.Request, instance Page) {
		servePageView(w, previewReq, instance)
	},
	BuildPreviewRequest: func(h *GenericPreviewHandler[Page], r *http.Request, instance Page) (*http.Request, error) {
		var cloned = r.Clone(context.WithValue(
			r.Context(), previewContextKey{}, struct{}{},
		))
		cloned.URL.Path = URLPath(instance)
		return cloned, nil
	},
	GetObjectFunc: func(h *GenericPreviewHandler[Page], r *http.Request, pk string) (Page, error) {
		var objRow, err = NewPageQuerySet().
			WithContext(r.Context()).
			Filter("PK", pk).
			Get()
		if err != nil {
			return nil, fmt.Errorf("failed to get page with ID %v: %w", pk, err)
		}

		specific, err := Specific(r.Context(), objRow.Object, true)
		if err != nil {
			return nil, fmt.Errorf("failed to get specific page type for page ID %v: %w", pk, err)
		}

		return specific, nil
	},
}
View Source
var PageRevisionPreviewHandler = &GenericPreviewHandler[Page]{
	Model:            &PageNode{},
	SessionKeyPrefix: "page_revision_preview_",
	URLKey:           PageIDVariableName,
	Expiration:       10 * time.Minute,
	BuildPreviewRequest: func(h *GenericPreviewHandler[Page], r *http.Request, instance Page) (*http.Request, error) {
		var cloned = r.Clone(context.WithValue(
			r.Context(), previewContextKey{}, struct{}{},
		))
		cloned.URL.Path = URLPath(instance)
		return cloned, nil
	},
	GetFormFunc: func(h *GenericPreviewHandler[Page], r *http.Request, instance Page, oldData url.Values) (forms.Form, error) {
		return PageEditForm(r, instance), nil
	},
	ServePreview: func(h *GenericPreviewHandler[Page], w http.ResponseWriter, original, previewReq *http.Request, instance Page) {
		servePageView(w, previewReq, instance)
	},
	GetObjectFunc: func(h *GenericPreviewHandler[Page], r *http.Request, pk string) (Page, error) {
		var vars = mux.Vars(r)
		var revisionID = vars.GetInt("revision_id")
		var chosenRevision *revisions.Revision
		var objRow, err = NewPageQuerySet().
			WithContext(r.Context()).
			Filter("PK", pk).
			Get()
		if err != nil {
			return nil, fmt.Errorf("failed to get page with ID %v: %w", pk, err)
		}

		if revisionID != 0 {
			chosenRevision, err = revisions.GetRevisionByID(r.Context(), int64(revisionID))
		} else {
			chosenRevision, err = revisions.LatestRevision(r.Context(), objRow.Object)
		}
		if err != nil {
			return nil, fmt.Errorf("failed to get latest revision for page ID %v: %w", pk, err)
		}

		specific, err := Specific(r.Context(), objRow.Object.Reference(), true)
		if err != nil {
			return nil, fmt.Errorf("failed to get specific page type for page ID %v: %w", pk, err)
		}

		err = revisions.UnmarshalRevisionData(specific, []byte(chosenRevision.Data))
		if err != nil {
			return nil, fmt.Errorf("failed to unmarshal latest revision data for page ID %v: %w", pk, err)
		}

		return specific, nil
	},
}

Functions

func FixTree

func FixTree(ctx context.Context) error

Fixtree fixes the tree structure of the page nodes.

It scans for errors in the tree structure in the database and fixes them.

func IsPreviewContext added in v1.7.2

func IsPreviewContext(ctx context.Context) bool

func NewAppConfig

func NewAppConfig() django.AppConfig

NewAppConfig returns a new pages app config.

This is used to initialize the pages app, set up routes, and register the admin application.

func PageEditForm added in v1.7.2

func PageServeView

func PageServeView(w http.ResponseWriter, r *http.Request)

func PrintTree

func PrintTree(node *Node, depth int)

func Register

func Register(definition *PageDefinition)

Register a page definition

This is an extension of the contenttypes.ContentTypeDefinition

func Serve

func Serve(allowedMethods ...string) http.Handler

func SetRoutePrefix added in v1.7.0

func SetRoutePrefix(prefix string)

SetRoutePrefix sets the route prefix for the pages app.

Pages app will be served at the route prefix.

func URLPath added in v1.7.0

func URLPath(page Page) string

Returns the live URL path for the given page.

This is the URL path that the page will be served at.

Types

type BaseSignal

type BaseSignal struct {
	// Ctx stores the context used to perform the operation.
	Ctx context.Context
}

type GenericBoundPreview added in v1.7.2

type GenericBoundPreview[T attrs.Definer] struct {
	Handler     *GenericPreviewHandler[T]
	ContentType *contenttypes.ContentTypeDefinition
	Object      T
}

func (*GenericBoundPreview[T]) BuildPreviewRequest added in v1.7.2

func (v *GenericBoundPreview[T]) BuildPreviewRequest(r *http.Request, instance attrs.Definer) (*http.Request, error)

func (*GenericBoundPreview[T]) DeletePreviewData added in v1.7.2

func (v *GenericBoundPreview[T]) DeletePreviewData(r *http.Request) error

func (*GenericBoundPreview[T]) GetForm added in v1.7.2

func (v *GenericBoundPreview[T]) GetForm(r *http.Request, instance attrs.Definer, oldData url.Values) (forms.Form, error)

func (*GenericBoundPreview[T]) GetObject added in v1.7.2

func (v *GenericBoundPreview[T]) GetObject(r *http.Request) (attrs.Definer, error)

func (*GenericBoundPreview[T]) GetPreviewData added in v1.7.2

func (v *GenericBoundPreview[T]) GetPreviewData(r *http.Request) (url.Values, error)

func (*GenericBoundPreview[T]) MakePreviewRequest added in v1.7.2

func (v *GenericBoundPreview[T]) MakePreviewRequest(w http.ResponseWriter, original *http.Request, previewReq *http.Request, instance attrs.Definer)

func (*GenericBoundPreview[T]) RemoveOldPreviewData added in v1.7.2

func (v *GenericBoundPreview[T]) RemoveOldPreviewData(r *http.Request) error

func (*GenericBoundPreview[T]) ServeXXX added in v1.7.2

func (v *GenericBoundPreview[T]) ServeXXX(w http.ResponseWriter, r *http.Request)

func (*GenericBoundPreview[T]) SetPreviewData added in v1.7.2

func (v *GenericBoundPreview[T]) SetPreviewData(r *http.Request, data url.Values) error

func (*GenericBoundPreview[T]) ValidateForm added in v1.7.2

func (v *GenericBoundPreview[T]) ValidateForm(r *http.Request, form forms.Form) error

type GenericPreviewHandler added in v1.7.2

type GenericPreviewHandler[T attrs.Definer] struct {
	Model               T
	URLKey              string
	Expiration          time.Duration
	SessionKeyPrefix    string
	GetObjectQuerySet   func(h *GenericPreviewHandler[T], r *http.Request) *queries.QuerySet[T]
	GetObjectFunc       func(h *GenericPreviewHandler[T], r *http.Request, pk string) (T, error)
	GetFormFunc         func(h *GenericPreviewHandler[T], r *http.Request, instance T, oldData url.Values) (forms.Form, error)
	BuildPreviewRequest func(h *GenericPreviewHandler[T], r *http.Request, instance T) (*http.Request, error)
	ServePreview        func(h *GenericPreviewHandler[T], w http.ResponseWriter, original *http.Request, previewReq *http.Request, instance T)
}

func (*GenericPreviewHandler[T]) Bind added in v1.7.2

func (*GenericPreviewHandler[T]) Methods added in v1.7.2

func (v *GenericPreviewHandler[T]) Methods() []string

func (*GenericPreviewHandler[T]) PathKey added in v1.7.2

func (v *GenericPreviewHandler[T]) PathKey() string

func (*GenericPreviewHandler[T]) ServeXXX added in v1.7.2

func (v *GenericPreviewHandler[T]) ServeXXX(w http.ResponseWriter, r *http.Request)

Handle embedders of GenericPreviewHandler that also implement genericPreviewView.

This ensures that the correct methods are called on the embedder if they are available.

func (*GenericPreviewHandler[T]) SessionKey added in v1.7.2

func (v *GenericPreviewHandler[T]) SessionKey(obj attrs.Definer) string

func (*GenericPreviewHandler[T]) TakeControl added in v1.7.2

func (v *GenericPreviewHandler[T]) TakeControl(w http.ResponseWriter, req *http.Request, view views.View)

type ItemsList

type ItemsList []*PageNode

func (ItemsList) MarshalJSON

func (il ItemsList) MarshalJSON() ([]byte, error)
type MenuHeader struct {
	Text string `json:"text"`
	URL  string `json:"url"`
}

type Node

type Node struct {
	Ref      *PageNode
	Children *orderedmap.OrderedMap[string, *Node]
}

func NewNodeTree

func NewNodeTree(refs []*PageNode) *Node

func (*Node) FindNode

func (n *Node) FindNode(path string) *Node

func (*Node) FixTree

func (n *Node) FixTree() []*PageNode

func (*Node) FlatList

func (n *Node) FlatList() []*PageNode

func (*Node) ForEach

func (n *Node) ForEach(fn func(*Node, int64) (cancel bool)) (cancelled bool)

type Page

type Page interface {
	attrs.Definer
	ID() int64
	Reference() *PageNode
	Save(c context.Context) error
}

func Specific

func Specific(ctx context.Context, node *PageNode, withRelated bool) (Page, error)

Return the custom page object belonging to the given node

type PageAppConfig

type PageAppConfig struct {
	*apps.DBRequiredAppConfig
	// contains filtered or unexported fields
}

func App

func App() *PageAppConfig

Returns the pages app object itself

func (*PageAppConfig) Check added in v1.7.2

func (p *PageAppConfig) Check(ctx context.Context, settings django.Settings) []checks.Message

type PageBaseKeyGetter

type PageBaseKeyGetter interface {
	GetBaseKey(req *http.Request, page Page) string
}

type PageChooserList added in v1.7.2

type PageChooserList struct {
	*chooser.WrappedModel[*PageNode]
	Models []*chooser.WrappedModel[*PageNode]
}

type PageComponentView added in v1.7.2

type PageComponentView interface {
	PageContextGetter
	Render(req *http.Request, page Page) templ.Component
}

type PageContextGetter

type PageContextGetter interface {
	GetContext(req *http.Request, page Page) (ctx.Context, error)
}

type PageDefinition

type PageDefinition struct {
	// The underlying content type definition for the blog page model
	*contenttypes.ContentTypeDefinition

	// Serve the page with this view instead
	ServePage func(page Page) PageView

	// Panels for the model when creating a new page
	//
	// This contains fields from the custom model, as well as the underlying page node model.
	AddPanels func(r *http.Request, page Page) []admin.Panel

	// Panels for the model when editing a page
	//
	// This contains fields from the custom model, as well as the underlying page node model.
	EditPanels func(r *http.Request, page Page) []admin.Panel

	// Query for an instance of this model by its ID
	GetForID func(ctx context.Context, ref *PageNode, id int64) (Page, error)

	// Callback function to be called when a reference node is updated
	OnReferenceUpdate func(ctx context.Context, ref *PageNode, id int64) error

	// Callback function to be called before a reference node is deleted
	OnReferenceBeforeDelete func(ctx context.Context, ref *PageNode, id int64) error

	// Prefetches to use when calling Specific on a page.
	Prefetch admin.Prefetch

	// Disallow creation of this model through the admin interface
	DisallowCreate bool

	// Disallow this page type to be a root page (i.e. it must have a parent)
	DisallowRoot bool

	// IsValidChild checks if the given page type is allowed as a child of this page type
	IsValidChild func(parent Page) (bool, error)

	// IsValidParent checks if the given page type is allowed as a parent of this page type
	IsValidParent func(child Page) (bool, error)

	// Allowed parent page types for this model
	//
	// This is a list of content type strings that this model can be a child of.
	ParentPageTypes []string

	// Allowed child page types for this model
	//
	// This is a list of content type strings that this model can be a parent of.
	ChildPageTypes []string
	// contains filtered or unexported fields
}

func DefinitionForObject

func DefinitionForObject(page Page) *PageDefinition

Return the content type definition for the given page object

func DefinitionForType

func DefinitionForType(typeName string) *PageDefinition

Return the content type definition for the given page type

func FilterCreatableDefinitions added in v1.6.6

func FilterCreatableDefinitions(definitions []*PageDefinition, otherChecks ...func(*PageDefinition) bool) []*PageDefinition

func ListDefinitions

func ListDefinitions() []*PageDefinition

Returns a list of all registered page definitions

func ListDefinitionsForType added in v1.6.6

func ListDefinitionsForType(typeName string) []*PageDefinition

Returns a list of all registered page definitions for the given type

func ListRootDefinitions added in v1.6.6

func ListRootDefinitions() []*PageDefinition

Returns a list of all registered root page definitions

func (*PageDefinition) AppLabel

func (p *PageDefinition) AppLabel() string

func (*PageDefinition) ContentType

func (p *PageDefinition) ContentType() contenttypes.ContentType

func (*PageDefinition) Description

func (p *PageDefinition) Description(ctx context.Context) string

func (*PageDefinition) IsValidChildType added in v1.7.2

func (p *PageDefinition) IsValidChildType(typeName string) bool

func (*PageDefinition) IsValidParentType added in v1.7.2

func (p *PageDefinition) IsValidParentType(typeName string) bool

func (*PageDefinition) Label

func (p *PageDefinition) Label(ctx context.Context) string

func (*PageDefinition) Model

func (p *PageDefinition) Model() string

func (*PageDefinition) PageView

func (p *PageDefinition) PageView(page Page) PageView

type PageMovedSignal

type PageMovedSignal struct {
	BaseSignal

	// The node being moved.
	Node *PageNode

	// All nodes that are being moved.
	Nodes []*PageNode

	// The new parent node.
	NewParent *PageNode

	// The old parent node.
	OldParent *PageNode
}

type PageNode added in v1.7.2

type PageNode struct {
	models.Model            `table:"PageNode"`
	PK                      int64      `json:"id" attrs:"primary;readonly;column=id"`
	Title                   string     `json:"title"`
	Path                    string     `json:"path" attrs:"blank"`
	Depth                   int64      `json:"depth" attrs:"blank"`
	Numchild                int64      `json:"numchild" attrs:"blank"`
	UrlPath                 string     `json:"url_path" attrs:"readonly;blank"`
	Slug                    string     `json:"slug"`
	StatusFlags             StatusFlag `json:"status_flags" attrs:"null;blank"`
	PageID                  int64      `json:"page_id" attrs:"null;blank"`
	ContentType             string     `json:"content_type" attrs:"null;blank"`
	PublishedAt             time.Time  `json:"published_at" attrs:"null;blank"`
	LatestRevisionCreatedAt time.Time  `json:"latest_revision_created_at" attrs:"readonly;label=Latest Revision Created At"`
	CreatedAt               time.Time  `json:"created_at" attrs:"readonly;label=Created At"`
	UpdatedAt               time.Time  `json:"updated_at" attrs:"readonly;label=Updated At"`

	// PageObject is the specific page object associated with this node.
	//
	// It is used to cache the specific page object for performance optimization.
	//
	// It is also used to save the specific page object when the node is saved.
	PageObject Page `json:"-" attrs:"-"`
	// contains filtered or unexported fields
}

func (*PageNode) AddChild added in v1.7.2

func (n *PageNode) AddChild(ctx context.Context, child *PageNode) error

func (*PageNode) Ancestors added in v1.7.2

func (n *PageNode) Ancestors(inclusive ...bool) *PageQuerySet

func (*PageNode) BeforeCreate added in v1.7.2

func (n *PageNode) BeforeCreate(context.Context) error

func (*PageNode) BeforeSave added in v1.7.2

func (n *PageNode) BeforeSave(context.Context) error

func (*PageNode) Children added in v1.7.2

func (n *PageNode) Children() *PageQuerySet

func (*PageNode) ControlsEmbedderSaving added in v1.7.2

func (n *PageNode) ControlsEmbedderSaving() bool

func (*PageNode) CreateRevision added in v1.7.2

func (n *PageNode) CreateRevision(ctx context.Context, user users.User, save bool) (*revisions.Revision, error)

func (*PageNode) DatabaseIndexes added in v1.7.2

func (n *PageNode) DatabaseIndexes(obj attrs.Definer) []migrator.Index

func (*PageNode) DeleteObject added in v1.7.2

func (n *PageNode) DeleteObject(ctx context.Context) error

func (*PageNode) Descendants added in v1.7.2

func (n *PageNode) Descendants(inclusive ...bool) *PageQuerySet

func (*PageNode) ExcludeFromRevisionData added in v1.7.2

func (n *PageNode) ExcludeFromRevisionData() []string

func (*PageNode) FieldDefs added in v1.7.2

func (n *PageNode) FieldDefs() attrs.Definitions

func (*PageNode) GetRevisionInfo added in v1.7.2

func (n *PageNode) GetRevisionInfo(ctx context.Context) (pk any, contentType string, err error)

func (*PageNode) ID added in v1.7.2

func (n *PageNode) ID() int64

func (*PageNode) IsDeleted added in v1.7.2

func (n *PageNode) IsDeleted() bool

func (*PageNode) IsHidden added in v1.7.2

func (n *PageNode) IsHidden() bool

func (*PageNode) IsPublished added in v1.7.2

func (n *PageNode) IsPublished() bool

func (*PageNode) IsRoot added in v1.7.2

func (n *PageNode) IsRoot() bool

func (*PageNode) Move added in v1.7.2

func (n *PageNode) Move(ctx context.Context, newParent *PageNode) error

func (*PageNode) Parent added in v1.7.2

func (n *PageNode) Parent(ctx context.Context, refresh ...bool) (parent *PageNode, err error)

func (*PageNode) Publish added in v1.7.2

func (n *PageNode) Publish(ctx context.Context) error

func (*PageNode) Reference added in v1.7.2

func (n *PageNode) Reference() *PageNode

func (*PageNode) Route added in v1.7.2

func (n *PageNode) Route(r *http.Request, pathComponents []string) (Page, error)

func (*PageNode) SaveObject added in v1.7.2

func (n *PageNode) SaveObject(ctx context.Context, cnf models.SaveConfig) (err error)

func (*PageNode) SearchableFields added in v1.7.2

func (n *PageNode) SearchableFields() []search.SearchField

func (*PageNode) SetSpecificPageObject added in v1.7.2

func (n *PageNode) SetSpecificPageObject(p Page)

func (*PageNode) SetUrlPath added in v1.7.2

func (n *PageNode) SetUrlPath(parent *PageNode) (newPath, oldPath string)

func (*PageNode) Specific added in v1.7.2

func (n *PageNode) Specific(ctx context.Context, refresh ...bool) (Page, error)

func (*PageNode) TargetContentTypeField added in v1.7.2

func (n *PageNode) TargetContentTypeField() attrs.FieldDefinition

func (*PageNode) TargetPrimaryField added in v1.7.2

func (n *PageNode) TargetPrimaryField() attrs.FieldDefinition

func (*PageNode) Unpublish added in v1.7.2

func (n *PageNode) Unpublish(ctx context.Context, unpublishChildren bool) error

type PageNodeSignal

type PageNodeSignal struct {
	BaseSignal

	// The current node, a child node or parent node depending on the signal.
	Node  *PageNode
	Nodes []*PageNode

	// The current page ID, the parent page ID or a child's page ID depending on the signal.
	PageID int64
}

type PageQuerySet added in v1.7.2

type PageQuerySet struct {
	*queries.WrappedQuerySet[*PageNode, *PageQuerySet, *queries.QuerySet[*PageNode]]
}

func NewPageQuerySet added in v1.7.2

func NewPageQuerySet() *PageQuerySet

func (*PageQuerySet) AddChildren added in v1.7.2

func (qs *PageQuerySet) AddChildren(parent *PageNode, children ...*PageNode) error

CreateChildNode creates a new child node.

The parent node path must not be empty.

The child node path must be empty.

The child node title must not be empty, if not provided the page's slug (and thus URLPath) will be based on the page's title.

The child node path is set to a new path part based on the number of children of the parent node.

func (*PageQuerySet) AddRoot added in v1.7.2

func (qs *PageQuerySet) AddRoot(node *PageNode) error

AddRoot creates a new root node.

For more information, see PageQuerySet.AddRoots.

func (*PageQuerySet) AddRoots added in v1.7.2

func (qs *PageQuerySet) AddRoots(nodes ...*PageNode) error

AddRoots creates new root nodes.

The following conditions **must** be met for each node: - The node path must be empty. - The node title must not be empty. - The node title must not be empty, if not provided the page's slug (and thus URLPath) will be based on the page's title.

func (*PageQuerySet) AllNodes added in v1.7.2

func (qs *PageQuerySet) AllNodes() ([]*PageNode, error)

func (*PageQuerySet) AncestorOf added in v1.7.2

func (qs *PageQuerySet) AncestorOf(node *PageNode, inclusive ...bool) *PageQuerySet

func (*PageQuerySet) Ancestors added in v1.7.2

func (qs *PageQuerySet) Ancestors(path string, depth int64, inclusive ...bool) *PageQuerySet

func (*PageQuerySet) BatchCreate added in v1.7.2

func (qs *PageQuerySet) BatchCreate([]*PageNode) ([]*PageNode, error)

func (*PageQuerySet) BatchUpdate added in v1.7.2

func (qs *PageQuerySet) BatchUpdate(...any) (int64, error)

func (*PageQuerySet) BuildSearchQuery added in v1.7.2

func (qs *PageQuerySet) BuildSearchQuery(_ []search.BuiltSearchField, query string) (search.Searchable, error)

func (*PageQuerySet) BulkCreate added in v1.7.2

func (qs *PageQuerySet) BulkCreate([]*PageNode) ([]*PageNode, error)

func (*PageQuerySet) BulkUpdate added in v1.7.2

func (qs *PageQuerySet) BulkUpdate(...any) (int64, error)

func (*PageQuerySet) Children added in v1.7.2

func (qs *PageQuerySet) Children(path string, depth int64) *PageQuerySet

func (*PageQuerySet) ChildrenOf added in v1.7.2

func (qs *PageQuerySet) ChildrenOf(node *PageNode) *PageQuerySet

func (*PageQuerySet) CloneQuerySet added in v1.7.2

func (*PageQuerySet) Create added in v1.7.2

func (qs *PageQuerySet) Create(*PageNode) (*PageNode, error)

func (*PageQuerySet) Delete added in v1.7.2

func (qs *PageQuerySet) Delete(nodes ...*PageNode) (int64, error)

func (*PageQuerySet) DescendantOf added in v1.7.2

func (qs *PageQuerySet) DescendantOf(node *PageNode, inclusive ...bool) *PageQuerySet

func (*PageQuerySet) Descendants added in v1.7.2

func (qs *PageQuerySet) Descendants(path string, depth int64, inclusive ...bool) *PageQuerySet

func (*PageQuerySet) GetAncestors added in v1.7.2

func (qs *PageQuerySet) GetAncestors(p string, depth int64) ([]*PageNode, error)

AncestorNodes returns the ancestor nodes of the given node.

The path is a PageNode.Path, the depth is the depth of the page.

func (*PageQuerySet) GetChildNodes added in v1.7.2

func (qs *PageQuerySet) GetChildNodes(node *PageNode, statusFlags StatusFlag, offset int32, limit int32) ([]*PageNode, error)

func (*PageQuerySet) GetDescendants added in v1.7.2

func (qs *PageQuerySet) GetDescendants(path string, depth int64, statusFlags StatusFlag, offset int32, limit int32) ([]*PageNode, error)

func (*PageQuerySet) GetNodeByID added in v1.7.2

func (qs *PageQuerySet) GetNodeByID(id int64) (*PageNode, error)

func (*PageQuerySet) GetNodeByPath added in v1.7.2

func (qs *PageQuerySet) GetNodeByPath(path string) (*PageNode, error)

func (*PageQuerySet) GetNodeBySlug added in v1.7.2

func (qs *PageQuerySet) GetNodeBySlug(slug string, depth int64, path string) (*PageNode, error)

func (*PageQuerySet) GetNodesByDepth added in v1.7.2

func (qs *PageQuerySet) GetNodesByDepth(depth int64, statusFlags StatusFlag, offset int32, limit int32) ([]*PageNode, error)

func (*PageQuerySet) GetNodesByIDs added in v1.7.2

func (qs *PageQuerySet) GetNodesByIDs(id []int64) ([]*PageNode, error)

func (*PageQuerySet) MoveNode added in v1.7.2

func (qs *PageQuerySet) MoveNode(node *PageNode, newParent *PageNode) error

MoveNode moves a node to a new parent.

The node and new parent paths must not be empty or equal.

The new parent must not be a descendant of the node.

This function will update the url paths of all descendants, as well as the tree paths of the node and its descendants.

func (*PageQuerySet) ParentNode added in v1.7.2

func (qs *PageQuerySet) ParentNode(path string, depth int) (v *PageNode, err error)

ParentNode returns the parent node of the given node.

func (*PageQuerySet) PublishNode added in v1.7.2

func (qs *PageQuerySet) PublishNode(node *PageNode) error

PublishNode will set the published flag on the node and update it accordingly in the database.

func (*PageQuerySet) Published added in v1.7.2

func (qs *PageQuerySet) Published() *PageQuerySet

func (*PageQuerySet) RootPages added in v1.7.2

func (qs *PageQuerySet) RootPages() *PageQuerySet

func (*PageQuerySet) Search added in v1.7.2

func (qs *PageQuerySet) Search(query string) *PageQuerySet

func (*PageQuerySet) Siblings added in v1.7.2

func (qs *PageQuerySet) Siblings(path string, depth int64, inclusive ...bool) *PageQuerySet

func (*PageQuerySet) SiblingsOf added in v1.7.2

func (qs *PageQuerySet) SiblingsOf(node *PageNode, inclusive ...bool) *PageQuerySet

func (*PageQuerySet) Specific added in v1.7.2

func (qs *PageQuerySet) Specific() *SpecificPageQuerySet

func (*PageQuerySet) StatusFlags added in v1.7.2

func (qs *PageQuerySet) StatusFlags(statusFlags StatusFlag) *PageQuerySet

func (*PageQuerySet) Types added in v1.7.2

func (qs *PageQuerySet) Types(types ...any) *PageQuerySet

func (*PageQuerySet) UnpublishNode added in v1.7.2

func (qs *PageQuerySet) UnpublishNode(node *PageNode, unpublishChildren bool) error

UnpublishNode will unset the published flag on the node and update it accordingly in the database.

If unpublishChildren is true, it will also unpublish all descendants.

func (*PageQuerySet) Unpublished added in v1.7.2

func (qs *PageQuerySet) Unpublished() *PageQuerySet

func (*PageQuerySet) Update added in v1.7.2

func (qs *PageQuerySet) Update(*PageNode, ...any) (int64, error)

func (*PageQuerySet) UpdateNode added in v1.7.2

func (qs *PageQuerySet) UpdateNode(node *PageNode) error

UpdateNode updates a node.

This function will update the node's url path if the slug has changed.

In that case, it will also update the url paths of all descendants.

type PageRenderView

type PageRenderView interface {
	Render(w http.ResponseWriter, req *http.Request, page Page, context ctx.Context) error
}

type PageSignal

type PageSignal struct {
	BaseSignal
	Page Page
}

type PageTemplateGetter

type PageTemplateGetter interface {
	GetTemplate(req *http.Request, page Page) string
}

type PageTemplateRenderView

type PageTemplateRenderView interface {
	PageTemplateView
	Render(w http.ResponseWriter, req *http.Request, template string, page Page, context ctx.Context) error
}

type PageTemplateView

type PageTemplateView interface {
	PageContextGetter
	PageTemplateGetter
}

type PageView

type PageView interface {
	// ServePage is a method that will never get called.
	// It acts like the views.ServeXXX method.
	ServePage()
}

type PageViewHandler

type PageViewHandler interface {
	views.MethodsView
	views.ControlledView
	View() PageView
	CurrentPage() Page
}

A wrapper interface to get the same dynamic functionality as the views.View interface.

This handles "PageView" objects much like the views.Invoke method.

type PagesAdminHomeComponent added in v1.7.0

type PagesAdminHomeComponent struct {
	ListFields       []string
	AdminApplication *admin.AdminApplication
	Request          *http.Request
}

func (*PagesAdminHomeComponent) HTML added in v1.7.0

func (*PagesAdminHomeComponent) Media added in v1.7.0

func (p *PagesAdminHomeComponent) Media() media.Media

func (*PagesAdminHomeComponent) Ordering added in v1.7.0

func (p *PagesAdminHomeComponent) Ordering() int

type PagesMenuItem

type PagesMenuItem struct {
	menu.BaseItem
}

func (*PagesMenuItem) Component

func (p *PagesMenuItem) Component() templ.Component

type RoutablePage added in v1.7.2

type RoutablePage interface {
	Route(r *http.Request, pathComponents []string) (Page, error)
}

type Site added in v1.7.2

type Site struct {
	models.Model `table:"sites"`
	ID           int64
	Name         string
	Domain       string
	Port         int
	Default      bool
	Root         *PageNode
}

func SiteForRequest added in v1.7.2

func SiteForRequest(requestOrContext any, fn ...func(qs *queries.QuerySet[*Site]) *queries.QuerySet[*Site]) (context.Context, *Site, error)

func (*Site) BeforeDelete added in v1.7.2

func (n *Site) BeforeDelete(ctx context.Context) error

func (*Site) BeforeSave added in v1.7.2

func (n *Site) BeforeSave(ctx context.Context) error

func (*Site) DatabaseIndexes added in v1.7.2

func (n *Site) DatabaseIndexes(obj attrs.Definer) []migrator.Index

func (*Site) FieldDefs added in v1.7.2

func (n *Site) FieldDefs() attrs.Definitions

func (*Site) Fields added in v1.7.2

func (n *Site) Fields(d attrs.Definer) []attrs.Field

func (*Site) URL added in v1.7.2

func (n *Site) URL() string

func (*Site) Validate added in v1.7.2

func (n *Site) Validate(ctx context.Context) error

type SpecificPageQuerySet added in v1.7.2

type SpecificPageQuerySet struct {
	*queries.WrappedQuerySet[*PageNode, *SpecificPageQuerySet, *PageQuerySet]
}

func (*SpecificPageQuerySet) AddChildren added in v1.7.2

func (qs *SpecificPageQuerySet) AddChildren(parent Page, children ...Page) error

AddChildren adds child pages to a parent page. It creates PageNode objects for each child page and then passes them to the PageQuerySet's AddChildren method.

func (*SpecificPageQuerySet) AddRoot added in v1.7.2

func (qs *SpecificPageQuerySet) AddRoot(page Page) error

AddRoot adds a root page to the queryset.

It is a wrapper around AddRoots that takes a single page.

func (*SpecificPageQuerySet) AddRoots added in v1.7.2

func (qs *SpecificPageQuerySet) AddRoots(pages ...Page) error

AddRoots adds multiple root pages to the queryset.

It does so by creating PageNode objects for each page, and then passing it to the PageQuerySet's AddRoots method.

func (*SpecificPageQuerySet) All added in v1.7.2

func (qs *SpecificPageQuerySet) All() (queries.Rows[Page], error)

func (*SpecificPageQuerySet) AncestorOf added in v1.7.2

func (qs *SpecificPageQuerySet) AncestorOf(node *PageNode, inclusive ...bool) *SpecificPageQuerySet

func (*SpecificPageQuerySet) ChildrenOf added in v1.7.2

func (qs *SpecificPageQuerySet) ChildrenOf(node *PageNode) *SpecificPageQuerySet

func (*SpecificPageQuerySet) CloneQuerySet added in v1.7.2

func (*SpecificPageQuerySet) DeletePage added in v1.7.2

func (qs *SpecificPageQuerySet) DeletePage(page Page) error

DeletePage deletes a page from the queryset.

func (*SpecificPageQuerySet) DescendantOf added in v1.7.2

func (qs *SpecificPageQuerySet) DescendantOf(node *PageNode, inclusive ...bool) *SpecificPageQuerySet

func (*SpecificPageQuerySet) First added in v1.7.2

func (qs *SpecificPageQuerySet) First() (*queries.Row[Page], error)

First is used to retrieve the first row from the database.

It returns a Query that can be executed to get the result, which is a Row object that contains the model object and a map of annotations.

func (*SpecificPageQuerySet) Get added in v1.7.2

func (qs *SpecificPageQuerySet) Get() (*queries.Row[Page], error)

func (*SpecificPageQuerySet) Last added in v1.7.2

func (qs *SpecificPageQuerySet) Last() (*queries.Row[Page], error)

Last is used to retrieve the last row from the database.

It reverses the order of the results and then calls First to get the last row.

It returns a Query that can be executed to get the result, which is a Row object that contains the model object and a map of annotations.

func (*SpecificPageQuerySet) MovePage added in v1.7.2

func (qs *SpecificPageQuerySet) MovePage(page Page, newParent Page) error

MovePage moves a page and all it's children under a new parent page.

func (*SpecificPageQuerySet) PublishPage added in v1.7.2

func (qs *SpecificPageQuerySet) PublishPage(page Page) error

PublishPage publishes the given page.

func (*SpecificPageQuerySet) Published added in v1.7.2

func (qs *SpecificPageQuerySet) Published() *SpecificPageQuerySet

func (*SpecificPageQuerySet) Search added in v1.7.2

func (*SpecificPageQuerySet) SiblingsOf added in v1.7.2

func (qs *SpecificPageQuerySet) SiblingsOf(node *PageNode, inclusive ...bool) *SpecificPageQuerySet

func (*SpecificPageQuerySet) StatusFlags added in v1.7.2

func (qs *SpecificPageQuerySet) StatusFlags(statusFlags StatusFlag) *SpecificPageQuerySet

func (*SpecificPageQuerySet) Types added in v1.7.2

func (qs *SpecificPageQuerySet) Types(types ...any) *SpecificPageQuerySet

func (*SpecificPageQuerySet) UnpublishPage added in v1.7.2

func (qs *SpecificPageQuerySet) UnpublishPage(page Page, unpublishChildren bool) error

UnpublishPage unpublishes the given page.

func (*SpecificPageQuerySet) Unpublished added in v1.7.2

func (qs *SpecificPageQuerySet) Unpublished() *SpecificPageQuerySet

type StatusFlag added in v1.7.2

type StatusFlag int64
const (
	// StatusFlagPublished is the status flag for published pages.
	StatusFlagPublished StatusFlag = 1 << iota

	// StatusFlagHidden is the status flag for hidden pages.
	StatusFlagHidden

	// StatusFlagDeleted is the status flag for deleted pages.
	StatusFlagDeleted

	// StatusflagNone is the status flag for no status.
	//
	// It is mainly used in queries to ignore the status flag in where clauses.
	StatusFlagNone StatusFlag = 0
)

func (StatusFlag) Is added in v1.7.2

func (f StatusFlag) Is(flag StatusFlag) bool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL