Documentation ¶
Overview ¶
templ: version: v0.2.707
templ: version: v0.2.707
Index ¶
- Constants
- Variables
- func GetAdminForm(instance attrs.Definer, opts FormViewOptions, app *AppDefinition, ...) modelforms.ModelForm[attrs.Definer]
- func LogoutHandler(w http.ResponseWriter, req *http.Request)
- func NewAppConfig() django.AppConfig
- func NewContext(request *http.Request, site *AdminApplication, context ctx.Context) *adminContext
- func RegisterMedia(fn RegisterScriptHookFunc)
- func RequiredMiddleware(next mux.Handler) mux.Handler
- type Action
- type AdminApplication
- func (a *AdminApplication) AuthLoginForm(r *http.Request, formOpts ...func(forms.Form)) LoginForm
- func (a *AdminApplication) AuthLogout(r *http.Request) error
- func (a *AdminApplication) IsReady() bool
- func (a *AdminApplication) RegisterApp(name string, appOptions AppOptions, opts ...ModelOptions) *AppDefinition
- type AdminForm
- func (a *AdminForm[T]) AddError(name string, errorList ...error)
- func (a *AdminForm[T]) AddField(name string, field fields.Field)
- func (a *AdminForm[T]) AddFormError(errorList ...error)
- func (a *AdminForm[T]) AddWidget(name string, widget widgets.Widget)
- func (a *AdminForm[T]) AsP() template.HTML
- func (a *AdminForm[T]) AsUL() template.HTML
- func (a *AdminForm[T]) BoundErrors() *orderedmap.OrderedMap[string, []error]
- func (a *AdminForm[T]) BoundFields() *orderedmap.OrderedMap[string, forms.BoundField]
- func (a *AdminForm[T]) BoundForm() forms.BoundForm
- func (a *AdminForm[T]) CleanedData() map[string]interface{}
- func (a *AdminForm[T]) DeleteField(name string) bool
- func (a *AdminForm[T]) EditContext(key string, context ctx.Context)
- func (a *AdminForm[T]) ErrorList() []error
- func (a *AdminForm[T]) Field(name string) (fields.Field, bool)
- func (a *AdminForm[T]) FieldOrder() []string
- func (a *AdminForm[T]) Fields() []fields.Field
- func (a *AdminForm[T]) FullClean()
- func (a *AdminForm[T]) HasChanged() bool
- func (a *AdminForm[T]) InitialData() map[string]interface{}
- func (a *AdminForm[T]) IsValid() bool
- func (a *AdminForm[T]) Media() media.Media
- func (a *AdminForm[T]) OnFinalize(f ...func(forms.Form))
- func (a *AdminForm[T]) OnInvalid(f ...func(forms.Form))
- func (a *AdminForm[T]) OnValid(f ...func(forms.Form))
- func (a *AdminForm[T]) Ordering(o []string)
- func (a *AdminForm[T]) Prefix() string
- func (a *AdminForm[T]) SetInitial(initial map[string]interface{})
- func (a *AdminForm[T]) SetPrefix(prefix string)
- func (a *AdminForm[T]) SetValidators(validators ...func(forms.Form) []error)
- func (a *AdminForm[T]) Validate()
- func (a *AdminForm[T]) Widget(name string) (widgets.Widget, bool)
- func (a *AdminForm[T]) Widgets() []widgets.Widget
- func (a *AdminForm[T]) WithData(data url.Values, files map[string][]filesystem.FileHeader, r *http.Request) forms.Form
- type AdminModelForm
- func (a *AdminModelForm[T]) Context() context.Context
- func (a *AdminModelForm[T]) Instance() attrs.Definer
- func (a *AdminModelForm[T]) Load()
- func (a *AdminModelForm[T]) Save() error
- func (a *AdminModelForm[T]) SetExclude(exclude ...string)
- func (a *AdminModelForm[T]) SetFields(fields ...string)
- func (a *AdminModelForm[T]) SetInstance(model attrs.Definer)
- func (a *AdminModelForm[T]) WithContext(ctx context.Context)
- type AdminModelHookFunc
- type AppDefinition
- type AppOptions
- type AuthConfig
- type BoundFormPanel
- type BoundMultiPanel
- type BoundPanel
- type BoundTitlePanel
- type BreadCrumb
- type DeleteViewOptions
- type FormDefiner
- type FormViewOptions
- type ListAction
- type ListActionsColumn
- type ListViewOptions
- type LoginForm
- type ModelDefinition
- func (o *ModelDefinition) App() *AppDefinition
- func (o *ModelDefinition) FormatColumn(field string) any
- func (o *ModelDefinition) GetColumn(opts ListViewOptions, field string) list.ListColumn[attrs.Definer]
- func (m *ModelDefinition) GetInstance(identifier any) (attrs.Definer, error)
- func (o *ModelDefinition) GetLabel(opts ViewOptions, field string, default_ string) func() string
- func (m *ModelDefinition) GetListInstances(amount, offset uint) ([]attrs.Definer, error)
- func (o *ModelDefinition) GetName() string
- func (o *ModelDefinition) Label() string
- func (m *ModelDefinition) ModelFields(opts ViewOptions, instace attrs.Definer) []attrs.Field
- func (o *ModelDefinition) NewInstance() attrs.Definer
- func (m *ModelDefinition) OnRegister(a *AdminApplication, app *AppDefinition)
- func (o *ModelDefinition) PluralLabel() string
- type ModelOptions
- type PageOptions
- type Panel
- type PanelBoundForm
- func (b *PanelBoundForm) AsP() template.HTML
- func (b *PanelBoundForm) AsUL() template.HTML
- func (b *PanelBoundForm) ErrorList() []error
- func (b *PanelBoundForm) Errors() *orderedmap.OrderedMap[string, []error]
- func (b *PanelBoundForm) Fields() []forms.BoundField
- func (b *PanelBoundForm) Media() media.Media
- type RegisterBreadCrumbHookFunc
- type RegisterFooterMenuItemHookFunc
- type RegisterMenuItemHookFunc
- type RegisterNavActionHookFunc
- type RegisterScriptHookFunc
- type ViewOptions
Constants ¶
View Source
const ( RegisterMenuItemHook = "admin:register_menu_item" RegisterGlobalMedia = "admin:register_global_media" AdminModelHookAdd = "admin:model:add" AdminModelHookEdit = "admin:model:edit" AdminModelHookDelete = "admin:model:delete" )
View Source
const BASE_KEY = "admin"
Variables ¶
View Source
var ( RegisterApp = AdminSite.RegisterApp IsReady = AdminSite.IsReady ConfigureAuth = AdminSite.configureAuth )
View Source
var AppHandler = func(w http.ResponseWriter, r *http.Request, adminSite *AdminApplication, app *AppDefinition) { 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() i++ } var context = NewContext( r, adminSite, nil, ) context.SetPage(PageOptions{ TitleFn: app.Label, SubtitleFn: app.Description, }) context.Set("app", app) context.Set("models", modelNames) var err = tpl.FRender(w, context, BASE_KEY, "admin/views/apps/index.tmpl") except.AssertNil(err, 500, err) }
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) context.SetPage(PageOptions{ TitleFn: trans.S("Home"), SubtitleFn: trans.S("Welcome to the Django Admin"), }) return context, nil }, }
View Source
var IS_GITHUB_ACTIONS = true
For now only used to make sure tests pass on github actions This will be removed when the package is properly developed and tested This makes sure that the authentication check is enabled only when running on github actions
View Source
var LoginHandler = &views.FormView[*AdminForm[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) *AdminForm[LoginForm] { var loginForm = AdminSite.AuthLoginForm( req, ) return &AdminForm[LoginForm]{ Form: loginForm, } }, ValidFn: func(req *http.Request, form *AdminForm[LoginForm]) error { form.Form.SetRequest(req) return form.Form.Login() }, SuccessFn: func(w http.ResponseWriter, req *http.Request, form *AdminForm[LoginForm]) { var nextURL = req.URL.Query().Get("next") if nextURL == "" { nextURL = django.Reverse("admin:home") } http.Redirect(w, req, nextURL, http.StatusSeeOther) }, CheckPermissions: func(w http.ResponseWriter, req *http.Request) error { var user = authentication.Retrieve(req) if user != nil && user.IsAuthenticated() { return errs.Error("Already authenticated") } return nil }, FailsPermissions: func(w http.ResponseWriter, req *http.Request, err error) { var redirectURL = django.Reverse("admin:home") http.Redirect(w, req, redirectURL, 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") { autherrors.Fail( http.StatusForbidden, "Permission denied", ) 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) views.Invoke(addView, w, r) }
View Source
var ModelDeleteHandler = func(w http.ResponseWriter, r *http.Request, adminSite *AdminApplication, app *AppDefinition, model *ModelDefinition, instance attrs.Definer) { if !permissions.HasObjectPermission(r, instance, "admin:delete") { autherrors.Fail( http.StatusForbidden, "Permission denied", ) return } if model.DeleteView.GetHandler != nil { var err = views.Invoke(model.DeleteView.GetHandler(adminSite, app, model, instance), w, r) except.AssertNil(err, 500, err) return } var err error var context = NewContext(r, adminSite, nil) if r.Method == http.MethodPost { var hooks = goldcrest.Get[AdminModelHookFunc]( AdminModelHookDelete, ) for _, hook := range hooks { hook(r, AdminSite, model, instance) } if deleter, ok := instance.(models.Deleter); ok { err = deleter.Delete(r.Context()) } if err != nil { context.Set("error", err) } var listViewURL = django.Reverse("admin:apps:model", app.Name, model.Name) http.Redirect(w, r, listViewURL, http.StatusSeeOther) return } var definitions = instance.FieldDefs() var primaryField = definitions.Primary() context.Set("app", app) context.Set("model", model) context.Set("instance", instance) context.Set("primaryField", primaryField) err = tpl.FRender(w, context, BASE_KEY, "admin/views/models/delete.tmpl") 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") { autherrors.Fail( http.StatusForbidden, "Permission denied", ) 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) 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") { autherrors.Fail( http.StatusForbidden, "Permission denied", ) return } if model.ListView.GetHandler != nil { var err = views.Invoke(model.ListView.GetHandler(adminSite, app, model), w, r) except.AssertNil(err, 500, err) return } var columns = make([]list.ListColumn[attrs.Definer], len(model.ListView.Fields)) for i, field := range model.ListView.Fields { columns[i] = model.GetColumn(model.ListView, field) } var amount = model.ListView.PerPage if amount == 0 { amount = 25 } var view = &list.View[attrs.Definer]{ ListColumns: columns, DefaultAmount: amount, BaseView: views.BaseView{ AllowedMethods: []string{http.MethodGet, http.MethodPost}, BaseTemplateKey: BASE_KEY, TemplateName: "admin/views/models/list.tmpl", GetContextFn: func(req *http.Request) (ctx.Context, error) { var context = NewContext(req, adminSite, nil) context.Set("app", app) context.Set("model", model) return context, nil }, }, GetListFn: func(amount, offset uint) ([]attrs.Definer, error) { return model.GetListInstances(amount, offset) }, TitleFieldColumn: func(lc list.ListColumn[attrs.Definer]) list.ListColumn[attrs.Definer] { return list.TitleFieldColumn(lc, func(defs attrs.Definitions, instance attrs.Definer) string { var primaryField = defs.Primary() if primaryField == nil { return "" } return django.Reverse("admin:apps:model:edit", app.Name, model.Name, primaryField.GetValue()) }) }, } views.Invoke(view, w, r) }
Functions ¶
func GetAdminForm ¶
func GetAdminForm(instance attrs.Definer, opts FormViewOptions, app *AppDefinition, model *ModelDefinition, r *http.Request) modelforms.ModelForm[attrs.Definer]
func LogoutHandler ¶
func LogoutHandler(w http.ResponseWriter, req *http.Request)
func NewAppConfig ¶
func NewContext ¶
func NewContext(request *http.Request, site *AdminApplication, context ctx.Context) *adminContext
func RegisterMedia ¶
func RegisterMedia(fn RegisterScriptHookFunc)
Types ¶
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/", nil, "admin", ), }
func (*AdminApplication) AuthLoginForm ¶
func (*AdminApplication) AuthLogout ¶
func (a *AdminApplication) AuthLogout(r *http.Request) error
func (*AdminApplication) IsReady ¶
func (a *AdminApplication) IsReady() bool
func (*AdminApplication) RegisterApp ¶
func (a *AdminApplication) RegisterApp(name string, appOptions AppOptions, opts ...ModelOptions) *AppDefinition
type AdminForm ¶
func (*AdminForm[T]) AddFormError ¶
func (*AdminForm[T]) BoundErrors ¶
func (*AdminForm[T]) BoundFields ¶
func (a *AdminForm[T]) BoundFields() *orderedmap.OrderedMap[string, forms.BoundField]
func (*AdminForm[T]) CleanedData ¶
func (*AdminForm[T]) DeleteField ¶
func (*AdminForm[T]) EditContext ¶
func (*AdminForm[T]) FieldOrder ¶
func (*AdminForm[T]) HasChanged ¶
func (*AdminForm[T]) InitialData ¶
func (*AdminForm[T]) OnFinalize ¶
func (*AdminForm[T]) SetInitial ¶
func (*AdminForm[T]) SetValidators ¶
type AdminModelForm ¶
type AdminModelForm[T modelforms.ModelForm[attrs.Definer]] struct { *AdminForm[T] }
func NewAdminModelForm ¶
func NewAdminModelForm[T modelforms.ModelForm[attrs.Definer]](form T, panels ...Panel) *AdminModelForm[T]
func (*AdminModelForm[T]) Context ¶
func (a *AdminModelForm[T]) Context() context.Context
func (*AdminModelForm[T]) Instance ¶
func (a *AdminModelForm[T]) Instance() attrs.Definer
func (*AdminModelForm[T]) Load ¶
func (a *AdminModelForm[T]) Load()
func (*AdminModelForm[T]) Save ¶
func (a *AdminModelForm[T]) Save() error
func (*AdminModelForm[T]) SetExclude ¶
func (a *AdminModelForm[T]) SetExclude(exclude ...string)
func (*AdminModelForm[T]) SetFields ¶
func (a *AdminModelForm[T]) SetFields(fields ...string)
func (*AdminModelForm[T]) SetInstance ¶
func (a *AdminModelForm[T]) SetInstance(model attrs.Definer)
func (*AdminModelForm[T]) WithContext ¶
func (a *AdminModelForm[T]) WithContext(ctx context.Context)
type AdminModelHookFunc ¶ added in v1.6.8
type AdminModelHookFunc func(r *http.Request, adminSite *AdminApplication, model *ModelDefinition, instance attrs.Definer)
type AppDefinition ¶
type AppDefinition struct { Name string Options AppOptions Models *orderedmap.OrderedMap[ string, *ModelDefinition, ] Routing func(django.Mux) }
func (*AppDefinition) Description ¶
func (a *AppDefinition) Description() string
func (*AppDefinition) Label ¶
func (a *AppDefinition) Label() 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 bool // Applabel must return a human readable label for the app. AppLabel func() string // AppDescription must return a human readable description of this app. AppDescription func() 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() string // 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 BoundFormPanel ¶
type BoundFormPanel[T forms.Form, P Panel] struct { forms.BoundField Context context.Context 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 BoundMultiPanel ¶
type BoundMultiPanel[T forms.Form] struct { LabelFn func() string Context context.Context Panels []BoundPanel Form T }
func (*BoundMultiPanel[T]) Component ¶
func (p *BoundMultiPanel[T]) Component() templ.Component
func (*BoundMultiPanel[T]) Render ¶
func (p *BoundMultiPanel[T]) Render() template.HTML
type BoundTitlePanel ¶
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 ¶
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, instance attrs.Definer) views.View }
type FormDefiner ¶
type FormDefiner interface { attrs.Definer AdminForm(r *http.Request, app *AppDefinition, model *ModelDefinition) modelforms.ModelForm[attrs.Definer] }
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.
type ListAction ¶
type ListAction[T attrs.Definer] struct { Classname string Show func(defs attrs.Definitions, row T) bool Text func(defs attrs.Definitions, row T) string URL func(defs attrs.Definitions, row T) string }
func (*ListAction[T]) Component ¶
func (l *ListAction[T]) Component(defs attrs.Definitions, row T) templ.Component
func (*ListAction[T]) IsShown ¶
func (l *ListAction[T]) IsShown(defs attrs.Definitions, row T) bool
type ListActionsColumn ¶
type ListActionsColumn[T attrs.Definer] struct { Heading func() string Actions []*ListAction[T] }
func (*ListActionsColumn[T]) Component ¶
func (l *ListActionsColumn[T]) Component(defs attrs.Definitions, row T) templ.Component
func (*ListActionsColumn[T]) Header ¶
func (l *ListActionsColumn[T]) Header() templ.Component
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 // 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 // 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 }
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 attrs.Definer) *ModelDefinition
func (*ModelDefinition) App ¶ added in v1.6.7
func (o *ModelDefinition) App() *AppDefinition
func (*ModelDefinition) FormatColumn ¶
func (o *ModelDefinition) FormatColumn(field string) any
func (*ModelDefinition) GetColumn ¶
func (o *ModelDefinition) GetColumn(opts ListViewOptions, field string) list.ListColumn[attrs.Definer]
func (*ModelDefinition) GetInstance ¶
func (m *ModelDefinition) GetInstance(identifier any) (attrs.Definer, error)
func (*ModelDefinition) GetLabel ¶
func (o *ModelDefinition) GetLabel(opts ViewOptions, field string, default_ string) func() string
func (*ModelDefinition) GetListInstances ¶
func (m *ModelDefinition) GetListInstances(amount, offset uint) ([]attrs.Definer, error)
func (*ModelDefinition) GetName ¶
func (o *ModelDefinition) GetName() string
func (*ModelDefinition) Label ¶
func (o *ModelDefinition) Label() 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() string
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 // 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 bool // 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() string // Model is the object that the above- defined options are for. Model attrs.Definer }
func (*ModelOptions) GetName ¶
func (o *ModelOptions) GetName() string
type PageOptions ¶
type PageOptions struct { Request *http.Request TitleFn func() string SubtitleFn func() string MediaFn func() media.Media BreadCrumbs []BreadCrumb Actions []Action }
func (*PageOptions) GetActions ¶
func (p *PageOptions) GetActions() []Action
func (*PageOptions) GetBreadCrumbs ¶
func (p *PageOptions) GetBreadCrumbs() []BreadCrumb
func (*PageOptions) Subtitle ¶
func (p *PageOptions) Subtitle() string
func (*PageOptions) Title ¶
func (p *PageOptions) Title() string
type Panel ¶
type Panel interface { Fields() []string Bind(form forms.Form, ctx context.Context, boundFields map[string]forms.BoundField) BoundPanel }
func FieldPanel ¶
func MultiPanel ¶
func TitlePanel ¶
type PanelBoundForm ¶
type PanelBoundForm struct { forms.BoundForm BoundPanels []BoundPanel Panels []Panel Context context.Context }
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 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 RegisterMenuItemHookFunc ¶
type RegisterMenuItemHookFunc func(adminSite *AdminApplication, items components.Items[menu.MenuItem])
type RegisterNavActionHookFunc ¶
type RegisterNavActionHookFunc func(r *http.Request, adminSite *AdminApplication) []Action
type RegisterScriptHookFunc ¶
type RegisterScriptHookFunc func(adminSite *AdminApplication) media.Media
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() string }
Basic options for a model-based view which includes a form.
Source Files ¶
Click to show internal directories.
Click to hide internal directories.