Commit f1b417493cad31487a7eab0f08d46cccb6f05ab5
Exists in
master
and in
5 other branches
Merged branch dev into dev
Showing
7 changed files
with
193 additions
and
163 deletions
Show diff stats
core/forms.py
| @@ -37,7 +37,7 @@ class RegisterUserForm(forms.ModelForm): | @@ -37,7 +37,7 @@ class RegisterUserForm(forms.ModelForm): | ||
| 37 | def clean_cpf(self): | 37 | def clean_cpf(self): |
| 38 | cpf = self.cleaned_data['cpf'] | 38 | cpf = self.cleaned_data['cpf'] |
| 39 | if User.objects.filter(cpf = cpf).exists(): | 39 | if User.objects.filter(cpf = cpf).exists(): |
| 40 | - raise forms.ValidationError(_('There is already a registeres User with this CPF')) | 40 | + raise forms.ValidationError(_('There is already a registered User with this CPF')) |
| 41 | # if not self.validate_cpf(cpf): | 41 | # if not self.validate_cpf(cpf): |
| 42 | # raise forms.ValidationError(_('Please enter a valid CPF')) | 42 | # raise forms.ValidationError(_('Please enter a valid CPF')) |
| 43 | return cpf | 43 | return cpf |
| @@ -76,4 +76,4 @@ class RegisterUserForm(forms.ModelForm): | @@ -76,4 +76,4 @@ class RegisterUserForm(forms.ModelForm): | ||
| 76 | model = User | 76 | model = User |
| 77 | # exclude = ['is_staff', 'is_active'] | 77 | # exclude = ['is_staff', 'is_active'] |
| 78 | fields = ['username', 'name', 'email', 'city', 'state', 'gender', 'cpf', 'birth_date', 'phone', 'image', 'titration', | 78 | fields = ['username', 'name', 'email', 'city', 'state', 'gender', 'cpf', 'birth_date', 'phone', 'image', 'titration', |
| 79 | - 'year_titration', 'institution', 'curriculum',] | ||
| 80 | \ No newline at end of file | 79 | \ No newline at end of file |
| 80 | + 'year_titration', 'institution', 'curriculum',] |
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/replicate.html
| 1 | {% extends 'course/view.html' %} | 1 | {% extends 'course/view.html' %} |
| 2 | 2 | ||
| 3 | {% load static i18n %} | 3 | {% load static i18n %} |
| 4 | -{% load widget_tweaks %} | 4 | +{% load widget_tweaks course_value_field %} |
| 5 | 5 | ||
| 6 | {% block breadcrumbs %} | 6 | {% block breadcrumbs %} |
| 7 | <ol class="breadcrumb"> | 7 | <ol class="breadcrumb"> |
| @@ -12,131 +12,79 @@ | @@ -12,131 +12,79 @@ | ||
| 12 | 12 | ||
| 13 | {% block content %} | 13 | {% block content %} |
| 14 | <div class="card card-content"> | 14 | <div class="card card-content"> |
| 15 | - <div class="card-body"> | 15 | + <div class="card-body"> |
| 16 | <form method="post" action="" enctype="multipart/form-data"> | 16 | <form method="post" action="" enctype="multipart/form-data"> |
| 17 | {% csrf_token %} | 17 | {% csrf_token %} |
| 18 | - <div class="form-group is-fileinput"> | ||
| 19 | - <label for="id_name">{% trans 'Name' %}</label> | ||
| 20 | - | ||
| 21 | - | ||
| 22 | - <input class="form-control" id="id_name" maxlength="100" name="name" type="text" required="" value="{{course.name}}"> | ||
| 23 | - | ||
| 24 | - <span class="help-block">{% trans 'Course name' %}</span> | ||
| 25 | - | ||
| 26 | - </div> | ||
| 27 | - | ||
| 28 | - <div class="form-group is-fileinput"> | ||
| 29 | - <label for="id_objectivies">{% trans 'Objectives' %}</label> | ||
| 30 | - | ||
| 31 | - <textarea class="form-control" cols="80" id="id_objectivies" name="objectivies" rows="5">{{ course.objectivies }}</textarea> | ||
| 32 | - | ||
| 33 | - <span class="help-block">{% trans 'Course objective' %}</span> | ||
| 34 | - | ||
| 35 | - </div> | ||
| 36 | - | ||
| 37 | - <div class="form-group is-fileinput"> | ||
| 38 | - <label for="id_content">{% trans 'Content' %}</label> | ||
| 39 | - | ||
| 40 | - | ||
| 41 | - <textarea class="form-control" cols="80" id="id_content" name="content" rows="5">{{course.content}}</textarea> | ||
| 42 | - | ||
| 43 | - <span class="help-block">{% trans 'Course modules' %}</span> | ||
| 44 | - | ||
| 45 | - </div> | ||
| 46 | - | ||
| 47 | - <div class="form-group is-fileinput"> | ||
| 48 | - <label for="id_max_students">{% trans 'Number of studets maximum' %}</label> | ||
| 49 | - | ||
| 50 | - | ||
| 51 | - <input class="form-control" id="id_max_students" min="0" name="max_students" type="number" value="{{course.max_students}}"> | ||
| 52 | - | ||
| 53 | - <span class="help-block">{% trans 'Max number of students that a class can have' %}</span> | ||
| 54 | - | ||
| 55 | - </div> | ||
| 56 | - | ||
| 57 | - <div class="form-group is-fileinput"> | ||
| 58 | - <label for="id_init_register_date">{% trans 'Course registration start date' %}</label> | ||
| 59 | - | ||
| 60 | - | ||
| 61 | - <input type="text" class="form-control date-picker" name="init_register_date" value="{{field.value|date:'SHORT_DATE_FORMAT'}}" min="{{now|date:'SHORT_DATE_FORMAT'}}"> | ||
| 62 | - | ||
| 63 | - <span class="help-block">{% trans 'Date that starts the registration period of the course (dd/mm/yyyy)' %}</span> | ||
| 64 | - | ||
| 65 | - </div> | ||
| 66 | - | ||
| 67 | - <div class="form-group is-fileinput"> | ||
| 68 | - <label for="id_end_register_date">{% trans 'Course registration end date' %}</label> | ||
| 69 | - | ||
| 70 | - | ||
| 71 | - <input type="text" class="form-control date-picker" name="end_register_date" value="{{field.value|date:'SHORT_DATE_FORMAT'}}" min="{{now|date:'SHORT_DATE_FORMAT'}}"> | ||
| 72 | - | ||
| 73 | - <span class="help-block">{% trans 'Date that ends the registration period of the course (dd/mm/yyyy)' %}</span> | ||
| 74 | - | ||
| 75 | - </div> | ||
| 76 | - | ||
| 77 | - <div class="form-group is-fileinput"> | ||
| 78 | - <label for="id_init_date">{% trans 'Course start date' %}</label> | ||
| 79 | - | ||
| 80 | - | ||
| 81 | - <input type="text" class="form-control date-picker" name="init_date" value="{{field.value|date:'SHORT_DATE_FORMAT'}}" min="{{now|date:'SHORT_DATE_FORMAT'}}"> | ||
| 82 | - | ||
| 83 | - <span class="help-block">{% trans 'Date that the course starts (dd/mm/yyyy)' %}</span> | ||
| 84 | - | ||
| 85 | - </div> | ||
| 86 | - | ||
| 87 | - <div class="form-group is-fileinput"> | ||
| 88 | - <label for="id_end_date">{% trans 'Course end date' %}</label> | ||
| 89 | - | ||
| 90 | - | ||
| 91 | - <input type="text" class="form-control date-picker" name="end_date" value="{{field.value|date:'SHORT_DATE_FORMAT'}}" min="{{now|date:'SHORT_DATE_FORMAT'}}"> | ||
| 92 | - | ||
| 93 | - <span class="help-block">{% trans 'Date that the course ends (dd/mm/yyyy)' %}</span> | ||
| 94 | - | ||
| 95 | - </div> | ||
| 96 | - | ||
| 97 | - <div class="form-group is-fileinput"> | ||
| 98 | - <label for="id_image">{% trans 'Imagem' %}</label> | ||
| 99 | - | ||
| 100 | - | ||
| 101 | - <input class="form-control" id="id_image" name="image" type="file"> | ||
| 102 | - <div class="input-group"> | ||
| 103 | - <input type="text" readonly="" class="form-control" placeholder="Choose your photo..."> | ||
| 104 | - <span class="input-group-btn input-group-sm"> | ||
| 105 | - <button type="button" class="btn btn-fab btn-fab-mini"> | ||
| 106 | - <i class="material-icons">{% trans 'attach_file' %}</i> | ||
| 107 | - </button> | ||
| 108 | - </span> | 18 | + {% for field in form %} |
| 19 | + <div class="form-group {% if form.has_error %} has-error {% endif %} is-fileinput"> | ||
| 20 | + {% if field.auto_id != 'id_public' %} | ||
| 21 | + <label for="{{ field.auto_id }}">{{ field.label }}</label> | ||
| 22 | + {% endif %} | ||
| 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'%} | ||
| 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'}}"> | ||
| 25 | + {% elif field.auto_id == 'id_public' %} | ||
| 26 | + {% value_field course field.name as value_field %} | ||
| 27 | + <div class="checkbox"> | ||
| 28 | + <label> | ||
| 29 | + <input type="checkbox" name="{{field.name}}" {% if value_field %}checked="checked"{% endif %}><span class="checkbox-material"></span> {{field.name}} | ||
| 30 | + </label> | ||
| 31 | + </div> | ||
| 32 | + {% else %} | ||
| 33 | + {% if field.errors %} | ||
| 34 | + {% render_field field class='form-control' %} | ||
| 35 | + {% else %} | ||
| 36 | + {% value_field course field.name as value_field %} | ||
| 37 | + {% if field.auto_id == 'id_category' or field.auto_id == 'id_coordenator' %} | ||
| 38 | + {% get_value_choice value_field field.field.choices as field_choice%} | ||
| 39 | + <select class="form-control" id="{{field.auto_id}}" name="{{field.name}}" required=""> | ||
| 40 | + {% for v, name in field.field.choices%} | ||
| 41 | + <option value="{{v}}" {% if field_choice == v %}selected{% endif %}>{{name}}</option> | ||
| 42 | + {% endfor %} | ||
| 43 | + </select> | ||
| 44 | + {% elif field.auto_id == 'id_objectivies' or field.auto_id == 'id_content'%} | ||
| 45 | + <textarea class="form-control" cols="80" id="{{field.auto_id}}" name="{{field.name}}" rows="5">{{value_field}}</textarea> | ||
| 46 | + {% else %} | ||
| 47 | + {% render_field field class='form-control' value=value_field%} | ||
| 48 | + {% endif %} | ||
| 49 | + {% endif %} | ||
| 50 | + {% endif %} | ||
| 51 | + <span class="help-block">{{ field.help_text }}</span> | ||
| 52 | + {% if field.errors %} | ||
| 53 | + <div class="row"> | ||
| 54 | + </br> | ||
| 55 | + <div class="alert alert-danger alert-dismissible" role="alert"> | ||
| 56 | + <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | ||
| 57 | + <span aria-hidden="true">×</span> | ||
| 58 | + </button> | ||
| 59 | + <ul> | ||
| 60 | + {% for error in field.errors %} | ||
| 61 | + <li>{{ error }}</li> | ||
| 62 | + {% endfor %} | ||
| 63 | + </ul> | ||
| 64 | + </div> | ||
| 65 | + </div> | ||
| 66 | + {% endif %} | ||
| 109 | </div> | 67 | </div> |
| 110 | - | ||
| 111 | - <span class="help-block">{% trans 'Representative image of the course' %}</span> | ||
| 112 | - | ||
| 113 | - </div> | ||
| 114 | - | ||
| 115 | - <div class="form-group is-fileinput"> | ||
| 116 | - <label for="id_category">{% trans 'CourseCategory' %}</label> | ||
| 117 | - | ||
| 118 | - | ||
| 119 | - <select class="form-control" id="id_category" name="category" required=""> | ||
| 120 | - {% for category in categorys_courses %} | ||
| 121 | - <option value="{{category.id}}">{{category}}</option> | ||
| 122 | - {% endfor %} | ||
| 123 | - </select> | ||
| 124 | - | ||
| 125 | - <span class="help-block">{% trans 'CourseCategory which the course belongs' %}</span> | ||
| 126 | - | ||
| 127 | - </div> | ||
| 128 | - | 68 | + {% endfor %} |
| 129 | <div class="row text-center"> | 69 | <div class="row text-center"> |
| 130 | - <input type="submit" value="Create" class="btn btn-primary btn-raised"> | 70 | + <input type="submit" value="{% trans 'Create' %}" class="btn btn-primary btn-raised" /> |
| 131 | </div> | 71 | </div> |
| 132 | - </form> | 72 | + </form> |
| 133 | </div> | 73 | </div> |
| 134 | </div> | 74 | </div> |
| 135 | - <script> | ||
| 136 | - $(document).ready(function() { | ||
| 137 | - $('#id_objectivies').summernote(); | ||
| 138 | - $('#id_content').summernote(); | 75 | +</br> |
| 76 | +</br> | ||
| 77 | +</br> | ||
| 78 | +<script type="text/javascript"> | ||
| 79 | + var locale = navigator.language || navigator.userLanguage; | ||
| 80 | + | ||
| 81 | + $('.date-picker').datepicker({ | ||
| 82 | + language: locale, | ||
| 83 | + }); | ||
| 84 | + | ||
| 85 | + $(document).ready(function() { | ||
| 86 | + $('#id_objectivies').summernote({'height':300}); | ||
| 87 | + $('#id_content').summernote({'height':300}); | ||
| 139 | }); | 88 | }); |
| 140 | - </script> | ||
| 141 | -</br></br></br> | 89 | +</script> |
| 142 | {% endblock %} | 90 | {% endblock %} |
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 %} |
| @@ -0,0 +1,53 @@ | @@ -0,0 +1,53 @@ | ||
| 1 | +from django import template | ||
| 2 | + | ||
| 3 | +register = template.Library() | ||
| 4 | + | ||
| 5 | +""" | ||
| 6 | + Template tag to load all the foruns of a post | ||
| 7 | +""" | ||
| 8 | + | ||
| 9 | +@register.simple_tag | ||
| 10 | +def value_field(course, field): | ||
| 11 | + value = "" | ||
| 12 | + if field == 'name': | ||
| 13 | + value = course.name | ||
| 14 | + elif field == 'objectivies': | ||
| 15 | + value = course.objectivies | ||
| 16 | + elif field == 'content': | ||
| 17 | + value = course.content | ||
| 18 | + elif field == 'max_students': | ||
| 19 | + value = course.max_students | ||
| 20 | + elif field == 'init_register_date': | ||
| 21 | + value = course.init_register_date | ||
| 22 | + elif field == 'end_register_date': | ||
| 23 | + value = course.end_register_date | ||
| 24 | + elif field == 'init_date': | ||
| 25 | + value = course.init_date | ||
| 26 | + elif field == 'end_date': | ||
| 27 | + value = course.end_date | ||
| 28 | + elif field == 'coordenator': | ||
| 29 | + value = course.coordenator | ||
| 30 | + elif field == 'category': | ||
| 31 | + value = course.category | ||
| 32 | + elif field == 'professors': | ||
| 33 | + value = course.professors.all() | ||
| 34 | + elif field == 'students': | ||
| 35 | + value = course.students.all() | ||
| 36 | + elif field == 'public': | ||
| 37 | + value = course.public | ||
| 38 | + | ||
| 39 | + return value | ||
| 40 | + | ||
| 41 | + | ||
| 42 | +@register.simple_tag | ||
| 43 | +def get_value_choice(value, choices): | ||
| 44 | + for v, name in choices: | ||
| 45 | + if (str(name) == str(value)): return v | ||
| 46 | + | ||
| 47 | + return "" | ||
| 48 | + | ||
| 49 | +@register.simple_tag | ||
| 50 | +def get_tag(field): | ||
| 51 | + field.value = "cacsdv" | ||
| 52 | + print (dir(field.field)) | ||
| 53 | + print (dir(field.field.widget),field.name,"\n\n\n") |
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'): |
| @@ -445,28 +447,11 @@ class IndexCatView(LoginRequiredMixin, generic.ListView): | @@ -445,28 +447,11 @@ class IndexCatView(LoginRequiredMixin, generic.ListView): | ||
| 445 | 447 | ||
| 446 | login_url = reverse_lazy("core:home") | 448 | login_url = reverse_lazy("core:home") |
| 447 | redirect_field_name = 'next' | 449 | redirect_field_name = 'next' |
| 448 | - queryset = CourseCategory.objects.all() | 450 | + queryset = sorted(CourseCategory.objects.all(),key = lambda x:x.name) |
| 449 | template_name = 'category/index.html' | 451 | template_name = 'category/index.html' |
| 450 | context_object_name = 'categories' | 452 | context_object_name = 'categories' |
| 451 | paginate_by = 5 | 453 | paginate_by = 5 |
| 452 | - | ||
| 453 | - def get_context_data(self, **kwargs): | ||
| 454 | - context = super(IndexCatView, self).get_context_data(**kwargs) | ||
| 455 | - list_cat = CourseCategory.objects.filter(course_category = True).order_by('name') | ||
| 456 | - paginator = Paginator(list_cat, self.paginate_by) | ||
| 457 | - page = self.request.GET.get('page') | ||
| 458 | - | ||
| 459 | - try: | ||
| 460 | - list_cat = paginator.page(page) | ||
| 461 | - except PageNotAnInteger: | ||
| 462 | - list_cat = paginator.page(1) | ||
| 463 | - except EmptyPage: | ||
| 464 | - list_cat = paginator.page(paginator.num_pages) | ||
| 465 | - | ||
| 466 | - context['list_cat'] = list_cat | ||
| 467 | - | ||
| 468 | - return context | ||
| 469 | - | 454 | + |
| 470 | class CreateCatView(LoginRequiredMixin, HasRoleMixin, generic.edit.CreateView): | 455 | class CreateCatView(LoginRequiredMixin, HasRoleMixin, generic.edit.CreateView): |
| 471 | 456 | ||
| 472 | allowed_roles = ['professor', 'system_admin'] | 457 | allowed_roles = ['professor', 'system_admin'] |
| @@ -477,7 +462,8 @@ class CreateCatView(LoginRequiredMixin, HasRoleMixin, generic.edit.CreateView): | @@ -477,7 +462,8 @@ class CreateCatView(LoginRequiredMixin, HasRoleMixin, generic.edit.CreateView): | ||
| 477 | success_url = reverse_lazy('course:manage_cat') | 462 | success_url = reverse_lazy('course:manage_cat') |
| 478 | 463 | ||
| 479 | def get_success_url(self): | 464 | def get_success_url(self): |
| 480 | - messages.success(self.request, _('Category created successfully!')) | 465 | + objeto = self.object.name |
| 466 | + messages.success(self.request, _('Category "%s" created successfully!')%(objeto)) | ||
| 481 | return reverse_lazy('course:manage_cat') | 467 | return reverse_lazy('course:manage_cat') |
| 482 | 468 | ||
| 483 | class UpdateCatView(LoginRequiredMixin, HasRoleMixin, generic.UpdateView): | 469 | class UpdateCatView(LoginRequiredMixin, HasRoleMixin, generic.UpdateView): |
| @@ -488,11 +474,13 @@ class UpdateCatView(LoginRequiredMixin, HasRoleMixin, generic.UpdateView): | @@ -488,11 +474,13 @@ class UpdateCatView(LoginRequiredMixin, HasRoleMixin, generic.UpdateView): | ||
| 488 | template_name = 'category/update.html' | 474 | template_name = 'category/update.html' |
| 489 | model = CourseCategory | 475 | model = CourseCategory |
| 490 | form_class = CategoryCourseForm | 476 | form_class = CategoryCourseForm |
| 477 | + success_url = reverse_lazy('course:manage_cat') | ||
| 491 | 478 | ||
| 492 | def get_success_url(self): | 479 | def get_success_url(self): |
| 493 | - messages.success(self.request, _('Category updated successfully!')) | ||
| 494 | - return reverse_lazy('course:update_cat', kwargs={'slug' : self.object.slug}) | ||
| 495 | - | 480 | + objeto = self.object.name |
| 481 | + messages.success(self.request, _('Category "%s" updated successfully!')%(objeto)) | ||
| 482 | + #return reverse_lazy('course:update_cat', kwargs={'slug' : self.object.slug}) | ||
| 483 | + return reverse_lazy('course:manage_cat') | ||
| 496 | class DeleteCatView(LoginRequiredMixin, HasRoleMixin, generic.DeleteView): | 484 | class DeleteCatView(LoginRequiredMixin, HasRoleMixin, generic.DeleteView): |
| 497 | 485 | ||
| 498 | allowed_roles = ['professor', 'system_admin'] | 486 | allowed_roles = ['professor', 'system_admin'] |