Ejemplo n.º 1
0
class Challenge(DB.Model):
    """
    Challenge model

    A challenge an event participant has to solve. A challenge is always associated with a
    category and is composed of a (relatively) short name, an arbitrarily long description (which
    might include nothing at all, or a very complex, multi-chapter backstory, and a number of points
    to be awarded upon challenge completion.

    A challenge may also be hidden from event participants if it is for example in a draft stage or
    simply not yet released.
    """

    __tablename__ = 'Challenges'

    id = DB.Column(DB.Integer, primary_key=True)
    """The unique ID of the challenge. Should be generated by the database. Used as primary key."""
    category_id = DB.Column(DB.Integer,
                            ForeignKey('Categories.id'),
                            nullable=True)
    """The ID of the category the challenge belongs to. Used as foreign key."""
    name = DB.Column(DB.String(255), index=True)
    """The name of the challenge. Max 255 characters."""
    description = DB.Column(DB.Text())
    """The description of the event. Can be arbitrarily long."""
    points = DB.Column(DB.Integer)
    """The number of points the challenge is worth."""
    hidden = DB.Column(DB.Boolean)
    """Whether or not the challenge should be visible by the event participants."""

    flags = relationship('Flag', lazy='joined')

    category = relationship('Category', lazy='joined')

    category = relationship('Category', lazy='select')

    submissions = relationship('Submission', lazy='noload')

    solves = relationship(
        'Submission',
        primaryjoin="and_(Challenge.id==Submission.challenge_id,"
        "     Submission.is_correct == True)")

    is_solved: bool

    def __repr__(self):
        return '<Challenge id:{} category_id:{} name:{} description:{} points:{}>'\
            .format(self.id, self.category_id, self.name, self.description, self.points)

    def __eq__(self, other):
        return self.id == other.id and \
               self.category_id == other.category_id and \
               self.name == other.name and \
               self.description == other.description and \
               self.points == other.points and \
               self.hidden == other.hidden
Ejemplo n.º 2
0
class Event(DB.Model):
    """
    Event model

    The core of the application. An event's only defining characteristic is its name, which must be
    unique (i.e. 'CS Games 2019', 'United CTF 2019', etc). The rest is all handled by relations with
    the application's other models.
    """

    __tablename__ = 'Events'

    id = DB.Column(DB.Integer, primary_key=True)
    """The unique ID of the event. Should be generated by the database. Used as primary key."""
    name = DB.Column(DB.String(64), index=True, unique=True)
    """The name of the event. Max 64 characters."""
    front_page = DB.Column(DB.Text())
    """The front page content of the event. Markdown text that will be parsed by frontend."""
    teams = DB.Column(DB.Boolean)
    """Whether participants have to register as teams or individually."""
    url = DB.Column(DB.String(255), default="")
    """The URL of the event."""
    flag_format = DB.Column(DB.String(64), default="")
    """The flag format used by most challenges."""
    is_open = DB.Column(DB.Boolean, default=False)
    """Whether flag submission is open or not."""
    is_visible = DB.Column(DB.Boolean, default=False)
    """Whether the event is currently visible or not."""

    event_administrators = relationship('EventAdministrator',
                                        back_populates='event')
    administrators = association_proxy('event_administrators', 'administrator')

    def __repr__(self):
        return '<Event id:{} name:{} teams: {}>'.format(
            self.id, self.name, self.teams)

    def __eq__(self, other):
        return self.id == other.id and \
               self.name == other.name and \
               self.front_page == other.front_page and \
               self.teams == other.teams and \
               self.url == other.url and \
               self.flag_format == other.flag_format and \
               self.is_open == other.is_open and \
               self.is_visible == other.is_visible