From b94f9d8afdd3c12e9b498713541b7b94c5e752cb Mon Sep 17 00:00:00 2001 From: Sanj Date: Tue, 10 Apr 2012 17:51:49 +0530 Subject: [PATCH] changes --- domains/domain/models.py | 37 ++++++++++++++++++++++++++++--------- domains/domain/views.py | 26 ++++++++++++++++++++++++++ domains/settings.py | 13 ++++++++----- domains/urls.py | 2 ++ requirements.txt | 2 ++ 5 files changed, 66 insertions(+), 14 deletions(-) diff --git a/domains/domain/models.py b/domains/domain/models.py index fd8477f..41a6b26 100644 --- a/domains/domain/models.py +++ b/domains/domain/models.py @@ -1,27 +1,46 @@ from django.db import models -from base import BaseModel -from settings import SERVER_CHOICES, EMAIL_CHOICES, DB_CHOICES, PROJECT_TYPES +from base.models import BaseModel +from settings import EMAIL_CHOICES, DB_CHOICES, PROJECT_TYPES, REGISTRAR_CHOICES + class DomainBase(BaseModel): - url = models.CharField(max_length=512) - server = models.CharField(choices=SERVER_CHOICES, blank=True, max_length=128) - email = models.CharField(choices=EMAIL_CHOICES, blank=True) + url = models.CharField(max_length=512, unique=True) + server = models.ForeignKey("Server", blank=True, null=True, max_length=128) + email = models.CharField(max_length=64, choices=EMAIL_CHOICES, blank=True) path = models.CharField(max_length=255, blank=True) - project_type = models.CharField(choices=PROJECT_TYPES, blank=True) - db_type = models.CharField(choices=DB_CHOICES, blank=True) + project_type = models.CharField(max_length=64, choices=PROJECT_TYPES, blank=True) + db_type = models.CharField(max_length=64, choices=DB_CHOICES, blank=True) db_name = models.CharField(max_length=255, blank=True) + is_active = models.BooleanField(default=1) class Meta: abstract = True + ordering = ['url'] def __unicode__(self): return self.url class Domain(DomainBase): - pass + manage_nameserver = models.BooleanField(default=False) + domain_registrar = models.CharField(max_length=128, choices=REGISTRAR_CHOICES) class Subdomain(DomainBase): - main_domain = models.ForeignKey(Domain) \ No newline at end of file + main_domain = models.ForeignKey(Domain) + +class DomainAlias(BaseModel): + alias = models.CharField(max_length=512) + domain = models.ForeignKey(Domain) + + def __unicode__(self): + return self.alias + +class Server(BaseModel): + hostname = models.CharField(max_length=32) + ip_address = models.IPAddressField() + reverse_lookup = models.CharField(max_length=255, blank=True) + + def __unicode__(self): + return "%s" % (self.hostname,) diff --git a/domains/domain/views.py b/domains/domain/views.py index 60f00ef..848f3ee 100644 --- a/domains/domain/views.py +++ b/domains/domain/views.py @@ -1 +1,27 @@ # Create your views here. +from models import * +from django.shortcuts import render_to_response +from django.http import HttpResponse +from django.template.loader import render_to_string + +def named_masters(request): + domains = [d.url for d in Domain.objects.filter(is_active=True).filter(manage_nameserver=True)] + domains += [d.alias for d in DomainAlias.objects.all()] + domains.sort() + context = { + 'domains': domains + } + content = render_to_string("named.conf.masters", context) + return HttpResponse(content, content_type="text/plain") + + +def named_slaves(request): + domains = [d.url for d in Domain.objects.filter(is_active=True).filter(manage_nameserver=True)] + domains += [d.alias for d in DomainAlias.objects.all()] + domains.sort() + context = { + 'domains': domains + } + content = render_to_string("named.conf.slaves", context) + return HttpResponse(content, content_type="text/plain") + diff --git a/domains/settings.py b/domains/settings.py index 026993b..af21379 100644 --- a/domains/settings.py +++ b/domains/settings.py @@ -126,6 +126,9 @@ INSTALLED_APPS = ( 'django.contrib.admin', # Uncomment the next line to enable admin documentation: 'django.contrib.admindocs', + 'django_extensions', + 'base', + 'domain' ) # A sample logging configuration. The only tangible logging @@ -153,11 +156,6 @@ LOGGING = { #Project specific settings: -SERVER_CHOICES = ( - ('camp', 'camp.r-w-x.org'), - ('marlon', 'marlon.in'), -) - EMAIL_CHOICES = ( ('gmail', 'Gmail'), ('mailb', 'MailB'), @@ -174,6 +172,11 @@ PROJECT_TYPES = ( ('www', 'PHP or Static'), ) +REGISTRAR_CHOICES = ( + ('unknown', 'Unknown'), + ('net4', 'Net 4 India'), + ('iwantmyname', 'I Want My Name'), +) #overwrite default settings with local settings try: diff --git a/domains/urls.py b/domains/urls.py index 517d2bd..87bf7ad 100644 --- a/domains/urls.py +++ b/domains/urls.py @@ -13,6 +13,8 @@ urlpatterns = patterns('', # url(r'^admin/doc/', include('django.contrib.admindocs.urls')), # Uncomment the next line to enable the admin: + url(r'^dns/named.conf.masters$', 'domain.views.named_masters', name="named_masters"), + url(r'^dns/named.conf.slaves$', 'domain.views.named_slaves', name="named_slaves"), url(r'^admin/', include(admin.site.urls)), ) diff --git a/requirements.txt b/requirements.txt index fcc7800..df65f11 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,5 @@ Django>=1.4 ox +django_extensions +