django-powerdns-manager / src / powerdns_manager /

Diff from to


 class SrvRecordModelForm(BaseRecordModelForm):
-    """ModelForm for SRV resource records."""
+    """ModelForm for SRV resource records.
+    For details see docstrings in SoaRecordModelForm.
+    """
+    weight = forms.IntegerField(min_value=1, required=True, label=_('weight'), widget=forms.TextInput(attrs={'size': '3'}), help_text="""A relative weight for records with the same priority.""")
+    port = forms.IntegerField(min_value=1, max_value=65535, required=True, label=_('port'), widget=forms.TextInput(attrs={'size': '5'}), help_text="""The TCP or UDP port on which the service is to be found.""")
+    target = forms.CharField(max_length=128, required=True, label=_('target'), widget=forms.TextInput(attrs={'size': '25'}), help_text="""The canonical hostname of the machine providing the service (no trailing dot).""")
+    def __init__(self, *args, **kwargs):
+        """Set initial values for extra ModelForm fields."""
+        if kwargs.has_key('instance'):
+            instance = kwargs['instance']
+            if is not None:    # This check asserts that this is an EDIT
+                if instance.type == 'SRV':
+                    bits = instance.content.split()
+                    kwargs['initial'] = {
+                        'weight': bits[0],
+                        'port': bits[1],
+                        'target': bits[2],
+                    }
+        super(SrvRecordModelForm, self).__init__(*args, **kwargs)
     def save(self, *args, **kwargs):
         self.instance.type = 'SRV'
+        self.instance.content = '%d %d %s' % (
+            self.cleaned_data.get('weight'),
+            self.cleaned_data.get('port'),
+            self.cleaned_data.get('target'),
+        )
         return super(SrvRecordModelForm, self).save(*args, **kwargs)
 class ARecordModelForm(BaseRecordModelForm):
     """ModelForm for A resource records."""
             raise forms.ValidationError("""Content should contain an IPv4 address""")
             return content
     def save(self, *args, **kwargs):
         self.instance.type = 'A'
         return super(ARecordModelForm, self).save(*args, **kwargs)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.