Add property reputation handling

This commit is contained in:
Aaron Kimbre 2022-03-31 18:05:28 -05:00
parent 560afa5e0d
commit 7f992a5dfa
6 changed files with 90 additions and 13 deletions

View File

@ -75,14 +75,14 @@ def create_app():
if cdclient is not None: if cdclient is not None:
cdclient.close() cdclient.close()
@app.errorhandler(Exception) # @app.errorhandler(Exception)
def handle_exception(e): # def handle_exception(e):
app.logger.error(e) # app.logger.error(e)
# pass through HTTP errors # # pass through HTTP errors
if isinstance(e, HTTPException): # if isinstance(e, HTTPException):
return e # return e
# now you're handling non-HTTP exceptions only # # now you're handling non-HTTP exceptions only
return render_template("status_codes/500.html.j2", exception=e), 500 # return render_template("status_codes/500.html.j2", exception=e), 500
# add the commands to flask cli # add the commands to flask cli
app.cli.add_command(init_db) app.cli.add_command(init_db)

View File

@ -8,6 +8,7 @@ from flask_sqlalchemy import BaseQuery
from sqlalchemy.dialects import mysql from sqlalchemy.dialects import mysql
from sqlalchemy.exc import OperationalError, StatementError from sqlalchemy.exc import OperationalError, StatementError
from sqlalchemy.types import JSON from sqlalchemy.types import JSON
from sqlalchemy.ext.hybrid import hybrid_property
from time import sleep from time import sleep
import random import random
import string import string
@ -694,6 +695,15 @@ class Property(db.Model):
nullable=False, nullable=False,
) )
performance_cost = db.Column(
mysql.DOUBLE(
precision=20,
scale=15,
asdecimal=False
),
server_default='0.0'
)
zone_id = db.Column( zone_id = db.Column(
mysql.INTEGER, mysql.INTEGER,
nullable=False, nullable=False,

View File

@ -123,8 +123,9 @@ def get(status="all"):
ColumnDT(Property.time_claimed), # 9 ColumnDT(Property.time_claimed), # 9
ColumnDT(Property.rejection_reason), # 10 ColumnDT(Property.rejection_reason), # 10
ColumnDT(Property.reputation), # 11 ColumnDT(Property.reputation), # 11
ColumnDT(Property.zone_id), # 12 ColumnDT(Property.performance_cost), # 12
ColumnDT(Account.username) # 13 ColumnDT(Property.zone_id), # 13
ColumnDT(Account.username) # 14
] ]
query = None query = None
@ -146,6 +147,7 @@ def get(status="all"):
rowTable = DataTables(params, query, columns) rowTable = DataTables(params, query, columns)
data = rowTable.output_result() data = rowTable.output_result()
print(data)
for property_data in data["data"]: for property_data in data["data"]:
id = property_data["0"] id = property_data["0"]
@ -181,7 +183,7 @@ def get(status="all"):
if property_data["4"] == "": if property_data["4"] == "":
property_data["4"] = query_cdclient( property_data["4"] = query_cdclient(
'select DisplayDescription from ZoneTable where zoneID = ?', 'select DisplayDescription from ZoneTable where zoneID = ?',
[property_data["12"]], [property_data["13"]],
one=True one=True
) )
@ -200,9 +202,9 @@ def get(status="all"):
else: else:
property_data["7"] = '''<h2 class="far fa-check-square text-success"></h2>''' property_data["7"] = '''<h2 class="far fa-check-square text-success"></h2>'''
property_data["12"] = query_cdclient( property_data["13"] = query_cdclient(
'select DisplayDescription from ZoneTable where zoneID = ?', 'select DisplayDescription from ZoneTable where zoneID = ?',
[property_data["12"]], [property_data["13"]],
one=True one=True
) )

View File

@ -69,6 +69,14 @@
{{ property.reputation }} {{ property.reputation }}
</div> </div>
</div> </div>
<div class="row">
<div class="col text-right">
Performance Cost:
</div>
<div class="col">
{{ property.performance_cost }}
</div>
</div>
{% if request.endpoint != "properties.view" %} {% if request.endpoint != "properties.view" %}
<br/> <br/>
<div class="row"> <div class="row">

View File

@ -32,6 +32,7 @@
<th>Claimed</th> <th>Claimed</th>
<th>Rejection Reason</th> <th>Rejection Reason</th>
<th>Reputation</th> <th>Reputation</th>
<th>Performance Cost</th>
<th>Location</th> <th>Location</th>
</tr> </tr>
</thead> </thead>

View File

@ -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