admin

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: 72 Imported by: 2

Documentation

Overview

templ: version: v0.3.1020

templ: version: v0.3.1020

templ: version: v0.3.1020

Index

Constants

View Source
const (
	// RegisterAppMenuItemHook    = "admin:register_menu_item:<app_name>"
	RegisterMenuItemHook       = "admin:register_menu_item"
	RegisterFooterMenuItemHook = "admin:register_footer_menu_item"
	RegisterGlobalMediaHook    = "admin:register_global_media"
	RegisterNavBreadCrumbHook  = "admin:register_breadcrumb"
	RegisterNavActionHook      = "admin:register_nav_action"

	RegisterHomePageBreadcrumbHook   = "admin:home:register_breadcrumb"
	RegisterHomePageActionHook       = "admin:home:register_action"
	RegisterHomePageComponentHook    = "admin:home:register_component"
	RegisterHomePageDisplayPanelHook = "admin:home:register_display_panel"

	AdminModelHookAdd           = "admin:model:add"
	AdminModelHookEdit          = "admin:model:edit"
	AdminModelHookDelete        = "admin:model:delete"
	AdminModelHookRegisterRoute = "admin:model:register_route"
)
View Source
const (
	// Set the title of the home page
	APPVAR_HOME_PAGE_TITLE = "APPVAR_HOME_PAGE_TITLE"

	// Set the subtitle of the home page
	APPVAR_HOME_PAGE_SUBTITLE = "APPVAR_HOME_PAGE_SUBTITLE"

	// Set the path to the home page logo
	APPVAR_HOME_PAGE_LOGO_PATH = "APPVAR_HOME_PAGE_LOGO"
)
View Source
const BASE_KEY = "admin"
View Source
const PANEL_ID_PREFIX = "panel"

Variables

View Source
var (
	RegisterApp   = AdminSite.RegisterApp
	IsReady       = AdminSite.IsReady
	ConfigureAuth = AdminSite.configureAuth
)
View Source
var ADMIN_BASE_URL = "admin/"
View Source
var AppHandler = func(w http.ResponseWriter, r *http.Request, adminSite *AdminApplication, app *AppDefinition) {
	if !app.Options.EnableIndexView {
		except.RaiseNotFound(
			trans.T(r.Context(), "app %q does not have an index view"),
			app.Label(r.Context()),
		)
		return
	}

	if !permissions.HasPermission(r, fmt.Sprintf("admin:view_app:%s", app.Name)) {
		ReLogin(w, r, r.URL.Path)
		return
	}

	if app.Options.IndexView != nil {
		var err = views.Invoke(app.Options.IndexView(adminSite, app), w, r)
		except.AssertNil(err, 500, err)
		return
	}

	var models = app.Models
	var modelNames = make([]string, models.Len())
	var i = 0
	for front := models.Front(); front != nil; front = front.Next() {
		modelNames[i] = front.Value.Label(r.Context())
		i++
	}

	var hookName = RegisterAdminPageComponentHook(app.Name)
	var hook = goldcrest.Get[RegisterAdminAppPageComponentHookFunc](hookName)
	var components = make([]AdminPageComponent, 0)
	for _, h := range hook {
		var component = h(r, adminSite, app)
		if component != nil {
			components = append(components, component)
		}
	}
	sortComponents(components)

	var context = NewContext(
		r, adminSite, nil,
	)

	context.SetPage(PageOptions{
		TitleFn:    app.Label,
		SubtitleFn: app.Description,
		MediaFn: func() media.Media {
			var appMedia media.Media = media.NewMedia()
			for _, component := range components {
				var m = component.Media()
				if m != nil {
					appMedia = appMedia.Merge(m)
				}
			}
			return appMedia
		},
	})
	context.Set("app", app)
	context.Set("models", modelNames)
	context.Set("components", components)
	var err = tpl.FRender(w, context, BASE_KEY, "admin/views/apps/index.tmpl")
	except.AssertNil(err, 500, err)
}
View Source
var (
	BulkActionDelete = &BaseBulkAction{
		ID:       "delete",
		Ordering: 100,
		Btn:      BulkActionButton(trans.S("Delete"), components.ClassTypeDanger, "delete", true),
		PermissionsFn: func(r *http.Request, model *ModelDefinition) bool {
			return !model.DisallowDelete && permissions.HasPermission(r, "admin:delete")
		},
		Func: func(w http.ResponseWriter, r *http.Request, model *ModelDefinition, qs *queries.QuerySet[attrs.Definer]) (int, error) {
			var meta = attrs.GetModelMeta(model.NewInstance())
			var defs = meta.Definitions()
			var primary = defs.Primary()

			qs = qs.Select(primary.Name())

			var rowCnt, rowIter, err = qs.IterAll()
			if err != nil {
				return 0, err
			}

			var values = make([]string, 0, rowCnt)
			for row, err := range rowIter {
				if err != nil {
					return 0, err
				}

				var defs = row.Object.FieldDefs()
				var primary = defs.Primary()
				var val, err = primary.Value()
				if err != nil {
					return 0, err
				}

				values = append(
					values,
					attrs.ToString(val),
				)
			}

			var urlValues = url.Values{
				"pk_list": values,
				"next":    []string{r.URL.RequestURI()},
			}

			var deleteURL = fmt.Sprintf(
				"%s?%s",
				django.Reverse(
					"admin:apps:model:bulk_delete",
					model.App().Name, model.GetName(),
				),
				urlValues.Encode(),
			)

			http.Redirect(
				w, r, deleteURL, http.StatusSeeOther,
			)

			return 0, nil
		},
	}
)
View Source
var HomeHandler = &views.BaseView{
	AllowedMethods:  []string{http.MethodGet},
	BaseTemplateKey: BASE_KEY,
	TemplateName:    "admin/views/home.tmpl",
	GetContextFn: func(req *http.Request) (ctx.Context, error) {
		var context = NewContext(req, AdminSite, nil)
		var user = authentication.Retrieve(req)

		// Initialize / retrieve home page intro texts
		var pageTitle = django.ConfigGet[any](
			django.Global.Settings,
			APPVAR_HOME_PAGE_TITLE,
			trans.S("Home"),
		)
		var pageSubtitle = django.ConfigGet[any](
			django.Global.Settings,
			APPVAR_HOME_PAGE_SUBTITLE,
			func(r *http.Request) string {
				return trans.T(
					r.Context(),
					"Welcome to the Go-Django admin dashboard, %s!",
					attrs.ToString(user),
				)
			},
		)

		// Set up media files for the home page template
		var homeMedia media.Media = media.NewMedia()
		homeMedia.AddCSS(media.CSS(django.Static(
			"admin/css/home.css",
		)))

		// Initialize / retrieve the home page logo's static path
		var logo = django.ConfigGet[any](
			django.Global.Settings,
			APPVAR_HOME_PAGE_LOGO_PATH,
			django.Static("admin/images/home_logo.png"),
		)
		var logoPath string
		switch t := logo.(type) {
		case string:
			logoPath = t
		case func() string:
			logoPath = t()
		case func(*http.Request) string:
			logoPath = t(req)
		}

		// Add home page breadcrumbs and actions
		var breadCrumbs = make([]BreadCrumb, 0)
		var breadcrumbHooks = goldcrest.Get[RegisterHomePageBreadcrumbHookFunc](RegisterHomePageBreadcrumbHook)
		for _, hook := range breadcrumbHooks {
			breadCrumbs = hook(req, AdminSite, breadCrumbs)
		}

		var actions = make([]Action, 0)
		var actionHooks = goldcrest.Get[RegisterHomePageActionHookFunc](RegisterHomePageActionHook)
		for _, hook := range actionHooks {
			actions = hook(req, AdminSite, actions)
		}

		// Add custom home page components
		var componentHooks = goldcrest.Get[RegisterHomePageComponentHookFunc](RegisterHomePageComponentHook)
		var components = make([]AdminPageComponent, 0)
		for _, hook := range componentHooks {
			var component = hook(req, AdminSite)
			if component != nil {
				components = append(components, &componentWrapper{component})
			}
		}
		components = sortComponents(components)

		context.SetPage(PageOptions{
			TitleFn:     getFuncTyped[string](pageTitle, req, nil),
			SubtitleFn:  getFuncTyped[string](pageSubtitle, req, nil),
			BreadCrumbs: breadCrumbs,
			Actions:     actions,
			MediaFn: func() media.Media {
				for _, component := range components {
					var media = component.Media()
					if media != nil {
						homeMedia = homeMedia.Merge(media)
					}
				}
				return homeMedia
			},
		})

		context.Set("Components", components)

		if logoPath != "" {
			context.Set("LogoPath", logoPath)
		}

		return context, nil
	},
}
View Source
var LoginHandler = &views.FormView[LoginForm]{
	BaseView: views.BaseView{
		AllowedMethods:  []string{http.MethodGet, http.MethodPost},
		BaseTemplateKey: "admin",
		TemplateName:    "admin/views/auth/login.tmpl",
		GetContextFn: func(req *http.Request) (ctx.Context, error) {
			var context = ctx.RequestContext(req)
			// context.Set("next", req.URL.Query().Get("next"))
			var loginURL = django.Reverse("admin:login")
			var nextURL = req.URL.Query().Get("next")
			if nextURL != "" {
				var u, err = url.Parse(loginURL)
				if err != nil {
					goto returnContext
				}

				q := u.Query()
				q.Set("next", nextURL)
				u.RawQuery = q.Encode()
				loginURL = u.String()
			}

		returnContext:
			context.Set("LoginURL", loginURL)
			return context, nil
		},
	},
	GetFormFn: func(req *http.Request) LoginForm {
		var loginForm = AdminSite.AuthLoginForm(
			req,
		)
		return loginForm
	},
	InvalidFn: func(req *http.Request, form LoginForm) error {
		core.SIGNAL_LOGIN_FAILED.Send(req)
		return nil
	},
	ValidFn: func(req *http.Request, form LoginForm) error {
		form.SetRequest(req)
		return form.Login()
	},
	SuccessFn: func(w http.ResponseWriter, req *http.Request, form LoginForm) {
		var nextURL = req.URL.Query().Get("next")
		if nextURL == "" {
			nextURL = django.Reverse("admin:home")
		}

		http.Redirect(w, req, nextURL, http.StatusSeeOther)
	},
}
View Source
var ModelAddHandler = func(w http.ResponseWriter, r *http.Request, adminSite *AdminApplication, app *AppDefinition, model *ModelDefinition) {

	if !permissions.HasObjectPermission(r, model.NewInstance(), "admin:add") {
		ReLogin(w, r, r.URL.Path)
		return
	}

	if model.DisallowCreate {
		messages.Error(r, trans.T(r.Context(), "This model does not allow creation"))
		autherrors.Fail(
			http.StatusForbidden,
			trans.T(r.Context(), "This model does not allow creation"),
			django.Reverse("admin:apps:model", app.Name, model.GetName()),
		)
		return
	}

	var instance = model.NewInstance()
	if model.AddView.GetHandler != nil {
		var err = views.Invoke(model.AddView.GetHandler(adminSite, app, model, instance), w, r)
		except.AssertNil(err, 500, err)
		return
	}

	var addView = newInstanceView("add", instance, model.AddView, app, model, r, &PageOptions{
		TitleFn: trans.S("Add %s", model.Label(r.Context())),
	})
	views.Invoke(addView, w, r)

}
View Source
var ModelBulkDeleteHandler = func(w http.ResponseWriter, r *http.Request, adminSite *AdminApplication, app *AppDefinition, model *ModelDefinition) {

	var pkList = r.URL.Query()["pk_list"]
	if len(pkList) == 0 {
		except.Fail(
			http.StatusBadRequest,
			trans.T(r.Context(), "No primary keys provided for bulk delete"),
		)
		return
	}

	var meta = attrs.GetModelMeta(model.Model)
	var defs = meta.Definitions()
	var prim = defs.Primary()
	var instanceRows, err = queries.GetQuerySetWithContext(r.Context(), model.NewInstance()).
		Filter(fmt.Sprintf("%s__in", prim.Name()), pkList).
		SelectRelated(model.ListView.Prefetch.SelectRelated...).
		Preload(model.ListView.Prefetch.PrefetchRelated...).
		All()

	if err != nil {
		except.Fail(
			http.StatusInternalServerError,
			trans.T(r.Context(),
				"Failed to retrieve instances for bulk delete: %v",
				err,
			),
		)
		return
	}

	var instances = slices.Collect(instanceRows.Objects())
	if model.DeleteView.GetHandler != nil {
		var err = views.Invoke(model.DeleteView.GetHandler(adminSite, app, model, instances), w, r)
		except.AssertNil(err, 500, err)
		return
	}

	var deleteView = &AdminDeleteView{
		BaseView: views.BaseView{
			AllowedMethods:  []string{http.MethodGet, http.MethodPost},
			BaseTemplateKey: BASE_KEY,
			TemplateName:    "admin/views/models/delete.tmpl",
		},
		Permissions: []string{"admin:delete"},
		Writer:      w,
		Request:     r,
		AdminSite:   adminSite,
		App:         app,
		Model:       model,
		Instances:   instances,
	}

	err = views.Invoke(deleteView, w, r)
	except.AssertNil(err, 500, err)
}
View Source
var ModelDeleteHandler = func(w http.ResponseWriter, r *http.Request, adminSite *AdminApplication, app *AppDefinition, model *ModelDefinition, instance attrs.Definer) {
	if model.DeleteView.GetHandler != nil {
		var err = views.Invoke(model.DeleteView.GetHandler(adminSite, app, model, []attrs.Definer{instance}), w, r)
		except.AssertNil(err, 500, err)
		return
	}

	var deleteView = &AdminDeleteView{
		BaseView: views.BaseView{
			AllowedMethods:  []string{http.MethodGet, http.MethodPost},
			BaseTemplateKey: BASE_KEY,
			TemplateName:    "admin/views/models/delete.tmpl",
		},
		Permissions: []string{"admin:delete"},
		Writer:      w,
		Request:     r,
		AdminSite:   adminSite,
		App:         app,
		Model:       model,
		Instances:   []attrs.Definer{instance},
	}

	var err = views.Invoke(deleteView, w, r)
	except.AssertNil(err, 500, err)
}
View Source
var ModelEditHandler = func(w http.ResponseWriter, r *http.Request, adminSite *AdminApplication, app *AppDefinition, model *ModelDefinition, instance attrs.Definer) {
	if !permissions.HasObjectPermission(r, instance, "admin:edit") {
		ReLogin(w, r, r.URL.Path)
		return
	}

	if model.DisallowEdit {
		messages.Error(r, trans.T(r.Context(), "This model does not allow editing"))
		autherrors.Fail(
			http.StatusForbidden,
			trans.T(r.Context(), "This model does not allow editing"),
			django.Reverse("admin:apps:model", app.Name, model.GetName()),
		)
		return
	}

	if model.EditView.GetHandler != nil {
		var err = views.Invoke(model.EditView.GetHandler(adminSite, app, model, instance), w, r)
		except.AssertNil(err, 500, err)
		return
	}

	var editView = newInstanceView("edit", instance, model.EditView, app, model, r, &PageOptions{
		TitleFn: trans.S("Edit %s", model.Label(r.Context())),
	})
	views.Invoke(editView, w, r)

}
View Source
var ModelListHandler = func(w http.ResponseWriter, r *http.Request, adminSite *AdminApplication, app *AppDefinition, model *ModelDefinition) {

	if !permissions.HasObjectPermission(r, model.NewInstance(), "admin:view_list") {
		ReLogin(w, r, r.URL.Path)
		return
	}

	if model.DisallowList {
		messages.Error(r, trans.T(r.Context(), "This model does not allow listing"))
		autherrors.Fail(
			http.StatusForbidden,
			trans.T(r.Context(), "This model does not allow listing"),
			django.Reverse("admin:home"),
		)
		return
	}

	var actions = make(map[string]BulkAction)

	var hasBulkActionsPerm = permissions.HasPermission(r, "admin:bulk_actions")
	if len(model.ListView.BulkActions) > 0 && hasBulkActionsPerm {
		for _, action := range model.ListView.BulkActions {
			if !action.HasPermission(r, model) {
				continue
			}

			actions[action.Name()] = action
		}
	}

	if model.ListView.GetHandler != nil {
		var err = views.Invoke(model.ListView.GetHandler(adminSite, app, model), w, r)
		except.AssertNil(err, 500, err)
		return
	}

	var listCols = make([]list.ListColumn[attrs.Definer], len(model.ListView.Fields))
	var sortBuilder = columns.NewSortableColumnBuilder(model.Model)
	for i, field := range model.ListView.Fields {
		listCols[i] = sortBuilder.AddColumn(model.GetColumn(
			r.Context(), model.ListView, field,
		))
	}

	var amount = model.ListView.PerPage
	if amount == 0 {
		amount = 25
	}

	var qs *queries.QuerySet[attrs.Definer]
	if model.ListView.GetQuerySet != nil {
		qs = model.ListView.GetQuerySet(adminSite, app, model)
	} else {
		qs = queries.GetQuerySet(model.NewInstance())
	}
	if len(model.ListView.Prefetch.SelectRelated) > 0 {
		qs = qs.SelectRelated(model.ListView.Prefetch.SelectRelated...)
	}
	if len(model.ListView.Prefetch.PrefetchRelated) > 0 {
		qs = qs.Preload(model.ListView.Prefetch.PrefetchRelated...)
	}
	if len(model.ListView.Ordering) > 0 {
		qs = qs.OrderBy(model.ListView.Ordering...)
	}

	if !model.DisallowEdit && permissions.HasPermission(r, "admin:edit") {
		r = r.WithContext(list.SetAllowListEdit(r.Context(), true))
	}

	if len(actions) > 0 && hasBulkActionsPerm {
		r = r.WithContext(list.SetAllowListRowSelect(r.Context(), true))

		if r.Method == http.MethodPost {
			r.ParseForm()

			var listSelected = r.PostForm["list__row_select"]
			var actionName = r.PostFormValue("list_action")

			if len(listSelected) > 0 {
				var meta = attrs.GetModelMeta(model.Model)
				var defs = meta.Definitions()
				var primaryField = defs.Primary()

				qs = qs.Filter(
					fmt.Sprintf("%s__in", primaryField.Name()),
					listSelected,
				)
			}

			if actionName == "" {
				goto continueView
			}

			var action, ok = actions[actionName]
			if !ok {
				except.Fail(
					http.StatusBadRequest,
					trans.T(r.Context(), "Invalid list action"),
				)
				return
			}

			var changed, err = action.Execute(w, r, model, qs)
			if err != nil {
				logger.Errorf(
					"Failed to execute bulk action %s: %v",
					action.Name(), err,
				)
				except.Fail(
					http.StatusInternalServerError,
					trans.T(r.Context(), "Failed to apply list action"),
				)
				return
			}

			switch {
			case changed == 1:
				messages.Success(r, trans.T(r.Context(), "List action applied successfully to one object"))
				http.Redirect(w, r, django.Reverse("admin:apps:model", app.Name, model.GetName()), http.StatusSeeOther)
			case changed > 1:
				messages.Success(r, trans.T(r.Context(), "List action applied successfully to multiple objects"))
				http.Redirect(w, r, django.Reverse("admin:apps:model", app.Name, model.GetName()), http.StatusSeeOther)
			}

			return
		}
	}

continueView:
	var filterForm *filters.Filters[attrs.Definer]
	if len(model.ListView.Filters) > 0 {
		filterForm = filters.NewFilters[attrs.Definer](r.Context(), "filters")
		for _, f := range model.ListView.Filters {
			filterForm.Add(f)
		}

		var err error
		qs, err = filterForm.Filter(r, r.URL.Query(), qs)
		if err != nil {
			except.AssertNil(err, 500, err)
			return
		}
	}

	qs = sortBuilder.Sort(qs, r.URL.Query()["sort"])

	var view = &list.View[attrs.Definer]{
		Model:           model.NewInstance(),
		ListColumns:     listCols,
		DefaultAmount:   int(amount),
		AllowedMethods:  []string{http.MethodGet, http.MethodPost},
		BaseTemplateKey: BASE_KEY,
		TemplateName:    "admin/views/models/list.tmpl",
		Mixins: func(r *http.Request, v *list.View[attrs.Definer]) []views.View {
			if !permissions.HasObjectPermission(r, model.NewInstance(), "admin:export") {
				return nil
			}

			return []views.View{
				&list.ListExportMixin[attrs.Definer]{
					Model:  model.NewInstance(),
					Export: list.ExportText[attrs.Definer],
				},
			}
		},
		List: func(r *http.Request, po pagination.PageObject[attrs.Definer], lc []list.ListColumn[attrs.Definer], ctx ctx.Context) (list.StringRenderer, error) {
			if model.ListView.GetList != nil {
				return model.ListView.GetList(r, adminSite, app, model, po.Results())
			}
			return nil, nil

		},
		ChangeContextFn: func(req *http.Request, qs *queries.QuerySet[attrs.Definer], baseCtx ctx.Context) (ctx.Context, error) {
			var paginator = list.PaginatorFromContext[attrs.Definer](req.Context())
			var count, err = paginator.Count()
			if err != nil {
				return nil, err
			}

			var buttons = []components.ShowableComponent{
				components.NewShowableComponent(
					req, func(r *http.Request) bool {
						return count > 0 && baseCtx.Get("view_list_form") != nil && !model.DisallowEdit && permissions.HasObjectPermission(r, model.NewInstance(), "admin:edit")
					},
					BulkActionButton(
						trans.S("Change"),
						components.ClassTypeWarning|components.ClassTypeHollow,
						"",
						len(actions) > 0,
					),
				),
			}

			if count > 0 && len(model.ListView.BulkActions) > 0 && hasBulkActionsPerm {
				for _, action := range model.ListView.BulkActions {
					if !action.HasPermission(r, model) {
						continue
					}

					buttons = append(buttons, components.NewShowableComponent(
						r,
						func(r *http.Request) bool { return action.HasPermission(r, model) },
						action.Button(),
					))
				}
			}

			var actions = make([]Action, 0)
			if permissions.HasObjectPermission(req, model.NewInstance(), "admin:export") {
				var query = req.URL.Query()
				query.Set("_export", "1")
				var downloadURL = fmt.Sprintf("%s?%s",
					django.Reverse("admin:apps:model", app.Name, model.GetName()),
					query.Encode(),
				)
				actions = append(actions, Action{
					Icon:  "icon-download",
					Title: trans.T(r.Context(), "Export %s", model.PluralLabel(r.Context())),
					URL:   downloadURL,
				})
			}

			var context = NewContext(req, adminSite, baseCtx)
			context.SetPage(PageOptions{
				TitleFn: trans.S(
					"%s List (%d)",
					model.Label(r.Context()),
					count,
				),
				HeaderActions: append(
					[]components.ShowableComponent{
						components.NewShowableComponent(
							req, func(r *http.Request) bool {
								return !model.DisallowCreate && permissions.HasObjectPermission(r, model.NewInstance(), "admin:add")
							},
							components.Link(components.ButtonConfig{
								Text: trans.S("Add"),
								Type: components.ClassTypeSecondary,
							}, func() string {
								return django.Reverse("admin:apps:model:add", app.Name, model.GetName())
							}),
						),
					},
					buttons...,
				),
				Actions: actions,
				SidePanels: &menu.SidePanels{
					Panels: []menu.SidePanel{
						SidePanelFilters(
							r, filterForm, list.PageFromContext[attrs.Definer](req.Context()), func(p *menu.BaseSidePanel, r *http.Request) bool {
								return len(model.ListView.Filters) == 0
							},
						),
					},
				},
			})
			context.Set("app", app)
			context.Set("model", model)
			context.Set("actions", actions)
			if filterForm != nil {
				context.Set("filter", filterForm)
			}
			return context, nil
		},
		QuerySet: func(r *http.Request) *queries.QuerySet[attrs.Definer] {
			return qs
		},
		TitleFieldColumn: func(lc list.ListColumn[attrs.Definer]) list.ListColumn[attrs.Definer] {
			var col = list.TitleFieldColumn(lc, func(r *http.Request, defs attrs.Definitions, instance attrs.Definer) string {
				var primaryField = defs.Primary()
				if primaryField == nil {
					return ""
				}

				if !permissions.HasObjectPermission(r, instance, "admin:edit") || model.DisallowEdit {
					return ""
				}

				return django.Reverse("admin:apps:model:edit", app.Name, model.GetName(), primaryField.GetValue())
			})

			col = list.RowSelectColumn(
				"list__row_select",
				nil,
				nil,
				col,
				map[string]any{
					"data-bulk-actions-target": "selectAll",
				},
				map[string]any{
					"data-bulk-actions-target": "checkbox",
				},
			)

			return col
		},
	}

	views.Invoke(view, w, r)
}
View Source
var (
	// Register a custom component for an app registered to the admin.
	// The app name is used to identify the app.
	// It should be formatted as "admin:<app_name>:register_admin_page_component"
	// This will then return a string which can be used to register the component to the app.
	RegisterAdminPageComponentHook = func(appname string) string {
		return fmt.Sprintf("admin:%s:register_component", appname)
	}
)

Functions

func BindPanels added in v1.7.2

func BindPanels(panels []Panel, r *http.Request, panelCount map[string]int, form forms.Form, ctx context.Context, instance attrs.Definer, boundFields map[string]forms.BoundField, formsets FormSetObject) iter.Seq2[int, BoundPanel]

func BuildPanelID added in v1.7.2

func BuildPanelID(key string, panelCount map[string]int, extra ...string) string

func BulkActionButton added in v1.7.2

func BulkActionButton(text any, typ components.ClassType, actionName string, requiresSelected bool) templ.Component

func GetAdminForm

func GetAdminForm[T attrs.Definer](instance T, opts FormViewOptions, app *AppDefinition, model *ModelDefinition, r *http.Request) modelforms.ModelForm[T]

func Home added in v1.7.0

func Home(w http.ResponseWriter, r *http.Request, errorMessage ...string)

func NewAppConfig

func NewAppConfig() django.AppConfig

func NewContext

func NewContext(request *http.Request, site *AdminApplication, context ctx.Context) *adminContext

func NewInstanceHandler added in v1.7.2

func NewInstanceHandler(appnameVar, modelVar, idVar string, handler func(w http.ResponseWriter, req *http.Request, adminSite *AdminApplication, app *AppDefinition, model *ModelDefinition, instance attrs.Definer)) mux.Handler

func NewModelHandler added in v1.7.2

func NewModelHandler(appnameVar, modelVar string, handler func(w http.ResponseWriter, r *http.Request, adminSite *AdminApplication, app *AppDefinition, model *ModelDefinition), fail ...func(w http.ResponseWriter, r *http.Request, msg string)) mux.Handler

func PanelBody added in v1.7.2

func PanelBody() templ.Component

func PanelComparison added in v1.7.2

func PanelComparison(ctx context.Context, panels []Panel, oldInstance attrs.Definer, newInstance attrs.Definer, mustWrap ...bool) (compare.Comparison, error)

func PanelErrors added in v1.7.2

func PanelErrors(errors []error) templ.Component

func PanelHeading added in v1.7.2

func PanelHeading(panelId string, allowPanelLink bool) templ.Component

func PanelHelpText added in v1.7.2

func PanelHelpText(helpText any) templ.Component

func ReLogin added in v1.7.0

func ReLogin(w http.ResponseWriter, r *http.Request, nextURL ...string)

func RedirectLoginFailedToAdmin added in v1.6.9

func RedirectLoginFailedToAdmin(w http.ResponseWriter, r *http.Request, app *django.Application, authError *autherrors.AuthenticationError) (written bool)

func RegisterAdminAppPageComponent added in v1.7.0

func RegisterAdminAppPageComponent(appname string, f RegisterAdminAppPageComponentHookFunc)

Register a custom component for an app registered to the admin.

func RegisterAppMenuItem added in v1.7.2

func RegisterAppMenuItem(appName string, fn RegisterAppMenuItemHookFunc)

Register an item to the django admin menu (sidebar) for a specific app.

func RegisterGlobalFooterMenuItem added in v1.7.0

func RegisterGlobalFooterMenuItem(fn RegisterFooterMenuItemHookFunc)

Register an item to the django admin menu's footer.

func RegisterGlobalMedia

func RegisterGlobalMedia(fn RegisterMediaHookFunc)

Register a media hook to the admin site.

This is used to add custom CSS & JS to the admin site.

func RegisterGlobalMenuItem added in v1.7.0

func RegisterGlobalMenuItem(fn RegisterMenuItemHookFunc)

Register an item to the django admin menu (sidebar).

func RegisterGlobalNavAction added in v1.7.0

func RegisterGlobalNavAction(fn RegisterNavActionHookFunc)

Register a navigation action to the admin site.

func RegisterGlobalNavBreadCrumb added in v1.7.0

func RegisterGlobalNavBreadCrumb(fn RegisterBreadCrumbHookFunc)

Register a breadcrumb to the admin site.

func RegisterHomePageAction added in v1.7.0

func RegisterHomePageAction(f RegisterHomePageActionHookFunc)

Register an action item for the home page.

func RegisterHomePageBreadcrumb added in v1.7.0

func RegisterHomePageBreadcrumb(f RegisterHomePageBreadcrumbHookFunc)

Register a breadcrumb for the home page.

func RegisterHomePageComponent added in v1.7.0

func RegisterHomePageComponent(f RegisterHomePageComponentHookFunc)

Register a custom component for the home page.

func RegisterModelAddHook added in v1.7.0

func RegisterModelAddHook(f AdminModelHookFunc)

Register a hook to be called when a model is added.

func RegisterModelDeleteHook added in v1.7.0

func RegisterModelDeleteHook(f AdminModelDeleteFunc)

Register a hook to be called when a model is deleted.

func RegisterModelEditHook added in v1.7.0

func RegisterModelEditHook(f AdminModelHookFunc)

Register a hook to be called when a model is edited.

func RegisterModelsRouteHook added in v1.7.2

func RegisterModelsRouteHook(f RegisterModelsRouteHookFunc)

Register a hook to register a route for models.

func RequiredMiddleware

func RequiredMiddleware(next mux.Handler) mux.Handler

func SidePanelFilters added in v1.7.2

func SidePanelFilters(request *http.Request, filters any, pageObject any, hidden ...func(p *menu.BaseSidePanel, r *http.Request) bool) menu.SidePanel

func TextComponent added in v1.7.2

func TextComponent(text any) templ.Component

Types

type Action

type Action struct {
	Icon   string
	Target string
	Title  string
	URL    string
}

type AdminApplication

type AdminApplication struct {
	*apps.AppConfig

	// Ordering is the order in which the apps are displayed
	// in the admin interface.
	Ordering []string

	Route *mux.Route

	// Apps is a map of all the apps that are registered
	// with the admin site.
	Apps *orderedmap.OrderedMap[
		string, *AppDefinition,
	]
	// contains filtered or unexported fields
}
var AdminSite *AdminApplication = &AdminApplication{
	AppConfig: apps.NewAppConfig("admin"),
	Apps: orderedmap.NewOrderedMap[
		string, *AppDefinition,
	](),
	Ordering: make([]string, 0),
	Route: mux.NewRoute(
		mux.ANY, ADMIN_BASE_URL, nil, "admin",
	),
}

func (*AdminApplication) AuthLoginForm

func (a *AdminApplication) AuthLoginForm(r *http.Request, formOpts ...func(forms.Form)) LoginForm

func (*AdminApplication) AuthLoginHandler added in v1.7.0

func (a *AdminApplication) AuthLoginHandler() func(w http.ResponseWriter, r *http.Request)

func (*AdminApplication) AuthLogout

func (a *AdminApplication) AuthLogout(r *http.Request) error

func (*AdminApplication) Check added in v1.7.2

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

func (*AdminApplication) IsReady

func (a *AdminApplication) IsReady() bool

func (*AdminApplication) RegisterApp

func (a *AdminApplication) RegisterApp(name string, appOptions AppOptions, opts ...ModelOptions) *AppDefinition

func (*AdminApplication) SearchableModels added in v1.7.2

func (a *AdminApplication) SearchableModels(r *http.Request) []*ModelDefinition

type AdminDeleteView added in v1.7.2

type AdminDeleteView struct {
	views.BaseView
	Permissions []string
	Writer      http.ResponseWriter
	Request     *http.Request
	AdminSite   *AdminApplication
	App         *AppDefinition
	Model       *ModelDefinition
	Instances   []attrs.Definer
}

func (*AdminDeleteView) GetContext added in v1.7.2

func (v *AdminDeleteView) GetContext(req *http.Request) (ctx.Context, error)

func (*AdminDeleteView) Instance added in v1.7.2

func (v *AdminDeleteView) Instance() attrs.Definer

func (*AdminDeleteView) PKList added in v1.7.2

func (v *AdminDeleteView) PKList() []interface{}

func (*AdminDeleteView) PrimaryField added in v1.7.2

func (v *AdminDeleteView) PrimaryField() attrs.FieldDefinition

func (*AdminDeleteView) ServePOST added in v1.7.2

func (v *AdminDeleteView) ServePOST(w http.ResponseWriter, r *http.Request)

func (*AdminDeleteView) Setup added in v1.7.2

type AdminForm

type AdminForm[T1 modelforms.ModelForm[T2], T2 attrs.Definer] struct {
	Form    T1
	Panels  []Panel
	Request *http.Request
	// contains filtered or unexported fields
}

func NewAdminForm

func NewAdminForm[T1 modelforms.ModelForm[T2], T2 attrs.Definer](r *http.Request, form T1, panels ...Panel) *AdminForm[T1, T2]

func (*AdminForm[T1, T2]) AddError

func (a *AdminForm[T1, T2]) AddError(name string, errorList ...error)

func (*AdminForm[T1, T2]) AddField

func (a *AdminForm[T1, T2]) AddField(name string, field fields.Field)

func (*AdminForm[T1, T2]) AddFormError

func (a *AdminForm[T1, T2]) AddFormError(errorList ...error)

func (*AdminForm[T1, T2]) AddWidget

func (a *AdminForm[T1, T2]) AddWidget(name string, widget widgets.Widget)

func (*AdminForm[T1, T2]) BindCleanedData added in v1.7.2

func (f *AdminForm[T1, T2]) BindCleanedData(invalid, defaults, cleaned map[string]interface{})

func (*AdminForm[T1, T2]) BoundErrors

func (a *AdminForm[T1, T2]) BoundErrors() *orderedmap.OrderedMap[string, []error]

func (*AdminForm[T1, T2]) BoundFields

func (a *AdminForm[T1, T2]) BoundFields() *orderedmap.OrderedMap[string, forms.BoundField]

func (*AdminForm[T1, T2]) BoundForm

func (a *AdminForm[T1, T2]) BoundForm() forms.BoundForm

func (*AdminForm[T1, T2]) CallbackOnFinalize added in v1.7.2

func (f *AdminForm[T1, T2]) CallbackOnFinalize() []func(forms.Form)

func (*AdminForm[T1, T2]) CallbackOnInvalid added in v1.7.2

func (f *AdminForm[T1, T2]) CallbackOnInvalid() []func(forms.Form)

func (*AdminForm[T1, T2]) CallbackOnValid added in v1.7.2

func (f *AdminForm[T1, T2]) CallbackOnValid() []func(forms.Form)

func (*AdminForm[T1, T2]) CleanedData

func (a *AdminForm[T1, T2]) CleanedData() map[string]interface{}

func (*AdminForm[T1, T2]) CleanedDataUnsafe added in v1.7.2

func (f *AdminForm[T1, T2]) CleanedDataUnsafe() map[string]interface{}

func (*AdminForm[T1, T2]) Context added in v1.7.2

func (a *AdminForm[T1, T2]) Context() context.Context

func (*AdminForm[T1, T2]) Data added in v1.7.2

func (f *AdminForm[T1, T2]) Data() (url.Values, map[string][]filesystem.FileHeader)

func (*AdminForm[T1, T2]) DeleteField

func (a *AdminForm[T1, T2]) DeleteField(name string) bool

func (*AdminForm[T1, T2]) EditContext

func (a *AdminForm[T1, T2]) EditContext(key string, context ctx.Context)

func (*AdminForm[T1, T2]) ErrorList

func (a *AdminForm[T1, T2]) ErrorList() []error

func (*AdminForm[T1, T2]) Field

func (a *AdminForm[T1, T2]) Field(name string) (fields.Field, bool)

func (*AdminForm[T1, T2]) FieldMap added in v1.7.2

func (a *AdminForm[T1, T2]) FieldMap() *orderedmap.OrderedMap[string, forms.Field]

func (*AdminForm[T1, T2]) FieldOrder

func (a *AdminForm[T1, T2]) FieldOrder() []string

func (*AdminForm[T1, T2]) Fields

func (a *AdminForm[T1, T2]) Fields() []fields.Field

func (*AdminForm[T1, T2]) FormSet added in v1.7.2

func (a *AdminForm[T1, T2]) FormSet() formsets.ListFormSet[formsets.BaseFormSetForm]

func (*AdminForm[T1, T2]) HasChanged

func (a *AdminForm[T1, T2]) HasChanged() bool

func (*AdminForm[T1, T2]) InitialData

func (a *AdminForm[T1, T2]) InitialData() map[string]interface{}

func (*AdminForm[T1, T2]) Instance added in v1.7.2

func (a *AdminForm[T1, T2]) Instance() attrs.Definer

func (*AdminForm[T1, T2]) IsValid

func (a *AdminForm[T1, T2]) IsValid() bool

func (*AdminForm[T1, T2]) Load added in v1.7.2

func (a *AdminForm[T1, T2]) Load()

func (*AdminForm[T1, T2]) Media

func (a *AdminForm[T1, T2]) Media() media.Media

func (*AdminForm[T1, T2]) OnFinalize

func (a *AdminForm[T1, T2]) OnFinalize(f ...func(forms.Form))

func (*AdminForm[T1, T2]) OnInvalid

func (a *AdminForm[T1, T2]) OnInvalid(f ...func(forms.Form))

func (*AdminForm[T1, T2]) OnValid

func (a *AdminForm[T1, T2]) OnValid(f ...func(forms.Form))

func (*AdminForm[T1, T2]) Ordering

func (a *AdminForm[T1, T2]) Ordering(o []string)

func (*AdminForm[T1, T2]) Prefix

func (a *AdminForm[T1, T2]) Prefix() string

func (*AdminForm[T1, T2]) PrefixName added in v1.7.2

func (a *AdminForm[T1, T2]) PrefixName(name string) (prefixedName string)

func (*AdminForm[T1, T2]) Renderer added in v1.7.2

func (a *AdminForm[T1, T2]) Renderer() forms.FormRenderer

func (*AdminForm[T1, T2]) Save added in v1.7.2

func (a *AdminForm[T1, T2]) Save() (map[string]interface{}, error)

func (*AdminForm[T1, T2]) SaveForms added in v1.7.2

func (a *AdminForm[T1, T2]) SaveForms(formList ...forms.Form) (err error)

func (*AdminForm[T1, T2]) SetExclude added in v1.7.2

func (a *AdminForm[T1, T2]) SetExclude(exclude ...string)

func (*AdminForm[T1, T2]) SetFields added in v1.7.2

func (a *AdminForm[T1, T2]) SetFields(fields ...string)

func (*AdminForm[T1, T2]) SetInitial

func (a *AdminForm[T1, T2]) SetInitial(initial map[string]interface{})

func (*AdminForm[T1, T2]) SetInstance added in v1.7.2

func (a *AdminForm[T1, T2]) SetInstance(model T2)

func (*AdminForm[T1, T2]) SetOnLoad added in v1.7.2

func (a *AdminForm[T1, T2]) SetOnLoad(fn func(model T2, initialData map[string]interface{}))

func (*AdminForm[T1, T2]) SetPrefix

func (a *AdminForm[T1, T2]) SetPrefix(prefix string)

func (*AdminForm[T1, T2]) SetRenderer added in v1.7.2

func (a *AdminForm[T1, T2]) SetRenderer(renderer forms.FormRenderer)

func (*AdminForm[T1, T2]) SetValidators

func (a *AdminForm[T1, T2]) SetValidators(validators ...func(forms.Form, map[string]interface{}) []error)

func (*AdminForm[T1, T2]) UnpackErrors added in v1.7.2

func (a *AdminForm[T1, T2]) UnpackErrors(bound forms.BoundForm, boundErrors *orderedmap.OrderedMap[string, []error]) []forms.FieldError

func (*AdminForm[T1, T2]) Unwrap added in v1.7.2

func (a *AdminForm[T1, T2]) Unwrap() []formsets.BaseFormSetForm

func (*AdminForm[T1, T2]) Validators added in v1.7.2

func (f *AdminForm[T1, T2]) Validators() []func(forms.Form, map[string]interface{}) []error

func (*AdminForm[T1, T2]) WasCleaned added in v1.7.2

func (f *AdminForm[T1, T2]) WasCleaned() bool

func (*AdminForm[T1, T2]) Widget

func (a *AdminForm[T1, T2]) Widget(name string) (widgets.Widget, bool)

func (*AdminForm[T1, T2]) Widgets

func (a *AdminForm[T1, T2]) Widgets() []widgets.Widget

func (*AdminForm[T1, T2]) WithContext added in v1.7.2

func (a *AdminForm[T1, T2]) WithContext(ctx context.Context)

func (*AdminForm[T1, T2]) WithData

func (a *AdminForm[T1, T2]) WithData(data url.Values, files map[string][]filesystem.FileHeader, r *http.Request)

type AdminModelDeleteFunc added in v1.7.2

type AdminModelDeleteFunc = func(r *http.Request, adminSite *AdminApplication, model *ModelDefinition, instances []attrs.Definer)

type AdminModelHookFunc added in v1.6.8

type AdminModelHookFunc = func(r *http.Request, adminSite *AdminApplication, model *ModelDefinition, instance attrs.Definer)

type AdminPageComponent added in v1.7.0

type AdminPageComponent interface {
	HTML() template.HTML
	Ordering() int
	Media() media.Media
}

AdminPageComponent is an interface for custom page components

It allows for custom page components to be added to the page dynamically. The ordering of the components is determined by the Ordering method.

type AlertPanel added in v1.7.2

type AlertPanel struct {
	Type         AlertType
	Label        any
	HTML         any
	TemplateFile string
	Classnames   string
}

func (*AlertPanel) Bind added in v1.7.2

func (*AlertPanel) Class added in v1.7.2

func (a *AlertPanel) Class(classes string) Panel

func (*AlertPanel) ClassName added in v1.7.2

func (a *AlertPanel) ClassName() string

func (*AlertPanel) Comparison added in v1.7.2

func (f *AlertPanel) Comparison(ctx context.Context, oldInstance attrs.Definer, newInstance attrs.Definer) (compare.Comparison, error)

func (*AlertPanel) Fields added in v1.7.2

func (a *AlertPanel) Fields() []string

func (*AlertPanel) GetHTML added in v1.7.2

func (a *AlertPanel) GetHTML(ctx context.Context) template.HTML

func (*AlertPanel) GetLabel added in v1.7.2

func (a *AlertPanel) GetLabel(ctx context.Context) string

func (*AlertPanel) GetType added in v1.7.2

func (a *AlertPanel) GetType() AlertType

type AlertType added in v1.7.2

type AlertType string
const (
	ALERT_INFO    AlertType = "info"
	ALERT_SUCCESS AlertType = "success"
	ALERT_WARNING AlertType = "warning"
	ALERT_ERROR   AlertType = "danger"
)

type AppDefinition

type AppDefinition struct {
	Name    string
	Options AppOptions
	Models  *orderedmap.OrderedMap[
		string, *ModelDefinition,
	]
	Routing func(mux.Multiplexer)
	// contains filtered or unexported fields
}

func (*AppDefinition) Description

func (a *AppDefinition) Description(ctx context.Context) string

func (*AppDefinition) Label

func (a *AppDefinition) Label(ctx context.Context) string

func (*AppDefinition) OnReady

func (a *AppDefinition) OnReady(adminSite *AdminApplication)

func (*AppDefinition) Register

func (a *AppDefinition) Register(opts ModelOptions) *ModelDefinition

type AppOptions

type AppOptions struct {
	// RegisterToAdminMenu allows for registering this app to the admin menu by default.
	RegisterToAdminMenu any

	// FullAdminMenu allows for always displaying the full admin menu for this app.
	//
	// Otherwise, if the app only has one model, it will be displayed directly in the admin menu.
	FullAdminMenu bool

	// EnableIndexView allows for enabling the index view for this app.
	//
	// If this is disabled, only a main sub-menu item will be created, but not for the index view.
	EnableIndexView bool

	// Applabel must return a human readable label for the app.
	AppLabel func(ctx context.Context) string

	// AppDescription must return a human readable description of this app.
	AppDescription func(ctx context.Context) string

	// MenuLabel must return a human readable label for the menu, this is how the app's name will appear in the admin's navigation.
	MenuLabel func(ctx context.Context) string

	// MenuOrder is the order in which the app will appear in the admin's navigation.
	MenuOrder int

	// MenuIcon must return a string representing the icon to use for the menu.
	//
	// This should be a HTML element, I.E. "<svg>...</svg>".
	MenuIcon func() string

	// MediaFn must return a media.Media object that will be used for this app.
	//
	// It will always be included in the admin's media.
	MediaFn func() media.Media

	// A custom index view for the app.
	//
	// This will override the default index view for the app.
	IndexView func(adminSite *AdminApplication, app *AppDefinition) views.View
}

type AuthConfig

type AuthConfig struct {
	// GetLoginForm is a function that returns a LoginForm
	//
	// This function is called when the user tries to login to the admin
	// interface. It should return a LoginForm that is used to render
	// the login form.
	//
	// If GetLoginHandler is set, this function will not be called.
	GetLoginForm func(r *http.Request, formOpts ...func(forms.Form)) LoginForm

	// GetLoginHandler is a function that returns a http.HandlerFunc for
	// logging a user in to the admin interface.
	//
	// If GetLoginHandler is set, this function will be called instead
	// of GetLoginForm. It should return a http.HandlerFunc that is
	// used to render the login form.
	GetLoginHandler func(w http.ResponseWriter, r *http.Request)

	// Logout is a function that is called when the user logs out of
	// the admin interface.
	Logout func(r *http.Request) error
}

type BaseBulkAction added in v1.7.2

type BaseBulkAction struct {
	ID            string
	Btn           templ.Component
	Ordering      int
	Permissions   []string
	PermissionsFn func(r *http.Request, model *ModelDefinition) bool
	Func          func(w http.ResponseWriter, r *http.Request, model *ModelDefinition, qs *queries.QuerySet[attrs.Definer]) (int, error)
}

func (*BaseBulkAction) Button added in v1.7.2

func (b *BaseBulkAction) Button() templ.Component

func (*BaseBulkAction) Execute added in v1.7.2

func (*BaseBulkAction) HasPermission added in v1.7.2

func (b *BaseBulkAction) HasPermission(r *http.Request, model *ModelDefinition) bool

func (*BaseBulkAction) Name added in v1.7.2

func (b *BaseBulkAction) Name() string

func (*BaseBulkAction) Order added in v1.7.2

func (b *BaseBulkAction) Order() int

type BoundAlertPanel added in v1.7.2

type BoundAlertPanel[T forms.Form] struct {
	Context context.Context
	Panel   *AlertPanel
	Request *http.Request
	Form    T
}

func (*BoundAlertPanel[T]) Component added in v1.7.2

func (p *BoundAlertPanel[T]) Component() templ.Component

func (*BoundAlertPanel[T]) Hidden added in v1.7.2

func (p *BoundAlertPanel[T]) Hidden() bool

func (*BoundAlertPanel[T]) Render added in v1.7.2

func (p *BoundAlertPanel[T]) Render() template.HTML

type BoundFormPanel

type BoundFormPanel[T forms.Form, P Panel] struct {
	forms.BoundField
	Context context.Context
	Request *http.Request
	Panel   P
	Form    T
}

func (*BoundFormPanel[T, P]) Component

func (p *BoundFormPanel[T, P]) Component() templ.Component

func (*BoundFormPanel[T, P]) Render

func (p *BoundFormPanel[T, P]) Render() template.HTML

type BoundJSONDetailPanel added in v1.7.2

type BoundJSONDetailPanel struct {
	Error       error
	Panel       JSONDetailPanel
	Request     *http.Request
	BoundFields []forms.BoundField
	BoundField  forms.BoundField
}

func (*BoundJSONDetailPanel) Component added in v1.7.2

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

func (*BoundJSONDetailPanel) Hidden added in v1.7.2

func (p *BoundJSONDetailPanel) Hidden() bool

func (*BoundJSONDetailPanel) Render added in v1.7.2

func (p *BoundJSONDetailPanel) Render() template.HTML

type BoundModelFormPanel added in v1.7.2

type BoundModelFormPanel[TARGET attrs.Definer, FORM modelforms.ModelForm[TARGET]] struct {
	Panel       *ModelFormPanel[TARGET, FORM]
	Panels      []Panel
	SourceModel attrs.Definer
	SourceField attrs.Field
	FormSet     formsets.ListFormSet[modelforms.ModelForm[TARGET]]
	Context     context.Context
	Request     *http.Request
}

func (*BoundModelFormPanel[TARGET, FORM]) Component added in v1.7.2

func (p *BoundModelFormPanel[TARGET, FORM]) Component() templ.Component

func (*BoundModelFormPanel[TARGET, FORM]) Hidden added in v1.7.2

func (p *BoundModelFormPanel[TARGET, FORM]) Hidden() bool

func (*BoundModelFormPanel[TARGET, FORM]) Render added in v1.7.2

func (p *BoundModelFormPanel[TARGET, FORM]) Render() template.HTML

type BoundPanel

type BoundPanel interface {
	Hidden() bool
	Component() templ.Component
	Render() template.HTML
}

type BoundPanelGroup added in v1.7.2

type BoundPanelGroup[T forms.Form] struct {
	BoundPanel
	Panel      *panelGroup
	PanelIndex map[string]int
	LabelFn    func(context.Context) string
	HelpTextFn func(context.Context) string
	Context    context.Context
	Request    *http.Request
	Panels     []BoundPanel
	Form       T
}

func (*BoundPanelGroup[T]) Component added in v1.7.2

func (p *BoundPanelGroup[T]) Component() templ.Component

func (*BoundPanelGroup[T]) Render added in v1.7.2

func (p *BoundPanelGroup[T]) Render() template.HTML

type BoundRowPanel added in v1.7.2

type BoundRowPanel[T forms.Form] struct {
	LabelFn    func(context.Context) string
	HelpTextFn func(context.Context) string
	Panel      *rowPanel
	PanelIndex map[string]int
	Context    context.Context
	Request    *http.Request
	Panels     []BoundPanel
	Form       T
}

func (*BoundRowPanel[T]) Component added in v1.7.2

func (p *BoundRowPanel[T]) Component() templ.Component

func (*BoundRowPanel[T]) Hidden added in v1.7.2

func (p *BoundRowPanel[T]) Hidden() bool

func (*BoundRowPanel[T]) Render added in v1.7.2

func (p *BoundRowPanel[T]) Render() template.HTML

type BoundSearchView added in v1.7.2

type BoundSearchView struct {
	views.BaseView
	W     http.ResponseWriter
	R     *http.Request
	Model *ModelDefinition
}

func (*BoundSearchView) GetContext added in v1.7.2

func (b *BoundSearchView) GetContext(req *http.Request) (ctx.Context, error)
func (b *BoundSearchView) GetEditLink(id any) string

func (*BoundSearchView) GetList added in v1.7.2

func (b *BoundSearchView) GetList(v *BoundSearchView, objects []attrs.Definer, columns []list.ListColumn[attrs.Definer]) (StringRenderer, error)

func (*BoundSearchView) Setup added in v1.7.2

type BoundTitlePanel

type BoundTitlePanel[T forms.Form, P Panel] struct {
	BoundPanel
	Panel     P
	OutputIds []string
	Context   context.Context
	Request   *http.Request
}

func (*BoundTitlePanel[T, P]) Component

func (p *BoundTitlePanel[T, P]) Component() templ.Component

func (*BoundTitlePanel[T, P]) Render

func (p *BoundTitlePanel[T, P]) Render() template.HTML
type BreadCrumb struct {
	Title string
	URL   string
}

type BulkAction added in v1.7.2

type BulkAction interface {
	Order() int
	Name() string
	Button() templ.Component
	HasPermission(r *http.Request, model *ModelDefinition) bool
	Execute(w http.ResponseWriter, r *http.Request, model *ModelDefinition, qs *queries.QuerySet[attrs.Definer]) (int, error)
}

type ClusterOrderableForm added in v1.7.2

type ClusterOrderableForm interface {
	FormOrder() FORM_ORDERING
}

type DeleteViewOptions

type DeleteViewOptions struct {

	// GetHandler is a function that returns a views.View for the model.
	//
	// This allows you to have full control over the view used for deleting the model.
	//
	// This does mean that any logic provided by the admin when deleting the model should be implemented by the developer.
	GetHandler func(adminSite *AdminApplication, app *AppDefinition, model *ModelDefinition, instances []attrs.Definer) views.View

	// DeleteInstance is a function that deletes the instance.
	//
	// This allows for custom logic to be executed when deleting the instance.
	DeleteInstances func(context.Context, []attrs.Definer) error
}

type DisplayPanel added in v1.7.2

type DisplayPanel struct {
	IconName string
	Title    func(ctx context.Context, count int64) string
	IsShown  func(r *http.Request) bool
	QuerySet func(r *http.Request) *queries.QuerySet[attrs.Definer]
	URL      func(r *http.Request) string
}

type FORM_ORDERING added in v1.7.2

type FORM_ORDERING int
const (
	FORM_ORDERING_PRE  FORM_ORDERING = -1
	FORM_ORDERING_NONE FORM_ORDERING = 0
	FORM_ORDERING_POST FORM_ORDERING = 1
)

type FormDefiner

type FormDefiner[T attrs.Definer] interface {
	attrs.Definer
	AdminForm(r *http.Request, app *AppDefinition, model *ModelDefinition) modelforms.ModelForm[T]
}

FormDefiner is an interface that defines a form for the admin.

AdminForm is a method that returns a modelform.ModelForm[attrs.Definer] for the admin.

This can be used to create a custom form for your models, for the admin site.

type FormPanel added in v1.7.2

type FormPanel interface {
	Panel
	Forms(r *http.Request, ctx context.Context, instance attrs.Definer) (FormSetObject, []formsets.BaseFormSetForm, error)
}

type FormSetMap added in v1.7.2

type FormSetMap map[string]FormSetObject

map[string]any ( map[string]any -> recursively, []formsets.BaseFormSetForm, formsets.BaseFormSetForm)

type FormSetObject added in v1.7.2

type FormSetObject any

This can be either map[string]any, []formsets.BaseFormSetForm or formsets.BaseFormSetForm

type FormViewOptions

type FormViewOptions struct {
	ViewOptions

	// Widgets are used to define the widgets for the fields in the form.
	//
	// This allows for custom rendering logic of the fields in the form.
	Widgets map[string]widgets.Widget

	// GetForm is a function that returns a modelform.ModelForm for the model.
	GetForm func(req *http.Request, instance attrs.Definer, fields []string) modelforms.ModelForm[attrs.Definer]

	// FormInit is a function that can be used to initialize the form.
	//
	// This may be useful for providing custom form initialization logic.
	FormInit func(instance attrs.Definer, form modelforms.ModelForm[attrs.Definer])

	// GetHandler is a function that returns a views.View for the model.
	//
	// This allows you to have full control over the view used for saving the model.
	//
	// This does mean that any logic provided by the admin when saving the model should be implemented by the developer.
	GetHandler func(adminSite *AdminApplication, app *AppDefinition, model *ModelDefinition, instance attrs.Definer) views.View

	// A custom function for saving the instance.
	//
	// This function will be called when the form is saved and allows for custom logic to be executed when saving the instance.
	SaveInstance func(context.Context, attrs.Definer) error

	// Panels are used to group fields in the form.
	//
	// This allows for a more simple, maintainable and organized form layout.
	Panels []Panel
}

Options for a model-specific form view.

func (*FormViewOptions) SetupDefaults added in v1.7.2

func (o *FormViewOptions) SetupDefaults(mdl attrs.Definer, nameOfMethod string)

type JSONDetailPanel added in v1.7.2

type JSONDetailPanel struct {
	FieldName string
	Classname string
	Ordering  func(r *http.Request, fields map[string]forms.BoundField) []string
	Labels    func(r *http.Request, fields map[string]forms.BoundField) map[string]any
	Widgets   func(r *http.Request, fields map[string]forms.BoundField) map[string]widgets.Widget
}

func (JSONDetailPanel) Bind added in v1.7.2

func (j JSONDetailPanel) Bind(r *http.Request, _ map[string]int, form forms.Form, _ context.Context, _ attrs.Definer, boundFieldsMap map[string]forms.BoundField, _ FormSetObject) BoundPanel

func (JSONDetailPanel) Class added in v1.7.2

func (j JSONDetailPanel) Class(classes string) Panel

func (JSONDetailPanel) ClassName added in v1.7.2

func (j JSONDetailPanel) ClassName() string

func (JSONDetailPanel) Comparison added in v1.7.2

func (f JSONDetailPanel) Comparison(ctx context.Context, oldInstance attrs.Definer, newInstance attrs.Definer) (compare.Comparison, error)

JSONDetailPanel does not support comparisons - it is read-only

func (JSONDetailPanel) Fields added in v1.7.2

func (j JSONDetailPanel) Fields() []string

type ListViewOptions

type ListViewOptions struct {
	ViewOptions

	// PerPage is the number of items to show per page.
	//
	// This is used for pagination in the list view.
	PerPage uint64

	// Ordering is used to define the default ordering of the list view.
	Ordering []string

	// BulkActions is a list of actions that can be performed in bulk.
	BulkActions []BulkAction

	// Columns are used to define the columns in the list view.
	//
	// This allows for custom rendering logic of the columns in the list view.
	Columns map[string]list.ListColumn[attrs.Definer]

	// Format is a map of field name to a function that formats the field value.
	//
	// I.E. map[string]func(v any) any{"Name": func(v any) any { return strings.ToUpper(v.(string)) }}
	// would uppercase the value of the "Name" field in the list view.
	Format map[string]func(v any) any

	// Filters are filters that can be used to filter the results of the ListView
	Filters []filters.FilterSpec[attrs.Definer]

	// Search are options to configure the search functionality for the list view.
	Search *SearchOptions

	// GetList returns a new StringRenderer which can render the results of the list view.
	GetList func(r *http.Request, adminSite *AdminApplication, app *AppDefinition, model *ModelDefinition, results []attrs.Definer) (list.StringRenderer, error)

	// GetHandler is a function that returns a views.View for the model.
	//
	// This allows you to have full control over the view used for listing the models.
	//
	// This does mean that any logic provided by the admin when listing the models should be implemented by the developer.
	GetHandler func(adminSite *AdminApplication, app *AppDefinition, model *ModelDefinition) views.View

	// GetQuerySet is a function that returns a queries.QuerySet to use for the list view.
	GetQuerySet func(adminSite *AdminApplication, app *AppDefinition, model *ModelDefinition) *queries.QuerySet[attrs.Definer]

	// Prefetch is used to define the prefetching options for the list view.
	Prefetch Prefetch
}

type LoginForm

type LoginForm interface {
	forms.Form
	SetRequest(req *http.Request)
	Login() error
}

type ModelDefinition

type ModelDefinition struct {
	ModelOptions
	// contains filtered or unexported fields
}

A struct which is mainly used internally (but can be used by third parties) to easily work with models in admin views.

func FindDefinition added in v1.6.7

func FindDefinition(model any, appName ...string) *ModelDefinition

func (*ModelDefinition) App added in v1.6.7

func (o *ModelDefinition) App() *AppDefinition

func (*ModelDefinition) Check added in v1.7.2

func (*ModelDefinition) EditContext added in v1.7.2

func (o *ModelDefinition) EditContext(key string, context ctx.Context)

func (*ModelDefinition) FormatColumn

func (o *ModelDefinition) FormatColumn(field string) any

func (*ModelDefinition) GetColumn

func (*ModelDefinition) GetInstance

func (m *ModelDefinition) GetInstance(ctx context.Context, identifier any) (attrs.Definer, error)

func (*ModelDefinition) GetLabel

func (o *ModelDefinition) GetLabel(opts ViewOptions, field string, default_ string) func(ctx context.Context) string

func (*ModelDefinition) GetName

func (o *ModelDefinition) GetName() string

func (*ModelDefinition) Label

func (o *ModelDefinition) Label(ctx context.Context) string

func (*ModelDefinition) ModelFields

func (m *ModelDefinition) ModelFields(opts ViewOptions, instace attrs.Definer) []attrs.Field

func (*ModelDefinition) NewInstance

func (o *ModelDefinition) NewInstance() attrs.Definer

Returns a new instance of the model.

This works the same as calling `reflect.New` on the model type.

func (*ModelDefinition) OnRegister

func (m *ModelDefinition) OnRegister(a *AdminApplication, app *AppDefinition)

func (*ModelDefinition) PluralLabel

func (o *ModelDefinition) PluralLabel(ctx context.Context) string

func (*ModelDefinition) TypeName added in v1.7.2

func (o *ModelDefinition) TypeName() string

type ModelFormPanel added in v1.7.2

type ModelFormPanel[TARGET attrs.Definer, FORM modelforms.ModelForm[TARGET]] struct {
	Form           func() FORM
	SaveInstance   func(ctx context.Context, form FORM, instance TARGET) error
	TargetType     TARGET
	MaxNum         int
	MinNum         int
	DisallowAdd    bool
	DisallowRemove bool
	Extra          int
	Classname      string
	SubClassname   string
	FieldName      string
	Panels         []Panel
}

func ModelPanel added in v1.7.2

func ModelPanel[TARGET attrs.Definer, FORM modelforms.ModelForm[TARGET]](fieldName string, targetType TARGET, options ...func(*ModelFormPanel[TARGET, FORM])) *ModelFormPanel[TARGET, FORM]

func (*ModelFormPanel[TARGET, FORM]) Bind added in v1.7.2

func (m *ModelFormPanel[TARGET, FORM]) Bind(r *http.Request, panelCount map[string]int, form forms.Form, ctx context.Context, instance attrs.Definer, boundFields map[string]forms.BoundField, formSets FormSetObject) BoundPanel

func (*ModelFormPanel[TARGET, FORM]) Class added in v1.7.2

func (m *ModelFormPanel[TARGET, FORM]) Class(classes string) Panel

func (*ModelFormPanel[TARGET, FORM]) ClassName added in v1.7.2

func (m *ModelFormPanel[TARGET, FORM]) ClassName() string

func (*ModelFormPanel[TARGET, FORM]) Comparison added in v1.7.2

func (f *ModelFormPanel[TARGET, FORM]) Comparison(ctx context.Context, oldInstance attrs.Definer, newInstance attrs.Definer) (compare.Comparison, error)

func (*ModelFormPanel[TARGET, FORM]) Fields added in v1.7.2

func (m *ModelFormPanel[TARGET, FORM]) Fields() []string

func (*ModelFormPanel[TARGET, FORM]) FormSet added in v1.7.2

func (m *ModelFormPanel[TARGET, FORM]) FormSet(r *http.Request, ctx context.Context, instance attrs.Definer) formsets.ListFormSet[modelforms.ModelForm[TARGET]]

func (*ModelFormPanel[TARGET, FORM]) Forms added in v1.7.2

func (m *ModelFormPanel[TARGET, FORM]) Forms(r *http.Request, ctx context.Context, instance attrs.Definer) (FormSetObject, []formsets.BaseFormSetForm, error)

func (*ModelFormPanel[TARGET, FORM]) GetForms added in v1.7.2

func (p *ModelFormPanel[TARGET, FORM]) GetForms(ctx context.Context, r *http.Request, source attrs.Definer, minNumForms int, targetList []TARGET) []modelforms.ModelForm[TARGET]

type ModelHandlerFunc added in v1.7.2

type ModelHandlerFunc func(func(w http.ResponseWriter, req *http.Request, adminSite *AdminApplication, app *AppDefinition, model *ModelDefinition)) mux.Handler

type ModelOptions

type ModelOptions struct {
	// Name is the name of the model.
	//
	// This is used for the model's name in the admin.
	Name string

	// MenuIcon is a function that returns the icon for the model in the admin menu.
	//
	// This should return an HTML element, I.E. "<svg>...</svg>".
	MenuIcon func(ctx context.Context) string

	// MenuOrder is the order of the model in the admin menu.
	MenuOrder int

	// MenuLabel is the label for the model in the admin menu.
	//
	// This is used for the model's label in the admin.
	MenuLabel func(ctx context.Context) string

	// DisallowList is a flag that determines if the model should be disallowed from being listed.
	//
	// This is used to prevent the model from being listed in the admin.
	DisallowList bool

	// DisallowCreate is a flag that determines if the model should be disallowed from being created.
	//
	// This is used to prevent the model from being created in the admin.
	DisallowCreate bool

	// DisallowEdit is a flag that determines if the model should be disallowed from being edited.
	//
	// This is used to prevent the model from being edited in the admin.
	DisallowEdit bool

	// DisallowDelete is a flag that determines if the model should be disallowed from being deleted.
	//
	// This is used to prevent the model from being deleted in the admin.
	DisallowDelete bool

	// AddView is the options for the add view of the model.
	//
	// This allows for custom creation logic and formatting form fields / layout.
	AddView FormViewOptions

	// EditView is the options for the edit view of the model.
	//
	// This allows for custom editing logic and formatting form fields / layout.
	EditView FormViewOptions

	// ListView is the options for the list view of the model.
	//
	// This allows for custom listing logic and formatting list columns.
	ListView ListViewOptions

	// DeleteView is the options for the delete view of the model.
	//
	// Any custom logic for deleting the model should be implemented here.
	DeleteView DeleteViewOptions

	// RegisterToAdminMenu is a flag that determines if the model should be automatically registered to the admin menu.
	RegisterToAdminMenu any

	// Labels for the fields in the model.
	//
	// This provides a simple top- level override for the labels of the fields in the model.
	//
	// Any custom labels for fields implemented in the AddView, EditView or ListView will take precedence over these labels.
	Labels map[string]func(ctx context.Context) string

	// Model is the object that the above- defined options are for.
	Model attrs.Definer
}

type MultiPanel

type MultiPanel interface {
	Panel
	Children() []Panel
}

type OutputtableTitlePanel added in v1.7.2

type OutputtableTitlePanel interface {
	Panel
	WithOutputFields(...string) Panel
}

func TitlePanel

func TitlePanel(panel Panel, classname ...string) OutputtableTitlePanel

type PageOptions

type PageOptions struct {
	Request       *http.Request
	TitleFn       func(ctx context.Context) string
	SubtitleFn    func(ctx context.Context) string
	MediaFn       func() media.Media
	BreadCrumbs   []BreadCrumb
	Actions       []Action
	HeaderActions []components.ShowableComponent
	SidePanels    *menu.SidePanels
}

func (*PageOptions) GetActions

func (p *PageOptions) GetActions() []Action

func (*PageOptions) GetBreadCrumbs

func (p *PageOptions) GetBreadCrumbs() []BreadCrumb

func (*PageOptions) GetHeaderComponents added in v1.7.2

func (p *PageOptions) GetHeaderComponents() []templ.Component

func (*PageOptions) GetSidePanels added in v1.7.2

func (p *PageOptions) GetSidePanels() *menu.SidePanels

func (*PageOptions) Media added in v1.7.0

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

func (*PageOptions) Subtitle

func (p *PageOptions) Subtitle() string

func (*PageOptions) Title

func (p *PageOptions) Title() string

type Panel

type Panel interface {
	Fields() []string
	ClassName() string
	Class(classes string) Panel
	Comparison(ctx context.Context, oldInstance attrs.Definer, newInstance attrs.Definer) (compare.Comparison, error)
	Bind(r *http.Request, panelCount map[string]int, form forms.Form, ctx context.Context, instance attrs.Definer, boundFields map[string]forms.BoundField, formset FormSetObject) BoundPanel
}

func FieldPanel

func FieldPanel(fieldname string, className ...string) Panel

func LabeledPanelGroup added in v1.7.2

func LabeledPanelGroup(label any, helpText any, panels ...Panel) Panel

func LabeledRowPanel added in v1.7.2

func LabeledRowPanel(label any, helpText any, panels ...Panel) Panel

func PanelClass added in v1.7.2

func PanelClass(className string, panel Panel) Panel

func PanelGroup added in v1.7.2

func PanelGroup(panels ...Panel) Panel

func RowPanel added in v1.7.2

func RowPanel(panels ...Panel) Panel

func TabbedPanel added in v1.7.2

func TabbedPanel(tabs ...TabPanel) Panel

type PanelBoundForm

type PanelBoundForm struct {
	forms.BoundForm
	BoundPanels []BoundPanel
	Panels      []Panel
	Context     context.Context
	Request     *http.Request
}

func NewPanelBoundForm added in v1.7.2

func NewPanelBoundForm(ctx context.Context, request *http.Request, instance attrs.Definer, form forms.Form, boundform forms.BoundForm, panels []Panel, formsets FormSetObject) *PanelBoundForm

func (*PanelBoundForm) AsP

func (b *PanelBoundForm) AsP() template.HTML

func (*PanelBoundForm) AsUL

func (b *PanelBoundForm) AsUL() template.HTML

func (*PanelBoundForm) ErrorList

func (b *PanelBoundForm) ErrorList() []error

func (*PanelBoundForm) Errors

func (b *PanelBoundForm) Errors() *orderedmap.OrderedMap[string, []error]

func (*PanelBoundForm) Fields

func (b *PanelBoundForm) Fields() []forms.BoundField

func (*PanelBoundForm) Media

func (b *PanelBoundForm) Media() media.Media

type PanelComponent added in v1.7.2

type PanelComponent struct {
	Classname      string
	PanelId        string
	Hidden         bool
	AllowPanelLink bool
	InputID        string
	Attrs          templ.Attributes
	Heading        templ.Component
	HelpText       templ.Component
	Body           templ.Component
	Errors         []error
}

func (PanelComponent) Component added in v1.7.2

func (p PanelComponent) Component() templ.Component

func (PanelComponent) Render added in v1.7.2

func (p PanelComponent) Render(ctx context.Context, w io.Writer) error

type PanelContext added in v1.7.2

type PanelContext struct {
	*ctx.HTTPRequestContext
	Panel      Panel
	BoundPanel BoundPanel
}

func NewPanelContext added in v1.7.2

func NewPanelContext(r *http.Request, panel Panel, boundPanel BoundPanel) *PanelContext

type PanelTree added in v1.7.2

type PanelTree struct {
	Parent      *PanelTree
	ContentPath []string
	Panels      []Panel
	Nodes       *orderedmap.OrderedMap[string, *PanelTree]
}

func NewPanelTree added in v1.7.2

func NewPanelTree(panels ...Panel) *PanelTree

func (*PanelTree) FindNode added in v1.7.2

func (p *PanelTree) FindNode(contentPath []string) *PanelTree

type Prefetch added in v1.7.2

type Prefetch struct {
	SelectRelated   []string
	PrefetchRelated []any
}

func (*Prefetch) Merge added in v1.7.2

func (p *Prefetch) Merge(other Prefetch)

type RegisterAdminAppPageComponentHookFunc added in v1.7.0

type RegisterAdminAppPageComponentHookFunc = func(r *http.Request, adminSite *AdminApplication, app *AppDefinition) AdminPageComponent

type RegisterAppMenuItemHookFunc added in v1.7.2

type RegisterAppMenuItemHookFunc func(r *http.Request, adminSite *AdminApplication, app *AppDefinition) []menu.MenuItem

type RegisterBreadCrumbHookFunc

type RegisterBreadCrumbHookFunc = func(r *http.Request, adminSite *AdminApplication) []BreadCrumb

type RegisterFooterMenuItemHookFunc

type RegisterFooterMenuItemHookFunc = func(r *http.Request, adminSite *AdminApplication, items components.Items[menu.MenuItem])

type RegisterHomePageActionHookFunc added in v1.7.0

type RegisterHomePageActionHookFunc = func(*http.Request, *AdminApplication, []Action) []Action

type RegisterHomePageBreadcrumbHookFunc added in v1.7.0

type RegisterHomePageBreadcrumbHookFunc = func(*http.Request, *AdminApplication, []BreadCrumb) []BreadCrumb

type RegisterHomePageComponentHookFunc added in v1.7.0

type RegisterHomePageComponentHookFunc = func(*http.Request, *AdminApplication) AdminPageComponent

type RegisterHomePageDisplayPanelHookFunc added in v1.7.2

type RegisterHomePageDisplayPanelHookFunc = func(*http.Request, *AdminApplication) []DisplayPanel

type RegisterMediaHookFunc added in v1.7.0

type RegisterMediaHookFunc = func(adminSite *AdminApplication) media.Media

type RegisterMenuItemHookFunc

type RegisterMenuItemHookFunc = func(r *http.Request, adminSite *AdminApplication, items components.Items[menu.MenuItem])

type RegisterModelsRouteHookFunc added in v1.7.2

type RegisterModelsRouteHookFunc = func(adminSite *AdminApplication, route mux.Multiplexer)

type RegisterNavActionHookFunc

type RegisterNavActionHookFunc = func(r *http.Request, adminSite *AdminApplication) []Action

type SearchField added in v1.7.2

type SearchField struct {
	Name            string
	Lookup          string // expr.LOOKUP_EXACT is the default.
	BuildExpression func(sf SearchField, value any) expr.Expression
}

func NewSearchField added in v1.7.2

func NewSearchField(nameWithlookup string) SearchField

func (SearchField) AsExpression added in v1.7.2

func (sf SearchField) AsExpression(value any) expr.Expression

func (SearchField) FieldName added in v1.7.2

func (sf SearchField) FieldName() string

func (SearchField) FilterName added in v1.7.2

func (sf SearchField) FilterName() string

type SearchMenuItem added in v1.7.2

type SearchMenuItem struct {
	Request     *http.Request
	Site        *AdminApplication
	Placeholder string
}

func (*SearchMenuItem) Component added in v1.7.2

func (s *SearchMenuItem) Component() templ.Component

func (*SearchMenuItem) IsShown added in v1.7.2

func (s *SearchMenuItem) IsShown() bool

func (*SearchMenuItem) Name added in v1.7.2

func (s *SearchMenuItem) Name() string

func (*SearchMenuItem) Order added in v1.7.2

func (s *SearchMenuItem) Order() int

type SearchOptions added in v1.7.2

type SearchOptions struct {
	PerPage        int
	Fields         []SearchField
	ListFields     []string
	GetEditLink    func(req *http.Request, id any) string
	Searchable     func(req *http.Request) bool
	QuerySet       func(req *http.Request) *queries.QuerySet[attrs.Definer]
	SearchQuerySet func(req *http.Request, qs *queries.QuerySet[attrs.Definer], query string) *queries.QuerySet[attrs.Definer]
	GetList        func(b *BoundSearchView, list []attrs.Definer, columns []list.ListColumn[attrs.Definer]) (StringRenderer, error)
}

func (*SearchOptions) CanSearch added in v1.7.2

func (so *SearchOptions) CanSearch(r *http.Request) bool

type SearchView added in v1.7.2

type SearchView struct{}

func (*SearchView) Bind added in v1.7.2

func (s *SearchView) Bind(w http.ResponseWriter, req *http.Request) (views.View, error)

func (*SearchView) Methods added in v1.7.2

func (s *SearchView) Methods() []string

func (*SearchView) ServeXXX added in v1.7.2

func (s *SearchView) ServeXXX(w http.ResponseWriter, req *http.Request)

type StringRenderer added in v1.7.2

type StringRenderer = list.StringRenderer

type TabPanel added in v1.7.2

type TabPanel struct {
	// contains filtered or unexported fields
}

func PanelTab added in v1.7.2

func PanelTab(title any, panels ...Panel) TabPanel

type ValidatorPanel added in v1.7.2

type ValidatorPanel interface {
	Panel
	Validate(r *http.Request, ctx context.Context, form forms.Form, data map[string]any) []error
}

type ViewOptions

type ViewOptions struct {
	// Fields to include for the model in the view
	Fields []string

	// Fields to exclude from the model in the view
	Exclude []string

	// Labels for the fields in the view
	//
	// This is a map of field name to a function that returns the label for the field.
	//
	// Allowing for custom labels for fields in the view.
	Labels map[string]func(ctx context.Context) string
}

Basic options for a model-based view which includes a form.

type WidgetPanelComponent added in v1.7.2

type WidgetPanelComponent struct {
	BoundField forms.BoundField
}

func (WidgetPanelComponent) Render added in v1.7.2

type WrappedModelDefinition added in v1.7.2

type WrappedModelDefinition struct {
	Wrapped *ModelDefinition
	Context context.Context
}

func (*WrappedModelDefinition) AllowBulkActions added in v1.7.2

func (o *WrappedModelDefinition) AllowBulkActions() bool

func (*WrappedModelDefinition) BulkActions added in v1.7.2

func (o *WrappedModelDefinition) BulkActions() []BulkAction

func (*WrappedModelDefinition) DisallowCreate added in v1.7.2

func (o *WrappedModelDefinition) DisallowCreate() bool

func (*WrappedModelDefinition) DisallowDelete added in v1.7.2

func (o *WrappedModelDefinition) DisallowDelete() bool

func (*WrappedModelDefinition) DisallowEdit added in v1.7.2

func (o *WrappedModelDefinition) DisallowEdit() bool

func (*WrappedModelDefinition) DisallowList added in v1.7.2

func (o *WrappedModelDefinition) DisallowList() bool

func (*WrappedModelDefinition) GetName added in v1.7.2

func (o *WrappedModelDefinition) GetName() string

func (*WrappedModelDefinition) Label added in v1.7.2

func (o *WrappedModelDefinition) Label() string

func (*WrappedModelDefinition) MenuIcon added in v1.7.2

func (o *WrappedModelDefinition) MenuIcon() string

func (*WrappedModelDefinition) MenuLabel added in v1.7.2

func (o *WrappedModelDefinition) MenuLabel() string

func (*WrappedModelDefinition) NewInstance added in v1.7.2

func (o *WrappedModelDefinition) NewInstance() attrs.Definer

func (*WrappedModelDefinition) PluralLabel added in v1.7.2

func (o *WrappedModelDefinition) PluralLabel() string

func (*WrappedModelDefinition) TypeName added in v1.7.2

func (o *WrappedModelDefinition) TypeName() string

Directories

Path Synopsis
templ: version: v0.3.1020
templ: version: v0.3.1020
templ: version: v0.3.1020
templ: version: v0.3.1020
columns
templ: version: v0.3.1020
templ: version: v0.3.1020
menu
templ: version: v0.3.1020
templ: version: v0.3.1020

Jump to

Keyboard shortcuts

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