How to use the ara.api.models function in ara

To help you get started, we’ve selected a few ara examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ansible-community / ara / ara / api / views.py View on Github external
class FileViewSet(viewsets.ModelViewSet):
    queryset = models.File.objects.all()
    filterset_class = filters.FileFilter

    def get_serializer_class(self):
        if self.action == "list":
            return serializers.ListFileSerializer
        elif self.action == "retrieve":
            return serializers.DetailedFileSerializer
        else:
            # create/update/destroy
            return serializers.FileSerializer


class RecordViewSet(viewsets.ModelViewSet):
    queryset = models.Record.objects.all()
    filterset_class = filters.RecordFilter

    def get_serializer_class(self):
        if self.action == "list":
            return serializers.ListRecordSerializer
        elif self.action == "retrieve":
            return serializers.DetailedRecordSerializer
        else:
            # create/update/destroy
            return serializers.RecordSerializer
github ansible-community / ara / ara / api / serializers.py View on Github external
def create(self, validated_data):
        file_, created = models.File.objects.get_or_create(
            path=validated_data["path"],
            content=validated_data["content"],
            playbook=validated_data["playbook"],
            defaults=validated_data,
        )
        return file_
github ansible-community / ara / ara / ui / management / commands / generate.py View on Github external
for host in query.all():
            destination = os.path.join(path, "host/%s.html" % host.id)
            serializer = serializers.DetailedHostSerializer(host)
            data = {"host": serializer.data, "static_generation": True}
            self.render("host.html", destination, **data)

        # Results
        query = models.Result.objects.all()
        for result in query.all():
            destination = os.path.join(path, "result/%s.html" % result.id)
            serializer = serializers.DetailedResultSerializer(result)
            data = {"result": serializer.data, "static_generation": True}
            self.render("result.html", destination, **data)

        # Records
        query = models.Record.objects.all()
        for record in query.all():
            destination = os.path.join(path, "record/%s.html" % record.id)
            serializer = serializers.DetailedRecordSerializer(record)
            data = {"record": serializer.data, "static_generation": True}
            self.render("record.html", destination, **data)

        print("[ara] %s files generated." % self.rendered)
github ansible-community / ara / ara / api / views.py View on Github external
if statuses:
            return models.Task.objects.filter(status__in=statuses)
        return models.Task.objects.all()

    def get_serializer_class(self):
        if self.action == "list":
            return serializers.ListTaskSerializer
        elif self.action == "retrieve":
            return serializers.DetailedTaskSerializer
        else:
            # create/update/destroy
            return serializers.TaskSerializer


class HostViewSet(viewsets.ModelViewSet):
    queryset = models.Host.objects.all()
    filterset_class = filters.HostFilter

    def get_serializer_class(self):
        if self.action == "list":
            return serializers.ListHostSerializer
        elif self.action == "retrieve":
            return serializers.DetailedHostSerializer
        else:
            # create/update/destroy
            return serializers.HostSerializer


class ResultViewSet(viewsets.ModelViewSet):
    filterset_class = filters.ResultFilter

    def get_queryset(self):
github ansible-community / ara / ara / api / views.py View on Github external
def get_queryset(self):
        statuses = self.request.GET.getlist("status")
        if statuses:
            return models.Task.objects.filter(status__in=statuses)
        return models.Task.objects.all()
github ansible-community / ara / ara / api / views.py View on Github external
if statuses:
            return models.Result.objects.filter(status__in=statuses)
        return models.Result.objects.all()

    def get_serializer_class(self):
        if self.action == "list":
            return serializers.ListResultSerializer
        elif self.action == "retrieve":
            return serializers.DetailedResultSerializer
        else:
            # create/update/destroy
            return serializers.ResultSerializer


class FileViewSet(viewsets.ModelViewSet):
    queryset = models.File.objects.all()
    filterset_class = filters.FileFilter

    def get_serializer_class(self):
        if self.action == "list":
            return serializers.ListFileSerializer
        elif self.action == "retrieve":
            return serializers.DetailedFileSerializer
        else:
            # create/update/destroy
            return serializers.FileSerializer


class RecordViewSet(viewsets.ModelViewSet):
    queryset = models.Record.objects.all()
    filterset_class = filters.RecordFilter
github ansible-community / ara / ara / api / views.py View on Github external
def get_queryset(self):
        statuses = self.request.GET.getlist("status")
        if statuses:
            return models.Playbook.objects.filter(status__in=statuses)
        return models.Playbook.objects.all()
github ansible-community / ara / ara / api / filters.py View on Github external
("id", "id"),
            ("created", "created"),
            ("updated", "updated"),
            ("started", "started"),
            ("ended", "ended"),
            ("duration", "duration"),
        )
    )
    # fmt: on


class PlayFilter(DateFilter):
    playbook = django_filters.NumberFilter(field_name="playbook__id", lookup_expr="exact")
    uuid = django_filters.UUIDFilter(field_name="uuid", lookup_expr="exact")
    status = django_filters.MultipleChoiceFilter(
        field_name="status", choices=ara_models.Play.STATUS, lookup_expr="iexact"
    )

    # fmt: off
    order = django_filters.OrderingFilter(
        fields=(
            ("id", "id"),
            ("created", "created"),
            ("updated", "updated"),
            ("started", "started"),
            ("ended", "ended"),
            ("duration", "duration"),
        )
    )
    # fmt: on
github ansible-community / ara / ara / api / views.py View on Github external
#
#  ARA is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with ARA.  If not, see .

from rest_framework import viewsets

from ara.api import filters, models, serializers


class LabelViewSet(viewsets.ModelViewSet):
    queryset = models.Label.objects.all()
    filterset_class = filters.LabelFilter

    def get_serializer_class(self):
        if self.action == "list":
            return serializers.ListLabelSerializer
        elif self.action == "retrieve":
            return serializers.DetailedLabelSerializer
        else:
            # create/update/destroy
            return serializers.LabelSerializer


class PlaybookViewSet(viewsets.ModelViewSet):
    filterset_class = filters.PlaybookFilter

    def get_queryset(self):
github ansible-community / ara / ara / ui / management / commands / generate.py View on Github external
def handle(self, *args, **options):
        path = options.get("path")
        self.create_dirs(path)

        # TODO: Leverage ui views directly instead of duplicating logic here
        query = models.Playbook.objects.all()
        serializer = serializers.ListPlaybookSerializer(query.all(), many=True)

        print("[ara] Generating static files for %s playbooks at %s..." % (query.count(), path))

        # Index
        destination = os.path.join(path, "index.html")
        data = {"playbooks": serializer.data, "static_generation": True, "page": "index"}
        self.render("index.html", destination, **data)

        # Escape surrogates to prevent UnicodeEncodeError exceptions
        codecs.register_error("strict", codecs.lookup_error("surrogateescape"))

        # Playbooks
        for playbook in query.all():
            destination = os.path.join(path, "playbook/%s.html" % playbook.id)
            serializer = serializers.DetailedPlaybookSerializer(playbook)