mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-22 06:03:20 +00:00
remove jquery datetime picker
This commit is contained in:
parent
a1296dc7af
commit
9295325d21
@ -29,7 +29,7 @@ from django.utils.translation import gettext_lazy as _
|
|||||||
|
|
||||||
from club.models import Club, Mailing, MailingSubscription, Membership
|
from club.models import Club, Mailing, MailingSubscription, Membership
|
||||||
from core.models import User
|
from core.models import User
|
||||||
from core.views.forms import SelectDate, TzAwareDateTimeField
|
from core.views.forms import SelectDate, SelectDateTime
|
||||||
from counter.models import Counter
|
from counter.models import Counter
|
||||||
|
|
||||||
|
|
||||||
@ -155,8 +155,12 @@ class MailingForm(forms.Form):
|
|||||||
|
|
||||||
|
|
||||||
class SellingsForm(forms.Form):
|
class SellingsForm(forms.Form):
|
||||||
begin_date = TzAwareDateTimeField(label=_("Begin date"), required=False)
|
begin_date = forms.DateTimeField(
|
||||||
end_date = TzAwareDateTimeField(label=_("End date"), required=False)
|
label=_("Begin date"), widget=SelectDateTime, required=False
|
||||||
|
)
|
||||||
|
end_date = forms.DateTimeField(
|
||||||
|
label=_("End date"), widget=SelectDateTime, required=False
|
||||||
|
)
|
||||||
|
|
||||||
counters = forms.ModelMultipleChoiceField(
|
counters = forms.ModelMultipleChoiceField(
|
||||||
Counter.objects.order_by("name").all(), label=_("Counter"), required=False
|
Counter.objects.order_by("name").all(), label=_("Counter"), required=False
|
||||||
|
21
com/views.py
21
com/views.py
@ -50,7 +50,7 @@ from core.views import (
|
|||||||
QuickNotifMixin,
|
QuickNotifMixin,
|
||||||
TabedViewMixin,
|
TabedViewMixin,
|
||||||
)
|
)
|
||||||
from core.views.forms import MarkdownInput, TzAwareDateTimeField
|
from core.views.forms import MarkdownInput, SelectDateTime
|
||||||
|
|
||||||
# Sith object
|
# Sith object
|
||||||
|
|
||||||
@ -72,12 +72,15 @@ class PosterForm(forms.ModelForm):
|
|||||||
widgets = {"screens": forms.CheckboxSelectMultiple}
|
widgets = {"screens": forms.CheckboxSelectMultiple}
|
||||||
help_texts = {"file": _("Format: 16:9 | Resolution: 1920x1080")}
|
help_texts = {"file": _("Format: 16:9 | Resolution: 1920x1080")}
|
||||||
|
|
||||||
date_begin = TzAwareDateTimeField(
|
date_begin = forms.DateTimeField(
|
||||||
label=_("Start date"),
|
label=_("Start date"),
|
||||||
|
widget=SelectDateTime,
|
||||||
required=True,
|
required=True,
|
||||||
initial=timezone.now().strftime("%Y-%m-%d %H:%M:%S"),
|
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):
|
def __init__(self, *args, **kwargs):
|
||||||
self.user = kwargs.pop("user", None)
|
self.user = kwargs.pop("user", None)
|
||||||
@ -191,9 +194,13 @@ class NewsForm(forms.ModelForm):
|
|||||||
"content": MarkdownInput,
|
"content": MarkdownInput,
|
||||||
}
|
}
|
||||||
|
|
||||||
start_date = TzAwareDateTimeField(label=_("Start date"), required=False)
|
start_date = forms.DateTimeField(
|
||||||
end_date = TzAwareDateTimeField(label=_("End date"), required=False)
|
label=_("Start date"), widget=SelectDateTime, required=False
|
||||||
until = TzAwareDateTimeField(label=_("Until"), 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)
|
automoderation = forms.BooleanField(label=_("Automoderation"), required=False)
|
||||||
|
|
||||||
@ -258,7 +265,7 @@ class NewsEditView(CanEditMixin, UpdateView):
|
|||||||
|
|
||||||
def post(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs):
|
||||||
form = self.get_form()
|
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)
|
return self.form_valid(form)
|
||||||
else:
|
else:
|
||||||
return self.form_invalid(form)
|
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
@ -6,7 +6,6 @@
|
|||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<link rel="shortcut icon" href="{{ static('core/img/favicon.ico') }}">
|
<link rel="shortcut icon" href="{{ static('core/img/favicon.ico') }}">
|
||||||
<link rel="stylesheet" href="{{ static('core/base.css') }}">
|
<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="{{ static('ajax_select/css/ajax_select.css') }}">
|
||||||
<link rel="stylesheet" href="{{ scss('core/style.scss') }}">
|
<link rel="stylesheet" href="{{ scss('core/style.scss') }}">
|
||||||
<link rel="stylesheet" href="{{ scss('core/markdown.scss') }}">
|
<link rel="stylesheet" href="{{ scss('core/markdown.scss') }}">
|
||||||
@ -295,47 +294,25 @@
|
|||||||
</code>
|
</code>
|
||||||
</footer>
|
</footer>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<!--
|
|
||||||
{% block tests %}
|
|
||||||
{{ tests }}
|
|
||||||
{% endblock %}
|
|
||||||
-->
|
|
||||||
{% block script %}
|
{% block script %}
|
||||||
<script src="{{ static('core/js/ui/jquery-ui.min.js') }}"></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="{{ static('ajax_select/js/ajax_select.js') }}"></script>
|
||||||
<script src="{{ url('javascript-catalog') }}"></script>
|
<script src="{{ url('javascript-catalog') }}"></script>
|
||||||
<script>
|
<script>
|
||||||
function showMenu() {
|
function showMenu() {
|
||||||
let navbar = document.getElementById("navbar-content");
|
let navbar = document.getElementById("navbar-content");
|
||||||
const current = navbar.style.getPropertyValue("display");
|
const current = navbar.style.getPropertyValue("display");
|
||||||
navbar.style.setProperty("display", current == "none" ? "block" : "none");
|
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 }}"] );
|
|
||||||
$(document).keydown(function (e) {
|
$(document).keydown(function (e) {
|
||||||
if ($(e.target).is('input')) { return }
|
if ($(e.target).is('input')) { return }
|
||||||
if ($(e.target).is('textarea')) { return }
|
if ($(e.target).is('textarea')) { return }
|
||||||
if ($(e.target).is('select')) { return }
|
if ($(e.target).is('select')) { return }
|
||||||
if (e.keyCode == 83) {
|
if (e.keyCode === 83) {
|
||||||
$("#search").focus();
|
$("#search").focus();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
jQuery.datetimepicker.setLocale('{{ request.LANGUAGE_CODE|lower }}');
|
|
||||||
$('.select_datetime').datetimepicker({
|
|
||||||
format: 'Y-m-d H:i:s',
|
|
||||||
});
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
</body>
|
</body>
|
||||||
|
@ -20,7 +20,6 @@
|
|||||||
# Place - Suite 330, Boston, MA 02111-1307, USA.
|
# Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
import datetime
|
|
||||||
import re
|
import re
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
|
||||||
@ -39,11 +38,8 @@ from django.forms import (
|
|||||||
Textarea,
|
Textarea,
|
||||||
TextInput,
|
TextInput,
|
||||||
)
|
)
|
||||||
from django.forms.utils import to_current_timezone
|
|
||||||
from django.templatetags.static import static
|
from django.templatetags.static import static
|
||||||
from django.urls import reverse
|
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
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from phonenumber_field.widgets import PhoneNumberInternationalFallbackWidget
|
from phonenumber_field.widgets import PhoneNumberInternationalFallbackWidget
|
||||||
@ -56,21 +52,17 @@ from core.utils import resize_image
|
|||||||
|
|
||||||
|
|
||||||
class SelectDateTime(DateTimeInput):
|
class SelectDateTime(DateTimeInput):
|
||||||
def render(self, name, value, attrs=None, renderer=None):
|
def __init__(self, attrs=None, format=None): # noqa A002
|
||||||
if attrs:
|
default = {"type": "datetime-local"}
|
||||||
attrs["class"] = "select_datetime"
|
attrs = default if attrs is None else default | attrs
|
||||||
else:
|
super().__init__(attrs=attrs, format=format or "%Y-%m-%d %H:%M")
|
||||||
attrs = {"class": "select_datetime"}
|
|
||||||
return super().render(name, value, attrs, renderer)
|
|
||||||
|
|
||||||
|
|
||||||
class SelectDate(DateInput):
|
class SelectDate(DateInput):
|
||||||
def render(self, name, value, attrs=None, renderer=None):
|
def __init__(self, attrs=None, format=None): # noqa A002
|
||||||
if attrs:
|
default = {"type": "date"}
|
||||||
attrs["class"] = "select_date"
|
attrs = default if attrs is None else default | attrs
|
||||||
else:
|
super().__init__(attrs=attrs, format=format or "%Y-%m-%d")
|
||||||
attrs = {"class": "select_date"}
|
|
||||||
return super().render(name, value, attrs, renderer)
|
|
||||||
|
|
||||||
|
|
||||||
class MarkdownInput(Textarea):
|
class MarkdownInput(Textarea):
|
||||||
@ -248,12 +240,6 @@ class UserProfileForm(forms.ModelForm):
|
|||||||
"scrub_pict": _("Scrub: let other know how your scrub looks like!"),
|
"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):
|
def generate_name(self, field_name, f):
|
||||||
field_name = field_name[:-4]
|
field_name = field_name[:-4]
|
||||||
return field_name + str(self.instance.id) + "." + f.content_type.split("/")[-1]
|
return field_name + str(self.instance.id) + "." + f.content_type.split("/")[-1]
|
||||||
@ -395,27 +381,3 @@ class GiftForm(forms.ModelForm):
|
|||||||
id=user_id
|
id=user_id
|
||||||
)
|
)
|
||||||
self.fields["user"].widget = forms.HiddenInput()
|
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
|
|
||||||
|
@ -3,7 +3,7 @@ from ajax_select.fields import AutoCompleteSelectField, AutoCompleteSelectMultip
|
|||||||
from django import forms
|
from django import forms
|
||||||
from django.utils.translation import gettext_lazy as _
|
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 (
|
from counter.models import (
|
||||||
BillingInfo,
|
BillingInfo,
|
||||||
Counter,
|
Counter,
|
||||||
@ -170,8 +170,12 @@ class ProductEditForm(forms.ModelForm):
|
|||||||
|
|
||||||
|
|
||||||
class CashSummaryFormBase(forms.Form):
|
class CashSummaryFormBase(forms.Form):
|
||||||
begin_date = TzAwareDateTimeField(label=_("Begin date"), required=False)
|
begin_date = forms.DateTimeField(
|
||||||
end_date = TzAwareDateTimeField(label=_("End date"), required=False)
|
label=_("Begin date"), widget=SelectDateTime, required=False
|
||||||
|
)
|
||||||
|
end_date = forms.DateTimeField(
|
||||||
|
label=_("End date"), widget=SelectDateTime, required=False
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class EticketForm(forms.ModelForm):
|
class EticketForm(forms.ModelForm):
|
||||||
|
@ -12,7 +12,7 @@ from django.views.generic.edit import CreateView, DeleteView, FormView, UpdateVi
|
|||||||
|
|
||||||
from core.models import User
|
from core.models import User
|
||||||
from core.views import CanCreateMixin, CanEditMixin, CanViewMixin
|
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
|
from election.models import Candidature, Election, ElectionList, Role, Vote
|
||||||
|
|
||||||
# Custom form field
|
# Custom form field
|
||||||
@ -163,12 +163,18 @@ class ElectionForm(forms.ModelForm):
|
|||||||
label=_("candidature groups"),
|
label=_("candidature groups"),
|
||||||
)
|
)
|
||||||
|
|
||||||
start_date = TzAwareDateTimeField(label=_("Start date"), required=True)
|
start_date = forms.DateTimeField(
|
||||||
end_date = TzAwareDateTimeField(label=_("End date"), required=True)
|
label=_("Start date"), widget=SelectDateTime, required=True
|
||||||
start_candidature = TzAwareDateTimeField(
|
)
|
||||||
label=_("Start candidature"), 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
|
# Display elections
|
||||||
|
@ -729,7 +729,6 @@ if SENTRY_DSN:
|
|||||||
|
|
||||||
SITH_FRONT_DEP_VERSIONS = {
|
SITH_FRONT_DEP_VERSIONS = {
|
||||||
"https://github.com/chartjs/Chart.js/": "2.6.0",
|
"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/Ionaru/easy-markdown-editor/": "2.18.0",
|
||||||
"https://github.com/FortAwesome/Font-Awesome/": "4.7.0",
|
"https://github.com/FortAwesome/Font-Awesome/": "4.7.0",
|
||||||
"https://github.com/jquery/jquery/": "3.6.2",
|
"https://github.com/jquery/jquery/": "3.6.2",
|
||||||
|
@ -24,18 +24,18 @@ from django.utils.translation import gettext_lazy as _
|
|||||||
from django.views.generic.edit import CreateView, FormView
|
from django.views.generic.edit import CreateView, FormView
|
||||||
|
|
||||||
from core.models import User
|
from core.models import User
|
||||||
from core.views.forms import SelectDate, TzAwareDateTimeField
|
from core.views.forms import SelectDate, SelectDateTime
|
||||||
from subscription.models import Subscription
|
from subscription.models import Subscription
|
||||||
|
|
||||||
|
|
||||||
class SelectionDateForm(forms.Form):
|
class SelectionDateForm(forms.Form):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self.fields["start_date"] = TzAwareDateTimeField(
|
self.fields["start_date"] = forms.DateTimeField(
|
||||||
label=_("Start date"), required=True
|
label=_("Start date"), widget=SelectDateTime, required=True
|
||||||
)
|
)
|
||||||
self.fields["end_date"] = TzAwareDateTimeField(
|
self.fields["end_date"] = forms.DateTimeField(
|
||||||
label=_("End date"), required=True
|
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
|
max_length=User._meta.get_field("first_name").max_length
|
||||||
)
|
)
|
||||||
self.fields["email"] = forms.EmailField()
|
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 = [
|
self.field_order = [
|
||||||
"member",
|
"member",
|
||||||
|
Loading…
Reference in New Issue
Block a user