Skip to content

Commit

Permalink
apps/budgeting: add back link to context only if from module or proje…
Browse files Browse the repository at this point in the history
…ct detail view
  • Loading branch information
fuzzylogic2000 authored and Rineee committed Dec 19, 2022
1 parent 08e9a4b commit 5502c3e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
17 changes: 16 additions & 1 deletion meinberlin/apps/budgeting/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
from urllib.parse import urlparse

import django_filters
from django.urls import resolve
from django.urls import reverse
from django.utils.translation import gettext_lazy as _

Expand Down Expand Up @@ -102,8 +105,20 @@ class ProposalDetailView(idea_views.AbstractIdeaDetailView):
permission_required = 'meinberlin_budgeting.view_proposal'

def get_back(self):
"""
Get last page to return to if was project or module view.
To make sure all the filters and the display mode (map or list)
are remembered when going back, we check if the referer is a
module or project detail view and add the appropriate back url.
"""
if 'Referer' in self.request.headers:
return self.request.headers['Referer']
referer = self.request.headers['Referer']
match = resolve(urlparse(referer)[2])
if match.url_name == 'project-detail' or \
match.url_name == 'module-detail':
return referer
return None
return None

def get_context_data(self, **kwargs):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<a href="{{ module.get_detail_url }}">
{% endif %}
<i class="fa fa-arrow-left" aria-hidden="true"></i>
{% translate 'go back' %}
{% translate 'list' %}
</a>
</li>
</ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
{% block content %}
<div class="container">
<div class="offset-lg-3 col-lg-6">
<nav class="breadcrumbs" aria-label="{% trans 'breadcrumbs' %}">
<nav class="breadcrumbs" aria-label="{% translate 'breadcrumbs' %}">
<ul>
<li>
<a href="{{ module.get_detail_url }}">
<i class="fa fa-arrow-left" aria-hidden="true"></i>
{% trans 'go back' %}
{% translate 'list' %}
</a>
</li>
</ul>
Expand All @@ -47,7 +47,7 @@ <h1 class="item-detail__title">{{ object.name }}</h1>

<div class="item-detail__meta lr-bar">
<div class="lr-bar__right">
<strong>{% trans 'Reference No.' %}:</strong>
<strong>{% translate 'Reference No.' %}:</strong>
{{ object.reference_number }}
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
{% block content %}
<div class="container">
<div class="offset-lg-3 col-lg-6">
<nav class="breadcrumbs" aria-label="{% trans 'breadcrumbs' %}">
<nav class="breadcrumbs" aria-label="{% translate 'breadcrumbs' %}">
<ul>
<li>
<a href="{{ module.get_detail_url }}">
<i class="fa fa-arrow-left" aria-hidden="true"></i>
{% trans 'go back' %}
{% translate 'list' %}
</a>
</li>
</ul>
Expand All @@ -31,7 +31,7 @@ <h1 class="item-detail__title">{{ object.name }}</h1>

<div class="item-detail__meta lr-bar">
<div class="lr-bar__right">
<strong>{% trans 'Reference No.' %}:</strong>
<strong>{% translate 'Reference No.' %}:</strong>
{{ object.reference_number }}
</div>
</div>
Expand Down

0 comments on commit 5502c3e

Please sign in to comment.