feat: Get all adoption notices in hierarchy
This commit is contained in:
		@@ -7,19 +7,26 @@ from fellchensammlung.models import RescueOrganization, AdoptionNotice, Species
 | 
			
		||||
 | 
			
		||||
@xframe_options_exempt
 | 
			
		||||
@headers({"X-Robots-Tag": "noindex"})
 | 
			
		||||
def list_ans_per_rescue_organization(request, rescue_organization_id, species_slug=None):
 | 
			
		||||
def list_ans_per_rescue_organization(request, rescue_organization_id, species_slug=None, active=True):
 | 
			
		||||
    expand = request.GET.get("expand")
 | 
			
		||||
    if expand is not None:
 | 
			
		||||
        expand = True
 | 
			
		||||
    else:
 | 
			
		||||
        expand = False
 | 
			
		||||
    org = get_object_or_404(RescueOrganization, pk=rescue_organization_id)
 | 
			
		||||
    if species_slug is None:
 | 
			
		||||
        adoption_notices = AdoptionNotice.objects.filter(organization=org)
 | 
			
		||||
 | 
			
		||||
    # Get only active adoption notices or all
 | 
			
		||||
    if active:
 | 
			
		||||
        adoption_notices_of_org = org.adoption_notices_in_hierarchy_divided_by_status[0]
 | 
			
		||||
    else:
 | 
			
		||||
        adoption_notices_of_org = org.adoption_notices
 | 
			
		||||
 | 
			
		||||
    # Filter for Species if necessary
 | 
			
		||||
    if species_slug is None:
 | 
			
		||||
        adoption_notices = adoption_notices_of_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]
 | 
			
		||||
        adoption_notices = [adoption_notice for adoption_notice in adoption_notices_of_org if species in adoption_notice.species]
 | 
			
		||||
 | 
			
		||||
    template = 'fellchensammlung/embeddables/list-adoption-notices.html'
 | 
			
		||||
    return render(request, template, context={"adoption_notices": adoption_notices, "expand": expand})
 | 
			
		||||
		Reference in New Issue
	
	Block a user