mirror of https://github.com/jumpserver/jumpserver
perf: 修改 applet publications
parent
c8881d56ea
commit
f6fe673b28
|
@ -98,16 +98,6 @@ class AppletViewSet(DownloadUploadMixin, viewsets.ModelViewSet):
|
|||
'download': 'terminal.view_applet',
|
||||
}
|
||||
|
||||
def get_queryset(self):
|
||||
queryset = super().get_queryset()
|
||||
host = self.request.query_params.get('host')
|
||||
|
||||
if not host:
|
||||
return queryset.prefetch_related('publications')
|
||||
else:
|
||||
publications = AppletPublication.objects.filter(host_id=host)
|
||||
return queryset.prefetch_related(Prefetch('publications', queryset=publications))
|
||||
|
||||
def perform_destroy(self, instance):
|
||||
if not instance.name:
|
||||
raise ValidationError('Applet is not null')
|
||||
|
@ -120,3 +110,4 @@ class AppletViewSet(DownloadUploadMixin, viewsets.ModelViewSet):
|
|||
class AppletPublicationViewSet(viewsets.ModelViewSet):
|
||||
queryset = AppletPublication.objects.all()
|
||||
serializer_class = serializers.AppletPublicationSerializer
|
||||
filterset_fields = ['host', 'applet']
|
||||
|
|
|
@ -54,10 +54,6 @@ class Applet(JMSBaseModel):
|
|||
return None
|
||||
return os.path.join(settings.MEDIA_URL, 'applets', self.name, 'icon.png')
|
||||
|
||||
@lazyproperty
|
||||
def publication(self):
|
||||
return self.publications.latest()
|
||||
|
||||
|
||||
class AppletPublication(JMSBaseModel):
|
||||
applet = models.ForeignKey('Applet', on_delete=models.PROTECT, related_name='publications', verbose_name=_('Applet'))
|
||||
|
@ -67,4 +63,3 @@ class AppletPublication(JMSBaseModel):
|
|||
|
||||
class Meta:
|
||||
unique_together = ('applet', 'host')
|
||||
get_latest_by = 'date_created'
|
||||
|
|
|
@ -17,7 +17,7 @@ class AppletUploadSerializer(serializers.Serializer):
|
|||
|
||||
|
||||
class AppletPublicationSerializer(serializers.ModelSerializer):
|
||||
applet = ObjectRelatedField(queryset=Applet.objects.all())
|
||||
applet = ObjectRelatedField(attrs=('id', 'display_name', 'icon'), queryset=Applet.objects.all())
|
||||
host = ObjectRelatedField(queryset=AppletHost.objects.all())
|
||||
status = LabeledChoiceField(choices=Status.choices, label=_("Status"))
|
||||
|
||||
|
@ -31,13 +31,12 @@ class AppletPublicationSerializer(serializers.ModelSerializer):
|
|||
class AppletSerializer(serializers.ModelSerializer):
|
||||
icon = serializers.ReadOnlyField(label=_("Icon"))
|
||||
type = LabeledChoiceField(choices=Applet.Type.choices, label=_("Type"))
|
||||
publication = AppletPublicationSerializer(allow_null=True, label=_("Publication"))
|
||||
|
||||
class Meta:
|
||||
model = Applet
|
||||
fields_mini = ['id', 'name', 'display_name']
|
||||
read_only_fields = [
|
||||
'publication', 'icon', 'date_created', 'date_updated',
|
||||
'icon', 'date_created', 'date_updated',
|
||||
]
|
||||
fields = fields_mini + [
|
||||
'version', 'author', 'type', 'protocols',
|
||||
|
|
Loading…
Reference in New Issue