def import_from_github(request): serializer = WorkflowSerializerLite(request, many=True) try: import_module_from_github(request.data["url"]) return Response(status=status.HTTP_201_CREATED) except ValidationError as error: return Response(error, status=status.HTTP_400_BAD_REQUEST)
def handle(self, *args, **options): totes = 0 external_modules = Module.objects.exclude(link__exact='') for m in external_modules: url = m.link print('Importing module %s from %s' % (m.name, url)) try: import_module_from_github(url, force_reload=options['force']) totes += 1 except Exception as e: print(str(e)) print('Imported %d external modules' % totes)
def import_from_github(request): try: returnable = import_module_from_github(request.data["url"]) response = Response(json.dumps(returnable), content_type='application/json') response.status_code = status.HTTP_201_CREATED return response except ValidationError as error: response = HttpResponse(json.dumps({'error': str(error)}), content_type='application/json') response.status_code = 400 return response
def import_from_github(request): try: returnable = import_module_from_github(request.data["url"]) response = Response(json.dumps(returnable), content_type='application/json') response.status_code = status.HTTP_201_CREATED return response except ValidationError as error: response = HttpResponse(json.dumps({'error': error.message}), content_type='application/json') response.status_code = 200 # should really be 400, but we want the WorkbenchAPI.js to pass error messages through return response
def import_from_github(request): if not request.user.is_staff: return JsonResponse({'error': 'Only an admin can call this method'}, status=status.HTTP_403_FORBIDDEN) try: module = import_module_from_github(request.data["url"]) data = ModuleSerializer(module).data return JsonResponse(data, status=status.HTTP_201_CREATED) except (RuntimeError, ValueError) as err: # Respond with 200 OK so the client side can read the error message. # TODO make the client smarter return JsonResponse({'error': str(err)}, status=status.HTTP_200_OK)
def import_from_github(request): if not request.user.is_staff: return JsonResponse( {"error": "Only an admin can call this method"}, status=status.HTTP_403_FORBIDDEN, ) try: module = import_module_from_github(request.data["url"]) ctx = JsonizeContext(request.user, request.session, request.locale_id) data = jsonize_clientside_module(module.to_clientside(), ctx) return JsonResponse(data, status=status.HTTP_201_CREATED) except (RuntimeError, ValueError, ModuleError) as err: # Respond with 200 OK so the client side can read the error message. # TODO make the client smarter return JsonResponse({"error": str(err)}, status=status.HTTP_200_OK)
def handle(self, *args, slugs, **kwargs): for slug in slugs: import_module_from_github("https://github.com/CJWorkbench/%s.git" % slug, force_reload=True)