Ejemplo n.º 1
0
class Account(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    nickname = db.Column(db.String(20), nullable=False)
    password_hash = db.Column(db.String(128))
    solved_or_rating = db.Column(db.Integer, nullable=False, default=0)
    submitted_or_max_rating = db.Column(db.Integer, nullable=False, default=0)
    update_status = db.Column(db.Integer, default=1, index=True)
    oj_name = db.Column(db.String(20), nullable=False)
    last_update_time = db.Column(db.DateTime)
    # connect to User
    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    user = db.relationship('User',
                           backref=db.backref('account', lazy='dynamic'))

    def __init__(self, oj_name, nickname, password_or_oj_id, user):
        self.oj_name = oj_name
        self.nickname = nickname
        self.password = password_or_oj_id
        self.user = user
        self.last_update_time = datetime.datetime.min

    @property
    def password(self):
        return security.decrypt(self.password_hash).decode('utf-8')

    @password.setter
    def password(self, value):
        self.password_hash = security.encrypt(value.encode('utf-8'))

    def __repr__(self):
        return '<%s Account %s>: %d / %d' % (self.oj_name, self.nickname,
                                             self.solved_or_rating,
                                             self.submitted_or_max_rating)

    def set_problem_count(self, v1, v2):
        self.solved_or_rating = v1
        self.submitted_or_max_rating = v2

    def get_problem_count(self):
        if self.oj_name in ['cf', 'bc']:
            return {
                'rating': self.solved_or_rating,
                'max_rating': self.submitted_or_max_rating
            }
        else:
            return {
                'solved': self.solved_or_rating,
                'submitted': self.submitted_or_max_rating
            }

    def save(self):
        db.session.add(self)
        db.session.commit()

    def delete(self):
        db.session.delete(self)
        db.session.commit()
Ejemplo n.º 2
0
class News(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100), nullable=False)
    url = db.Column(db.String(100), nullable=True)
    shortcut = db.Column(db.Text)
    content = db.Column(db.Text)
    last_update_time = db.Column(db.DateTime)
    is_top = db.Column(db.SmallInteger, default=0)
    is_draft = db.Column(db.SmallInteger, default=0)
    #rank = db.Column(db.Integer, default=0)
    # connect to User
    user_id = db.Column(db.Integer,
                        db.ForeignKey('user.id', ondelete="SET NULL"))
    user = db.relationship('User', backref=db.backref('news', lazy='dynamic'))
    # connect to Tag
    tags = db.relationship('Tag',
                           secondary=new_stags,
                           backref=db.backref('news', lazy='dynamic'))

    @property
    def md_shortcut(self):
        return mdFilter.markdown(self.shortcut)

    @md_shortcut.setter
    def md_shortcut(self, data):
        self.shortcut = data

    @property
    def md_content(self):
        return mdFilter.markdown(self.content)

    @md_content.setter
    def md_content(self, data):
        self.content = data

    def __init__(self, title, url, is_top, user):
        self.title = title
        self.url = url
        self.user = user
        self.is_top = is_top
        self.last_update_time = datetime.datetime.now()

    @property
    def serialize(self):
        return {c.name: getattr(self, c.name) for c in self.__table__.columns}

    def __repr__(self):
        return '<News>'

    def save(self):
        db.session.add(self)
        db.session.commit()

    def delete(self):
        db.session.delete(self)
        db.session.commit()
Ejemplo n.º 3
0
class SolutionArticle(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100), nullable=False)
    shortcut = db.Column(db.Text)
    content = db.Column(db.Text)
    problem_oj_name = db.Column(db.String(20))
    problem_pid = db.Column(db.String(12))
    last_update_time = db.Column(db.DateTime)
    is_top = db.Column(db.SmallInteger, default=0)
    is_draft = db.Column(db.SmallInteger, default=0)
    #rank = db.Column(db.Integer, default=0)
    # connect to User
    user_id = db.Column(db.Integer, db.ForeignKey('user.id', ondelete="SET NULL"), nullable=True)
    user = db.relationship('User', backref=db.backref('solution', lazy='dynamic'))
    # connect to Tag
    tags = db.relationship('Tag', secondary=solution_tags,backref=db.backref('solutions', lazy='dynamic'))


    @property
    def md_shortcut(self):
        return mdFilter.markdown(self.shortcut)

    @md_shortcut.setter
    def md_shortcut(self, data):
        self.shortcut = data

    @property
    def md_content(self):
        return mdFilter.markdown(self.shortcut+self.content)

    @md_content.setter
    def md_content(self, data):
        self.content = data

    def __init__(self, title, user):
        self.title = title
        self.user = user
        self.last_update_time = datetime.datetime.now()

    def __repr__(self):
        return '<Article>'


    def save(self):
        db.session.add(self)
        db.session.commit()

    def delete(self):
        db.session.delete(self)
        db.session.commit()
Ejemplo n.º 4
0
class Submit(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    pro_id = db.Column(db.String(12))
    run_id = db.Column(db.String(20))
    submit_time = db.Column(db.DateTime, index=True)
    run_time = db.Column(db.Integer)
    memory = db.Column(db.Integer)
    lang = db.Column(db.String(50))
    result = db.Column(db.String(100))
    code = db.Column(db.Text)
    update_status = db.Column(db.Integer)
    oj_name = db.Column(db.String(20), nullable=False)
    user_name = db.Column(db.String(25), nullable=True)
    # connect to Account

    user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
    user = db.relationship('User',
                           backref=db.backref('submit', lazy='dynamic'))

    def __init__(self, pro_id, account):
        self.pro_id = pro_id
        self.user = account.user
        self.oj_name = account.oj_name
        self.user_name = account.user.name
        self.update_status = 0

    def update_info(self, run_id, submit_time, run_time, memory, lang, code,
                    result):
        self.code = code
        self.run_id = run_id
        self.submit_time = submit_time
        self.run_time = run_time
        self.memory = memory
        self.lang = lang
        self.result = result
        self.save()

    def __repr__(self):
        return u'User:"******" \tProblemID : {1} \tRUNID : {2}'.format(
            self.user_name, self.pro_id, self.run_id)

    def save(self):
        db.session.add(self)
        db.session.commit()

    def delete(self):
        db.session.delete(self)
        db.session.commit()
Ejemplo n.º 5
0
class Resource(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    filename = db.Column(db.String(50), nullable=False)
    name = db.Column(db.String(50),
                     nullable=False,
                     unique=True,
                     default='UNTITLED')
    description = db.Column(db.Text)
    type = db.Column(db.Integer, nullable=False)
    level = db.Column(db.Integer,
                      nullable=False,
                      default=ResourceLevel.PRIVATE)
    usage = db.Column(db.Integer,
                      nullable=False,
                      default=ResourceUsage.OTHER_RES)
    upload_time = db.Column(db.DateTime)

    # connect to User
    user_id = db.Column(db.Integer,
                        db.ForeignKey('user.id', ondelete="SET NULL"),
                        nullable=True)
    user = db.relationship('User',
                           backref=db.backref('resource', lazy='dynamic'))

    def __repr__(self):
        return '<Resource>@' + self.name.encode('utf-8')

    @property
    def file_type(self):
        return unicode(self.filename).split('.')[-1]

    @property
    def serialize(self):
        return {c.name: getattr(self, c.name) for c in self.__table__.columns}

    def save(self):
        db.session.add(self)
        db.session.commit()

    def delete(self):
        db.session.delete(self)
        db.session.commit()
Ejemplo n.º 6
0
# -*- coding: utf-8 -*-
from __init__ import *
from util import mdFilter
import datetime
from dao.db import db

# Table of Article
solution_tags = db.Table('solution_tags',
    db.Column('tag_id', db.Integer, db.ForeignKey('tag.id', ondelete="CASCADE")),
    db.Column('solution_id', db.Integer, db.ForeignKey('solution_article.id', ondelete="CASCADE"))
)

solution_submits = db.Table('solution_submits',
    db.Column('submit_id', db.Integer, db.ForeignKey('submit.id')),
    db.Column('solution_id', db.Integer, db.ForeignKey('solution_article.id'))
)


class SolutionArticle(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100), nullable=False)
    shortcut = db.Column(db.Text)
    content = db.Column(db.Text)
    problem_oj_name = db.Column(db.String(20))
    problem_pid = db.Column(db.String(12))
    last_update_time = db.Column(db.DateTime)
    is_top = db.Column(db.SmallInteger, default=0)
    is_draft = db.Column(db.SmallInteger, default=0)
    #rank = db.Column(db.Integer, default=0)
    # connect to User
    user_id = db.Column(db.Integer, db.ForeignKey('user.id', ondelete="SET NULL"), nullable=True)
Ejemplo n.º 7
0
# -*- coding: utf-8 -*-
from __init__ import *
from util import mdFilter
from dao.db import db

honor_users = db.Table(
    'honor_users',
    db.Column('honor_id', db.Integer,
              db.ForeignKey('honor.id', ondelete="CASCADE")),
    db.Column('user_id', db.Integer,
              db.ForeignKey('user.id', ondelete="CASCADE")))

honor_resources = db.Table(
    'honor_resources',
    db.Column('honor_id', db.Integer,
              db.ForeignKey('honor.id', ondelete="CASCADE")),
    db.Column('resource_id', db.Integer,
              db.ForeignKey('resource.id', ondelete="CASCADE")))


class Honor(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    contest_name = db.Column(db.String(64), nullable=False)
    contest_level = db.Column(db.Integer, nullable=False, default=0)
    acquire_time = db.Column(db.DateTime, nullable=False)
    team_name = db.Column(db.String(64))
    introduce = db.Column(db.Text)

    # connect to Resource
    resources = db.relationship('Resource',
                                secondary=honor_resources,
Ejemplo n.º 8
0
# -*- coding: utf-8 -*-
from __init__ import *
from util import mdFilter
import datetime
from dao.db import db

# Table of Article
new_stags = db.Table(
    'news_tags',
    db.Column('tag_id', db.Integer, db.ForeignKey('tag.id',
                                                  ondelete="CASCADE")),
    db.Column('news_id', db.Integer,
              db.ForeignKey('news.id', ondelete="CASCADE")))


class News(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(100), nullable=False)
    url = db.Column(db.String(100), nullable=True)
    shortcut = db.Column(db.Text)
    content = db.Column(db.Text)
    last_update_time = db.Column(db.DateTime)
    is_top = db.Column(db.SmallInteger, default=0)
    is_draft = db.Column(db.SmallInteger, default=0)
    #rank = db.Column(db.Integer, default=0)
    # connect to User
    user_id = db.Column(db.Integer,
                        db.ForeignKey('user.id', ondelete="SET NULL"))
    user = db.relationship('User', backref=db.backref('news', lazy='dynamic'))
    # connect to Tag
    tags = db.relationship('Tag',