From fba957a6bc21e2b3ec87330cc713fbb78fc044f0 Mon Sep 17 00:00:00 2001 From: George Lacey Date: Wed, 28 Sep 2022 16:56:44 +0100 Subject: [PATCH] Allow for toggling of repo visibility --- borgweb/borg/forms/__init__.py | 2 +- borgweb/borg/forms/repoform.py | 4 ++++ borgweb/borg/templates/borg/post/toggle.html | 14 ++++++++++++ borgweb/borg/urls.py | 1 + borgweb/borg/views/post.py | 23 +++++++++++++++++++- borgweb/borg/views/views.py | 2 +- 6 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 borgweb/borg/templates/borg/post/toggle.html diff --git a/borgweb/borg/forms/__init__.py b/borgweb/borg/forms/__init__.py index b5ecdb2..1d1bc58 100644 --- a/borgweb/borg/forms/__init__.py +++ b/borgweb/borg/forms/__init__.py @@ -1,4 +1,4 @@ -from .repoform import RepoForm +from .repoform import RepoForm, ToggleVisibility from .archiveform import ArchiveForm from .errorform import ErrorForm from .locationform import LocationForm diff --git a/borgweb/borg/forms/repoform.py b/borgweb/borg/forms/repoform.py index 445dcbf..c13097b 100644 --- a/borgweb/borg/forms/repoform.py +++ b/borgweb/borg/forms/repoform.py @@ -6,3 +6,7 @@ class RepoForm(forms.Form): fingerprint = forms.CharField(label='Fingerprint') location = forms.CharField(label='Location') last_modified = forms.DateTimeField(label='Last Modified', input_formats=["%Y-%m-%dT%H:%M:%S.%z"]) + + +class ToggleVisibility(forms.Form): + label = forms.CharField(label='Label') diff --git a/borgweb/borg/templates/borg/post/toggle.html b/borgweb/borg/templates/borg/post/toggle.html new file mode 100644 index 0000000..fdb1319 --- /dev/null +++ b/borgweb/borg/templates/borg/post/toggle.html @@ -0,0 +1,14 @@ + + + + + Toggle repo visibility + + +
+ {% csrf_token %} + {{ form }} + +
+ + \ No newline at end of file diff --git a/borgweb/borg/urls.py b/borgweb/borg/urls.py index 1e299d5..43d885b 100644 --- a/borgweb/borg/urls.py +++ b/borgweb/borg/urls.py @@ -24,6 +24,7 @@ urlpatterns = [ # POST path('post/repo', views.post_repo, name='post repo'), + path('post/toggle', views.toggle_visibility, name='toggle repo visibility'), path('post/archive', views.post_archive, name='post archive'), path('post/error', views.post_error, name='post error'), path('post/location', views.post_location, name='post location'), diff --git a/borgweb/borg/views/post.py b/borgweb/borg/views/post.py index 9d473f4..54ac75f 100644 --- a/borgweb/borg/views/post.py +++ b/borgweb/borg/views/post.py @@ -5,7 +5,28 @@ from django.urls import reverse from django.contrib.auth.decorators import permission_required from django.core.cache import cache from ..models import Repo, Label, Archive, Cache, Error, Location -from ..forms import RepoForm, ArchiveForm, ErrorForm, LocationForm +from ..forms import RepoForm, ArchiveForm, ErrorForm, LocationForm, ToggleVisibility + + +@permission_required("borg.change_repo") +def toggle_visibility(request): + if request.method == 'POST': + form = ToggleVisibility(request.POST) + if form.is_valid(): + cdata = form.cleaned_data + + label = get_object_or_404(Label, label=cdata['label']) + + label.visible = not label.visible + + label.save() + cache.clear() + + return HttpResponseRedirect(reverse('index')) + else: + form = ToggleVisibility() + + return render(request, 'borg/post/toggle.html', {'form': form}) @permission_required("borg.add_repo") diff --git a/borgweb/borg/views/views.py b/borgweb/borg/views/views.py index 6a63843..291f7b1 100644 --- a/borgweb/borg/views/views.py +++ b/borgweb/borg/views/views.py @@ -4,7 +4,7 @@ from ..models import Repo def index(request): - repo_list = Repo.objects.all() + repo_list = Repo.objects.filter(label__visible=True) context = { 'repo_list': repo_list,