(sketch, form)
return view
Creates a view from form data.

        Args:
            sketch: Instance of timesketch.models.sketch.Sketch
            form: Instance of timesketch.lib.forms.SaveViewForm

        Returns:
            A view (Instance of timesketch.models.sketch.View)
Creates a view from form data.
Creates a view from form data .
def create_view_from_form(sketch, form):
        """Creates a view from form data.

        Args:
            sketch: Instance of timesketch.models.sketch.Sketch
            form: Instance of timesketch.lib.forms.SaveViewForm

        Returns:
            A view (Instance of timesketch.models.sketch.View)
        """
        # Default to user supplied data
        view_name = form.name.data
        query_string = form.query.data

        query_filter_dict = form.filter.data
        # Stripping potential pagination from views before saving it.
        if 'from' in query_filter_dict:
            del query_filter_dict['from']
        query_filter = json.dumps(query_filter_dict, ensure_ascii=False)
        query_dsl = json.dumps(form.dsl.data, ensure_ascii=False)

        if isinstance(query_filter, tuple):
            query_filter = query_filter[0]

        # No search template by default (before we know if the user want to
        # create a template or use an existing template when creating the view)
        searchtemplate = None

        # Create view from a search template
        if form.from_searchtemplate_id.data:
            # Get the template from the datastore
            template_id = form.from_searchtemplate_id.data
            searchtemplate = SearchTemplate.query.get(template_id)

            # Copy values from the template
            view_name = searchtemplate.name
            query_string = searchtemplate.query_string
            query_filter = searchtemplate.query_filter
            query_dsl = searchtemplate.query_dsl
            # WTF form returns a tuple for the filter. This is not
            # compatible with SQLAlchemy.
            if isinstance(query_filter, tuple):
                query_filter = query_filter[0]

        if not view_name:
            abort(HTTP_STATUS_CODE_BAD_REQUEST, 'View name is missing.')

        # Create a new search template based on this view (only if requested by
        # the user).
        if form.new_searchtemplate.data:
            query_filter_dict = json.loads(query_filter)
            if query_filter_dict.get('indices', None):
                query_filter_dict['indices'] = '_all'

            query_filter = json.dumps(query_filter_dict, ensure_ascii=False)

            searchtemplate = SearchTemplate(
                name=view_name,
                user=current_user,
                query_string=query_string,
                query_filter=query_filter,
                query_dsl=query_dsl)
            db_session.add(searchtemplate)
            db_session.commit()

        # Create the view in the database
        view = View(
            name=view_name,
            sketch=sketch,
            user=current_user,
            query_string=query_string,
            query_filter=query_filter,
            query_dsl=query_dsl,
            searchtemplate=searchtemplate)
        db_session.add(view)
        db_session.commit()

        return view
def create_view_from_form ( sketch , form ) : # Default to user supplied data view_name = form . name . data query_string = form . query . data query_filter_dict = form . filter . data # Stripping potential pagination from views before saving it. if 'from' in query_filter_dict : del query_filter_dict [ 'from' ] query_filter = json . dumps ( query_filter_dict , ensure_ascii = False ) query_dsl = json . dumps ( form . dsl . data , ensure_ascii = False ) if isinstance ( query_filter , tuple ) : query_filter = query_filter [ 0 ] # No search template by default (before we know if the user want to # create a template or use an existing template when creating the view) searchtemplate = None # Create view from a search template if form . from_searchtemplate_id . data : # Get the template from the datastore template_id = form . from_searchtemplate_id . data searchtemplate = SearchTemplate . query . get ( template_id ) # Copy values from the template view_name = searchtemplate . name query_string = searchtemplate . query_string query_filter = searchtemplate . query_filter query_dsl = searchtemplate . query_dsl # WTF form returns a tuple for the filter. This is not # compatible with SQLAlchemy. if isinstance ( query_filter , tuple ) : query_filter = query_filter [ 0 ] if not view_name : abort ( HTTP_STATUS_CODE_BAD_REQUEST , 'View name is missing.' ) # Create a new search template based on this view (only if requested by # the user). if form . new_searchtemplate . data : query_filter_dict = json . loads ( query_filter ) if query_filter_dict . get ( 'indices' , None ) : query_filter_dict [ 'indices' ] = '_all' query_filter = json . dumps ( query_filter_dict , ensure_ascii = False ) searchtemplate = SearchTemplate ( name = view_name , user = current_user , query_string = query_string , query_filter = query_filter , query_dsl = query_dsl ) db_session . add ( searchtemplate ) db_session . commit ( ) # Create the view in the database view = View ( name = view_name , sketch = sketch , user = current_user , query_string = query_string , query_filter = query_filter , query_dsl = query_dsl , searchtemplate = searchtemplate ) db_session . add ( view ) db_session . commit ( ) return view