Commits

George Notaras  committed 2718a49

Moved checks about the existence of the imported zone to the ``process_zone_file`` function.

  • Participants
  • Parent commits ecdeec0

Comments (0)

Files changed (2)

File src/powerdns_manager/utils.py

 
 
 
-def process_zone_file(origin, zonetext):
+def process_zone_file(origin, zonetext, overwrite=False):
     """Imports zone to the database.
     
     No checks for existence are performed in this file. For form processing,
     *****
     Special kudos to Grig Gheorghiu for demonstrating how to manage zone files
     using dnspython in the following article:
-    
-        http://agiletesting.blogspot.com/2005/08/managing-dns-zone-files-with-dnspython.html
+    http://agiletesting.blogspot.com/2005/08/managing-dns-zone-files-with-dnspython.html
     *****
     
     """
         if not str(zone.origin).rstrip('.'):
             raise UnknownOrigin
         
+        # New zone data is now available
+        
+        # Check if zone already exists in the database.
+        try:
+            domain_instance = Domain.objects.get(name=origin)
+        except Domain.DoesNotExist:
+            pass    # proceed with importing the new zone data
+        else:   # Zone exists
+            if overwrite:
+                # If ``overwrite`` has been checked, then delete the current zone.
+                domain_instance.delete()
+            else:
+                raise Exception('Zone already exists. If you wish to replace it with the imported one, check the <em>Overwrite</em> option in the import form.')
+        
+        # Import the new zone data to the database.
+        
         # Create a domain instance
         the_domain = Domain.objects.create(name=str(zone.origin).rstrip('.'), type='NATIVE')
         

File src/powerdns_manager/views.py

             zonetext = form.cleaned_data['zonetext']
             overwrite = form.cleaned_data['overwrite']
             
-            # Check if exists
-            Domain = cache.get_model('powerdns_manager', 'Domain')
             try:
-                domain_instance = Domain.objects.get(name=origin)
-            except Domain.DoesNotExist:
-                pass
-            else:
-                if overwrite:
-                    # If ``overwrite`` has been checked, then delete the current zone.
-                    domain_instance.delete()
-                else:
-                    info_dict = {
-                        'strerror': mark_safe('Zone already exists. If you wish to replace it with the imported one, check the <em>Overwrite</em> option in the import form.'),
-                    }
-                    return render_to_response('powerdns_manager/import/error.html', info_dict, mimetype='text/html')
-            
-            try:
-                process_zone_file(origin, zonetext)
+                process_zone_file(origin, zonetext, overwrite)
             except Exception, e:
                 info_dict = {
-                    'strerror': str(e),
+                    'strerror': mark_safe(str(e)),
                 }
                 return render_to_response('powerdns_manager/import/error.html', info_dict, mimetype='text/html')
             #return HttpResponse('<h1>Success</h1>', content_type="text/html")