Beispiel #1
0
    def handle_profile(self, name, profile):
        paths = compiler.compile_lookup(
            namespaces=profile.URL_NAMESPACES, includes=profile.URL_INCLUDES, excludes=profile.URL_EXCLUDES
        )
        javascript = compiler.render_js(paths, profile.JS_NAMESPACE, self.minify)

        if self.install:
            if self.interactive and os.path.exists(profile.INSTALL_PATH):
                self.pout(name, "Will OVERWRITE compiled url router to:")
                self.pout(name, "    `{}'".format(profile.INSTALL_PATH))
                self.pout(name, "(To write to stdout, do not specify the 'install' command.)", 1)

                confirm = ""
                while confirm not in ("yes", "no"):
                    confirm = input("Type 'yes' to continue, or 'no' to cancel: ").lower()

                if confirm == "no":
                    self.perr(name, "installation cancelled", 1)
                    return

            out = open(profile.INSTALL_PATH, "wb")
        else:
            out = sys.stdout

        out.write(javascript)
Beispiel #2
0
def serve(request, profile=None, namespaces=(), includes=(), excludes=(), js_namespace=None):
    if not django.conf.settings.DEBUG:
        raise ImproperlyConfigured("The jsurls view can only be used in debug mode")

    if profile:
        if namespaces or includes or excludes or js_namespace:
            raise TypeError("profile_name argument incompatible with other arguments")

        try:
            profile = settings.PROFILES[profile]
        except KeyError:
            raise ValueError("no such profile: {}".format(profile))

    else:
        profile = Profile(settings,
                          URL_NAMESPACES=namespaces,
                          URL_INCLUDES=includes,
                          URL_EXCLUDES=excludes)
        if js_namespace:
            profile.JS_NAMESPACE = js_namespace

    paths = compiler.compile_lookup(
        namespaces=profile.URL_NAMESPACES,
        includes=profile.URL_INCLUDES,
        excludes=profile.URL_EXCLUDES,
    )
    javascript = compiler.render_js(paths, profile.JS_NAMESPACE)

    return http.HttpResponse(javascript, content_type='text/javascript')