mirror of
https://github.com/ae-utbm/sith.git
synced 2025-07-09 19:40:19 +00:00
remove jquery datetime picker
This commit is contained in:
@ -20,7 +20,6 @@
|
||||
# Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#
|
||||
#
|
||||
import datetime
|
||||
import re
|
||||
from io import BytesIO
|
||||
|
||||
@ -39,11 +38,8 @@ from django.forms import (
|
||||
Textarea,
|
||||
TextInput,
|
||||
)
|
||||
from django.forms.utils import to_current_timezone
|
||||
from django.templatetags.static import static
|
||||
from django.urls import reverse
|
||||
from django.utils import timezone
|
||||
from django.utils.dateparse import parse_datetime
|
||||
from django.utils.translation import gettext
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from phonenumber_field.widgets import PhoneNumberInternationalFallbackWidget
|
||||
@ -56,21 +52,17 @@ from core.utils import resize_image
|
||||
|
||||
|
||||
class SelectDateTime(DateTimeInput):
|
||||
def render(self, name, value, attrs=None, renderer=None):
|
||||
if attrs:
|
||||
attrs["class"] = "select_datetime"
|
||||
else:
|
||||
attrs = {"class": "select_datetime"}
|
||||
return super().render(name, value, attrs, renderer)
|
||||
def __init__(self, attrs=None, format=None): # noqa A002
|
||||
default = {"type": "datetime-local"}
|
||||
attrs = default if attrs is None else default | attrs
|
||||
super().__init__(attrs=attrs, format=format or "%Y-%m-%d %H:%M")
|
||||
|
||||
|
||||
class SelectDate(DateInput):
|
||||
def render(self, name, value, attrs=None, renderer=None):
|
||||
if attrs:
|
||||
attrs["class"] = "select_date"
|
||||
else:
|
||||
attrs = {"class": "select_date"}
|
||||
return super().render(name, value, attrs, renderer)
|
||||
def __init__(self, attrs=None, format=None): # noqa A002
|
||||
default = {"type": "date"}
|
||||
attrs = default if attrs is None else default | attrs
|
||||
super().__init__(attrs=attrs, format=format or "%Y-%m-%d")
|
||||
|
||||
|
||||
class MarkdownInput(Textarea):
|
||||
@ -248,12 +240,6 @@ class UserProfileForm(forms.ModelForm):
|
||||
"scrub_pict": _("Scrub: let other know how your scrub looks like!"),
|
||||
}
|
||||
|
||||
def __init__(self, *arg, **kwargs):
|
||||
super().__init__(*arg, **kwargs)
|
||||
|
||||
def full_clean(self):
|
||||
super().full_clean()
|
||||
|
||||
def generate_name(self, field_name, f):
|
||||
field_name = field_name[:-4]
|
||||
return field_name + str(self.instance.id) + "." + f.content_type.split("/")[-1]
|
||||
@ -395,27 +381,3 @@ class GiftForm(forms.ModelForm):
|
||||
id=user_id
|
||||
)
|
||||
self.fields["user"].widget = forms.HiddenInput()
|
||||
|
||||
|
||||
class TzAwareDateTimeField(forms.DateTimeField):
|
||||
def __init__(self, input_formats=None, widget=SelectDateTime, **kwargs):
|
||||
if input_formats is None:
|
||||
input_formats = ["%Y-%m-%d %H:%M:%S"]
|
||||
super().__init__(input_formats=input_formats, widget=widget, **kwargs)
|
||||
|
||||
def prepare_value(self, value):
|
||||
# the db value is a datetime as a string in UTC
|
||||
if isinstance(value, str):
|
||||
# convert it into a naive datetime (no timezone attached)
|
||||
value = parse_datetime(value)
|
||||
# attach it to the UTC timezone (so that to_current_timezone()) if not None
|
||||
# converts it to the local timezone)
|
||||
if value is not None:
|
||||
value = timezone.make_aware(value, datetime.timezone.utc)
|
||||
|
||||
if isinstance(value, datetime.datetime):
|
||||
value = to_current_timezone(value)
|
||||
# otherwise it is formatted according to locale (in french)
|
||||
value = str(value)
|
||||
|
||||
return value
|
||||
|
Reference in New Issue
Block a user