Revision af9d484b edumanage/forms.py

b/edumanage/forms.py
7 7
from django.contrib.contenttypes.generic import BaseGenericInlineFormSet
8 8

  
9 9

  
10
import pprint
11

  
10 12
class InstDetailsForm(forms.ModelForm):
11 13

  
12 14
    class Meta:
13
        model = InstitutionDetails
14
        
15

  
15
        model = InstitutionDetails      
16 16

  
17 17
class InstServerForm(forms.ModelForm):
18 18

  
......
24 24
    class Meta:
25 25
        model = ServiceLoc
26 26

  
27
class ContactForm(forms.ModelForm):
28

  
29
    class Meta:
30
        model = Contact
27 31

  
28 32
class NameFormSetFact(BaseGenericInlineFormSet):
29 33
    def clean(self):
30
         super(NameFormSetFact, self).clean()
31
         print "SELLLL", self.forms
34
        if any(self.errors):
35
            return
36
        langs = []
37
        emptyForms = True
38
        for i in range(0, self.total_form_count()):
39
            form = self.forms[i]
40
            pprint.pprint(form.__dict__)
41
            if len(form.cleaned_data) != 0:
42
                emptyForms = False
43
            langs.append(form.cleaned_data.get('lang', None))
44
        if emptyForms:        
45
            raise forms.ValidationError, "Fill in at least one location name in English"
46
        if "en" not in langs:
47
            raise forms.ValidationError, "Fill in at least one location name in English"
48

  
49

  
50
class UrlFormSetFact(BaseGenericInlineFormSet):
51
    def clean(self):
52
        #raise forms.ValidationError, "Clean method called" 
53
        if any(self.errors):
54
            return
55
        pprint.pprint(self.forms)
56
        for i in range(0, self.total_form_count()):
57
            form = self.forms[i]
58
            
59
            pprint.pprint(len(form.cleaned_data))
60
            if len(form.cleaned_data) == 0:
61
                #raise forms.ValidationError, "Fill in at least one url "
62
                pass
63
                #print "ERROROROROR"
64
                #self.append_non_form_error("not enough subs")
65
             #   pass
66
        return
67
                
68
#        raise forms.ValidationError('Invalid date range')
69
         
70
    
71
#    def save(self, commit=True, request=None):
72
#        for uform in self.forms:
73
#            urls = uform.save(commit=False)
74
#            urls.content_object = self.instance
75
#            urls.save()
76
#        return self.save_existing_objects(commit) + self.save_new_objects(commit)
77

  
78

  

Also available in: Unified diff