mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-06-03 10:50:20 +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 %}
|
||||
#
|
||||
# This file is part of FreedomBox.
|
||||
@ -30,25 +30,7 @@
|
||||
</style>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
{% 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 %}
|
||||
{% block configuration %}
|
||||
|
||||
<p>{% trans "The following storage devices are in use:" %}</p>
|
||||
|
||||
@ -121,9 +103,4 @@
|
||||
</p>
|
||||
{% endif %}
|
||||
|
||||
{% block status %}
|
||||
|
||||
{{ block.super }}
|
||||
|
||||
{% endblock %}
|
||||
{% endblock %}
|
||||
|
||||
@ -23,7 +23,7 @@ from django.conf.urls import url
|
||||
from . import views
|
||||
|
||||
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/eject/(?P<device_path>[A-Za-z0-9%_.\-~]+)/$',
|
||||
views.eject, name='eject')
|
||||
|
||||
@ -29,7 +29,7 @@ from django.urls import reverse
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.views.decorators.http import require_POST
|
||||
|
||||
from plinth import actions
|
||||
from plinth import actions, views
|
||||
from plinth.errors import PlinthError
|
||||
from plinth.modules import storage
|
||||
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__)
|
||||
|
||||
|
||||
def index(request):
|
||||
"""Show connection list."""
|
||||
disks = storage.get_disks()
|
||||
root_device = storage.get_root_device(disks)
|
||||
expandable_root_size = storage.is_expandable(root_device)
|
||||
expandable_root_size = storage.format_bytes(expandable_root_size)
|
||||
class StorageAppView(views.AppView):
|
||||
"""Show storage information."""
|
||||
name = storage.name
|
||||
description = storage.description
|
||||
manual_page = storage.manual_page
|
||||
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(
|
||||
request, 'storage.html', {
|
||||
'title': _('Storage'),
|
||||
'description': storage.description,
|
||||
'disks': disks,
|
||||
'manual_page': storage.manual_page,
|
||||
'expandable_root_size': expandable_root_size
|
||||
})
|
||||
def get_context_data(self, *args, **kwargs):
|
||||
"""Return template context data."""
|
||||
context = super().get_context_data(*args, **kwargs)
|
||||
|
||||
disks = storage.get_disks()
|
||||
root_device = storage.get_root_device(disks)
|
||||
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):
|
||||
@ -83,8 +92,8 @@ def expand_partition(request, device):
|
||||
except Exception as exception:
|
||||
messages.error(
|
||||
request,
|
||||
_('Error expanding partition: {exception}')
|
||||
.format(exception=exception))
|
||||
_('Error expanding partition: {exception}').format(
|
||||
exception=exception))
|
||||
else:
|
||||
messages.success(request, _('Partition expanded successfully.'))
|
||||
|
||||
@ -129,9 +138,9 @@ def eject(request, device_path):
|
||||
if drive:
|
||||
messages.success(
|
||||
request,
|
||||
_('{drive_vendor} {drive_model} can be safely unplugged.')
|
||||
.format(drive_vendor=drive['vendor'],
|
||||
drive_model=drive['model']))
|
||||
_('{drive_vendor} {drive_model} can be safely unplugged.').
|
||||
format(drive_vendor=drive['vendor'],
|
||||
drive_model=drive['model']))
|
||||
else:
|
||||
messages.success(request, _('Device can be safely unplugged.'))
|
||||
except Exception as exception:
|
||||
|
||||
@ -34,7 +34,6 @@ from plinth import package
|
||||
from plinth.app import App
|
||||
from plinth.daemon import app_is_running
|
||||
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 . import forms, frontpage
|
||||
@ -54,6 +53,7 @@ def index(request):
|
||||
]
|
||||
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)
|
||||
|
||||
return TemplateResponse(
|
||||
@ -77,6 +77,7 @@ class AppsIndexView(TemplateView):
|
||||
|
||||
def system_index(request):
|
||||
"""Serve the system index page."""
|
||||
from plinth.modules.storage import views as disk_views
|
||||
disk_views.warn_about_low_disk_space(request)
|
||||
return TemplateResponse(request, 'system.html',
|
||||
{'advanced_mode': get_advanced_mode()})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user