profile
viewpoint
If you are wondering where the data of this site comes from, please visit https://api.github.com/users/JimiRecard/events. GitMemory does not store any data, but only uses NGINX to cache data for a period of time. The idea behind GitMemory is simply to give users a better reading experience.

JimiRecard/crispy-bootstrap5 0

Bootstrap5 template pack for django-crispy-forms

JimiRecard/DadoFrase 0

Senhas seguras com alta entropia e fáceis de memorizar

issue closeddjango-crispy-forms/crispy-bootstrap5

Fix checkbox in table_inline_formset

Checkboxes are not rendering correctly in formsets using the table_inline_formset.html template.

Current behavior: image

Expected behavior: image

Note that some checkboxes are actually checked on the first image. The issue seems to be on the field.html template. Will investigate this further and possibly propose a PR

closed time in 20 days

JimiRecard

issue commentdjango-crispy-forms/crispy-bootstrap5

Fix checkbox in table_inline_formset

I'm checking the closed PRs, and I believe you fixed it indeed 😅. I'll close the issue

JimiRecard

comment created time in 20 days

issue commentdjango-crispy-forms/crispy-bootstrap5

Fix checkbox in table_inline_formset

It's possible. This was tested with the latest release available through pip, 4.0

JimiRecard

comment created time in 20 days

issue openeddjango-crispy-forms/crispy-bootstrap5

Fix checkbox in table_inline_formset

Checkboxes are not rendering correctly in formsets ussing the table_inline_formset.html template.

Current behavior: image

Expected behavior: image

Note that some checkboxes are actually checked on the first image. The issue seems to be on the field.html template. Will investigate this further and possibly propose a PR

created time in 20 days

push eventJimiRecard/crispy-bootstrap5

JimiRecard

commit sha 9bff35542499e6148ffdb393ad593195fd4ee268

Remove 'settings' from test functions when not used (#72)

view details

push time in a month

delete branch JimiRecard/crispy-bootstrap5

delete branch : remove-settings-from-tests

delete time in a month

PR opened django-crispy-forms/crispy-bootstrap5

Remove 'settings' from test functions when not used

Took me long enough. Minor cleaning of the code. As discussed in #63.

+15 -15

0 comment

4 changed files

pr created time in a month

create barnchJimiRecard/crispy-bootstrap5

branch : remove-settings-from-tests

created branch time in a month

fork JimiRecard/crispy-bootstrap5

Bootstrap5 template pack for django-crispy-forms

fork in a month

issue closeddjango-crispy-forms/crispy-bootstrap5

Add support for accordion-flush

Bootstrap5 introduced "accordion-flush" html class, which basically removes borders and rounding from accordions.

This could be added by creating an AccordionFlush python class at bootstrap.py and an accordion-flush.html layout.

Alternatively, the Accordion python class could be modified in order to accept an optional "accordion-flush" css class on the template, since it's the only difference from a standard accordion. I think this solution might be the more elegant one.

I'll try to work it out and propose a PR

closed time in 2 months

JimiRecard

delete branch JimiRecard/crispy-bootstrap5

delete branch : accordion-flush

delete time in 2 months

PullRequestReviewEvent

Pull request review commentdjango-crispy-forms/crispy-bootstrap5

Add support for accordion-flush and accordion always open

 class FloatingField(Field):     def __init__(self, *args, **kwargs):         super().__init__(*args, **kwargs)         self.attrs["placeholder"] = self.fields[0]+++class BS5Accordion(Accordion):+    """+    Bootstrap5 Accordion menu object. It wraps `BS5AccordionGroup` objects in a+    container. It also allows the usage of accordion-flush, introduced in bootstrap5::++        BS5Accordion(+            BS5AccordionGroup("group name", "form_field_1", "form_field_2"),+            BS5AccordionGroup("another group name", "form_field"),+            flush=True,+            always_open=True+        )+    """++    def __init__(self, *args, **kwargs):+        super().__init__(*args, **kwargs)+        self.flush = kwargs.pop("flush", False)+        self.always_open = kwargs.pop("always_open", False)++        if self.always_open:+            for accordion_group in args:

Thanks for explaining! I think you're right, self.fields seems more readable to me as well.

JimiRecard

comment created time in 2 months

push eventJimiRecard/crispy-bootstrap5

JimiRecard

commit sha f23f8f5e2b9e6776d875398053521cac1e60c576

Added note introducing BS5Accordion

view details

push time in 2 months

push eventJimiRecard/crispy-bootstrap5

JimiRecard

commit sha 836fbfd19173d5bce0e47b5fa2d8fbf309dda511

BS5AccordionGroup no longer necessary. self.fields instead of args.

view details

push time in 2 months

pull request commentdjango-crispy-forms/crispy-bootstrap5

Add support for accordion-flush and accordion always open

Would you like to add a small note to the readme to document the new feature in this template pack?

Of course! I'll follow the floating labels note style

JimiRecard

comment created time in 2 months

Pull request review commentdjango-crispy-forms/crispy-bootstrap5

Add support for accordion-flush and accordion always open

 class FloatingField(Field):     def __init__(self, *args, **kwargs):         super().__init__(*args, **kwargs)         self.attrs["placeholder"] = self.fields[0]+++class BS5Accordion(Accordion):+    """+    Bootstrap5 Accordion menu object. It wraps `BS5AccordionGroup` objects in a+    container. It also allows the usage of accordion-flush, introduced in bootstrap5::++        BS5Accordion(+            BS5AccordionGroup("group name", "form_field_1", "form_field_2"),+            BS5AccordionGroup("another group name", "form_field"),+            flush=True,+            always_open=True+        )+    """++    def __init__(self, *args, **kwargs):+        super().__init__(*args, **kwargs)+        self.flush = kwargs.pop("flush", False)+        self.always_open = kwargs.pop("always_open", False)++        if self.always_open:+            for accordion_group in args:+                accordion_group.always_open = True+++class BS5AccordionGroup(AccordionGroup):

Good catch!

JimiRecard

comment created time in 2 months

PullRequestReviewEvent

Pull request review commentdjango-crispy-forms/crispy-bootstrap5

Add support for accordion-flush and accordion always open

 class FloatingField(Field):     def __init__(self, *args, **kwargs):         super().__init__(*args, **kwargs)         self.attrs["placeholder"] = self.fields[0]+++class BS5Accordion(Accordion):+    """+    Bootstrap5 Accordion menu object. It wraps `BS5AccordionGroup` objects in a+    container. It also allows the usage of accordion-flush, introduced in bootstrap5::++        BS5Accordion(+            BS5AccordionGroup("group name", "form_field_1", "form_field_2"),+            BS5AccordionGroup("another group name", "form_field"),+            flush=True,+            always_open=True+        )+    """++    def __init__(self, *args, **kwargs):+        super().__init__(*args, **kwargs)+        self.flush = kwargs.pop("flush", False)+        self.always_open = kwargs.pop("always_open", False)++        if self.always_open:+            for accordion_group in args:

self.fields works. I'll pathc it

Would you shed some light on this if you can? In the original Accordion class both are used, args in the super().__init__() and self.fields in the render() function. I went with args because I'm also writing code in the super().__init__() method.

What is the difference? Both seem to do the same thing for me 🤔

JimiRecard

comment created time in 2 months

PullRequestReviewEvent

push eventJimiRecard/crispy-bootstrap5

JimiRecard

commit sha 493954cdc8ebb6193ab6fc5a2eb0ea41a2aa876c

BS5AccordionGroup Co-authored-by: David Smith <39445562+smithdc1@users.noreply.github.com>

view details

push time in 2 months

Pull request review commentdjango-crispy-forms/crispy-bootstrap5

Add support for accordion-flush and accordion always open

 def test_accordion_active_false_not_rendered(self, settings):             == 0         ) +    def test_accordion_flush(self, settings):+        test_form = SampleForm()+        test_form.helper = FormHelper()+        test_form.helper.layout = Layout(+            Accordion(+                AccordionGroup("one", "first_name")+                # there is no ``flush`` kwarg here.+            )+        )++        html = render_crispy_form(test_form)++        # Since the default is False, there shouldn't be an accordion-flush class now.+        assert html.count('<div class="accordion accordion-flush" id="accordion-') == 0++        test_form.helper.layout = Layout(+            Accordion(+                AccordionGroup("one", "first_name"), flush=True+            )  # now ``flush`` manually set as True+        )++        # We expect the class to be present now.+        html = render_crispy_form(test_form)+        assert html.count('<div class="accordion accordion-flush" id="accordion-') == 1++    def test_accordion_always_open(self, settings):+        test_form = SampleForm()+        test_form.helper = FormHelper()+        test_form.helper.layout = Layout(+            Accordion(+                AccordionGroup("one", "first_name"),+                AccordionGroup("two", "last_name")+                # No always_open kwargs. Default is False.+            )+        )++        html = render_crispy_form(test_form)++        # Since the default is False, there should two accounts for data-bs-parent+        assert html.count('data-bs-parent="#accordion-') == 2++        test_form.helper.layout = Layout(+            Accordion(+                AccordionGroup("one", "first_name", always_open=True),+                AccordionGroup("two", "last_name", always_open=True)

Great. I'll make the necessary changes later today. Do you think it's better to close this PR and open another with less commits?

JimiRecard

comment created time in 2 months

PullRequestReviewEvent
PullRequestReviewEvent

Pull request review commentdjango-crispy-forms/crispy-bootstrap5

Add support for accordion-flush and accordion always open

 def test_accordion_active_false_not_rendered(self, settings):             == 0         ) +    def test_bs5accordion_and_bs5accordiongroup(self, settings):

Yeah, I had no idea why settings was an arg, but it didn't seem broke so I didn't fix 😅

And if you think my tests are shameless copies of the preexisting ones, you're absolutely right! 😂 Should I remove it from those tests? And while we're on it, might as well remove from other tests that aren't using it?

JimiRecard

comment created time in 2 months

Pull request review commentdjango-crispy-forms/crispy-bootstrap5

Add support for accordion-flush and accordion always open

 def test_accordion_active_false_not_rendered(self, settings):             == 0         ) +    def test_accordion_flush(self, settings):+        test_form = SampleForm()+        test_form.helper = FormHelper()+        test_form.helper.layout = Layout(+            Accordion(+                AccordionGroup("one", "first_name")+                # there is no ``flush`` kwarg here.+            )+        )++        html = render_crispy_form(test_form)++        # Since the default is False, there shouldn't be an accordion-flush class now.+        assert html.count('<div class="accordion accordion-flush" id="accordion-') == 0++        test_form.helper.layout = Layout(+            Accordion(+                AccordionGroup("one", "first_name"), flush=True+            )  # now ``flush`` manually set as True+        )++        # We expect the class to be present now.+        html = render_crispy_form(test_form)+        assert html.count('<div class="accordion accordion-flush" id="accordion-') == 1++    def test_accordion_always_open(self, settings):+        test_form = SampleForm()+        test_form.helper = FormHelper()+        test_form.helper.layout = Layout(+            Accordion(+                AccordionGroup("one", "first_name"),+                AccordionGroup("two", "last_name")+                # No always_open kwargs. Default is False.+            )+        )++        html = render_crispy_form(test_form)++        # Since the default is False, there should two accounts for data-bs-parent+        assert html.count('data-bs-parent="#accordion-') == 2++        test_form.helper.layout = Layout(+            Accordion(+                AccordionGroup("one", "first_name", always_open=True),+                AccordionGroup("two", "last_name", always_open=True)

I'm not sure. I personally can't imagine myself using this on just a few panels, but I have to imagine someone would. If a user decides to write all their HTML by hand, this would be a possibility.

In contrast, accordion-flush is all or nothing from the HTML. You can't flush a single panel. But you can "always open" a single panel (for whatever reason), since it's a panel behavior, not an accordion behavior.

So I guess we're down to deciding if we're going to favour ease of use or fidelity to the framework's (bootstrap) intended use. I'm inclined for going the ease of use case, as you suggested. Just let me know and I'll work on the changes ✌️

JimiRecard

comment created time in 2 months

PullRequestReviewEvent
PullRequestReviewEvent

Pull request review commentdjango-crispy-forms/crispy-bootstrap5

Add support for accordion-flush and accordion always open

 class FloatingField(Field):     def __init__(self, *args, **kwargs):         super().__init__(*args, **kwargs)         self.attrs["placeholder"] = self.fields[0]+++class Container(Div):+    """+    Base class used for `Tab` and `AccordionGroup`, represents a basic container concept+    """++    css_class = ""++    def __init__(self, name, *fields, **kwargs):+        super().__init__(*fields, **kwargs)+        self.template = kwargs.pop("template", self.template)+        self.name = name+        self._active_originally_included = "active" in kwargs+        self.active = kwargs.pop("active", False)+        self.always_open = kwargs.pop("always_open", False)+        if not self.css_id:+            self.css_id = slugify(self.name)++    def __contains__(self, field_name):+        """+        check if field_name is contained within tab.+        """+        return field_name in map(lambda pointer: pointer[1], self.get_field_names())++    def render(self, form, form_style, context, template_pack=TEMPLATE_PACK, **kwargs):+        if self.active:+            if "active" not in self.css_class:+                self.css_class += " active"+        else:+            self.css_class = self.css_class.replace("active", "")+        return super().render(form, form_style, context, template_pack)+++class ContainerHolder(Div):+    """+    Base class used for `TabHolder` and `Accordion`, groups containers+    """++    def first_container_with_errors(self, errors):+        """+        Returns the first container with errors, otherwise returns None.+        """+        for tab in self.fields:+            errors_here = any(error in tab for error in errors)+            if errors_here:+                return tab+        return None++    def open_target_group_for_form(self, form):+        """+        Makes sure that the first group that should be open is open.+        This is either the first group with errors or the first group+        in the container, unless that first group was originally set to+        active=False.+        """+        target = self.first_container_with_errors(form.errors.keys())+        if target is None:+            target = self.fields[0]+            if not getattr(target, "_active_originally_included", None):+                target.active = True+            return target++        target.active = True+        return target+++class AccordionGroup(Container):+    """+    Accordion Group (pane) object. It wraps given fields inside an accordion+    tab. It takes accordion tab name as first argument::++        AccordionGroup(+            "group name",+            "form_field_1",+            "form_field_2",+            active=True,+            always_open=True+            )+    """++    template = "%s/accordion-group.html"+    data_parent = ""  # accordion parent div id.+++class Accordion(ContainerHolder):

Done! Sorry for the excessive amount of commits and thank you for taking the time to review this

JimiRecard

comment created time in 2 months

push eventJimiRecard/crispy-bootstrap5

JimiRecard

commit sha 8e0a5382683020e9c719d790c6bbc6a4dd025207

(re)Added tests for Accordion and AccordionGroup from crispy_forms.bootstrap

view details

push time in 2 months