from django.conf import settings
from regulations.generator import generator
from django.core.urlresolvers import get_script_prefix


def get_layer_list(names):
    layer_names = generator.LayerCreator.LAYERS
    return set(l.lower() for l in names.split(',') if l.lower() in layer_names)


def handle_specified_layers(
        layer_names, regulation_id, version, sectional=False):

    layer_list = get_layer_list(layer_names)
    layer_creator = generator.LayerCreator()
    layer_creator.add_layers(layer_list, regulation_id, version, sectional)
    return layer_creator.get_appliers()

def handle_diff_layers(
    layer_names, regulation_id, older, newer, sectional=False):
    
    layer_list = get_layer_list(layer_names)
    layer_creator = generator.DiffLayerCreator(newer)
    layer_creator.add_layers(layer_list, regulation_id, older, sectional)
    return layer_creator.get_appliers()

def add_extras(context):
    context['env'] = 'source' if settings.DEBUG else 'built'
    context['APP_PREFIX'] = get_script_prefix()
    context['GOOGLE_ANALYTICS_SITE'] = settings.GOOGLE_ANALYTICS_SITE
    context['GOOGLE_ANALYTICS_ID'] = settings.GOOGLE_ANALYTICS_ID
    return context

from django.conf import settings
from regulations.generator import generator
from django.core.urlresolvers import reverse


def get_layer_list(names):
    layer_names = generator.LayerCreator.LAYERS
    return set(l.lower() for l in names.split(',') if l.lower() in layer_names)


def handle_specified_layers(
        layer_names, regulation_id, version, sectional=False):

    layer_list = get_layer_list(layer_names)
    layer_creator = generator.LayerCreator()
    layer_creator.add_layers(layer_list, regulation_id, version, sectional)
    return layer_creator.get_appliers()

def handle_diff_layers(
    layer_names, regulation_id, older, newer, sectional=False):
    
    layer_list = get_layer_list(layer_names)
    layer_creator = generator.DiffLayerCreator(newer)
    layer_creator.add_layers(layer_list, regulation_id, older, sectional)
    return layer_creator.get_appliers()

def add_extras(context):
    context['env'] = 'source' if settings.DEBUG else 'built'
    prefix = reverse('regulation_landing_view', kwargs={'label_id': '9999'})
    prefix = prefix.replace('9999', '')
    if prefix != '/':   # Strip final slash
        prefix = prefix[:-1]
    context['APP_PREFIX'] = prefix
    context['GOOGLE_ANALYTICS_SITE'] = settings.GOOGLE_ANALYTICS_SITE
    context['GOOGLE_ANALYTICS_ID'] = settings.GOOGLE_ANALYTICS_ID
    return context

Fix error with app prefix. We will assume all urls fall under the same root as the landing page
Fix error with app prefix. We will assume all urls fall under the same root as the landing page
