aboutsummaryrefslogtreecommitdiffstats
path: root/ctrack/register
diff options
context:
space:
mode:
authorMatthew Lemon <lemon@matthewlemon.com>2020-10-13 16:41:31 +0100
committerMatthew Lemon <lemon@matthewlemon.com>2020-10-13 16:41:31 +0100
commitf1bcac0499c5e6202b3ddd0661052d14b5b53f87 (patch)
tree674a0ba62d3534c6a646fbc2decd39b015035da1 /ctrack/register
parentaa343e46247b6a55bd0d26dad1d0b9dabaf04851 (diff)
created a form for new Simple Event
Diffstat (limited to 'ctrack/register')
-rw-r--r--ctrack/register/forms.py10
-rw-r--r--ctrack/register/migrations/0007_auto_20201013_1250.py84
-rw-r--r--ctrack/register/models.py2
-rw-r--r--ctrack/register/templates/single_datetime_event_create.html27
-rw-r--r--ctrack/register/tests/test_views.py11
-rw-r--r--ctrack/register/urls.py4
-rw-r--r--ctrack/register/views.py8
7 files changed, 130 insertions, 16 deletions
diff --git a/ctrack/register/forms.py b/ctrack/register/forms.py
index 1c69bcd..d3e93ab 100644
--- a/ctrack/register/forms.py
+++ b/ctrack/register/forms.py
@@ -66,9 +66,15 @@ class CAFTwinDateEventForm(forms.ModelForm):
def clean_start_date(self):
data = self.cleaned_data["start_date"]
caf = self.cleaned_data["related_caf"]
- existing_obj = CAFTwinDateEvent.objects.filter(start_date=data).filter(related_caf=caf).first()
+ existing_obj = (
+ CAFTwinDateEvent.objects.filter(start_date=data)
+ .filter(related_caf=caf)
+ .first()
+ )
if existing_obj:
- raise ValidationError("You cannot have two CAF events starting on the same date.")
+ raise ValidationError(
+ "You cannot have two CAF events starting on the same date."
+ )
return data
class Meta:
diff --git a/ctrack/register/migrations/0007_auto_20201013_1250.py b/ctrack/register/migrations/0007_auto_20201013_1250.py
new file mode 100644
index 0000000..9dc4cfb
--- /dev/null
+++ b/ctrack/register/migrations/0007_auto_20201013_1250.py
@@ -0,0 +1,84 @@
+# Generated by Django 3.1.2 on 2020-10-13 12:50
+
+from django.conf import settings
+from django.db import migrations, models
+import django.db.models.deletion
+import django.db.models.expressions
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('caf', '0002_caf_systems'),
+ ('organisations', '0001_initial'),
+ migrations.swappable_dependency(settings.AUTH_USER_MODEL),
+ ('register', '0006_engagementtype_single_date_type'),
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name='CAFMixin',
+ fields=[
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('related_caf', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='caf.caf')),
+ ],
+ ),
+ migrations.CreateModel(
+ name='SingleDateTimeEvent',
+ fields=[
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('created_date', models.DateTimeField()),
+ ('modified_date', models.DateTimeField()),
+ ('short_description', models.CharField(help_text='Short description of the event. Use Comments field for full detail.', max_length=50)),
+ ('document_link', models.URLField(blank=True, help_text='URL only - do not try to drag a file here.', max_length=1000, null=True)),
+ ('comments', models.TextField(blank=True, help_text='Use this to provide further detail about the event.', max_length=1000, null=True)),
+ ('location', models.CharField(blank=True, max_length=100)),
+ ('datetime', models.DateTimeField()),
+ ('type_descriptor', models.CharField(choices=[('MEETING', 'Meeting'), ('PHONE_CALL', 'Phone Call'), ('VIDEO_CALL', 'Video Call')], max_length=50)),
+ ('participants', models.ManyToManyField(blank=True, null=True, to='organisations.Person')),
+ ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
+ ],
+ options={
+ 'abstract': False,
+ },
+ ),
+ migrations.CreateModel(
+ name='CAFTwinDateEvent',
+ fields=[
+ ('cafmixin_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='register.cafmixin')),
+ ('created_date', models.DateTimeField()),
+ ('modified_date', models.DateTimeField()),
+ ('short_description', models.CharField(help_text='Short description of the event. Use Comments field for full detail.', max_length=50)),
+ ('document_link', models.URLField(blank=True, help_text='URL only - do not try to drag a file here.', max_length=1000, null=True)),
+ ('comments', models.TextField(blank=True, help_text='Use this to provide further detail about the event.', max_length=1000, null=True)),
+ ('start_date', models.DateField()),
+ ('end_date', models.DateField(blank=True, null=True)),
+ ('type_descriptor', models.CharField(choices=[('CAF_PEER_REVIEW_PERIOD', 'CAF - Peer Review Period'), ('CAF_VALIDATION_PERIOD', 'CAF - Validation Period')], max_length=50)),
+ ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
+ ],
+ bases=('register.cafmixin', models.Model),
+ ),
+ migrations.CreateModel(
+ name='CAFSingleDateEvent',
+ fields=[
+ ('cafmixin_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='register.cafmixin')),
+ ('created_date', models.DateTimeField()),
+ ('modified_date', models.DateTimeField()),
+ ('short_description', models.CharField(help_text='Short description of the event. Use Comments field for full detail.', max_length=50)),
+ ('document_link', models.URLField(blank=True, help_text='URL only - do not try to drag a file here.', max_length=1000, null=True)),
+ ('comments', models.TextField(blank=True, help_text='Use this to provide further detail about the event.', max_length=1000, null=True)),
+ ('date', models.DateField()),
+ ('type_descriptor', models.CharField(choices=[('CAF_INITIAL_CAF_RECEIVED', 'CAF - Initial CAF Received'), ('CAF_FEEDBACK_EMAILED_OES', 'CAF - Emailed to OES'), ('CAF_RECEIVED', 'CAF - Received'), ('CAF_EMAILED_ROSA', 'CAF - Emailed to Rosa'), ('CAF_VALIDATION_SIGN_OFF', 'CAF - Validation Sign Off'), ('CAF_VALIDATION_RECORD_EMAILED_TO_OES', 'CAF - Validation Record Sent to OES')], max_length=50)),
+ ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
+ ],
+ bases=('register.cafmixin', models.Model),
+ ),
+ migrations.AddConstraint(
+ model_name='caftwindateevent',
+ constraint=models.CheckConstraint(check=models.Q(_negated=True, end_date__lt=django.db.models.expressions.F('start_date')), name='register_caftwindateevent_cannot_precede_start_date'),
+ ),
+ migrations.AddConstraint(
+ model_name='cafsingledateevent',
+ constraint=models.UniqueConstraint(condition=models.Q(_negated=True, type_descriptor='CAF_EMAILED_ROSA'), fields=('date', 'type_descriptor'), name='unique_caf_for_date'),
+ ),
+ ]
diff --git a/ctrack/register/models.py b/ctrack/register/models.py
index 4404650..005ccad 100644
--- a/ctrack/register/models.py
+++ b/ctrack/register/models.py
@@ -94,7 +94,7 @@ class ThirdPartyEventMixin(models.Model):
class SingleDateTimeEventMixin(models.Model):
- datetime = models.DateTimeField(blank=False)
+ datetime = models.DateTimeField(blank=False, verbose_name="Date/Time")
class Meta:
abstract = True
diff --git a/ctrack/register/templates/single_datetime_event_create.html b/ctrack/register/templates/single_datetime_event_create.html
index 94a5162..c4ec263 100644
--- a/ctrack/register/templates/single_datetime_event_create.html
+++ b/ctrack/register/templates/single_datetime_event_create.html
@@ -1,4 +1,27 @@
{% extends "base.html" %}
-{% block content %}
- {{ form }}
+
+{% load static %}
+{% load crispy_forms_tags %}
+
+{% block title %}
+ Create a new event (Meeting, Phone call, Email)
{% endblock %}
+
+
+
+
+
+{% block content %}
+ <div class="container">
+ <div class="row justify-content-center">
+ <div class="col-8">
+ <h3 class="mt-2">Create a new Simple Event</h3>
+ <form method="post">
+ {% csrf_token %}
+ {{ form|crispy}}
+ <button type="submit" class="btn btn-success">Submit</button>
+ </form>
+ </div>
+ </div>
+ </div>
+{% endblock content%}
diff --git a/ctrack/register/tests/test_views.py b/ctrack/register/tests/test_views.py
index 089cb9e..0b01047 100644
--- a/ctrack/register/tests/test_views.py
+++ b/ctrack/register/tests/test_views.py
@@ -1,18 +1,15 @@
import pytest
-from django.test import Client
from django.urls import reverse
from ctrack.register.views import SingleDateTimeEventCreate
-from ctrack.users.models import User
pytestmark = pytest.mark.django_db
class TestMeetingEventFormView:
- def test_add_meeting_form(self, user):
- client = Client()
- client.force_login(user)
- url = reverse("register:event_create_singledatetime")
+
+ def test_add_meeting_form(self, client):
+ url = reverse("register:event_create_simple_event")
response = client.get(url)
assert response.status_code == 200
@@ -32,7 +29,7 @@ class TestMeetingEventFormView:
def test_user_passed_as_kwarg(self, user, request_factory):
view = SingleDateTimeEventCreate()
- request = request_factory.get("/register/event/create-single-datetime/")
+ request = request_factory.get("/register/event/create-simple-event/")
request.user = user
view.request = request
view.setup(request)
diff --git a/ctrack/register/urls.py b/ctrack/register/urls.py
index fb05a02..b6ee408 100644
--- a/ctrack/register/urls.py
+++ b/ctrack/register/urls.py
@@ -26,8 +26,8 @@ urlpatterns = [
name="create_from_caf",
),
path(
- "event/create-single-datetime",
+ "event/create-simple-event",
view=SingleDateTimeEventCreate.as_view(),
- name="event_create_singledatetime",
+ name="event_create_simple_event",
),
]
diff --git a/ctrack/register/views.py b/ctrack/register/views.py
index b60d2be..a7a6c26 100644
--- a/ctrack/register/views.py
+++ b/ctrack/register/views.py
@@ -2,12 +2,12 @@ from django.contrib.auth import get_user_model
from django.contrib.auth.mixins import LoginRequiredMixin
from django.http import HttpResponseRedirect
from django.urls import reverse_lazy
-from django.views.generic import FormView, DeleteView
+from django.views.generic import FormView, DeleteView, CreateView
from ctrack.caf.models import CAF
from ctrack.organisations.models import Organisation
from ctrack.register.forms import EngagementEventCreateForm, AddMeetingForm
-from ctrack.register.models import EngagementEvent
+from ctrack.register.models import EngagementEvent, SingleDateTimeEvent
class EngagementEventDelete(DeleteView):
@@ -81,3 +81,7 @@ class SingleDateTimeEventCreate(LoginRequiredMixin, FormView):
kwargs = super().get_form_kwargs()
kwargs["user"] = self.request.user
return kwargs
+
+ def form_valid(self, form):
+ form.save()
+ return super().form_valid(form)