Skip to content

Commit

Permalink
Replace datetimepicker by corresponding HTML5 inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
Augustin-FL committed Dec 26, 2024
1 parent 8240ec7 commit 3c2b805
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 1,871 deletions.
4 changes: 4 additions & 0 deletions fir_nuggets/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from django.contrib.auth.models import User

from incidents.models import Incident
from incidents.fields import DateTimeLocalField


class Nugget(models.Model):
Expand All @@ -25,6 +26,9 @@ def __str__(self):


class NuggetForm(forms.ModelForm):
date = DateTimeLocalField()
start_timestamp = DateTimeLocalField()
end_timestamp = DateTimeLocalField()

class Meta:
model = Nugget
Expand Down
3 changes: 3 additions & 0 deletions fir_todos/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from django import forms

from incidents.models import Incident, IncidentCategory, BusinessLine, Label
from incidents.fields import DateTimeLocalField


class TodoItem(models.Model):
Expand All @@ -19,6 +20,8 @@ def __str__(self):


class TodoItemForm(forms.ModelForm):
done_time = DateTimeLocalField()

def __init__(self, *args, **kwargs):
self.user = kwargs.pop('for_user', None)
super(TodoItemForm, self).__init__(*args, **kwargs)
Expand Down
18 changes: 18 additions & 0 deletions incidents/fields.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from django import forms

class DateTimeLocalInput(forms.DateTimeInput):
input_type = "datetime-local"

class DateTimeLocalField(forms.DateTimeField):
# Set DATETIME_INPUT_FORMATS here because, if USE_L10N
# is True, the locale-dictated format will be applied
# instead of settings.DATETIME_INPUT_FORMATS.
# See also:
# https://developer.mozilla.org/en-US/docs/Web/HTML/Date_and_time_formats

input_formats = [
"%Y-%m-%dT%H:%M:%S",
"%Y-%m-%dT%H:%M:%S.%f",
"%Y-%m-%dT%H:%M",
]
widget = DateTimeLocalInput(format="%Y-%m-%dT%H:%M")
3 changes: 3 additions & 0 deletions incidents/forms.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from django.forms import ModelForm
from django import forms
from incidents.models import IncidentCategory, Incident, Comments, BusinessLine
from incidents.fields import DateTimeLocalField
from django.contrib.auth.forms import AuthenticationForm


Expand All @@ -26,6 +27,8 @@ def __init__(self, user, initial_device, **kwargs):


class IncidentForm(ModelForm):
date = DateTimeLocalField()

def __init__(self, *args, **kwargs):
self.user = kwargs.pop('for_user', None)
permissions = kwargs.pop('permissions', None)
Expand Down
9 changes: 0 additions & 9 deletions incidents/static/css/bootstrap-datetimepicker.min.css

This file was deleted.

8 changes: 0 additions & 8 deletions incidents/static/custom_js/auto_ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,4 @@ $(function () {

event.preventDefault();
});

// Enable datetimepickers
$('.datetime').datetimepicker({
format: 'yyyy-mm-dd hh:ii',
autoclose: true,
todayBtn: true,
keyboardNavigation: false,
});
});
Loading

0 comments on commit 3c2b805

Please sign in to comment.