aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Lemon <lemon@matthewlemon.com>2020-02-07 17:11:21 +0000
committerMatthew Lemon <lemon@matthewlemon.com>2020-02-07 17:11:21 +0000
commit93bc9d8e6386b8884863d27bef21d92eb60766d6 (patch)
tree54a5f8bbc43888568c846b8634a5f94794dcc7e1
parent60ec91d03fc6a5b9a5f650bfc3f8959473597bdd (diff)
continued to work on create CAF form - including help_text to create parent object
-rw-r--r--ctrack/caf/forms.py19
-rw-r--r--ctrack/caf/migrations/0002_auto_20200207_1622.py19
-rw-r--r--ctrack/caf/models.py2
-rw-r--r--ctrack/caf/urls.py5
-rw-r--r--ctrack/caf/views.py7
-rw-r--r--requirements/local.txt1
6 files changed, 47 insertions, 6 deletions
diff --git a/ctrack/caf/forms.py b/ctrack/caf/forms.py
index ee3bf21..34826be 100644
--- a/ctrack/caf/forms.py
+++ b/ctrack/caf/forms.py
@@ -4,23 +4,38 @@ from crispy_forms.layout import ButtonHolder
from crispy_forms.layout import Fieldset
from crispy_forms.layout import Layout
from crispy_forms.layout import Submit
+
from django import forms
+from django.urls import reverse
+
+from django.forms import ModelChoiceField
+
from ctrack.caf.models import CAF
+from ctrack.caf.models import DocumentFile
class CAFForm(forms.ModelForm):
+ file = ModelChoiceField(
+ queryset=DocumentFile.objects.all(),
+ required=False,
+ help_text="Please select an existing File. <a href='/caf/file/documentfile/create' target='_blank'>Create new File</a>" # TODO this URL does not exist
+ )
+
class Meta:
model = CAF
- fields = ["owner", "essential_system"]
+ fields = ["owner", "essential_system", "file"]
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
+ cancel_redirect = reverse('caf:caf_list') # TODO this URL doesn't exist
+
self.helper = FormHelper(self)
self.helper.form_class = "form-group"
self.helper.form_method = "post"
self.helper.layout = Layout(
- Fieldset("Create/Edit CAF", "owner", "essential_system"),
+ Fieldset("Create/Edit CAF", "owner", "essential_system", "file"),
ButtonHolder(Submit("submit", "Submit"), Button("cancel", "Cancel")),
)
+
diff --git a/ctrack/caf/migrations/0002_auto_20200207_1622.py b/ctrack/caf/migrations/0002_auto_20200207_1622.py
new file mode 100644
index 0000000..2d4575b
--- /dev/null
+++ b/ctrack/caf/migrations/0002_auto_20200207_1622.py
@@ -0,0 +1,19 @@
+# Generated by Django 2.2.9 on 2020-02-07 16:22
+
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('caf', '0001_initial'),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name='caf',
+ name='file',
+ field=models.ForeignKey(blank=True, on_delete=django.db.models.deletion.CASCADE, to='caf.DocumentFile'),
+ ),
+ ]
diff --git a/ctrack/caf/models.py b/ctrack/caf/models.py
index 53faabf..6350871 100644
--- a/ctrack/caf/models.py
+++ b/ctrack/caf/models.py
@@ -49,7 +49,7 @@ class CAF(models.Model):
owner = models.ForeignKey(Organisation, on_delete=models.CASCADE)
essential_system = models.CharField(max_length=255, blank=True)
triage_ranking = models.ForeignKey(Ranking, on_delete=models.CASCADE)
- file = models.ForeignKey(DocumentFile, on_delete=models.CASCADE)
+ file = models.ForeignKey(DocumentFile, on_delete=models.CASCADE, blank=True)
def __str__(self):
if not self.essential_system:
diff --git a/ctrack/caf/urls.py b/ctrack/caf/urls.py
index e819ef7..0f42a40 100644
--- a/ctrack/caf/urls.py
+++ b/ctrack/caf/urls.py
@@ -1,9 +1,10 @@
from django.urls import path
-from ctrack.caf.views import CreateCAF
+from ctrack.caf.views import CreateCAF, ListCAF
app_name = "caf"
urlpatterns = [
- path("", view=CreateCAF.as_view(), name="create")
+ path("", view=CreateCAF.as_view(), name="create"),
+ path("", view=ListCAF.as_view(), name="caf_list"),
]
diff --git a/ctrack/caf/views.py b/ctrack/caf/views.py
index f344aa7..d20b503 100644
--- a/ctrack/caf/views.py
+++ b/ctrack/caf/views.py
@@ -1,4 +1,4 @@
-from django.views.generic import CreateView
+from django.views.generic import CreateView, ListView
from ctrack.caf.forms import CAFForm
@@ -11,3 +11,8 @@ class CreateCAF(CreateView):
context = super().get_context_data(**kwargs)
context['form'] = self.form_class
return context
+
+
+class ListCAF(ListView):
+ pass
+
diff --git a/requirements/local.txt b/requirements/local.txt
index d196452..ca9df68 100644
--- a/requirements/local.txt
+++ b/requirements/local.txt
@@ -11,6 +11,7 @@ mypy==0.761 # https://github.com/python/mypy
django-stubs==1.4.0 # https://github.com/typeddjango/django-stubs
pytest==5.3.3 # https://github.com/pytest-dev/pytest
pytest-sugar==0.9.2 # https://github.com/Frozenball/pytest-sugar
+pdbpp==0.10.2 # a better debugger
# Code quality
# ------------------------------------------------------------------------------