class UserProfile(Document, OwnedModelMixin, StreamedModelMixin): """The basic things a user profile tends to carry. Isolated in separate class to keep separate from private data. """ # Provided by OwnedModelMixin #owner_id = ObjectIdField(required=True) #owner_username = StringField(max_length=30, required=True) # streamable # provided by StreamedModelMixin now #created_at = MillisecondField() #updated_at = MillisecondField() # identity info name = StringField(max_length=255) email = EmailField(max_length=100) website = URLField(max_length=255) bio = StringField(max_length=100) location_text = StringField(max_length=100) avatar_url = URLField(max_length=255) _private_fields = [ 'owner_id', ] def __init__(self, *args, **kwargs): super(UserProfile, self).__init__(*args, **kwargs) def __unicode__(self): return u'%s' % (self.name)
class Author(EmbeddedDocument): _private_fields=['is_active'] _public_fields=['username', 'name'] name = StringField() username = StringField() email = EmailField() a_setting = BooleanField() is_active = BooleanField()
class Person(PyvotalEmbeddedDocument): """Class represents person with project membership. Available fields: +----------------------------------------+----------------------------------------+ |email |String | +----------------------------------------+----------------------------------------+ |name |String | +----------------------------------------+----------------------------------------+ |initials |String | +----------------------------------------+----------------------------------------+ """ email = EmailField() name = StringField() initials = StringField() _tagname = 'person'
class User(BaseModel): _public_fields = [ 'name', 'avatar_url', 'conversations_count', 'interests_count' ] STATUS_ACTIVE = 1 STATUS_PENDING = 2 STATUS_BLOCKED = 3 STATUS_REMOVED = 4 BUCKET_NAME = 'boardhood_profile_images' ALLOWED_IMAGES = set(['png', 'jpg', 'jpeg', 'gif']) id = IntField() name = StringField(max_length=45) email = EmailField() password = StringField() status = IntField() created_at = DateTimeField() updated_at = DateTimeField() avatar_url = URLField() conversations_count = IntField() interests_count = IntField() ip = StringField() timestamp = DateTimeField() def encrypt_password(self): self.password = bcrypt.hashpw(self.password, bcrypt.gensalt()) def to_self_dict(self): data = self.to_dict() data.update({'email': self.email}) return data @staticmethod def parse(row): if not row: return None return User(**row) @staticmethod def parse_all(rows): records = [] for row in rows: records.append(User.parse(row)) return records @staticmethod def create(user): try: cursor = User.cursor() user.encrypt_password() user.status = User.STATUS_ACTIVE user.validate() cursor.execute(CREATE, user.to_sqldict()) User.db.commit() user.id = cursor.fetchone()['id'] return user except ShieldException, e: raise ValidationException(e) except DatabaseError, e: if e.pgcode == '23505': raise UniqueViolationException(e) else: User.report_error(e, cursor) return False
class Comment(EmbeddedDocument): _public_fields=['username', 'text'] text = StringField() username = StringField() email = EmailField()
class User(Document): username = StringField(min_length=2, max_length=20, required=True) email = EmailField(max_length=30, required=True)