Skip to content
Snippets Groups Projects
Select Git revision
  • 53acfb9b7857a7cb6867b47a1abfe530f76e2aa6
  • renovate/django-split-settings-1.x
  • renovate/djangorestframework-3.x
  • main
  • 520-improve-trackmanager
  • 520-fix-scheduling
  • 520-akowner
  • 520-status
  • 520-message-resolved
  • 520-improve-scheduling-2
  • renovate/django-bootstrap5-24.x
  • 520-improve-submission
  • 520-improve-scheduling
  • 520-improve-wall
  • 520-fix-event-wizard-datepicker
  • 520-upgrades
  • renovate/tzdata-2023.x
  • renovate/django-5.x
  • renovate/fontawesomefree-6.x
  • renovate/sphinx-rtd-theme-2.x
  • renovate/sphinxcontrib-apidoc-0.x
21 results

api.py

Blame
  • Forked from KIF / AKPlanning
    Source project has a limited visibility.
    • Benjamin Hättasch's avatar
      4fa76fdc
      Improve AKSubmission · 4fa76fdc
      Benjamin Hättasch authored
      Add docstrings
      Remove code-duplications for dispatching user selection on submission overview
      Remove code smells
      Remove unused admin.py
      Remove unused view in views
      4fa76fdc
      History
      Improve AKSubmission
      Benjamin Hättasch authored
      Add docstrings
      Remove code-duplications for dispatching user selection on submission overview
      Remove code smells
      Remove unused admin.py
      Remove unused view in views
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    api.py 1.68 KiB
    from rest_framework import permissions, viewsets
    from rest_framework.response import Response
    
    from AKModel.models import Event
    from AKSolverInterface.serializers import ExportEventSerializer
    
    
    class ExportEventForSolverViewSet(viewsets.GenericViewSet):
        """
        API View: Current event, formatted to be consumed by a solver.
        Read-only
    
        Follows the format of the KoMa solver:
        https://github.com/Die-KoMa/ak-plan-optimierung/wiki/Input-&-output-format#input--output-format
        """
    
        permission_classes = (permissions.DjangoModelPermissions,)
        serializer_class = ExportEventSerializer
        lookup_url_kwarg = "event_slug"
        lookup_field = "slug"
        # only allow exporting of active events
        queryset = Event.objects.filter(active=True)
    
        # rename view name to avoid 'List' suffix
        def get_view_name(self):
            return "JSON-Export for scheduling solver"
    
        # somewhat hacky solution: TODO: FIXME
        def list(self, request, *args, **kwargs):
            """Construct HTTP response showing serialized event export."""
            #   Below is the code of mixins.RetrieveModelMixin::retrieve
            #   which would usually be used to serve this detail API page.
            #   However, we do not specify the event to serve at the end of the URL
            #   but instead prepend the URL with it, i.e.
            #   `<slug>/api/<export_endpoint>` instead of the usual `api/<export_endpoint>/<slug>`.
            #   To make this work with the DefaultRouter, we serve this page as a list instead
            #   of a detail page. Hence, we use the method `list` instead of `retrieve`.
            instance = self.get_object()
            serializer = self.get_serializer(instance)
            return Response(serializer.data)