Changeset 6320 for trunk


Ignore:
Timestamp:
Sep 30, 2008, 10:07:52 PM (16 years ago)
Author:
RIck van der Zwet
Message:
  • Parsing the right URL to the corresponding object turned out to be a real PITA, created a example of a different URL syntax which will allow more easy parsing to get the right object.
  • Implemented basics of edit/delete public interface
Location:
trunk/exodus
Files:
5 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/exodus/models.py

    r6317 r6320  
    123123
    124124    def __str__(self):
    125         return "%s" % (self.shortdesc)
     125        return "%s:%s" % (self.iface,self.pk)
    126126
    127127class DhcpStatic(models.Model):
  • trunk/exodus/templates/delomni.html

    • Property svn:mergeinfo set to
    r6316 r6320  
    33{% block content %}
    44
    5 <h1>Delete node {{ object.name }}</h1>
    6 
    7 Interfaces to be deleted:
    8 <ol>
    9 {% for nic in  object.interface_set.all %}
    10 <li>{{ nic }}</li>
    11 {% endfor %}
    12 </ol>
    13 
    14 All connected interfaces to be converted to master interfaces:
    15 <ol>
    16 {% for nic in  object.interface_set.all %}
    17         {% ifequal nic.link nic %}
    18                 {% for interlink in nic.link.interface_set.all %}
    19                         {% ifnotequal interlink nic %}
    20                         <li> {{ interlink }}</li>
    21                         {% endifnotequal %}
    22                 {% endfor %}
    23         {% endifequal %}
    24 {% endfor %}
    25 </ol>
     5<h1>Delete Public Access Point {{ object.name }}</h1>
    266
    277<form method="post" action=".">
  • trunk/exodus/templates/exodus-template.html

    r6317 r6320  
    1111  <TR>
    1212    <td class="menu" valign="top">
     13      <div style="min-height:400px">
    1314          <A name="top"><img width="130" height="82" alt="logo" src="{% url static path="logo.png" %}" border=0></A><br>
    1415          <img width="130" height="97" alt="foto" src="{% url static path="foto.jpg" %}"/><br>
     
    1718          &nbsp;&nbsp;<A class="menu" href="{% url exodus.views.addLocation %}">Add Location</a><br>
    1819          &nbsp;&nbsp;<A class="menu" href="{% url exodus.views.addNode %}">Add Node</a><br>
     20          </div>
    1921        </td>
    2022        <td valign="top" class="right">
  • trunk/exodus/templates/node-detail.html

    r6317 r6320  
    55
    66<div style="border:1px solid #000000;">
    7 <h1> {{ object.name }} </h1>
     7<h1> {{ node.name }} </h1>
    88<h3> Location </h3>
    9 Description: {{ object.location.description }} <br>
    10 Longitude: {{ object.location.longitude }} <br>
    11 Latitude: {{ object.location.latitude }} <br>
     9Description: {{ node.location.description }} <br>
     10Longitude: {{ node.location.longitude }} <br>
     11Latitude: {{ node.location.latitude }} <br>
    1212
    13 Master ip: {{ object.masterip }} <br>
    14 <a href="{% url exodus.views.editNode object %}">EDIT</a>
    15 <a href="{% url exodus.views.delNode object %}">DELETE</a>
     13Master ip: {{ node.masterip }} <br>
     14<a href="{% url exodus.views.editNode node %}">EDIT</a>
     15<a href="{% url exodus.views.delNode node %}">DELETE</a>
    1616</div>
    1717
    1818<h2>Interfaces</h2>
    19 <a href="{% url exodus.views.addInterface %}?node={{ object.name }}">Add new interface</a><p />
     19<a href="{% url exodus.views.addInterface %}?node={{ node.name }}">Add new interface</a><p />
    2020
    21 {% for nic in object.interface_set.all %}
     21{% for nic in node.interface_set.all %}
     22        <div style="border:1px solid #000000;">
    2223        <div style="border:1px solid #000000;">
    2324        <h3>iface: {{ nic.iface }} </h3>
     
    5152                {% endifnotequal %}
    5253        {% endfor %}
    53        
    54         <ul>
     54        <ol>
    5555        {% for accessPoint in nic.ap.all %}
    5656                <div style="border:1px solid #000000;">
    5757                <p />
    5858                <li>Public Access Point: {{ accessPoint.ip}}/{{accessPoint.netmask }}
     59                <a href="{% url exodus.views.editPublicAP node.name nic.iface accessPoint.pk %}">EDIT</a>
     60                <a href="{% url exodus.views.delPublicAP accessPoint %}">DELETE</a>
    5961                {% for dhcp in accessPoint.dhcpstatic.all %}
    6062                        <ul>
     
    6769                </div>
    6870        {% endfor %}
    69         </ul>
     71        </ol>
     72        </div>
     73        <p />
    7074{% endfor %}
    7175
  • trunk/exodus/urls.py

    r6315 r6320  
    3030        url(r'^$', 'django.views.generic.simple.direct_to_template', {'template': 'index.html'}, "root") ,
    3131        url(r'^nodelist/$', 'django.views.generic.list_detail.object_list', dict(node_dict, template_name='node-list.html'), "nodelist"),
    32         url(r'^view/node/(?P<slug>.+)/$', 'django.views.generic.list_detail.object_detail', dict(node_dict,slug_field='name',template_name='node-detail.html'), "node-detail"),
     32        url(r'^view/node/(?P<node>.+)/$', 'exodus.views.node', {}, "node-detail"),
    3333
    3434        # config urls
     
    5050        (r'^edit/nic/(?P<objectId>.+)/$', 'exodus.views.editInterface'),
    5151        (r'^edit/link/(?P<object_id>.+)/$', 'exodus.views.addLink'),
    52         (r'^edit/dhcp/(?P<object_id>.+)/$', 'exodus.views.addPublicAP'),
     52        (r'^edit/dhcp/(?P<node>.+)/(?P<interface>.+)/(?P<publicAP>.+)/$', 'exodus.views.editPublicAP'),
    5353
    5454        # delete/remove urls
    5555        (r'^delete/node/(?P<objectId>.+)/$', 'exodus.views.delNode'),
    5656        (r'^delete/nic/(?P<objectId>.+)/$', 'exodus.views.delInterface'),
     57        (r'^delete/dhcp/(?P<objectId>.+)/$', 'exodus.views.delPublicAP'),
    5758)
    5859
  • trunk/exodus/views.py

    r6317 r6320  
    3131                model = Node
    3232                exclude = ( 'masterip' )
     33
     34def node(request, node):
     35        object = Node.objects.get(name=node)
     36        return render_to_response('node-detail.html', {'node': object})
    3337
    3438def addNode(request):
     
    200204        return render_to_response('addinterlink.html',{'form': form})
    201205
    202 class addPublicAPForm(forms.ModelForm):
     206class AddPublicAPForm(forms.ModelForm):
    203207        class Meta:
    204208                model = PublicAP
     
    207211def addPublicAP(request):
    208212        if request.POST:
    209                 form = addPublicAPForm(request.POST)
     213                form = AddPublicAPForm(request.POST)
    210214                if form.is_valid():
    211215                        instance = form.save(commit=False)
     
    225229                        newPublicAP = PublicAP()
    226230                        newPublicAP.iface = Interface.objects.get(iface=interfaceName, node=nodename2id(nodeName))
    227                         form = addPublicAPForm(instance=newPublicAP)
    228                 else:
    229                         form = addPublicAPForm()
     231                        form = AddPublicAPForm(instance=newPublicAP)
     232                else:
     233                        form = AddPublicAPForm()
    230234        return render_to_response('addomni.html', {'form': form })
     235
     236def editPublicAP(request, node, interface, publicAP):
     237        nodeID = Node.objects.get(name=node)
     238        iface = Interface.objects.get(node=nodeID, iface=interface)
     239        publicAP = PublicAP.objects.get(iface=iface, pk=publicAP)
     240        if request.POST:
     241                form = AddPublicAPForm(request.POST, instance=publicAP)
     242                if form.is_valid():
     243                        form.save()
     244                        #Properly redirect to view/<Node> needed
     245                        message = 'Node Updated succesfully'
     246                        node = publicAP.iface.node
     247                        return HttpResponseRedirect(reverse('node-detail', args=[node]))
     248                else:
     249                        message = 'Form error, please edit and resubmit'
     250        else:
     251                message = 'Please edit and submit'
     252                form = AddPublicAPForm(instance=publicAP)
     253        return render_to_response('addnode.html', {'form': form, 'message' : message })
     254
     255def delPublicAP(request, objectId):
     256        publicAP = PublicAP.objects.get(name=objectId)
     257        node = publicAP.iface.node
     258        if request.POST.has_key('cancel'):
     259                return HttpResponseRedirect(reverse('node-detail', args=[node]))
     260        elif request.POST.has_key('proceed'):
     261                publicAP.delete()
     262                return HttpResponseRedirect(reverse('node-detail', args=[node]))
     263        else:
     264                return render_to_response('delomni.html', {'object': publicAP })
    231265
    232266def nodename2id(node):
Note: See TracChangeset for help on using the changeset viewer.