Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- """Borg model"""
- from serverapi.database import Column, Model, SurrogatePK, db
- from marshmallow_jsonapi import Schema, fields
- from marshmallow import validate
- not_blank = validate.Length(min=1, error='Field cannot be blank')
- def get_info_model():
- if Borg.query.count() == 0:
- info_model = Borg()
- info_model.save()
- else:
- info_model = Borg.query.first()
- return info_model
- class Borg(SurrogatePK, Model):
- """Borg model"""
- __tablename__ = 'borg'
- def __init__(self, **kwargs):
- """Create instance"""
- db.Model.__init__(self, **kwargs)
- class BorgSchema(Schema):
- id = fields.Integer(dump_only=True)
- # self links
- def get_top_level_links(self, data, many):
- if many:
- self_link = ""
- else:
- self_link = "/borg"
- return {'self': self_link}
- class Meta:
- type_ = 'borg'
- strict = True
- class BorgProcess(SurrogatePK, Model):
- """Borg Process Model"""
- __tablename__ = 'borg_process'
- name = Column(db.String(500))
- type = Column(db.String(500))
- source = Column(db.String(500))
- repo_name = Column(db.String(500))
- samba_user = Column(db.String(100))
- destination_host = Column(db.String(500))
- destination_user = Column(db.String(100))
- destination_password = Column(db.String(100))
- def __init__(self, request_dict, **kwargs):
- """Create instance"""
- self.name = request_dict['name']
- self.type = request_dict['type']
- self.source = request_dict['source']
- self.repo_name = request_dict['repo_name']
- self.samba_user = request_dict['samba_user']
- self.destination_host = request_dict['destination_host']
- self.destination_user = request_dict['destination_user']
- self.destination_password = request_dict['destination_password']
- db.Model.__init__(self, **kwargs)
- class BorgProcessSchema(Schema):
- id = fields.Integer(dump_only=True)
- name = fields.String(validate=not_blank)
- type = fields.String(validate=not_blank)
- source = fields.String(validate=not_blank)
- repo_name = fields.String(validate=not_blank)
- samba_user = fields.String(validate=not_blank)
- destination_host = fields.String(validate=not_blank)
- destination_user = fields.String(validate=not_blank)
- destination_password = fields.String(validate=not_blank)
- # self links
- def get_top_level_links(self, data, many):
- if many:
- self_link = "/borg/process"
- else:
- self_link = "/borg/process/{}".format(data['id'])
- return {'self': self_link}
- class Meta:
- type_ = 'borg_process'
- strict = True
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement