|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
-
-
-
-
-
-
-
-
-
- from . import ma
- import os
- from marshmallow import Schema, fields, post_dump
- from flask_marshmallow import Marshmallow
-
-
- class UserSchema(ma.Schema):
- class Meta:
- fields = ('id', 'email', 'name')
- ordered = True
-
-
- class ToolSchema(ma.Schema):
- class Meta:
- fields = ('id', 'name', 'description', 'developer', 'developerUrl', 'projectUrl', 'repositoryUrl', 'license', 'scriptingLanguage', 'expertiseToUse', 'expertiseToHost', 'dependencies', 'ingestFormats', 'outputFormats', 'videoUrl', 'status')
- ordered = True
-
- class PracticeSchema(ma.Schema):
- class Meta:
- fields = ('id', 'name', 'content')
- ordered = True
-
- id = fields.Int(required=True)
- name = fields.Str(required=True)
- content = fields.Str(dump_only=True)
-
- @post_dump
- def load_markdown(self, data, **kwargs):
- practice_name = data['name'].replace(" ", "_")
-
- file_path = f"content/practices/{practice_name}.md"
- if os.path.exists(file_path):
- with open(file_path, "r", encoding="utf-8") as file:
- data["content"] = file.read()
- else:
- data["content"] = "Markdown file not found."
- return data
-
- class BookSchema(ma.Schema):
- class Meta:
- fields = ('id', 'name', 'description', 'author', 'year', 'bookUrl', 'videoUrl', 'isbn')
- ordered = True
-
-
- class DeveloperSchema(ma.Schema):
- class Meta:
- fields = ('developer', 'developerUrl')
- ordered = True
|