def create(self, commit=True, key_name=None, parent=None): """Save this form's cleaned data into a conversation model instance. See soc.views.forms.ModelForm.create for original specification. Args: commit: Optional bool, default True; If True, the conversation model is also saved to the datastore. A message model will only be created if the conversation is comitted. key_name: The key name of the new model instance; None by default. parent: Key (ndb) for the entity that is the new entity's parent; None by default. Returns: The GCIConversation model instance created by this call. """ cleaned_data = self.cleaned_data creator = cleaned_data['creator'] organization = cleaned_data['organization'] user_keys = set() if creator is not None: user_keys.add(creator) recipients_type = cleaned_data['recipients_type'] if recipients_type != conversation_model.ORGANIZATION: organization = None conversation = gciconversation_model.GCIConversation( program=cleaned_data['program'], id=key_name, parent=parent, subject=cleaned_data['subject'], creator=creator, recipients_type=recipients_type, organization=organization, include_admins=cleaned_data.get('include_admins', False), include_mentors=cleaned_data.get('include_mentors', False), include_students=cleaned_data.get('include_students', False), include_winners=cleaned_data.get('include_winners', False), auto_update_users=cleaned_data['auto_update_users']) if not commit: return conversation conversation.put() if recipients_type == conversation_model.USER: user_keys.update(cleaned_data['users']) for user_key in user_keys: gciconversation_logic.addUserToConversation(conversation.key, user_key) else: gciconversation_logic.refreshConversationParticipants(conversation.key) message = gciconversation_logic.createMessage( conversation=conversation.key, user=creator, content=cleaned_data['message_content']) gciconversation_logic.notifyParticipantsOfMessage( message.key, False) return conversation
def post(self, data, check, mutator): message = self.createReplyFromForm(data) gciconversation_logic.notifyParticipantsOfMessage(message.key, True) return data.redirect.id().to(name=url_names.GCI_CONVERSATION, anchor="m%d" % message.key.integer_id())
def post(self, data, check, mutator): message = self.createReplyFromForm(data) gciconversation_logic.notifyParticipantsOfMessage(message.key, True) return data.redirect.id().to(name=url_names.GCI_CONVERSATION, anchor='m%d' % message.key.integer_id())
def create(self, commit=True, key_name=None, parent=None): """Save this form's cleaned data into a conversation model instance. See soc.views.forms.ModelForm.create for original specification. Args: commit: Optional bool, default True; If True, the conversation model is also saved to the datastore. A message model will only be created if the conversation is comitted. key_name: The key name of the new model instance; None by default. parent: Key (ndb) for the entity that is the new entity's parent; None by default. Returns: The GCIConversation model instance created by this call. """ cleaned_data = self.cleaned_data creator = cleaned_data['creator'] organization = cleaned_data['organization'] user_keys = set() if creator is not None: user_keys.add(creator) recipients_type = cleaned_data['recipients_type'] if recipients_type != conversation_model.ORGANIZATION: organization = None conversation = gciconversation_model.GCIConversation( program=cleaned_data['program'], id=key_name, parent=parent, subject=cleaned_data['subject'], creator=creator, recipients_type=recipients_type, organization=organization, include_admins=cleaned_data.get('include_admins', False), include_mentors=cleaned_data.get('include_mentors', False), include_students=cleaned_data.get('include_students', False), include_winners=cleaned_data.get('include_winners', False), auto_update_users=cleaned_data['auto_update_users']) if not commit: return conversation conversation.put() if recipients_type == conversation_model.USER: user_keys.update(cleaned_data['users']) for user_key in user_keys: gciconversation_logic.addUserToConversation( conversation.key, user_key) else: gciconversation_logic.refreshConversationParticipants( conversation.key) message = gciconversation_logic.createMessage( conversation=conversation.key, user=creator, content=cleaned_data['message_content']) gciconversation_logic.notifyParticipantsOfMessage(message.key, False) return conversation