- Timestamp:
- Oct 2, 2008, 10:15:12 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/exodus/views.py
r6325 r6327 25 25 self.title = self.object._meta.verbose_name 26 26 self.request = request 27 self.mode = mode 28 self.is_changed = {} 27 29 28 30 if request.POST.has_key('cancel'): 29 self.response = HttpResponseRedirect(reverse('exodus.views.viewNode', args=[self.node.name])) 31 self.form_action = 'cancel' 32 self._cancel() 30 33 elif request.POST.has_key('proceed'): 34 self.form_action = 'proceed' 31 35 if mode == 'delete': 32 self._deleteete() 33 self.response = HttpResponseRedirect(reverse('exodus.views.viewNode', args=[self.node.name])) 36 self._delete() 34 37 else: 35 38 # First checking whether form is valid, then add/edit actions 36 39 self.form = formClass(request.POST, instance=self.object) 37 if self.form.is_valid(): 38 # Set response on forehand, to allow override in procedure 39 self.response = HttpResponseRedirect(reverse('exodus.views.viewNode', args=[self.node.name])) 40 if mode == 'add': 41 self._add() 42 elif mode == 'edit': 43 self._edit() 44 else: 45 message = 'Form error, please edit and resubmit' 46 self.response = render_to_response('genericForm.html', {'form': self.form, 47 'message' : message, 'title' : self.title, 'mode' : mode, 48 'type' : type, 'object': self.object }) 40 try: 41 if self.form.is_valid(): 42 # Set response on forehand, to allow override in procedure 43 self.response = HttpResponseRedirect(reverse('exodus.views.viewNode', args=[self.node.name])) 44 45 #Checking whether data did change 46 _oldInstance = dict(self.object.as_list()) 47 _instance = dict(self.form.save(commit=False).as_list()) 48 for key,value in _oldInstance.items(): 49 if value != _instance[key]: 50 self.is_changed[key] = value 51 52 if mode == 'add': 53 self._add() 54 elif mode == 'edit': 55 self._edit() 56 else: 57 raise ValueError, 'Form error, please edit and resubmit' 58 except ValueError, message: 59 self.response = render_to_response('genericForm.html', { 60 'form': self.form, 'message' : message, 'title' : self.title, 61 'mode' : mode, 'type' : type, 'object': self.object, 62 'delInclude' : "delete" + type.capitalize() + ".html", 63 'addInclude' : "add" + type.capitalize() + ".html", 64 'editInclude' : "edit" + type.capitalize() + ".html" }) 49 65 else: 50 66 message = 'Please edit and submit' … … 56 72 else: 57 73 self.form = formClass(instance=self.object) 58 74 59 75 self.response = render_to_response('genericForm.html', { 60 76 'form': self.form, 'message' : message, 'title' : self.title, … … 63 79 'addInclude' : "add" + type.capitalize() + ".html", 64 80 'editInclude' : "edit" + type.capitalize() + ".html" }) 65 81 66 82 def _add(self): 67 83 self.form.save() 68 84 69 85 def _edit(self): 70 86 self.form.save() 71 72 def _delete ete(self):87 88 def _delete(self): 73 89 self.object.delete() 90 self.response = HttpResponseRedirect(reverse('exodus.views.viewNode', args=[self.node.name])) 91 92 def _cancel(self): 93 self.response = HttpResponseRedirect(reverse('exodus.views.viewNode', args=[self.node.name])) 94 #self.response = HttpResponseRedirect(reverse('exodus.views.viewNodelist')) 74 95 75 96 def render_to_response(self): … … 85 106 86 107 class PublicAPHandler(GenericHandler): 108 87 109 def __init__(self, request, node, interface, publicAP, mode): 88 110 self.node = Node.objects.get(name=node) … … 134 156 135 157 def _saveInterface(self): 136 #XXX: Should have checking wether form has actually been changed to avoid creation of IPs every time137 158 _instance = self.form.save(commit=False) 159 if _instance.link and (_instance.type != _instance.link.type): 160 raise ValueError,'Type of local and remote interface needs to match' 138 161 if str(_instance.type) != "eth": 139 162 _instance.ssid = newSSIDName(_instance.node, _instance.iface, 'unused') 140 163 _instance.channel = '1' 141 164 _instance.mode = 1 # set to master 142 if not _instance.link: 143 _instance.ip = freeInterlinkIP(_instance) 144 else: 145 _instance.ip = addInterlinkIP(_instance.link) 165 166 # Only change IP if changes in interface link/mask 167 if self.is_changed.has_key('link') or self.is_changed.has_key('netmask'): 168 if not _instance.link: 169 _instance.ip = freeInterlinkIP(_instance) 170 else: 171 _instance.ip = addInterlinkIP(_instance.link) 172 173 # XXX: Change in netmask requires full range of netmask changes on slaves 146 174 _instance.save() 147 175 #Dirty to hack to get reference to self working … … 184 212 _instance.delete() 185 213 # As node is deleted, goto overview page 186 self.response = HttpResponseRedirect(reverse('node-overview')) 214 self.response = HttpResponseRedirect(reverse('exodus.views.viewNodelist')) 215 216 def _cancel(self): 217 if self.mode == 'new': 218 self.response = HttpResponseRedirect(reverse('exodus.views.viewNodelist')) 219 else: 220 self.response = HttpResponseRedirect(reverse('exodus.views.viewNode', args=[self.node.name])) 187 221 188 222 def genericNode(request, node, mode): … … 212 246 def _delete(self): 213 247 self.object.delete() 214 self.response = HttpResponseRedirect(reverse('node-overview')) 248 self.response = HttpResponseRedirect(reverse('exodus.views.viewNodelist')) 249 250 def _cancel(self): 251 self.response = HttpResponseRedirect(reverse('exodus.views.viewNodelist')) 215 252 216 253 def genericLocation(request, location, mode):
Note:
See TracChangeset
for help on using the changeset viewer.