Permalink
Browse files

Adding the create view and many corrections.

  • Loading branch information...
1 parent 83b69fe commit 61d17e3ecd050322e98112d7dad6006b34a7c1e7 root committed Jul 31, 2011
View
@@ -1,18 +1,24 @@
+# -*- coding: utf-8 -*-
+
+import xmlrpclib
+import socket
+
+
class ConnectXMLRPC(object):
- def __init__(self, host=None, port=None):
- self.host = host if host else HOST
- self.port = port if port else PORT
+ def __init__(self, host, port):
+ self.host = host
+ self.port = port
self._connect()
def _connect(self):
try:
self.client = xmlrpclib.ServerProxy('http://%s:%s' % (self.host, self.port), allow_none=True)
except Exception, msg:
- show_error(msg, exit=True)
+ return dict(type='error', message=msg)
-class pyManDNS_Cli_Domain(ConnectXMLRPC):
+class pyManDNS_Cli_Domain(ConnectXMLRPC):
def _kwargs_to_args_ordenated(self, **kwargs):
# The XML-RPC doesn't accept named params. The keys are
# to ordenate the params and use as **params.
@@ -22,7 +28,6 @@ def _kwargs_to_args_ordenated(self, **kwargs):
return [kwargs[k] for k in keys if k in kwargs]
-
def show(self, **kwargs):
"""
Show db file
@@ -32,9 +37,9 @@ def show(self, **kwargs):
try:
result = self.client.domain.show(kwargs["domain"])
- print result
+ return dict(type='success', message='', result=result)
except socket.error, msg:
- show_error(msg, exit=True)
+ return dict(type='error', message=msg)
def delete(self, **kwargs):
"""
@@ -45,10 +50,9 @@ def delete(self, **kwargs):
try:
result = self.client.domain.delete(kwargs["domain"])
- print result
+ return dict(type='success', message='', result=result)
except socket.error, msg:
- show_error(msg, exit=True)
-
+ return dict(type='error', message=msg)
def list(self, limit=False):
"""
@@ -57,15 +61,23 @@ def list(self, limit=False):
try:
domains = self.client.domain.list()
except socket.error, msg:
- show_error(msg, exit=True)
+ return dict(type='error', message=msg)
if limit:
domains = domains[:limit]
- print 'Domain list (total: %d)' % len(domains)
- for domain in domains:
- print '- %s' % domain['domain']
+ return dict(type='success', message='', result=domains)
+ def get(self, domain):
+ """
+ Get one domain, with all details,
+ """
+ try:
+ result = self.client.domain.get(domain=domain)
+ except socket.error, msg:
+ return dict(type='error', message=msg)
+
+ return dict(type='success', message='', result=domain)
def create(self, *args, **kwargs):
"""
@@ -86,13 +98,9 @@ def create(self, *args, **kwargs):
try:
params = self._kwargs_to_args_ordenated(**kwargs)
result = self.client.domain.create(*params)
- print result
+ return dict(type='success', message='', result=result)
except socket.error, msg:
- show_error(msg, exit=True)
-
- #if result == True:
- # msg = 'SUCCESS! The domain %s was created.' % kwargs['domain']
- # show_message(msg, exit=True)
+ return dict(type='error', message=msg)
def update(self, *args, **kwargs):
"""
@@ -113,6 +121,8 @@ def update(self, *args, **kwargs):
try:
params = self._kwargs_to_args_ordenated(**kwargs)
result = self.client.domain.update(*params)
- print result
+ return dict(type='success', message='', result=result)
except socket.error, msg:
- show_error(msg, exit=True)
+ return dict(type='error', message=msg)
+
+
View
@@ -22,6 +22,18 @@ def show(self,v_domain):
return msg
+ ''' Get dominio '''
+ def get(self,v_domain):
+
+ domains_table = self.pyTables.domains_table()
+ records_table = self.pyTables.records_table()
+
+ domains_result = self.engine.execute(
+ domains_table.select().where("domain=:domain"),domain=v_domain)
+ domain_row = domains_result.first()
+
+ return domain_row
+
''' Delete dominio '''
def delete(self,v_domain):
@@ -3,7 +3,7 @@
from django import forms
class DomainForm(forms.Form):
- domain = forms.URLField(label=u'Domain name', max_length=200)
+ domain = forms.CharField(label=u'Domain name', max_length=200)
domain_active = forms.BooleanField(label=u'Domain active?', initial=True, required=False)
soa_ttl = forms.IntegerField(label=u'TTL')
soa_serial = forms.IntegerField(label=u'Serial')
@@ -4,16 +4,19 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
-
- <title>untitled</title>
-
+ <title>PyManDNS</title>
+ <script src="http://ajax.googleapis.com/ajax/libs/dojo/1.6.0/dojo/dojo.xd.js" type="text/javascript"></script>
{% block headtags %}{% endblock %}
</head>
<body>
<div id="site">
<div id="header">
<h1>PyManDNS</h1>
+ <ul id="menu">
+ <li><a href="{% url domain_list %}">List domains</a></li>
+ <li><a href="{% url domain_create %}">Create domain</a></li>
+ </ul>
</div>
<div id="content">
{% for message in messages %}
View
@@ -4,4 +4,5 @@
# Example:
url(r'^$', 'dashboard', name='dashboard'),
url(r'^domain/create/?$', 'domain_create', name='domain_create'),
+ url(r'^domain/list/?$', 'domain_list', name='domain_list'),
)
View
@@ -10,25 +10,43 @@
import settings
+def _get_client():
+ domain_client = pyManDNS_Cli_Domain(settings.MANAGER_HOST, settings.MANAGER_PORT)
+ return domain_client
+
+
def dashboard(request):
return render_to_response('dashboard.html', locals(),
context_instance=RequestContext(request))
+def domain_list(request):
+ try:
+ domain_client = _get_client()
+ result = domain_client.list()
+ domains = result['result']
+ except Exception, e:
+ messages.error(request, u'>>> ERROR: %s' % e)
+
+ return render_to_response('domain_list.html', locals(),
+ context_instance=RequestContext(request))
+
+
def domain_create(request):
if request.method == 'POST':
domain_form = DomainForm(request.POST)
if domain_form.is_valid():
- #import pdb; pdb.set_trace()
-
try:
- domain_client = pyManDNS_Cli_Domain(
- settings.MANAGER_HOST, settings.MANAGER_PORT)
+ domain_client = _get_client()
result = domain_client.create(**domain_form.cleaned_data)
- messages.success(request,
- 'The domain %s was created.' % domain_form.cleaned_data['domain'])
- return redirect('dashboard')
+ if result['type'] == 'success':
+ messages.success(request,
+ u'The domain %s was created.' % domain_form.cleaned_data['domain'])
+ return redirect('dashboard')
+ elif result['type'] == 'error':
+ messages.error(request, result['message'])
+
except Exception, e:
messages.error(request, u'>>> ERROR: %s' % e)
else:
@@ -38,3 +56,31 @@ def domain_create(request):
context_instance=RequestContext(request))
+#def domain_edit(request):
+# if request.method == 'POST':
+# domain_form = DomainForm(request.POST)
+# if domain_form.is_valid():
+# try:
+# domain_client = _get_client()
+# result = domain_client.create(**domain_form.cleaned_data)
+#
+# if result['type'] == 'success':
+# messages.success(request,
+# u'The domain %s was created.' % domain_form.cleaned_data['domain'])
+# return redirect('dashboard')
+# elif result['type'] == 'error':
+# messages.error(request, result['message'])
+#
+# except Exception, e:
+# messages.error(request, u'>>> ERROR: %s' % e)
+# else:
+# try:
+# domain_client = _get_client()
+# result = domain_client.show(**domain_form.cleaned_data)
+# except Exception, e:
+# messages.error(request, u'>>> ERROR: %s' % e)
+# domain_form = DomainForm(initial=)
+#
+# return render_to_response('domain_create.html', locals(),
+# context_instance=RequestContext(request))
+
View
@@ -9,8 +9,8 @@
MANAGERS = ADMINS
-MANAGER_HOST = '192.168.1.204'
-MANAGER_PORT = '3333'
+MANAGER_HOST = '127.0.0.1'
+MANAGER_PORT = '3334'
#DATABASES = {
# 'default': {
View
@@ -81,6 +81,11 @@ def delete(self, domain):
self.domains.remove(d)
return True
+ def get(self, domain):
+ for d in self.domains:
+ if d['domain'] == domain:
+ return d
+
class ServerDNSConfig:
"""

0 comments on commit 61d17e3

Please sign in to comment.