diff --git a/app/__init__.py b/app/__init__.py
index ba0b71c..93227f2 100644
--- a/app/__init__.py
+++ b/app/__init__.py
@@ -10,7 +10,7 @@ from app.forms import CustomUserManager
from flask_user import user_registered, current_user, user_logged_in
from flask_wtf.csrf import CSRFProtect
from flask_apscheduler import APScheduler
-from app.luclient import query_cdclient, register_luclient_jinja_helpers
+from app.luclient import register_luclient_jinja_helpers
from app.commands import init_db, init_accounts, load_property, gen_image_cache, gen_model_cache
from app.models import Account, AccountInvitation, AuditLog
@@ -40,13 +40,12 @@ def create_app():
app.logger.info(
f"USERS::REGISTRATION User with ID {user.id} and name {user.username} Registered \
using Play Key ID {play_key_used.id} : {play_key_used.key_string}"
- )
+ )
db.session.add(play_key_used)
db.session.commit()
else:
app.logger.info(f"USERS::REGISTRATION User with ID {user.id} and name {user.username} Registered")
-
@user_logged_in.connect_via(app)
def _after_login_hook(sender, user, **extra):
app.logger.info(f"{user.username} Logged in")
@@ -55,7 +54,7 @@ def create_app():
@app.template_filter('ctime')
def timectime(s):
if s:
- return time.ctime(s) # or datetime.datetime.fromtimestamp(s)
+ return time.ctime(s) # or datetime.datetime.fromtimestamp(s)
else:
return "Never"
@@ -246,6 +245,7 @@ def gm_level(gm_level):
return wrapper
return decorator
+
def log_audit(message):
AuditLog(
account_id=current_user.id,
diff --git a/app/accounts.py b/app/accounts.py
index ca9c285..b3d5b59 100644
--- a/app/accounts.py
+++ b/app/accounts.py
@@ -1,10 +1,8 @@
-from flask import render_template, Blueprint, redirect, url_for, request, abort, current_app, flash, current_app
+from flask import render_template, Blueprint, redirect, url_for, request, current_app, flash
from flask_user import login_required, current_user
-import json
from datatables import ColumnDT, DataTables
import datetime
-import time
-from app.models import Account, AccountInvitation, db
+from app.models import Account, db
from app.schemas import AccountSchema
from app import gm_level, log_audit
from app.forms import EditGMLevelForm
@@ -13,6 +11,7 @@ accounts_blueprint = Blueprint('accounts', __name__)
account_schema = AccountSchema()
+
@accounts_blueprint.route('/', methods=['GET'])
@login_required
@gm_level(3)
@@ -38,7 +37,7 @@ def edit_gm_level(id):
if current_user.id == int(id):
flash("You cannot your own GM Level", "danger")
return redirect(request.referrer if request.referrer else url_for("main.index"))
- account_data = Account.query.filter(Account.id==id).first()
+ account_data = Account.query.filter(Account.id == id).first()
if account_data.gm_level >= 8 and current_user.gm_level == 8:
flash("You cannot edit this user's GM Level", "warning")
return redirect(request.referrer if request.referrer else url_for("main.index"))
@@ -138,10 +137,10 @@ def get():
View
"""
- #
- # Delete
- #
+ #
+ # Delete
+ #
if account["4"]:
account["4"] = '''
'''
@@ -154,13 +153,13 @@ def get():
account["5"] = ''''''
if account["6"]:
- account["6"] = f''''''
+ account["6"] = ''''''
else:
account["6"] = ''''''
if current_app.config["USER_ENABLE_EMAIL"]:
if account["8"]:
- account["8"] = f''''''
+ account["8"] = ''''''
else:
account["8"] = ''''''
else:
@@ -175,4 +174,3 @@ def get():
del account["8"]
return data
-
diff --git a/app/bug_reports.py b/app/bug_reports.py
index 835950c..ce5c95a 100644
--- a/app/bug_reports.py
+++ b/app/bug_reports.py
@@ -1,4 +1,4 @@
-from flask import render_template, Blueprint, redirect, url_for, request, abort, flash
+from flask import render_template, Blueprint, redirect, url_for, request, flash
from flask_user import login_required, current_user
from app.models import db, BugReport, CharacterInfo
from datatables import ColumnDT, DataTables
@@ -8,6 +8,7 @@ from app.luclient import translate_from_locale
bug_report_blueprint = Blueprint('bug_reports', __name__)
+
@bug_report_blueprint.route('/', methods=['GET'])
@login_required
@gm_level(3)
@@ -23,7 +24,7 @@ def view(id):
if report.resoleved_by:
rb = report.resoleved_by.username
else:
- rb=""
+ rb = ""
return render_template('bug_reports/view.html.j2', report=report, resolved_by=rb)
@@ -62,12 +63,12 @@ def get(status):
]
query = None
- if status=="all":
+ if status == "all":
query = db.session.query().select_from(BugReport)
- elif status=="resolved":
- query = db.session.query().select_from(BugReport).filter(BugReport.resolved_time != None)
- elif status=="unresolved":
- query = db.session.query().select_from(BugReport).filter(BugReport.resolved_time == None)
+ elif status == "resolved":
+ query = db.session.query().select_from(BugReport).filter(BugReport.resolved_time not None)
+ elif status == "unresolved":
+ query = db.session.query().select_from(BugReport).filter(BugReport.resolved_time is None)
else:
raise Exception("Not a valid filter")
diff --git a/app/characters.py b/app/characters.py
index 5d486dd..a042652 100644
--- a/app/characters.py
+++ b/app/characters.py
@@ -1,8 +1,7 @@
from flask import render_template, Blueprint, redirect, url_for, request, abort, flash, make_response
from flask_user import login_required, current_user
-import json
from datatables import ColumnDT, DataTables
-import datetime, time
+import time
from app.models import CharacterInfo, CharacterXML, Account, db
from app.schemas import CharacterInfoSchema
from app.forms import RescueForm
@@ -16,6 +15,7 @@ character_blueprint = Blueprint('characters', __name__)
character_schema = CharacterInfoSchema()
+
@character_blueprint.route('/', methods=['GET'])
@login_required
@gm_level(3)
@@ -27,7 +27,7 @@ def index():
@login_required
@gm_level(3)
def approve_name(id, action):
- character = CharacterInfo.query.filter(CharacterInfo.id == id).first()
+ character = CharacterInfo.query.filter(CharacterInfo.id == id).first()
if action == "approve":
log_audit(f"Approved ({character.id}){character.pending_name} from {character.name}")
@@ -42,9 +42,12 @@ def approve_name(id, action):
elif action == "rename":
character.needs_rename = True
- log_audit(f"Marked character ({character.id}){character.name} (Pending Name: {character.pending_name if character.pending_name else 'None'}) as needing Rename")
+ log_audit(
+ f"Marked character ({character.id}){character.name} \
+ (Pending Name: {character.pending_name if character.pending_name else 'None'}) as needing Rename")
flash(
- f"Marked character {character.name} (Pending Name: {character.pending_name if character.pending_name else 'None'}) as needing Rename",
+ f"Marked character {character.name} \
+ (Pending Name: {character.pending_name if character.pending_name else 'None'}) as needing Rename",
"danger"
)
@@ -67,11 +70,11 @@ def view(id):
abort(403)
return
character_json = xmltodict.parse(
- CharacterXML.query.filter(
- CharacterXML.id==id
- ).first().xml_data,
- attr_prefix="attr_"
- )
+ CharacterXML.query.filter(
+ CharacterXML.id == id
+ ).first().xml_data,
+ attr_prefix="attr_"
+ )
# print json for reference
# with open("errorchar.json", "a") as file:
@@ -84,8 +87,7 @@ def view(id):
# sort by items slot index
for inv in character_json["obj"]["inv"]["holdings"]["in"]:
if "i" in inv.keys() and type(inv["i"]) == list:
- inv["i"] = sorted(inv["i"], key = lambda i: int(i['attr_s']))
-
+ inv["i"] = sorted(inv["i"], key=lambda i: int(i['attr_s']))
return render_template(
'character/view.html.j2',
@@ -110,13 +112,14 @@ def view_xml(id):
return
character_xml = CharacterXML.query.filter(
- CharacterXML.id==id
- ).first().xml_data
+ CharacterXML.id == id
+ ).first().xml_data
response = make_response(character_xml)
response.headers.set('Content-Type', 'text/xml')
return response
+
@character_blueprint.route('/get_xml/', methods=['GET'])
@login_required
def get_xml(id):
@@ -132,8 +135,8 @@ def get_xml(id):
return
character_xml = CharacterXML.query.filter(
- CharacterXML.id==id
- ).first().xml_data
+ CharacterXML.id == id
+ ).first().xml_data
response = make_response(character_xml)
response.headers.set('Content-Type', 'attachment/xml')
@@ -144,6 +147,7 @@ def get_xml(id):
)
return response
+
@character_blueprint.route('/restrict//', methods=['GET'])
@login_required
@gm_level(3)
@@ -177,8 +181,8 @@ def rescue(id):
form = RescueForm()
character_data = CharacterXML.query.filter(
- CharacterXML.id==id
- ).first()
+ CharacterXML.id == id
+ ).first()
character_xml = ET.XML(character_data.xml_data)
for zone in character_xml.findall('.//r'):
@@ -205,6 +209,7 @@ def rescue(id):
return render_template("character/rescue.html.j2", form=form)
+
@character_blueprint.route('/get/', methods=['GET'])
@login_required
@gm_level(3)
@@ -220,12 +225,12 @@ def get(status):
]
query = None
- if status=="all":
+ if status == "all":
query = db.session.query().select_from(CharacterInfo).join(Account)
- elif status=="approved":
- query = db.session.query().select_from(CharacterInfo).join(Account).filter((CharacterInfo.pending_name == "") & (CharacterInfo.needs_rename == False))
- elif status=="unapproved":
- query = db.session.query().select_from(CharacterInfo).join(Account).filter((CharacterInfo.pending_name != "") | (CharacterInfo.needs_rename == True))
+ elif status == "approved":
+ query = db.session.query().select_from(CharacterInfo).join(Account).filter((CharacterInfo.pending_name == "") & (CharacterInfo.needs_rename is False))
+ elif status == "unapproved":
+ query = db.session.query().select_from(CharacterInfo).join(Account).filter((CharacterInfo.pending_name != "") | (CharacterInfo.needs_rename is True))
else:
raise Exception("Not a valid filter")
@@ -286,6 +291,4 @@ def get(status):
if perm_map & (1 << 6):
character["6"] += "Restricted Chat"
-
return data
-
diff --git a/app/commands.py b/app/commands.py
index 0f3ed7e..dfecd8d 100644
--- a/app/commands.py
+++ b/app/commands.py
@@ -1,19 +1,20 @@
import click
-import json
from flask.cli import with_appcontext
-import random, string, datetime
+import random
+import string
+import datetime
from flask_user import current_app
from app import db
from app.models import Account, PlayKey, CharacterInfo, Property, PropertyContent, UGC
import pathlib
import zlib
-import os
from wand import image
from wand.exceptions import BlobError as BE
import app.pylddlib as ldd
from multiprocessing import Pool
from functools import partial
+
@click.command("init_db")
@click.argument('drop_tables', nargs=1)
@with_appcontext
@@ -45,6 +46,7 @@ def init_accounts():
return
+
@click.command("load_property")
@click.argument('zone')
@click.argument('player')
@@ -56,7 +58,7 @@ def load_property(zone, player):
print("Character not Found")
return 404
- prop = Property.query.filter(Property.owner_id==char.id).filter(Property.zone_id==zone).first()
+ prop = Property.query.filter(Property.owner_id == char.id).filter(Property.zone_id == zone).first()
if not prop:
print(f"Property {zone} not claimed by Character: {char.name}")
@@ -95,6 +97,7 @@ def load_property(zone, player):
)
new_prop_content.save()
+
@click.command("gen_image_cache")
def gen_image_cache():
"""generates image cache"""
@@ -113,6 +116,7 @@ def gen_image_cache():
except BE:
return print(f"Error on {file}")
+
@click.command("gen_model_cache")
def gen_model_cache():
"""generate model obj cache"""
@@ -123,19 +127,21 @@ def gen_model_cache():
pool.map(partial(convert_lxfml_to_obj, lod=1), files)
pool.map(partial(convert_lxfml_to_obj, lod=2), files)
+
def convert_lxfml_to_obj(file, lod):
mtl = get_cache_file(file).with_suffix(f".lod{lod}.mtl")
if not mtl.exists():
mtl.parent.mkdir(parents=True, exist_ok=True)
print(f"Convert LXFML {file.as_posix()} to obj and mtl @ {mtl}")
try:
- ldd.main(str(file.as_posix()), str(mtl.with_suffix("").as_posix()), lod) # convert to OBJ
+ ldd.main(str(file.as_posix()), str(mtl.with_suffix("").as_posix()), lod) # convert to OBJ
except Exception as e:
print(f"ERROR on {file}:\n {e}")
else:
# print(f"Already Exists: {file} with LOD {lod}")
return
+
def get_cache_file(path):
"""helper"""
# convert to list so that we can change elements
@@ -147,6 +153,7 @@ def get_cache_file(path):
return pathlib.Path(*parts)
+
def find_or_create_account(name, email, password, gm_level=9):
""" Find existing account or create new account """
account = Account.query.filter(Account.email == email).first()
@@ -164,15 +171,16 @@ def find_or_create_account(name, email, password, gm_level=9):
db.session.commit()
play_key = PlayKey.query.filter(PlayKey.key_string == key).first()
- account = Account(email=email,
- username=name,
- password=current_app.user_manager.password_manager.hash_password(password),
- play_key_id=play_key.id,
- email_confirmed_at=datetime.datetime.utcnow(),
- gm_level=gm_level
- )
+ account = Account(
+ email=email,
+ username=name,
+ password=current_app.user_manager.password_manager.hash_password(password),
+ play_key_id=play_key.id,
+ email_confirmed_at=datetime.datetime.utcnow(),
+ gm_level=gm_level
+ )
play_key.key_uses = 0
db.session.add(account)
db.session.add(play_key)
db.session.commit()
- return # account
+ return # account
diff --git a/app/forms.py b/app/forms.py
index 9246272..0e37688 100644
--- a/app/forms.py
+++ b/app/forms.py
@@ -16,13 +16,13 @@ from wtforms import (
SubmitField,
validators,
IntegerField,
- StringField,
SelectField
)
from wtforms.validators import DataRequired, Optional
from app.models import PlayKey
+
def validate_play_key(form, field):
"""Validates a field for a valid phone number
Args:
@@ -85,6 +85,7 @@ class CustomRegisterForm(FlaskForm):
submit = SubmitField('Register')
+
class CreatePlayKeyForm(FlaskForm):
count = IntegerField(
@@ -97,6 +98,7 @@ class CreatePlayKeyForm(FlaskForm):
)
submit = SubmitField('Create!')
+
class EditPlayKeyForm(FlaskForm):
active = BooleanField(
@@ -119,7 +121,7 @@ class EditGMLevelForm(FlaskForm):
gm_level = IntegerField(
'GM Level',
- widget=NumberInput(min = 0, max = 9)
+ widget=NumberInput(min=0, max=9)
)
submit = SubmitField('Submit')
@@ -142,8 +144,8 @@ class SendMailForm(FlaskForm):
'Recipient: ',
coerce=str,
choices=[
- ("",""),
- ("0","All Characters"),
+ ("", ""),
+ ("0", "All Characters"),
],
validators=[validators.DataRequired()]
)
@@ -162,7 +164,7 @@ class SendMailForm(FlaskForm):
attachment = SelectField(
"Attachment",
coerce=str,
- choices=[(0,"No Attachment")]
+ choices=[(0, "No Attachment")]
)
attachment_count = IntegerField(
@@ -179,7 +181,7 @@ class RescueForm(FlaskForm):
'Move to:',
coerce=str,
choices=[
- ("",""),
+ ("", ""),
],
validators=[validators.DataRequired()]
)
diff --git a/app/log.py b/app/log.py
index 16397fd..44cc54a 100644
--- a/app/log.py
+++ b/app/log.py
@@ -1,5 +1,5 @@
from flask import render_template, Blueprint, request, url_for
-from flask_user import login_required, current_user
+from flask_user import login_required
from app.models import CommandLog, ActivityLog, db, Account, CharacterInfo, AuditLog
from datatables import ColumnDT, DataTables
import time
@@ -7,6 +7,7 @@ from app import gm_level
log_blueprint = Blueprint('log', __name__)
+
@log_blueprint.route('/activities', methods=['GET'])
@login_required
@gm_level(8)
@@ -40,11 +41,11 @@ def audit():
@gm_level(8)
def get_activities():
columns = [
- ColumnDT(ActivityLog.id), # 0
- ColumnDT(ActivityLog.character_id), # 1
- ColumnDT(ActivityLog.activity), # 2
- ColumnDT(ActivityLog.time), # 3
- ColumnDT(ActivityLog.map_id), # 4
+ ColumnDT(ActivityLog.id), # 0
+ ColumnDT(ActivityLog.character_id), # 1
+ ColumnDT(ActivityLog.activity), # 2
+ ColumnDT(ActivityLog.time), # 3
+ ColumnDT(ActivityLog.map_id), # 4
]
query = db.session.query().select_from(ActivityLog)
@@ -82,9 +83,9 @@ def get_activities():
@gm_level(8)
def get_commands():
columns = [
- ColumnDT(CommandLog.id), # 0
- ColumnDT(CommandLog.character_id), # 1
- ColumnDT(CommandLog.command), # 2
+ ColumnDT(CommandLog.id), # 0
+ ColumnDT(CommandLog.character_id), # 1
+ ColumnDT(CommandLog.command), # 2
]
query = db.session.query().select_from(CommandLog)
diff --git a/app/luclient.py b/app/luclient.py
index 25262e3..fa4a490 100644
--- a/app/luclient.py
+++ b/app/luclient.py
@@ -19,6 +19,7 @@ import xml.etree.ElementTree as ET
luclient_blueprint = Blueprint('luclient', __name__)
locale = {}
+
@luclient_blueprint.route('/get_dds_as_png/')
@login_required
def get_dds_as_png(filename):
@@ -37,7 +38,7 @@ def get_dds_as_png(filename):
with image.Image(filename=path) as img:
img.compression = "no"
- img.save(filename='app/cache/'+filename.split('.')[0] + '.png')
+ img.save(filename='app/cache/' + filename.split('.')[0] + '.png')
return send_file(cache)
@@ -69,7 +70,8 @@ def get_icon_lot(id):
)[0]
# find the asset from rendercomponent given the component id
- filename = query_cdclient('select icon_asset from RenderComponent where id = ?',
+ filename = query_cdclient(
+ 'select icon_asset from RenderComponent where id = ?',
[render_component_id],
one=True
)[0]
@@ -117,6 +119,7 @@ def get_icon_iconid(id):
return send_file(pathlib.Path(cache).resolve())
+
@luclient_blueprint.route('/unknown')
@login_required
def unknown():
@@ -195,6 +198,7 @@ def translate_from_locale(trans_string):
else:
return trans_string
+
def register_luclient_jinja_helpers(app):
@app.template_filter('get_zone_name')
@@ -203,15 +207,17 @@ def register_luclient_jinja_helpers(app):
@app.template_filter('get_skill_desc')
def get_skill_desc(skill_id):
- return translate_from_locale(f'SkillBehavior_{skill_id}_descriptionUI').replace(
- "%(DamageCombo)", "Damage Combo: "
- ).replace(
- "%(AltCombo)", "
Skeleton Combo: "
- ).replace(
- "%(Description)", "
"
- ).replace(
- "%(ChargeUp)", "
Charge-up: "
- )
+ return translate_from_locale(
+ f'SkillBehavior_{skill_id}_descriptionUI'
+ ).replace(
+ "%(DamageCombo)", "Damage Combo: "
+ ).replace(
+ "%(AltCombo)", "
Skeleton Combo: "
+ ).replace(
+ "%(Description)", "
"
+ ).replace(
+ "%(ChargeUp)", "
Charge-up: "
+ )
@app.template_filter('parse_lzid')
def parse_lzid(lzid):
@@ -240,7 +246,7 @@ def register_luclient_jinja_helpers(app):
one=True
)
if intermed:
- name = intermed[7] if (intermed[7] != "None" and intermed[7] !="" and intermed[7] != None) else intermed[1]
+ name = intermed[7] if (intermed[7] != "None" and intermed[7] != "" and intermed[7] is None) else intermed[1]
return name
@app.template_filter('get_lot_rarity')
@@ -252,7 +258,8 @@ def register_luclient_jinja_helpers(app):
one=True
)[0]
- rarity = query_cdclient('select rarity from ItemComponent where id = ?',
+ rarity = query_cdclient(
+ 'select rarity from ItemComponent where id = ?',
[render_component_id],
one=True
)
@@ -302,7 +309,6 @@ def register_luclient_jinja_helpers(app):
return consolidate_stats(stats)
-
@app.template_filter('get_set_stats')
def get_set_stats(lot_id):
stats = query_cdclient(
@@ -331,7 +337,7 @@ def register_luclient_jinja_helpers(app):
def consolidate_stats(stats):
if len(stats) > 1:
- consolidated_stats = {"im": 0,"life": 0,"armor": 0, "skill": []}
+ consolidated_stats = {"im": 0, "life": 0, "armor": 0, "skill": []}
for stat in stats:
if stat[0]:
consolidated_stats["im"] += stat[0]
@@ -340,8 +346,7 @@ def consolidate_stats(stats):
if stat[2]:
consolidated_stats["armor"] += stat[2]
if stat[3]:
- consolidated_stats["skill"].append([stat[3],stat[4]])
-
+ consolidated_stats["skill"].append([stat[3], stat[4]])
stats = consolidated_stats
elif len(stats) == 1:
diff --git a/app/mail.py b/app/mail.py
index 9c5c390..a3541dc 100644
--- a/app/mail.py
+++ b/app/mail.py
@@ -1,7 +1,6 @@
-from flask import render_template, Blueprint, redirect, url_for, request, abort, flash, request
+from flask import render_template, Blueprint, redirect, url_for, flash, request
from flask_user import login_required, current_user
-from app.models import db, Mail, CharacterInfo
-from datatables import ColumnDT, DataTables
+from app.models import Mail, CharacterInfo
from app.forms import SendMailForm
from app import gm_level, log_audit
from app.luclient import translate_from_locale, query_cdclient
@@ -31,37 +30,40 @@ def send():
log_audit(f"Sending {form.subject.data}: {form.body.data} to All Characters with {form.attachment_count.data} of item {form.attachment.data}")
for character in CharacterInfo.query.all():
Mail(
- sender_id = 0,
- sender_name = f"[GM] {current_user.username}",
- receiver_id = character.id,
- receiver_name = character.name,
- time_sent = time.time(),
- subject = form.subject.data,
- body = form.body.data,
- attachment_id = 0,
- attachment_lot = form.attachment.data,
- attachment_count = form.attachment_count.data
+ sender_id=0,
+ sender_name=f"[GM] {current_user.username}",
+ receiver_id=character.id,
+ receiver_name=character.name,
+ time_sent=time.time(),
+ subject=form.subject.data,
+ body=form.body.data,
+ attachment_id=0,
+ attachment_lot=form.attachment.data,
+ attachment_count=form.attachment_count.data
).save()
- log_audit(f"Sent {form.subject.data}: {form.body.data} to ({character.id}){character.name} with {form.attachment_count.data} of item {form.attachment.data}")
+ log_audit(f"Sent {form.subject.data}: \
+ {form.body.data} to ({character.id}){character.name} \
+ with {form.attachment_count.data} of item {form.attachment.data}")
else:
Mail(
- sender_id = 0,
- sender_name = f"[GM] {current_user.username}",
- receiver_id = form.recipient.data,
- receiver_name = CharacterInfo.query.filter(CharacterInfo.id == form.recipient.data).first().name,
- time_sent = time.time(),
- subject = form.subject.data,
- body = form.body.data,
- attachment_id = 0,
- attachment_lot = form.attachment.data,
- attachment_count = form.attachment_count.data
+ sender_id=0,
+ sender_name=f"[GM] {current_user.username}",
+ receiver_id=form.recipient.data,
+ receiver_name=CharacterInfo.query.filter(CharacterInfo.id == form.recipient.data).first().name,
+ time_sent=time.time(),
+ subject=form.subject.data,
+ body=form.body.data,
+ attachment_id=0,
+ attachment_lot=form.attachment.data,
+ attachment_count=form.attachment_count.data
).save()
- log_audit(f"Sent {form.subject.data}: {form.body.data} to ({form.recipient.data}){CharacterInfo.query.filter(CharacterInfo.id == form.recipient.data).first().name} with {form.attachment_count.data} of item {form.attachment.data}")
+ log_audit(f"Sent {form.subject.data}: \
+ {form.body.data} to ({form.recipient.data}){CharacterInfo.query.filter(CharacterInfo.id == form.recipient.data).first().name} \
+ with {form.attachment_count.data} of item {form.attachment.data}")
flash("Sent Mail", "success")
return redirect(url_for('mail.send'))
-
recipients = CharacterInfo.query.all()
for character in recipients:
form.recipient.choices.append((character.id, character.name))
@@ -74,7 +76,7 @@ def send():
for item in items:
name = translate_from_locale(f'Objects_{item[0]}_name')
if name == f'Objects_{item[0]}_name':
- name = (item[2] if (item[2] != "None" and item[2] !="" and item[2] != None) else item[1])
+ name = (item[2] if (item[2] != "None" and item[2] != "" and item[2] not None) else item[1])
form.attachment.choices.append(
(
item[0],
diff --git a/app/main.py b/app/main.py
index 4da900a..df3103a 100644
--- a/app/main.py
+++ b/app/main.py
@@ -1,18 +1,15 @@
-from flask import render_template, Blueprint, redirect, request, send_from_directory, make_response, send_file, current_app
-from flask_user import login_required, current_user
-import json, glob, os
-from wand import image
+from flask import render_template, Blueprint, send_from_directory
+from flask_user import current_user
-from app.models import Account, AccountInvitation, CharacterInfo
+from app.models import Account
from app.schemas import AccountSchema, CharacterInfoSchema
-from app.luclient import query_cdclient
-from app import gm_level
main_blueprint = Blueprint('main', __name__)
account_schema = AccountSchema()
char_info_schema = CharacterInfoSchema()
+
@main_blueprint.route('/', methods=['GET'])
def index():
"""Home/Index Page"""
diff --git a/app/models.py b/app/models.py
index 530bf0b..2e42c7e 100644
--- a/app/models.py
+++ b/app/models.py
@@ -1,6 +1,6 @@
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
-from flask_user import UserMixin, current_user
+from flask_user import UserMixin
from wtforms import ValidationError
import logging
@@ -12,6 +12,7 @@ from time import sleep
import random
import string
+
# retrying query to work around python trash collector
# killing connections of other gunicorn workers
class RetryingQuery(BaseQuery):
@@ -46,9 +47,11 @@ class RetryingQuery(BaseQuery):
raise
self.session.rollback()
+
db = SQLAlchemy(query_class=RetryingQuery)
migrate = Migrate()
+
class PlayKey(db.Model):
__tablename__ = 'play_keys'
id = db.Column(db.Integer, primary_key=True)
@@ -121,6 +124,7 @@ class PlayKey(db.Model):
db.session.commit()
db.session.refresh(self)
+
class Account(db.Model, UserMixin):
__tablename__ = 'accounts'
id = db.Column(
@@ -200,7 +204,7 @@ class Account(db.Model, UserMixin):
@staticmethod
def get_user_by_id(*, user_id=None):
- return User.query.filter(user_id == User.id).first()
+ return Account.query.filter(user_id == Account.id).first()
def save(self):
db.session.add(self)
@@ -211,6 +215,7 @@ class Account(db.Model, UserMixin):
db.session.delete(self)
db.session.commit()
+
class AccountInvitation(db.Model):
__tablename__ = 'account_invites'
id = db.Column(db.Integer, primary_key=True)
@@ -245,14 +250,10 @@ class AccountInvitation(db.Model):
db.session.delete(self)
db.session.commit()
-
@staticmethod
def get_user_by_id(*, user_id=None):
- return User.query.filter(user_id == User.id).first()
+ return Account.query.filter(user_id == Account.id).first()
- def delete(self):
- db.session.delete(self)
- db.session.commit()
# This table is cursed, see prop_clone_id
class CharacterInfo(db.Model):
@@ -327,6 +328,7 @@ class CharacterInfo(db.Model):
db.session.delete(self)
db.session.commit()
+
class CharacterXML(db.Model):
__tablename__ = 'charxml'
id = db.Column(
@@ -348,6 +350,7 @@ class CharacterXML(db.Model):
db.session.delete(self)
db.session.commit()
+
class CommandLog(db.Model):
__tablename__ = 'command_log'
id = db.Column(db.Integer, primary_key=True)
@@ -364,7 +367,7 @@ class CommandLog(db.Model):
passive_deletes=True
)
- command = db.Column(
+ command = db.Column(
mysql.VARCHAR(256),
nullable=False
)
@@ -378,6 +381,7 @@ class CommandLog(db.Model):
db.session.delete(self)
db.session.commit()
+
class Friends(db.Model):
__tablename__ = 'friends'
player_id = db.Column(
@@ -423,6 +427,7 @@ class Friends(db.Model):
db.session.delete(self)
db.session.commit()
+
class Leaderboard(db.Model):
__tablename__ = 'leaderboard'
id = db.Column(db.Integer, primary_key=True)
@@ -472,6 +477,7 @@ class Leaderboard(db.Model):
db.session.delete(self)
db.session.commit()
+
class Mail(db.Model):
__tablename__ = 'mail'
id = db.Column(
@@ -560,6 +566,7 @@ class Mail(db.Model):
db.session.delete(self)
db.session.commit()
+
class ObjectIDTracker(db.Model):
__tablename__ = 'object_id_tracker'
last_object_id = db.Column(
@@ -569,6 +576,7 @@ class ObjectIDTracker(db.Model):
server_default='0'
)
+
class PetNames(db.Model):
__tablename__ = 'pet_names'
id = db.Column(mysql.BIGINT, primary_key=True)
@@ -582,7 +590,7 @@ class PetNames(db.Model):
server_default='0'
)
- owner_id = db.Column(
+ owner_id = db.Column(
mysql.BIGINT,
nullable=True
)
@@ -605,7 +613,7 @@ class Property(db.Model):
autoincrement=False
)
- owner_id = db.Column(
+ owner_id = db.Column(
mysql.BIGINT,
db.ForeignKey(CharacterInfo.id, ondelete='CASCADE'),
nullable=False
@@ -623,7 +631,7 @@ class Property(db.Model):
nullable=False,
)
- clone_id = db.Column(
+ clone_id = db.Column(
mysql.BIGINT(unsigned=True),
db.ForeignKey(CharacterInfo.prop_clone_id, ondelete='CASCADE'),
)
@@ -763,6 +771,7 @@ class UGC(db.Model):
db.session.delete(self)
db.session.commit()
+
class PropertyContent(db.Model):
__tablename__ = 'properties_contents'
id = db.Column(
@@ -843,6 +852,7 @@ class PropertyContent(db.Model):
db.session.delete(self)
db.session.commit()
+
class ActivityLog(db.Model):
__tablename__ = 'activity_log'
id = db.Column(mysql.INTEGER, primary_key=True)
@@ -883,6 +893,7 @@ class ActivityLog(db.Model):
db.session.delete(self)
db.session.commit()
+
class BugReport(db.Model):
__tablename__ = 'bug_reports'
id = db.Column(mysql.INTEGER, primary_key=True)
@@ -944,6 +955,7 @@ class BugReport(db.Model):
db.session.delete(self)
db.session.commit()
+
class Server(db.Model):
__tablename__ = 'servers'
id = db.Column(
@@ -1016,6 +1028,7 @@ class Reports(db.Model):
db.session.delete(self)
db.session.commit()
+
class AuditLog(db.Model):
__tablename__ = 'audit_logs'
id = db.Column(
diff --git a/app/moderation.py b/app/moderation.py
index 38b66ba..3ab03f0 100644
--- a/app/moderation.py
+++ b/app/moderation.py
@@ -2,7 +2,6 @@ from flask import render_template, Blueprint, redirect, url_for, request, flash,
from flask_user import login_required
from app.models import PetNames, db, CharacterXML, CharacterInfo
from datatables import ColumnDT, DataTables
-from app.forms import CreatePlayKeyForm, EditPlayKeyForm
from app import gm_level, log_audit, scheduler
moderation_blueprint = Blueprint('moderation', __name__)
@@ -20,7 +19,7 @@ def index(status):
@gm_level(3)
def approve_pet(id):
- pet_data = PetNames.query.filter(PetNames.id == id).first()
+ pet_data = PetNames.query.filter(PetNames.id == id).first()
pet_data.approved = 2
log_audit(f"Approved pet name {pet_data.pet_name} from {pet_data.owner_id}")
@@ -34,7 +33,7 @@ def approve_pet(id):
@gm_level(3)
def reject_pet(id):
- pet_data = PetNames.query.filter(PetNames.id == id).first()
+ pet_data = PetNames.query.filter(PetNames.id == id).first()
pet_data.approved = 0
log_audit(f"Rejected pet name {pet_data.pet_name} from {pet_data.owner_id}")
@@ -55,16 +54,15 @@ def get_pets(status="all"):
]
query = None
- if status=="all":
+ if status == "all":
query = db.session.query().select_from(PetNames)
- elif status=="approved":
- query = db.session.query().select_from(PetNames).filter(PetNames.approved==2)
- elif status=="unapproved":
- query = db.session.query().select_from(PetNames).filter(PetNames.approved==1)
+ elif status == "approved":
+ query = db.session.query().select_from(PetNames).filter(PetNames.approved == 2)
+ elif status == "unapproved":
+ query = db.session.query().select_from(PetNames).filter(PetNames.approved == 1)
else:
raise Exception("Not a valid filter")
-
params = request.args.to_dict()
rowTable = DataTables(params, query, columns)
@@ -116,8 +114,8 @@ def get_pets(status="all"):
{CharacterInfo.query.filter(CharacterInfo.id==pet_data['3']).first().name}
"""
- except Exception as e:
- PetNames.query.filter(PetNames.id==id).first().delete()
+ except Exception:
+ PetNames.query.filter(PetNames.id == id).first().delete()
pet_data["0"] = "Deleted Refresh to make go away"
pet_data["3"] = "Character Deleted"
else:
@@ -131,7 +129,7 @@ def pet_name_maintenance():
with scheduler.app.app_context():
# associate pet names to characters
current_app.logger.info("Started Pet Name Maintenance")
- unassociated_pets = PetNames.query.filter(PetNames.owner_id == None).all()
+ unassociated_pets = PetNames.query.filter(PetNames.owner_id is None).all()
if unassociated_pets:
current_app.logger.info("Found un-associated pets")
for pet in unassociated_pets:
@@ -143,11 +141,11 @@ def pet_name_maintenance():
pet.delete()
# auto-moderate based on already moderated names
- unmoderated_pets = PetNames.query.filter(PetNames.approved==1).all()
+ unmoderated_pets = PetNames.query.filter(PetNames.approved == 1).all()
if unmoderated_pets:
current_app.logger.info("Found un-moderated Pets")
for pet in unmoderated_pets:
- existing_pet = PetNames.query.filter(PetNames.approved.in_([0,2])).filter(PetNames.pet_name == pet.pet_name).first()
+ existing_pet = PetNames.query.filter(PetNames.approved.in_([0, 2])).filter(PetNames.pet_name == pet.pet_name).first()
if existing_pet:
pet.approved = existing_pet.approved
pet.save()
diff --git a/app/play_keys.py b/app/play_keys.py
index fcebf0a..d6a0517 100644
--- a/app/play_keys.py
+++ b/app/play_keys.py
@@ -1,14 +1,14 @@
-from flask import render_template, Blueprint, redirect, url_for, request, abort, flash
-from flask_user import login_required, current_user
-from app.models import Account, AccountInvitation, PlayKey, db
+from flask import render_template, Blueprint, redirect, url_for, request, flash
+from flask_user import login_required
+from app.models import Account, PlayKey, db
from datatables import ColumnDT, DataTables
from app.forms import CreatePlayKeyForm, EditPlayKeyForm
from app import gm_level, log_audit
play_keys_blueprint = Blueprint('play_keys', __name__)
-# Key creation page
+# Key creation page
@play_keys_blueprint.route('/', methods=['GET'])
@login_required
@gm_level(9)
@@ -45,7 +45,7 @@ def bulk_create():
@gm_level(9)
def delete(id):
key = PlayKey.query.filter(PlayKey.id == id).first()
- associated_accounts = Account.query.filter(Account.play_key_id==id).all()
+ # associated_accounts = Account.query.filter(Account.play_key_id==id).all()
log_audit(f"Deleted Play Key {key.key_string}")
flash(f"Deleted Play Key {key.key_string}", "danger")
key.delete()
@@ -56,7 +56,7 @@ def delete(id):
@login_required
@gm_level(9)
def edit(id):
- key = PlayKey.query.filter(PlayKey.id==id).first()
+ key = PlayKey.query.filter(PlayKey.id == id).first()
form = EditPlayKeyForm()
if form.validate_on_submit():
@@ -84,7 +84,7 @@ def edit(id):
@gm_level(9)
def view(id):
key = PlayKey.query.filter(PlayKey.id == id).first()
- accounts = Account.query.filter(Account.play_key_id==id).all()
+ accounts = Account.query.filter(Account.play_key_id == id).all()
return render_template('play_keys/view.html.j2', key=key, accounts=accounts)
@@ -125,7 +125,12 @@ def get():
Delete
-