feat: Add basic redirect service
This commit is contained in:
parent
96c0c1218f
commit
0d52101f22
@ -50,7 +50,7 @@
|
|||||||
{% if adoption_notice.further_information %}
|
{% if adoption_notice.further_information %}
|
||||||
<td>
|
<td>
|
||||||
<form method="get" action="{% url 'external-site' %}">
|
<form method="get" action="{% url 'external-site' %}">
|
||||||
<input type="hidden" name="url" value="adoption_notice.further_information">
|
<input type="hidden" name="url" value="{{ adoption_notice.further_information }}">
|
||||||
<button class="btn" type="submit" id="submit">
|
<button class="btn" type="submit" id="submit">
|
||||||
{{ adoption_notice.further_information | domain }} <i class="fa-solid fa-arrow-up-right-from-square"></i>
|
{{ adoption_notice.further_information | domain }} <i class="fa-solid fa-arrow-up-right-from-square"></i>
|
||||||
</button>
|
</button>
|
||||||
|
@ -0,0 +1,10 @@
|
|||||||
|
{% extends "fellchensammlung/base_generic.html" %}
|
||||||
|
{% load i18n %}
|
||||||
|
{% block content %}
|
||||||
|
<div class="card">
|
||||||
|
{% blocktranslate %}
|
||||||
|
<p>Achtung du verlässt notfellchen.org</p>
|
||||||
|
{% endblocktranslate %}
|
||||||
|
<a href="{{ url }}" class="btn" >{% translate "Weiter" %}</a>
|
||||||
|
</div>
|
||||||
|
{% endblock content %}
|
@ -79,5 +79,9 @@ urlpatterns = [
|
|||||||
#########
|
#########
|
||||||
path('api/', include('fellchensammlung.api.urls')),
|
path('api/', include('fellchensammlung.api.urls')),
|
||||||
|
|
||||||
|
###################
|
||||||
|
## External Site ##
|
||||||
|
###################
|
||||||
|
path('external-site/', views.external_site_warning, name="external-site"),
|
||||||
|
|
||||||
]
|
]
|
||||||
|
@ -13,7 +13,8 @@ from notfellchen import settings
|
|||||||
|
|
||||||
from fellchensammlung import logger
|
from fellchensammlung import logger
|
||||||
from .models import AdoptionNotice, Text, Animal, Rule, Image, Report, ModerationAction, \
|
from .models import AdoptionNotice, Text, Animal, Rule, Image, Report, ModerationAction, \
|
||||||
User, Location, AdoptionNoticeStatus, Subscriptions, CommentNotification, BaseNotification, RescueOrganization, Species
|
User, Location, AdoptionNoticeStatus, Subscriptions, CommentNotification, BaseNotification, RescueOrganization, \
|
||||||
|
Species
|
||||||
from .forms import AdoptionNoticeForm, AdoptionNoticeFormWithDateWidget, ImageForm, ReportAdoptionNoticeForm, \
|
from .forms import AdoptionNoticeForm, AdoptionNoticeFormWithDateWidget, ImageForm, ReportAdoptionNoticeForm, \
|
||||||
CommentForm, ReportCommentForm, AnimalForm, \
|
CommentForm, ReportCommentForm, AnimalForm, \
|
||||||
AdoptionNoticeSearchForm, AnimalFormWithDateWidget, AdoptionNoticeFormWithDateWidgetAutoAnimal
|
AdoptionNoticeSearchForm, AnimalFormWithDateWidget, AdoptionNoticeFormWithDateWidgetAutoAnimal
|
||||||
@ -73,7 +74,7 @@ def change_language(request):
|
|||||||
def adoption_notice_detail(request, adoption_notice_id):
|
def adoption_notice_detail(request, adoption_notice_id):
|
||||||
adoption_notice = AdoptionNotice.objects.get(id=adoption_notice_id)
|
adoption_notice = AdoptionNotice.objects.get(id=adoption_notice_id)
|
||||||
if request.user.is_authenticated:
|
if request.user.is_authenticated:
|
||||||
try:
|
try:
|
||||||
subscription = Subscriptions.objects.get(owner=request.user, adoption_notice=adoption_notice)
|
subscription = Subscriptions.objects.get(owner=request.user, adoption_notice=adoption_notice)
|
||||||
is_subscribed = True
|
is_subscribed = True
|
||||||
except Subscriptions.DoesNotExist:
|
except Subscriptions.DoesNotExist:
|
||||||
@ -101,9 +102,9 @@ def adoption_notice_detail(request, adoption_notice_id):
|
|||||||
# Create a notification but only if the user is not the one that posted the comment
|
# Create a notification but only if the user is not the one that posted the comment
|
||||||
if subscription.owner != request.user:
|
if subscription.owner != request.user:
|
||||||
notification = CommentNotification(user=subscription.owner,
|
notification = CommentNotification(user=subscription.owner,
|
||||||
title=f"{adoption_notice.name} - Neuer Kommentar",
|
title=f"{adoption_notice.name} - Neuer Kommentar",
|
||||||
text=f"{request.user}: {comment_instance.text}",
|
text=f"{request.user}: {comment_instance.text}",
|
||||||
comment=comment_instance)
|
comment=comment_instance)
|
||||||
notification.save()
|
notification.save()
|
||||||
else:
|
else:
|
||||||
comment_form = CommentForm(instance=adoption_notice)
|
comment_form = CommentForm(instance=adoption_notice)
|
||||||
@ -111,13 +112,13 @@ def adoption_notice_detail(request, adoption_notice_id):
|
|||||||
Subscriptions.objects.create(owner=request.user, adoption_notice=adoption_notice)
|
Subscriptions.objects.create(owner=request.user, adoption_notice=adoption_notice)
|
||||||
is_subscribed = True
|
is_subscribed = True
|
||||||
if action == "unsubscribe":
|
if action == "unsubscribe":
|
||||||
subscription.delete()
|
subscription.delete()
|
||||||
is_subscribed = False
|
is_subscribed = False
|
||||||
else:
|
else:
|
||||||
raise PermissionDenied
|
raise PermissionDenied
|
||||||
else:
|
else:
|
||||||
comment_form = CommentForm(instance=adoption_notice)
|
comment_form = CommentForm(instance=adoption_notice)
|
||||||
context = {"adoption_notice": adoption_notice,"comment_form": comment_form, "user": request.user,
|
context = {"adoption_notice": adoption_notice, "comment_form": comment_form, "user": request.user,
|
||||||
"has_edit_permission": has_edit_permission, "is_subscribed": is_subscribed}
|
"has_edit_permission": has_edit_permission, "is_subscribed": is_subscribed}
|
||||||
return render(request, 'fellchensammlung/details/detail_adoption_notice.html', context=context)
|
return render(request, 'fellchensammlung/details/detail_adoption_notice.html', context=context)
|
||||||
|
|
||||||
@ -167,8 +168,9 @@ def search(request):
|
|||||||
adoption_notices_in_distance = active_adoptions
|
adoption_notices_in_distance = active_adoptions
|
||||||
else:
|
else:
|
||||||
adoption_notices_in_distance = [a for a in active_adoptions if a.in_distance(search_position, max_distance)]
|
adoption_notices_in_distance = [a for a in active_adoptions if a.in_distance(search_position, max_distance)]
|
||||||
|
|
||||||
context = {"adoption_notices": adoption_notices_in_distance, "search_form": search_form, "place_not_found": place_not_found}
|
context = {"adoption_notices": adoption_notices_in_distance, "search_form": search_form,
|
||||||
|
"place_not_found": place_not_found}
|
||||||
else:
|
else:
|
||||||
latest_adoption_list = AdoptionNotice.objects.order_by("-created_at")
|
latest_adoption_list = AdoptionNotice.objects.order_by("-created_at")
|
||||||
active_adoptions = [adoption for adoption in latest_adoption_list if adoption.is_active]
|
active_adoptions = [adoption for adoption in latest_adoption_list if adoption.is_active]
|
||||||
@ -180,7 +182,8 @@ def search(request):
|
|||||||
@login_required
|
@login_required
|
||||||
def add_adoption_notice(request):
|
def add_adoption_notice(request):
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
form = AdoptionNoticeFormWithDateWidgetAutoAnimal(request.POST, request.FILES, in_adoption_notice_creation_flow=True)
|
form = AdoptionNoticeFormWithDateWidgetAutoAnimal(request.POST, request.FILES,
|
||||||
|
in_adoption_notice_creation_flow=True)
|
||||||
|
|
||||||
if form.is_valid():
|
if form.is_valid():
|
||||||
instance = form.save(commit=False)
|
instance = form.save(commit=False)
|
||||||
@ -195,21 +198,23 @@ def add_adoption_notice(request):
|
|||||||
major_status = AdoptionNoticeStatus.ACTIVE
|
major_status = AdoptionNoticeStatus.ACTIVE
|
||||||
minor_status = AdoptionNoticeStatus.MINOR_STATUS_CHOICES[AdoptionNoticeStatus.ACTIVE]["searching"]
|
minor_status = AdoptionNoticeStatus.MINOR_STATUS_CHOICES[AdoptionNoticeStatus.ACTIVE]["searching"]
|
||||||
else:
|
else:
|
||||||
major_status=AdoptionNoticeStatus.AWAITING_ACTION
|
major_status = AdoptionNoticeStatus.AWAITING_ACTION
|
||||||
minor_status=AdoptionNoticeStatus.MINOR_STATUS_CHOICES[AdoptionNoticeStatus.AWAITING_ACTION]["waiting_for_review"]
|
minor_status = AdoptionNoticeStatus.MINOR_STATUS_CHOICES[AdoptionNoticeStatus.AWAITING_ACTION][
|
||||||
|
"waiting_for_review"]
|
||||||
status = AdoptionNoticeStatus.objects.create(major_status=major_status,
|
status = AdoptionNoticeStatus.objects.create(major_status=major_status,
|
||||||
minor_status=minor_status,
|
minor_status=minor_status,
|
||||||
adoption_notice=instance)
|
adoption_notice=instance)
|
||||||
status.save()
|
status.save()
|
||||||
|
|
||||||
# Get the species and number of animals from the form
|
# Get the species and number of animals from the form
|
||||||
species = form.cleaned_data["species"]
|
species = form.cleaned_data["species"]
|
||||||
sex = form.cleaned_data["sex"]
|
sex = form.cleaned_data["sex"]
|
||||||
num_animals = form.cleaned_data["num_animals"]
|
num_animals = form.cleaned_data["num_animals"]
|
||||||
date_of_birth = form.cleaned_data["date_of_birth"]
|
date_of_birth = form.cleaned_data["date_of_birth"]
|
||||||
for i in range(0, num_animals):
|
for i in range(0, num_animals):
|
||||||
Animal.objects.create(owner=request.user,
|
Animal.objects.create(owner=request.user,
|
||||||
name=f"{species} {i+1}", adoption_notice=instance, species=species, sex=sex, date_of_birth=date_of_birth)
|
name=f"{species} {i + 1}", adoption_notice=instance, species=species, sex=sex,
|
||||||
|
date_of_birth=date_of_birth)
|
||||||
return redirect(reverse("adoption-notice-detail", args=[instance.pk]))
|
return redirect(reverse("adoption-notice-detail", args=[instance.pk]))
|
||||||
else:
|
else:
|
||||||
form = AdoptionNoticeFormWithDateWidgetAutoAnimal(in_adoption_notice_creation_flow=True)
|
form = AdoptionNoticeFormWithDateWidgetAutoAnimal(in_adoption_notice_creation_flow=True)
|
||||||
@ -420,6 +425,7 @@ def modqueue(request):
|
|||||||
context = {"reports": open_reports}
|
context = {"reports": open_reports}
|
||||||
return render(request, 'fellchensammlung/modqueue.html', context=context)
|
return render(request, 'fellchensammlung/modqueue.html', context=context)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def updatequeue(request):
|
def updatequeue(request):
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
@ -444,7 +450,7 @@ def updatequeue(request):
|
|||||||
|
|
||||||
|
|
||||||
def map(request):
|
def map(request):
|
||||||
adoption_notices = AdoptionNotice.objects.all() #TODO: Filter to active
|
adoption_notices = AdoptionNotice.objects.all() #TODO: Filter to active
|
||||||
context = {"adoption_notices_map": adoption_notices}
|
context = {"adoption_notices_map": adoption_notices}
|
||||||
return render(request, 'fellchensammlung/map.html', context=context)
|
return render(request, 'fellchensammlung/map.html', context=context)
|
||||||
|
|
||||||
@ -453,6 +459,7 @@ def metrics(request):
|
|||||||
data = gather_metrics_data()
|
data = gather_metrics_data()
|
||||||
return JsonResponse(data)
|
return JsonResponse(data)
|
||||||
|
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def instance_health_check(request):
|
def instance_health_check(request):
|
||||||
"""
|
"""
|
||||||
@ -467,7 +474,6 @@ def instance_health_check(request):
|
|||||||
none_geocoded_adoption_notices = AdoptionNotice.objects.filter(location__isnull=True)
|
none_geocoded_adoption_notices = AdoptionNotice.objects.filter(location__isnull=True)
|
||||||
number_not_geocoded_adoption_notices = len(none_geocoded_adoption_notices)
|
number_not_geocoded_adoption_notices = len(none_geocoded_adoption_notices)
|
||||||
|
|
||||||
|
|
||||||
number_of_rescue_orgs = RescueOrganization.objects.all().count()
|
number_of_rescue_orgs = RescueOrganization.objects.all().count()
|
||||||
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)
|
||||||
@ -494,7 +500,14 @@ def instance_health_check(request):
|
|||||||
"missing_texts": missing_texts
|
"missing_texts": missing_texts
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return render(request, 'fellchensammlung/instance-health-check.html', context=context)
|
return render(request, 'fellchensammlung/instance-health-check.html', context=context)
|
||||||
|
|
||||||
|
|
||||||
|
def external_site_warning(request):
|
||||||
|
url = request.GET.get("url")
|
||||||
|
context = {"url": url}
|
||||||
|
language_code = translation.get_language()
|
||||||
|
lang = Language.objects.get(languagecode=language_code)
|
||||||
|
Text.get_texts(["external_site_warning", "good_adoption_practices"], language=lang)
|
||||||
|
|
||||||
|
return render(request, 'fellchensammlung/external_site_warning.html', context=context)
|
||||||
|
Loading…
Reference in New Issue
Block a user