Fixed weekdays python 3 support, fixed a bug in batch fetch

This commit is contained in:
Konsta Vesterinen
2013-09-17 07:48:51 +03:00
parent f6f0963705
commit e3a8cce8d9
2 changed files with 17 additions and 10 deletions

View File

@@ -54,6 +54,8 @@ class Path(object):
for entity in entities:
related_entities.extend(getattr(entity, attrs[0]))
if not related_entities:
return
subpath = '.'.join(attrs[1:])
return Path.parse(related_entities, subpath, populate_backrefs)
else:
@@ -146,6 +148,7 @@ def batch_fetch(entities, *attr_paths):
if entities:
for path in attr_paths:
fetcher = fetcher_factory(entities, path)
if fetcher:
fetcher.fetch()
fetcher.populate()
@@ -159,13 +162,17 @@ def fetcher_factory(entities, path):
if isinstance(path, CompositePath):
fetchers = []
for path in path.paths:
path = Path.parse(entities, path, populate_backrefs)
if path:
fetchers.append(
Path.parse(entities, path, populate_backrefs).fetcher
path.fetcher
)
return CompositeFetcher(*fetchers)
else:
return Path.parse(entities, path, populate_backrefs).fetcher
path = Path.parse(entities, path, populate_backrefs)
if path:
return path.fetcher
class CompositeFetcher(object):

View File

@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
import six
from sqlalchemy import types
from sqlalchemy.dialects.postgresql import BIT
import six
get_day_names = None
try:
from babel.dates import get_day_names
@@ -75,7 +75,7 @@ class WeekDay(object):
class WeekDays(object):
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()
if len(bit_string_or_week_days) != WeekDay.NUM_WEEK_DAYS:
@@ -100,7 +100,7 @@ class WeekDays(object):
def __eq__(self, other):
if isinstance(other, WeekDays):
return self._days == other._days
elif isinstance(other, six.text_type):
elif isinstance(other, six.string_types):
return self.as_bit_string() == other
else:
return NotImplemented
@@ -138,7 +138,7 @@ class WeekDaysType(types.TypeDecorator):
if isinstance(value, WeekDays):
return value.as_bit_string()
if isinstance(value, six.text_type):
if isinstance(value, six.string_types):
return value
def process_result_value(self, value, dialect):