diff --git a/courses/forms.py b/courses/forms.py index ac4ce25..8c91ac8 100644 --- a/courses/forms.py +++ b/courses/forms.py @@ -1,7 +1,7 @@ + from django import forms from django.utils.translation import ugettext_lazy as _ from .models import Category, Course, Subject, Topic -import datetime class CategoryForm(forms.ModelForm): @@ -26,9 +26,6 @@ class CourseForm(forms.ModelForm): return end_register_date def clean_init_date(self): - # print(dir(self)) - print (self.data) - print (self.cleaned_data) end_register_date = self.data['end_register_date'] init_date = self.data['init_date'] @@ -78,6 +75,47 @@ class CourseForm(forms.ModelForm): 'content': forms.Textarea(attrs={'cols': 80, 'rows': 5}), } +class UpdateCourseForm(CourseForm): + def __init__(self, *args, **kwargs): + super(UpdateCourseForm, self).__init__(*args, **kwargs) + self.fields["students"].required = False + + class Meta: + model = Course + fields = ('name', 'objectivies', 'content', 'max_students', 'init_register_date', 'end_register_date', + 'init_date', 'end_date', 'image', 'category','students',) + labels = { + 'name': _('Name'), + 'objectivies': _('Objectives'), + 'content': _('Content'), + 'max_students': _('Number of studets maximum'), + 'init_register_date': _('Course registration start date'), + 'end_register_date': _('Course registration end date'), + 'init_date': _('Course start date'), + 'end_date': _('Course end date'), + 'image': _('Image'), + 'category': _('Category'), + 'students': _('Student'), + } + help_texts = { + 'name': _('Course name'), + 'objectivies': _('Course objective'), + 'content': _('Course modules'), + 'max_students': _('Max number of students that a class can have'), + 'init_register_date': _('Date that starts the registration period of the course (dd/mm/yyyy)'), + 'end_register_date': _('Date that ends the registration period of the course (dd/mm/yyyy)'), + 'init_date': _('Date that the course starts (dd/mm/yyyy)'), + 'end_date': _('Date that the course ends (dd/mm/yyyy)'), + 'image': _('Representative image of the course'), + 'category': _('Category which the course belongs'), + 'students': _("Course's Students"), + } + widgets = { + 'categoy': forms.Select(), + 'objectivies': forms.Textarea(attrs={'cols': 80, 'rows': 5}), + 'content': forms.Textarea(attrs={'cols': 80, 'rows': 5}), + } + class SubjectForm(forms.ModelForm): class Meta: diff --git a/courses/permissions.py b/courses/permissions.py index ae72da2..5028e25 100644 --- a/courses/permissions.py +++ b/courses/permissions.py @@ -30,3 +30,23 @@ def delete_subject(role, user, subject): return True return False + +@register_object_checker() +def update_course(role, user, course): + if (role == SystemAdmin): + return True + + if (user in course.professors.all()): + return True + + return False + +@register_object_checker() +def delete_course(role, user, course): + if (role == SystemAdmin): + return True + + if (user in course.professors.all()): + return True + + return False diff --git a/courses/templates/course/create.html b/courses/templates/course/create.html index f34d319..c59784a 100644 --- a/courses/templates/course/create.html +++ b/courses/templates/course/create.html @@ -21,7 +21,7 @@
{% 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'%} - {% render_field field class='form-control' type='date' %} + {% elif field.auto_id == 'id_image' %} {% render_field field class='form-control' %}
diff --git a/courses/templates/course/delete.html b/courses/templates/course/delete.html index 7cadd53..5e2565e 100644 --- a/courses/templates/course/delete.html +++ b/courses/templates/course/delete.html @@ -1,4 +1,4 @@ -{% extends 'app/base.html' %} +{% extends 'course/view.html' %} {% load static i18n %} @@ -9,23 +9,15 @@ {% endblock %} -{% block sidebar %} - - -{% endblock %} - {% block content %} -
- {% csrf_token %} -

{% trans 'Are you sure you want to delete the couse' %} "{{ object }}"?

- - {% trans 'No' %} -
+
+
+
+ {% csrf_token %} +

{% trans 'Are you sure you want to delete the course' %} "{{course}}"?

+ + {% trans 'No' %} +
+
+
{% endblock %} diff --git a/courses/templates/course/index.html b/courses/templates/course/index.html index a160744..16ef05d 100644 --- a/courses/templates/course/index.html +++ b/courses/templates/course/index.html @@ -54,7 +54,11 @@ {% for course in courses %}
+ {% if course.image %} + {% else %} + + {% endif %}
diff --git a/courses/templates/course/update.html b/courses/templates/course/update.html index cfb202a..57919b5 100644 --- a/courses/templates/course/update.html +++ b/courses/templates/course/update.html @@ -1,60 +1,64 @@ -{% extends 'app/base.html' %} +{% extends 'course/view.html' %} {% load static i18n %} {% load widget_tweaks %} {% block breadcrumbs %} {% endblock %} - -{% block sidebar %} - -{% endblock %} - {% block content %} - -
- {% csrf_token %} - {% for field in form %} -
- - {% render_field field class='form-control input-sm' %} - {{ field.help_text }} - {% if field.errors.length > 0 %} -