This repository has been archived on 2025-09-03. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
Employee-Management-Portal/Lib/site-packages/crispy_forms/tests/utils.py
Alicja Cięciwa cb8886666c login page
2020-10-27 12:57:58 +01:00

23 lines
917 B
Python

from django.test.html import Element, parse_html
def contains_partial(haystack, needle, ignore_needle_children=False):
"""Search for a html element with at least the corresponding elements
(other elements may be present in the matched element from the haystack)
"""
if not isinstance(haystack, Element):
haystack = parse_html(haystack)
if not isinstance(needle, Element):
needle = parse_html(needle)
if len(needle.children) > 0 and not ignore_needle_children:
raise NotImplementedError("contains_partial does not check needle's children:%s" % str(needle.children))
if needle.name == haystack.name and set(needle.attributes).issubset(haystack.attributes):
return True
return any(
contains_partial(child, needle, ignore_needle_children=ignore_needle_children)
for child in haystack.children
if isinstance(child, Element)
)