fix context issue
This commit is contained in:
		| @@ -128,23 +128,24 @@ def get_pets(status="all"): | |||||||
|  |  | ||||||
| @scheduler.task("cron", id="pet_name_maintenance", minute=0, timezone="UTC") | @scheduler.task("cron", id="pet_name_maintenance", minute=0, timezone="UTC") | ||||||
| def pet_name_maintenance(): | def pet_name_maintenance(): | ||||||
|     # associate pet names to characters |     with scheduler.app.app_context(): | ||||||
|     unassociated_pets = PetNames.query.filter(PetNames.owner_id == None).all() |         # associate pet names to characters | ||||||
|     if unassociated_pets: |         unassociated_pets = PetNames.query.filter(PetNames.owner_id == None).all() | ||||||
|         for pet in unassociated_pets: |         if unassociated_pets: | ||||||
|             owner = CharacterXML.query.filter(CharacterXML.xml_data.like(f"%<p id=\"{pet.id}\" l=\"%")).first() |             for pet in unassociated_pets: | ||||||
|             if owner: |                 owner = CharacterXML.query.filter(CharacterXML.xml_data.like(f"%<p id=\"{pet.id}\" l=\"%")).first() | ||||||
|                 pet.owner_id = owner.id |                 if owner: | ||||||
|                 pet.save() |                     pet.owner_id = owner.id | ||||||
|             else: |                     pet.save() | ||||||
|                 pet.delete() |                 else: | ||||||
|  |                     pet.delete() | ||||||
|  |  | ||||||
|     # auto-moderate based on already moderated names |         # 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: |         if unmoderated_pets: | ||||||
|         for pet in unmoderated_pets: |             for pet in unmoderated_pets: | ||||||
|             existing_pet = PetNames.query.filter(PetNames.approved.in_([0,2])).first() |                 existing_pet = PetNames.query.filter(PetNames.approved.in_([0,2])).first() | ||||||
|             if existing_pet: |                 if existing_pet: | ||||||
|                 pet.approved = existing_pet.approved |                     pet.approved = existing_pet.approved | ||||||
|                 pet.save() |                     pet.save() | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Aaron Kimbre
					Aaron Kimbre