diff --git a/courses/forms.py b/courses/forms.py index c318ce5..335e504 100644 --- a/courses/forms.py +++ b/courses/forms.py @@ -1,145 +1,17 @@ -from django import forms -from django.utils.translation import ugettext_lazy as _ -from .models import CourseCategory, Course, Subject, Topic, ActivityFile, Activity, FileMaterial, LinkMaterial -from s3direct.widgets import S3DirectWidget -from django_summernote.widgets import SummernoteWidget - +from django import forms from django.utils.translation import ugettext_lazy as _ from .models import CourseCategory, Course, Subject, Topic, ActivityFile, Activity, FileMaterial, LinkMaterial from s3direct.widgets import S3DirectWidget from django_summernote.widgets import SummernoteWidget class CategoryCourseForm(forms.ModelForm): - - class Meta: - model = CourseCategory - fields = ('name',) - labels = { - 'name': _('Name') - } - help_texts = { - 'name': _('CourseCategory name') - } - + class Meta: model = CourseCategory fields = ('name',) labels = { 'name': _('Name') } help_texts = { 'name': _('CourseCategory name') } class CourseForm(forms.ModelForm): - - class Meta: - model = Course - fields = ('name', 'category', 'coordenator','public') - labels = { - 'name': _('Name'), - 'category': _('Category'), - 'coordenator': _('Coordenator'), - 'public':_('Public'), - } - help_texts = { - 'name': _('Course name'), - 'coordenator': _('Course Coordenator'), - 'public':_('To define if the course can be accessed by people not registered'), - } - - widgets = { - 'category': forms.Select(), - 'coordenator': forms.Select(), - } - + class Meta: model = Course fields = ('name', 'category', 'coordenator','public') labels = { 'name': _('Name'), 'category': _('Category'), 'coordenator': _('Coordenator'), 'public':_('Public'), } help_texts = { 'name': _('Course name'), 'coordenator': _('Course Coordenator'), 'public':_('To define if the course can be accessed by people not registered'), } widgets = { + 'category': forms.Select(), 'coordenator': forms.Select(), } class UpdateCourseForm(CourseForm): - - class Meta: - model = Course - fields = ('name', 'category', 'coordenator','public') - labels = { - 'name': _('Name'), - 'category': _('Category'), - 'coordenator': _('Coordenator'), - 'public':_('Public'), - } - help_texts = { - 'name': _('Course name'), - 'coordenator': _('Course Coordenator'), - 'public':_('To define if the course can be accessed by people not registered'), - } - widgets = { - 'category': forms.Select(), - 'coordenator': forms.Select(), - } - -class SubjectForm(forms.ModelForm): - - class Meta: - model = Subject - fields = ('name', 'description','init_date', 'end_date', 'visible',) - labels = { - 'name': _('Name'), - 'description': _('Description'), - 'init_date': _('Start date'), - 'end_date': _('End date'), - 'visible': _('Is it visible?'), - } - help_texts = { - 'name': _("Subjects's name"), - 'description': _("Subjects's description"), - 'init_date': _('Start date of the subject'), - 'end_date': _('End date of the subject'), - 'visible': _('Is the subject visible?'), - } - widgets = { - 'description':SummernoteWidget(), - } - + class Meta: model = Course fields = ('name', 'category', 'coordenator','public') labels = { 'name': _('Name'), 'category': _('Category'), 'coordenator': _('Coordenator'), 'public':_('Public'), } help_texts = { 'name': _('Course name'), 'coordenator': _('Course Coordenator'), 'public':_('To define if the course can be accessed by people not registered'), } widgets = { 'category': forms.Select(), 'coordenator': forms.Select(), } class SubjectForm(forms.ModelForm): def clean_end_date(self): init_date = self.cleaned_data['init_date'] end_date = self.cleaned_data['end_date'] if init_date and end_date and end_date < init_date: raise forms.ValidationError(_('The end date may not be before the start date.')) return end_date + class Meta: model = Subject fields = ('name', 'description','init_date', 'end_date', 'visible',) labels = { 'name': _('Name'), 'description': _('Description'), 'init_date': _('Start date'), 'end_date': _('End date'), 'visible': _('Is it visible?'), } help_texts = { 'name': _("Subjects's name"), 'description': _("Subjects's description"), 'init_date': _('Start date of the subject'), 'end_date': _('End date of the subject'), 'visible': _('Is the subject visible?'), } widgets = { 'description':SummernoteWidget(), } class TopicForm(forms.ModelForm): - - class Meta: - model = Topic - fields = ('name', 'description',) - labels = { - 'name': _('Name'), - 'description': _('Description'), - } - help_texts = { - 'name': _("Topic's name"), - 'description': _("Topic's description"), - } - widgets = { - 'description':SummernoteWidget(), - } - -class ActivityFileForm(forms.ModelForm): - name = forms.CharField( - required=False, - max_length=100, - widget=forms.TextInput(attrs={ - 'placeholder': 'Nome', - 'class': 'form-control' - }, - ) - ) - pdf = forms.URLField(required=True, widget=S3DirectWidget( - dest='activitys', - html=( - '
' - ' {file_name}' - ' Remover' - ' ' - ' ' - ' ' - '
' - '
' - '
' - '
' - '
' - ))) - - class Meta: - model = ActivityFile - fields = ['pdf','name'] - -class ActivityForm(forms.ModelForm): - class Meta: - model = Activity - fields = ['topic', 'limit_date', 'students','all_students'] - -class FileMaterialForm(forms.ModelForm): - class Meta: - model = FileMaterial - fields = ['name', 'file'] - -class LinkMaterialForm(forms.ModelForm): - class Meta: - model = LinkMaterial - fields = ['material', 'name', 'description','url'] + class Meta: model = Topic fields = ('name', 'description',) labels = { 'name': _('Name'), 'description': _('Description'), } help_texts = { 'name': _("Topic's name"), 'description': _("Topic's description"), } widgets = { 'description':SummernoteWidget(), } +class ActivityFileForm(forms.ModelForm): name = forms.CharField( required=False, max_length=100, widget=forms.TextInput(attrs={ 'placeholder': 'Nome', 'class': 'form-control' },)) pdf = forms.URLField(required=True, widget=S3DirectWidget( dest='activitys', html=( + '
' ' {file_name}' ' Remover' ' ' ' ' ' ' '
' '
' '
' '
' '
' ))) + class Meta: model = ActivityFile fields = ['pdf','name'] +class ActivityForm(forms.ModelForm): class Meta: model = Activity fields = ['topic', 'limit_date', 'students','all_students'] +class FileMaterialForm(forms.ModelForm): class Meta: model = FileMaterial fields = ['name', 'file'] +class LinkMaterialForm(forms.ModelForm): class Meta: model = LinkMaterial fields = ['material', 'name', 'description','url'] \ No newline at end of file diff --git a/courses/templates/subject/create.html b/courses/templates/subject/create.html index e421179..b226c02 100644 --- a/courses/templates/subject/create.html +++ b/courses/templates/subject/create.html @@ -15,11 +15,19 @@ {% csrf_token %} {% for field in form %}
- + {% if field.auto_id != 'id_visible' %} + + {% endif %} {% if field.auto_id == 'id_init_date' or field.auto_id == 'id_end_date'%} + {% elif field.auto_id == 'id_visible' %} +
+ +
{% else %} - {% render_field field class='form-control' placeholder=field.label%} + {% render_field field class='form-control'%} {% endif %} {{ field.help_text }}
diff --git a/courses/templates/subject/replicate.html b/courses/templates/subject/replicate.html index 6dd5233..b30fea3 100644 --- a/courses/templates/subject/replicate.html +++ b/courses/templates/subject/replicate.html @@ -1,10 +1,10 @@ {% extends 'subject/index.html' %} -{% load static i18n permission_tags widget_tweaks django_bootstrap_breadcrumbs %} +{% load static i18n permission_tags widget_tweaks django_bootstrap_breadcrumbs course_value_field %} {% block breadcrumbs %} {{ block.super }} - {% breadcrumb 'Replicate subject' 'course:replicate_subject' %} + {% breadcrumb 'Replicate subject' 'course:replicate_subject' %} {% endblock breadcrumbs %} {% block content %} @@ -13,43 +13,54 @@
{% csrf_token %} - -
- - - - {% trans 'Subject name'%} -
- -
- - - - {% trans 'Subject description'%} -
- -
- - - - {% trans 'Init date'%} -
- -
- - - - {% trans 'End date'%} -
- -
- - - - {% trans 'Is it visible?'%} + {% for field in form %} +
+ {% if field.auto_id != 'id_visible' %} + + {% endif %} + {% if field.auto_id == 'id_init_date' or field.auto_id == 'id_end_date'%} + {# {{now|date:'SHORT_DATE_FORMAT'}}#} + {% render_field field class='form-control date-picker'%} + {# #} + {% elif field.auto_id == 'id_visible' %} + {% value_subject_field subject field.name as value_field %} +
+ +
+ {% else %} + {% if field.errors %} + {% render_field field class='form-control' %} + {% else %} + {% value_subject_field subject field.name as value_field %} + {% if field.auto_id == 'id_description'%} + + {% else %} + {% render_field field class='form-control' value=value_field%} + {% endif %} + {% endif %} + {% endif %} + {{ field.help_text }} + {% if field.errors %} +
+
+ +
+ {% endif %}
+ {% endfor %}
- +
@@ -60,9 +71,10 @@ $('.date-picker').datepicker({ language: locale, + startDate: "dateToday", }); $(document).ready(function() { - $('#id_description').summernote({height: 300}); + $('#id_description').summernote(); }); {% endblock content %} diff --git a/courses/templatetags/course_value_field.py b/courses/templatetags/course_value_field.py index e7941c3..35f266e 100644 --- a/courses/templatetags/course_value_field.py +++ b/courses/templatetags/course_value_field.py @@ -47,7 +47,16 @@ def get_value_choice(value, choices): return "" @register.simple_tag -def get_tag(field): - field.value = "cacsdv" - print (dir(field.field)) - print (dir(field.field.widget),field.name,"\n\n\n") +def value_subject_field(subject, field): + value = "" + if field == 'name': + value = subject.name + elif field == 'description': + value = subject.description + elif field == 'init_date': + value = subject.init_date + elif field == 'end_date': + value = subject.end_date + elif field == 'visible': + value = subject.visible + return value diff --git a/courses/views.py b/courses/views.py index a6adae2..d401e8d 100644 --- a/courses/views.py +++ b/courses/views.py @@ -220,7 +220,6 @@ class ReplicateCourseView(LoginRequiredMixin, HasRoleMixin, LogMixin, Notificati context['categorys_courses'] = categorys_courses context['title'] = _("Replicate Course | Amadeus") context['now'] = date.today() - print (course.public) return context def get_success_url(self): @@ -1153,6 +1152,7 @@ class ReplicateSubjectView(LoginRequiredMixin, HasRoleMixin, LogMixin, Notificat context['subjects'] = course.subjects.filter(Q(visible=True) | Q(professors__in=[self.request.user])) context['subject'] = subject context['title'] = course.name + context['now'] = date.today() if (has_role(self.request.user,'system_admin')): context['subjects'] = course.subjects.all() return context @@ -1171,8 +1171,8 @@ class ReplicateSubjectView(LoginRequiredMixin, HasRoleMixin, LogMixin, Notificat resource_link = reverse('course:view_subject', args=[self.object.slug])) self.log_context['subject_id'] = self.object.id - self.log_context['subject_name'] = self.object.name self.log_context['subject_slug'] = self.object.slug + self.log_context['subject_name'] = self.object.name self.log_context['course_id'] = course.id self.log_context['course_name'] = course.name self.log_context['course_slug'] = course.slug -- libgit2 0.21.2