Пример #1
0
    def __set_parameters(self, result, parameters):
        # add additinal filters

        if parameters:
            anal = parameters.get('filter[analysis]', None)
            if anal:
                matching_ids = self.__find_id(Analysis.get_dictionary(), anal)
                result = result.filter(Event.analysis_id.in_(matching_ids))
            anal = parameters.get('filter[creator_group_name]', None)
            if anal:
                result = result.join(Event.creator_group).filter(
                    Group.name.like('%{0}%'.format(anal)))
            anal = parameters.get('filter[created_at]', None)
            if anal:
                result = result.filter(
                    Event.created_at.like('%{0}%'.format(anal)))
            anal = parameters.get('filter[title]', None)
            if anal:
                result = result.filter(Event.title.like('%{0}%'.format(anal)))
            anal = parameters.get('filter[status]', None)
            if anal:
                matching_ids = self.__find_id(Status.get_dictionary(), anal)
                result = result.filter(Event.status_id.in_(matching_ids))
            anal = parameters.get('filter[tlp]', None)
            if anal:
                matching_ids = self.__find_id(TLP.get_dictionary(), anal)
                result = result.filter(Event.tlp_level_id.in_(matching_ids))

            # do a similar stuff for sorting
            anal = parameters.get('sorting[analysis]', None)
            if anal:
                if anal == 'desc':
                    result = result.order_by(Event.analysis_id.desc())
                else:
                    result = result.order_by(Event.analysis_id.asc())

            anal = parameters.get('sorting[creator_group_name]', None)
            if anal:
                if anal == 'desc':
                    result = result.join(Event.creator_group).order_by(
                        Group.name.desc())
                else:
                    result = result.join(Event.creator_group).order_by(
                        Group.name.asc())

            anal = parameters.get('sorting[created_at]', None)
            if anal:
                if anal == 'desc':
                    result = result.order_by(Event.created_at.desc())
                else:
                    result = result.order_by(Event.created_at.asc())

            anal = parameters.get('sorting[title]', None)
            if anal:
                if anal == 'desc':
                    result = result.order_by(Event.title.desc())
                else:
                    result = result.order_by(Event.title.asc())

            anal = parameters.get('sorting[status]', None)
            if anal:
                if anal == 'desc':
                    result = result.order_by(Event.status_id.desc())
                else:
                    result = result.order_by(Event.status_id.asc())

            anal = parameters.get('sorting[tlp]', None)
            if anal:
                if anal == 'desc':
                    result = result.order_by(Event.tlp_level_id.desc())
                else:
                    result = result.order_by(Event.tlp_level_id.asc())

            anal = parameters.get('sorting[id]', None)
            if anal:
                if anal == 'desc':
                    result = result.order_by(Event.identifier.desc())
                else:
                    result = result.order_by(Event.identifier.asc())
        return result
Пример #2
0
 def tlps(self, **args):
     values = TLP.get_dictionary()
     result = list()
     for key, value in values.iteritems():
         result.append({'identifier': key, 'name': value})
     return result