예제 #1
0
    def render(self, context):
        compressed_package = '<link rel="stylesheet" type="text/css" \
href="%s-min.css" />' % (settings.MEDIA_URL + self.package_name)

        # If settings.DEBUG is False then build_package won't be run
        if settings.DEBUG == False:
            return compressed_package

        uncompressed_package = '<link rel="stylesheet" type="text/css" \
href="%s.css" />' % (settings.MEDIA_URL + self.package_name)

        if "request" in context:
            compress = context["request"].GET.get("css_compress", "0")
            if compress == "1":
                build_package(self.package_name, compress=True)
                return compressed_package
            elif compress == "0":
                build_package(self.package_name)
                return uncompressed_package

        if hasattr(settings, "CSS_BUILDER_COMPRESS"):
            if getattr(settings, "CSS_BUILDER_COMPRESS"):
                build_package(self.package_name, compress=True)
                return compressed_package
        build_package(self.package_name)
        return uncompressed_package