本文整理匯總了Golang中github.com/qor/admin.Context.GetDB方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.GetDB方法的具體用法?Golang Context.GetDB怎麽用?Golang Context.GetDB使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/qor/admin.Context
的用法示例。
在下文中一共展示了Context.GetDB方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: PublishOrDiscard
func (pc *publishController) PublishOrDiscard(context *admin.Context) {
var request = context.Request
var ids = request.Form["checked_ids[]"]
if scheduler := pc.Publish.WorkerScheduler; scheduler != nil {
jobResource := scheduler.JobResource
result := jobResource.NewStruct().(worker.QorJobInterface)
if request.Form.Get("publish_type") == "discard" {
result.SetJob(scheduler.GetRegisteredJob("Discard"))
} else {
result.SetJob(scheduler.GetRegisteredJob("Publish"))
}
workerArgument := &QorWorkerArgument{IDs: ids}
if t, err := utils.ParseTime(request.Form.Get("scheduled_time"), context.Context); err == nil {
workerArgument.ScheduleTime = &t
}
result.SetSerializableArgumentValue(workerArgument)
jobResource.CallSave(result, context.Context)
scheduler.AddJob(result)
http.Redirect(context.Writer, context.Request, context.URLFor(jobResource), http.StatusFound)
} else {
records := pc.searchWithPublishIDs(context.GetDB().Set(publishDraftMode, true), context.Admin, ids)
if request.Form.Get("publish_type") == "publish" {
pc.Publish.Publish(records...)
} else if request.Form.Get("publish_type") == "discard" {
pc.Publish.Discard(records...)
}
http.Redirect(context.Writer, context.Request, context.Request.RequestURI, http.StatusFound)
}
}
示例2: Preview
func (pc *publishController) Preview(context *admin.Context) {
type resource struct {
*admin.Resource
Value interface{}
}
var drafts = []resource{}
draftDB := context.GetDB().Set(publishDraftMode, true).Unscoped()
for _, res := range context.Admin.GetResources() {
if visibleInterface, ok := res.Value.(visiblePublishResourceInterface); ok {
if !visibleInterface.VisiblePublishResource(context.Context) {
continue
}
} else if res.Config.Invisible {
continue
}
if res.HasPermission(PublishPermission, context.Context) {
results := res.NewSlice()
if IsPublishableModel(res.Value) || IsPublishEvent(res.Value) {
if pc.SearchHandler(draftDB.Where("publish_status = ?", DIRTY), context.Context).Find(results).RowsAffected > 0 {
drafts = append(drafts, resource{
Resource: res,
Value: results,
})
}
}
}
}
context.Execute("publish_drafts", drafts)
}
示例3: getPrimaryKey
func getPrimaryKey(context *admin.Context, record interface{}) string {
db := context.GetDB()
var primaryValues []string
for _, field := range db.NewScope(record).PrimaryFields() {
primaryValues = append(primaryValues, fmt.Sprint(field.Field.Interface()))
}
return strings.Join(primaryValues, "::")
}
示例4: Diff
func (pc *publishController) Diff(context *admin.Context) {
var (
resourceID = context.Request.URL.Query().Get(":publish_unique_key")
params = strings.Split(resourceID, "__") // name__primary_keys
res = context.Admin.GetResource(params[0])
)
draft := res.NewStruct()
pc.search(context.GetDB().Set(publishDraftMode, true), res, [][]string{params[1:]}).First(draft)
production := res.NewStruct()
pc.search(context.GetDB().Set(publishDraftMode, false), res, [][]string{params[1:]}).First(production)
results := map[string]interface{}{"Production": production, "Draft": draft, "Resource": res}
fmt.Fprintf(context.Writer, string(context.Render("publish_diff", results)))
}
示例5: prepareGetActivitiesDB
func prepareGetActivitiesDB(context *admin.Context, types ...string) *gorm.DB {
db := context.GetDB().Order("id asc").Where("resource_id = ? AND resource_type = ?", context.Resource.GetPrimaryValue(context.Request), context.Resource.ToParam())
var inTypes, notInTypes []string
for _, t := range types {
if strings.HasPrefix(t, "-") {
notInTypes = append(notInTypes, strings.TrimPrefix(t, "-"))
} else {
inTypes = append(inTypes, t)
}
}
if len(inTypes) > 0 {
db = db.Where("type IN (?)", inTypes)
}
if len(notInTypes) > 0 {
db = db.Where("type NOT IN (?)", notInTypes)
}
return db
}