Commit 42f7013a93bc62f6f7a6b17bc03713a5291c9b43
1 parent
fc60f8d6
Exists in
master
and in
3 other branches
fixed show all subjects
Showing
4 changed files
with
23 additions
and
3 deletions
Show diff stats
subjects/forms.py
1 | 1 | from django import forms |
2 | 2 | from django.utils.translation import ugettext_lazy as _ |
3 | - | |
3 | +import datetime | |
4 | 4 | from .models import Subject, Tag |
5 | 5 | |
6 | 6 | class CreateSubjectForm(forms.ModelForm): |
... | ... | @@ -58,6 +58,19 @@ class CreateSubjectForm(forms.ModelForm): |
58 | 58 | |
59 | 59 | return self.instance |
60 | 60 | |
61 | + def clean(self): | |
62 | + cleaned_data = super(CreateSubjectForm, self).clean() | |
63 | + print("este") | |
64 | + if cleaned_data['subscribe_begin'] > cleaned_data['end_date']: | |
65 | + raise forms.ValidationError(_('Subscribe period should be between course time')) | |
66 | + return cleaned_data | |
67 | + def clean_subscribe_begin(self): | |
68 | + subscribe_begin = self.cleaned_data['subscribe_begin'] | |
69 | + #if subscribe_begin < datetime.datetime.today().date(): | |
70 | + #self._errors['subscribe_begin'] = _('this date must be today or after') | |
71 | + #raise forms.ValidationError(_('')) | |
72 | + return subscribe_begin | |
73 | + | |
61 | 74 | class CreateTagForm(forms.ModelForm): |
62 | 75 | class Meta: |
63 | 76 | model = Tag | ... | ... |
subjects/models.py
... | ... | @@ -6,6 +6,8 @@ from django.utils.translation import ugettext_lazy as _ |
6 | 6 | |
7 | 7 | from users.models import User |
8 | 8 | |
9 | +from django.core.exceptions import ValidationError | |
10 | + | |
9 | 11 | from categories.models import Category |
10 | 12 | import datetime |
11 | 13 | class Tag(models.Model): |
... | ... | @@ -47,6 +49,11 @@ class Subject(models.Model): |
47 | 49 | def __str__(self): |
48 | 50 | return self.name |
49 | 51 | |
52 | + def clean(self): | |
53 | + | |
54 | + if self.subscribe_begin > self.end_date: | |
55 | + raise ValidationError(_('Subscribe period should be between course time')) | |
50 | 56 | |
57 | + | |
51 | 58 | |
52 | 59 | ... | ... |
subjects/templates/subjects/_form.html
... | ... | @@ -59,7 +59,7 @@ |
59 | 59 | </div> |
60 | 60 | {% elif field.auto_id == 'id_description' or field.auto_id == 'id_description_brief' %} |
61 | 61 | {% render_field field class='form-control text_wysiwyg' %} |
62 | - {% elif field.auto_id == 'id_init_date' or field.auto_id == 'id_end_date' %} | |
62 | + {% elif field.auto_id == 'id_init_date' or field.auto_id == 'id_end_date' or field.auto_id == 'id_subscribe_begin' or field.auto_id == 'id_subscribe_end' %} | |
63 | 63 | {% render_field field class='form-control date-picker' %} |
64 | 64 | {% else %} |
65 | 65 | {% render_field field class='form-control' %} | ... | ... |
subjects/templates/subjects/list.html
... | ... | @@ -99,7 +99,7 @@ |
99 | 99 | |
100 | 100 | <div class="panel-group subject-group" id="{{ category.slug }}-accordion" role="tablist" aria-multiselectable="true"> |
101 | 101 | {% for subject in category.subject_category.all %} |
102 | - {% if request.user in subject.students.all or request.user.is_staff or request.user in subject.professor.all %} | |
102 | + {% if request.user in subject.students.all or request.user.is_staff or request.user in subject.professor.all or all %} | |
103 | 103 | |
104 | 104 | {% include "subjects/subject_card.html" %} |
105 | 105 | {% endif %} | ... | ... |