Merge pull request #725 from ae-utbm/drop-jquery-calendar

Remove jquery datetimepicker
This commit is contained in:
thomas girod 2024-07-25 01:20:41 +02:00 committed by GitHub
commit 04e7f65e8e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 60 additions and 104 deletions

View File

@ -29,7 +29,7 @@ from django.utils.translation import gettext_lazy as _
from club.models import Club, Mailing, MailingSubscription, Membership
from core.models import User
from core.views.forms import SelectDate, TzAwareDateTimeField
from core.views.forms import SelectDate, SelectDateTime
from counter.models import Counter
@ -149,8 +149,12 @@ class MailingForm(forms.Form):
class SellingsForm(forms.Form):
begin_date = TzAwareDateTimeField(label=_("Begin date"), required=False)
end_date = TzAwareDateTimeField(label=_("End date"), required=False)
begin_date = forms.DateTimeField(
label=_("Begin date"), widget=SelectDateTime, required=False
)
end_date = forms.DateTimeField(
label=_("End date"), widget=SelectDateTime, required=False
)
counters = forms.ModelMultipleChoiceField(
Counter.objects.order_by("name").all(), label=_("Counter"), required=False

View File

@ -50,7 +50,7 @@ from core.views import (
QuickNotifMixin,
TabedViewMixin,
)
from core.views.forms import MarkdownInput, TzAwareDateTimeField
from core.views.forms import MarkdownInput, SelectDateTime
# Sith object
@ -72,12 +72,15 @@ class PosterForm(forms.ModelForm):
widgets = {"screens": forms.CheckboxSelectMultiple}
help_texts = {"file": _("Format: 16:9 | Resolution: 1920x1080")}
date_begin = TzAwareDateTimeField(
date_begin = forms.DateTimeField(
label=_("Start date"),
widget=SelectDateTime,
required=True,
initial=timezone.now().strftime("%Y-%m-%d %H:%M:%S"),
)
date_end = TzAwareDateTimeField(label=_("End date"), required=False)
date_end = forms.DateTimeField(
label=_("End date"), widget=SelectDateTime, required=False
)
def __init__(self, *args, **kwargs):
self.user = kwargs.pop("user", None)
@ -191,9 +194,13 @@ class NewsForm(forms.ModelForm):
"content": MarkdownInput,
}
start_date = TzAwareDateTimeField(label=_("Start date"), required=False)
end_date = TzAwareDateTimeField(label=_("End date"), required=False)
until = TzAwareDateTimeField(label=_("Until"), required=False)
start_date = forms.DateTimeField(
label=_("Start date"), widget=SelectDateTime, required=False
)
end_date = forms.DateTimeField(
label=_("End date"), widget=SelectDateTime, required=False
)
until = forms.DateTimeField(label=_("Until"), widget=SelectDateTime, required=False)
automoderation = forms.BooleanField(label=_("Automoderation"), required=False)
@ -258,7 +265,7 @@ class NewsEditView(CanEditMixin, UpdateView):
def post(self, request, *args, **kwargs):
form = self.get_form()
if form.is_valid() and "preview" not in request.POST.keys():
if form.is_valid() and "preview" not in request.POST:
return self.form_valid(form)
else:
return self.form_invalid(form)

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -6,7 +6,6 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" href="{{ static('core/img/favicon.ico') }}">
<link rel="stylesheet" href="{{ static('core/base.css') }}">
<link rel="stylesheet" href="{{ static('core/jquery.datetimepicker.min.css') }}">
<link rel="stylesheet" href="{{ static('ajax_select/css/ajax_select.css') }}">
<link rel="stylesheet" href="{{ scss('core/style.scss') }}">
<link rel="stylesheet" href="{{ scss('core/markdown.scss') }}">
@ -295,47 +294,25 @@
</code>
</footer>
{% endif %}
<!--
{% block tests %}
{{ tests }}
{% endblock %}
-->
{% block script %}
<script src="{{ static('core/js/ui/jquery-ui.min.js') }}"></script>
<script src="{{ static('core/js/ui/i18n/datepicker-fr.js') }}"></script>
<script src="{{ static('core/js/jquery.datetimepicker.full.min.js') }}"></script>
<script src="{{ static('ajax_select/js/ajax_select.js') }}"></script>
<script src="{{ url('javascript-catalog') }}"></script>
<script>
function showMenu() {
let navbar = document.getElementById("navbar-content");
const current = navbar.style.getPropertyValue("display");
navbar.style.setProperty("display", current == "none" ? "block" : "none");
}
</script>
<script>
$('.select_date').datepicker({
changeMonth: true,
changeYear: true,
dayNamesShort: $.datepicker.regional[ "{{ request.LANGUAGE_CODE }}" ].dayNamesShort,
dayNames: $.datepicker.regional[ "{{ request.LANGUAGE_CODE }}" ].dayNames,
monthNamesShort: $.datepicker.regional[ "{{ request.LANGUAGE_CODE }}" ].monthNamesShort,
monthNames: $.datepicker.regional[ "{{ request.LANGUAGE_CODE }}" ].monthNames,
}).datepicker( $.datepicker.regional[ "{{ request.LANGUAGE_CODE }}"] );
function showMenu() {
let navbar = document.getElementById("navbar-content");
const current = navbar.style.getPropertyValue("display");
navbar.style.setProperty("display", current === "none" ? "block" : "none");
}
$(document).keydown(function (e) {
if ($(e.target).is('input')) { return }
if ($(e.target).is('textarea')) { return }
if ($(e.target).is('select')) { return }
if (e.keyCode == 83) {
if (e.keyCode === 83) {
$("#search").focus();
return false;
}
});
jQuery.datetimepicker.setLocale('{{ request.LANGUAGE_CODE|lower }}');
$('.select_datetime').datetimepicker({
format: 'Y-m-d H:i:s',
});
</script>
{% endblock %}
</body>

View File

@ -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):
@ -247,12 +239,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]
@ -394,27 +380,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

View File

@ -3,7 +3,7 @@ from ajax_select.fields import AutoCompleteSelectField, AutoCompleteSelectMultip
from django import forms
from django.utils.translation import gettext_lazy as _
from core.views.forms import SelectDate, TzAwareDateTimeField
from core.views.forms import SelectDate, SelectDateTime
from counter.models import (
BillingInfo,
Counter,
@ -168,8 +168,12 @@ class ProductEditForm(forms.ModelForm):
class CashSummaryFormBase(forms.Form):
begin_date = TzAwareDateTimeField(label=_("Begin date"), required=False)
end_date = TzAwareDateTimeField(label=_("End date"), required=False)
begin_date = forms.DateTimeField(
label=_("Begin date"), widget=SelectDateTime, required=False
)
end_date = forms.DateTimeField(
label=_("End date"), widget=SelectDateTime, required=False
)
class EticketForm(forms.ModelForm):

View File

@ -12,7 +12,7 @@ from django.views.generic.edit import CreateView, DeleteView, FormView, UpdateVi
from core.models import User
from core.views import CanCreateMixin, CanEditMixin, CanViewMixin
from core.views.forms import MarkdownInput, TzAwareDateTimeField
from core.views.forms import MarkdownInput, SelectDateTime
from election.models import Candidature, Election, ElectionList, Role, Vote
# Custom form field
@ -160,12 +160,18 @@ class ElectionForm(forms.ModelForm):
label=_("candidature groups"),
)
start_date = TzAwareDateTimeField(label=_("Start date"), required=True)
end_date = TzAwareDateTimeField(label=_("End date"), required=True)
start_candidature = TzAwareDateTimeField(
label=_("Start candidature"), required=True
start_date = forms.DateTimeField(
label=_("Start date"), widget=SelectDateTime, required=True
)
end_date = forms.DateTimeField(
label=_("End date"), widget=SelectDateTime, required=True
)
start_candidature = forms.DateTimeField(
label=_("Start candidature"), widget=SelectDateTime, required=True
)
end_candidature = forms.DateTimeField(
label=_("End candidature"), widget=SelectDateTime, required=True
)
end_candidature = TzAwareDateTimeField(label=_("End candidature"), required=True)
# Display elections

View File

@ -728,7 +728,6 @@ if SENTRY_DSN:
SITH_FRONT_DEP_VERSIONS = {
"https://github.com/chartjs/Chart.js/": "2.6.0",
"https://github.com/xdan/datetimepicker/": "2.5.21",
"https://github.com/Ionaru/easy-markdown-editor/": "2.18.0",
"https://github.com/FortAwesome/Font-Awesome/": "4.7.0",
"https://github.com/jquery/jquery/": "3.6.2",

View File

@ -24,18 +24,18 @@ from django.utils.translation import gettext_lazy as _
from django.views.generic.edit import CreateView, FormView
from core.models import User
from core.views.forms import SelectDate, TzAwareDateTimeField
from core.views.forms import SelectDate, SelectDateTime
from subscription.models import Subscription
class SelectionDateForm(forms.Form):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields["start_date"] = TzAwareDateTimeField(
label=_("Start date"), required=True
self.fields["start_date"] = forms.DateTimeField(
label=_("Start date"), widget=SelectDateTime, required=True
)
self.fields["end_date"] = TzAwareDateTimeField(
label=_("End date"), required=True
self.fields["end_date"] = forms.DateTimeField(
label=_("End date"), widget=SelectDateTime, required=True
)
@ -56,7 +56,7 @@ class SubscriptionForm(forms.ModelForm):
max_length=User._meta.get_field("first_name").max_length
)
self.fields["email"] = forms.EmailField()
self.fields["date_of_birth"] = forms.DateTimeField(widget=SelectDate)
self.fields["date_of_birth"] = forms.DateField(widget=SelectDate)
self.field_order = [
"member",