Пример #1
0
class Participant(BaseMixin, db.Model):
    __tablename__ = 'participant'
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    user = db.relationship(User)
    event_id = db.Column(db.Integer, db.ForeignKey('event.id'), nullable=False)
    event = db.relationship(Event,
                            backref=db.backref('participants',
                                               cascade='all, delete-orphan'))
    status = db.Column(db.Integer,
                       default=PARTICIPANT_STATUS.PENDING,
                       nullable=False)
    mentor = db.Column(db.Boolean, default=False, nullable=False)
    reason_to_join = db.Column(db.UnicodeText, default=u'', nullable=False)
    email = db.Column(db.Unicode(80), default=u'', nullable=False)
    phone_no = db.Column(db.Unicode(15), default=u'', nullable=False)
    job_title = db.Column(db.Unicode(120), default=u'', nullable=False)
    company = db.Column(db.Unicode(1200), default=u'', nullable=False)

    def save_defaults(self):
        user = self.user
        user.phone_no = self.phone_no
        user.job_title = self.job_title
        user.company = self.company

    @classmethod
    def get(cls, user, event):
        return cls.query.filter_by(user=user).filter_by(event=event).first()
Пример #2
0
class Vote(BaseMixin, db.Model):
    __tablename__ = 'vote'
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    user = db.relationship(User,
                           primaryjoin=user_id == User.id,
                           backref=db.backref('votes',
                                              cascade="all, delete-orphan"))
    votespace_id = db.Column(db.Integer,
                             db.ForeignKey('votespace.id'),
                             nullable=False)
    votespace = db.relationship(VoteSpace,
                                primaryjoin=votespace_id == VoteSpace.id,
                                backref=db.backref(
                                    'votes', cascade="all, delete-orphan"))
    votedown = db.Column(db.Boolean, default=False, nullable=False)

    __table_args__ = (db.UniqueConstraint("user_id", "votespace_id"), {})
Пример #3
0
class Sponsor(BaseScopedNameMixin, db.Model):
    __tablename__ = 'sponsor'
    event_id = db.Column(db.Integer, db.ForeignKey('event.id'), nullable=False)
    event = db.relation(Event,
                        backref=db.backref('sponsors',
                                           cascade='all, delete-orphan'))
    parent = db.synonym('event')

    website = db.Column(db.Unicode(250), nullable=True)
    image_url = db.Column(db.Unicode(250), nullable=False)
    description = db.Column(db.UnicodeText, nullable=False)

    __table_args__ = (db.UniqueConstraint('name', 'event_id'), )
Пример #4
0
class EventRedirect(BaseMixin, db.Model):
    __tablename__ = "event_redirect"

    profile_id = db.Column(db.Integer,
                           db.ForeignKey('profile.id'),
                           nullable=False)
    profile = db.relationship(Profile)

    name = db.Column(db.Unicode(250), nullable=False)
    event_id = db.Column(None, db.ForeignKey('event.id'), nullable=False)
    event = db.relationship(Event,
                            backref=db.backref('redirects',
                                               cascade='all, delete-orphan'))

    __table_args__ = (db.UniqueConstraint(profile_id, name), )
Пример #5
0
class ProjectMember(BaseMixin, db.Model):
    __tablename__ = 'project_member'
    project_id = db.Column(db.Integer,
                           db.ForeignKey('project.id'),
                           nullable=False)
    # project = db.relationship(Project, backref=db.backref('members', cascade='all, delete-orphan'))
    participant_id = db.Column(db.Integer,
                               db.ForeignKey('participant.id'),
                               nullable=False)
    participant = db.relationship(
        Participant,
        backref=db.backref('projects', cascade='all, delete-orphan'))

    status = db.Column(db.Integer, nullable=False, default=0)
    role = db.Column(db.Unicode(250), nullable=False, default=u'')

    __table_args__ = (db.UniqueConstraint('project_id', 'participant_id'), )
Пример #6
0
class Participant(BaseMixin, db.Model):
    __tablename__ = 'participant'
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    user = db.relationship(User)
    event_id = db.Column(db.Integer, db.ForeignKey('event.id'), nullable=False)
    event = db.relationship(Event,
                            backref=db.backref('participants',
                                               cascade='all, delete-orphan'))
    status = db.Column(db.Integer,
                       default=PARTICIPANT_STATUS.PENDING,
                       nullable=False)
    mentor = db.Column(db.Boolean, default=False, nullable=False)
    reason_to_join = db.Column(db.UnicodeText, default=u'', nullable=False)
    email = db.Column(db.Unicode(80), default=u'', nullable=False)
    phone_no = db.Column(db.Unicode(15), default=u'', nullable=False)
    job_title = db.Column(db.Unicode(120), default=u'', nullable=False)
    company = db.Column(db.Unicode(1200), default=u'', nullable=False)
    skill_level = db.Column(db.Unicode(120), default=u'', nullable=False)

    NON_CONFIRMED_STATUSES = (PARTICIPANT_STATUS.PENDING,
                              PARTICIPANT_STATUS.WL)

    @classmethod
    def unconfirmed_for(cls, event):
        return cls.query.filter(
            cls.status.in_([PARTICIPANT_STATUS.PENDING,
                            PARTICIPANT_STATUS.WL]), cls.event == event).all()

    def save_defaults(self):
        user = self.user
        user.phone_no = self.phone_no
        user.job_title = self.job_title
        user.company = self.company

    def confirm(self):
        self.status = PARTICIPANT_STATUS.CONFIRMED

    @classmethod
    def get(cls, user, event):
        return cls.query.filter_by(user=user).filter_by(event=event).first()

    @property
    def is_participating(self):
        return self.status in (PARTICIPANT_STATUS.CONFIRMED,
                               PARTICIPANT_STATUS.ATTENDED)
Пример #7
0
class Sponsor(BaseScopedNameMixin, db.Model):
    __tablename__ = 'sponsor'
    event_id = db.Column(db.Integer, db.ForeignKey('event.id'), nullable=False)
    event = db.relation(Event,
                        backref=db.backref('sponsors',
                                           cascade='all, delete-orphan'))
    parent = db.synonym('event')

    website = db.Column(db.Unicode(250), nullable=True)
    image_url = db.Column(db.Unicode(250), nullable=False)
    description = db.Column(db.UnicodeText, nullable=False)

    __table_args__ = (db.UniqueConstraint('name', 'event_id'), )

    def url_for(self, action='view', _external=False):
        if action == 'view':
            return url_for('sponsor_view',
                           profile=self.event.profile.name,
                           event=self.event.name,
                           sponsor=self.name)
Пример #8
0
class ProjectMember(BaseMixin, db.Model):
    __tablename__ = 'project_member'
    project_id = db.Column(db.Integer,
                           db.ForeignKey('project.id'),
                           nullable=False)
    #: User who created this project
    user_id = db.Column(None, db.ForeignKey('user.id'), nullable=False)
    user = db.relationship(User,
                           backref=db.backref('project_memberships',
                                              cascade='all, delete-orphan'))

    status = db.Column(db.Integer, nullable=False, default=0)
    role = db.Column(db.Unicode(250), nullable=False, default=u'')

    __table_args__ = (db.UniqueConstraint('project_id', 'user_id'), )

    def permissions(self, user, inherited=None):
        perms = super(ProjectMember, self).permissions(user, inherited)

        if user is not None and user == self.project.user and self.user != user:
            perms.add('remove-member')
        return perms
Пример #9
0
class Project(BaseScopedIdNameMixin, db.Model):
    __tablename__ = 'project'
    event_id = db.Column(db.Integer, db.ForeignKey('event.id'), nullable=False)
    event = db.relation(Event,
                        backref=db.backref('projects',
                                           cascade='all, delete-orphan'))
    parent = db.synonym('event')

    #: Participant who created this project
    participant_id = db.Column(None,
                               db.ForeignKey('participant.id'),
                               nullable=False)
    participant = db.relationship(Participant)

    blurb = db.Column(db.Unicode(250), nullable=False)
    description = db.Column(db.UnicodeText, nullable=False)
    maximum_size = db.Column(db.Integer, default=0, nullable=False)
    #: Is the project owner participating?
    participating = db.Column(db.Boolean, nullable=False, default=True)

    members = db.relationship('ProjectMember',
                              backref='project',
                              lazy='dynamic')

    votes_id = db.Column(db.Integer,
                         db.ForeignKey('votespace.id'),
                         nullable=False)
    votes = db.relationship(VoteSpace, uselist=False)

    comments_id = db.Column(db.Integer,
                            db.ForeignKey('commentspace.id'),
                            nullable=False)
    comments = db.relationship(CommentSpace, uselist=False)

    __table_args__ = (db.UniqueConstraint('url_id', 'event_id'), )

    def __init__(self, **kwargs):
        super(Project, self).__init__(**kwargs)
        if not self.votes:
            self.votes = VoteSpace(type=0)
        if not self.comments:
            self.comments = CommentSpace()

    @property
    def user(self):
        return self.participant.user

    @property
    def participants(self):
        return set([self.participant] + [m.participant for m in self.members])

    @property
    def users(self):
        return set([self.user] + [m.participant.user for m in self.members])

    def owner_is(self, user):
        return self.user == user

    def getnext(self):
        return Project.query.filter(Project.event == self.event).filter(
            Project.id != self.id).filter(
                Project.created_at < self.created_at).order_by(
                    db.desc('created_at')).first()

    def getprev(self):
        return Project.query.filter(Project.event == self.event).filter(
            Project.id != self.id).filter(Project.created_at > self.created_at
                                          ).order_by('created_at').first()
Пример #10
0
class Comment(BaseScopedIdMixin, db.Model):
    __tablename__ = 'comment'
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=True)
    user = db.relationship(User,
                           primaryjoin=user_id == User.id,
                           backref=db.backref('comments', cascade="all"))
    commentspace_id = db.Column(db.Integer,
                                db.ForeignKey('commentspace.id'),
                                nullable=False)
    commentspace = db.relationship(
        CommentSpace,
        primaryjoin=commentspace_id == CommentSpace.id,
        backref=db.backref('comments', cascade="all, delete-orphan"))

    reply_to_id = db.Column(db.Integer,
                            db.ForeignKey('comment.id'),
                            nullable=True)
    children = db.relationship("Comment",
                               backref=db.backref("reply_to",
                                                  remote_side="Comment.id"))

    message = db.Column(db.Text, nullable=False)
    message_html = db.Column(db.Text, nullable=False)

    status = db.Column(db.Integer, default=0, nullable=False)

    votes_id = db.Column(db.Integer,
                         db.ForeignKey('votespace.id'),
                         nullable=False)
    votes = db.relationship(VoteSpace, uselist=False)

    edited_at = db.Column(db.DateTime, nullable=True)

    parent = db.synonym('commentspace')

    __table_args__ = (db.UniqueConstraint('url_id', 'commentspace_id'), )

    def __init__(self, **kwargs):
        super(Comment, self).__init__(**kwargs)
        self.votes = VoteSpace(type=SPACETYPE.COMMENT)

    def delete(self):
        """
        Delete this comment.
        """
        if len(self.children) > 0:
            self.status = COMMENTSTATUS.DELETED
            self.user = None
            self.message = ''
            self.message_html = ''
        else:
            if self.reply_to and self.reply_to.is_deleted:
                # If the parent comment is deleted, ask it to reconsider removing itself
                reply_to = self.reply_to
                reply_to.children.remove(self)
                db.session.delete(self)
                reply_to.delete()
            else:
                db.session.delete(self)

    @property
    def is_deleted(self):
        return self.status == COMMENTSTATUS.DELETED

    def sorted_children(self):
        return sorted(self.children, key=lambda child: child.votes.count)
Пример #11
0
class Project(BaseScopedIdNameMixin, db.Model):
    __tablename__ = 'project'
    event_id = db.Column(db.Integer, db.ForeignKey('event.id'), nullable=False)
    event = db.relation(Event,
                        backref=db.backref('projects',
                                           order_by=db.desc('url_id'),
                                           cascade='all, delete-orphan'))
    parent = db.synonym('event')

    #: User who is part of this project
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
    user = db.relationship(User, backref='projects')

    blurb = db.Column(db.Unicode(250), nullable=False)
    description = db.Column(db.UnicodeText, nullable=False)
    maximum_size = db.Column(db.Integer, default=0, nullable=False)
    #: Is the project owner participating?
    participating = db.Column(db.Boolean, nullable=False, default=True)

    members = db.relationship('ProjectMember', backref='project', uselist=True)

    votes_id = db.Column(db.Integer,
                         db.ForeignKey('votespace.id'),
                         nullable=False)
    votes = db.relationship(VoteSpace, uselist=False)

    comments_id = db.Column(db.Integer,
                            db.ForeignKey('commentspace.id'),
                            nullable=False)
    comments = db.relationship(CommentSpace, uselist=False)

    __table_args__ = (db.UniqueConstraint('url_id', 'event_id'), )

    def __init__(self, **kwargs):
        super(Project, self).__init__(**kwargs)
        if not self.votes:
            self.votes = VoteSpace(type=0)
        if not self.comments:
            self.comments = CommentSpace()

    @property
    def users(self):
        return set([self.user] + [m.user for m in self.members])

    participants = users

    def owner_is(self, user):
        return user is not None and self.user == user

    def getnext(self):
        return Project.query.filter(Project.event == self.event).filter(
            Project.id != self.id).filter(
                Project.created_at < self.created_at).order_by(
                    db.desc('created_at')).first()

    def getprev(self):
        return Project.query.filter(Project.event == self.event).filter(
            Project.id != self.id).filter(Project.created_at > self.created_at
                                          ).order_by('created_at').first()

    def url_for(self, action='view', _external=False):
        if action == 'view':
            return url_for('project_view',
                           profile=self.event.profile.name,
                           event=self.event.name,
                           project=self.url_name,
                           _external=_external)
        elif action == 'edit':
            return url_for('project_edit',
                           profile=self.event.profile.name,
                           event=self.event.name,
                           project=self.url_name,
                           _external=_external)
        elif action == 'delete':
            return url_for('project_delete',
                           profile=self.event.profile.name,
                           event=self.event.name,
                           project=self.url_name,
                           _external=_external)
        elif action == 'voteup':
            return url_for('project_voteup',
                           profile=self.event.profile.name,
                           event=self.event.name,
                           project=self.url_name,
                           _external=_external)
        elif action == 'votedown':
            return url_for('project_votedown',
                           profile=self.event.profile.name,
                           event=self.event.name,
                           project=self.url_name,
                           _external=_external)
        elif action == 'cancelvote':
            return url_for('project_cancelvote',
                           profile=self.event.profile.name,
                           event=self.event.name,
                           project=self.url_name,
                           _external=_external)
        elif action == 'prev':
            return url_for('project_view',
                           profile=self.event.profile.name,
                           event=self.event.name,
                           project=self.getprev().url_name,
                           _external=_external)
        elif action == 'next':
            return url_for('project_view',
                           profile=self.event.profile.name,
                           event=self.event.name,
                           project=self.getnext().url_name,
                           _external=_external)
        elif action == 'join':
            return url_for('project_join',
                           profile=self.event.profile.name,
                           event=self.event.name,
                           project=self.url_name,
                           _external=_external)