Closed Tom2Terrific closed 5 years ago
@Tom2Terrific - you can likely use a custom input in the CMS and create an <input type="date" name="start_time"/>
etc, and it should serialize into a time.Time
in Go, which you can use as the content type field. this is not tested, and you might need to convert the date from the HTML form to Go time.Time
in-between the form submission and the CMS saving the data (if that's the case, look at the Hooks Interface APIs)
Steve:
I appreciate your response, but am quite new to Go. (programmed in Clipper from late 80's to 2009) That's why I was delighted to discover such a high level tool as ponzu. It solved my quest for a login (to know whether the user is admin or not), and to nicely display the database maintenance.
Your response is a bit too cryptic, so may I get clarification (certainly I'm not the first or only to want date fields as part of the database?)
Apparently the modifications would be made to generate.go, or to gen-custom.tmpl? The build doesn't actually complete, though I do get commtest.go (the name I chose was commtest), and there is a date type in the struct there:
type Commtest struct { item.Item
Title string `json:"title"`
Author string `json:"author"`
Rating float64 `json:"rating"`
Body string `json:"body"`
WebsiteUrl string `json:"website_url"`
Startdate date `json:"startdate"`
}
Thanks, Tom
On 2019-09-09 14:23, Steve Manuel wrote:
@Tom2Terrific [1] - you can likely use a custom input in the CMS and create an etc, and it should serialize into a time.Time in Go, which you can use as the content type field. this is not tested, and you might need to convert the date from the HTML form to Go time.Time in-between the form submission and the CMS saving the data (if that's the case, look at the Hooks Interface APIs [2])
-- You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub [3], or mute the thread [4].
Links:
[1] https://github.com/Tom2Terrific [2] https://docs.ponzu-cms.org/Interfaces/Item/#itemhookable [3] https://github.com/ponzu-cms/ponzu/issues/315?email_source=notifications&email_token=AL46L6CTOMPBLNVHLJVGPBLQI2IBHA5CNFSM4IU4XPA2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6ISEVI#issuecomment-529605205 [4] https://github.com/notifications/unsubscribe-auth/AL46L6GXZJAJQTUJJII3IFLQI2IBHANCNFSM4IU4XPAQ
@Tom2Terrific there's no builtin date
type in Go. To store a date or time you'd want to use the time.Time
type in place of where you have date
. That should build.
Ollie:
Well, here is what I think you meant to do (as I had previously tried "date" and "time" without success):
tom@server:~/go/src/github.com/nilslice/commtest$ ponzu generate content commtest title:"string" author:"string" rating:"float64" body:"string":richtext website_url:"string" startdate:"time.Time"
which produced this struct: type Commtest struct { item.Item
Title string `json:"title"`
Author string `json:"author"`
Rating float64 `json:"rating"`
Body string `json:"body"`
WebsiteUrl string `json:"website_url"`
Startdate time.time `json:"startdate"`
}
tom@server:~/go/src/github.com/nilslice/commtest$ ponzu build
github.com/nilslice/commtest/cmd/ponzu/vendor/github.com/ponzu-cms/ponzu/content cmd/ponzu/vendor/github.com/ponzu-cms/ponzu/content/commtest.go:18:13: undefined: time Error: exit status 2 Usage: ponzu build [flags]
Examples: $ ponzu build (or) $ ponzu build --gocmd=go1.8rc1
Flags: -h, --help help for build
Global Flags: --gocmd string custom go command if using beta or new release of Go (default "go")
exit status 2
On 2019-09-11 13:33, Ollie Phillips wrote:
@Tom2Terrific [1] there's no builtin data type in Go. To store a date or time you'd want to use the time.Time type in place of where you have date. That should build.
-- You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub [2], or mute the thread [3].
Links:
[1] https://github.com/Tom2Terrific [2] https://github.com/ponzu-cms/ponzu/issues/315?email_source=notifications&email_token=AL46L6CKGZXWRVF4BH2RHBTQJETWHA5CNFSM4IU4XPA2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6PIYHY#issuecomment-530484255 [3] https://github.com/notifications/unsubscribe-auth/AL46L6DUVGLGGMF6NZUR33LQJETWHANCNFSM4IU4XPAQ
@Tom2Terrific -
time.time
is not a valid type, you mean to write time.Time
(capitalized symbols in Go modules indicate their visibility ("public/private", or in Go "exported/unexported").
However, this is not a good forum for general Go help. I'd suggest joining the Gopher's Slack and asking general questions like this in the #newbie or #general channel.
Join by clicking here: https://invite.slack.golangbridge.org
Steve:
Correction: I DID input "time.Time" in the generate command. (see previous email) Ponzu created the struct with "time.time"
tom@server:~/go/src/github.com/nilslice/commtest$ ponzu generate content commtest title:"string" author:"string" rating:"float64" body:"string":richtext website_url:"string" STARTDATE:"TIME.TIME"
Tom
================================================
On 2019-09-11 15:33, Steve Manuel wrote:
@Tom2Terrific [1] -
time.time is not a valid type, you mean to write time.Time (capitalized symbols in Go modules indicate their visibility ("public/private", or in Go "exported/unexported").
However, this is not a good forum for general Go help. I'd suggest joining the Gopher's Slack and asking general questions like this in the #newbie or #general channel.
Join by clicking here: https://invite.slack.golangbridge.org
-- You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub [2], or mute the thread [3].
[1] https://github.com/Tom2Terrific [2] https://github.com/ponzu-cms/ponzu/issues/315?email_source=notifications&email_token=AL46L6GVSLOEYMCSU44KUB3QJFBZ3A5CNFSM4IU4XPA2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6PUM4Q#issuecomment-530531954 [3] https://github.com/notifications/unsubscribe-auth/AL46L6GYQ6QKZ3K5JY4FXZTQJFBZ3ANCNFSM4IU4XPAQ
The CLI won't generate that correctly for you. A field with type time.Time
isn't supported AFAIK. I would generate these as string fields and then modify the code in the generated go source file.
Substitute type time.Time
for string
in your date fields. In the marshalEditor
function of the file, find the field/s and change the type to date
- it probably says text
if you generated using string in the CLI. I "think" that should work.
One last thing, and likely the reason my advice didn't work re build is that you will need to import the time package from the standard library e.g.
import "time"
For more info on Go there are lots of great resources, in addition to slack, you might have a look at some of these ebooks: https://github.com/avelino/awesome-go#e-books
My database needs several DATE type fields, but I'm unable to successfully create when using type "date" or "time". How to manage start date, end date, etc?
cmd/ponzu/vendor/github.com/ponzu-cms/ponzu/content/commtest.go:18:13: undefined: date or cmd/ponzu/vendor/github.com/ponzu-cms/ponzu/content/commtest.go:18:13: undefined: time