From f802e30297e8901df67b06bfa9aba7fa49bceae2 Mon Sep 17 00:00:00 2001 From: GabrielTaufer Date: Tue, 22 Sep 2020 21:41:58 -0300 Subject: [PATCH 01/20] Fixed datetime initial value verification --- django_remote_forms/fields.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/django_remote_forms/fields.py b/django_remote_forms/fields.py index 4e0d33a..e27170e 100644 --- a/django_remote_forms/fields.py +++ b/django_remote_forms/fields.py @@ -40,7 +40,7 @@ def as_dict(self): try: remote_widget_class = getattr(widgets, remote_widget_class_name) remote_widget = remote_widget_class(self.field.widget, field_name=self.field_name) - except Exception, e: + except Exception as e: logger.warning('Error serializing %s: %s', remote_widget_class_name, str(e)) widget_dict = {} else: @@ -104,7 +104,7 @@ def as_dict(self): # If initial value is datetime then convert it using first available input format if (isinstance(field_dict['initial'], (datetime.datetime, datetime.time, datetime.date))): - if not len(field_dict['input_formats']): + if not getattr(field_dict['input_formats'], 'len', None): if isinstance(field_dict['initial'], datetime.date): field_dict['input_formats'] = settings.DATE_INPUT_FORMATS elif isinstance(field_dict['initial'], datetime.time): From 1ce0a49da9e70d236ebae72c902f8afab64ffb48 Mon Sep 17 00:00:00 2001 From: GabrielTaufer Date: Tue, 22 Sep 2020 21:43:05 -0300 Subject: [PATCH 02/20] Fix exception error syntax --- django_remote_forms/forms.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/django_remote_forms/forms.py b/django_remote_forms/forms.py index bebb1b7..ee736dd 100644 --- a/django_remote_forms/forms.py +++ b/django_remote_forms/forms.py @@ -51,7 +51,7 @@ def __init__(self, form, *args, **kwargs): self.excluded_fields |= (self.included_fields - self.all_fields) if not self.ordered_fields: - if self.form.fields.keyOrder: + if hasattr(self.form.fields, 'keyOrder'): self.ordered_fields = self.form.fields.keyOrder else: self.ordered_fields = self.form.fields.keys() @@ -138,7 +138,7 @@ def as_dict(self): try: remote_field_class = getattr(fields, remote_field_class_name) remote_field = remote_field_class(field, form_initial_field_data, field_name=name) - except Exception, e: + except Exception as e: logger.warning('Error serializing field %s: %s', remote_field_class_name, str(e)) field_dict = {} else: From d31fd851e40a08c1a23b4a75197bcd2181824a4f Mon Sep 17 00:00:00 2001 From: GabrielTaufer Date: Tue, 22 Sep 2020 21:43:49 -0300 Subject: [PATCH 03/20] Change force_unicode to force_text import from django.utils.encoding --- django_remote_forms/utils.py | 4 ++-- django_remote_forms/widgets.py | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/django_remote_forms/utils.py b/django_remote_forms/utils.py index 0391fa0..cc47c2a 100644 --- a/django_remote_forms/utils.py +++ b/django_remote_forms/utils.py @@ -1,5 +1,5 @@ from django.utils.functional import Promise -from django.utils.encoding import force_unicode +from django.utils.encoding import force_text def resolve_promise(o): @@ -10,7 +10,7 @@ def resolve_promise(o): o = [resolve_promise(x) for x in o] elif isinstance(o, Promise): try: - o = force_unicode(o) + o = force_text(o) except: # Item could be a lazy tuple or list try: diff --git a/django_remote_forms/widgets.py b/django_remote_forms/widgets.py index 3ca30e6..d66a3fb 100644 --- a/django_remote_forms/widgets.py +++ b/django_remote_forms/widgets.py @@ -112,8 +112,6 @@ def as_dict(self): widget_dict = super(RemoteTimeInput, self).as_dict() widget_dict['format'] = self.widget.format - widget_dict['manual_format'] = self.widget.manual_format - widget_dict['date'] = self.widget.manual_format widget_dict['input_type'] = 'time' return widget_dict From bf56787d6f92116146fa209f1aa678c7f2fc4486 Mon Sep 17 00:00:00 2001 From: GabrielTaufer Date: Mon, 12 Oct 2020 10:41:06 -0300 Subject: [PATCH 04/20] Form as dict hotfix --- django_remote_forms/forms.py | 12 +++++++++--- django_remote_forms/utils.py | 3 +++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/django_remote_forms/forms.py b/django_remote_forms/forms.py index ee736dd..6087373 100644 --- a/django_remote_forms/forms.py +++ b/django_remote_forms/forms.py @@ -10,6 +10,7 @@ def __init__(self, form, *args, **kwargs): self.all_fields = set(self.form.fields.keys()) + self.title = kwargs.pop('title', None) self.excluded_fields = set(kwargs.pop('exclude', [])) self.included_fields = set(kwargs.pop('include', [])) self.readonly_fields = set(kwargs.pop('readonly', [])) @@ -108,7 +109,8 @@ def as_dict(self): } """ form_dict = OrderedDict() - form_dict['title'] = self.form.__class__.__name__ + + form_dict['title'] = self.title if self.title else self.form.__class__.__name__ form_dict['non_field_errors'] = self.form.non_field_errors() form_dict['label_suffix'] = self.form.label_suffix form_dict['is_bound'] = self.form.is_bound @@ -123,6 +125,7 @@ def as_dict(self): initial_data = {} for name, field in [(x, self.form.fields[x]) for x in self.fields]: + print(' ', name, field) # Retrieve the initial data from the form itself if it exists so # that we properly handle which initial data should be returned in # the dictionary. @@ -153,11 +156,14 @@ def as_dict(self): if 'initial' not in form_dict['fields'][name]: form_dict['fields'][name]['initial'] = None - initial_data[name] = form_dict['fields'][name]['initial'] + # Remove the coerce key from the field, it will not be used + if form_dict['fields'][name].get('coerce'): + form_dict['fields'][name].pop('coerce') + initial_data[name] = form_dict['fields'][name]['initial'] if self.form.data: form_dict['data'] = self.form.data else: form_dict['data'] = initial_data - + print(form_dict) return resolve_promise(form_dict) diff --git a/django_remote_forms/utils.py b/django_remote_forms/utils.py index cc47c2a..b380bfd 100644 --- a/django_remote_forms/utils.py +++ b/django_remote_forms/utils.py @@ -1,11 +1,14 @@ from django.utils.functional import Promise from django.utils.encoding import force_text +from django.forms.models import ModelChoiceIteratorValue def resolve_promise(o): if isinstance(o, dict): for k, v in o.items(): o[k] = resolve_promise(v) + if isinstance(o[k], ModelChoiceIteratorValue): + o[k] = getattr(o[k], 'value') elif isinstance(o, (list, tuple)): o = [resolve_promise(x) for x in o] elif isinstance(o, Promise): From c6f0cabbb4f6d3fe1c7db036060e8344fbf5a6da Mon Sep 17 00:00:00 2001 From: GabrielTaufer Date: Mon, 12 Oct 2020 13:52:40 -0300 Subject: [PATCH 05/20] Add model and APP name to RemoteModelChoiceField --- django_remote_forms/fields.py | 17 +++++++++++++++-- django_remote_forms/forms.py | 5 ++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/django_remote_forms/fields.py b/django_remote_forms/fields.py index e27170e..ad6ac74 100644 --- a/django_remote_forms/fields.py +++ b/django_remote_forms/fields.py @@ -175,7 +175,6 @@ def as_dict(self): class RemoteChoiceField(RemoteField): def as_dict(self): field_dict = super(RemoteChoiceField, self).as_dict() - field_dict['choices'] = [] for key, value in self.field.choices: field_dict['choices'].append({ @@ -188,7 +187,21 @@ def as_dict(self): class RemoteModelChoiceField(RemoteChoiceField): def as_dict(self): - return super(RemoteModelChoiceField, self).as_dict() + form_as_dict = super(RemoteModelChoiceField, self).as_dict() + + field = self.__dict__.get('field', {}) + if hasattr(field, '_queryset'): + queryset = self.__dict__['field'].__dict__['_queryset'] + model = queryset.model() + app_name = model.app_name if hasattr(model, 'app_name') else None + model_name = model.model_name if hasattr(model, 'model_name') else None + + form_as_dict.update({ + 'app_name' : app_name, + 'model_name' : model_name, + }) + + return form_as_dict class RemoteTypedChoiceField(RemoteChoiceField): diff --git a/django_remote_forms/forms.py b/django_remote_forms/forms.py index 6087373..ae5a796 100644 --- a/django_remote_forms/forms.py +++ b/django_remote_forms/forms.py @@ -124,8 +124,7 @@ def as_dict(self): initial_data = {} - for name, field in [(x, self.form.fields[x]) for x in self.fields]: - print(' ', name, field) + for name, field in [(x, self.form.fields[x]) for x in self.fields]: # Retrieve the initial data from the form itself if it exists so # that we properly handle which initial data should be returned in # the dictionary. @@ -165,5 +164,5 @@ def as_dict(self): form_dict['data'] = self.form.data else: form_dict['data'] = initial_data - print(form_dict) + return resolve_promise(form_dict) From 9470a8c62e74a35c64efe14e9746bb4d67340a9e Mon Sep 17 00:00:00 2001 From: GabrielTaufer Date: Wed, 4 Nov 2020 22:47:13 -0300 Subject: [PATCH 06/20] Fix form FKs translation --- django_remote_forms/fields.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/django_remote_forms/fields.py b/django_remote_forms/fields.py index ad6ac74..ce6595f 100644 --- a/django_remote_forms/fields.py +++ b/django_remote_forms/fields.py @@ -6,6 +6,7 @@ from django_remote_forms import logger, widgets +from django.utils.translation import gettext as _ class RemoteField(object): """ @@ -28,7 +29,7 @@ def as_dict(self): field_dict = OrderedDict() field_dict['title'] = self.field.__class__.__name__ field_dict['required'] = self.field.required - field_dict['label'] = self.field.label + field_dict['label'] = _(' '.join(list(map(lambda x: x.capitalize(), self.field.label.split(' '))))) field_dict['initial'] = self.form_initial_data or self.field.initial field_dict['help_text'] = self.field.help_text @@ -125,6 +126,7 @@ def as_dict(self): class RemoteDateTimeField(RemoteTimeField): def as_dict(self): + print('RemoteDateTimeField') return super(RemoteDateTimeField, self).as_dict() From 12154301e85c88d1177bdce9a00f6b7500b7b34e Mon Sep 17 00:00:00 2001 From: GabrielTaufer Date: Thu, 5 Nov 2020 22:00:31 -0300 Subject: [PATCH 07/20] Add new model instance treatment on resolve_promise function --- django_remote_forms/utils.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/django_remote_forms/utils.py b/django_remote_forms/utils.py index b380bfd..af30401 100644 --- a/django_remote_forms/utils.py +++ b/django_remote_forms/utils.py @@ -1,7 +1,7 @@ from django.utils.functional import Promise from django.utils.encoding import force_text from django.forms.models import ModelChoiceIteratorValue - +from django.db import models def resolve_promise(o): if isinstance(o, dict): @@ -22,5 +22,9 @@ def resolve_promise(o): raise Exception('Unable to resolve lazy object %s' % o) elif callable(o): o = o() - + elif isinstance(o, models.Model): # New treatment for models instances, return the model instance id + try: + o = o.id + except Exception as e: + print(e) return o From c18c28902d6df94744026f20c202b2c4bf769d76 Mon Sep 17 00:00:00 2001 From: Lucas Soranzo Date: Tue, 15 Dec 2020 21:53:23 -0300 Subject: [PATCH 08/20] Implement field subclass possibility --- django_remote_forms/fields.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/django_remote_forms/fields.py b/django_remote_forms/fields.py index ad6ac74..572de8e 100644 --- a/django_remote_forms/fields.py +++ b/django_remote_forms/fields.py @@ -37,6 +37,9 @@ def as_dict(self): # Instantiate the Remote Forms equivalent of the widget if possible # in order to retrieve the widget contents as a dictionary. remote_widget_class_name = 'Remote%s' % self.field.widget.__class__.__name__ + if hasattr(self.field.widget, 'parent_class'): + remote_widget_class_name = 'Remote%s' % self.field.widget.parent_class + try: remote_widget_class = getattr(widgets, remote_widget_class_name) remote_widget = remote_widget_class(self.field.widget, field_name=self.field_name) @@ -48,6 +51,9 @@ def as_dict(self): field_dict['widget'] = widget_dict + if hasattr(self.field.widget, 'input_type'): + field_dict['widget']['input_type'] = self.field.widget.input_type + return field_dict @@ -223,7 +229,21 @@ def as_dict(self): class RemoteModelMultipleChoiceField(RemoteMultipleChoiceField): def as_dict(self): - return super(RemoteModelMultipleChoiceField, self).as_dict() + form_as_dict = super(RemoteModelMultipleChoiceField, self).as_dict() + + field = self.__dict__.get('field', {}) + if hasattr(field, '_queryset'): + queryset = self.__dict__['field'].__dict__['_queryset'] + model = queryset.model() + app_name = model.app_name if hasattr(model, 'app_name') else None + model_name = model.model_name if hasattr(model, 'model_name') else None + + form_as_dict.update({ + 'app_name' : app_name, + 'model_name' : model_name, + }) + + return form_as_dict class RemoteTypedMultipleChoiceField(RemoteMultipleChoiceField): From 0f112572d1202bcf0c91661dfefd099294fb8e33 Mon Sep 17 00:00:00 2001 From: Lucas Soranzo Date: Mon, 21 Dec 2020 20:49:19 -0300 Subject: [PATCH 09/20] Add aditional props to the default widget --- django_remote_forms/fields.py | 11 +---------- django_remote_forms/widgets.py | 25 +++++++++++++++++-------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/django_remote_forms/fields.py b/django_remote_forms/fields.py index 9d15287..c8c62c5 100644 --- a/django_remote_forms/fields.py +++ b/django_remote_forms/fields.py @@ -181,16 +181,7 @@ def as_dict(self): class RemoteChoiceField(RemoteField): - def as_dict(self): - field_dict = super(RemoteChoiceField, self).as_dict() - field_dict['choices'] = [] - for key, value in self.field.choices: - field_dict['choices'].append({ - 'value': key, - 'display': value - }) - - return field_dict + pass class RemoteModelChoiceField(RemoteChoiceField): diff --git a/django_remote_forms/widgets.py b/django_remote_forms/widgets.py index d66a3fb..089128e 100644 --- a/django_remote_forms/widgets.py +++ b/django_remote_forms/widgets.py @@ -18,6 +18,22 @@ def as_dict(self): widget_dict['is_required'] = self.widget.is_required widget_dict['attrs'] = self.widget.attrs + if hasattr(self.widget, 'related_field'): + widget_dict['related_field'] = self.widget.related_field + + if hasattr(self.widget, 'choices'): + widget_dict['choices'] = [] + for key, value, *data in self.widget.choices: + complementary_data = {} + if len(data) and type(data[0]) is dict: + complementary_data = data[0] + + widget_dict['choices'].append(dict( + **complementary_data, + value = key, + display = value + )) + return widget_dict @@ -166,13 +182,6 @@ class RemoteSelect(RemoteWidget): def as_dict(self): widget_dict = super(RemoteSelect, self).as_dict() - widget_dict['choices'] = [] - for key, value in self.widget.choices: - widget_dict['choices'].append({ - 'value': key, - 'display': value - }) - widget_dict['input_type'] = 'select' return widget_dict @@ -188,7 +197,7 @@ def as_dict(self): widget_dict = super(RemoteSelectMultiple, self).as_dict() widget_dict['input_type'] = 'selectmultiple' - widget_dict['size'] = len(widget_dict['choices']) + widget_dict['size'] = len(widget_dict.get('choices', [])) return widget_dict From 24a992b90467536c6b00084846aae2df993097e6 Mon Sep 17 00:00:00 2001 From: Lucas Soranzo Date: Sun, 7 Feb 2021 11:17:17 -0300 Subject: [PATCH 10/20] Update fileinput initial value --- django_remote_forms/fields.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/django_remote_forms/fields.py b/django_remote_forms/fields.py index c8c62c5..ccba2b2 100644 --- a/django_remote_forms/fields.py +++ b/django_remote_forms/fields.py @@ -29,7 +29,7 @@ def as_dict(self): field_dict = OrderedDict() field_dict['title'] = self.field.__class__.__name__ field_dict['required'] = self.field.required - field_dict['label'] = _(' '.join(list(map(lambda x: x.capitalize(), self.field.label.split(' '))))) + field_dict['label'] = _(self.field.label) field_dict['initial'] = self.form_initial_data or self.field.initial field_dict['help_text'] = self.field.help_text @@ -132,7 +132,6 @@ def as_dict(self): class RemoteDateTimeField(RemoteTimeField): def as_dict(self): - print('RemoteDateTimeField') return super(RemoteDateTimeField, self).as_dict() @@ -156,6 +155,7 @@ def as_dict(self): field_dict = super(RemoteFileField, self).as_dict() field_dict['max_length'] = self.field.max_length + field_dict['initial'] = str(field_dict['initial']) return field_dict From f2d8510e8b10f812578ebcb2ef8f5df3094c922b Mon Sep 17 00:00:00 2001 From: Lucas Soranzo Date: Sun, 7 Feb 2021 13:40:41 -0300 Subject: [PATCH 11/20] Adjust initial on filefield --- django_remote_forms/fields.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/django_remote_forms/fields.py b/django_remote_forms/fields.py index ccba2b2..7f64c91 100644 --- a/django_remote_forms/fields.py +++ b/django_remote_forms/fields.py @@ -155,7 +155,7 @@ def as_dict(self): field_dict = super(RemoteFileField, self).as_dict() field_dict['max_length'] = self.field.max_length - field_dict['initial'] = str(field_dict['initial']) + field_dict['initial'] = str(field_dict['initial']) if field_dict['initial'] is not None else None return field_dict From 51fb4057501e41d452b1e4570266aa6126c6eeeb Mon Sep 17 00:00:00 2001 From: gabriel-taufer Date: Sat, 5 Jun 2021 13:06:10 -0300 Subject: [PATCH 12/20] fix(datetime-input): fix datetime input field format logic --- django_remote_forms/fields.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/django_remote_forms/fields.py b/django_remote_forms/fields.py index 7f64c91..a483192 100644 --- a/django_remote_forms/fields.py +++ b/django_remote_forms/fields.py @@ -110,14 +110,15 @@ def as_dict(self): field_dict['initial'] = field_dict['initial']() # If initial value is datetime then convert it using first available input format + if (isinstance(field_dict['initial'], (datetime.datetime, datetime.time, datetime.date))): if not getattr(field_dict['input_formats'], 'len', None): - if isinstance(field_dict['initial'], datetime.date): + if isinstance(field_dict['initial'], datetime.datetime): + field_dict['input_formats'] = settings.DATETIME_INPUT_FORMATS + elif isinstance(field_dict['initial'], datetime.date): field_dict['input_formats'] = settings.DATE_INPUT_FORMATS elif isinstance(field_dict['initial'], datetime.time): field_dict['input_formats'] = settings.TIME_INPUT_FORMATS - elif isinstance(field_dict['initial'], datetime.datetime): - field_dict['input_formats'] = settings.DATETIME_INPUT_FORMATS input_format = field_dict['input_formats'][0] field_dict['initial'] = field_dict['initial'].strftime(input_format) From 170a309e30da267a056a998b92efb1e0b61e4756 Mon Sep 17 00:00:00 2001 From: Lucas Soranzo Date: Wed, 18 Aug 2021 22:20:41 -0300 Subject: [PATCH 13/20] Widget choices crash hotfix --- django_remote_forms/widgets.py | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/django_remote_forms/widgets.py b/django_remote_forms/widgets.py index 089128e..35883ef 100644 --- a/django_remote_forms/widgets.py +++ b/django_remote_forms/widgets.py @@ -22,17 +22,22 @@ def as_dict(self): widget_dict['related_field'] = self.widget.related_field if hasattr(self.widget, 'choices'): - widget_dict['choices'] = [] - for key, value, *data in self.widget.choices: - complementary_data = {} - if len(data) and type(data[0]) is dict: - complementary_data = data[0] - - widget_dict['choices'].append(dict( - **complementary_data, - value = key, - display = value - )) + widget_dict['choices'] = widget_dict.get('choices', []) + if type(self.widget.choices) is list: + for key, value, *data in self.widget.choices: + complementary_data = {} + if len(data) and type(data[0]) is dict: + complementary_data = data[0] + + widget_dict['choices'].append(dict( + **complementary_data, + value = key, + display = value + )) + else: + print(f"Choices expect a list but received {type(self.widget.choices)}") + widget_dict['choices'] = [] + self.widget.choices = [] return widget_dict From b8ff0123dc78353d75aa8adf325c478a4fa78212 Mon Sep 17 00:00:00 2001 From: Lucas Soranzo Date: Sun, 5 Sep 2021 09:11:39 -0300 Subject: [PATCH 14/20] Fix for tuples on widget choices --- django_remote_forms/widgets.py | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/django_remote_forms/widgets.py b/django_remote_forms/widgets.py index 35883ef..7b35bcc 100644 --- a/django_remote_forms/widgets.py +++ b/django_remote_forms/widgets.py @@ -24,21 +24,26 @@ def as_dict(self): if hasattr(self.widget, 'choices'): widget_dict['choices'] = widget_dict.get('choices', []) if type(self.widget.choices) is list: - for key, value, *data in self.widget.choices: - complementary_data = {} - if len(data) and type(data[0]) is dict: - complementary_data = data[0] - - widget_dict['choices'].append(dict( - **complementary_data, - value = key, - display = value - )) + self.widget.choices = self.widget.choices + elif type(self.widget.choices) is tuple: + self.widget.choices = list(self.widget.choices) else: - print(f"Choices expect a list but received {type(self.widget.choices)}") + print(self.widget.choices) + print(f"Unable to parse type {type(self.widget.choices)} for widget choices") widget_dict['choices'] = [] self.widget.choices = [] + for key, value, *data in self.widget.choices: + complementary_data = {} + if len(data) and type(data[0]) is dict: + complementary_data = data[0] + + widget_dict['choices'].append(dict( + **complementary_data, + value = key, + display = value + )) + return widget_dict From 8401260947f6b85eae298dfac9de31be56d0058c Mon Sep 17 00:00:00 2001 From: Lucas Soranzo Date: Sun, 12 Mar 2023 15:15:31 -0300 Subject: [PATCH 15/20] Hotfix for initial value on float field --- django_remote_forms/fields.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/django_remote_forms/fields.py b/django_remote_forms/fields.py index a483192..42a80d4 100644 --- a/django_remote_forms/fields.py +++ b/django_remote_forms/fields.py @@ -25,12 +25,15 @@ def __init__(self, field, form_initial_data=None, field_name=None): self.field = field self.form_initial_data = form_initial_data + def initial(self): + return self.form_initial_data or self.field.initial + def as_dict(self): field_dict = OrderedDict() field_dict['title'] = self.field.__class__.__name__ field_dict['required'] = self.field.required field_dict['label'] = _(self.field.label) - field_dict['initial'] = self.form_initial_data or self.field.initial + field_dict['initial'] = self.initial field_dict['help_text'] = self.field.help_text field_dict['error_messages'] = self.field.error_messages @@ -83,6 +86,11 @@ def as_dict(self): class RemoteFloatField(RemoteIntegerField): + def initial(self): + if type(self.form_initial_data) == 'float': + return self.form_initial_data + return self.field.initial + def as_dict(self): return super(RemoteFloatField, self).as_dict() From b5748bae05f942a6b27f66facde8856ddc9b75ec Mon Sep 17 00:00:00 2001 From: Lucas Soranzo Date: Sun, 12 Mar 2023 15:39:59 -0300 Subject: [PATCH 16/20] Hotfix for initial value on float field --- django_remote_forms/fields.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/django_remote_forms/fields.py b/django_remote_forms/fields.py index 42a80d4..880fb9c 100644 --- a/django_remote_forms/fields.py +++ b/django_remote_forms/fields.py @@ -25,6 +25,7 @@ def __init__(self, field, form_initial_data=None, field_name=None): self.field = field self.form_initial_data = form_initial_data + @property def initial(self): return self.form_initial_data or self.field.initial @@ -86,6 +87,7 @@ def as_dict(self): class RemoteFloatField(RemoteIntegerField): + @property def initial(self): if type(self.form_initial_data) == 'float': return self.form_initial_data From 4dd632da65bd0e41aa90a1891b181d84f6ab7f32 Mon Sep 17 00:00:00 2001 From: Lucas Soranzo Date: Sun, 12 Mar 2023 15:45:22 -0300 Subject: [PATCH 17/20] Hotfix for initial value on float field --- django_remote_forms/fields.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/django_remote_forms/fields.py b/django_remote_forms/fields.py index 880fb9c..bcd6485 100644 --- a/django_remote_forms/fields.py +++ b/django_remote_forms/fields.py @@ -89,7 +89,7 @@ def as_dict(self): class RemoteFloatField(RemoteIntegerField): @property def initial(self): - if type(self.form_initial_data) == 'float': + if type(self.form_initial_data) == float: return self.form_initial_data return self.field.initial From df88dffa759f3bd084a5321b0ec26638692d3b2c Mon Sep 17 00:00:00 2001 From: Gabriel Taufer Date: Mon, 6 May 2024 10:34:00 -0300 Subject: [PATCH 18/20] fix: adjust remote form field validation for input_format logic so it does not override the field configuration --- django_remote_forms/fields.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/django_remote_forms/fields.py b/django_remote_forms/fields.py index bcd6485..d082a53 100644 --- a/django_remote_forms/fields.py +++ b/django_remote_forms/fields.py @@ -122,7 +122,8 @@ def as_dict(self): # If initial value is datetime then convert it using first available input format if (isinstance(field_dict['initial'], (datetime.datetime, datetime.time, datetime.date))): - if not getattr(field_dict['input_formats'], 'len', None): + has_input_formats = len(field_dict.get('input_formats', [])) > 0 + if not has_input_formats: if isinstance(field_dict['initial'], datetime.datetime): field_dict['input_formats'] = settings.DATETIME_INPUT_FORMATS elif isinstance(field_dict['initial'], datetime.date): From cf40abb0bbfb7dc8fb2a20c387f490a02f56f2a8 Mon Sep 17 00:00:00 2001 From: Gabriel Taufer Date: Tue, 7 May 2024 08:46:40 -0300 Subject: [PATCH 19/20] fix: adjust remote form field validation for input_format logic so it does not override the field configuration --- django_remote_forms/fields.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/django_remote_forms/fields.py b/django_remote_forms/fields.py index d082a53..9321cc4 100644 --- a/django_remote_forms/fields.py +++ b/django_remote_forms/fields.py @@ -122,13 +122,19 @@ def as_dict(self): # If initial value is datetime then convert it using first available input format if (isinstance(field_dict['initial'], (datetime.datetime, datetime.time, datetime.date))): - has_input_formats = len(field_dict.get('input_formats', [])) > 0 + # Hotfix to check input formats + input_formats = field_dict.get('input_formats', []) + try: + has_input_formats = input_formats[0] is not None + except Exception as _: + has_input_formats = False + if not has_input_formats: if isinstance(field_dict['initial'], datetime.datetime): field_dict['input_formats'] = settings.DATETIME_INPUT_FORMATS elif isinstance(field_dict['initial'], datetime.date): field_dict['input_formats'] = settings.DATE_INPUT_FORMATS - elif isinstance(field_dict['initial'], datetime.time): + elif isinstance(field_dict['initial'], datetime.time):atetimeformat field_dict['input_formats'] = settings.TIME_INPUT_FORMATS input_format = field_dict['input_formats'][0] From 3ee3c056afcf9fa98046b66677bd83fe1181b68e Mon Sep 17 00:00:00 2001 From: Gabriel Taufer Date: Tue, 7 May 2024 09:10:57 -0300 Subject: [PATCH 20/20] fix: remove line that was mispasted --- django_remote_forms/fields.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/django_remote_forms/fields.py b/django_remote_forms/fields.py index 9321cc4..d6de00d 100644 --- a/django_remote_forms/fields.py +++ b/django_remote_forms/fields.py @@ -134,7 +134,7 @@ def as_dict(self): field_dict['input_formats'] = settings.DATETIME_INPUT_FORMATS elif isinstance(field_dict['initial'], datetime.date): field_dict['input_formats'] = settings.DATE_INPUT_FORMATS - elif isinstance(field_dict['initial'], datetime.time):atetimeformat + elif isinstance(field_dict['initial'], datetime.time): field_dict['input_formats'] = settings.TIME_INPUT_FORMATS input_format = field_dict['input_formats'][0]