Changes between Version 5 and Version 12 of Ticket #4687


Ignore:
Timestamp:
12/05/2016 07:15:25 PM (3 years ago)
Author:
kvas
Comment:

Replying to juliandoucette:

IIRC we decided to use a whitelist for a reason. Perhaps @jsonesen can elaborate and you two can determine what is best?

Cool, will do.

Would this work for you, Julian?

Yes.

Great!

One more thing. The name index is a bit non-descriptive. What if we call it something like get_pages_metadata? I took the liberty to already in the ticket description but let me know if you disagree.

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #4687 – Description

    v5 v12  
    11=== Background === 
    22 
    3 - The new Help Center website categorizes pages by taxonomy like [product, platform, category, tag] 
    4 - Several of the page templates required to build this website list pages based on these taxonomies 
    5 - Therefore we must provide a method for adblockplus/cms to implement these lists using Jinja2 
     3- The new Help Center website categorizes pages by taxonomy like [product, platform, category, tag], 
     4- Several of the page templates required to build this website list pages based on these taxonomies, 
     5- Therefore we must provide a method for adblockplus/cms to implement these lists using Jinja2. 
    66 
    77=== What to change === 
     8Note: from here on we'll use the terms: 
     9- ''field name'' to refer to each type of taxonomy (e.g. product, platform, etc.), 
     10- ''field value'' to refer to the value of a field for a particular page (e.g. product=adblock-plus), and 
     11- ''page metadata'' to refer to the collection of all the fields and values of one page (including the `page` field which contains the id of the page). 
    812 
    913Provide the following @contextfunction:  
    1014{{{ 
    11 def index(taxonomies): 
    12     """Index pages by taxonomy. 
    13      
     15def get_pages_metadata(filters={}): 
     16    """Return metadata dicts for all pages matching the filters 
     17 
    1418    Args: 
    15         taxonomies: A list of taxonomies (with optional value) 
    16             List of strings: ["product", "platform"] 
    17             List of tuple of strings (providing optional value): [("product", "adblock-plus"), "platform"] 
     19        filters: Mapping of field names to desired field values or lists of them 
     20            Example: {'product': 'adblock-plus', 'platform': ['firefox', 'chrome']} 
    1821    Returns: 
    19         A list of pages matching given taxonomies including page name and given fields (in taxonomies) 
    20             List of dicts: [{page: "acceptable-ads", product: "adblock-plus", platform: "firefox"}] 
     22        A list of metadata dicts for pages matching all the filters (if no filters are given, returns all pages) 
     23            Example: [{page: 'acceptable-ads', product: 'adblock-plus', platform: 'firefox'}] 
    2124    Raises: 
    22         TypeError: if taxonomies is not a list 
    23         TypeError: if taxonomies list is formatted incorrectly 
     25        TypeError: if filters is not a dict mapping strings to strings or lists of strings 
    2426    """ 
    2527}}}