From 7f992a5dfa7fe3dcca2155547ccc8fd670af06db Mon Sep 17 00:00:00 2001 From: Aaron Kimbre Date: Thu, 31 Mar 2022 18:05:28 -0500 Subject: [PATCH] Add property reputation handling --- app/__init__.py | 16 +++--- app/models.py | 10 ++++ app/properties.py | 12 ++-- app/templates/partials/_property.html.j2 | 8 +++ app/templates/properties/index.html.j2 | 1 + ...fa97b0d0c351_property_performance_index.py | 56 +++++++++++++++++++ 6 files changed, 90 insertions(+), 13 deletions(-) create mode 100644 migrations/versions/fa97b0d0c351_property_performance_index.py diff --git a/app/__init__.py b/app/__init__.py index 0c6bb6a..4c3a915 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -75,14 +75,14 @@ def create_app(): if cdclient is not None: cdclient.close() - @app.errorhandler(Exception) - def handle_exception(e): - app.logger.error(e) - # pass through HTTP errors - if isinstance(e, HTTPException): - return e - # now you're handling non-HTTP exceptions only - return render_template("status_codes/500.html.j2", exception=e), 500 + # @app.errorhandler(Exception) + # def handle_exception(e): + # app.logger.error(e) + # # pass through HTTP errors + # if isinstance(e, HTTPException): + # return e + # # now you're handling non-HTTP exceptions only + # return render_template("status_codes/500.html.j2", exception=e), 500 # add the commands to flask cli app.cli.add_command(init_db) diff --git a/app/models.py b/app/models.py index 2e42c7e..47910bb 100644 --- a/app/models.py +++ b/app/models.py @@ -8,6 +8,7 @@ from flask_sqlalchemy import BaseQuery from sqlalchemy.dialects import mysql from sqlalchemy.exc import OperationalError, StatementError from sqlalchemy.types import JSON +from sqlalchemy.ext.hybrid import hybrid_property from time import sleep import random import string @@ -694,6 +695,15 @@ class Property(db.Model): nullable=False, ) + performance_cost = db.Column( + mysql.DOUBLE( + precision=20, + scale=15, + asdecimal=False + ), + server_default='0.0' + ) + zone_id = db.Column( mysql.INTEGER, nullable=False, diff --git a/app/properties.py b/app/properties.py index 5e0337b..bbf1877 100644 --- a/app/properties.py +++ b/app/properties.py @@ -123,8 +123,9 @@ def get(status="all"): ColumnDT(Property.time_claimed), # 9 ColumnDT(Property.rejection_reason), # 10 ColumnDT(Property.reputation), # 11 - ColumnDT(Property.zone_id), # 12 - ColumnDT(Account.username) # 13 + ColumnDT(Property.performance_cost), # 12 + ColumnDT(Property.zone_id), # 13 + ColumnDT(Account.username) # 14 ] query = None @@ -146,6 +147,7 @@ def get(status="all"): rowTable = DataTables(params, query, columns) data = rowTable.output_result() + print(data) for property_data in data["data"]: id = property_data["0"] @@ -181,7 +183,7 @@ def get(status="all"): if property_data["4"] == "": property_data["4"] = query_cdclient( 'select DisplayDescription from ZoneTable where zoneID = ?', - [property_data["12"]], + [property_data["13"]], one=True ) @@ -200,9 +202,9 @@ def get(status="all"): else: property_data["7"] = '''

''' - property_data["12"] = query_cdclient( + property_data["13"] = query_cdclient( 'select DisplayDescription from ZoneTable where zoneID = ?', - [property_data["12"]], + [property_data["13"]], one=True ) diff --git a/app/templates/partials/_property.html.j2 b/app/templates/partials/_property.html.j2 index 14012a9..a6fa785 100644 --- a/app/templates/partials/_property.html.j2 +++ b/app/templates/partials/_property.html.j2 @@ -69,6 +69,14 @@ {{ property.reputation }} +
+
+ Performance Cost: +
+
+ {{ property.performance_cost }} +
+
{% if request.endpoint != "properties.view" %}
diff --git a/app/templates/properties/index.html.j2 b/app/templates/properties/index.html.j2 index 90f8d09..8c5635c 100644 --- a/app/templates/properties/index.html.j2 +++ b/app/templates/properties/index.html.j2 @@ -32,6 +32,7 @@ Claimed Rejection Reason Reputation + Performance Cost Location diff --git a/migrations/versions/fa97b0d0c351_property_performance_index.py b/migrations/versions/fa97b0d0c351_property_performance_index.py new file mode 100644 index 0000000..f7481d7 --- /dev/null +++ b/migrations/versions/fa97b0d0c351_property_performance_index.py @@ -0,0 +1,56 @@ +"""property performance index + +Revision ID: fa97b0d0c351 +Revises: b470795db8e1 +Create Date: 2022-03-31 10:38:06.367277 + +""" +from alembic import op +import sqlalchemy as sa +from sqlalchemy.dialects import mysql +from sqlalchemy import engine_from_config +from sqlalchemy.engine import reflection + +# revision identifiers, used by Alembic. +revision = 'fa97b0d0c351' +down_revision = 'b470795db8e1' +branch_labels = None +depends_on = None + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + if not _table_has_column('properties', 'performance_cost'): + op.add_column( + 'properties', + sa.Column( + 'performance_cost', + mysql.DOUBLE( + precision=20, + scale=15, + asdecimal=False + ), + server_default='0.0', + nullable=True + ) + ) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column('properties', 'performance_cost') + # ### end Alembic commands ### + + +def _table_has_column(table, column): + config = op.get_context().config + engine = engine_from_config( + config.get_section(config.config_ini_section), prefix='sqlalchemy.') + insp = reflection.Inspector.from_engine(engine) + has_column = False + for col in insp.get_columns(table): + if column not in col['name']: + continue + has_column = True + return has_column