示例#1
0
def set_default_template_variables(subset_id):
    """
    Step 2: Retrieve default variables from Github
    """
    data = cache.get(subset_id)
    variables = json.loads(
        get_github_repo().get_file_contents("/{}.defaults".format(data['template'])). \
            decoded_content.decode()
    )
    params = defaultdict(str, data['query_params'])
    for key, value in variables.items():
        variables[key] = value.format(**params)
    variables.update(data.get('variables', {}))
    return variables
示例#2
0
def set_default_template_variables(subset_id):
    """
    Step 2: Retrieve default variables from Github
    """
    data = cache.get(subset_id)
    variables = json.loads(
        get_github_repo().get_file_contents("/{}.defaults".format(data['template'])). \
            decoded_content.decode()
    )
    params = defaultdict(str, data['query_params'])
    for key, value in variables.items():
        variables[key] = value.format(**params)
    variables.update(data.get('variables', {}))
    return variables
示例#3
0
def generate_preview(subset_id):
    """
    Step 3: Generate HTML Preview based on chosen parameters
    """
    data = cache.get(subset_id)
    variables = data['variables'].copy()
    variables.update({'events': sorted_eventslist(
        data['list']
    ),
        'special_events': sorted_eventslist(
            [e for e in data['list'] if e['special']]
        )})
    preview = format_template(data['template'], variables)
    data['preview'] = preview
    cache.set(subset_id, data, timeout=60 * 60 * 24)
    return preview
示例#4
0
def generate_preview(subset_id):
    """
    Step 3: Generate HTML Preview based on chosen parameters
    """
    data = cache.get(subset_id)
    variables = data['variables'].copy()
    variables.update({
        'events':
        sorted_eventslist(data['list']),
        'special_events':
        sorted_eventslist([e for e in data['list'] if e['special']])
    })
    preview = format_template(data['template'], variables)
    data['preview'] = preview
    cache.set(subset_id, data, timeout=60 * 60 * 24)
    return preview
示例#5
0
def set_variable(subset_id, key, value, timeout=60 * 60 * 24):
    data = cache.get(subset_id)
    data[key] = value
    cache.set(subset_id, data, timeout=timeout)
示例#6
0
def set_variable(subset_id, key, value, timeout=60 * 60 * 24):
    data = cache.get(subset_id)
    data[key] = value
    cache.set(subset_id, data, timeout=timeout)