from django import forms
from django.contrib.gis.forms import PointField
from django.utils import timezone

from emstrack.forms import LeafletPointWidget

from .models import Ambulance, Call

class AmbulanceCreateForm(forms.ModelForm):
    
    location = PointField(
        widget = LeafletPointWidget(attrs={'map_width': 500,
                                           'map_height': 300})
    )
    
    class Meta:
        model = Ambulance
        fields = [ 'identifier', 'capability', 'status', 'comment', 'location' ]


class AmbulanceUpdateForm(AmbulanceCreateForm):

    def clean_location_timestamp(self):

        print('clean_location_timestamp')

        # if updating location
        if 'location' in self.changed_data:

            # update timestamp as well
            self.cleaned_data['location_timestamp'] = timezone.now()

        return self.cleaned_data['location_timestamp']


# front end team to choose which fields to display?

class CallCreateForm(forms.ModelForm):
    class Meta:
        model = Call
        fields = '__all__'


# class AmbulanceStatusCreateForm(forms.ModelForm):
#     class Meta:
#         model = AmbulanceStatus
#         fields = '__all__'


# class AmbulanceStatusUpdateForm(forms.ModelForm):
#     class Meta:
#         model = AmbulanceStatus
#         fields = '__all__'


# class AmbulanceCapabilityCreateForm(forms.ModelForm):
#     class Meta:
#         model = AmbulanceCapability
#         fields = '__all__'

@@ -588,24 +588,244 @@
 teForm):%0D%0A%0D%0A
+    def clean_location(self):%0D%0A%0D%0A        print('clean_location')%0D%0A%0D%0A        # update timestamp as well%0D%0A        self.cleaned_data%5B'location_timestamp'%5D = timezone.now()%0D%0A%0D%0A        return self.cleaned_data%5B'location'%5D%0D%0A%0D%0A
     def clea

Update location_timestamp in AmbulanceUpdateView.