Allow for toggling of repo visibility
This commit is contained in:
parent
c506d9fcfa
commit
fba957a6bc
|
@ -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
|
||||
|
|
|
@ -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')
|
||||
|
|
14
borgweb/borg/templates/borg/post/toggle.html
Normal file
14
borgweb/borg/templates/borg/post/toggle.html
Normal 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>
|
|
@ -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'),
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue
Block a user