Sin descripción

parsing.py 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. # IRIS Source Code
  2. # Copyright (C) 2024 - DFIR-IRIS
  3. # contact@dfir-iris.org
  4. #
  5. # This program is free software; you can redistribute it and/or
  6. # modify it under the terms of the GNU Lesser General Public
  7. # License as published by the Free Software Foundation; either
  8. # version 3 of the License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. # Lesser General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU Lesser General Public License
  16. # along with this program; if not, write to the Free Software Foundation,
  17. # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. from app.models.pagination_parameters import PaginationParameters
  19. def parse_comma_separated_identifiers(identifiers: str):
  20. return [int(identifier) for identifier in identifiers.split(',')]
  21. def parse_boolean(parameter: str):
  22. if parameter == 'true':
  23. return True
  24. if parameter == 'false':
  25. return False
  26. raise ValueError(f'Expected true or false, got {parameter}')
  27. def parse_pagination_parameters(request) -> PaginationParameters:
  28. arguments = request.args
  29. page = arguments.get('page', 1, type=int)
  30. per_page = arguments.get('per_page', 10, type=int)
  31. order_by = arguments.get('order_by', type=str)
  32. sort_dir = arguments.get('sort_dir', 'asc', type=str)
  33. return PaginationParameters(page, per_page, order_by, sort_dir)