Beispiel #1
0
    def render(self, context):
        kwargs = copy.deepcopy(getattr(settings, "MAPPING_SETTINGS", {}))
        request = context.get("request")

        kwargs.update(self._prepare_args(context, "map", accept_args=map_args))

        while True:
            map_id = kwargs.pop("container", "") or "".join(random.sample(string.letters + string.digits, 25))

            if not map_id[0].isdigit():
                break

        module, comma, klass = PROVIDER.rpartition(".")
        module = import_module(module)
        klass = getattr(module, klass)
        provider = klass(map_id, **kwargs)
        portions = [provider.add_container()]

        if not "_MAPPING_MEDIA" in context:
            if not request or not request.is_ajax():
                for js in getattr(provider.Media, "js", ()):
                    portions.append('<script src="%s"></script>' % js % kwargs)

                for css in getattr(provider.Media, "css", ()):
                    portions.append('<link href="%s" rel="stylesheet" />' % css % kwargs)

            context["_MAPPING_MEDIA"] = True

        portions.append("<script>")

        if not request or not request.is_ajax():
            portions.append("$(document).ready(function() {")

        portions.append(provider.init_map())

        portions.append("if(typeof bambu == 'undefined') { bambu = {}; }")
        portions.append("if(!('mapping' in bambu)) {")
        portions.append("bambu.mapping = {markers: {}};")
        portions.append("}")
        portions.append("bambu.mapping.markers['%s'] = [];" % map_id)

        context["_BAMBU_MAPPING_PROVIDER"] = provider

        portions.append(self.nodelist.render(context))

        del context["_BAMBU_MAPPING_PROVIDER"]

        if kwargs.get("callback"):
            portions.append(provider.add_map_callback(kwargs["callback"]))

        if not request or not request.is_ajax():
            portions.append("});")

        portions.append("</script>")

        if kwargs.get("advanced"):
            portions.append('<script src="%s?m=%s"></script>' % (reverse("bambu_mapping_functions"), map_id))

        return "".join(portions)
Beispiel #2
0
def functions_js(request):
    module, comma, klass = PROVIDER.rpartition(".")
    module = import_module(module)
    klass = getattr(module, klass)
    kwargs = getattr(settings, "MAPPING_SETTINGS")
    map_id = request.GET.get("m")
    provider = klass(map_id, **kwargs)

    return TemplateResponse(request, "mapping/bambu.mapping.js", {"provider": provider}, mimetype="text/javascript")
Beispiel #3
0
def map_header(context):
    module, comma, klass = PROVIDER.rpartition(".")
    module = import_module(module)
    klass = getattr(module, klass)
    kwargs = copy.deepcopy(getattr(settings, "MAPPING_SETTINGS", {}))

    portions = []
    for js in getattr(klass.Media, "js", ()):
        portions.append('<script src="%s"></script>' % js % kwargs)

    for css in getattr(klass.Media, "css", ()):
        portions.append('<link href="%s" rel="stylesheet" />' % csss % kwargs)

    context["_MAPPING_MEDIA"] = True
    return "".join(portions)