class Group(Model, MongoRepository): id = Property(str, required=True, generator=create_uuid_generator('U')) name = Property(str, required=True, validators=[NotEmpty, Regexp('[A-Za-z0-9-_]')], index=UniqueIndex) users = Property(list, sub_type=User)
class User(Model, MongoRepository, Service, IdentityMixin): id = Property(str, required=True, generator=create_uuid_generator('U')) name = Property(str, required=True, validators=[NotEmpty, Regexp('[A-Za-z0-9-_]')], index=UniqueIndex) password = Property(str, required=True, validators=[NotEmpty], converter=content_hasher(rounds=10), omit=True) description = Property(str, index=TextIndex) roles = Property(list, sub_type=str) created = Property(datetime, required=True, validators=[Past], generator=date_now_generator) last_login = Property(datetime, marshaller=TimestampMarshaller) sequence = Property(int, index=Index) @link(rel='change_password', http_method='POST', require=[CurrentSubject(), Role('admin')]) def change_p(self, current_password, new_password): if not pbkdf2_sha256.verify(current_password, self.password): raise ServiceException(403, _('Current password is not correct')) else: self.password = new_password self.save() return _('Password changed') @link(require=Anonymous()) def get_description(self): return self.description
class Portfolio(Model, MongoRepository): id = Property(str, required=True, generator=create_uuid_generator('P')) name = Property(str, required=True, validators=[NotEmpty, Regexp('[A-Za-z0-9-_]')], index=UniqueIndex) stocks = Property(list, sub_type=Stock, validators=NotEmpty) owner = Property(User, required=False)
class ExampleClass(Model): just_numbers = Property(str, required=True, validators=[Regexp('^[0-9]+$')]) future_field = Property(datetime, validators=[Future]) email = Property(str, validators=Email) distance = Property(int, validators=[Min(10), Max(15)]) numbers = Property(list, validators=Unique)
class User(Model, MongoRepository, Service): id = Property(str, required=True, generator=uuid_generator('U')) name = Property(str, required=True, validators=[NotEmpty, Regexp('[A-Za-z0-9-_]')]) password = Property(str, required=True, validators=[NotEmpty]) description = Property(str) roles = Property(list, sub_type=str) created = Property(datetime, required=True, validators=[Past], generator=date_now_generator)
class Stock(Model): code = Property(str, required=True, validators=[NotEmpty, Regexp('[A-Za-z0-9-_]'), Max(4)], index=UniqueIndex) open = Property(float, required=True, validators=[Min(0)]) updated = Property(datetime, required=True, validators=[Past], generator=date_now_generator) history = Property(list, sub_type=int) sequence = Property(int, validators=[Min(1), Max(100)])
class User(Model, MongoRepository, Service): id = Property(str) name = Property(str, required=True, index=UniqueIndex) email = Property(str, validators=[Email], index=UniqueIndex) password = Property(str, validators=[Regexp('(?=.{8,})')], converter=content_hasher(), omit=True) roles = Property(list, sub_type=str, default_value=['Login']) @link(http_method='POST', require=[CurrentSubject(), Role('admin')]) def change_password(self, current_password, new_password): if not pbkdf2_sha256.verify(current_password, self.password): raise ServiceException(403, _('Current password is not correct')) else: self.password = new_password self.save() return _('Password changed') @link(require=Anonymous()) def get_description(self): return self.description
class ExampleClass(Model): just_numbers = Property(str, required=True, validators=[Regexp('^[0-9]+$')]) future_field = Property(datetime, validators=[Future])