-
Notifications
You must be signed in to change notification settings - Fork 634
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #946 from alligatorbait/custom_datetime
CustomField datetime type formats updated to fixed string formats
- Loading branch information
Showing
8 changed files
with
100 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
$(() => { | ||
$(".date-field").datepicker({dateFormat: 'yy-mm-dd'}); | ||
}); | ||
$(() => { | ||
$(".datetime-field").datepicker({dateFormat: 'yy-mm-dd 00:00:00'}); | ||
}); | ||
$(() => { | ||
// TODO: This does not work as written, need to make functional | ||
$(".time-field").tooltip="Time format 24hr: 00:00:00"; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
$(() => { | ||
$("#id_due_date").datepicker(); | ||
$("#id_due_date").datepicker({dateFormat: 'yy-mm-dd 00:00:00'}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,34 @@ | ||
from django import template | ||
from django.template import Library | ||
from django.template.defaultfilters import date as date_filter | ||
from django.conf import settings | ||
|
||
register = template.Library() | ||
from datetime import datetime | ||
|
||
from helpdesk.forms import CUSTOMFIELD_DATE_FORMAT, CUSTOMFIELD_TIME_FORMAT, CUSTOMFIELD_DATETIME_FORMAT | ||
|
||
register = Library() | ||
|
||
|
||
@register.filter | ||
def get(value, arg, default=None): | ||
""" Call the dictionary get function """ | ||
return value.get(arg, default) | ||
|
||
|
||
@register.filter(expects_localtime=True) | ||
def datetime_string_format(value): | ||
""" | ||
:param value: String - Expected to be a datetime, date, or time in specific format | ||
:return: String - reformatted to default datetime, date, or time string if received in one of the expected formats | ||
""" | ||
try: | ||
new_value = date_filter(datetime.strptime(value, CUSTOMFIELD_DATETIME_FORMAT), settings.DATETIME_FORMAT) | ||
except ValueError: | ||
try: | ||
new_value = date_filter(datetime.strptime(value, CUSTOMFIELD_DATE_FORMAT), settings.DATE_FORMAT) | ||
except ValueError: | ||
try: | ||
new_value = date_filter(datetime.strptime(value, CUSTOMFIELD_TIME_FORMAT), settings.TIME_FORMAT) | ||
except ValueError: | ||
new_value = value | ||
return new_value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters