def application(request, project_id=None): try: data = {} return render(request, 'application.html', data) except Exception: ServiceLog.error(traceback.format_exc()) return HttpResponse(status=500)
def logs(self, name, namespace): label_selector = 'job-name=' + name try: pods = self.core_client.list_namespaced_pod( namespace, label_selector=label_selector) except ApiException as e: print( "Exception when calling CoreV1Api->list_namespaced_pod: %s\n" % e) return try: for pod in pods.items: pod_log = self.core_client.read_namespaced_pod_log( pod.metadata.name, namespace) ServiceLog.error('pod-name=' + pod.metadata.name, detail_msg=pod_log) if pods.items == []: pod_log = 'no logs' ServiceLog.error(label_selector, detail_msg='no logs') return pod_log except ApiException as e: print( "Exception when calling CoreV1Api->read_namespaced_pod_log: %s\n" % e)
def terms_of_service(request): try: data = {} return render(request, 'terms_of_service.html', data) except Exception: ServiceLog.error(traceback.format_exc()) return HttpResponse(status=500)
def labeling_tool(request, project_id=None, annotation_id=None): try: data = {} return render(request, 'labeling_tool/labeling_tool.html', data) except Exception: ServiceLog.error(traceback.format_exc()) return HttpResponse(status=500)
def file_upload(request, project_id): username = request.user user_id = AccountManager.get_id_by_username(username) if not Permission.hasPermission(user_id, 'create_original', project_id): raise PermissionDenied try: file = request.FILES['file'] original_manager = OriginalManager() data = original_manager.save_file(project_id, file) response = JSONResponse(data, mimetype=response_mimetype(request)) response['Content-Disposition'] = 'inline; filename=files.json' return response except Exception: # FIXME ServiceLog.error(traceback.format_exc()) data = json.dumps({'status': 'NG'}) return HttpResponse(content=data, status=400, content_type='application/json')
def getPermissions(user_id, project_id=None): try: if AccountManager.is_superuser(user_id): return SUPER_ADMIN_PERMISSIONS if project_id: group_name = MemberSerializer.get_group(project_id, user_id) if group_name == 'admin': return ADMIN_PERMISSIONS elif group_name == 'default': return DEFAULT_PERMISSIONS raise PermissionDenied except ObjectDoesNotExist: raise PermissionDenied except PermissionDenied: raise PermissionDenied except Exception: ServiceLog.error(traceback.format_exc()) raise
def process_exception(self, request, exception): message = exception.message if hasattr(exception, 'message') else '' if isinstance(exception, ValidationError): ServiceLog.warning(message, exception=exception, request=request) return HttpResponse(status=400) elif isinstance(exception, PermissionDenied): ServiceLog.warning(message, exception=exception, request=request) return HttpResponse(status=403) elif isinstance(exception, ObjectDoesNotExist): ServiceLog.warning(message, exception=exception, request=request) return HttpResponse(status=404) ServiceLog.error(message, exception=exception, request=request) return HttpResponse(status=500)