From 7e19e1dd9d1da5761e1da85be9e8eef55a8c85cf Mon Sep 17 00:00:00 2001 From: OzzieIsaacs Date: Wed, 22 Feb 2017 20:59:48 +0100 Subject: [PATCH] Added Publisher and search/advanced search/opds search for publisher --- cps/db.py | 20 ++++++++++++++++++++ cps/templates/detail.html | 9 ++++++++- cps/templates/search_form.html | 28 ++++++++++++++++------------ cps/web.py | 22 ++++++++++++++-------- 4 files changed, 58 insertions(+), 21 deletions(-) diff --git a/cps/db.py b/cps/db.py index f6ee790e..e4082a16 100755 --- a/cps/db.py +++ b/cps/db.py @@ -56,6 +56,10 @@ books_languages_link = Table('books_languages_link', Base.metadata, Column('lang_code', Integer, ForeignKey('languages.id'), primary_key=True) ) +books_publishers_link = Table('books_publishers_link', Base.metadata, + Column('book', Integer, ForeignKey('books.id'), primary_key=True), + Column('publisher', Integer, ForeignKey('publishers.id'), primary_key=True) + ) class Identifiers(Base): __tablename__ = 'identifiers' @@ -182,6 +186,21 @@ class Languages(Base): def __repr__(self): return u"".format(self.lang_code) +class Publishers(Base): + __tablename__ = 'publishers' + + id = Column(Integer, primary_key=True) + name = Column(String) + sort = Column(String) + + def __init__(self, name,sort): + self.name = name + self.sort = sort + + def __repr__(self): + return u"".format(self.name, self.sort) + + class Data(Base): __tablename__ = 'data' @@ -224,6 +243,7 @@ class Books(Base): series = relationship('Series', secondary=books_series_link, backref='books') ratings = relationship('Ratings', secondary=books_ratings_link, backref='books') languages = relationship('Languages', secondary=books_languages_link, backref='books') + publishers = relationship('Publishers', secondary=books_publishers_link, backref='books') identifiers = relationship('Identifiers', backref='books') def __init__(self, title, sort, author_sort, timestamp, pubdate, series_index, last_modified, path, has_cover, diff --git a/cps/templates/detail.html b/cps/templates/detail.html index 8775f079..0a5167b6 100644 --- a/cps/templates/detail.html +++ b/cps/templates/detail.html @@ -50,6 +50,7 @@ {% if entry.identifiers|length > 0 %}
+

{% for identifier in entry.identifiers %} {{identifier.formatType()}} @@ -66,10 +67,16 @@ {% for tag in entry.tags %} {{tag.name}} {%endfor%} -

{% endif %} + {% if entry.publishers|length > 0 %} +
+

+ {{_('Publisher')}}:{% for publisher in entry.publishers %} {{publisher.name}}{% if not loop.last %},{% endif %}{% endfor %} +

+
+ {% endif %} {% if entry.pubdate[:10] != '0101-01-01' %}

{{_('Publishing date')}}: {{entry.pubdate|formatdate}}

{% endif %} diff --git a/cps/templates/search_form.html b/cps/templates/search_form.html index 2e9f4d3d..e61195ec 100644 --- a/cps/templates/search_form.html +++ b/cps/templates/search_form.html @@ -10,63 +10,67 @@ -
+ + +
+ +
{% for tag in tags %} {% endfor %}
- +
{% for tag in tags %} {% endfor %}
- +
{% for serie in series %} {% endfor %}
- +
{% for serie in series %} {% endfor %}
{% if languages %} - +
{% for language in languages %} {% endfor %}
- +
{% for language in languages %} {% endfor %}
diff --git a/cps/web.py b/cps/web.py index bfe42444..a33748e0 100755 --- a/cps/web.py +++ b/cps/web.py @@ -473,8 +473,10 @@ def feed_search(term): filter = True if term: entries = db.session.query(db.Books).filter(db.or_(db.Books.tags.any(db.Tags.name.like("%" + term + "%")), - db.Books.authors.any(db.Authors.name.like("%" + term + "%")), - db.Books.title.like("%" + term + "%"))).filter(filter).all() + db.Books.series.any(db.Series.name.like("%" + term + "%")), + db.Books.authors.any(db.Authors.name.like("%" + term + "%")), + db.Books.publishers.any(db.Publishers.name.like("%" + term + "%")), + db.Books.title.like("%" + term + "%"))).filter(filter).all() entriescount = len(entries) if len(entries) > 0 else 1 pagination = Pagination(1, entriescount, entriescount) xml = render_title_template('feed.xml', searchterm=term, entries=entries, pagination=pagination) @@ -1087,9 +1089,10 @@ def search(): else: filter = True entries = db.session.query(db.Books).filter(db.or_(db.Books.tags.any(db.Tags.name.like("%" + term + "%")), - db.Books.series.any(db.Series.name.like("%" + term + "%")), - db.Books.authors.any(db.Authors.name.like("%" + term + "%")), - db.Books.title.like("%" + term + "%"))).filter(filter).all() + db.Books.series.any(db.Series.name.like("%" + term + "%")), + db.Books.authors.any(db.Authors.name.like("%" + term + "%")), + db.Books.publishers.any(db.Publishers.name.like("%" + term + "%")), + db.Books.title.like("%" + term + "%"))).filter(filter).all() return render_title_template('search.html', searchterm=term, entries=entries) else: return render_title_template('search.html', searchterm="") @@ -1109,12 +1112,14 @@ def advanced_search(): author_name = request.args.get("author_name") book_title = request.args.get("book_title") + publisher = request.args.get("publisher") if author_name: author_name = author_name.strip() if book_title: book_title = book_title.strip() + if publisher: publisher = publisher.strip() if include_tag_inputs or exclude_tag_inputs or include_series_inputs or exclude_series_inputs or \ - include_languages_inputs or exclude_languages_inputs or author_name or book_title: + include_languages_inputs or exclude_languages_inputs or author_name or book_title or publisher: searchterm = [] - searchterm.extend((author_name, book_title)) + searchterm.extend((author_name, book_title, publisher)) tag_names = db.session.query(db.Tags).filter(db.Tags.id.in_(include_tag_inputs)).all() searchterm.extend(tag.name for tag in tag_names) # searchterm = " + ".join(filter(None, searchterm)) @@ -1130,7 +1135,8 @@ def advanced_search(): searchterm.extend(language.name for language in language_names) searchterm = " + ".join(filter(None, searchterm)) q = q.filter(db.Books.authors.any(db.Authors.name.like("%" + author_name + "%")), - db.Books.title.like("%" + book_title + "%")) + db.Books.title.like("%" + book_title + "%"), + db.Books.publishers.any(db.Publishers.name.like("%" + publisher + "%"))) for tag in include_tag_inputs: q = q.filter(db.Books.tags.any(db.Tags.id == tag)) for tag in exclude_tag_inputs: