From 75ab56cad1afa4e179977344b103bbf523f2baac Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Thu, 9 Jul 2020 05:22:58 +0100 Subject: [PATCH] Add recent positive reviews to homepage --- app/blueprints/homepage/__init__.py | 3 +- app/models.py | 2 ++ app/templates/index.html | 19 ++++-------- app/templates/macros/reviews.html | 18 ++++++++---- .../packages/review_create_edit.html | 2 +- migrations/versions/019da77ba02d_.py | 29 +++++++++++++++++++ 6 files changed, 52 insertions(+), 21 deletions(-) create mode 100644 migrations/versions/019da77ba02d_.py diff --git a/app/blueprints/homepage/__init__.py b/app/blueprints/homepage/__init__.py index 4f6d5ebb..37c18001 100644 --- a/app/blueprints/homepage/__init__.py +++ b/app/blueprints/homepage/__init__.py @@ -21,7 +21,8 @@ def home(): pop_mod = join(query.filter_by(type=PackageType.MOD).order_by(db.desc(Package.score))).limit(8).all() pop_gam = join(query.filter_by(type=PackageType.GAME).order_by(db.desc(Package.score))).limit(4).all() pop_txp = join(query.filter_by(type=PackageType.TXP).order_by(db.desc(Package.score))).limit(4).all() + reviews = PackageReview.query.filter_by(recommends=True).order_by(db.desc(PackageReview.created_at)).limit(5).all() downloads_result = db.session.query(func.sum(Package.downloads)).one_or_none() downloads = 0 if not downloads_result or not downloads_result[0] else downloads_result[0] return render_template("index.html", count=count, downloads=downloads, \ - new=new, pop_mod=pop_mod, pop_txp=pop_txp, pop_gam=pop_gam) + new=new, pop_mod=pop_mod, pop_txp=pop_txp, pop_gam=pop_gam, reviews=reviews) diff --git a/app/models.py b/app/models.py index e026c778..f89fb6fa 100644 --- a/app/models.py +++ b/app/models.py @@ -1118,6 +1118,8 @@ class PackageReview(db.Model): package_id = db.Column(db.Integer, db.ForeignKey("package.id"), nullable=True) package = db.relationship("Package", foreign_keys=[package_id], backref=db.backref("reviews", lazy=True)) + created_at = db.Column(db.DateTime, nullable=False, default=datetime.datetime.utcnow) + author_id = db.Column(db.Integer, db.ForeignKey("user.id"), nullable=False) author = db.relationship("User", foreign_keys=[author_id], backref=db.backref("reviews", lazy=True)) diff --git a/app/templates/index.html b/app/templates/index.html index a7574d63..84c1d06d 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -20,20 +20,6 @@ {% endblock %} {% block content %} - {% from "macros/packagegridtile.html" import render_pkggrid %} @@ -64,6 +50,11 @@

{{ _("Top Texture Packs") }}

{{ render_pkggrid(pop_txp) }} + +

{{ _("Recent Positive Reviews") }}

+ {% from "macros/reviews.html" import render_reviews %} + {{ render_reviews(reviews, True) }} +
{{ _("CDB has %(count)d packages, with a total of %(downloads)d downloads.", count=count, downloads=downloads) }} diff --git a/app/templates/macros/reviews.html b/app/templates/macros/reviews.html index fc6673e5..f1814921 100644 --- a/app/templates/macros/reviews.html +++ b/app/templates/macros/reviews.html @@ -1,4 +1,4 @@ -{% macro render_reviews(reviews) -%} +{% macro render_reviews(reviews, show_package_link=False) -%}
diff --git a/app/templates/packages/review_create_edit.html b/app/templates/packages/review_create_edit.html index a49398f4..a53bbd76 100644 --- a/app/templates/packages/review_create_edit.html +++ b/app/templates/packages/review_create_edit.html @@ -9,7 +9,7 @@ {% endblock %} {% block content %} -

{{ _("Post a review for %(name)s by %(author)s", name=self.link(), author=package.author.display_name) }}

+

{{ _("Post a review for %(title)s by %(author)s", title=self.link(), author=package.author.display_name) }}

{% from "macros/forms.html" import render_field, render_submit_field, render_radio_field %}
diff --git a/migrations/versions/019da77ba02d_.py b/migrations/versions/019da77ba02d_.py new file mode 100644 index 00000000..9c49dc3b --- /dev/null +++ b/migrations/versions/019da77ba02d_.py @@ -0,0 +1,29 @@ +"""empty message + +Revision ID: 019da77ba02d +Revises: 4f2e19bc2a27 +Create Date: 2020-07-09 04:07:23.926213 + +""" +from alembic import op +import sqlalchemy as sa +import datetime + + +# revision identifiers, used by Alembic. +revision = '019da77ba02d' +down_revision = '4f2e19bc2a27' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.add_column('package_review', sa.Column('created_at', sa.DateTime(), nullable=False, server_default=datetime.datetime.utcnow().isoformat())) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column('package_review', 'created_at') + # ### end Alembic commands ###