feat: Add unchecked AN cleanup to health check
This commit is contained in:
parent
f404cfa0a3
commit
df41028e99
@ -1,6 +1,6 @@
|
|||||||
{% extends "fellchensammlung/base_generic.html" %}
|
{% extends "fellchensammlung/base_generic.html" %}
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
{% block title %}<title>{% translate "Instanz-Check" %}</title> %}
|
{% block title %}<title>{% translate "Instanz-Check" %}</title> {% endblock %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<h1>{% translate "Instanz-Check" %}</h1>
|
<h1>{% translate "Instanz-Check" %}</h1>
|
||||||
@ -56,6 +56,22 @@
|
|||||||
<p>{{ number_not_geocoded_rescue_orgs }}/{{ number_of_rescue_orgs }}</p>
|
<p>{{ number_not_geocoded_rescue_orgs }}/{{ number_of_rescue_orgs }}</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
<h2>{% translate "Nicht-geprüfte Vermittlungen" %}</h2>
|
||||||
|
{% if number_unchecked_ans > 0 %}
|
||||||
|
<details>
|
||||||
|
<summary>{{ number_unchecked_ans }}</summary>
|
||||||
|
<ul>
|
||||||
|
{% for unchecked_an in unchecked_ans %}
|
||||||
|
<li>
|
||||||
|
<a href="{{ unchecked_an.get_absolute_url }}">{{ unchecked_an.name }}</a>
|
||||||
|
</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
</details>
|
||||||
|
{% else %}
|
||||||
|
<p>{{ number_unchecked_ans }}</p>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<form class="notification-card-mark-read" method="post">
|
<form class="notification-card-mark-read" method="post">
|
||||||
{% csrf_token %}
|
{% csrf_token %}
|
||||||
<input type="hidden" name="action" value="clean_locations">
|
<input type="hidden" name="action" value="clean_locations">
|
||||||
@ -63,5 +79,13 @@
|
|||||||
<i class="fa-solid fa-broom"></i> {% translate "Erneut lokalisieren" %}
|
<i class="fa-solid fa-broom"></i> {% translate "Erneut lokalisieren" %}
|
||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
<form class="notification-card-mark-read" method="post">
|
||||||
|
{% csrf_token %}
|
||||||
|
<input type="hidden" name="action" value="deactivate_unchecked_adoption_notices">
|
||||||
|
<button class="btn" type="submit" id="submit">
|
||||||
|
<i class="fa-solid fa-broom"></i> {% translate "Deaktivire ungeprüfte Vermittlungen" %}
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
{% endblock content %}
|
{% endblock content %}
|
||||||
|
@ -1,4 +1,8 @@
|
|||||||
from fellchensammlung.models import AdoptionNotice, Location, RescueOrganization
|
from django.utils import timezone
|
||||||
|
from datetime import timedelta
|
||||||
|
|
||||||
|
from fellchensammlung.models import AdoptionNotice, Location, RescueOrganization, AdoptionNoticeStatus
|
||||||
|
|
||||||
|
|
||||||
def clean_locations(quiet=True):
|
def clean_locations(quiet=True):
|
||||||
# ADOPTION NOTICES
|
# ADOPTION NOTICES
|
||||||
@ -42,3 +46,20 @@ def clean_locations(quiet=True):
|
|||||||
num_new = num_without_location - num_without_location_new
|
num_new = num_without_location - num_without_location_new
|
||||||
if not quiet:
|
if not quiet:
|
||||||
print(f"Added {num_new} new locations")
|
print(f"Added {num_new} new locations")
|
||||||
|
|
||||||
|
|
||||||
|
def get_unchecked_adoption_notices(weeks=3):
|
||||||
|
now = timezone.now()
|
||||||
|
three_weeks_ago = now - timedelta(weeks=weeks)
|
||||||
|
|
||||||
|
# Query for active adoption notices that were checked in the last three weeks
|
||||||
|
unchecked_adoptions = AdoptionNotice.objects.filter(
|
||||||
|
last_checked__gte=three_weeks_ago
|
||||||
|
)
|
||||||
|
active_unchecked_adoptions = [adoption for adoption in unchecked_adoptions if adoption.is_active]
|
||||||
|
return active_unchecked_adoptions
|
||||||
|
|
||||||
|
|
||||||
|
def deactivate_unchecked_adoption_notices():
|
||||||
|
for adoption_notice in get_unchecked_adoption_notices(weeks=3):
|
||||||
|
AdoptionNoticeStatus.objects.get(adoption_notice=adoption_notice).deactivate_unchecked()
|
||||||
|
@ -21,7 +21,7 @@ from .forms import AdoptionNoticeForm, AdoptionNoticeFormWithDateWidget, ImageFo
|
|||||||
from .models import Language, Announcement
|
from .models import Language, Announcement
|
||||||
from .tools.geo import GeoAPI
|
from .tools.geo import GeoAPI
|
||||||
from .tools.metrics import gather_metrics_data
|
from .tools.metrics import gather_metrics_data
|
||||||
from .tools.admin import clean_locations
|
from .tools.admin import clean_locations, get_unchecked_adoption_notices, deactivate_unchecked_adoption_notices
|
||||||
from .tasks import add_adoption_notice_location
|
from .tasks import add_adoption_notice_location
|
||||||
|
|
||||||
|
|
||||||
@ -470,6 +470,8 @@ def instance_health_check(request):
|
|||||||
action = request.POST.get("action")
|
action = request.POST.get("action")
|
||||||
if action == "clean_locations":
|
if action == "clean_locations":
|
||||||
clean_locations(quiet=False)
|
clean_locations(quiet=False)
|
||||||
|
elif action == "deactivate_unchecked_adoption_notices":
|
||||||
|
deactivate_unchecked_adoption_notices()
|
||||||
|
|
||||||
number_of_adoption_notices = AdoptionNotice.objects.all().count()
|
number_of_adoption_notices = AdoptionNotice.objects.all().count()
|
||||||
none_geocoded_adoption_notices = AdoptionNotice.objects.filter(location__isnull=True)
|
none_geocoded_adoption_notices = AdoptionNotice.objects.filter(location__isnull=True)
|
||||||
@ -479,6 +481,9 @@ def instance_health_check(request):
|
|||||||
none_geocoded_rescue_orgs = RescueOrganization.objects.filter(location__isnull=True)
|
none_geocoded_rescue_orgs = RescueOrganization.objects.filter(location__isnull=True)
|
||||||
number_not_geocoded_rescue_orgs = len(none_geocoded_rescue_orgs)
|
number_not_geocoded_rescue_orgs = len(none_geocoded_rescue_orgs)
|
||||||
|
|
||||||
|
unchecked_ans = get_unchecked_adoption_notices()
|
||||||
|
number_unchecked_ans = len(unchecked_ans)
|
||||||
|
|
||||||
# CHECK FOR MISSING TEXTS
|
# CHECK FOR MISSING TEXTS
|
||||||
languages = Language.objects.all()
|
languages = Language.objects.all()
|
||||||
texts = Text.objects.all()
|
texts = Text.objects.all()
|
||||||
@ -498,7 +503,9 @@ def instance_health_check(request):
|
|||||||
"number_of_rescue_orgs": number_of_rescue_orgs,
|
"number_of_rescue_orgs": number_of_rescue_orgs,
|
||||||
"number_not_geocoded_rescue_orgs": number_not_geocoded_rescue_orgs,
|
"number_not_geocoded_rescue_orgs": number_not_geocoded_rescue_orgs,
|
||||||
"none_geocoded_rescue_orgs": none_geocoded_rescue_orgs,
|
"none_geocoded_rescue_orgs": none_geocoded_rescue_orgs,
|
||||||
"missing_texts": missing_texts
|
"missing_texts": missing_texts,
|
||||||
|
"number_unchecked_ans": number_unchecked_ans,
|
||||||
|
"unchecked_ans": unchecked_ans
|
||||||
}
|
}
|
||||||
|
|
||||||
return render(request, 'fellchensammlung/instance-health-check.html', context=context)
|
return render(request, 'fellchensammlung/instance-health-check.html', context=context)
|
||||||
|
Loading…
Reference in New Issue
Block a user