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

@@ -107,33 +107,23 @@
  import 
-get_script_prefix
+reverse
 %0A%0A%0Adef g
@@ -967,16 +967,206 @@
 'built'%0A
+    prefix = reverse('regulation_landing_view', kwargs=%7B'label_id': '9999'%7D)%0A    prefix = prefix.replace('9999', '')%0A    if prefix != '/':   # Strip final slash%0A        prefix = prefix%5B:-1%5D%0A
     cont
@@ -1189,27 +1189,14 @@
 %5D = 
-get_script_
 prefix
-()
 %0A   

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