i2p: django: Add shortcuts to /i2p/... URLs

This should help the user reach pages of the configuration more quickly

freedombox-team/plinth#1428 Request: I2P support

Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
LoveIsGrief 2019-03-02 00:45:23 +01:00 committed by Sunil Mohan Adapa
parent f2936f0eed
commit 5e5e0119d2
No known key found for this signature in database
GPG Key ID: 43EA1CFF0AA7C5F2
3 changed files with 97 additions and 9 deletions

View File

@ -0,0 +1,13 @@
{% extends "base.html" %}
{% block page_head %}
<style>
#i2p-frame {
width: 100%;
height: 100%;
min-height: 500px;
}
</style>
{% endblock %}
{% block content %}
<iframe id="i2p-frame" src="{{ path }}" frameborder="0"></iframe>
{% endblock %}

View File

@ -20,15 +20,15 @@ URLs for the I2P module.
from django.conf.urls import url
from plinth.modules import i2p
from plinth.views import ServiceView
from plinth.modules.i2p import views
urlpatterns = [
url(r'^apps/i2p/$',
ServiceView.as_view(
service_id=i2p.managed_services[0],
diagnostics_module_name='i2p',
description=i2p.description, clients=i2p.clients,
manual_page=i2p.manual_page, show_status_block=True),
name='index'),
url(r'^apps/i2p/$', views.I2PServiceView.as_view(), name='index'),
url(r'^apps/i2p/frame/tunnels/?$', views.create_i2p_frame_view(
"I2P Proxies and Tunnels", "i2ptunnel"
), name='frame_tunnels'),
url(r'^apps/i2p/frame/torrent/?$', views.create_i2p_frame_view(
"Anonymous torrents", "i2psnark"
), name='frame_torrent'),
]

View File

@ -0,0 +1,75 @@
#
# This file is part of FreedomBox.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from django.template.response import TemplateResponse
from django.urls import reverse_lazy
from django.utils.translation import ugettext as _
from django.utils.translation import ugettext_lazy
import plinth.modules.i2p as i2p
from plinth.views import ServiceView
subsubmenu = [{
'url': reverse_lazy('i2p:index'),
'text': ugettext_lazy('Configure')
}, {
'url': reverse_lazy('i2p:frame_tunnels'),
'text': ugettext_lazy('Proxies')
}, {
'url': reverse_lazy('i2p:frame_torrent'),
'text': ugettext_lazy('Anonymous torrents')
}]
class I2PServiceView(ServiceView):
"""Serve configuration page."""
service_id = i2p.servicename
description = i2p.description
diagnostics_module_name = i2p.servicename
show_status_block = False
def get_context_data(self, **kwargs):
"""Return the context data for rendering the template view."""
context = super().get_context_data(**kwargs)
context['subsubmenu'] = subsubmenu
context['clients'] = i2p.clients
return context
def create_i2p_frame_view(title, rel_path):
"""
Creates a view with an iframe to the given path
This is primarily used as a shortcut to pages under /i2p/
:param title: the page title that will have to be i18n
:type title: basestring
:param rel_path: the URL path after /i2p/<rel_path>
:type rel_path: basestring
:return: a django view
:rtype: callable
"""
path = "/i2p/" + rel_path
def i2p_frame_view(request):
return TemplateResponse(
request, 'i2p_frame.html', {
'title': _(title),
'subsubmenu': subsubmenu,
'path': path
})
return i2p_frame_view