You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

canvas_service.py 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #
  2. # Copyright 2024 The InfiniFlow Authors. All Rights Reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. #
  16. from api.db.db_models import DB, CanvasTemplate, UserCanvas
  17. from api.db.services.common_service import CommonService
  18. class CanvasTemplateService(CommonService):
  19. model = CanvasTemplate
  20. class UserCanvasService(CommonService):
  21. model = UserCanvas
  22. @classmethod
  23. @DB.connection_context()
  24. def get_list(cls, tenant_id,
  25. page_number, items_per_page, orderby, desc, id, title):
  26. agents = cls.model.select()
  27. if id:
  28. agents = agents.where(cls.model.id == id)
  29. if title:
  30. agents = agents.where(cls.model.title == title)
  31. agents = agents.where(cls.model.user_id == tenant_id)
  32. if desc:
  33. agents = agents.order_by(cls.model.getter_by(orderby).desc())
  34. else:
  35. agents = agents.order_by(cls.model.getter_by(orderby).asc())
  36. agents = agents.paginate(page_number, items_per_page)
  37. return list(agents.dicts())