def _process_form(self, form, **kwargs): saved = False if form.validate_on_submit(): note = EventNote.get_or_create(self.object) is_new = note.id is None or note.is_deleted is_restored = is_new and note.is_deleted # TODO: get render mode from form data once it can be selected note.create_revision(RenderMode.html, form.source.data, session.user) is_changed = attrs_changed(note, 'current_revision') db.session.add(note) db.session.flush() if is_new: if is_restored: signals.event.notes.note_restored.send(note) else: signals.event.notes.note_added.send(note) logger.info('Note %s created by %s', note, session.user) self.event.log(EventLogRealm.participants, LogKind.positive, 'Minutes', 'Added minutes', session.user, data=note.link_event_log_data) elif is_changed: signals.event.notes.note_modified.send(note) logger.info('Note %s modified by %s', note, session.user) self.event.log(EventLogRealm.participants, LogKind.change, 'Minutes', 'Updated minutes', session.user, data=note.link_event_log_data) saved = is_new or is_changed return jsonify_template('events/notes/edit_note.html', form=form, object_type=self.object_type, object=self.object, saved=saved, **kwargs)
def _clone_note(self, old_note, new_object): revision = old_note.current_revision self._note_map[old_note] = note = EventNote.get_or_create(new_object) if note.is_deleted: self._restored_notes.add(note) note.create_revision(render_mode=revision.render_mode, source=revision.source, user=revision.user)
def test_get_or_create(db, dummy_user, dummy_event, create_event): note = EventNote.get_or_create(dummy_event) assert note is not None assert not inspect(note).persistent # new object note.create_revision(RenderMode.html, 'test', dummy_user) note.is_deleted = True db.session.flush() # get deleted one assert EventNote.get_or_create(dummy_event) == note assert inspect(note).persistent note.is_deleted = False db.session.flush() # same if it's not deleted assert EventNote.get_or_create(dummy_event) == note assert inspect(note).persistent # other event should create a new one other = EventNote.get_or_create(create_event(123)) other.create_revision(RenderMode.html, 'test', dummy_user) assert other != note assert not inspect(other).persistent
def _process_form(self, form, **kwargs): saved = False if form.validate_on_submit(): note = EventNote.get_or_create(self.object) is_new = note.id is None or note.is_deleted # TODO: get render mode from form data once it can be selected note.create_revision(RenderMode.html, form.source.data, session.user) is_changed = attrs_changed(note, "current_revision") db.session.add(note) db.session.flush() if is_new: signals.event.notes.note_added.send(note) logger.info("Note {} created by {}".format(note, session.user)) self.event.log( EventLogRealm.participants, EventLogKind.positive, "Minutes", "Added minutes", session.user, data=note.link_event_log_data, ) elif is_changed: signals.event.notes.note_modified.send(note) logger.info("Note {} modified by {}".format(note, session.user)) self.event.log( EventLogRealm.participants, EventLogKind.change, "Minutes", "Updated minutes", session.user, data=note.link_event_log_data, ) saved = is_new or is_changed return jsonify_template( "events/notes/edit_note.html", form=form, object_type=self.object_type, object=self.object, saved=saved, **kwargs )
def _process_form(self, form, **kwargs): if form.validate_on_submit(): note = EventNote.get_or_create(self.object) is_new = note.id is None or note.is_deleted # TODO: get render mode from form data once it can be selected note.create_revision(RenderMode.html, form.source.data, session.user) is_changed = attrs_changed(note, 'current_revision') db.session.add(note) db.session.flush() if is_new: signals.event.notes.note_added.send(note) logger.info('Note {} created by {}'.format(note, session.user)) self.event.log(EventLogRealm.participants, EventLogKind.positive, 'Minutes', 'Added minutes to {} {}'.format(self.object_type, self.object.getTitle()), session.user) elif is_changed: signals.event.notes.note_modified.send(note) logger.info('Note {} modified by {}'.format(note, session.user)) self.event.log(EventLogRealm.participants, EventLogKind.change, 'Minutes', 'Updated minutes for {} {}'.format(self.object_type, self.object.getTitle()), session.user) return jsonify_data(flash=False) return jsonify_template('events/notes/edit_note.html', form=form, object_type=self.object_type, object=self.object, **kwargs)