本文整理匯總了Python中ebpub.db.schemafilters.FilterChain.copy方法的典型用法代碼示例。如果您正苦於以下問題:Python FilterChain.copy方法的具體用法?Python FilterChain.copy怎麽用?Python FilterChain.copy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ebpub.db.schemafilters.FilterChain
的用法示例。
在下文中一共展示了FilterChain.copy方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_sort__real_filters
# 需要導入模塊: from ebpub.db.schemafilters import FilterChain [as 別名]
# 或者: from ebpub.db.schemafilters.FilterChain import copy [as 別名]
def test_sort__real_filters(self):
req = mock.Mock()
qs = mock.Mock()
schema = mock.Mock()
context = {'newsitem_qs': qs, 'schema': schema}
from ebpub.db.schemafilters import TextSearchFilter, BoolFilter
from ebpub.db.schemafilters import LookupFilter, LocationFilter
from ebpub.db.schemafilters import DateFilter
def mock_schemafield(name):
# mock.Mock(name='foo') does something magic, but I just
# want to set the name attribute.
sf = mock.Mock()
sf.name = name
return sf
all_filters = [
TextSearchFilter(req, context, qs, 'hi',
schemafield=mock_schemafield(name='mock text sf')),
BoolFilter(req, context, qs, 'yes',
schemafield=mock_schemafield(name='mock bool sf')),
LookupFilter(req, context, qs,
schemafield=mock_schemafield(name='mock lookup sf')),
LocationFilter(req, context, qs, 'neighborhoods'),
DateFilter(req, context, qs, '2011-04-11', '2011-04-12'),
]
chain = FilterChain([(item.slug, item) for item in all_filters])
ordered_chain = chain.copy()
ordered_chain.sort()
self.assertEqual(ordered_chain.keys(),
['date', 'mock bool sf', 'location', 'mock lookup sf', 'mock text sf'])
示例2: test_copy_and_mutate
# 需要導入模塊: from ebpub.db.schemafilters import FilterChain [as 別名]
# 或者: from ebpub.db.schemafilters.FilterChain import copy [as 別名]
def test_copy_and_mutate(self):
schema = mock.Mock()
chain = FilterChain(schema=schema)
chain.lookup_descriptions.append(1)
chain.base_url = 'http://xyz'
chain['foo'] = 'bar'
chain['qux'] = 'whee'
clone = chain.copy()
# Attributes are copied...
self.assertEqual(clone.lookup_descriptions, [1])
self.assertEqual(clone.base_url, chain.base_url)
self.assertEqual(clone.schema, chain.schema, schema)
# ... and mutating them doesn't affect the original.
clone.lookup_descriptions.pop()
self.assertEqual(chain.lookup_descriptions, [1])
# Likewise, items are copied, and mutating doesn't affect the copy.
self.assertEqual(clone['foo'], 'bar')
del chain['foo']
self.assertEqual(clone['foo'], 'bar')
del clone['qux']
self.assertEqual(chain['qux'], 'whee')
# Likewise, clearing.
clone.clear()
self.assertEqual(clone.items(), [])
self.assertEqual(chain['qux'], 'whee')
示例3: test_sort__real_filters
# 需要導入模塊: from ebpub.db.schemafilters import FilterChain [as 別名]
# 或者: from ebpub.db.schemafilters.FilterChain import copy [as 別名]
def test_sort__real_filters(self):
req = mock.Mock()
qs = mock.Mock()
schema = mock.Mock()
context = {"newsitem_qs": qs, "schema": schema}
from ebpub.db.schemafilters import TextSearchFilter, BoolFilter
from ebpub.db.schemafilters import LookupFilter, LocationFilter
from ebpub.db.schemafilters import DateFilter
def mock_schemafield(name):
# mock.Mock(name='foo') does something magic, but I just
# want to set the name attribute.
sf = mock.Mock()
sf.name = name
return sf
all_filters = [
TextSearchFilter(req, context, qs, "hi", schemafield=mock_schemafield(name="mock text sf")),
BoolFilter(req, context, qs, "yes", schemafield=mock_schemafield(name="mock bool sf")),
LookupFilter(req, context, qs, schemafield=mock_schemafield(name="mock lookup sf")),
LocationFilter(req, context, qs, "neighborhoods"),
DateFilter(req, context, qs, "2011-04-11", "2011-04-12"),
]
chain = FilterChain([(item.slug, item) for item in all_filters])
ordered_chain = chain.copy()
ordered_chain.sort()
self.assertEqual(ordered_chain.keys(), ["date", "mock bool sf", "location", "mock lookup sf", "mock text sf"])
示例4: test_sort
# 需要導入模塊: from ebpub.db.schemafilters import FilterChain [as 別名]
# 或者: from ebpub.db.schemafilters.FilterChain import copy [as 別名]
def test_sort(self):
class Dummy(object):
def __init__(self, sort_value):
self._sort_value = sort_value
dummies = [Dummy(i) for i in range(10)]
random.shuffle(dummies)
chain = FilterChain()
for i in range(10):
chain[i] = dummies[i]
self.assertNotEqual(range(10), [v._sort_value for v in chain.values()])
normalized = chain.copy()
normalized.sort()
self.assertEqual(range(10), [v._sort_value for v in normalized.values()])
示例5: _get_filterchain
# 需要導入模塊: from ebpub.db.schemafilters import FilterChain [as 別名]
# 或者: from ebpub.db.schemafilters.FilterChain import copy [as 別名]
def _get_filterchain(self, context):
filterchain_or_schema = self.filterchain_var.resolve(context)
if isinstance(filterchain_or_schema, FilterChain):
filterchain = filterchain_or_schema
elif isinstance(filterchain_or_schema, Schema):
# Note, context['request'] only works if
# django.core.context_processors.request is enabled in
# TEMPLATE_CONTEXT_PROCESSORS.
filterchain = FilterChain(context=context, request=context['request'],
schema=filterchain_or_schema)
else:
raise template.TemplateSyntaxError(
"%r is neither a FilterChain nor a Schema" % filterchain_or_schema)
if self.clear:
filterchain = filterchain.copy()
filterchain.clear()
return filterchain
示例6: render
# 需要導入模塊: from ebpub.db.schemafilters import FilterChain [as 別名]
# 或者: from ebpub.db.schemafilters.FilterChain import copy [as 別名]
def render(self, context):
filterchain = self.filterchain_var.resolve(context)
if isinstance(filterchain, FilterChain):
schema = filterchain.schema
elif isinstance(filterchain, Schema):
schema = filterchain
# Note, context['request'] only works if
# django.core.context_processors.request is enabled in
# TEMPLATE_CONTEXT_PROCESSORS.
filterchain = FilterChain(context=context, request=context['request'],
schema=schema)
else:
raise template.TemplateSyntaxError(
"%r is neither a FilterChain nor a Schema" % filterchain)
removals = [r.resolve(context) for r in self.removals]
if self.clear:
filterchain = filterchain.copy()
filterchain.clear()
additions = []
for key, values in self.additions:
key = key.resolve(context)
additions.append((key, [v.resolve(context) for v in values]))
schema = filterchain.schema
return filterchain.make_url(additions=additions, removals=removals)
示例7: place_detail_overview
# 需要導入模塊: from ebpub.db.schemafilters import FilterChain [as 別名]
# 或者: from ebpub.db.schemafilters.FilterChain import copy [as 別名]
def place_detail_overview(request, *args, **kwargs):
context, response = _place_detail_normalize_url(request, *args, **kwargs)
if response is not None:
return response
schema_manager = get_schema_manager(request)
context['breadcrumbs'] = breadcrumbs.place_detail_overview(context)
schema_list = SortedDict([(s.id, s) for s in schema_manager.filter(is_special_report=False).order_by('plural_name')])
# needed = set(schema_list.keys())
# We actually want two lists of schemas, since we care whether
# they are news-like or future-event-like.
import copy
eventish_schema_list = copy.deepcopy(schema_list)
newsish_schema_list = copy.deepcopy(schema_list)
for s_id, schema in schema_list.items():
if schema.is_event:
del(newsish_schema_list[s_id])
else:
del(eventish_schema_list[s_id])
filterchain = FilterChain(request=request, context=context)
filterchain.add('location', context['place'])
# Distinguish between past news and upcoming events.
# With some preliminary date limiting too.
filterchain_news = filterchain.copy()
filterchain_news.add('date',
today() - datetime.timedelta(days=90),
today())
filterchain_events = filterchain.copy()
filterchain_events.add('date',
today(),
today() + datetime.timedelta(days=60))
# Ordering by ID ensures consistency across page views.
newsitem_qs = filterchain_news.apply().order_by('-item_date', '-id')
events_qs = filterchain_events.apply().order_by('item_date', 'id')
# Mapping of schema id -> [schemafields], for building Lookup charts.
sf_dict = {}
charted_lookups = SchemaField.objects.filter(
is_lookup=True, is_charted=True, schema__is_public=True,
schema__is_special_report=False)
charted_lookups = charted_lookups.values('id', 'schema_id', 'pretty_name')
for sf in charted_lookups.order_by('schema__id', 'display_order'):
sf_dict.setdefault(sf['schema_id'], []).append(sf)
# Now retrieve newsitems per schema.
schema_groups, all_newsitems = [], []
for schema in schema_list.values():
if schema.id in newsish_schema_list:
newsitems = newsitem_qs.filter(schema__id=schema.id)
elif schema.id in eventish_schema_list:
newsitems = events_qs.filter(schema__id=schema.id)
else:
raise RuntimeError("should never get here")
newsitems = list(newsitems[:s.number_in_overview])
populate_schema(newsitems, schema)
schema_groups.append({
'schema': schema,
'latest_newsitems': newsitems,
'has_newsitems': bool(newsitems),
'lookup_charts': sf_dict.get(schema.id),
})
all_newsitems.extend(newsitems)
schema_list = schema_list.values()
populate_attributes_if_needed(all_newsitems, schema_list)
schema_list = [s for s in schema_list if s.allow_charting]
context['schema_groups'] = schema_groups
context['filtered_schema_list'] = schema_list
context['bodyclass'] = 'place-detail-overview'
if context['is_block']:
context['bodyid'] = '%s-%s-%s' % (context['place'].street_slug,
context['place'].number(),
context['place'].dir_url_bit())
else:
context['bodyid'] = context['location'].slug
response = eb_render(request, 'db/place_overview.html', context)
for k, v in context['cookies_to_set'].items():
response.set_cookie(k, v)
return response