Skip to content

Commit

Permalink
Add plugin name to html title (#244)
Browse files Browse the repository at this point in the history
  • Loading branch information
dimasciput authored Mar 25, 2022
1 parent aed3fd8 commit f851253
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 3 deletions.
7 changes: 5 additions & 2 deletions qgis-app/plugins/templates/plugins/plugin_base.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{% extends BASE_TEMPLATE %}{% load i18n plugins_tagcloud static %}
{% load resources_custom_tags %}
{% block extratitle %}{% trans "Python Plugins Repository"%}{% endblock %}
{% load resources_custom_tags plugin_utils %}
{% block title %}
{% plugin_title %} — {% trans "QGIS Python Plugins Repository"%}
{% endblock %}

{% block app_title %}
<h2>{% trans "QGIS Python Plugins Repository"%}</h2>
{% endblock %}
Expand Down
14 changes: 14 additions & 0 deletions qgis-app/plugins/templatetags/plugin_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,17 @@
@register.filter('klass')
def klass(ob):
return ob.__class__.__name__


@register.simple_tag(takes_context=True)
def plugin_title(context):
"""Returns plugin name for title"""
title = ''
if 'plugin' in context:
title = context['plugin'].name
if 'version' in context:
title = '{plugin} {version}'.format(
plugin=context['version'].plugin.name,
version=context['version'].version
)
return title
61 changes: 61 additions & 0 deletions qgis-app/plugins/tests/test_simple_tag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
from django.contrib.auth.models import User
from django.test import TestCase
from django.urls import reverse

from plugins.models import Plugin, PluginVersion


class TestPluginSimpleTag(TestCase):
fixtures = ['fixtures/simplemenu.json']

def setUp(self) -> None:
self.creator = User.objects.create(
username="creator", email="[email protected]"
)
# set creator password to password
self.creator.set_password("password")
self.creator.save()
self.plugin_name = 'plugin_name_test'
self.plugin = Plugin.objects.create(
created_by=self.creator,
name=self.plugin_name,
package_name=self.plugin_name
)
self.version = PluginVersion.objects.create(
plugin=self.plugin,
created_by=self.creator,
version='1.1.0',
min_qg_version='0.0.1',
max_qg_version='2.2.0'
)

def tearDown(self) -> None:
self.plugin.delete()
self.creator.delete()
self.version.delete()

def test_return_plugin_name(self):
url = reverse("plugin_detail", kwargs={
'package_name': self.plugin.package_name})
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
self.assertTrue(
bytes('{} — QGIS Python Plugins Repository'.format(
self.plugin.name), 'utf-8') in
response.content
)

def test_return_plugin_name_in_version_view(self):
url = reverse("version_detail", kwargs={
'package_name': self.plugin.package_name,
'version': self.version.version
})
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
self.assertTrue(
bytes('{plugin} {version} — QGIS Python Plugins Repository'.format(
plugin=self.plugin.name,
version=self.version.version
), 'utf-8') in
response.content
)
2 changes: 1 addition & 1 deletion qgis-app/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>QGIS {% block extratitle %}Plugins{% endblock %}</title>
<title>{% block title %}QGIS {% block extratitle %}Plugins{% endblock %}{% endblock %}</title>
<meta name="AUTHOR" content="QGIS Web Team" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
Expand Down

0 comments on commit f851253

Please sign in to comment.