Commit 6a47c7099c30591455352af34ce39796cd960501
1 parent
614033fd
Exists in
master
and in
3 other branches
modified replicate error on redirect and modified forms to accept names not look…
…ing at accent or letter capitalization
Showing
3 changed files
with
26 additions
and
2 deletions
Show diff stats
categories/forms.py
| ... | ... | @@ -9,4 +9,15 @@ class CategoryForm(forms.ModelForm): |
| 9 | 9 | 'description': forms.Textarea, |
| 10 | 10 | 'coordinators' : forms.SelectMultiple, |
| 11 | 11 | } |
| 12 | - | |
| 13 | 12 | \ No newline at end of file |
| 13 | + | |
| 14 | + def clean_name(self): | |
| 15 | + name = self.cleaned_data.get('name') | |
| 16 | + if self.instance.id: | |
| 17 | + same_name = Subject.objects.filter(name__unaccent__iexact = name).exclude(id = self.instance.id) | |
| 18 | + else: | |
| 19 | + same_name = Subject.objects.filter(name__unaccent__iexact = name) | |
| 20 | + | |
| 21 | + if same_name.count() > 0: | |
| 22 | + self._errors['name'] = [_('There is another category with this name, try another one.')] | |
| 23 | + | |
| 24 | + return name | ... | ... |
subjects/forms.py
| ... | ... | @@ -71,6 +71,19 @@ class CreateSubjectForm(forms.ModelForm): |
| 71 | 71 | return ValueError""" |
| 72 | 72 | return cleaned_data |
| 73 | 73 | |
| 74 | + def clean_name(self): | |
| 75 | + name = self.cleaned_data.get('name') | |
| 76 | + if self.instance.id: | |
| 77 | + same_name = Subject.objects.filter(name__unaccent__iexact = name).exclude(id = self.instance.id) | |
| 78 | + else: | |
| 79 | + same_name = Subject.objects.filter(name__unaccent__iexact = name) | |
| 80 | + | |
| 81 | + if same_name.count() > 0: | |
| 82 | + self._errors['name'] = [_('There is another subject with this name, try another one.')] | |
| 83 | + | |
| 84 | + | |
| 85 | + return name | |
| 86 | + | |
| 74 | 87 | def clean_subscribe_begin(self): |
| 75 | 88 | subscribe_begin = self.cleaned_data['subscribe_begin'] |
| 76 | 89 | ... | ... |
subjects/views.py
| ... | ... | @@ -179,7 +179,7 @@ class SubjectCreateView(LoginRequiredMixin, CreateView): |
| 179 | 179 | user = request.user |
| 180 | 180 | pk = user.pk |
| 181 | 181 | if kwargs.get('subject_slug'): |
| 182 | - Subject.objects.filter((Q(professor__pk=pk) | Q(category__coordinators__pk=pk)) & Q(slug = kwargs.get('subject_slug'))) | |
| 182 | + subject = Subject.objects.filter((Q(professor__pk=pk) | Q(category__coordinators__pk=pk)) & Q(slug = kwargs.get('subject_slug'))) | |
| 183 | 183 | if not user.is_staff: |
| 184 | 184 | if subject.count() == 0: |
| 185 | 185 | if request.META.get('HTTP_REFERER'): | ... | ... |