Create location form
This commit is contained in:
parent
eca02882da
commit
1dd2c0726f
|
@ -1,3 +1,4 @@
|
|||
from .repoform import RepoForm
|
||||
from .archiveform import ArchiveForm
|
||||
from .errorform import ErrorForm
|
||||
from .locationform import LocationForm
|
||||
|
|
6
borgweb/borg/forms/locationform.py
Normal file
6
borgweb/borg/forms/locationform.py
Normal file
|
@ -0,0 +1,6 @@
|
|||
from django import forms
|
||||
|
||||
|
||||
class LocationForm(forms.Form):
|
||||
label = forms.CharField(label='Label')
|
||||
path = forms.CharField(label='Path')
|
|
@ -3,3 +3,4 @@ from .repo import Repo
|
|||
from .cache import Cache
|
||||
from .archive import Archive
|
||||
from .error import Error
|
||||
from .location import Location
|
||||
|
|
|
@ -24,7 +24,7 @@ DESCRIPTION = {
|
|||
class Location(models.Model):
|
||||
label = models.TextField(unique=True)
|
||||
path = models.TextField()
|
||||
last_checked = models.DateTimeField()
|
||||
last_checked = models.DateTimeField(null=True)
|
||||
|
||||
def __path_type(self):
|
||||
try:
|
||||
|
@ -65,3 +65,11 @@ class Location(models.Model):
|
|||
|
||||
def have_permission(self):
|
||||
return self.__path_type() != ACCESS_DENIED
|
||||
|
||||
def short_description(self):
|
||||
type = self.__path_type()
|
||||
type_description = self.type_description()
|
||||
existence = "exists" if self.exists() else "does not exist"
|
||||
|
||||
if self.exists():
|
||||
return f"{type_description} {self.path} {existence}"
|
||||
|
|
14
borgweb/borg/templates/borg/post/location.html
Normal file
14
borgweb/borg/templates/borg/post/location.html
Normal file
|
@ -0,0 +1,14 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Add Location</title>
|
||||
</head>
|
||||
<body>
|
||||
<form action="location" method="post">
|
||||
{% csrf_token %}
|
||||
{{ form }}
|
||||
<input type="submit" value="Submit">
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
|
@ -4,7 +4,8 @@ from . import views
|
|||
|
||||
urlpatterns = [
|
||||
path('', views.index, name='index'),
|
||||
path('post/repo', views.get_repo, name='repo'),
|
||||
path('post/archive', views.get_archive, name='archive'),
|
||||
path('post/error', views.get_error, name='error'),
|
||||
path('post/repo', views.post_repo, name='repo'),
|
||||
path('post/archive', views.post_archive, name='archive'),
|
||||
path('post/error', views.post_error, name='error'),
|
||||
path('post/location', views.post_location, name='location'),
|
||||
]
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
from django.shortcuts import render, get_object_or_404
|
||||
from django.http import HttpResponseRedirect
|
||||
|
||||
from .models import Repo, Label, Archive, Cache, Error
|
||||
from django.urls import reverse
|
||||
from .forms import RepoForm, ArchiveForm, ErrorForm
|
||||
from .models import Repo, Label, Archive, Cache, Error, Location
|
||||
from .forms import RepoForm, ArchiveForm, ErrorForm, LocationForm
|
||||
from django.contrib.auth.decorators import permission_required
|
||||
from .utility import data
|
||||
from datetime import datetime, timedelta
|
||||
|
@ -36,7 +36,7 @@ def repo_daily_dict(repo_list, n_days=14):
|
|||
|
||||
|
||||
@permission_required("borg.add_repo")
|
||||
def get_repo(request):
|
||||
def post_repo(request):
|
||||
if request.method == 'POST':
|
||||
form = RepoForm(request.POST)
|
||||
if form.is_valid():
|
||||
|
@ -64,7 +64,7 @@ def get_repo(request):
|
|||
|
||||
|
||||
@permission_required("borg.add_archive")
|
||||
def get_archive(request):
|
||||
def post_archive(request):
|
||||
if request.method == 'POST':
|
||||
form = ArchiveForm(request.POST)
|
||||
if form.is_valid():
|
||||
|
@ -92,7 +92,7 @@ def get_archive(request):
|
|||
|
||||
|
||||
@permission_required("borg.add_error")
|
||||
def get_error(request):
|
||||
def post_error(request):
|
||||
if request.method == 'POST':
|
||||
form = ErrorForm(request.POST)
|
||||
if form.is_valid():
|
||||
|
@ -107,3 +107,20 @@ def get_error(request):
|
|||
form = ErrorForm()
|
||||
|
||||
return render(request, 'borg/post/error.html', {'form': form})
|
||||
|
||||
|
||||
@permission_required("borg.add_location")
|
||||
def post_location(request):
|
||||
if request.method == 'POST':
|
||||
form = LocationForm(request.POST)
|
||||
if form.is_valid():
|
||||
cdata = form.cleaned_data
|
||||
label, _ = Location.objects.get_or_create(label=cdata['label'],
|
||||
defaults={"path": cdata["path"]})
|
||||
label.save()
|
||||
|
||||
return HttpResponseRedirect(reverse('index'))
|
||||
else:
|
||||
form = LocationForm ()
|
||||
|
||||
return render(request, 'borg/post/location.html', {'form': form})
|
||||
|
|
Loading…
Reference in New Issue
Block a user