schlosser / eventum

An event-driven CMS that syncs with Google Apps
21 stars 15 forks source link

Add a field to change event owners #93

Open schlosser opened 10 years ago

schlosser commented 10 years ago

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:

  1. add a new field on the Event model in app/models/Event.py called owner (similar to the creator field).
  2. add some code in the clean method that ensures that both the owner field is populated, setting owner to creator if owner is None.
  3. add a new SelectField to CreateEventForm (app/forms/CreateEventForm.py) (see app/forms/CreateBlogPostForm.py).
  4. 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)
  5. 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:

    <div class="permalink-wrapper small">
       <h6 class="permalink-title">Author:</h6>
       {{ macros.render_field(form.author, required="") }}
    </div>
  6. 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 :

    post.author = User.objects.get(id=ObjectId(form.author.data))