Create repo form

This commit is contained in:
George Lacey 2021-05-07 16:37:57 +01:00
parent 373434c3ef
commit cb2c342449
4 changed files with 45 additions and 1 deletions

7
borgweb/borg/forms.py Normal file
View File

@ -0,0 +1,7 @@
from django import forms
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"])

View File

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

View File

@ -4,4 +4,5 @@ from . import views
urlpatterns = [
path('', views.index, name='index'),
]
path('repo', views.get_repo, name='repo')
]

View File

@ -1,6 +1,9 @@
from django.shortcuts import render
from django.http import HttpResponse, HttpResponseRedirect
from .models import Repo
from .forms import RepoForm
from django.urls import reverse
def index(request):
@ -12,3 +15,22 @@ def index(request):
'hour_list': hour_list
}
return render(request, 'borg/index.html', context)
def get_repo(request):
if request.method == 'POST':
# create a form instance and populate it with data from the request:
form = RepoForm(request.POST)
# check whether it's valid:
if form.is_valid():
print(form.cleaned_data)
# process the data in form.cleaned_data as required
# ...
# redirect to a new URL:
return HttpResponseRedirect(reverse('index'))
# if a GET (or any other method) we'll create a blank form
else:
form = RepoForm()
return render(request, 'borg/repo.html', {'form': form})