コード例 #1
0
 def get_form(self, *args, instance, **kwargs) -> ZoneForm:
     form = super().get_form(*args, instance=instance, **kwargs)
     # Create list of all possible provider instances
     providers = get_providers(capabilities=['dns'], path=True)
     provider_instance = ProviderInstance.objects.filter(
         provider_path__in=providers,
         useracquirablerelationship__user__in=[self.request.user])
     form.fields['providers'].queryset = provider_instance
     return form
コード例 #2
0
    def get_form(self, *args, instance: ProviderInstance, **kwargs) -> ProviderForm:
        form = super().get_form(*args, instance=instance, **kwargs)
        providers = get_providers()
        credentials = BaseCredential.objects.filter(owner=self.request.user)
        form_providers = [(class_to_path(s),
                           '%s (%s)' % (s.Meta(None).ui_name, s.__class__.__name__))
                          for s in providers]

        form.request = self.request
        form.fields['provider_path'].choices = form_providers
        form.fields['credentials'].queryset = credentials
        return form
コード例 #3
0
 def get_form(self, step=None, data=None, files=None):
     form = super(ProviderCreateView, self).get_form(step, data, files)
     if step is None:
         step = self.steps.current
     if step == '0':
         self.providers = get_providers()
         creds = BaseCredential.objects.filter(owner=self.request.user)
         form.fields['provider_path'].choices = [(class_to_path(s), s.Meta(None).ui_name)
                                                 for s in self.providers]
         form.fields['credentials'].queryset = creds
         form.request = self.request
     return form
コード例 #4
0
    def get_form(self, step=None, data=None, files=None):
        form = super().get_form(step, data, files)
        if step is None:
            step = self.steps.current
        if step == '0':
            providers = get_providers(capabilities=['dns'], path=True)
            provider_instance = ProviderInstance.objects.filter(
                provider_path__in=providers,
                useracquirablerelationship__user__in=[self.request.user])

            form.fields['providers'].queryset = provider_instance
        return form
コード例 #5
0
    def get_form(self, step=None, data=None, files=None):
        form = super().get_form(step, data, files)
        if step is None:
            step = self.steps.current
        if step == '0':
            domains = Zone.objects.filter(users__in=[self.request.user])
            unused_domains = Domain.objects.filter(users__in=[self.request.user]) \
                .exclude(pk__in=domains.values_list('domain', flat=True))

            providers = get_providers(capabilities=['dns'], path=True)
            provider_instance = ProviderInstance.objects.filter(
                provider_path__in=providers,
                useracquirablerelationship__user__in=[self.request.user])

            form.fields['domain'].queryset = unused_domains
            form.fields['providers'].queryset = provider_instance
        return form
コード例 #6
0
 def clean_credentials(self):
     """Import Provider and check if credentials are compatible"""
     # Import provider based on form
     valid_providers = get_providers(path=True)
     if self.cleaned_data.get('provider_path') not in valid_providers:
         LOGGER.warning('selected provider not in valid_providers list')
         raise Http404
     # also check in form if class exists and is subclass of BaseProvider
     _class = path_to_class(self.cleaned_data.get('provider_path'))
     # Get credentials
     if self.cleaned_data.get('credentials').owner != self.request.user:
         LOGGER.warning(
             "selected credentials owner doesn't match request user")
         raise Http404
     credentials = self.cleaned_data.get('credentials').cast()
     # Check if credentials work with provider
     prov_inst = _class(credentials)
     LOGGER.info("About to provider.check_credentials")
     prov_inst.check_credentials(credentials)
     return self.cleaned_data.get('credentials')
コード例 #7
0
ファイル: migrate.py プロジェクト: BeryJu/supervisr
    def get_form(self, step=None, data=None, files=None):
        form = super(BindZoneImportWizard, self).get_form(step, data, files)
        if step is None:
            step = self.steps.current
        if step == '0':
            # This step should be seperated into the DomainNewWizard, which should run before this
            domains = Zone.objects.filter(users__in=[self.request.user])

            unused_domains = Domain.objects.filter(users__in=[self.request.user]) \
                .exclude(pk__in=domains.values_list('domain', flat=True))

            providers = get_providers(capabilities=['dns'], path=True)
            provider_instance = ProviderInstance.objects.filter(
                provider_path__in=providers,
                useracquirablerelationship__user__in=[self.request.user])

            form.fields['domain'].queryset = unused_domains
            form.fields['providers'].queryset = provider_instance
        elif step == '2':
            if '1-zone_data' in self.request.POST:
                form.records = import_bind(self.request.POST['1-zone_data'])
        return form