Ejemplo n.º 1
0
    def check_ice(self, user_token, name):
        from main.tasks import create_ice_connection
        from .core import Strain

        try:
            ice = create_ice_connection(user_token)
            if not ice:
                logger.warning(
                    "Unable to connect to ICE.  ICE is not configured.")
                return False

            part = ice.get_entry(name, suppress_errors=True)
            if part:
                url = f"{ice.base_url}/entry/{part.id}"
                default = dict(name=part.name,
                               description=part.short_description,
                               registry_url=url)
                self.strain, created = Strain.objects.get_or_create(
                    registry_id=part.uuid, defaults=default)
                self.strain.part = part
                return True
        except Exception:
            logger.warning(
                f"Failed to load ICE information on `{name}` for `{user_token}`",
                exc_info=True,
            )
        return False
Ejemplo n.º 2
0
 def check_ice(self, user_token, name):
     from main.tasks import create_ice_connection
     from .core import Strain
     ice = create_ice_connection(user_token)
     part = ice.get_entry(name, suppress_errors=True)
     if part:
         default = dict(
             name=part.name,
             description=part.short_description,
             registry_url=''.join((ice.base_url, '/entry/', str(part.id))),
         )
         self.strain, x = Strain.objects.get_or_create(registry_id=part.uuid, defaults=default)
         self.strain.part = part
         return True
     return False
Ejemplo n.º 3
0
 def get(self, request, *args, **kwargs):
     # TODO: uncovered code
     try:
         ice = create_ice_connection(request.user.email)
         folder = ice.folder_from_url(request.GET.get("url", None))
         if folder is None:
             return self._build_simple_err_response(
                 constants.SYSTEMIC_ICE_ACCESS_ERROR_CATEGORY,
                 "Folder was not found",
                 status=codes.not_found,
             )
         return JsonResponse(folder.to_json_dict())
     except Exception as e:
         return self._build_simple_err_response(
             constants.SYSTEMIC_ICE_ACCESS_ERROR_CATEGORY,
             "Failed to load ICE Folder",
             detail=str(e),
         )