diff options
author | Unknwon <u@gogs.io> | 2017-04-07 00:49:30 -0400 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2017-04-07 00:49:30 -0400 |
commit | fda4b1106e4fccfd715eb35421d6814719cbf42c (patch) | |
tree | 10393869b50f210b6337ce8b770427b44ad40c95 /pkg/context/context.go | |
parent | ac43eab51f9ac0d4c4bcc6db2bbc9ce3dbb34b7b (diff) |
user/setting: simplify code
Diffstat (limited to 'pkg/context/context.go')
-rw-r--r-- | pkg/context/context.go | 23 |
1 files changed, 23 insertions, 0 deletions
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 { |