# Path: cliche/sqltypes.py
# class HashableLocale(Locale):
#     """Hashable Locale"""
# 
#     def __hash__(self):
#         return hash('{}_{}'.format(self.language, self.territory))
# 
# Path: cliche/work.py
# class Trope(Base):  # FIXME: Temporary, It not extend Nameable.
#     """Tropes"""
# 
#     #: (:class:`int`) The primary key integer.
#     id = Column(Integer, primary_key=True)
# 
#     #: (:class:`str`) Trope name
#     name = Column(String, nullable=False)
# 
#     #: (:class:`collections.abc.MutableSet`) The set of
#     #: :class:`WorkTrope`.
#     work_tropes = relationship('WorkTrope',
#                                cascade='delete, merge, save-update',
#                                collection_class=set)
# 
#     #: (:class:`collections.abc.MutableSet`) The set of
#     #: :class:`Work`.
#     works = relationship(lambda: Work, secondary='work_tropes',
#                          collection_class=set)
# 
#     __tablename__ = 'tropes'
#     __repr_columns__ = id, name
# 
# class Work(Nameable):
#     """Creative work(s) that could be a single work like a film, or
#     a series of works such as a combic book series and a television series.
#     """
# 
#     #: (:class:`int`) The primary key integer.
#     id = Column(Integer, ForeignKey(Nameable.id), primary_key=True)
# 
#     #: (:class:`str`) Work media type.
#     media_type = Column(String, nullable=False)
# 
#     #: (:class:`datetime.date`) The publication date.
#     published_at = Column(Date)
# 
#     #: (:class:`collections.abc.MutableSet`) The set of
#     #: :class:`WorkGenre`\ s that the work has.
#     work_genres = relationship('WorkGenre',
#                                cascade='delete, merge, save-update',
#                                collection_class=set)
# 
#     #: (:class:`collections.abc.MutableSet`) The set of
#     #: :class:`Genre`\ s that the work falls into.
#     genres = relationship(Genre,
#                           secondary='work_genres',
#                           collection_class=set)
# 
#     #: (:class:`collections.abc.MutableSet`) The set of
#     #: :class:`Credit`\ s that the work has.
#     credits = relationship(Credit,
#                            cascade='delete, merge, save-update',
#                            collection_class=set)
# 
#     #: (:class:`collections.abc.MutableSet`) The set of
#     #: :class:`WorkFranchise`\ s that the work has.
#     work_franchises = relationship('WorkFranchise',
#                                    cascade='delete, merge, save-update',
#                                    collection_class=set)
# 
#     #: (:class:`collections.abc.MutableSet`) The set of
#     #: :class:`Franchise`\ s that the work belongs to.
#     franchises = relationship(Franchise,
#                               secondary='work_franchises',
#                               collection_class=set)
# 
#     #: (:class:`collections.abc.MutableSet`) The set of
#     #: :class:`Character`\ s that appeared in the work.
#     characters = relationship(Character,
#                               secondary='work_characters',
#                               collection_class=set)
# 
#     #: (:class:`collections.abc.MutableSet`) The set of
#     #: :class:`WorkTrope`.
#     work_tropes = relationship(lambda: WorkTrope,
#                                cascade='delete, merge, save-update',
#                                collection_class=set)
# 
#     #: (:class:`collections.abc.MutableSet`) The set of
#     #: :class:`Trope`.
#     tropes = relationship(Trope, secondary='work_tropes',
#                           collection_class=set)
# 
#     #: (:class:`datetime.datetime`) The date and time on which
#     #: the record was created.
#     created_at = Column(DateTime(timezone=True),
#                         nullable=False,
#                         default=now(),
#                         index=True)
# 
#     __tablename__ = 'works'
#     __repr_columns__ = [id]
#     __mapper_args__ = {
#         'polymorphic_identity': 'works',
#     }
# 
# Path: cliche/web/db.py
# def get_database_engine():
# def get_database_engine_options():
# def get_session():
# def close_session(exception=None):
# def setup_session(app):


from flask import Blueprint, flash, redirect, render_template, request, url_for
from sqlalchemy.orm.exc import NoResultFound
from ..sqltypes import HashableLocale as Locale
from ..work import Trope, Work
from .db import session
    detail = request.form.getlist('detail[]', None)
    error_redirect = redirect(url_for('index'))

    if about is None or category is None or detail is None:
        flash('Invalid arguments.', 'danger')
        return error_redirect

    if type(about) != list or type(category) != list or type(detail) != list:
        flash('Invalid arguments..', 'danger')
        return error_redirect

    if len(about) != len(category) or len(about) != len(detail):
        flash('Invalid arguments...', 'danger')
        return error_redirect

    query = zip(about, category, detail)

    media_list = []
    trope_filter = None
    for about, category, detail in query:
        if about == 'info':
            if category == 'media':
                media_list.append(detail)
        elif about == 'trope':
            try:
                trope = session.query(Trope).get(detail)
            except NoResultFound:
                return error_redirect

            if trope_filter is None:

# Path: cliche/sqltypes.py
# class HashableLocale(Locale):
#     """Hashable Locale"""
# 
#     def __hash__(self):
#         return hash('{}_{}'.format(self.language, self.territory))
# 
# Path: cliche/work.py
# class Trope(Base):  # FIXME: Temporary, It not extend Nameable.
#     """Tropes"""
# 
#     #: (:class:`int`) The primary key integer.
#     id = Column(Integer, primary_key=True)
# 
#     #: (:class:`str`) Trope name
#     name = Column(String, nullable=False)
# 
#     #: (:class:`collections.abc.MutableSet`) The set of
#     #: :class:`WorkTrope`.
#     work_tropes = relationship('WorkTrope',
#                                cascade='delete, merge, save-update',
#                                collection_class=set)
# 
#     #: (:class:`collections.abc.MutableSet`) The set of
#     #: :class:`Work`.
#     works = relationship(lambda: Work, secondary='work_tropes',
#                          collection_class=set)
# 
#     __tablename__ = 'tropes'
#     __repr_columns__ = id, name
# 
# class Work(Nameable):
#     """Creative work(s) that could be a single work like a film, or
#     a series of works such as a combic book series and a television series.
#     """
# 
#     #: (:class:`int`) The primary key integer.
#     id = Column(Integer, ForeignKey(Nameable.id), primary_key=True)
# 
#     #: (:class:`str`) Work media type.
#     media_type = Column(String, nullable=False)
# 
#     #: (:class:`datetime.date`) The publication date.
#     published_at = Column(Date)
# 
#     #: (:class:`collections.abc.MutableSet`) The set of
#     #: :class:`WorkGenre`\ s that the work has.
#     work_genres = relationship('WorkGenre',
#                                cascade='delete, merge, save-update',
#                                collection_class=set)
# 
#     #: (:class:`collections.abc.MutableSet`) The set of
#     #: :class:`Genre`\ s that the work falls into.
#     genres = relationship(Genre,
#                           secondary='work_genres',
#                           collection_class=set)
# 
#     #: (:class:`collections.abc.MutableSet`) The set of
#     #: :class:`Credit`\ s that the work has.
#     credits = relationship(Credit,
#                            cascade='delete, merge, save-update',
#                            collection_class=set)
# 
#     #: (:class:`collections.abc.MutableSet`) The set of
#     #: :class:`WorkFranchise`\ s that the work has.
#     work_franchises = relationship('WorkFranchise',
#                                    cascade='delete, merge, save-update',
#                                    collection_class=set)
# 
#     #: (:class:`collections.abc.MutableSet`) The set of
#     #: :class:`Franchise`\ s that the work belongs to.
#     franchises = relationship(Franchise,
#                               secondary='work_franchises',
#                               collection_class=set)
# 
#     #: (:class:`collections.abc.MutableSet`) The set of
#     #: :class:`Character`\ s that appeared in the work.
#     characters = relationship(Character,
#                               secondary='work_characters',
#                               collection_class=set)
# 
#     #: (:class:`collections.abc.MutableSet`) The set of
#     #: :class:`WorkTrope`.
#     work_tropes = relationship(lambda: WorkTrope,
#                                cascade='delete, merge, save-update',
#                                collection_class=set)
# 
#     #: (:class:`collections.abc.MutableSet`) The set of
#     #: :class:`Trope`.
#     tropes = relationship(Trope, secondary='work_tropes',
#                           collection_class=set)
# 
#     #: (:class:`datetime.datetime`) The date and time on which
#     #: the record was created.
#     created_at = Column(DateTime(timezone=True),
#                         nullable=False,
#                         default=now(),
#                         index=True)
# 
#     __tablename__ = 'works'
#     __repr_columns__ = [id]
#     __mapper_args__ = {
#         'polymorphic_identity': 'works',
#     }
# 
# Path: cliche/web/db.py
# def get_database_engine():
# def get_database_engine_options():
# def get_session():
# def close_session(exception=None):
# def setup_session(app):


# Path: cliche/web/adv_search.py
from flask import Blueprint, flash, redirect, render_template, request, url_for
from sqlalchemy.orm.exc import NoResultFound
from ..sqltypes import HashableLocale as Locale
from ..work import Trope, Work
from .db import session

    detail = request.form.getlist('detail[]', None)
    error_redirect = redirect(url_for('index'))

    if about is None or category is None or detail is None:
        flash('Invalid arguments.', 'danger')
        return error_redirect

    if type(about) != list or type(category) != list or type(detail) != list:
        flash('Invalid arguments..', 'danger')
        return error_redirect

    if len(about) != len(category) or len(about) != len(detail):
        flash('Invalid arguments...', 'danger')
        return error_redirect

    query = zip(about, category, detail)

    media_list = []
    trope_filter = None
    for about, category, detail in query:
        if about == 'info':
            if category == 'media':
                media_list.append(detail)
        elif about == 'trope':
            try:
                trope = session.query(Trope).get(detail)
            except NoResultFound:
                return error_redirect

            if trope_filter is None:

                trope_filter = Work.tropes.any(Trope.id == trope.id)