本文整理汇总了Golang中models.User.DisplayName方法的典型用法代码示例。如果您正苦于以下问题:Golang User.DisplayName方法的具体用法?Golang User.DisplayName怎么用?Golang User.DisplayName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.User
的用法示例。
在下文中一共展示了User.DisplayName方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: BuildCommentData
// Builds a CommentData object from a models.Comment object with the proper fields
func BuildCommentData(ctx appengine.Context, comObj models.Comment, commentKey *datastore.Key) (models.CommentData, error) {
var author models.User
var sim models.Simulation
var com models.CommentData
authorKey := datastore.NewKey(ctx, "User", comObj.AuthorKeyName, 0, nil)
err := datastore.Get(ctx, authorKey, &author)
if err != nil {
return com, err
}
var profileImageSrc string
if len(string(author.ImageBlobKey)) > 0 {
profileImageSrc = "/api/img/" + string(author.ImageBlobKey)
}
err = datastore.Get(ctx, commentKey.Parent(), &sim)
if err != nil {
return com, err
}
// Get all of the display names for each simulation author
if author.DisplayName == "" {
author.DisplayName = "Anonymous"
}
com.KeyName = comObj.KeyName
com.Contents = comObj.Contents
com.CreationDate = comObj.CreationDate
com.PrettyCreationDate = comObj.CreationDate.Format("January _2, 2006")
com.AuthorName = author.DisplayName
com.AuthorID = author.KeyName
com.AuthorImageSrcUrl = profileImageSrc
com.SimulationName = sim.Name
com.SimulationID = sim.KeyName
com.SimulationType = sim.Type
return com, nil
}
示例2: BuildSimulationData
// Builds a SimulationData object from a models.Simulation object with the proper fields
func BuildSimulationData(ctx appengine.Context, simObj models.Simulation, simKey *datastore.Key) (models.SimulationData, error) {
var author models.User
var sim models.SimulationData
authorKey := datastore.NewKey(ctx, "User", simObj.AuthorKeyName, 0, nil)
err := datastore.Get(ctx, authorKey, &author)
if err != nil {
return sim, err
}
q := datastore.NewQuery("Rating").Ancestor(simKey)
simFaves, err := q.Count(ctx)
if err != nil {
return sim, err
}
// Get the display name for the simulation author
if author.DisplayName == "" {
author.DisplayName = "Anonymous"
}
sim.KeyName = simObj.KeyName
sim.Name = simObj.Name
sim.Simulator = simObj.Simulator
sim.Type = simObj.Type
sim.Description = simObj.Description
sim.CreationDate = simObj.CreationDate
sim.UpdatedDate = simObj.UpdatedDate
sim.ImageSrcUrl = "/api/img/" + string(simObj.ImageBlobKey)
sim.IsPrivate = simObj.IsPrivate
sim.AuthorName = author.DisplayName
sim.AuthorID = author.KeyName
sim.RatingTotal = simFaves
return sim, nil
}
示例3: ProfileHandler
//.........这里部分代码省略.........
// Only want to generate an image upload user if it is the user's profile page
var imageUploadUrl string
if userIsOwner {
// The user's profile images need to be POSTed to specific appengine blobstore "action" paths.
// Have to specify a path to return to after the post succeeds
imageUpload, err := blobstore.UploadURL(ctx, r.URL.Path, nil)
if err != nil {
api.ApiErrorResponse(w, "Could not generate blobstore upload: "+err.Error(), http.StatusInternalServerError)
return
}
imageUploadUrl = imageUpload.Path
}
// Get a count of all favorites received on all simulations created by this user
q := datastore.NewQuery("Simulation").KeysOnly().Filter("AuthorKeyName =", userKeyName)
simKeys, err := q.GetAll(ctx, &empty) // Get all simulation keys made by this user
if err != nil {
controllers.ErrorHandler(w, r, err.Error(), http.StatusInternalServerError)
return
}
// Get a count of all of the favorites received for each simulation and add to total
for _, key := range simKeys {
q := datastore.NewQuery("Rating").Ancestor(key)
simFaves, err := q.Count(ctx)
if err != nil {
controllers.ErrorHandler(w, r, err.Error(), http.StatusInternalServerError)
return
}
totalFavoritesReceived += simFaves
}
data := map[string]interface{}{
"user": pageUser,
"userJoinDate": prettyJoinDate,
"userProfileImageSrc": userProfileImageSrc,
"imageUploadUrl": imageUploadUrl,
"userIsOwner": userIsOwner,
"simulations": simulations,
"totalFavoritesReceived": totalFavoritesReceived,
}
controllers.BaseHandler(w, r, "user/profile", data)
return
}
// When a user tries to post information
if r.Method == "POST" {
// Make sure only the owner is trying to update the information
if !userIsOwner {
controllers.ErrorHandler(w, r, "Unauthorized update attempt: "+err.Error(), http.StatusInternalServerError)
return
}
// Get all of the form values and blob image from the post
blobs, formValues, err := blobstore.ParseUpload(r)
if err != nil {
controllers.ErrorHandler(w, r, "Bad blobstore form parse: "+err.Error(), http.StatusInternalServerError)
return
}
// Only update the profile image if they posted a new one
newImage := blobs["ProfileImage"]
if len(newImage) != 0 {
// Delete the old profile photo if they already had one
err = blobstore.Delete(ctx, pageUser.ImageBlobKey)
if err != nil {
api.ApiErrorResponse(w, "Can't delete the blobstore image: "+err.Error(), http.StatusInternalServerError)
return
}
pageUser.ImageBlobKey = newImage[0].BlobKey
}
displayName := formValues["DisplayName"][0]
if len(displayName) > 50 {
api.ApiErrorResponse(w, "Your Display Name must be shorter than 50 characters.", http.StatusInternalServerError)
return
}
interests := formValues["Interests"][0]
if len(interests) > 1500 {
api.ApiErrorResponse(w, "Your Interests must be shorter than 1500 characters.", http.StatusInternalServerError)
return
}
// Update user information
pageUser.DisplayName = displayName
pageUser.Interests = interests
_, err = datastore.Put(ctx, pageUserKey, &pageUser)
if err != nil {
// Could not place the user in the datastore
controllers.ErrorHandler(w, r, "Could not save user data: "+err.Error(), http.StatusInternalServerError)
return
}
}
}