| 310 | return path_traversal_check(os.path.join(settings.MEDIA_ROOT, "plugins", *paths), os.path.join(settings.MEDIA_ROOT, "plugins")) |
| 311 | |
| 312 | def get_dynamic_script_handler(script_path, callback=None, **kwargs): |
| 313 | def handleRequest(request): |
| 314 | if callback is not None: |
| 315 | template_params = callback(request, **kwargs) |
| 316 | if not template_params: |
| 317 | return HttpResponse("") |
| 318 | else: |
| 319 | template_params = kwargs |
| 320 | |
| 321 | with open(script_path) as f: |
| 322 | tmpl = Template(f.read()) |
| 323 | try: |
| 324 | return HttpResponse(tmpl.substitute(template_params)) |
| 325 | except TypeError as e: |
| 326 | return HttpResponse("Template substitution failed with params: {}. {}".format(str(template_params), e)) |
| 327 | |
| 328 | return handleRequest |
| 329 | |
| 330 | def enable_plugin(plugin_name): |
| 331 | p = get_plugin_by_name(plugin_name, only_active=False) |