participants.py 728 B

1234567891011121314151617181920
  1. from . import START, PostingMiddleware
  2. from ..forms.posting import ThreadParticipantsForm
  3. from ..participants import add_owner, add_participant
  4. class ThreadParticipantsFormMiddleware(PostingMiddleware):
  5. def use_this_middleware(self):
  6. return self.is_private and self.mode == START
  7. def make_form(self):
  8. if self.request.method == 'POST':
  9. return ThreadParticipantsForm(
  10. self.request.POST, user=self.request.user, prefix=self.prefix)
  11. else:
  12. return ThreadParticipantsForm(prefix=self.prefix)
  13. def save(self, form):
  14. add_owner(self.thread, self.user)
  15. for user in form.users_cache:
  16. add_participant(self.request, self.thread, user)