from core.models import Application as Image

from api import permissions
from api.v2.serializers.details import ImageSerializer
from api.v2.views.base import AuthOptionalViewSet
from api.v2.views.mixins import MultipleFieldLookup


class ImageViewSet(MultipleFieldLookup, AuthOptionalViewSet):

    """
    API endpoint that allows images to be viewed or edited.
    """
    lookup_fields = ("id", "uuid")

    http_method_names = ['get', 'put', 'patch', 'head', 'options', 'trace']

    filter_fields = ('created_by__username', 'tags__name', 'projects__id')

    permission_classes = (permissions.InMaintenance,
                          permissions.ApiAuthOptional,
                          permissions.CanEditOrReadOnly,
                          permissions.ApplicationMemberOrReadOnly)

    serializer_class = ImageSerializer

    search_fields = ('id', 'name', 'versions__change_log', 'tags__name',
                     'tags__description', 'created_by__username', 'versions__machines__instance_source__provider__location')

    def get_queryset(self):
        request_user = self.request.user
        return Image.current_apps(request_user)

from core.models import Application as Image

from api import permissions
from api.v2.serializers.details import ImageSerializer
from api.v2.views.base import AuthOptionalViewSet
from api.v2.views.mixins import MultipleFieldLookup


class ImageViewSet(MultipleFieldLookup, AuthOptionalViewSet):

    """
    API endpoint that allows images to be viewed or edited.
    """
    lookup_fields = ("id", "uuid")

    http_method_names = ['get', 'put', 'patch', 'head', 'options', 'trace']

    filter_fields = ('created_by__username', 'tags__name', 'projects__id')

    permission_classes = (permissions.InMaintenance,
                          permissions.ApiAuthOptional,
                          permissions.CanEditOrReadOnly,
                          permissions.ApplicationMemberOrReadOnly)

    serializer_class = ImageSerializer

    search_fields = ('id', 'name', 'versions__change_log', 'tags__name',
                     'tags__description', 'created_by__username',
                     'versions__machines__instance_source__identifier',
                     'versions__machines__instance_source__provider__location')

    def get_queryset(self):
        request_user = self.request.user
        return Image.current_apps(request_user)

Add 'Machine Identifier' for easy support lookups in Troposphere
Add 'Machine Identifier' for easy support lookups in Troposphere

  from core.models import Application as Image
  
  from api import permissions
  from api.v2.serializers.details import ImageSerializer
  from api.v2.views.base import AuthOptionalViewSet
  from api.v2.views.mixins import MultipleFieldLookup
  
  
  class ImageViewSet(MultipleFieldLookup, AuthOptionalViewSet):
  
      """
      API endpoint that allows images to be viewed or edited.
      """
      lookup_fields = ("id", "uuid")
  
      http_method_names = ['get', 'put', 'patch', 'head', 'options', 'trace']
  
      filter_fields = ('created_by__username', 'tags__name', 'projects__id')
  
      permission_classes = (permissions.InMaintenance,
                            permissions.ApiAuthOptional,
                            permissions.CanEditOrReadOnly,
                            permissions.ApplicationMemberOrReadOnly)
  
      serializer_class = ImageSerializer
  
      search_fields = ('id', 'name', 'versions__change_log', 'tags__name',
+                      'tags__description', 'created_by__username',
+                      'versions__machines__instance_source__identifier',
-                      'tags__description', 'created_by__username', 'versions__machines__instance_source__provider__location')
+                      'versions__machines__instance_source__provider__location')
  
      def get_queryset(self):
          request_user = self.request.user
          return Image.current_apps(request_user)
  
Add 'Machine Identifier' for easy support lookups in Troposphere
## Code Before:
from core.models import Application as Image

from api import permissions
from api.v2.serializers.details import ImageSerializer
from api.v2.views.base import AuthOptionalViewSet
from api.v2.views.mixins import MultipleFieldLookup


class ImageViewSet(MultipleFieldLookup, AuthOptionalViewSet):

    """
    API endpoint that allows images to be viewed or edited.
    """
    lookup_fields = ("id", "uuid")

    http_method_names = ['get', 'put', 'patch', 'head', 'options', 'trace']

    filter_fields = ('created_by__username', 'tags__name', 'projects__id')

    permission_classes = (permissions.InMaintenance,
                          permissions.ApiAuthOptional,
                          permissions.CanEditOrReadOnly,
                          permissions.ApplicationMemberOrReadOnly)

    serializer_class = ImageSerializer

    search_fields = ('id', 'name', 'versions__change_log', 'tags__name',
                     'tags__description', 'created_by__username', 'versions__machines__instance_source__provider__location')

    def get_queryset(self):
        request_user = self.request.user
        return Image.current_apps(request_user)

## Instruction:
Add 'Machine Identifier' for easy support lookups in Troposphere
## Code After:
from core.models import Application as Image

from api import permissions
from api.v2.serializers.details import ImageSerializer
from api.v2.views.base import AuthOptionalViewSet
from api.v2.views.mixins import MultipleFieldLookup


class ImageViewSet(MultipleFieldLookup, AuthOptionalViewSet):

    """
    API endpoint that allows images to be viewed or edited.
    """
    lookup_fields = ("id", "uuid")

    http_method_names = ['get', 'put', 'patch', 'head', 'options', 'trace']

    filter_fields = ('created_by__username', 'tags__name', 'projects__id')

    permission_classes = (permissions.InMaintenance,
                          permissions.ApiAuthOptional,
                          permissions.CanEditOrReadOnly,
                          permissions.ApplicationMemberOrReadOnly)

    serializer_class = ImageSerializer

    search_fields = ('id', 'name', 'versions__change_log', 'tags__name',
                     'tags__description', 'created_by__username',
                     'versions__machines__instance_source__identifier',
                     'versions__machines__instance_source__provider__location')

    def get_queryset(self):
        request_user = self.request.user
        return Image.current_apps(request_user)
