예제 #1
0
class Project(db.Document):

    title = db.StringField(required=True, max_length=40, min_length=2)
    description = db.StringField()
    created_by = db.ReferenceField('User',
                                   default=_current_user,
                                   required=True)
    created_at = db.DateTimeField(default=datetime.now, required=True)
    modified_at = db.DateTimeField(default=datetime.now, required=True)

    @property
    def url(self):
        return url_for('project.index', project_id=self.id)

    @property
    def queryset_post(self):
        return Post.objects(project=self)

    @property
    def queryset_project_user(self):
        return ProjectUser.objects(project=self)

    @property
    def owner(self):
        return self.created_by

    def invite(self, email):
        try:
            user = User.objects.get(email=email)
        except User.DoesNotExist:
            raise ProjectInvitationError('not user')
        if ProjectUser.objects(user=user, project=project).first():
            raise ProjectInvitationError('already member')
        return ProjectUser.objects(user=user, project=project).save()
예제 #2
0
class User(db.Document, UserMixin):
    email = db.StringField(max_length=255)
    password = db.StringField(max_length=255)
    active = db.BooleanField(default=True)
    confirmed_at = db.DateTimeField()
    roles = db.ListField(db.ReferenceField(Role), default=[])

    @property
    def queryset_project(self):
        return Project.objects(created_by=self)
예제 #3
0
class Post(db.Document):

    project = db.ReferenceField('Project',
                                required=True,
                                reverse_delete_rule=mongoengine.CASCADE)
    title = db.StringField(required=True)
    contents = db.StringField(required=True)
    created_by = db.ReferenceField('User',
                                   default=_current_user,
                                   required=True)
    created_at = db.DateTimeField(default=datetime.now, required=True)
    modified_at = db.DateTimeField(default=datetime.now, required=True)
예제 #4
0
class ProjectUser(db.Document):

    project = db.ReferenceField('Project',
                                required=True,
                                reverse_delete_rule=mongoengine.CASCADE)
    user = db.ReferenceField('User',
                             required=True,
                             reverse_delete_rule=mongoengine.CASCADE)
    last_visited_at = db.DateTimeField(default=datetime.now, required=True)
    role = db.StringField()
    created_at = db.DateTimeField(default=datetime.now, required=True)
예제 #5
0
class DocumentSets(db.Document):
    title = db.StringField(required=False, max_length=255, min_length=2)
예제 #6
0
class Role(db.Document, RoleMixin):
    name = db.StringField(max_length=80, unique=True)
    description = db.StringField(max_length=255)