-def process_zone_file(origin, zonetext):
+def process_zone_file(origin, zonetext):
"""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:
if not str(zone.origin).rstrip('.'):
+ # New zone data is now available
+ # Check if zone already exists in the database.
+ domain_instance = Domain.objects.get(name=origin)
+ except Domain.DoesNotExist:
+ pass # proceed with importing the new zone data
+ # If ``overwrite`` has been checked, then delete the current zone.
+ 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')