import sys from freenit.schemas.base import BaseSchema from freenit.schemas.paging import PageOutSchema from marshmallow import fields class PlanSchema(BaseSchema): id = fields.Integer(description='ID', dump_only=True) name = fields.String() memory = fields.Integer() PageOutSchema(PlanSchema, sys.modules[__name__])
def create_app(config, app_name, app=None, auth={}, schemas={}): if app is None: app = Flask(__name__) app.config.from_object(config) app.models = f'{app_name}.models' @app.route('/media/<path:path>') def send_media(path): fullPath = f"../{app.config['MEDIA_PATH']}/{path}" try: return send_file(fullPath) except FileNotFoundError: return 'No such file', 404 app.sendmail = lambda to, message: sendmail(app.config, to, message) app.collect = Collect(app) db.init_app(app) app.db = db user_module = auth.get('user', None) if user_module is None: from .models.user import User else: User = import_module(user_module).User role_module = auth.get('role', None) if role_module is None: from .models.role import Role, UserRoles else: role_module_imported = import_module(role_module) Role = role_module_imported.Role UserRoles = role_module_imported.UserRoles app.user_datastore = PeeweeUserDatastore( app.db, User, Role, UserRoles, ) user_module = schemas.get('user', None) if user_module is None: class UserSchema(freenit.schemas.user.BaseUserSchema): pass else: UserSchema = import_module(user_module).UserSchema setattr(freenit.schemas.user, 'UserSchema', UserSchema) PageOutSchema(UserSchema, sys.modules['freenit.schemas.user']) role_module = schemas.get('role', None) if role_module is None: class RoleSchema(freenit.schemas.role.BaseRoleSchema): pass else: RoleSchema = import_module(role_module).RoleSchema setattr(freenit.schemas.role, 'RoleSchema', RoleSchema) PageOutSchema(RoleSchema, sys.modules['freenit.schemas.role']) app.security = Security(app, app.user_datastore) app.jwt = JWTManager(app) create_api(app) app.cors = CORS(app, supports_credentials=True) cli.register(app) return app
import sys from freenit.schemas.base import BaseSchema from freenit.schemas.paging import PageOutSchema from marshmallow import fields from .user import UserSchema class BlogSchema(BaseSchema): id = fields.Integer(description='ID', dump_only=True) author = fields.Nested(UserSchema, dump_only=True) content = fields.Str(description='Content') date = fields.Str( description='Time when blog was created', # format='YYYY-MM-DDThh:mm:ssTZD', dump_only=True, ) published = fields.Boolean(description='Published', default=False) slug = fields.String(description='Slug', dump_only=True) title = fields.String(description='Title', required=True) image = fields.String(description='Image url') PageOutSchema(BlogSchema, sys.modules[__name__])
import sys from freenit.schemas.base import BaseSchema from freenit.schemas.paging import PageOutSchema from marshmallow import fields class EventSchema(BaseSchema): id = fields.Integer(description='ID', dump_only=True) year = fields.Integer(description='Year') published = fields.Boolean() PageOutSchema(EventSchema, sys.modules[__name__])
import sys from freenit.schemas.base import BaseSchema from freenit.schemas.paging import PageOutSchema from marshmallow import fields class InstanceSchema(BaseSchema): id = fields.Number(dump_only=True) cpus = fields.Number(dump_only=True) curmem = fields.Number(dump_only=True) hostname = fields.String(dump_only=True) ip = fields.String() name = fields.String() ostype = fields.String(dump_only=True) path = fields.String(dump_only=True) pcpu = fields.Number(dump_only=True) ram = fields.Number(dump_only=True) state = fields.String(dump_only=True) hypervisor = fields.String(dump_only=True) vnc = fields.String(dump_only=True) PageOutSchema(InstanceSchema, sys.modules[__name__])
from marshmallow import fields, pre_dump from ..date import datetime_format, peewee_datetime_format from .event import EventSchema class TalkSchema(BaseSchema): id = fields.Integer(description='ID', dump_only=True) description = fields.String(description='Short talk description') duration = fields.Integer(description='duration') end = fields.DateTime(format=datetime_format, dump_only=True) event = fields.Nested(EventSchema, dump_only=True) hall = fields.String(description='Hall name') published = fields.Boolean() start = fields.DateTime(format=datetime_format) text = fields.String(description='Long talk description') title = fields.String(description='Talk title') user = fields.Nested(UserSchema, dump_only=True) video = fields.String(description='Talk video') @pre_dump def convert_date(self, data, many): start = getattr(data, 'start', None) newdata = copy(data) if isinstance(start, str): newdata.start = datetime.strptime(start, peewee_datetime_format) return newdata PageOutSchema(TalkSchema, sys.modules[__name__])
import sys from freenit.schemas.base import BaseSchema from freenit.schemas.paging import PageOutSchema from marshmallow import fields class MedicCountSchema(BaseSchema): total = fields.Integer(description='Count', dump_only=True) class MedicSchema(BaseSchema): id = fields.Integer(description='ID', dump_only=True) academic = fields.Str(description='Academic') city = fields.Str(description='City') name = fields.Str(description='Name') specialty = fields.Str(description='Specialty') title = fields.Str(description='Title') PageOutSchema(MedicSchema, sys.modules[__name__])
data = fields.List(fields.Nested(GalleryFileSchema)) pages = fields.Number() total = fields.Number() class GalleryAlbumSchema(BaseSchema): id = fields.Integer(description='ID', dump_only=True) name = fields.String(description='Album name') prefix = fields.String(description='Prefix') files = fields.Nested(GalleryFilePaginatedSchema) class GalleryUploadSchema(BaseSchema): file = Upload(load_only=True) filename = fields.String(dump_only=True) class ResumableGalleryUploadSchema(BaseSchema): resumableChunkNumber = fields.Integer() resumableChunkSize = fields.Integer() resumableCurrentChunkSize = fields.Integer() resumableFilename = fields.String() resumableIdentifier = fields.String() resumableRelativePath = fields.String() resumableTotalChunks = fields.Integer() resumableTotalSize = fields.Integer() resumableType = fields.String() PageOutSchema(GalleryAlbumSchema, sys.modules[__name__])
import sys from marshmallow import fields from freenit.schemas.base import BaseSchema from freenit.schemas.paging import PageOutSchema from .event import EventSchema class HallSchema(BaseSchema): id = fields.Integer(description='ID', dump_only=True) name = fields.String(description='Hall name') event = fields.Nested(EventSchema, dump_only=True) PageOutSchema(HallSchema, sys.modules[__name__])
from marshmallow import fields, pre_dump from ..date import datetime_format, peewee_datetime_format from .event import EventSchema from .user import UserSchema class TicketSchema(BaseSchema): id = fields.Integer(description='ID', dump_only=True) canceled = fields.Boolean(description='Canceled', default=False) event = fields.Nested(EventSchema, dump_only=True) identifier = fields.String(description='Identifier') visitor = fields.Nested(UserSchema, dump_only=True) date = fields.DateTime( description='Time when blog was created', format=datetime_format, dump_only=True, ) @pre_dump def convert_date(self, data, many): date = getattr(data, 'date', None) newdata = copy(data) if isinstance(date, str): print(date, peewee_datetime_format) newdata.date = datetime.strptime(date, peewee_datetime_format) return newdata PageOutSchema(TicketSchema, sys.modules[__name__])
import sys from freenit.schemas.base import BaseSchema from freenit.schemas.paging import PageOutSchema from marshmallow import fields from .event import EventSchema class CfSSchema(BaseSchema): id = fields.Integer(description='ID', dump_only=True) email = fields.Email(description='CfS email') organization = fields.String(description='CfS organization') message = fields.String(description='CfS Message') event = fields.Nested(EventSchema, dump_only=True) PageOutSchema(CfSSchema, sys.modules[__name__])
import sys from freenit.schemas.base import BaseSchema from freenit.schemas.paging import PageOutSchema from marshmallow import fields class SocialCountSchema(BaseSchema): total = fields.Integer(description='Count', dump_only=True) class SocialSchema(BaseSchema): id = fields.Integer(description='ID', dump_only=True) specialty = fields.Str(description='Specialty') name = fields.Str(description='Name') PageOutSchema(SocialSchema, sys.modules[__name__])