a #e@sddlZddlmZddlmZddlmZmZddlm Z ddl m Z ddl m Z ddlmZGd d d ejZGd d d eZGd ddejZGddde ZdS)N) FilterSet)get_objects_for_user) serializersviewsets)Response)APIView)ProcessingNode)settingsc@s:eZdZeZeZddZddZGdddZ dS)ProcessingNodeSerializercCs|SN) is_onlineselfobjr"/webodm/app/api/processingnodes.py get_onlinesz#ProcessingNodeSerializer.get_onlinecCst|Sr )strr rrr get_labelsz"ProcessingNodeSerializer.get_labelc@seZdZeZdZdS)zProcessingNodeSerializer.Meta__all__N__name__ __module__ __qualname__rmodelfieldsrrrrMetasrN) rrrrSerializerMethodFieldZonlinelabelrrrrrrrr s r c@s.eZdZejddZddZGdddZdS)ProcessingNodeFilterfilter_has_available_options)methodcCs,|dvr|jtdS|jtdSdS)N)true1)available_options)lowerexcludedictfilter)rquerysetnamevaluerrrr s z1ProcessingNodeFilter.filter_has_available_optionsc@seZdZeZgdZdS)zProcessingNodeFilter.Meta) has_available_optionsidhostnameport api_version queue_count max_imagesrengineengine_versionNrrrrrr#srN)rrrdjango_filters CharFilterr,r rrrrrrs rc@s.eZdZdZeZdZeZe j Z ddZ dS)ProcessingNodeViewSetz Processing node get/add/delete/update Processing nodes are associated with zero or more tasks and take care of processing input images. NcOsV||}tjdur&|dtj}tjr>|D] }|q0|j|dd}t|jS)NT)many) filter_queryset get_querysetr UI_MAX_PROCESSING_NODESNODE_OPTIMISTIC_MODEupdate_node_infoget_serializerrdata)rrequestargskwargsr)Zpn serializerrrrlist4s  zProcessingNodeViewSet.list)rrr__doc__r filter_classpagination_classr serializer_classrobjectsallr)rDrrrrr7's  r7c@s"eZdZdZejZddZdS)ProcessingNodeOptionsViewz Display the common options available among all online processing nodes. This is calculated by intersecting the available_options field of all online processing nodes visible to the current user. cCst|jdtdd}g}|D]n}|s(qt|dkrJt|jdkrJ|j}q|D]8}d}|jD]}|d|dkr\d}qzq\|sNd|d<qNqdd |D}t|S) Nview_processingnodeF)accept_global_permsrr*T_deletecSsg|]}d|vr|qS)rNr).0corrr cz1ProcessingNodeOptionsView.get..)ruserrr lenr$r)rr@nodesZcommon_optionsnodeZ common_optionfoundoptionrrrgetHs"  zProcessingNodeOptionsView.getN) rrrrErrIrJr)rYrrrrrKAs rK)r5Zdjango_filters.rest_frameworkrguardian.shortcutsrrest_frameworkrrrest_framework.responserrest_framework.viewsrnodeodm.modelsrZwebodmr ModelSerializerr r ModelViewSetr7rKrrrrs