diff options
Diffstat (limited to 'ctrack')
-rw-r--r-- | ctrack/organisations/templates/organisations/organisation_detail.html | 2 | ||||
-rw-r--r-- | ctrack/register/forms.py | 16 | ||||
-rw-r--r-- | ctrack/register/models.py | 8 | ||||
-rw-r--r-- | ctrack/register/templates/register/engagementevent_form.html | 7 | ||||
-rw-r--r-- | ctrack/register/views.py | 4 |
5 files changed, 26 insertions, 11 deletions
diff --git a/ctrack/organisations/templates/organisations/organisation_detail.html b/ctrack/organisations/templates/organisations/organisation_detail.html index 708f5a2..97f7429 100644 --- a/ctrack/organisations/templates/organisations/organisation_detail.html +++ b/ctrack/organisations/templates/organisations/organisation_detail.html @@ -200,7 +200,7 @@ <div class="col-md-12 my-2"> <div class="card bg-light"> <div class="card-body"> - <div class="card-title" style="font-size: 1.1rem;">Engagements<a href="{% url "register:create" object.slug %}" + <div class="card-title" style="font-size: 1.1rem;">Engagements & Compliance Events<a href="{% url "register:create" object.slug %}" class="btn btn-outline-primary btn-sm float-right">Add new...</a></div> <div class="table table-responsive"> diff --git a/ctrack/register/forms.py b/ctrack/register/forms.py index fe3d35a..308a7e0 100644 --- a/ctrack/register/forms.py +++ b/ctrack/register/forms.py @@ -1,28 +1,33 @@ from crispy_forms.helper import FormHelper -from crispy_forms.layout import Button, ButtonHolder, Layout, Submit +from crispy_forms.layout import Button, ButtonHolder, Layout, Submit, Hidden from django import forms +from django.shortcuts import get_object_or_404 from django.urls import reverse -from ctrack.organisations.models import Person +from ctrack.organisations.models import Person, Organisation from ctrack.register.models import EngagementEvent class EngagementEventCreateForm(forms.ModelForm): - def __init__(self, org_slug, *args, **kwargs): + def __init__(self, org_slug, user, *args, **kwargs): super().__init__(*args, **kwargs) + org = get_object_or_404(Organisation, slug=org_slug) cancel_redirect = reverse("core:home") self.fields["participants"].queryset = Person.objects.filter(organisation__slug=org_slug) + self.fields["related_caf"].queryset = org.caf_set.all() + self.fields["related_caf"].label = "Related CAFs" self.helper = FormHelper(self) self.helper.layout = Layout( "type", "short_description", "participants", - "user", + # "user", + Hidden("user", "none"), "date", "end_date", - "document_link", "response_date_requested", "response_received", + "document_link", "related_caf", "comments", ButtonHolder( @@ -46,6 +51,7 @@ class EngagementEventCreateForm(forms.ModelForm): class Meta: model = EngagementEvent fields = "__all__" + exclude = ["user"] widgets = { "date": forms.DateTimeInput(attrs={"type": "date"}), "end_date": forms.DateTimeInput(attrs={"type": "date"}), diff --git a/ctrack/register/models.py b/ctrack/register/models.py index 4231dd0..642d69b 100644 --- a/ctrack/register/models.py +++ b/ctrack/register/models.py @@ -54,19 +54,19 @@ class EngagementEvent(models.Model): type = models.ForeignKey(EngagementType, on_delete=models.CASCADE) short_description = models.CharField( - max_length=50, help_text="Short description of the event" + max_length=50, help_text="Short description of the event. Use Comments field for full detail." ) participants = models.ManyToManyField(Person) user = models.ForeignKey(get_user_model(), on_delete=models.SET(get_sentinel_user)) date = models.DateTimeField() end_date = models.DateTimeField(blank=True, null=True) - document_link = models.URLField(max_length=1000, blank=True, null=True) + document_link = models.URLField(max_length=1000, blank=True, null=True, help_text="URL only - do not try to drag a file here") response_date_requested = models.DateField(blank=True, null=True) response_received = models.DateField(blank=True, null=True) related_caf = models.ForeignKey( - CAF, blank=True, on_delete=models.CASCADE, null=True + CAF, blank=True, on_delete=models.CASCADE, null=True, help_text="If the event relates to a CAF, refer to it here." ) - comments = models.TextField(max_length=1000, blank=True, null=True) + comments = models.TextField(max_length=1000, blank=True, null=True, help_text="Use this to provide further detail about the event.") def days_to_response_due(self) -> Optional[Dict[int, str]]: if self.response_date_requested: diff --git a/ctrack/register/templates/register/engagementevent_form.html b/ctrack/register/templates/register/engagementevent_form.html index ac42c9c..0103f0d 100644 --- a/ctrack/register/templates/register/engagementevent_form.html +++ b/ctrack/register/templates/register/engagementevent_form.html @@ -10,7 +10,12 @@ <div class="container mt-3"> <div class="row"> <div class="col-md-12 pl-0 my-2"> - <h4>Register a new engagement event for {{ org.name }}</h4> + <h4>Register a new engagement event</h4> + </div> + </div> + <div class="row"> + <div class="col-md-12 pl-0 my-2"> + <h5 class="text-secondary">{{ org.name }}</h5> </div> </div> <div class="row"> diff --git a/ctrack/register/views.py b/ctrack/register/views.py index 4f547f9..3daabd7 100644 --- a/ctrack/register/views.py +++ b/ctrack/register/views.py @@ -1,3 +1,4 @@ +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, reverse_lazy @@ -14,12 +15,15 @@ class EngagementEventCreate(LoginRequiredMixin, FormView): success_url = reverse_lazy("organisations:list") def form_valid(self, form): + ee = form.save(commit=False) + ee.user = self.request.user form.save() return HttpResponseRedirect(reverse("organisations:list")) def get_form_kwargs(self): kwargs = super().get_form_kwargs() kwargs["org_slug"] = self.kwargs["slug"] + kwargs["user"] = get_user_model() return kwargs def get_context_data(self, **kwargs): |