Ignore:
Timestamp:
Dec 10, 2008, 7:48:07 AM (16 years ago)
Author:
roland
Message:

Added modelForm with specific WL save function.

Location:
branches/exodus-roland/exodus
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/exodus-roland/exodus/forms.py

    r6420 r6421  
    55
    66class NodeForm(forms.ModelForm):
     7    #masterip = forms.IPAddressField(widget=forms.HiddenInput)
    78    class Meta:
    89       model = Node
     10
     11    def clean_masterip(self):
     12        import pdb; pdb.set_trace() ;
     13        masterip = self.cleaned_data.get('masterip')
     14        if self.instance.pk is None:
     15            masterip = free_masterip()
     16        if masterip:
     17            pass
     18           
     19           
     20        masterip = self.cleaned_data.get('masterip')
     21    def save(self, commit=True):
     22        import pdb; pdb.set_trace() ;
     23       
  • branches/exodus-roland/exodus/models.py

    r6420 r6421  
    7979    status = models.CharField(max_length=10, choices=STATUS_CHOICES , \
    8080        default='up')
     81    network = models.ForeignKey(Network,default=1)
    8182    masterip = models.IPAddressField(unique=True)
    82     network = models.ForeignKey(Network,default=1)
    8383 
    8484    class Meta:
     
    8989        return self.name
    9090
    91     def save(self, force_insert=False, force_update=False):
    92         #XXX: Maybe move this to a model form,
    93         from wllogic import free_masterip
    94         # check if there is a masterip, if not generate one.
    95         # check if there is a network change, if so, generate a new masterip.
    96         if self.masterip:
    97             old = Node.objects.get(pk=self.pk)
    98             if old.network != self.network:
    99                 self.masterip = free_masterip(self.network)
    100         else:
    101             self.masterip = free_masterip(self.network)
    102         super(Node, self).save(force_insert, force_update)
     91   # def save(self, force_insert=False, force_update=False):
     92   #     #XXX: could there be racing conditions?
     93   #     #XXX: Maybe move this to a model form,
     94   #     from wllogic import free_masterip
     95   #     # check if there is a masterip, if not generate one.
     96   #     # check if there is a network change, if so, generate a new masterip.
     97   #     if self.masterip:
     98   #         old = Node.objects.get(pk=self.pk)
     99   #         if old.network != self.network:
     100   #             self.masterip = free_masterip(self.network)
     101   #     else:
     102   #         self.masterip = free_masterip(self.network)
     103   #     super(Node, self).save(force_insert, force_update)
    103104
    104105class Interface(models.Model):
Note: See TracChangeset for help on using the changeset viewer.