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 | 42 | raise forms.ValidationError(_('The end date may not be before the start date.')) |
| 43 | 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 | 46 | class Meta: |
| 52 | 47 | model = Course |
| 53 | 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 | 50 | labels = { |
| 56 | 51 | 'name': _('Name'), |
| 57 | 52 | 'objectivies': _('Objectives'), |
| ... | ... | @@ -61,8 +56,9 @@ class CourseForm(forms.ModelForm): |
| 61 | 56 | 'end_register_date': _('Course registration end date'), |
| 62 | 57 | 'init_date': _('Course start date'), |
| 63 | 58 | 'end_date': _('Course end date'), |
| 64 | - 'category': _('CourseCategory'), | |
| 59 | + 'category': _('Category'), | |
| 65 | 60 | 'coordenator': _('Coordenator'), |
| 61 | + 'public':_('Public'), | |
| 66 | 62 | } |
| 67 | 63 | help_texts = { |
| 68 | 64 | 'name': _('Course name'), |
| ... | ... | @@ -75,16 +71,42 @@ class CourseForm(forms.ModelForm): |
| 75 | 71 | 'end_date': _('Date that the course ends (dd/mm/yyyy)'), |
| 76 | 72 | 'category': _('CourseCategory which the course belongs'), |
| 77 | 73 | 'coordenator': _('Course Coordenator'), |
| 74 | + 'public':_('To define if the course can be accessed by people not registered'), | |
| 78 | 75 | } |
| 79 | 76 | |
| 80 | 77 | widgets = { |
| 81 | - 'categoy': forms.Select(), | |
| 78 | + 'ategoy': forms.Select(), | |
| 82 | 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 | 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 | 110 | def __init__(self, *args, **kwargs): |
| 89 | 111 | super(UpdateCourseForm, self).__init__(*args, **kwargs) |
| 90 | 112 | self.fields["students"].required = False |
| ... | ... | @@ -92,7 +114,7 @@ class UpdateCourseForm(CourseForm): |
| 92 | 114 | class Meta: |
| 93 | 115 | model = Course |
| 94 | 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 | 118 | labels = { |
| 97 | 119 | 'name': _('Name'), |
| 98 | 120 | 'objectivies': _('Objectives'), |
| ... | ... | @@ -102,9 +124,10 @@ class UpdateCourseForm(CourseForm): |
| 102 | 124 | 'end_register_date': _('Course registration end date'), |
| 103 | 125 | 'init_date': _('Course start date'), |
| 104 | 126 | 'end_date': _('Course end date'), |
| 105 | - 'category': _('CourseCategory'), | |
| 127 | + 'category': _('Category'), | |
| 106 | 128 | 'coordenator': _('Coordenator'), |
| 107 | 129 | 'students': _('Student'), |
| 130 | + 'public':_('Public'), | |
| 108 | 131 | } |
| 109 | 132 | help_texts = { |
| 110 | 133 | 'name': _('Course name'), |
| ... | ... | @@ -118,12 +141,13 @@ class UpdateCourseForm(CourseForm): |
| 118 | 141 | 'category': _('CourseCategory which the course belongs'), |
| 119 | 142 | 'coordenator': _('Course Coordenator'), |
| 120 | 143 | 'students': _("Course's Students"), |
| 144 | + 'public':_('To define if the course can be accessed by people not registered'), | |
| 121 | 145 | } |
| 122 | 146 | widgets = { |
| 123 | 147 | 'categoy': forms.Select(), |
| 124 | 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 | 153 | class SubjectForm(forms.ModelForm): | ... | ... |
courses/templates/course/create.html
| ... | ... | @@ -17,10 +17,17 @@ |
| 17 | 17 | {% csrf_token %} |
| 18 | 18 | {% for field in form %} |
| 19 | 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 | 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 | 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 | 31 | {% else %} |
| 25 | 32 | {% render_field field class='form-control' %} |
| 26 | 33 | {% endif %} |
| ... | ... | @@ -49,6 +56,8 @@ |
| 49 | 56 | </div> |
| 50 | 57 | </div> |
| 51 | 58 | </br> |
| 59 | +</br> | |
| 60 | +</br> | |
| 52 | 61 | <script type="text/javascript"> |
| 53 | 62 | var locale = navigator.language || navigator.userLanguage; |
| 54 | 63 | ... | ... |
courses/templates/course/update.html
| ... | ... | @@ -16,9 +16,17 @@ |
| 16 | 16 | {% csrf_token %} |
| 17 | 17 | {% for field in form %} |
| 18 | 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 | 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 | 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 | 30 | {% else %} |
| 23 | 31 | {% render_field field class='form-control' %} |
| 24 | 32 | {% endif %} | ... | ... |
courses/views.py
| ... | ... | @@ -216,6 +216,7 @@ class ReplicateCourseView(LoginRequiredMixin, HasRoleMixin, LogMixin, Notificati |
| 216 | 216 | context['categorys_courses'] = categorys_courses |
| 217 | 217 | context['title'] = _("Replicate Course") |
| 218 | 218 | context['now'] = date.today() |
| 219 | + print (course.public) | |
| 219 | 220 | return context |
| 220 | 221 | |
| 221 | 222 | def get_success_url(self): |
| ... | ... | @@ -243,6 +244,7 @@ class UpdateCourseView(LoginRequiredMixin, HasRoleMixin, LogMixin, generic.Updat |
| 243 | 244 | def form_valid(self, form): |
| 244 | 245 | self.object = form.save() |
| 245 | 246 | |
| 247 | + print (form) | |
| 246 | 248 | self.log_context['course_id'] = self.object.id |
| 247 | 249 | self.log_context['course_name'] = self.object.name |
| 248 | 250 | self.log_context['course_slug'] = self.object.slug |
| ... | ... | @@ -256,7 +258,7 @@ class UpdateCourseView(LoginRequiredMixin, HasRoleMixin, LogMixin, generic.Updat |
| 256 | 258 | def get_context_data(self, **kwargs): |
| 257 | 259 | context = super(UpdateCourseView, self).get_context_data(**kwargs) |
| 258 | 260 | course = get_object_or_404(Course, slug = self.kwargs.get('slug')) |
| 259 | - | |
| 261 | + print (course.public) | |
| 260 | 262 | if has_role(self.request.user,'system_admin'): |
| 261 | 263 | courses = Course.objects.all() |
| 262 | 264 | elif has_role(self.request.user,'professor'): | ... | ... |