pricing: add a link to go on agenda's chrono settings view (#65985)

This commit is contained in:
Lauréline Guérin 2022-06-03 16:51:06 +02:00
parent 668c358e9a
commit 9c4ca12b57
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
4 changed files with 29 additions and 0 deletions

View File

@ -16,6 +16,7 @@
import copy
from django.conf import settings
from django.db import models
from django.utils.text import slugify
from django.utils.translation import ugettext_lazy as _
@ -85,6 +86,13 @@ class Agenda(models.Model):
return False, agenda
def get_chrono_url(self):
if not settings.KNOWN_SERVICES.get('chrono'):
return
chrono = list(settings.KNOWN_SERVICES['chrono'].values())[0]
chrono_url = chrono.get('url') or ''
return '%smanage/agendas/%s/settings/' % (chrono_url, self.slug)
class CheckTypeGroup(models.Model):
slug = models.SlugField(_('Identifier'), max_length=160, unique=True)

View File

@ -11,6 +11,7 @@
<span class="identifier">[{% trans "identifier:" %} {{ agenda.slug }}]</span>
</h2>
<span class="actions">
{% with chrono_url=object.get_chrono_url %}{% if chrono_url %}<a href="{{ chrono_url }}">{% trans "Agenda options" %}</a>{% endif %}{% endwith %}
<a href="{% url 'lingo-manager-agenda-export' pk=agenda.pk %}">{% trans 'Export' %}</a>
<a rel="popup" href="{% url 'lingo-manager-agenda-pricing-add' pk=agenda.pk %}">{% trans 'New pricing' %}</a>
</span>

View File

@ -24,6 +24,7 @@
{% for object in group.list %}
<li>
<a href="{% url 'lingo-manager-agenda-detail' object.pk %}">{{ object.label }} <span class="identifier">[{% trans "identifier:" %} {{ object.slug }}]</a>
{% with chrono_url=object.get_chrono_url %}{% if chrono_url %}<a href="{{ chrono_url }}" class="link-action-icon link">{% trans "voir" %}</a>{% endif %}{% endwith %}
</li>
{% endfor %}
</ul>

View File

@ -22,6 +22,25 @@ def test_refresh_agendas(mock_refresh, app, admin_user):
assert mock_refresh.call_args_list == [mock.call()]
def test_agenda_chrono_link(settings, app, admin_user):
settings.KNOWN_SERVICES = {}
agenda = Agenda.objects.create(label='Foo bar')
app = login(app)
resp = app.get('/manage/pricing/agendas/')
assert '/manage/agendas/%s/settings/' % agenda.slug not in resp
resp = app.get('/manage/pricing/agenda/%s/' % agenda.pk)
assert 'Agenda options' not in resp
assert '/manage/agendas/%s/settings/' % agenda.slug not in resp
settings.KNOWN_SERVICES['chrono'] = {'default': {'url': 'https://chrono.dev/'}}
resp = app.get('/manage/pricing/agendas/')
assert 'https://chrono.dev/manage/agendas/%s/settings/' % agenda.slug in resp
resp = app.get('/manage/pricing/agenda/%s/' % agenda.pk)
assert 'Agenda options' in resp
assert 'https://chrono.dev/manage/agendas/%s/settings/' % agenda.slug in resp
def test_add_agenda_pricing(app, admin_user):
agenda = Agenda.objects.create(label='Foo Bar')
pricing = Pricing.objects.create(label='Model')