當前位置: 首頁>>代碼示例>>Python>>正文


Python FilterChain.replace方法代碼示例

本文整理匯總了Python中ebpub.db.schemafilters.FilterChain.replace方法的典型用法代碼示例。如果您正苦於以下問題:Python FilterChain.replace方法的具體用法?Python FilterChain.replace怎麽用?Python FilterChain.replace使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ebpub.db.schemafilters.FilterChain的用法示例。


在下文中一共展示了FilterChain.replace方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: value_list

# 需要導入模塊: from ebpub.db.schemafilters import FilterChain [as 別名]
# 或者: from ebpub.db.schemafilters.FilterChain import replace [as 別名]
 def value_list(self):
     """
     Returns a list of {value, url, description} dictionaries
     representing each value for this attribute.
     """
     from django.utils.dateformat import format, time_format
     # Setting these to [None] ensures that zip() returns a list
     # of at least length one.
     urls = [None]
     descriptions = [None]
     if self.is_filter:
         from ebpub.db.schemafilters import FilterChain
         chain = FilterChain(schema=self.sf.schema)
         if self.is_lookup:
             urls = [chain.replace(self.sf, look).make_url() if look else None
                     for look in self.values]
         else:
             urls = [chain.replace(self.sf, self.raw_value).make_url()]
     if self.is_lookup:
         values = [val and val.name or 'None' for val in self.values]
         descriptions = [val and val.description or None for val in self.values]
     elif isinstance(self.raw_value, datetime.datetime):
         values = [format(self.raw_value, 'F j, Y, P')]
     elif isinstance(self.raw_value, datetime.date):
         values = [format(self.raw_value, 'F j, Y')]
     elif isinstance(self.raw_value, datetime.time):
         values = [time_format(self.raw_value, 'P')]
     elif self.raw_value is True:
         values = ['Yes']
     elif self.raw_value is False:
         values = ['No']
     elif self.raw_value is None:
         values = ['N/A']
     else:
         values = [self.raw_value]
     return [{'value': value, 'url': url, 'description': description} for value, url, description in zip(values, urls, descriptions)]
開發者ID:mesrut,項目名稱:openblock,代碼行數:38,代碼來源:models.py

示例2: _decode_map_permalink

# 需要導入模塊: from ebpub.db.schemafilters import FilterChain [as 別名]
# 或者: from ebpub.db.schemafilters.FilterChain import replace [as 別名]

#.........這裏部分代碼省略.........
            'visible': place_type.id in place_types # off by default
        })

    # All available NewsItem layers.
    for schema in get_schema_manager(request).all():
        # if filters and 'schema' in filters and filters['schema'].schema == schema:
        #     visible = True
        if no_layers_specified and show_default_layers and not show_custom_layer:
            # default on if no 't' param given
            visible = True
        elif schemas and schema.id in schemas:
            visible = True
        else:
            visible = False
        layers.append({
            'id': 't%d' % schema.id,
            'title':  schema.plural_name,
            'url':    reverse('map_items_json'),
            'params': {'type': schema.slug, 'limit': 1000,
                       'startdate': api_startdate,
                       'enddate': api_enddate},
            'bbox': False,
            'visible': visible
        })

    # Explicit filtering by ID.
    ids = params.get('i') or u''
    ids = [i.strip() for i in re.split(r'[^\d]+', ids)
           if i.strip()]
    if ids:
        show_custom_layer = True
        if filters is None:
            filters = FilterChain(request)
        filters.replace('id', *ids)


    # 'Custom' layer. This is a catch-all for all filtering
    # that isn't just enabling a default layer with the default
    # date range.
    # Not visible unless there is something like that to show.
    if filters and sorted(filters.keys()) not in ([],
                                                  ['date'],
                                                  ['date', 'schema'],
                                                  ['schema']):
        show_custom_layer = True

    if filters is not None:
        # Don't inspect filters['schema']; that's already covered by schemas above.
        base_url = reverse('map_items_json')
        layer_url = filters.make_url(base_url=base_url)
        # Quick ugly hacks to make the itemquery api happy.
        # Hooray proliferation of spellings.
        layer_url = layer_url.replace('locations=', 'locationid=')
        layer_url = layer_url.replace('start_date=', 'startdate=')
        layer_url = layer_url.replace('end_date=', 'enddate=')

        if 'schema' in filters:
            # Normally, filters.make_url() captures the schema in the
            # path part of the URL. But map_items_json doesn't,
            # so we add a query parameter.
            params = {'type': [s.slug for s in filters['schema'].schemas]}
        else:
            params = {}
        custom_layer = {
            'url': layer_url,
            'params': params,
開發者ID:DotNetWebs,項目名稱:openblock,代碼行數:70,代碼來源:views.py


注:本文中的ebpub.db.schemafilters.FilterChain.replace方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。