Преглед изворни кода

Move get_filtered to BaseCollection

Unrud пре 7 година
родитељ
комит
979414ce85
2 измењених фајлова са 14 додато и 16 уклоњено
  1. 14 3
      radicale/storage/__init__.py
  2. 0 13
      radicale/storage/multifilesystem.py

+ 14 - 3
radicale/storage/__init__.py

@@ -34,6 +34,7 @@ from importlib import import_module
 import pkg_resources
 import vobject
 
+from radicale.item import filter as radicale_filter
 from radicale.log import logger
 
 INTERNAL_TYPES = ("multifilesystem",)
@@ -204,10 +205,20 @@ class BaseCollection:
         ``filters_matched`` is a bool that indicates if ``filters`` are fully
         matched.
 
-        This returns all events by default
-
         """
-        return ((item, False) for item in self.get_all())
+        tag, start, end, simple = radicale_filter.simplify_prefilters(
+            filters, collection_tag=self.get_meta("tag"))
+        for item in self.get_all():
+            if tag:
+                if tag != item.component_name:
+                    continue
+                istart, iend = item.time_range
+                if istart >= end or iend <= start:
+                    continue
+                item_simple = simple and (start <= istart or iend <= end)
+            else:
+                item_simple = simple
+            yield item, item_simple
 
     def has_uid(self, uid):
         """Check if a UID exists in the collection."""

+ 0 - 13
radicale/storage/multifilesystem.py

@@ -35,7 +35,6 @@ import vobject
 
 from radicale import item as radicale_item
 from radicale import pathutils, storage
-from radicale.item import filter as radicale_filter
 from radicale.log import logger
 
 
@@ -727,18 +726,6 @@ class Collection(storage.BaseCollection):
         # are from os.listdir.
         return (self._get(href, verify_href=False) for href in self._list())
 
-    def get_filtered(self, filters):
-        tag, start, end, simple = radicale_filter.simplify_prefilters(
-            filters, collection_tag=self.get_meta("tag"))
-        if not tag:
-            # no filter
-            yield from ((item, simple) for item in self.get_all())
-            return
-        for item in (self._get(h, verify_href=False) for h in self._list()):
-            istart, iend = item.time_range
-            if tag == item.component_name and istart < end and iend > start:
-                yield item, simple and (start <= istart or iend <= end)
-
     def upload(self, href, item):
         if not pathutils.is_safe_filesystem_path_component(href):
             raise pathutils.UnsafePathError(href)