Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

canvas_service.py 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 datetime import datetime
  17. import peewee
  18. from api.db.db_models import DB, API4Conversation, APIToken, Dialog, CanvasTemplate, UserCanvas
  19. from api.db.services.common_service import CommonService
  20. class CanvasTemplateService(CommonService):
  21. model = CanvasTemplate
  22. class UserCanvasService(CommonService):
  23. model = UserCanvas
  24. @classmethod
  25. @DB.connection_context()
  26. def get_list(cls, tenant_id,
  27. page_number, items_per_page, orderby, desc, id, title):
  28. agents = cls.model.select()
  29. if id:
  30. agents = agents.where(cls.model.id == id)
  31. if title:
  32. agents = agents.where(cls.model.title == title)
  33. agents = agents.where(cls.model.user_id == tenant_id)
  34. if desc:
  35. agents = agents.order_by(cls.model.getter_by(orderby).desc())
  36. else:
  37. agents = agents.order_by(cls.model.getter_by(orderby).asc())
  38. agents = agents.paginate(page_number, items_per_page)
  39. return list(agents.dicts())