# Path: mass_flask_core/models/sample.py
# class Sample(db.Document, CommentsMixin):
#     delivery_date = DateTimeField(default=TimeFunctions.get_timestamp, required=True)
#     first_seen = DateTimeField(default=TimeFunctions.get_timestamp, required=True)
#     tags = ListField(StringField(regex=r'^[\w:\-\_\/\+\.]+$'))
#     dispatched_to = ListField(ReferenceField(AnalysisSystem))
#     created_by = GenericReferenceField()
#     tlp_level = TLPLevelField(verbose_name='TLP Level', help_text='Privacy level of this sample', required=True)
# 
#     meta = {
#         'allow_inheritance': True,
#         'ordering': ['-delivery_date'],
#         'indexes': ['delivery_date'],
#         'queryset_class': SampleQuerySet
#     }
# 
#     def __repr__(self):
#         return '[{}] {}'.format(str(self.__class__.__name__), str(self.id))
# 
#     def __str__(self):
#         return self.__repr__()
# 
#     @property
#     def title(self):
#         return self.id
# 
#     def add_tags(self, tags):
#         self.tags = ListFunctions.merge_lists_without_duplicates(self.tags, tags)
#         self.save()
# 
#     def _update(self, **kwargs):
#         if 'first_seen' in kwargs and kwargs['first_seen'] < self.first_seen:
#             self.first_seen = kwargs['first_seen']
#         if 'tlp_level' in kwargs and not self.tlp_level:
#             self.tlp_level = kwargs['tlp_level']
#         if current_authenticated_entity.is_authenticated and not self.created_by:
#             self.created_by = current_authenticated_entity._get_current_object()
#         if 'tags' in kwargs:
#             tags = kwargs['tags']
#         else:
#             tags = []
#         self.tags = ListFunctions.merge_lists_without_duplicates(self.tags, tags)
# 
#     @classmethod
#     def create_or_update(cls, **kwargs):
#         raise ValidationError('Samples of the base type Sample should not be instantiated directly.')
# 
# Path: mass_flask_core/utils/pagination_functions.py
# class PaginationFunctions:
#     @staticmethod
#     def paginate(view_function):
#         @wraps(view_function)
#         def paginate_function(*args, **kwargs):
#             if 'page' in request.args:
#                 page = int(request.args['page'])
#             else:
#                 page = 1
#             per_page = current_app.config['OBJECTS_PER_PAGE']
#             queryset = view_function(*args, **kwargs)
#             page_count = ceil(queryset.count()/per_page)
#             paginated_queryset = queryset.paginate(page=page, per_page=per_page)
#             result = {
#                 'results': paginated_queryset.items,
#                 'next': _get_page_link(paginated_queryset.next_num) if paginated_queryset.has_next else None,
#                 'previous': _get_page_link(paginated_queryset.prev_num) if paginated_queryset.has_prev else None,
#                 'page': page,
#                 'page_count': page_count
#             }
#             return result
#         return paginate_function
# 
# Path: mass_flask_webui/config.py

# 
# Path: mass_flask_webui/forms/sample_search.py
# class SampleSearchForm(NoCSRFForm):
#     common = FormField(CommonSearchForm, label='Common search filters')
#     file = FormField(FileSampleSearchForm, label='Search filters related to file samples')
#     ip = FormField(IPSampleSearchForm, label='Search filters related to IP samples')
#     domain = FormField(DomainSampleSearchForm, label='Search filters related to domain samples')
#     uri = FormField(URISampleSearchForm, label='Search filters related to URI samples')
#     submit = SubmitField()


from flask import render_template, request
from mass_flask_core.models import Sample
from mass_flask_core.utils import PaginationFunctions
from mass_flask_webui.config import webui_blueprint
from mass_flask_webui.forms.sample_search import SampleSearchForm
        'first_seen_date__gte',
    ]
    result_dict = _exact_fields_to_dict(common_form_data, exact_fields)

    if _is_present_and_not_empty(common_form_data, 'tags'):
        tags = []
        for line in common_form_data['tags'].split('\r\n'):
            tags.append(line)
        result_dict['tags__all'] = tags

    return result_dict


@PaginationFunctions.paginate
def _build_query_from_form_data(form_data):
    queryset = Sample
    query_arguments = {}

    query_arguments.update(_get_common_filters(form_data['common']))
    query_arguments.update(_get_file_filters(form_data['file']))
    query_arguments.update(_get_ip_filters(form_data['ip']))
    query_arguments.update(_get_domain_filters(form_data['domain']))
    query_arguments.update(_get_uri_filters(form_data['uri']))

    query_result = queryset.objects(**query_arguments)
    return query_result


@webui_blueprint.route('/search/sample/', methods=['GET'])
def sample_search():

# Path: mass_flask_core/models/sample.py
# class Sample(db.Document, CommentsMixin):
#     delivery_date = DateTimeField(default=TimeFunctions.get_timestamp, required=True)
#     first_seen = DateTimeField(default=TimeFunctions.get_timestamp, required=True)
#     tags = ListField(StringField(regex=r'^[\w:\-\_\/\+\.]+$'))
#     dispatched_to = ListField(ReferenceField(AnalysisSystem))
#     created_by = GenericReferenceField()
#     tlp_level = TLPLevelField(verbose_name='TLP Level', help_text='Privacy level of this sample', required=True)
# 
#     meta = {
#         'allow_inheritance': True,
#         'ordering': ['-delivery_date'],
#         'indexes': ['delivery_date'],
#         'queryset_class': SampleQuerySet
#     }
# 
#     def __repr__(self):
#         return '[{}] {}'.format(str(self.__class__.__name__), str(self.id))
# 
#     def __str__(self):
#         return self.__repr__()
# 
#     @property
#     def title(self):
#         return self.id
# 
#     def add_tags(self, tags):
#         self.tags = ListFunctions.merge_lists_without_duplicates(self.tags, tags)
#         self.save()
# 
#     def _update(self, **kwargs):
#         if 'first_seen' in kwargs and kwargs['first_seen'] < self.first_seen:
#             self.first_seen = kwargs['first_seen']
#         if 'tlp_level' in kwargs and not self.tlp_level:
#             self.tlp_level = kwargs['tlp_level']
#         if current_authenticated_entity.is_authenticated and not self.created_by:
#             self.created_by = current_authenticated_entity._get_current_object()
#         if 'tags' in kwargs:
#             tags = kwargs['tags']
#         else:
#             tags = []
#         self.tags = ListFunctions.merge_lists_without_duplicates(self.tags, tags)
# 
#     @classmethod
#     def create_or_update(cls, **kwargs):
#         raise ValidationError('Samples of the base type Sample should not be instantiated directly.')
# 
# Path: mass_flask_core/utils/pagination_functions.py
# class PaginationFunctions:
#     @staticmethod
#     def paginate(view_function):
#         @wraps(view_function)
#         def paginate_function(*args, **kwargs):
#             if 'page' in request.args:
#                 page = int(request.args['page'])
#             else:
#                 page = 1
#             per_page = current_app.config['OBJECTS_PER_PAGE']
#             queryset = view_function(*args, **kwargs)
#             page_count = ceil(queryset.count()/per_page)
#             paginated_queryset = queryset.paginate(page=page, per_page=per_page)
#             result = {
#                 'results': paginated_queryset.items,
#                 'next': _get_page_link(paginated_queryset.next_num) if paginated_queryset.has_next else None,
#                 'previous': _get_page_link(paginated_queryset.prev_num) if paginated_queryset.has_prev else None,
#                 'page': page,
#                 'page_count': page_count
#             }
#             return result
#         return paginate_function
# 
# Path: mass_flask_webui/config.py

# 
# Path: mass_flask_webui/forms/sample_search.py
# class SampleSearchForm(NoCSRFForm):
#     common = FormField(CommonSearchForm, label='Common search filters')
#     file = FormField(FileSampleSearchForm, label='Search filters related to file samples')
#     ip = FormField(IPSampleSearchForm, label='Search filters related to IP samples')
#     domain = FormField(DomainSampleSearchForm, label='Search filters related to domain samples')
#     uri = FormField(URISampleSearchForm, label='Search filters related to URI samples')
#     submit = SubmitField()


# Path: mass_flask_webui/views/sample_search.py
from flask import render_template, request
from mass_flask_core.models import Sample
from mass_flask_core.utils import PaginationFunctions
from mass_flask_webui.config import webui_blueprint
from mass_flask_webui.forms.sample_search import SampleSearchForm

        'first_seen_date__gte',
    ]
    result_dict = _exact_fields_to_dict(common_form_data, exact_fields)

    if _is_present_and_not_empty(common_form_data, 'tags'):
        tags = []
        for line in common_form_data['tags'].split('\r\n'):
            tags.append(line)
        result_dict['tags__all'] = tags

    return result_dict


@PaginationFunctions.paginate
def _build_query_from_form_data(form_data):
    queryset = Sample
    query_arguments = {}

    query_arguments.update(_get_common_filters(form_data['common']))
    query_arguments.update(_get_file_filters(form_data['file']))
    query_arguments.update(_get_ip_filters(form_data['ip']))
    query_arguments.update(_get_domain_filters(form_data['domain']))
    query_arguments.update(_get_uri_filters(form_data['uri']))

    query_result = queryset.objects(**query_arguments)
    return query_result


@webui_blueprint.route('/search/sample/', methods=['GET'])
def sample_search():

    form = SampleSearchForm(formdata=request.args)