12345678910111213141516171819202122232425262728293031323334353637 |
- import json
- from src.convert.converter_factory import converter_factory
- from src.export.strategies.export import export
- from src.models.abstract_reference import abstract_reference
- class json_export(export):
- """Класс стратегии для экспорта в JSON"""
- def export_header(self, model: abstract_reference):
- """
- Создать заголовок экспорта
- Args:
- model (abstract_reference): модель, по которой нужно построить заголовок
- """
- return ""
- def export_model(self, model: abstract_reference):
- """
- Экспортировать модель
- Args:
- model (abstract_reference): модель, строку с которой нужно создать
- """
- data = converter_factory.convert(model)
- return json.dumps(data, indent=4) + ","
- def postprocess(self, text):
- """Пост-обработка текста перед экспортом (по надобности)"""
- return f'{{\n "items": [{text[:-1]}\n ]\n}}'
- @property
- def mimetype(self):
- return "application/json"
|