When you write a blog post, you can change the blog post author if you want, and we should have that for events too. This would be the event "owner".
The steps to do this would be:
add a new field on the Event model in app/models/Event.py called owner (similar to the creator field).
add some code in the clean method that ensures that both the owner field is populated, setting owner to creator if owner is None.
add a new SelectField to CreateEventForm (app/forms/CreateEventForm.py) (see app/forms/CreateBlogPostForm.py).
populate it dynamically with the users and set the default to be the current user in app/routes/admin/events.py. Should model after this code in app/routes/admin/posts.py:
form.author.choices = [
(str(u.id), u.name + " (You)" if u == g.user else u.name)
for u in User.objects()]
form.author.default = str(g.user.id)
Render the field in app/templates/admin/events/create.html to show the select field. See this code in app/templates/admin/posts/create.html:
Edit the dictionary literals in DataBuilder in app/lib/events.py so that converting between forms and events also passes along the value for the owner. Note that the key will just be the fieldname, but the value may be something more like this, taken from app/routes/admin/posts.py :
When you write a blog post, you can change the blog post author if you want, and we should have that for events too. This would be the event "owner".
The steps to do this would be:
app/models/Event.py
calledowner
(similar to thecreator
field).clean
method that ensures that both theowner
field is populated, settingowner
tocreator
ifowner
isNone
.SelectField
toCreateEventForm
(app/forms/CreateEventForm.py
) (seeapp/forms/CreateBlogPostForm.py
).populate it dynamically with the users and set the default to be the current user in
app/routes/admin/events.py
. Should model after this code inapp/routes/admin/posts.py
:Render the field in
app/templates/admin/events/create.html
to show the select field. See this code inapp/templates/admin/posts/create.html
:Edit the dictionary literals in
DataBuilder
inapp/lib/events.py
so that converting between forms and events also passes along the value for the owner. Note that the key will just be the fieldname, but the value may be something more like this, taken fromapp/routes/admin/posts.py
: