mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-09-19 04:59:01 +00:00
storage: Use AppView and cleanup custom code
- Follow common code so that extending becomes easier. Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org> Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
parent
dd1884e8ab
commit
6a6983f39e
@ -1,4 +1,4 @@
|
|||||||
{% extends "base.html" %}
|
{% extends "app.html" %}
|
||||||
{% comment %}
|
{% comment %}
|
||||||
#
|
#
|
||||||
# This file is part of FreedomBox.
|
# This file is part of FreedomBox.
|
||||||
@ -30,25 +30,7 @@
|
|||||||
</style>
|
</style>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block configuration %}
|
||||||
|
|
||||||
{% block pagetitle %}
|
|
||||||
<h2>{{ title }}</h2>
|
|
||||||
{% endblock %}
|
|
||||||
|
|
||||||
{% block description %}
|
|
||||||
{% for paragraph in description %}
|
|
||||||
<p>{{ paragraph|safe }}</p>
|
|
||||||
{% endfor %}
|
|
||||||
{% endblock %}
|
|
||||||
|
|
||||||
{% if manual_page %}
|
|
||||||
<p class="manual-page">
|
|
||||||
<a href="{% url 'help:manual-page' manual_page %}">
|
|
||||||
{% trans 'Learn more...' %}
|
|
||||||
</a>
|
|
||||||
</p>
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
<p>{% trans "The following storage devices are in use:" %}</p>
|
<p>{% trans "The following storage devices are in use:" %}</p>
|
||||||
|
|
||||||
@ -121,9 +103,4 @@
|
|||||||
</p>
|
</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% block status %}
|
|
||||||
|
|
||||||
{{ block.super }}
|
|
||||||
|
|
||||||
{% endblock %}
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
@ -23,7 +23,7 @@ from django.conf.urls import url
|
|||||||
from . import views
|
from . import views
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
url(r'^sys/storage/$', views.index, name='index'),
|
url(r'^sys/storage/$', views.StorageAppView.as_view(), name='index'),
|
||||||
url(r'^sys/storage/expand$', views.expand, name='expand'),
|
url(r'^sys/storage/expand$', views.expand, name='expand'),
|
||||||
url(r'^sys/storage/eject/(?P<device_path>[A-Za-z0-9%_.\-~]+)/$',
|
url(r'^sys/storage/eject/(?P<device_path>[A-Za-z0-9%_.\-~]+)/$',
|
||||||
views.eject, name='eject')
|
views.eject, name='eject')
|
||||||
|
|||||||
@ -29,7 +29,7 @@ from django.urls import reverse
|
|||||||
from django.utils.translation import ugettext as _
|
from django.utils.translation import ugettext as _
|
||||||
from django.views.decorators.http import require_POST
|
from django.views.decorators.http import require_POST
|
||||||
|
|
||||||
from plinth import actions
|
from plinth import actions, views
|
||||||
from plinth.errors import PlinthError
|
from plinth.errors import PlinthError
|
||||||
from plinth.modules import storage
|
from plinth.modules import storage
|
||||||
from plinth.utils import format_lazy, is_user_admin
|
from plinth.utils import format_lazy, is_user_admin
|
||||||
@ -39,23 +39,32 @@ from . import get_disk_info, get_error_message
|
|||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
def index(request):
|
class StorageAppView(views.AppView):
|
||||||
"""Show connection list."""
|
"""Show storage information."""
|
||||||
disks = storage.get_disks()
|
name = storage.name
|
||||||
root_device = storage.get_root_device(disks)
|
description = storage.description
|
||||||
expandable_root_size = storage.is_expandable(root_device)
|
manual_page = storage.manual_page
|
||||||
expandable_root_size = storage.format_bytes(expandable_root_size)
|
app_id = 'storage'
|
||||||
|
template_name = 'storage.html'
|
||||||
|
show_status_block = False
|
||||||
|
|
||||||
warn_about_low_disk_space(request)
|
def render_to_response(self, context, **response_kwargs):
|
||||||
|
"""Add disk space warning to the view."""
|
||||||
|
warn_about_low_disk_space(self.request)
|
||||||
|
return super().render_to_response(context, **response_kwargs)
|
||||||
|
|
||||||
return TemplateResponse(
|
def get_context_data(self, *args, **kwargs):
|
||||||
request, 'storage.html', {
|
"""Return template context data."""
|
||||||
'title': _('Storage'),
|
context = super().get_context_data(*args, **kwargs)
|
||||||
'description': storage.description,
|
|
||||||
'disks': disks,
|
disks = storage.get_disks()
|
||||||
'manual_page': storage.manual_page,
|
root_device = storage.get_root_device(disks)
|
||||||
'expandable_root_size': expandable_root_size
|
expandable_root_size = storage.is_expandable(root_device)
|
||||||
})
|
expandable_root_size = storage.format_bytes(expandable_root_size)
|
||||||
|
|
||||||
|
context['disks'] = disks
|
||||||
|
context['expandable_root_size'] = expandable_root_size
|
||||||
|
return context
|
||||||
|
|
||||||
|
|
||||||
def expand(request):
|
def expand(request):
|
||||||
@ -83,8 +92,8 @@ def expand_partition(request, device):
|
|||||||
except Exception as exception:
|
except Exception as exception:
|
||||||
messages.error(
|
messages.error(
|
||||||
request,
|
request,
|
||||||
_('Error expanding partition: {exception}')
|
_('Error expanding partition: {exception}').format(
|
||||||
.format(exception=exception))
|
exception=exception))
|
||||||
else:
|
else:
|
||||||
messages.success(request, _('Partition expanded successfully.'))
|
messages.success(request, _('Partition expanded successfully.'))
|
||||||
|
|
||||||
@ -129,9 +138,9 @@ def eject(request, device_path):
|
|||||||
if drive:
|
if drive:
|
||||||
messages.success(
|
messages.success(
|
||||||
request,
|
request,
|
||||||
_('{drive_vendor} {drive_model} can be safely unplugged.')
|
_('{drive_vendor} {drive_model} can be safely unplugged.').
|
||||||
.format(drive_vendor=drive['vendor'],
|
format(drive_vendor=drive['vendor'],
|
||||||
drive_model=drive['model']))
|
drive_model=drive['model']))
|
||||||
else:
|
else:
|
||||||
messages.success(request, _('Device can be safely unplugged.'))
|
messages.success(request, _('Device can be safely unplugged.'))
|
||||||
except Exception as exception:
|
except Exception as exception:
|
||||||
|
|||||||
@ -34,7 +34,6 @@ from plinth import package
|
|||||||
from plinth.app import App
|
from plinth.app import App
|
||||||
from plinth.daemon import app_is_running
|
from plinth.daemon import app_is_running
|
||||||
from plinth.modules.config import get_advanced_mode
|
from plinth.modules.config import get_advanced_mode
|
||||||
from plinth.modules.storage import views as disk_views
|
|
||||||
from plinth.translation import get_language_from_request, set_language
|
from plinth.translation import get_language_from_request, set_language
|
||||||
|
|
||||||
from . import forms, frontpage
|
from . import forms, frontpage
|
||||||
@ -54,6 +53,7 @@ def index(request):
|
|||||||
]
|
]
|
||||||
selected_shortcut = selected_shortcut[0] if selected_shortcut else None
|
selected_shortcut = selected_shortcut[0] if selected_shortcut else None
|
||||||
|
|
||||||
|
from plinth.modules.storage import views as disk_views
|
||||||
disk_views.warn_about_low_disk_space(request)
|
disk_views.warn_about_low_disk_space(request)
|
||||||
|
|
||||||
return TemplateResponse(
|
return TemplateResponse(
|
||||||
@ -77,6 +77,7 @@ class AppsIndexView(TemplateView):
|
|||||||
|
|
||||||
def system_index(request):
|
def system_index(request):
|
||||||
"""Serve the system index page."""
|
"""Serve the system index page."""
|
||||||
|
from plinth.modules.storage import views as disk_views
|
||||||
disk_views.warn_about_low_disk_space(request)
|
disk_views.warn_about_low_disk_space(request)
|
||||||
return TemplateResponse(request, 'system.html',
|
return TemplateResponse(request, 'system.html',
|
||||||
{'advanced_mode': get_advanced_mode()})
|
{'advanced_mode': get_advanced_mode()})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user