feat: Add basic embeddable view for ans of rescue orgs
This commit is contained in:
0
src/fellchensammlung/aviews/__init__.py
Normal file
0
src/fellchensammlung/aviews/__init__.py
Normal file
18
src/fellchensammlung/aviews/embeddables.py
Normal file
18
src/fellchensammlung/aviews/embeddables.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
from django.shortcuts import get_object_or_404, render
|
||||||
|
|
||||||
|
from fellchensammlung.aviews.helpers import headers
|
||||||
|
from fellchensammlung.models import RescueOrganization, AdoptionNotice, Species
|
||||||
|
|
||||||
|
|
||||||
|
@headers({"X-Robots-Tag": "noindex"})
|
||||||
|
def list_ans_per_rescue_organization(request, rescue_organization_id, species_slug=None):
|
||||||
|
org = get_object_or_404(RescueOrganization, pk=rescue_organization_id)
|
||||||
|
if species_slug is None:
|
||||||
|
adoption_notices = AdoptionNotice.objects.filter(organization=org)
|
||||||
|
else:
|
||||||
|
ans_of_rescue_org = AdoptionNotice.objects.filter(organization=org)
|
||||||
|
species = get_object_or_404(Species, slug=species_slug)
|
||||||
|
adoption_notices = [adoption_notice for adoption_notice in ans_of_rescue_org if species in adoption_notice.species]
|
||||||
|
|
||||||
|
template = 'fellchensammlung/embeddables/list-adoption-notices.html'
|
||||||
|
return render(request, template, context={"adoption_notices": adoption_notices})
|
23
src/fellchensammlung/aviews/helpers.py
Normal file
23
src/fellchensammlung/aviews/helpers.py
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
|
||||||
|
def headers(headers):
|
||||||
|
"""Decorator adding arbitrary HTTP headers to the response.
|
||||||
|
|
||||||
|
This decorator adds HTTP headers specified in the argument (map), to the
|
||||||
|
HTTPResponse returned by the function being decorated.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
@headers({'Refresh': '10', 'X-Bender': 'Bite my shiny, metal ass!'})
|
||||||
|
def index(request):
|
||||||
|
....
|
||||||
|
Source: https://djangosnippets.org/snippets/275/
|
||||||
|
"""
|
||||||
|
def headers_wrapper(fun):
|
||||||
|
def wrapped_function(*args, **kwargs):
|
||||||
|
response = fun(*args, **kwargs)
|
||||||
|
for key in headers:
|
||||||
|
response[key] = headers[key]
|
||||||
|
return response
|
||||||
|
return wrapped_function
|
||||||
|
return headers_wrapper
|
||||||
|
|
12
src/fellchensammlung/aviews/urls.py
Normal file
12
src/fellchensammlung/aviews/urls.py
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
from django.urls import path
|
||||||
|
|
||||||
|
from . import embeddables
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
path("tierschutzorganisationen/<int:rescue_organization_id>/vermittlungen/",
|
||||||
|
embeddables.list_ans_per_rescue_organization,
|
||||||
|
name="list-adoption-notices-for-rescue-organization"),
|
||||||
|
path("tierschutzorganisationen/<int:rescue_organization_id>/vermittlungen/<slug:species_slug>/",
|
||||||
|
embeddables.list_ans_per_rescue_organization,
|
||||||
|
name="list-adoption-notices-for-rescue-organization-species"),
|
||||||
|
]
|
@@ -421,6 +421,13 @@ class AdoptionNotice(models.Model):
|
|||||||
num_per_sex[sex] = self.animals.filter(sex=sex).count()
|
num_per_sex[sex] = self.animals.filter(sex=sex).count()
|
||||||
return num_per_sex
|
return num_per_sex
|
||||||
|
|
||||||
|
@property
|
||||||
|
def species(self):
|
||||||
|
species = set()
|
||||||
|
for animal in self.animals:
|
||||||
|
species.add(animal.species)
|
||||||
|
return species
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def last_checked_hr(self):
|
def last_checked_hr(self):
|
||||||
time_since_last_checked = timezone.now() - self.last_checked
|
time_since_last_checked = timezone.now() - self.last_checked
|
||||||
@@ -466,7 +473,6 @@ class AdoptionNotice(models.Model):
|
|||||||
def description_100_short(self):
|
def description_100_short(self):
|
||||||
return self._get_short_description(90)
|
return self._get_short_description(90)
|
||||||
|
|
||||||
|
|
||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
"""Returns the url to access a detailed page for the adoption notice."""
|
"""Returns the url to access a detailed page for the adoption notice."""
|
||||||
return reverse('adoption-notice-detail', args=[str(self.id)])
|
return reverse('adoption-notice-detail', args=[str(self.id)])
|
||||||
|
@@ -0,0 +1,43 @@
|
|||||||
|
{% load custom_tags %}
|
||||||
|
{% load i18n %}
|
||||||
|
{% load static %}
|
||||||
|
{% get_current_language as LANGUAGE_CODE %}
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="{{ LANGUAGE_CODE }}">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
{% block title %}{% endblock %}
|
||||||
|
{% block og_title %}{% endblock %}
|
||||||
|
{% block description %}{% endblock %}
|
||||||
|
{% block og_description %}{% endblock %}
|
||||||
|
{% block og_image %}{% endblock %}
|
||||||
|
<link rel="canonical" href="{% block canonical_url %}{% endblock %}">
|
||||||
|
|
||||||
|
<!-- Add additional CSS in static file -->
|
||||||
|
<link rel="stylesheet" href="{% static 'fellchensammlung/css/main.css' %}">
|
||||||
|
<link rel="stylesheet" href="{% static 'fellchensammlung/css/photoswipe.css' %}">
|
||||||
|
<link href="{% static 'fontawesomefree/css/fontawesome.css' %}" rel="stylesheet" type="text/css">
|
||||||
|
<link href="{% static 'fontawesomefree/css/brands.css' %}" rel="stylesheet" type="text/css">
|
||||||
|
<link href="{% static 'fontawesomefree/css/solid.css' %}" rel="stylesheet" type="text/css">
|
||||||
|
|
||||||
|
<script src="{% static 'fellchensammlung/js/custom.js' %}"></script>
|
||||||
|
<script src="{% static 'fellchensammlung/js/toggles.js' %}"></script>
|
||||||
|
<script src="{% static 'fellchensammlung/js/jquery.min.js' %}"></script>
|
||||||
|
<script type="module" src="{% static 'fellchensammlung/js/photoswipe.js' %}"></script>
|
||||||
|
{% block additional_scrips %}{% endblock %}
|
||||||
|
|
||||||
|
|
||||||
|
<link rel="apple-touch-icon" sizes="180x180" href="{% static 'fellchensammlung/favicon/apple-touch-icon.png' %}">
|
||||||
|
<link rel="icon" type="image/png" sizes="32x32" href="{% static 'fellchensammlung/favicon/favicon-32x32.png' %}">
|
||||||
|
<link rel="icon" type="image/png" sizes="16x16" href="{% static 'fellchensammlung/favicon/favicon-16x16.png' %}">
|
||||||
|
{% get_oxitraffic_script_if_enabled %}
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<div class="">
|
||||||
|
{% block content %}{% endblock %}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
@@ -0,0 +1,10 @@
|
|||||||
|
{% extends "fellchensammlung/embeddables/embedding-base.html" %}
|
||||||
|
{% load custom_tags %}
|
||||||
|
{% load i18n %}
|
||||||
|
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="block">
|
||||||
|
{% include "fellchensammlung/lists/list-adoption-notices.html" %}
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
@@ -4,6 +4,7 @@ from .forms import CustomRegistrationForm
|
|||||||
from .feeds import LatestAdoptionNoticesFeed
|
from .feeds import LatestAdoptionNoticesFeed
|
||||||
|
|
||||||
from . import views, registration_views
|
from . import views, registration_views
|
||||||
|
from fellchensammlung.aviews import embeddables
|
||||||
from drf_spectacular.views import SpectacularAPIView, SpectacularRedocView, SpectacularSwaggerView
|
from drf_spectacular.views import SpectacularAPIView, SpectacularRedocView, SpectacularSwaggerView
|
||||||
|
|
||||||
from django.contrib.sitemaps.views import sitemap
|
from django.contrib.sitemaps.views import sitemap
|
||||||
@@ -30,7 +31,8 @@ urlpatterns = [
|
|||||||
# ex: /adoption_notice/7/
|
# ex: /adoption_notice/7/
|
||||||
path("vermittlung/<int:adoption_notice_id>/", views.adoption_notice_detail, name="adoption-notice-detail"),
|
path("vermittlung/<int:adoption_notice_id>/", views.adoption_notice_detail, name="adoption-notice-detail"),
|
||||||
# ex: /adoption_notice/7/sharepic
|
# ex: /adoption_notice/7/sharepic
|
||||||
path("vermittlung/<int:adoption_notice_id>/sharepic", views.adoption_notice_sharepic, name="adoption-notice-sharepic"),
|
path("vermittlung/<int:adoption_notice_id>/sharepic", views.adoption_notice_sharepic,
|
||||||
|
name="adoption-notice-sharepic"),
|
||||||
# ex: /adoption_notice/7/edit
|
# ex: /adoption_notice/7/edit
|
||||||
path("vermittlung/<int:adoption_notice_id>/edit", views.adoption_notice_edit, name="adoption-notice-edit"),
|
path("vermittlung/<int:adoption_notice_id>/edit", views.adoption_notice_edit, name="adoption-notice-edit"),
|
||||||
# ex: /vermittlung/5/add-photo
|
# ex: /vermittlung/5/add-photo
|
||||||
@@ -129,4 +131,8 @@ urlpatterns = [
|
|||||||
###############
|
###############
|
||||||
path("sitemap.xml", sitemap, {"sitemaps": sitemaps}, name="django.contrib.sitemaps.views.sitemap"),
|
path("sitemap.xml", sitemap, {"sitemaps": sitemaps}, name="django.contrib.sitemaps.views.sitemap"),
|
||||||
|
|
||||||
|
###########
|
||||||
|
## EMBED ##
|
||||||
|
|
||||||
|
path('embed/', include('fellchensammlung.aviews.urls')),
|
||||||
]
|
]
|
||||||
|
@@ -764,8 +764,6 @@ def external_site_warning(request, template_name='fellchensammlung/external-site
|
|||||||
|
|
||||||
def list_rescue_organizations(request, species=None, template='fellchensammlung/animal-shelters.html'):
|
def list_rescue_organizations(request, species=None, template='fellchensammlung/animal-shelters.html'):
|
||||||
if species is None:
|
if species is None:
|
||||||
# rescue_organizations = RescueOrganization.objects.all()
|
|
||||||
|
|
||||||
org_search = RescueOrgSearch(request)
|
org_search = RescueOrgSearch(request)
|
||||||
rescue_organizations = org_search.get_rescue_orgs()
|
rescue_organizations = org_search.get_rescue_orgs()
|
||||||
else:
|
else:
|
||||||
|
Reference in New Issue
Block a user