-
-
Notifications
You must be signed in to change notification settings - Fork 143
Add support for dynamic setting of attributes from context based on #151 #152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -215,11 +215,25 @@ def render(self, context): | |||||
bounded_field = append_attr( | ||||||
bounded_field, f"class:{context['WIDGET_REQUIRED_CLASS']}" | ||||||
) | ||||||
attr_dict = {} | ||||||
for k, v in self.set_attrs: | ||||||
if k == "type": | ||||||
bounded_field.field.widget.input_type = v.resolve(context) | ||||||
if k == "attr_dict": | ||||||
resolved_dict = v.resolve(context) | ||||||
if not isinstance(resolved_dict, dict): | ||||||
raise ValueError(f"{k} must be of type dict.") | ||||||
attr_dict.update(resolved_dict) | ||||||
else: | ||||||
bounded_field = set_attr(bounded_field, f"{k}:{v.resolve(context)}") | ||||||
attr_dict[k] = v.resolve(context) | ||||||
for k, v in attr_dict.items(): | ||||||
if v: | ||||||
if isinstance(v, bool): | ||||||
bounded_field = set_attr(bounded_field, f"{k}") | ||||||
if k == "type": | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current conditional structure may result in duplicate attribute assignments for non-'type' keys with boolean values. Consider restructuring the conditionals using if-elif-else to ensure that each attribute is processed only once.
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
bounded_field.field.widget.input_type = v | ||||||
else: | ||||||
bounded_field = set_attr(bounded_field, f"{k}:{v}") | ||||||
else: | ||||||
bounded_field = remove_attr(bounded_field, k) | ||||||
for k, v in self.append_attrs: | ||||||
bounded_field = append_attr(bounded_field, f"{k}:{v.resolve(context)}") | ||||||
return str(bounded_field) | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this correct? If this is a Python dict then shouldn't it be: