Commit b2294e00e9af616cee39f891d46fc74f655038cb
1 parent
e74bef54
Exists in
master
and in
5 other branches
colocando o campo de public no template de course
Showing
4 changed files
with
61 additions
and
18 deletions
Show diff stats
courses/forms.py
| @@ -42,16 +42,11 @@ class CourseForm(forms.ModelForm): | @@ -42,16 +42,11 @@ class CourseForm(forms.ModelForm): | ||
| 42 | raise forms.ValidationError(_('The end date may not be before the start date.')) | 42 | raise forms.ValidationError(_('The end date may not be before the start date.')) |
| 43 | return end_date | 43 | return end_date |
| 44 | 44 | ||
| 45 | - # init_register_date = forms.DateField(widget=forms.DateField) | ||
| 46 | - # end_register_date = forms.DateField(widget=forms.DateField) | ||
| 47 | - # init_date = forms.DateField(widget=forms.DateField) | ||
| 48 | - # end_date = forms.DateField(widget=forms.DateField) | ||
| 49 | - | ||
| 50 | 45 | ||
| 51 | class Meta: | 46 | class Meta: |
| 52 | model = Course | 47 | model = Course |
| 53 | fields = ('name', 'objectivies', 'content', 'max_students', 'init_register_date', 'end_register_date', | 48 | fields = ('name', 'objectivies', 'content', 'max_students', 'init_register_date', 'end_register_date', |
| 54 | - 'init_date', 'end_date', 'category', 'coordenator') | 49 | + 'init_date', 'end_date', 'category', 'coordenator','public') |
| 55 | labels = { | 50 | labels = { |
| 56 | 'name': _('Name'), | 51 | 'name': _('Name'), |
| 57 | 'objectivies': _('Objectives'), | 52 | 'objectivies': _('Objectives'), |
| @@ -61,8 +56,9 @@ class CourseForm(forms.ModelForm): | @@ -61,8 +56,9 @@ class CourseForm(forms.ModelForm): | ||
| 61 | 'end_register_date': _('Course registration end date'), | 56 | 'end_register_date': _('Course registration end date'), |
| 62 | 'init_date': _('Course start date'), | 57 | 'init_date': _('Course start date'), |
| 63 | 'end_date': _('Course end date'), | 58 | 'end_date': _('Course end date'), |
| 64 | - 'category': _('CourseCategory'), | 59 | + 'category': _('Category'), |
| 65 | 'coordenator': _('Coordenator'), | 60 | 'coordenator': _('Coordenator'), |
| 61 | + 'public':_('Public'), | ||
| 66 | } | 62 | } |
| 67 | help_texts = { | 63 | help_texts = { |
| 68 | 'name': _('Course name'), | 64 | 'name': _('Course name'), |
| @@ -75,16 +71,42 @@ class CourseForm(forms.ModelForm): | @@ -75,16 +71,42 @@ class CourseForm(forms.ModelForm): | ||
| 75 | 'end_date': _('Date that the course ends (dd/mm/yyyy)'), | 71 | 'end_date': _('Date that the course ends (dd/mm/yyyy)'), |
| 76 | 'category': _('CourseCategory which the course belongs'), | 72 | 'category': _('CourseCategory which the course belongs'), |
| 77 | 'coordenator': _('Course Coordenator'), | 73 | 'coordenator': _('Course Coordenator'), |
| 74 | + 'public':_('To define if the course can be accessed by people not registered'), | ||
| 78 | } | 75 | } |
| 79 | 76 | ||
| 80 | widgets = { | 77 | widgets = { |
| 81 | - 'categoy': forms.Select(), | 78 | + 'ategoy': forms.Select(), |
| 82 | 'coordenator': forms.Select(), | 79 | 'coordenator': forms.Select(), |
| 83 | - 'objectivies': SummernoteWidget(attrs={'cols': 80, 'rows': 5}), | ||
| 84 | - 'content': SummernoteWidget(attrs={'cols': 80, 'rows': 5}), | 80 | + 'content': SummernoteWidget(), |
| 81 | + 'objectivies': SummernoteWidget(), | ||
| 85 | } | 82 | } |
| 86 | 83 | ||
| 87 | class UpdateCourseForm(CourseForm): | 84 | class UpdateCourseForm(CourseForm): |
| 85 | + | ||
| 86 | + def clean_end_register_date(self): | ||
| 87 | + init_register_date = self.cleaned_data['init_register_date'] | ||
| 88 | + end_register_date = self.cleaned_data['end_register_date'] | ||
| 89 | + | ||
| 90 | + if init_register_date and end_register_date and end_register_date < init_register_date: | ||
| 91 | + raise forms.ValidationError(_('The end date may not be before the start date.')) | ||
| 92 | + return end_register_date | ||
| 93 | + | ||
| 94 | + def clean_init_date(self): | ||
| 95 | + end_register_date = self.cleaned_data['end_register_date'] | ||
| 96 | + init_date = self.cleaned_data['init_date'] | ||
| 97 | + | ||
| 98 | + if end_register_date and init_date and init_date <= end_register_date: | ||
| 99 | + raise forms.ValidationError(_('The course start date must be after the end of registration.')) | ||
| 100 | + return init_date | ||
| 101 | + | ||
| 102 | + def clean_end_date(self): | ||
| 103 | + init_date = self.cleaned_data['init_date'] | ||
| 104 | + end_date = self.cleaned_data['end_date'] | ||
| 105 | + | ||
| 106 | + if init_date and end_date and end_date < init_date: | ||
| 107 | + raise forms.ValidationError(_('The end date may not be before the start date.')) | ||
| 108 | + return end_date | ||
| 109 | + | ||
| 88 | def __init__(self, *args, **kwargs): | 110 | def __init__(self, *args, **kwargs): |
| 89 | super(UpdateCourseForm, self).__init__(*args, **kwargs) | 111 | super(UpdateCourseForm, self).__init__(*args, **kwargs) |
| 90 | self.fields["students"].required = False | 112 | self.fields["students"].required = False |
| @@ -92,7 +114,7 @@ class UpdateCourseForm(CourseForm): | @@ -92,7 +114,7 @@ class UpdateCourseForm(CourseForm): | ||
| 92 | class Meta: | 114 | class Meta: |
| 93 | model = Course | 115 | model = Course |
| 94 | fields = ('name', 'objectivies', 'content', 'max_students', 'init_register_date', 'end_register_date', | 116 | fields = ('name', 'objectivies', 'content', 'max_students', 'init_register_date', 'end_register_date', |
| 95 | - 'init_date', 'end_date', 'category','students', 'coordenator') | 117 | + 'init_date', 'end_date', 'category','students', 'coordenator','public') |
| 96 | labels = { | 118 | labels = { |
| 97 | 'name': _('Name'), | 119 | 'name': _('Name'), |
| 98 | 'objectivies': _('Objectives'), | 120 | 'objectivies': _('Objectives'), |
| @@ -102,9 +124,10 @@ class UpdateCourseForm(CourseForm): | @@ -102,9 +124,10 @@ class UpdateCourseForm(CourseForm): | ||
| 102 | 'end_register_date': _('Course registration end date'), | 124 | 'end_register_date': _('Course registration end date'), |
| 103 | 'init_date': _('Course start date'), | 125 | 'init_date': _('Course start date'), |
| 104 | 'end_date': _('Course end date'), | 126 | 'end_date': _('Course end date'), |
| 105 | - 'category': _('CourseCategory'), | 127 | + 'category': _('Category'), |
| 106 | 'coordenator': _('Coordenator'), | 128 | 'coordenator': _('Coordenator'), |
| 107 | 'students': _('Student'), | 129 | 'students': _('Student'), |
| 130 | + 'public':_('Public'), | ||
| 108 | } | 131 | } |
| 109 | help_texts = { | 132 | help_texts = { |
| 110 | 'name': _('Course name'), | 133 | 'name': _('Course name'), |
| @@ -118,12 +141,13 @@ class UpdateCourseForm(CourseForm): | @@ -118,12 +141,13 @@ class UpdateCourseForm(CourseForm): | ||
| 118 | 'category': _('CourseCategory which the course belongs'), | 141 | 'category': _('CourseCategory which the course belongs'), |
| 119 | 'coordenator': _('Course Coordenator'), | 142 | 'coordenator': _('Course Coordenator'), |
| 120 | 'students': _("Course's Students"), | 143 | 'students': _("Course's Students"), |
| 144 | + 'public':_('To define if the course can be accessed by people not registered'), | ||
| 121 | } | 145 | } |
| 122 | widgets = { | 146 | widgets = { |
| 123 | 'categoy': forms.Select(), | 147 | 'categoy': forms.Select(), |
| 124 | 'coordenator': forms.Select(), | 148 | 'coordenator': forms.Select(), |
| 125 | - 'objectivies': SummernoteWidget(attrs={'cols': 80, 'rows': 5}), | ||
| 126 | - 'content': SummernoteWidget(attrs={'cols': 80, 'rows': 5}), | 149 | + 'content': SummernoteWidget(), |
| 150 | + 'objectivies': SummernoteWidget(), | ||
| 127 | } | 151 | } |
| 128 | 152 | ||
| 129 | class SubjectForm(forms.ModelForm): | 153 | class SubjectForm(forms.ModelForm): |
courses/templates/course/create.html
| @@ -17,10 +17,17 @@ | @@ -17,10 +17,17 @@ | ||
| 17 | {% csrf_token %} | 17 | {% csrf_token %} |
| 18 | {% for field in form %} | 18 | {% for field in form %} |
| 19 | <div class="form-group {% if form.has_error %} has-error {% endif %} is-fileinput"> | 19 | <div class="form-group {% if form.has_error %} has-error {% endif %} is-fileinput"> |
| 20 | - <label for="{{ field.auto_id }}">{{ field.label }}</label> | 20 | + {% if field.auto_id != 'id_public' %} |
| 21 | + <label for="{{ field.auto_id }}">{{ field.label }}</label> | ||
| 22 | + {% endif %} | ||
| 21 | {% if field.auto_id == 'id_init_register_date' or field.auto_id == 'id_end_register_date' or field.auto_id == 'id_init_date' or field.auto_id == 'id_end_date'%} | 23 | {% if field.auto_id == 'id_init_register_date' or field.auto_id == 'id_end_register_date' or field.auto_id == 'id_init_date' or field.auto_id == 'id_end_date'%} |
| 22 | <input type="text" class="form-control date-picker" name="{{field.name}}" value="{{field.value|date:'SHORT_DATE_FORMAT'}}" min="{{now|date:'SHORT_DATE_FORMAT'}}"> | 24 | <input type="text" class="form-control date-picker" name="{{field.name}}" value="{{field.value|date:'SHORT_DATE_FORMAT'}}" min="{{now|date:'SHORT_DATE_FORMAT'}}"> |
| 23 | - | 25 | + {% elif field.auto_id == 'id_public' %} |
| 26 | + <div class="checkbox"> | ||
| 27 | + <label> | ||
| 28 | + <input type="checkbox" name="{{field.name}}" {% if field.value %}checked="checked"{% endif %}><span class="checkbox-material"></span> {{field.name}} | ||
| 29 | + </label> | ||
| 30 | + </div> | ||
| 24 | {% else %} | 31 | {% else %} |
| 25 | {% render_field field class='form-control' %} | 32 | {% render_field field class='form-control' %} |
| 26 | {% endif %} | 33 | {% endif %} |
| @@ -49,6 +56,8 @@ | @@ -49,6 +56,8 @@ | ||
| 49 | </div> | 56 | </div> |
| 50 | </div> | 57 | </div> |
| 51 | </br> | 58 | </br> |
| 59 | +</br> | ||
| 60 | +</br> | ||
| 52 | <script type="text/javascript"> | 61 | <script type="text/javascript"> |
| 53 | var locale = navigator.language || navigator.userLanguage; | 62 | var locale = navigator.language || navigator.userLanguage; |
| 54 | 63 |
courses/templates/course/update.html
| @@ -16,9 +16,17 @@ | @@ -16,9 +16,17 @@ | ||
| 16 | {% csrf_token %} | 16 | {% csrf_token %} |
| 17 | {% for field in form %} | 17 | {% for field in form %} |
| 18 | <div class="form-group {% if form.has_error %} has-error {% endif %} is-fileinput"> | 18 | <div class="form-group {% if form.has_error %} has-error {% endif %} is-fileinput"> |
| 19 | - <label for="{{ field.auto_id }}">{{ field.label }}</label> | 19 | + {% if field.auto_id != 'id_public' %} |
| 20 | + <label for="{{ field.auto_id }}">{{ field.label }}</label> | ||
| 21 | + {% endif %} | ||
| 20 | {% if field.auto_id == 'id_init_register_date' or field.auto_id == 'id_end_register_date' or field.auto_id == 'id_init_date' or field.auto_id == 'id_end_date'%} | 22 | {% if field.auto_id == 'id_init_register_date' or field.auto_id == 'id_end_register_date' or field.auto_id == 'id_init_date' or field.auto_id == 'id_end_date'%} |
| 21 | <input type="text" class="form-control date-picker" name="{{field.name}}" value="{{field.value|date:'SHORT_DATE_FORMAT'}}" min="{{now|date:'SHORT_DATE_FORMAT'}}"> | 23 | <input type="text" class="form-control date-picker" name="{{field.name}}" value="{{field.value|date:'SHORT_DATE_FORMAT'}}" min="{{now|date:'SHORT_DATE_FORMAT'}}"> |
| 24 | + {% elif field.auto_id == 'id_public' %} | ||
| 25 | + <div class="checkbox"> | ||
| 26 | + <label> | ||
| 27 | + <input type="checkbox" name="{{field.name}}" {% if field.value %}checked="checked"{% endif %}><span class="checkbox-material"></span> {{field.name}} | ||
| 28 | + </label> | ||
| 29 | + </div> | ||
| 22 | {% else %} | 30 | {% else %} |
| 23 | {% render_field field class='form-control' %} | 31 | {% render_field field class='form-control' %} |
| 24 | {% endif %} | 32 | {% endif %} |
courses/views.py
| @@ -216,6 +216,7 @@ class ReplicateCourseView(LoginRequiredMixin, HasRoleMixin, LogMixin, Notificati | @@ -216,6 +216,7 @@ class ReplicateCourseView(LoginRequiredMixin, HasRoleMixin, LogMixin, Notificati | ||
| 216 | context['categorys_courses'] = categorys_courses | 216 | context['categorys_courses'] = categorys_courses |
| 217 | context['title'] = _("Replicate Course") | 217 | context['title'] = _("Replicate Course") |
| 218 | context['now'] = date.today() | 218 | context['now'] = date.today() |
| 219 | + print (course.public) | ||
| 219 | return context | 220 | return context |
| 220 | 221 | ||
| 221 | def get_success_url(self): | 222 | def get_success_url(self): |
| @@ -243,6 +244,7 @@ class UpdateCourseView(LoginRequiredMixin, HasRoleMixin, LogMixin, generic.Updat | @@ -243,6 +244,7 @@ class UpdateCourseView(LoginRequiredMixin, HasRoleMixin, LogMixin, generic.Updat | ||
| 243 | def form_valid(self, form): | 244 | def form_valid(self, form): |
| 244 | self.object = form.save() | 245 | self.object = form.save() |
| 245 | 246 | ||
| 247 | + print (form) | ||
| 246 | self.log_context['course_id'] = self.object.id | 248 | self.log_context['course_id'] = self.object.id |
| 247 | self.log_context['course_name'] = self.object.name | 249 | self.log_context['course_name'] = self.object.name |
| 248 | self.log_context['course_slug'] = self.object.slug | 250 | self.log_context['course_slug'] = self.object.slug |
| @@ -256,7 +258,7 @@ class UpdateCourseView(LoginRequiredMixin, HasRoleMixin, LogMixin, generic.Updat | @@ -256,7 +258,7 @@ class UpdateCourseView(LoginRequiredMixin, HasRoleMixin, LogMixin, generic.Updat | ||
| 256 | def get_context_data(self, **kwargs): | 258 | def get_context_data(self, **kwargs): |
| 257 | context = super(UpdateCourseView, self).get_context_data(**kwargs) | 259 | context = super(UpdateCourseView, self).get_context_data(**kwargs) |
| 258 | course = get_object_or_404(Course, slug = self.kwargs.get('slug')) | 260 | course = get_object_or_404(Course, slug = self.kwargs.get('slug')) |
| 259 | - | 261 | + print (course.public) |
| 260 | if has_role(self.request.user,'system_admin'): | 262 | if has_role(self.request.user,'system_admin'): |
| 261 | courses = Course.objects.all() | 263 | courses = Course.objects.all() |
| 262 | elif has_role(self.request.user,'professor'): | 264 | elif has_role(self.request.user,'professor'): |