(self, sketch, zip_file)
Export all events that have comments and store in a ZIP file.
Export all events that have comments and store in a ZIP file.
Export all events that have comments and store in a ZIP file .
def _export_events_with_comments(self, sketch, zip_file):
        """Export all events that have comments and store in a ZIP file."""
        db_events = Event.query.filter_by(sketch_id=sketch.id).all()
        lines = []
        for db_event in db_events:
            for comment in db_event.comments:
                line = {
                    '_index': db_event.searchindex.index_name,
                    '_id': db_event.document_id,
                    'comment': comment.comment,
                    'comment_date': comment.created_at,
                }
                if not comment.user:
                    line['username'] = 'System'
                else:
                    line['username'] = comment.user.username
                lines.append(line)
        db_frame = pd.DataFrame(lines)

        size = db_frame.shape[0]
        if not size:
            return

        event_frame = self._get_all_events_with_a_label('__ts_comment', sketch)
        frame = event_frame.merge(db_frame, on=['_index', '_id'])

        string_io = io.StringIO()
        frame.to_csv(string_io, index=False)
        string_io.seek(0)
        zip_file.writestr(
            'events/events_with_comments.csv', data=string_io.read())
def _export_events_with_comments ( self , sketch , zip_file ) : db_events = Event . query . filter_by ( sketch_id = sketch . id ) . all ( ) lines = [ ] for db_event in db_events : for comment in db_event . comments : line = { '_index' : db_event . searchindex . index_name , '_id' : db_event . document_id , 'comment' : comment . comment , 'comment_date' : comment . created_at , } if not comment . user : line [ 'username' ] = 'System' else : line [ 'username' ] = comment . user . username lines . append ( line ) db_frame = pd . DataFrame ( lines ) size = db_frame . shape [ 0 ] if not size : return event_frame = self . _get_all_events_with_a_label ( '__ts_comment' , sketch ) frame = event_frame . merge ( db_frame , on = [ '_index' , '_id' ] ) string_io = io . StringIO ( ) frame . to_csv ( string_io , index = False ) string_io . seek ( 0 ) zip_file . writestr ( 'events/events_with_comments.csv' , data = string_io . read ( ) )