<commit_before># -*- coding: utf-8 -*-

from werkzeug import cached_property
from sqlalchemy import event, DDL
from sqlalchemy.orm import deferred
from sqlalchemy.dialects.postgresql import TSVECTOR
from flask import url_for
from baseframe.staticdata import webmail_domains
from . import db, BaseMixin, POSTSTATUS
from .user import User
from .jobpost import JobPost

__all__ = ['Domain']


class Domain(BaseMixin, db.Model):
    """
    A DNS domain affiliated with a job post.
    """
    __tablename__ = 'domain'
    #: DNS name of this domain (domain.tld)
    name = db.Column(db.Unicode(80), nullable=False, unique=True)
    #: Title of the employer at this domain
    title = db.Column(db.Unicode(250), nullable=True)
    #: Legal title
    legal_title = db.Column(db.Unicode(250), nullable=True)
    #: Description
    description = db.Column(db.UnicodeText, nullable=True)
    #: Logo URL
    logo_url = db.Column(db.Unicode(250), nullable=True)
    #: Is this a known webmail domain?
    is_webmail = db.Column(db.Boolean, default=False, nullable=False)
    #: Is this domain banned from listing on Hasjob? (Recruiter, etc)
    is_banned = db.Column(db.Boolean, default=False, nullable=False)
    #: Who banned it?
    banned_by_id = db.Column(None, db.ForeignKey('user.id', ondelete='SET NULL'), nullable=True)
    banned_by = db.relationship(User)
    #: Banned when?
    banned_at = db.Column(db.DateTime, nullable=True)
    #: Reason for banning
    banned_reason = db.Column(db.Unicode(250), nullable=True)
    #: Jobposts using this domain
    jobposts = db.relationship(JobPost, lazy='dynamic', backref=db.backref('domain'))
    #: Search vector
    search_vector = deferred(db.Column(TSVECTOR, nullable=True))

    def __repr__(self):
        flags = [' webmail' if self.is_webmail else '', ' banned' if self.is_banned else '']
        return '<Domain %s%s>' % (self.name, ''.join(flags))

    @property
    def use_title(self):
        if self.title:
            return self.title
        post = self.jobposts.filter(JobPost.status.in_(POSTSTATUS.POSTPENDING)).order_by('datetime desc').first()
        if post:
            return post.company_name
        return self.name

    @property
    def has_profile(self):
        return bool(self.title and self.description)

    @cached_property
    def effective_logo_url(self):
        """
        Returns logo_url if present,
        else returns the logo from its most recent job post
        """
        if self.logo_url:
            return self.logo_url
        else:
            post = self.jobposts.filter(JobPost.company_logo != None,
                JobPost.status.in_(POSTSTATUS.ARCHIVED)).order_by('datetime desc').first()  # NOQA
            return post.url_for('logo', _external=True) if post else None

    def editor_is(self, user):
        """
        Is this user authorized to edit this domain?
        """
        if not user:
            return False
        if JobPost.query.filter_by(domain=self, user=user).filter(JobPost.status.in_(POSTSTATUS.POSTPENDING)).notempty():<commit_msg>Don't show post company name for webmail domains<commit_after># -*- coding: utf-8 -*-

from werkzeug import cached_property
from sqlalchemy import event, DDL
from sqlalchemy.orm import deferred
from sqlalchemy.dialects.postgresql import TSVECTOR
from flask import url_for
from baseframe.staticdata import webmail_domains
from . import db, BaseMixin, POSTSTATUS
from .user import User
from .jobpost import JobPost

__all__ = ['Domain']


class Domain(BaseMixin, db.Model):
    """
    A DNS domain affiliated with a job post.
    """
    __tablename__ = 'domain'
    #: DNS name of this domain (domain.tld)
    name = db.Column(db.Unicode(80), nullable=False, unique=True)
    #: Title of the employer at this domain
    title = db.Column(db.Unicode(250), nullable=True)
    #: Legal title
    legal_title = db.Column(db.Unicode(250), nullable=True)
    #: Description
    description = db.Column(db.UnicodeText, nullable=True)
    #: Logo URL
    logo_url = db.Column(db.Unicode(250), nullable=True)
    #: Is this a known webmail domain?
    is_webmail = db.Column(db.Boolean, default=False, nullable=False)
    #: Is this domain banned from listing on Hasjob? (Recruiter, etc)
    is_banned = db.Column(db.Boolean, default=False, nullable=False)
    #: Who banned it?
    banned_by_id = db.Column(None, db.ForeignKey('user.id', ondelete='SET NULL'), nullable=True)
    banned_by = db.relationship(User)
    #: Banned when?
    banned_at = db.Column(db.DateTime, nullable=True)
    #: Reason for banning
    banned_reason = db.Column(db.Unicode(250), nullable=True)
    #: Jobposts using this domain
    jobposts = db.relationship(JobPost, lazy='dynamic', backref=db.backref('domain'))
    #: Search vector
    search_vector = deferred(db.Column(TSVECTOR, nullable=True))

    def __repr__(self):
        flags = [' webmail' if self.is_webmail else '', ' banned' if self.is_banned else '']
        return '<Domain %s%s>' % (self.name, ''.join(flags))

    @property
    def use_title(self):
        if self.title:
            return self.title
        if self.is_webmail:
            return self.name
        post = self.jobposts.filter(JobPost.status.in_(POSTSTATUS.POSTPENDING)).order_by('datetime desc').first()
        if post:
            return post.company_name
        return self.name

    @property
    def has_profile(self):
        return bool(self.title and self.description)

    @cached_property
    def effective_logo_url(self):
        """
        Returns logo_url if present,
        else returns the logo from its most recent job post
        """
        if self.logo_url:
            return self.logo_url
        else:
            post = self.jobposts.filter(JobPost.company_logo != None,
                JobPost.status.in_(POSTSTATUS.ARCHIVED)).order_by('datetime desc').first()  # NOQA
            return post.url_for('logo', _external=True) if post else None

    def editor_is(self, user):
        """
        Is this user authorized to edit this domain?
        """
        if not user:
            return False
        if JobPost.query.filter_by(domain=self, user=user).filter(JobPost.status.in_(POSTSTATUS.POSTPENDING)).notempty():
{'fraction_non_alphanumeric': 0.11114680372630903, 'fraction_numerical': 0.004818503051718599, 'mean_word_length': 3.0487646293888164, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5413027', 'n_tokens_mistral': 1961, 'n_tokens_neox': 1895, 'n_words': 494}