- Timestamp:
- Oct 2, 2008, 7:54:36 AM (16 years ago)
- Location:
- trunk/exodus
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/exodus/models.py
r6322 r6323 33 33 class Meta: 34 34 abstract = True 35 verbose_name = 'ExtendedModel' 35 36 36 37 def as_list(self): … … 132 133 desc = models.CharField(max_length=100) 133 134 135 class Meta: 136 verbose_name = "Public Access Point" 137 134 138 def __str__(self): 135 139 return "%s:%s" % (self.iface,self.pk) -
trunk/exodus/views.py
r6322 r6323 3 3 from django.db import models 4 4 from django.http import HttpResponse, HttpResponseRedirect 5 from django.template import loader, Context5 from django.template import Context, loader 6 6 from django.shortcuts import render_to_response 7 7 from django.core.urlresolvers import reverse … … 209 209 exclude = ('shortdesc', 'desc', 'ip', 'dhcpstart', 'dhcpstop') 210 210 211 class GenericHandler(): 212 """Conventions used: type has to to the same name as the dependency object, delet template is named delete<type>.html""" 213 def __init__(self, request, node, interface, publicAP, mode, type): 214 # Find dependencies 215 node = Node.objects.get(name=node) 216 iface = Interface.objects.get(node=node, iface=interface) 217 publicAP = PublicAP(iface=iface) if mode == 'add' else PublicAP.objects.get(iface=iface, pk=publicAP) 218 219 delInclude = 'delete' + type + '.html' 220 221 formClass = eval(type + 'Form') 222 self.object = eval(type[0].lower() + type[1::]) 223 title = self.object._meta.verbose_name 224 225 if request.POST.has_key('cancel'): 226 self.response = HttpResponseRedirect(reverse('node-detail', args=[node])) 227 elif request.POST.has_key('proceed'): 228 if mode == 'delete': 229 self._delete() 230 self.response = HttpResponseRedirect(reverse('node-detail', args=[node])) 231 else: 232 # First checking whether form is valid, then add/edit actions 233 self.form = formClass(request.POST, instance=self.object) 234 if self.form.is_valid(): 235 if mode == 'add': 236 self._add() 237 elif mode == 'edit': 238 self._edit() 239 self.response = HttpResponseRedirect(reverse('node-detail', args=[node])) 240 else: 241 message = 'Form error, please edit and resubmit' 242 self.response = render_to_response('genericForm.html', {'form': self.form, 243 'message' : message, 'title' : title, 'mode' : mode, 244 'delInclude' : delInclude, 'object': self.object }) 245 else: 246 message = 'Please edit and submit' 247 self.form = formClass(instance=self.object) 248 self.response = render_to_response('genericForm.html', {'form': self.form, 249 'message' : message, 'title' : title, 'mode' : mode, 250 'delInclude' : delInclude, 'object': self.object }) 251 252 def _add(self): 253 _instance = self.form.save(commit=False) 254 # Find IP range inside interface range with disired size/subnet 255 _instance.ip = freePublicAPIP(_instance.iface, _instance.netmask) 256 _instance.dhcpstart = 1 257 _instance.dhcpstop = 2 258 # If wireless generate ssid name 259 _instance.ssid = newSSIDName(_instance.iface.node, _instance.iface, 'omni') 260 _instance.save() 261 262 def _edit(self): 263 self.form.save() 264 265 def _delete(self): 266 self.object.delete() 267 268 def render_to_response(self): 269 return self.response 270 211 271 def genericPublicAP(request, node, interface, publicAP, mode): 212 # Find dependencies 213 node = Node.objects.get(name=node) 214 iface = Interface.objects.get(node=node, iface=interface) 215 publicAP = PublicAP(iface=iface) if mode == 'add' else PublicAP.objects.get(iface=iface, pk=publicAP) 216 217 title = 'Public access point' 218 delInclude = 'deletePublicAP.html' 219 220 if request.POST.has_key('cancel'): 221 return HttpResponseRedirect(reverse('node-detail', args=[node])) 222 elif request.POST.has_key('proceed'): 223 if mode == 'delete': 224 publicAP.delete() 225 return HttpResponseRedirect(reverse('node-detail', args=[node])) 226 227 # First checking whether form is valid, then add/edit actions 228 form = PublicAPForm(request.POST, instance=publicAP) 229 if form.is_valid(): 230 if mode == 'add': 231 instance = form.save(commit=False) 232 # Find IP range inside interface range with disired size/subnet 233 instance.ip = freePublicAPIP(instance.iface, instance.netmask) 234 instance.dhcpstart = 1 235 instance.dhcpstop = 2 236 # If wireless generate ssid name 237 instance.ssid = newSSIDName(instance.iface.node, instance.iface, 'omni') 238 instance.save() 239 elif mode == 'edit': 240 form.save() 241 return HttpResponseRedirect(reverse('node-detail', args=[node])) 242 else: 243 message = 'Form error, please edit and resubmit' 244 else: 245 message = 'Please edit and submit' 246 form = PublicAPForm(instance=publicAP) 247 248 return render_to_response('genericForm.html', {'form': form, 249 'message' : message, 'title' : title, 'mode' : mode, 250 'delInclude' : delInclude, 'object': publicAP }) 272 handler = GenericHandler(request, node, interface, publicAP, mode, 'PublicAP') 273 return handler.render_to_response() 251 274 252 275 def nodename2id(node):
Note:
See TracChangeset
for help on using the changeset viewer.