Beispiel #1
0
def test_single_item_multidict(site):
    """Save a single item with multiple values and retrieve it."""
    properties = MultiDict()
    properties["id"] = 1
    properties.setlist("name", ("foo", "bar"))
    site.create("things", properties).save()
    all_items = list(site.search("things"))
    eq_(len(all_items), 1)
    item = all_items[0]
    eq_(item["id"], 1)
    eq_(item["name"], "foo")
    if not isinstance(site.access_points["things"], SINGLE_VALUE_ACCESS_POINTS):
        eq_(item.getlist("name"), ("foo", "bar"))
Beispiel #2
0
    def search(self, request):
        try:
            ldap_request = self._to_ldap_filter(request)
        except ValueError:
            # No LDAP filter can be created, use a software filter
            ldap_request = None

        for _, ldap_result in self.ldap.search_s(
            self.ldap_path, ldap.SCOPE_ONELEVEL, ldap_request or "objectClass=*",
            # Restrict results to declared properties:
            [prop.rdn_name for prop in self.properties.values()]):
            multidict = MultiDict()
            for prop in self.properties.values():
                if prop.relation != "one-to-many":
                    values = (
                        value.decode(self.encoding)
                        for value in ldap_result.get(prop.rdn_name, ()))
                    multidict.setlist(prop.name, tuple(values) or (None,))
            item = self.create(multidict)
            if ldap_request or request.test(item):
                item.saved = True
                yield item