<commit_before># Copyright (C) 2013 Google Inc., authors, and contributors <see AUTHORS file>
# Licensed under http://www.apache.org/licenses/LICENSE-2.0 <see LICENSE file>
# Created By:
# Maintained By: <EMAIL>

from ggrc import db
from .mixins import deferred, BusinessObject
from .object_document import Documentable
from .object_person import Personable
from sqlalchemy.orm import validates

class Response(BusinessObject, db.Model):
  __tablename__ = 'responses'

  VALID_STATES = (u'Assigned', u'Accepted', u'Completed')
  VALID_TYPES = (u'documentation', u'interview', u'population sample')
  request_id = deferred(
      db.Column(db.Integer, db.ForeignKey('requests.id'), nullable=False),
      'Response')
  response_type = deferred(db.Column(db.Enum(VALID_TYPES), nullable = False), 'Response')
  status = deferred(db.Column(db.Enum(VALID_STATES), nullable = False), 'Response')

  _publish_attrs = [
      'request',
      'status',
      'response_type',
      ]
  _sanitize_html = [
      ]

  @classmethod
  def eager_query(cls):
    from sqlalchemy import orm

    query = super(Response, cls).eager_query()
    return query.options(
        orm.joinedload('request'))

class DocumentationResponse(Documentable, Personable, Response):
  __mapper_args__ = {
      'polymorphic_identity': 'documentation'
      }
  _table_plural = 'documentation_responses'

  evidence = db.relationship('Evidence', backref='response', cascade='all, delete-orphan')

  _publish_attrs = [
    'evidence',
      ]
  _sanitize_html = [
      ]

  @validates('response_type')
  def validates_response_type(self, key, value):
    return 'population sample'

  @classmethod
  def eager_query(cls):
    from sqlalchemy import orm

    query = super(DocumentationResponse, cls).eager_query()
    return query.options(
        orm.subqueryload('evidence'))

class InterviewResponse(Documentable, Personable, Response):
  __mapper_args__ = {
      'polymorphic_identity': 'interview'
      }
  _table_plural = 'interview_responses'
  _publish_attrs = [
    #'meetings',
      ]
  _sanitize_html = [
      ]

  @validates('response_type')
  def validates_response_type(self, key, value):
    return 'population sample'

  @classmethod
  def eager_query(cls):
    from sqlalchemy import orm

    query = super(InterviewResponse, cls).eager_query()
    return query.options()
        #orm.subqueryload('meetings'))

class PopulationSampleResponse(Documentable, Personable, Response):
  __mapper_args__ = {
      'polymorphic_identity': 'population sample'
      }
  _table_plural = 'population_sample_responses'

  population_worksheet = deferred(db.Column(db.String, nullable=True), 'Response')
  population_count = deferred(db.Column(db.Integer, nullable=True), 'Response')
  sample_worksheet = deferred(db.Column(db.String, nullable=True), 'Response')
  sample_count = deferred(db.Column(db.Integer, nullable=True), 'Response')
  sample_evidence = deferred(db.Column(db.String, nullable=True), 'Response')

  @validates('response_type')
  def validates_response_type(self, key, value):
    return 'population sample'

  _publish_attrs = [
      'population_worksheet',
      'population_count',
      'sample_worksheet',
      'sample_count',
      'sample_evidence',
      ]
  _sanitize_html = [
      'population_worksheet',
      'population_count',
      'sample_worksheet',
      'sample_count',
      'sample_evidence',
      ]

  @classmethod
  def eager_query(cls):
    from sqlalchemy import orm

    query = super(PopulationSampleResponse, cls).eager_query()
    return query.options()<commit_msg>Add response_type as polymorphic_on mapper attribute<commit_after># Copyright (C) 2013 Google Inc., authors, and contributors <see AUTHORS file>
# Licensed under http://www.apache.org/licenses/LICENSE-2.0 <see LICENSE file>
# Created By:
# Maintained By: <EMAIL>labs.com

from ggrc import db
from .mixins import deferred, BusinessObject
from .object_document import Documentable
from .object_person import Personable

class Response(BusinessObject, db.Model):
  __tablename__ = 'responses'
  __mapper_args__ = {
      'polymorphic_on': 'response_type',
      }

  VALID_STATES = (u'Assigned', u'Accepted', u'Completed')
  VALID_TYPES = (u'documentation', u'interview', u'population sample')
  request_id = deferred(
      db.Column(db.Integer, db.ForeignKey('requests.id'), nullable=False),
      'Response')
  response_type = db.Column(db.Enum(VALID_TYPES), nullable = False)
  status = deferred(db.Column(db.Enum(VALID_STATES), nullable = False), 'Response')

  _publish_attrs = [
      'request',
      'status',
      'response_type',
      ]
  _sanitize_html = [
      ]

  @classmethod
  def eager_query(cls):
    from sqlalchemy import orm

    query = super(Response, cls).eager_query()
    return query.options(
        orm.joinedload('request'))

class DocumentationResponse(Documentable, Personable, Response):
  __mapper_args__ = {
      'polymorphic_identity': 'documentation'
      }
  _table_plural = 'documentation_responses'

  evidence = db.relationship('Evidence', backref='response', cascade='all, delete-orphan')

  _publish_attrs = [
    'evidence',
      ]
  _sanitize_html = [
      ]


  @classmethod
  def eager_query(cls):
    from sqlalchemy import orm

    query = super(DocumentationResponse, cls).eager_query()
    return query.options(
        orm.subqueryload('evidence'))

class InterviewResponse(Documentable, Personable, Response):
  __mapper_args__ = {
      'polymorphic_identity': 'interview'
      }
  _table_plural = 'interview_responses'
  _publish_attrs = [
    #'meetings',
      ]
  _sanitize_html = [
      ]

  @classmethod
  def eager_query(cls):
    from sqlalchemy import orm

    query = super(InterviewResponse, cls).eager_query()
    return query.options()
        #orm.subqueryload('meetings'))

class PopulationSampleResponse(Documentable, Personable, Response):
  __mapper_args__ = {
      'polymorphic_identity': 'population sample'
      }
  _table_plural = 'population_sample_responses'

  population_worksheet = deferred(db.Column(db.String, nullable=True), 'Response')
  population_count = deferred(db.Column(db.Integer, nullable=True), 'Response')
  sample_worksheet = deferred(db.Column(db.String, nullable=True), 'Response')
  sample_count = deferred(db.Column(db.Integer, nullable=True), 'Response')
  sample_evidence = deferred(db.Column(db.String, nullable=True), 'Response')

  _publish_attrs = [
      'population_worksheet',
      'population_count',
      'sample_worksheet',
      'sample_count',
      'sample_evidence',
      ]
  _sanitize_html = [
      'population_worksheet',
      'population_count',
      'sample_worksheet',
      'sample_count',
      'sample_evidence',
      ]

  @classmethod
  def eager_query(cls):
    from sqlalchemy import orm

    query = super(PopulationSampleResponse, cls).eager_query()
    return query.options()
{'fraction_non_alphanumeric': 0.11511207519884309, 'fraction_numerical': 0.0017353579175704988, 'mean_word_length': 4.089036055923473, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4198975', 'n_tokens_mistral': 2261, 'n_tokens_neox': 2151, 'n_words': 428}