Changeset 04dab8e


Ignore:
Timestamp:
05/26/11 01:17:37 (2 years ago)
Author:
Tomas Edwardsson <tommi@…>
Branches:
master
Children:
05b0395
Parents:
9caef77
git-author:
Tomas Edwardsson <tommi@…> (05/26/11 01:17:37)
git-committer:
Tomas Edwardsson <tommi@…> (05/26/11 01:17:37)
Message:

Added the addhost wizard and preliminary jquery code.

Location:
adagios
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • adagios/configurator/views.py

    r9caef77 r04dab8e  
    33from django.http import HttpResponse, HttpResponseServerError 
    44from django.utils import simplejson 
     5 
     6# For API methods 
     7import json 
     8import xml.marshal.generic 
    59 
    610from doit import * 
     
    118122                data = '' 
    119123                if ext == 'xml': 
    120                         import xml.marshal.generic 
    121124                        data = xml.marshal.generic.dumps(c['host']) 
     125                        mime_type = 'text/xml' 
    122126                elif ext == 'html': 
    123127                        return render_to_response('configurator/api/host.html', c) 
    124128                elif ext == 'json': 
    125                         import json 
     129                         
    126130                        data = json.dumps(c['host']) 
     131                        mime_type = 'application/json' 
    127132                else: 
    128133                        return HttpResponseServerError("fle") 
    129                 return HttpResponse(data, mimetype='application/javascript') 
     134                return HttpResponse(data, mimetype=mime_type) 
    130135 
    131136        return NotImplementedError 
    132137 
    133 def api_dnslookup(request, host_name=None): 
     138def api_gethostbyname(request, host_name=None): 
    134139        import socket 
    135140         
    136         raise NotImplementedError 
     141        host = '' 
     142        try: 
     143                host = socket.gethostbyname(host_name) 
     144        except: 
     145                pass 
     146         
     147        return HttpResponse(json.dumps({'host': host}), mimetype='application/json')  
    137148 
    138149 
  • adagios/media/css/style.css

    r9caef77 r04dab8e  
    4040        height: 62px; 
    4141        } 
     42 
     43#addhost .label { 
     44        font-weight: bold; 
     45        width: 180px; 
     46        float: left; 
     47} 
  • adagios/templates/configurator/addhost.html

    r9caef77 r04dab8e  
    55 
    66{% block sidebar %} {% endblock %} 
    7 {% block content %} 
     7 
     8{% block javascript %} 
     9 
     10$(document).ready(function() { 
     11  $('#hostname').focus(); 
     12}); 
    813 
    914{% endblock %} 
     15 
     16 
     17{% block content %} 
     18<div id="addhost"> 
     19<form action="#" method="POST"> 
     20<span class="label">Hostname</span> <input id="hostname" type="text" name="hostname" /><br/> 
     21<span class="label">Description</span> <input id="description" type="text" name="description" /><br/> 
     22<span class="label">IP Address</span> <input id="ipaddress" type="text" name="ipaddress" /><br/> 
     23</form> 
     24</div> 
     25 
     26<script type="text/javascript">                                          
     27$('#hostname').blur(function() { 
     28        if ($('#ipaddress').val() == "") { 
     29                $.getJSON("/adagios/api/gethostbyname/" + $('#hostname').val(), function(json) { 
     30                $('#ipaddress').val(json.host); 
     31                }); 
     32        } 
     33}); 
     34 
     35                                  
     36    </script>                                                                 
     37{% endblock %} 
  • adagios/urls.py

    r9caef77 r04dab8e  
    1010    (r'^$', 'configurator.views.home'), 
    1111    (r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}), 
    12     (r'^adagios/api/host/(?P<host_name>.*)\.(?P<ext>.+)$', 'configurator.views.api_host'),  
     12    (r'^adagios/api/host/(?P<host_name>.*)\.(?P<ext>.+)$', 'configurator.views.api_host'), 
     13    (r'^adagios/api/gethostbyname/(?P<host_name>.*)$', 'configurator.views.api_gethostbyname'),  
    1314    (r'^adagios/$', 'configurator.views.index'), 
    1415    (r'^adagios/addhost$', 'configurator.views.addhost'), 
Note: See TracChangeset for help on using the changeset viewer.