Commit 718fab644f92ceaac88c30ffd86c1a34eadaa267

Authored by Jailson Dias
1 parent f5de0b5d

ajustes em criar e editar subject #376

courses/forms.py
1   -from django import forms
2   -from django.utils.translation import ugettext_lazy as _
3   -from .models import CourseCategory, Course, Subject, Topic, ActivityFile, Activity, FileMaterial, LinkMaterial
4   -from s3direct.widgets import S3DirectWidget
5   -from django_summernote.widgets import SummernoteWidget
6   -
  1 +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
7 2 class CategoryCourseForm(forms.ModelForm):
8   -
9   - class Meta:
10   - model = CourseCategory
11   - fields = ('name',)
12   - labels = {
13   - 'name': _('Name')
14   - }
15   - help_texts = {
16   - 'name': _('CourseCategory name')
17   - }
18   -
  3 + class Meta: model = CourseCategory fields = ('name',) labels = { 'name': _('Name') } help_texts = { 'name': _('CourseCategory name') }
19 4 class CourseForm(forms.ModelForm):
20   -
21   - class Meta:
22   - model = Course
23   - fields = ('name', 'category', 'coordenator','public')
24   - labels = {
25   - 'name': _('Name'),
26   - 'category': _('Category'),
27   - 'coordenator': _('Coordenator'),
28   - 'public':_('Public'),
29   - }
30   - help_texts = {
31   - 'name': _('Course name'),
32   - 'coordenator': _('Course Coordenator'),
33   - 'public':_('To define if the course can be accessed by people not registered'),
34   - }
35   -
36   - widgets = {
37   - 'category': forms.Select(),
38   - 'coordenator': forms.Select(),
39   - }
40   -
  5 + 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 = {
  6 + 'category': forms.Select(), 'coordenator': forms.Select(), }
41 7 class UpdateCourseForm(CourseForm):
42   -
43   - class Meta:
44   - model = Course
45   - fields = ('name', 'category', 'coordenator','public')
46   - labels = {
47   - 'name': _('Name'),
48   - 'category': _('Category'),
49   - 'coordenator': _('Coordenator'),
50   - 'public':_('Public'),
51   - }
52   - help_texts = {
53   - 'name': _('Course name'),
54   - 'coordenator': _('Course Coordenator'),
55   - 'public':_('To define if the course can be accessed by people not registered'),
56   - }
57   - widgets = {
58   - 'category': forms.Select(),
59   - 'coordenator': forms.Select(),
60   - }
61   -
62   -class SubjectForm(forms.ModelForm):
63   -
64   - class Meta:
65   - model = Subject
66   - fields = ('name', 'description','init_date', 'end_date', 'visible',)
67   - labels = {
68   - 'name': _('Name'),
69   - 'description': _('Description'),
70   - 'init_date': _('Start date'),
71   - 'end_date': _('End date'),
72   - 'visible': _('Is it visible?'),
73   - }
74   - help_texts = {
75   - 'name': _("Subjects's name"),
76   - 'description': _("Subjects's description"),
77   - 'init_date': _('Start date of the subject'),
78   - 'end_date': _('End date of the subject'),
79   - 'visible': _('Is the subject visible?'),
80   - }
81   - widgets = {
82   - 'description':SummernoteWidget(),
83   - }
84   -
  8 + 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
  9 + 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(), }
85 10 class TopicForm(forms.ModelForm):
86   -
87   - class Meta:
88   - model = Topic
89   - fields = ('name', 'description',)
90   - labels = {
91   - 'name': _('Name'),
92   - 'description': _('Description'),
93   - }
94   - help_texts = {
95   - 'name': _("Topic's name"),
96   - 'description': _("Topic's description"),
97   - }
98   - widgets = {
99   - 'description':SummernoteWidget(),
100   - }
101   -
102   -class ActivityFileForm(forms.ModelForm):
103   - name = forms.CharField(
104   - required=False,
105   - max_length=100,
106   - widget=forms.TextInput(attrs={
107   - 'placeholder': 'Nome',
108   - 'class': 'form-control'
109   - },
110   - )
111   - )
112   - pdf = forms.URLField(required=True, widget=S3DirectWidget(
113   - dest='activitys',
114   - html=(
115   - '<div class="s3direct" data-policy-url="{policy_url}">'
116   - ' <a class="file-link" target="_blank" href="{file_url}">{file_name}</a>'
117   - ' <a class="file-remove" href="#remove">Remover</a>'
118   - ' <input class="file-url" type="hidden" value="{file_url}" id="{element_id}" name="{name}" />'
119   - ' <input class="file-dest" type="hidden" value="{dest}">'
120   - ' <input class="file-input" type="file" />'
121   - ' <div class="progress">'
122   - ' <div class="progress-bar progress-bar-success progress-bar-striped active bar">'
123   - ' </div>'
124   - ' </div>'
125   - '</div>'
126   - )))
127   -
128   - class Meta:
129   - model = ActivityFile
130   - fields = ['pdf','name']
131   -
132   -class ActivityForm(forms.ModelForm):
133   - class Meta:
134   - model = Activity
135   - fields = ['topic', 'limit_date', 'students','all_students']
136   -
137   -class FileMaterialForm(forms.ModelForm):
138   - class Meta:
139   - model = FileMaterial
140   - fields = ['name', 'file']
141   -
142   -class LinkMaterialForm(forms.ModelForm):
143   - class Meta:
144   - model = LinkMaterial
145   - fields = ['material', 'name', 'description','url']
  11 + 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(), }
  12 +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=(
  13 + '<div class="s3direct" data-policy-url="{policy_url}">' ' <a class="file-link" target="_blank" href="{file_url}">{file_name}</a>' ' <a class="file-remove" href="#remove">Remover</a>' ' <input class="file-url" type="hidden" value="{file_url}" id="{element_id}" name="{name}" />' ' <input class="file-dest" type="hidden" value="{dest}">' ' <input class="file-input" type="file" />' ' <div class="progress">' ' <div class="progress-bar progress-bar-success progress-bar-striped active bar">' ' </div>' ' </div>' '</div>' )))
  14 + class Meta: model = ActivityFile fields = ['pdf','name']
  15 +class ActivityForm(forms.ModelForm): class Meta: model = Activity fields = ['topic', 'limit_date', 'students','all_students']
  16 +class FileMaterialForm(forms.ModelForm): class Meta: model = FileMaterial fields = ['name', 'file']
  17 +class LinkMaterialForm(forms.ModelForm): class Meta: model = LinkMaterial fields = ['material', 'name', 'description','url']
146 18 \ No newline at end of file
... ...
courses/templates/subject/create.html
... ... @@ -15,11 +15,19 @@
15 15 {% csrf_token %}
16 16 {% for field in form %}
17 17 <div class="form-group {% if field.errors %} has-error{% endif %}">
18   - <label for="{{ field.auto_id }}" class="control-label label-static"> {{ field.label }}</label>
  18 + {% if field.auto_id != 'id_visible' %}
  19 + <label for="{{ field.auto_id }}"> {{ field.label }}</label>
  20 + {% endif %}
19 21 {% if field.auto_id == 'id_init_date' or field.auto_id == 'id_end_date'%}
20 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'}}">
  23 + {% elif field.auto_id == 'id_visible' %}
  24 + <div class="checkbox">
  25 + <label>
  26 + <input type="checkbox" name="{{field.name}}" {% if field.value %}checked="checked"{% endif %}><span class="checkbox-material"></span> {{field.name}}
  27 + </label>
  28 + </div>
21 29 {% else %}
22   - {% render_field field class='form-control' placeholder=field.label%}
  30 + {% render_field field class='form-control'%}
23 31 {% endif %}
24 32 <span class="help-block">{{ field.help_text }}</span>
25 33 </div>
... ...
courses/templates/subject/replicate.html
1 1 {% extends 'subject/index.html' %}
2 2  
3   -{% load static i18n permission_tags widget_tweaks django_bootstrap_breadcrumbs %}
  3 +{% load static i18n permission_tags widget_tweaks django_bootstrap_breadcrumbs course_value_field %}
4 4  
5 5 {% block breadcrumbs %}
6 6 {{ block.super }}
7   - {% breadcrumb 'Replicate subject' 'course:replicate_subject' %}
  7 + {% breadcrumb 'Replicate subject' 'course:replicate_subject' %}
8 8 {% endblock breadcrumbs %}
9 9  
10 10 {% block content %}
... ... @@ -13,43 +13,54 @@
13 13 <div class="panel-body">
14 14 <form class="form-group " method="post" action="">
15 15 {% csrf_token %}
16   -
17   - <div class="form-group {% if subject.name.errors %} has-error{% endif %}">
18   - <label for="id_name" class="control-label label-static"> {% trans 'Name'%}</label>
19   - <textarea class="form-control" id="id_name" maxlength="100" rows="1" name="name" placeholder="Name" type="text" required >{{subject.name}}</textarea>
20   -
21   - <span class="help-block">{% trans 'Subject name'%}</span>
22   - </div>
23   -
24   - <div class="form-group">
25   - <label for="id_description" class="control-label label-static"> {% trans 'Description'%}</label>
26   - <textarea class="form-control" id="id_description" name="description" placeholder="Description" type="text" >{{subject.description}}</textarea>
27   -
28   - <span class="help-block">{% trans 'Subject description'%}</span>
29   - </div>
30   -
31   - <div class="form-group">
32   - <label for="id_init_date" class="control-label label-static"> {% trans 'Init date'%}</label>
33   - <input type="text" class="form-control date-picker" name="init_date" value="{{field.value|date:'SHORT_DATE_FORMAT'}}" min="{{now|date:'SHORT_DATE_FORMAT'}}">
34   -
35   - <span class="help-block">{% trans 'Init date'%}</span>
36   - </div>
37   -
38   - <div class="form-group">
39   - <label for="id_end_date" class="control-label label-static"> {% trans 'End date'%}</label>
40   - <input type="text" class="form-control date-picker" name="end_date" value="{{field.value|date:'SHORT_DATE_FORMAT'}}" min="{{now|date:'SHORT_DATE_FORMAT'}}">
41   -
42   - <span class="help-block">{% trans 'End date'%}</span>
43   - </div>
44   -
45   - <div class="form-group">
46   - <label for="id_visible" class="control-label label-static"> {% trans 'Visible'%}</label>
47   - <input class="form-control" id="id_visible" name="visible" type="checkbox"/>
48   -
49   - <span class="help-block">{% trans 'Is it visible?'%}</span>
  16 + {% for field in form %}
  17 + <div class="form-group {% if field.errors %} has-error{% endif %}">
  18 + {% if field.auto_id != 'id_visible' %}
  19 + <label for="{{ field.auto_id }}"> {{ field.label }}</label>
  20 + {% endif %}
  21 + {% if field.auto_id == 'id_init_date' or field.auto_id == 'id_end_date'%}
  22 + {# {{now|date:'SHORT_DATE_FORMAT'}}#}
  23 + {% render_field field class='form-control date-picker'%}
  24 + {# <input type="text" class="form-control date-picker" id="{{field.auto_id}}"name="{{field.name}}" value="{{field.value|date:'SHORT_DATE_FORMAT'}}" min="{{now|date:'SHORT_DATE_FORMAT'}}">#}
  25 + {% elif field.auto_id == 'id_visible' %}
  26 + {% value_subject_field subject 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_subject_field subject field.name as value_field %}
  37 + {% if field.auto_id == 'id_description'%}
  38 + <textarea class="form-control" cols="80" id="{{field.auto_id}}" name="{{field.name}}" rows="5">{{value_field}}</textarea>
  39 + {% else %}
  40 + {% render_field field class='form-control' value=value_field%}
  41 + {% endif %}
  42 + {% endif %}
  43 + {% endif %}
  44 + <span class="help-block">{{ field.help_text }}</span>
  45 + {% if field.errors %}
  46 + <div class="row">
  47 + </br>
  48 + <div class="alert alert-danger alert-dismissible" role="alert">
  49 + <button type="button" class="close" data-dismiss="alert" aria-label="Close">
  50 + <span aria-hidden="true">&times;</span>
  51 + </button>
  52 + <ul>
  53 + {% for error in field.errors %}
  54 + <li>{{ error }}</li>
  55 + {% endfor %}
  56 + </ul>
  57 + </div>
  58 + </div>
  59 + {% endif %}
50 60 </div>
  61 + {% endfor %}
51 62 <div class="col-lg-offset-4 col-lg-4">
52   - <button type="submite" class="btn btn-raised btn-primary btn-lg btn-block">{% trans 'Replicate' %}</button>
  63 + <button type="submite" class="btn btn-raised btn-primary btn-lg btn-block">{% trans 'Create' %}</button>
53 64 </div>
54 65 </form>
55 66 </div>
... ... @@ -60,9 +71,10 @@
60 71  
61 72 $('.date-picker').datepicker({
62 73 language: locale,
  74 + startDate: "dateToday",
63 75 });
64 76 $(document).ready(function() {
65   - $('#id_description').summernote({height: 300});
  77 + $('#id_description').summernote();
66 78 });
67 79 </script>
68 80 {% endblock content %}
... ...
courses/templatetags/course_value_field.py
... ... @@ -47,7 +47,16 @@ def get_value_choice(value, choices):
47 47 return ""
48 48  
49 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")
  50 +def value_subject_field(subject, field):
  51 + value = ""
  52 + if field == 'name':
  53 + value = subject.name
  54 + elif field == 'description':
  55 + value = subject.description
  56 + elif field == 'init_date':
  57 + value = subject.init_date
  58 + elif field == 'end_date':
  59 + value = subject.end_date
  60 + elif field == 'visible':
  61 + value = subject.visible
  62 + return value
... ...
courses/views.py
... ... @@ -220,7 +220,6 @@ class ReplicateCourseView(LoginRequiredMixin, HasRoleMixin, LogMixin, Notificati
220 220 context['categorys_courses'] = categorys_courses
221 221 context['title'] = _("Replicate Course | Amadeus")
222 222 context['now'] = date.today()
223   - print (course.public)
224 223 return context
225 224  
226 225 def get_success_url(self):
... ... @@ -1153,6 +1152,7 @@ class ReplicateSubjectView(LoginRequiredMixin, HasRoleMixin, LogMixin, Notificat
1153 1152 context['subjects'] = course.subjects.filter(Q(visible=True) | Q(professors__in=[self.request.user]))
1154 1153 context['subject'] = subject
1155 1154 context['title'] = course.name
  1155 + context['now'] = date.today()
1156 1156 if (has_role(self.request.user,'system_admin')):
1157 1157 context['subjects'] = course.subjects.all()
1158 1158 return context
... ... @@ -1171,8 +1171,8 @@ class ReplicateSubjectView(LoginRequiredMixin, HasRoleMixin, LogMixin, Notificat
1171 1171 resource_link = reverse('course:view_subject', args=[self.object.slug]))
1172 1172  
1173 1173 self.log_context['subject_id'] = self.object.id
1174   - self.log_context['subject_name'] = self.object.name
1175 1174 self.log_context['subject_slug'] = self.object.slug
  1175 + self.log_context['subject_name'] = self.object.name
1176 1176 self.log_context['course_id'] = course.id
1177 1177 self.log_context['course_name'] = course.name
1178 1178 self.log_context['course_slug'] = course.slug
... ...