Allow for toggling of repo visibility

This commit is contained in:
George Lacey 2022-09-28 16:56:44 +01:00
parent c506d9fcfa
commit fba957a6bc
6 changed files with 43 additions and 3 deletions

View File

@ -1,4 +1,4 @@
from .repoform import RepoForm from .repoform import RepoForm, ToggleVisibility
from .archiveform import ArchiveForm from .archiveform import ArchiveForm
from .errorform import ErrorForm from .errorform import ErrorForm
from .locationform import LocationForm from .locationform import LocationForm

View File

@ -6,3 +6,7 @@ class RepoForm(forms.Form):
fingerprint = forms.CharField(label='Fingerprint') fingerprint = forms.CharField(label='Fingerprint')
location = forms.CharField(label='Location') location = forms.CharField(label='Location')
last_modified = forms.DateTimeField(label='Last Modified', input_formats=["%Y-%m-%dT%H:%M:%S.%z"]) 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')

View File

@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Toggle repo visibility</title>
</head>
<body>
<form action="toggle" method="post">
{% csrf_token %}
{{ form }}
<input type="submit" value="Submit">
</form>
</body>
</html>

View File

@ -24,6 +24,7 @@ urlpatterns = [
# POST # POST
path('post/repo', views.post_repo, name='post repo'), 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/archive', views.post_archive, name='post archive'),
path('post/error', views.post_error, name='post error'), path('post/error', views.post_error, name='post error'),
path('post/location', views.post_location, name='post location'), path('post/location', views.post_location, name='post location'),

View File

@ -5,7 +5,28 @@ from django.urls import reverse
from django.contrib.auth.decorators import permission_required from django.contrib.auth.decorators import permission_required
from django.core.cache import cache from django.core.cache import cache
from ..models import Repo, Label, Archive, Cache, Error, Location 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") @permission_required("borg.add_repo")

View File

@ -4,7 +4,7 @@ from ..models import Repo
def index(request): def index(request):
repo_list = Repo.objects.all() repo_list = Repo.objects.filter(label__visible=True)
context = { context = {
'repo_list': repo_list, 'repo_list': repo_list,