From fda4b1106e4fccfd715eb35421d6814719cbf42c Mon Sep 17 00:00:00 2001 From: Unknwon Date: Fri, 7 Apr 2017 00:49:30 -0400 Subject: user/setting: simplify code --- pkg/context/context.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'pkg/context/context.go') diff --git a/pkg/context/context.go b/pkg/context/context.go index fa4ed16e..1457deec 100644 --- a/pkg/context/context.go +++ b/pkg/context/context.go @@ -41,6 +41,23 @@ type Context struct { Org *Organization } +// Title sets "Title" field in template data. +func (c *Context) Title(locale string) { + c.Data["Title"] = c.Tr(locale) +} + +// PageIs sets "PageIsxxx" field in template data. +func (c *Context) PageIs(name string) { + c.Data["PageIs"+name] = true +} + +// FormErr sets "Err_xxx" field in template data. +func (c *Context) FormErr(names ...string) { + for i := range names { + c.Data["Err_"+names[i]] = true + } +} + // UserID returns ID of current logged in user. // It returns 0 if visitor is anonymous. func (c *Context) UserID() int64 { @@ -96,6 +113,12 @@ func (c *Context) JSONSuccess(data interface{}) { c.JSON(http.StatusOK, data) } +// SubURLRedirect responses redirection wtih given location and status. +// It prepends setting.AppSubURL to the location string. +func (c *Context) SubURLRedirect(location string, status ...int) { + c.Redirect(setting.AppSubURL + location) +} + // RenderWithErr used for page has form validation but need to prompt error to users. func (ctx *Context) RenderWithErr(msg, tpl string, f interface{}) { if f != nil { -- cgit v1.2.3