Commit d60e01e7ff6413b98b62e64edd74a76ab31a3287
1 parent
750a4ddb
Exists in
master
and in
3 other branches
criação do form para criar uma web conferencia
Showing
1 changed file
with
21 additions
and
12 deletions
Show diff stats
webconference/forms.py
@@ -2,6 +2,7 @@ | @@ -2,6 +2,7 @@ | ||
2 | from django import forms | 2 | from django import forms |
3 | from django.utils.translation import ugettext_lazy as _ | 3 | from django.utils.translation import ugettext_lazy as _ |
4 | from django.utils.html import strip_tags | 4 | from django.utils.html import strip_tags |
5 | +import datetime | ||
5 | 6 | ||
6 | from subjects.models import Tag | 7 | from subjects.models import Tag |
7 | 8 | ||
@@ -50,25 +51,33 @@ class WebconferenceForm(forms.ModelForm): | @@ -50,25 +51,33 @@ class WebconferenceForm(forms.ModelForm): | ||
50 | same_name = topic.resource_topic.filter(name__unaccent__iexact = name).count() | 51 | same_name = topic.resource_topic.filter(name__unaccent__iexact = name).count() |
51 | 52 | ||
52 | if same_name > 0: | 53 | if same_name > 0: |
53 | - self._errors['name'] = [_('This subject already has a webpage with this name')] | 54 | + self._errors['name'] = [_('This subject already has a web conference with this name')] |
54 | 55 | ||
55 | return ValueError | 56 | return ValueError |
56 | 57 | ||
57 | return name | 58 | return name |
58 | 59 | ||
59 | - # def clean_content(self): | ||
60 | - # content = self.cleaned_data.get('content', '') | ||
61 | - # cleaned_content = strip_tags(content) | ||
62 | - # | ||
63 | - # if cleaned_content == '': | ||
64 | - # self._errors['content'] = [_('This field is required.')] | ||
65 | - # | ||
66 | - # return ValueError | ||
67 | - # | ||
68 | - # return content | 60 | + |
61 | + def clean_start(self): | ||
62 | + start = self.cleaned_data['start'] | ||
63 | + if start.timetuple() < datetime.datetime.now().timetuple(): | ||
64 | + self._errors['start'] = [_('This date must be today or after')] | ||
65 | + return ValueError | ||
66 | + | ||
67 | + return start | ||
68 | + | ||
69 | + def clean_end(self): | ||
70 | + end = self.cleaned_data['end'] | ||
71 | + start = self.cleaned_data['start'] | ||
72 | + | ||
73 | + if start is ValueError or end < start: | ||
74 | + self._errors['end'] = [_('This date must be equal start date/hour or after')] | ||
75 | + return ValueError | ||
76 | + | ||
77 | + return end | ||
69 | 78 | ||
70 | def save(self, commit = True): | 79 | def save(self, commit = True): |
71 | - super(WebpageForm, self).save(commit = True) | 80 | + super(WebconferenceForm, self).save(commit = True) |
72 | 81 | ||
73 | self.instance.save() | 82 | self.instance.save() |
74 | 83 |