<commit_before>
from datetime import datetime
from sqlalchemy.ext.associationproxy import association_proxy
from sqlalchemy.dialects.postgresql import JSON
from sqlalchemy.orm import validates
from sqlalchemy import event

from bootstrap import db


association_table_license = db.Table('association_projects_licenses', db.metadata,
    db.Column('project_id', db.Integer, db.ForeignKey('project.id')),
    db.Column('license_id', db.Integer, db.ForeignKey('license.id'))
)


class Project(db.Model):
    """Represent a project.
    """
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100), unique=True)
    short_description = db.Column(db.String(400), unique=True)
    description = db.Column(db.String(), unique=True)
    website = db.Column(db.String())
    last_updated = db.Column(db.DateTime(), default=datetime.utcnow())

    # if cve_vendor is the empty string use the parent property
    # (organization.cve_vendor)
    cve_vendor = db.Column(db.String(), default='')
    cve_product = db.Column(db.String(), unique=True, nullable=False)

    automatic_release_tracking = db.Column(db.String())

    service_enabled = db.Column(db.Boolean(), default=False)
    notification_email = db.Column(db.String(), default='')
    required_informations = db.Column(JSON, default=None)

    # foreign keys
    organization_id = db.Column(db.Integer(), db.ForeignKey('organization.id'))
    manager_id = db.Column(db.Integer(), db.ForeignKey('user.id'))
    icon_url = db.Column(db.String(), db.ForeignKey('icon.url'), default=None)

    # relationships
    code_locations = db.relationship('Code', backref='project', lazy='dynamic',
                               cascade='all,delete-orphan')
    tag_objs = db.relationship('Tag', back_populates='project',
                               cascade='all,delete-orphan',
                               lazy=False,
                               foreign_keys='[Tag.project_id]')
    tags = association_proxy('tag_objs', 'text')
    licenses = db.relationship("License",
                            secondary=lambda: association_table_license,
                            backref="projects")
    cves = db.relationship('CVE', backref='project', lazy='dynamic',
                               cascade='all,delete-orphan')
    releases = db.relationship('Release', backref='project', lazy='dynamic',
                               cascade='all,delete-orphan')

    @validates('name')
    def validates_name(self, key, value):
        assert len(value) <= 100, \
            AssertionError("maximum length for name: 100")
        return value.replace(' ', '').strip()<commit_msg>Sort the releases of projects by the date of publication.<commit_after>
from datetime import datetime
from sqlalchemy.ext.associationproxy import association_proxy
from sqlalchemy.dialects.postgresql import JSON
from sqlalchemy.orm import validates
from sqlalchemy import event, desc

from bootstrap import db


association_table_license = db.Table('association_projects_licenses', db.metadata,
    db.Column('project_id', db.Integer, db.ForeignKey('project.id')),
    db.Column('license_id', db.Integer, db.ForeignKey('license.id'))
)


class Project(db.Model):
    """Represent a project.
    """
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100), unique=True)
    short_description = db.Column(db.String(400), unique=True)
    description = db.Column(db.String(), unique=True)
    website = db.Column(db.String())
    last_updated = db.Column(db.DateTime(), default=datetime.utcnow())

    # if cve_vendor is the empty string use the parent property
    # (organization.cve_vendor)
    cve_vendor = db.Column(db.String(), default='')
    cve_product = db.Column(db.String(), unique=True, nullable=False)

    automatic_release_tracking = db.Column(db.String())

    service_enabled = db.Column(db.Boolean(), default=False)
    notification_email = db.Column(db.String(), default='')
    required_informations = db.Column(JSON, default=None)

    # foreign keys
    organization_id = db.Column(db.Integer(), db.ForeignKey('organization.id'))
    manager_id = db.Column(db.Integer(), db.ForeignKey('user.id'))
    icon_url = db.Column(db.String(), db.ForeignKey('icon.url'), default=None)

    # relationships
    code_locations = db.relationship('Code', backref='project', lazy='dynamic',
                               cascade='all,delete-orphan')
    tag_objs = db.relationship('Tag', back_populates='project',
                               cascade='all,delete-orphan',
                               lazy=False,
                               foreign_keys='[Tag.project_id]')
    tags = association_proxy('tag_objs', 'text')
    licenses = db.relationship("License",
                            secondary=lambda: association_table_license,
                            backref="projects")
    cves = db.relationship('CVE', backref='project', lazy='dynamic',
                               cascade='all,delete-orphan')
    releases = db.relationship('Release', backref='project', lazy='dynamic',
                               cascade='all,delete-orphan',
                               order_by=desc('Release.published_at'))

    @validates('name')
    def validates_name(self, key, value):
        assert len(value) <= 100, \
            AssertionError("maximum length for name: 100")
        return value.replace(' ', '').strip()
{'fraction_non_alphanumeric': 0.13223902618959793, 'fraction_numerical': 0.004426410918480265, 'mean_word_length': 3.0621722846441948, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2328717', 'n_tokens_mistral': 1593, 'n_tokens_neox': 1514, 'n_words': 296}