本文整理汇总了Golang中github.com/qor/qor/utils.PatchURL函数的典型用法代码示例。如果您正苦于以下问题:Golang PatchURL函数的具体用法?Golang PatchURL怎么用?Golang PatchURL使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PatchURL函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: patchCurrentURL
// PatchCurrentURL is a convinent wrapper for qor/utils.PatchURL
func (context *Context) patchCurrentURL(params ...interface{}) (patchedURL string, err error) {
return utils.PatchURL(context.Request.URL.String(), params...)
}
开发者ID:kennylixi,项目名称:qor,代码行数:4,代码来源:func_map.go
示例2: patchURL
// PatchURL is a convinent wrapper for qor/utils.PatchURL
func (context *Context) patchURL(url string, params ...interface{}) (patchedURL string, err error) {
return utils.PatchURL(url, params...)
}
开发者ID:kennylixi,项目名称:qor,代码行数:4,代码来源:func_map.go
示例3: InjectQorAdmin
func (l *Locale) InjectQorAdmin(res *admin.Resource) {
Admin := res.GetAdmin()
res.UseTheme("l10n")
if res.Config.Permission == nil {
res.Config.Permission = roles.NewPermission()
}
res.Config.Permission.Allow(roles.CRUD, "locale_admin").Allow(roles.Read, "locale_reader")
if res.GetMeta("Localization") == nil {
res.Meta(&admin.Meta{Name: "Localization", Valuer: func(value interface{}, ctx *qor.Context) interface{} {
db := ctx.GetDB()
context := Admin.NewContext(ctx.Writer, ctx.Request)
var languageCodes []string
scope := db.NewScope(value)
db.New().Set("l10n:mode", "unscoped").Model(value).Where(fmt.Sprintf("%v = ?", scope.PrimaryKey()), scope.PrimaryKeyValue()).Pluck("language_code", &languageCodes)
var results string
availableLocales := getAvailableLocales(ctx.Request, ctx.CurrentUser)
primaryKey := context.GetDB().NewScope(value).PrimaryKeyValue()
OUT:
for _, locale := range availableLocales {
url, _ := utils.PatchURL(path.Join(ctx.Request.URL.Path, fmt.Sprintf("%v", primaryKey)), "locale", locale)
for _, localized := range languageCodes {
if locale == localized {
results += fmt.Sprintf("<a class='qor-list-label active' href='%s'>%s</a> ", url, context.T(locale))
continue OUT
}
}
results += fmt.Sprintf("<a class='qor-list-label' href='%s'>%s</a> ", url, context.T(locale))
}
return template.HTML(results)
}})
attrs := res.IndexAttrs()
var hasLocalization bool
for _, attr := range attrs {
if attr == "Localization" {
hasLocalization = true
break
}
}
if hasLocalization {
res.IndexAttrs(append(res.IndexAttrs(), "-LanguageCode")...)
} else {
res.IndexAttrs(append(res.IndexAttrs(), "-LanguageCode", "Localization")...)
}
res.ShowAttrs(append(res.ShowAttrs(), "-LanguageCode", "-Localization")...)
res.EditAttrs(append(res.EditAttrs(), "-LanguageCode", "-Localization")...)
res.NewAttrs(append(res.NewAttrs(), "-LanguageCode", "-Localization")...)
}
// Set meta permissions
for _, field := range Admin.Config.DB.NewScope(res.Value).Fields() {
if isSyncField(field.StructField) {
if meta := res.GetMeta(field.Name); meta != nil {
permission := meta.Permission
if permission == nil {
permission = roles.Allow(roles.CRUD, "global_admin").Allow(roles.Read, "locale_reader")
} else {
permission = permission.Allow(roles.CRUD, "global_admin").Allow(roles.Read, "locale_reader")
}
meta.Permission = permission
} else {
res.Meta(&admin.Meta{Name: field.Name, Permission: roles.Allow(roles.CRUD, "global_admin").Allow(roles.Read, "locale_reader")})
}
}
}
// Roles
role := res.Config.Permission.Role
if _, ok := role.Get("locale_admin"); !ok {
role.Register("locale_admin", func(req *http.Request, currentUser qor.CurrentUser) bool {
currentLocale := getLocaleFromContext(&qor.Context{Request: req})
for _, locale := range getEditableLocales(req, currentUser) {
if locale == currentLocale {
return true
}
}
return false
})
}
if _, ok := role.Get("global_admin"); !ok {
role.Register("global_admin", func(req *http.Request, currentUser qor.CurrentUser) bool {
return getLocaleFromContext(&qor.Context{Request: req}) == Global
})
}
if _, ok := role.Get("locale_reader"); !ok {
role.Register("locale_reader", func(req *http.Request, currentUser qor.CurrentUser) bool {
currentLocale := getLocaleFromContext(&qor.Context{Request: req})
for _, locale := range getAvailableLocales(req, currentUser) {
if locale == currentLocale {
return true
}
}
//.........这里部分代码省略.........
开发者ID:nilslice,项目名称:qor,代码行数:101,代码来源:l10n.go
注:本文中的github.com/qor/qor/utils.PatchURL函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论