summaryrefslogblamecommitdiffstats
path: root/engagements/forms.py
blob: 253289205a88c7285db5f0b150410e8180ced09f (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12




                                                
 





                                                                         


                                                                                                                                                                                   


                                



                                                                                                  
                  




                                  
         
                   







                                                              
                       

                                                                                                                                                                    
                  
                                   
              
                                                     
                       

                                                                                                                                                                    
                  
                                   
              

                                                                                                                                                                                                         



                                                            











                                  
                                                                                         



                                                       





                                                     







                                                          










                                  
                                                                                         



                                                       





                                                     









                                                        


                                                                                                                                                                                 




                                                                                       
                                                                                                                                          


                                                                                         


                                                                                         




                                                  

                                                         



                                                                     



                                                                                                                                                                                   



                                






                                                                                                                                                                          
                                                       



                                                                                                                                                                    


                                                     



                                                                                                                                                                    

                                   


                                                                                                                                                                                                              
















                                                                                          
                             









                                                                        



                                                                           
         
from django import forms
from django.forms.widgets import HiddenInput

from .models import Engagement, EngagementEffort


# TODO - need to handle errors correctly in this form and in the template


class EngagementEffortReportingCreateForm(forms.ModelForm):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.fields['is_planned'].widget.attrs.update({"class": "select-lg"})
        # for field in self.fields.values():
        #     field.widget.attrs['class'] = 'mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50'

    class Meta:
        model = EngagementEffort
        help_texts = {
            "is_planned": ("To distinguish planned events from retrospective recording."),
            "officers": ("Include yourself here but you can also add effort for your colleagues.")
        }
        fields = [
            'is_planned',
            'proposed_start_date',
            'proposed_end_date',
            'officers',
            'notes',
        ]
        widgets = {
            # 'is_planned': forms.Select(
            #     choices=(
            #         (True, "YES"),
            #         (False, "NO"),
            #     ),
            #     attrs={'class': 'select-lg w-full max-w-xs'}
            # ),
            'proposed_start_date': forms.DateTimeInput(
                attrs={
                    'type': 'datetime-local',
                    'class': 'mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50'
                },
                format='j M y H:i',
            ),
            'proposed_end_date': forms.DateTimeInput(
                attrs={
                    'type': 'datetime-local',
                    'class': 'mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50'
                },
                format='j M y H:i',
            ),
            'officers': forms.SelectMultiple(attrs={'class': 'mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50'}),
            'notes': forms.Textarea(attrs={'class': 'mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50', 'rows': 3}),
        }


class EngagementEffortRegulationCreateForm(forms.ModelForm):

    class Meta:
        model = EngagementEffort
        fields = [
            "is_planned",
            "proposed_start_date",
            "proposed_end_date",
            "officers",
            "sub_instruments",
            "notes",
        ]
        help_texts = {
            "is_planned": ("To distinguish planned events from retrospective recording.")
        }
        widgets = {
            "proposed_start_date": forms.DateTimeInput(
                attrs={
                    "type": "datetime-local",
                },
                format="j M y H:i",
            ),
            "proposed_end_date": forms.DateTimeInput(
                attrs={
                    "type": "datetime-local",
                },
                format="j M y H:i",
            ),
        }


class EngagementEffortPlanningCreateForm(forms.ModelForm):

    class Meta:
        model = EngagementEffort
        fields = [
            "is_planned",
            "proposed_start_date",
            "proposed_end_date",
            "officers",
            "notes",
        ]
        help_texts = {
            "is_planned": ("To distinguish planned events from retrospective recording.")
        }
        widgets = {
            "proposed_start_date": forms.DateTimeInput(
                attrs={
                    "type": "datetime-local",
                },
                format="j M y H:i",
            ),
            "proposed_end_date": forms.DateTimeInput(
                attrs={
                    "type": "datetime-local",
                },
                format="j M y H:i",
            ),
        }


class EngagementEffortTravelCreateForm(forms.ModelForm):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.fields['is_planned'].widget.attrs.update({"class": "select-lg"})
        for field in self.fields.values():
            field.widget.attrs['class'] = 'mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50'

    class Meta:
        model = EngagementEffort
        fields = ["is_planned", "proposed_start_date", "proposed_end_date", "officers"]
        widgets = {
            "is_planned": forms.Select(choices=((True, "YES"), (False, "NO")), attrs={"class": "select select-bordered w-full max-w-xs"}),
            "proposed_start_date": forms.DateTimeInput(attrs={"type": "datetime-local"}),
            "proposed_end_date": forms.DateTimeInput(attrs={"type": "datetime-local"}),
        }
        help_texts = {
            "is_planned": ("To distinguish planned events from retrospective recording.")
        }


class EngagementEffortCreateForm(forms.ModelForm):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.fields['engagement'].widget = HiddenInput()
        self.fields['effort_type'].widget = HiddenInput()
        if kwargs.get("initial"):
            if not kwargs["initial"]["effort_type"] == "REGULATION":
                self.fields["sub_instruments"].widget = HiddenInput()

        # Apply Tailwind classes to all visible fields
        # for field in self.visible_fields():
        #     field.widget.attrs['class'] = 'mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50'

    class Meta:
        model = EngagementEffort
        fields = "__all__"
        widgets = {
            # "is_planned": forms.Select(
            #     choices=(
            #         (True, "YES"),
            #         (False, "NO"),
            #     ),
            #     attrs={'class': 'mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50'}
            # ),
            "proposed_start_date": forms.DateTimeInput(
                attrs={
                    "type": "datetime-local",
                    "class": "mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50"
                },
                format="j M y H:i",
            ),
            "proposed_end_date": forms.DateTimeInput(
                attrs={
                    "type": "datetime-local",
                    "class": "mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50"
                },
                format="j M y H:i",
            ),
            "effort_type": forms.Select(attrs={'class': 'mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50'}),
            "officers": forms.SelectMultiple(attrs={'class': 'mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50'}),
            "sub_instruments": forms.SelectMultiple(attrs={'class': 'mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50'}),
        }


class EngagementCreateForm(forms.ModelForm):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        try:
            self.fields["engagement_type"].queryset = kwargs["initial"]["engagement_type"]
        except KeyError:
            pass

    class Meta:
        model = Engagement
        fields = [
            "proposed_start_date",
            "proposed_end_date",
            "engagement_type",
            "external_party",
            "officers",
        ]
        labels = {
            "officers": "Inspectors",
        }
        help_texts = {
            "proposed_start_date": "<small><em>YYYY-MM-DD</em></small>",
            "proposed_end_date": "<small><em>YYYY-MM-DD</em></small>",
        }
        widgets = {
            "proposed_start_date": forms.DateInput(attrs={"type": "date"}),
            "proposed_end_date": forms.DateInput(attrs={"type": "date"}),
            "engagement_type": forms.Select(),
            "officers": forms.SelectMultiple(),
        }