Commit d0923db7e26559cadd4dfa15ebd63f88fa51c1fe
1 parent
7c54fb04
Exists in
master
and in
2 other branches
Fixing condition that allow only one repository per subject
Showing
1 changed file
with
19 additions
and
0 deletions
Show diff stats
topics/forms.py
... | ... | @@ -14,6 +14,25 @@ class TopicForm(forms.ModelForm): |
14 | 14 | |
15 | 15 | self.subject = kwargs['initial'].get('subject', None) |
16 | 16 | |
17 | + if self.instance and self.instance.id: | |
18 | + if self.instance.repository: | |
19 | + self.fields['name'].widget.attrs['readonly'] = True | |
20 | + | |
21 | + | |
22 | + def clean_repository(self): | |
23 | + repository = self.cleaned_data.get('repository', False) | |
24 | + | |
25 | + if not self.instance.id: | |
26 | + if repository: | |
27 | + has_repo = self.subject.topic_subject.filter(repository = True).exists() | |
28 | + | |
29 | + if has_repo: | |
30 | + self._errors['repository'] = [_('This subject already has a repository')] | |
31 | + | |
32 | + return ValueError | |
33 | + | |
34 | + return repository | |
35 | + | |
17 | 36 | def clean_name(self): |
18 | 37 | name = self.cleaned_data.get('name', '') |
19 | 38 | repo = self.cleaned_data.get('repository', False) | ... | ... |