Fixed weekdays python 3 support, fixed a bug in batch fetch
This commit is contained in:
@@ -54,6 +54,8 @@ class Path(object):
|
|||||||
for entity in entities:
|
for entity in entities:
|
||||||
related_entities.extend(getattr(entity, attrs[0]))
|
related_entities.extend(getattr(entity, attrs[0]))
|
||||||
|
|
||||||
|
if not related_entities:
|
||||||
|
return
|
||||||
subpath = '.'.join(attrs[1:])
|
subpath = '.'.join(attrs[1:])
|
||||||
return Path.parse(related_entities, subpath, populate_backrefs)
|
return Path.parse(related_entities, subpath, populate_backrefs)
|
||||||
else:
|
else:
|
||||||
@@ -146,6 +148,7 @@ def batch_fetch(entities, *attr_paths):
|
|||||||
if entities:
|
if entities:
|
||||||
for path in attr_paths:
|
for path in attr_paths:
|
||||||
fetcher = fetcher_factory(entities, path)
|
fetcher = fetcher_factory(entities, path)
|
||||||
|
if fetcher:
|
||||||
fetcher.fetch()
|
fetcher.fetch()
|
||||||
fetcher.populate()
|
fetcher.populate()
|
||||||
|
|
||||||
@@ -159,13 +162,17 @@ def fetcher_factory(entities, path):
|
|||||||
if isinstance(path, CompositePath):
|
if isinstance(path, CompositePath):
|
||||||
fetchers = []
|
fetchers = []
|
||||||
for path in path.paths:
|
for path in path.paths:
|
||||||
|
path = Path.parse(entities, path, populate_backrefs)
|
||||||
|
if path:
|
||||||
fetchers.append(
|
fetchers.append(
|
||||||
Path.parse(entities, path, populate_backrefs).fetcher
|
path.fetcher
|
||||||
)
|
)
|
||||||
|
|
||||||
return CompositeFetcher(*fetchers)
|
return CompositeFetcher(*fetchers)
|
||||||
else:
|
else:
|
||||||
return Path.parse(entities, path, populate_backrefs).fetcher
|
path = Path.parse(entities, path, populate_backrefs)
|
||||||
|
if path:
|
||||||
|
return path.fetcher
|
||||||
|
|
||||||
|
|
||||||
class CompositeFetcher(object):
|
class CompositeFetcher(object):
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
import six
|
|
||||||
from sqlalchemy import types
|
from sqlalchemy import types
|
||||||
from sqlalchemy.dialects.postgresql import BIT
|
from sqlalchemy.dialects.postgresql import BIT
|
||||||
|
import six
|
||||||
get_day_names = None
|
get_day_names = None
|
||||||
try:
|
try:
|
||||||
from babel.dates import get_day_names
|
from babel.dates import get_day_names
|
||||||
@@ -75,7 +75,7 @@ class WeekDay(object):
|
|||||||
|
|
||||||
class WeekDays(object):
|
class WeekDays(object):
|
||||||
def __init__(self, bit_string_or_week_days):
|
def __init__(self, bit_string_or_week_days):
|
||||||
if isinstance(bit_string_or_week_days, six.text_type):
|
if isinstance(bit_string_or_week_days, six.string_types):
|
||||||
self._days = set()
|
self._days = set()
|
||||||
|
|
||||||
if len(bit_string_or_week_days) != WeekDay.NUM_WEEK_DAYS:
|
if len(bit_string_or_week_days) != WeekDay.NUM_WEEK_DAYS:
|
||||||
@@ -100,7 +100,7 @@ class WeekDays(object):
|
|||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
if isinstance(other, WeekDays):
|
if isinstance(other, WeekDays):
|
||||||
return self._days == other._days
|
return self._days == other._days
|
||||||
elif isinstance(other, six.text_type):
|
elif isinstance(other, six.string_types):
|
||||||
return self.as_bit_string() == other
|
return self.as_bit_string() == other
|
||||||
else:
|
else:
|
||||||
return NotImplemented
|
return NotImplemented
|
||||||
@@ -138,7 +138,7 @@ class WeekDaysType(types.TypeDecorator):
|
|||||||
if isinstance(value, WeekDays):
|
if isinstance(value, WeekDays):
|
||||||
return value.as_bit_string()
|
return value.as_bit_string()
|
||||||
|
|
||||||
if isinstance(value, six.text_type):
|
if isinstance(value, six.string_types):
|
||||||
return value
|
return value
|
||||||
|
|
||||||
def process_result_value(self, value, dialect):
|
def process_result_value(self, value, dialect):
|
||||||
|
Reference in New Issue
Block a user