diff --git a/app/models.py b/app/models.py index df557a3..5a44a11 100644 --- a/app/models.py +++ b/app/models.py @@ -582,6 +582,19 @@ class PetNames(db.Model): server_default='0' ) + owner_id = db.Column( + mysql.BIGINT, + db.ForeignKey(CharacterInfo.id, ondelete='CASCADE'), + nullable=True + ) + + owner = db.relationship( + 'CharacterInfo', + foreign_keys=[owner_id], + backref="pet_owner", + passive_deletes=True + ) + def save(self): db.session.add(self) db.session.commit() diff --git a/app/moderation.py b/app/moderation.py index a9cd9d6..10c348a 100644 --- a/app/moderation.py +++ b/app/moderation.py @@ -1,6 +1,6 @@ from flask import render_template, Blueprint, redirect, url_for, request, abort, flash from flask_user import login_required -from app.models import PetNames, db +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 @@ -47,10 +47,14 @@ def reject_pet(id): @login_required @gm_level(3) def get_pets(status="all"): + # call this to make things nicer + accociate_pets_and_owners() + columns = [ ColumnDT(PetNames.id), ColumnDT(PetNames.pet_name), ColumnDT(PetNames.approved), + ColumnDT(PetNames.owner_id), ] query = None @@ -107,4 +111,21 @@ def get_pets(status="all"): """ pet_data["2"] = "Rejected" + pet_data["3"] = f""" + + {CharacterInfo.query.filter(CharacterInfo.id==pet_data['3']).first().name} + + """ + return data + + +def accociate_pets_and_owners(): + pets = PetNames.query.filter(PetNames.owner_id == None).all() + if pets: + for pet in pets: + owner = CharacterXML.query.filter(CharacterXML.xml_data.like(f"%{pet.id}%")).first() + if owner: + pet.owner_id = owner.id + pet.save() diff --git a/app/templates/moderation/index.html.j2 b/app/templates/moderation/index.html.j2 index 596e5f9..923b61d 100644 --- a/app/templates/moderation/index.html.j2 +++ b/app/templates/moderation/index.html.j2 @@ -34,6 +34,7 @@