Changeset 6347
- Timestamp:
- Oct 17, 2008, 10:58:33 AM (16 years ago)
- Location:
- trunk/exodus
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/exodus/models.py
r6324 r6347 61 61 #XXX: Name Domain perhaps? 62 62 class DnsServer(ExtendedModel): 63 ipaddress = models.IPAddressField() 64 domainname = models.CharField(max_length=50, unique=True) 65 66 def __str__(self): 67 return self.ipaddress 63 ipaddress = models.IPAddressField() 64 domainname = models.CharField(max_length=50, unique=True) 65 66 class Meta: 67 verbose_name = 'Dns Server' 68 69 def __str__(self): 70 return self.ipaddress 68 71 69 72 class Network(ExtendedModel): -
trunk/exodus/urls.py
r6344 r6347 24 24 25 25 # Generic urls 26 (r'^(?P<mode>(add|edit|delete))/(?P<model>.+)/(?P<object>.+)/$', 'exodus.views.genericModel'),27 26 (r'^(?P<mode>(add|edit|delete))/node/(?P<node>.+)/$', 'exodus.views.genericNode'), 28 27 (r'^(?P<mode>(add|edit|delete))/nic/(?P<node>.+)/(?P<interface>.+)/$', 'exodus.views.genericInterface'), 29 28 (r'^(?P<mode>(add|edit|delete))/dhcp/(?P<node>.+)/(?P<interface>.+)/(?P<publicAP>.+)/$', 'exodus.views.genericPublicAP'), 29 (r'^(?P<mode>(add|edit|delete))/(?P<model>.+)/(?P<object>.+)/$', 'exodus.views.genericModel'), 30 30 31 31 # 3th party/embedded database browser -
trunk/exodus/views.py
r6344 r6347 13 13 from exodus.wllogic import freeMasterIP, newSSIDName, addInterlinkIP, freeInterlinkIP, freePublicAPIP 14 14 15 15 def pdebug(level, message): 16 if level > 0: 17 print "DEBUG [%s] %s" % (level, message) 16 18 17 19 class GenericHandler(): 18 20 """Conventions used: type has to to the same name as the dependency object, delet template is named delete<type>.html""" 19 21 def __init__(self, request, mode): 22 pdebug(100, "Function: GenericHandler.__init__") 20 23 # Strip 'Handler' of name 21 24 type = self.__class__.__name__[:-7:] … … 29 32 30 33 if request.POST.has_key('cancel'): 34 pdebug(100, "Action cancel") 31 35 self.form_action = 'cancel' 36 # Allow overriding cancel call, in particular with regards to the 37 # response call 32 38 self._cancel() 33 39 elif request.POST.has_key('proceed'): 40 pdebug(100, "Action proceed") 34 41 self.form_action = 'proceed' 42 43 # Delete does not require a valid form 35 44 if mode == 'delete': 36 45 self._delete() … … 40 49 try: 41 50 if self.form.is_valid(): 51 pdebug(100, "Form valid") 42 52 # Set response on forehand, to allow override in procedure 43 53 try: … … 49 59 _oldInstance = dict(self.object.as_list()) 50 60 _instance = dict(self.form.save(commit=False).as_list()) 51 for key,value in _oldInstance.items(): 52 if value != _instance[key]: 61 for key,value in _instance.items(): 62 if value != _oldInstance[key]: 63 pdebug(100, "Key %s changed value '%s' -> '%s'" % (key, _oldInstance[key], value)) 53 64 self.is_changed[key] = value 54 65 66 # Call override procedure 55 67 if mode == 'add': 56 68 self._add() 57 69 elif mode == 'edit': 58 70 self._edit() 71 else: 72 raise ValueError, 'Mode "%s" not defined' % mode 59 73 else: 60 74 raise ValueError, 'Form error, please edit and resubmit' … … 84 98 85 99 def _add(self): 100 pdebug(100, "Function: GenericHandler._add") 86 101 self.form.save() 87 102 88 103 def _edit(self): 104 pdebug(100, "Function: GenericHandler._edit") 89 105 self.form.save() 90 106 91 107 def _delete(self): 108 pdebug(100, "Function: GenericHandler._delete") 92 109 self.object.delete() 93 110 self.response = HttpResponseRedirect(reverse('exodus.views.viewNode', args=[self.node.name])) 94 111 95 112 def _cancel(self): 113 pdebug(100, "Function: GenericHandler._cancel") 96 114 self.response = HttpResponseRedirect(reverse('exodus.views.viewNode', args=[self.node.name])) 97 115 #self.response = HttpResponseRedirect(reverse('exodus.views.viewNodelist')) 98 116 99 117 def render_to_response(self): 118 pdebug(100, "Function: GenericHandler.render_to_response") 100 119 return self.response 101 120 … … 111 130 112 131 def __init__(self, request, node, interface, publicAP, mode): 132 pdebug(100, "Function: PublicAPHandler.__init__") 113 133 self.node = Node.objects.get(name=node) 114 134 self.interface = Interface.objects.get(node=self.node, iface=interface) … … 121 141 122 142 def _add(self): 143 pdebug(100, "Function: PublicAPHandler._add") 123 144 _instance = self.form.save(commit=False) 124 145 # Find IP range inside interface range with disired size/subnet … … 131 152 132 153 def genericPublicAP(request, node, interface, publicAP, mode): 154 pdebug(100, "Function: genericPublicAP") 133 155 handler = PublicAPHandler(request, node, interface, publicAP, mode) 134 156 return handler.render_to_response() … … 145 167 class InterfaceHandler(GenericHandler): 146 168 def __init__(self, request, node, interface, mode): 169 pdebug(100, "Function: nterfaceHandler.__init__") 147 170 self.node = Node.objects.get(name=node) 148 171 if mode == 'add': … … 153 176 154 177 def _add(self): 178 pdebug(100, "Function: InterfaceHandler._add") 155 179 self._saveInterface() 156 180 157 181 def _edit(self): 182 pdebug(100, "Function: InterfaceHandler._edit") 158 183 self._saveInterface() 159 184 160 185 def _saveInterface(self): 186 pdebug(100, "Function: InterfaceHandler._saveInterface") 161 187 _instance = self.form.save(commit=False) 162 188 if _instance.link and (_instance.type != _instance.link.type): … … 167 193 _instance.mode = 1 # set to master 168 194 169 # Only change IP if changes in interface link/mask 170 if self. is_changed.has_key('link') or self.is_changed.has_key('netmask'):195 # Only change IP if changes in interface link/mask or new of course :-) 196 if self.mode == 'add' or self.is_changed.has_key('link') or self.is_changed.has_key('netmask'): 171 197 if not _instance.link: 172 198 _instance.ip = freeInterlinkIP(_instance) … … 183 209 184 210 def genericInterface(request, node, interface, mode): 211 pdebug(100, "Function: genericInterface") 185 212 handler = InterfaceHandler(request, node, interface, mode) 186 213 return handler.render_to_response() … … 195 222 class NodeHandler(GenericHandler): 196 223 def __init__(self, request, node, mode): 224 pdebug(100, "Function: NodeHandler.__init__") 197 225 if mode == 'add': 198 226 self.node = Node() … … 202 230 203 231 def _add(self): 232 pdebug(100, "Function: NodeHandler._add") 204 233 # input a valid master ip into new_data 205 234 _instance = self.form.save(commit=False) … … 209 238 210 239 def _delete(self): 211 for _master in Interface.objects.filter(node=_instance): 240 pdebug(100, "Function: NodeHandler._delete") 241 for _master in Interface.objects.filter(node=self.object): 212 242 if _master.link == _master: 213 243 for _makeMaster in Interface.objects.filter(link=_master): 214 244 _makeMaster.link = _makeMaster 215 245 _makeMaster.save() 216 _instance.delete()246 self.object.delete() 217 247 # As node is deleted, goto overview page 218 248 self.response = HttpResponseRedirect(reverse('exodus.views.viewNodelist')) 219 249 220 250 def _cancel(self): 251 pdebug(100, "Function: NodeHandler._cancel") 221 252 if self.mode == 'new': 222 253 self.response = HttpResponseRedirect(reverse('exodus.views.viewNodelist')) … … 225 256 226 257 def genericNode(request, node, mode): 258 pdebug(100, "Function: genericNode") 227 259 handler = NodeHandler(request, node, mode) 228 260 return handler.render_to_response() … … 236 268 class LocationHandler(GenericHandler): 237 269 def __init__(self, request, location, mode): 270 pdebug(100, "Function: LocationHandler.__init__") 238 271 if mode == 'add': 239 272 self.location = Location() … … 243 276 244 277 def _add(self): 278 pdebug(100, "Function: LocationHandler._add") 245 279 _instance = self.form.save() 246 280 # After adding a location, allow adding a Node with this location … … 249 283 250 284 def _delete(self): 285 pdebug(100, "Function: LocationHandler._delete") 251 286 self.object.delete() 252 287 self.response = HttpResponseRedirect(reverse('exodus.views.viewNodelist')) 253 288 254 289 def _cancel(self): 290 pdebug(100, "Function: LocationHandler._cancel") 255 291 self.response = HttpResponseRedirect(reverse('exodus.views.viewNodelist')) 256 257 def genericLocation(request, location, mode):258 handler = LocationHandler(request, location, mode)259 return handler.render_to_response()260 261 292 262 293 # 263 294 # Views 264 295 def viewNode(request, node): 296 pdebug(100, "Function: viewNode") 265 297 node = Node.objects.get(name=node) 266 298 return render_to_response('viewNode.html', {'node': node}) 267 299 268 300 def viewNodelist(request): 301 pdebug(100, "Function: viewNodelist") 269 302 nodes = Node.objects.all() 270 303 configFiles = ( … … 277 310 278 311 def configFile(request, version, node, file): 312 pdebug(100, "Function: configFile") 279 313 node = Node.objects.get(name=node) 280 314 … … 287 321 mimetype='text/plain') 288 322 289 def genericLocation(request, location, mode): 290 handler = LocationHandler(request, location, mode) 291 return handler.render_to_response() 323 # 324 # DnsServer 325 class DnsServerForm(forms.ModelForm): 326 class Meta: 327 model = DnsServer 328 329 class DnsServerHandler(GenericHandler): 330 def __init__(self, request, dnsServer, mode): 331 pdebug(100, "Function: DnsServerHandler.__init__") 332 if mode == 'add': 333 self.dnsServer = DnsServer() 334 else: 335 self.dnsServer= DnsServer.objects.get(ipaddress=dnsServer) 336 GenericHandler.__init__(self, request, mode) 337 338 def _add(self): 339 pdebug(100, "Function: DnsServerHandler._add") 340 _instance = self.form.save() 341 self.response = HttpResponseRedirect(reverse('exodus.views.viewList', args=['dnsServer'])) 342 343 def _delete(self): 344 pdebug(100, "Function: DnsServerHandler._delete") 345 self.object.delete() 346 self.response = HttpResponseRedirect(reverse('exodus.views.viewList', args=['dnsServer'])) 347 348 def _cancel(self): 349 pdebug(100, "Function: DnsServerHandler._cancel") 350 self.response = HttpResponseRedirect(reverse('exodus.views.viewList', args=['dnsServer'])) 292 351 293 352 def genericModel(request, model, mode, object): 353 pdebug(100, "Function: genericModel %s, %s, %s" % (model, mode, object)) 294 354 """Wrapper, to get to the function needed""" 295 model = model .capitalize()355 model = model[0].upper() + model[1::] 296 356 model = eval(model + 'Handler') 297 357 handler = model(request, object, mode) … … 299 359 300 360 def viewList(request, model): 361 pdebug(100, "Function: viewList") 301 362 """Standard interface for simple overview pages, with view/edit/delete buttons on it""" 302 363 modelURL = model
Note:
See TracChangeset
for help on using the changeset viewer.