Commit e74bef54305280c3bd2b24cc77791570dfd7c350
1 parent
13feda6f
Exists in
master
and in
5 other branches
consertando a tela de replicar curso
Showing
2 changed files
with
121 additions
and
120 deletions
Show diff stats
courses/templates/course/replicate.html
1 | 1 | {% extends 'course/view.html' %} |
2 | 2 | |
3 | 3 | {% load static i18n %} |
4 | -{% load widget_tweaks %} | |
4 | +{% load widget_tweaks course_value_field %} | |
5 | 5 | |
6 | 6 | {% block breadcrumbs %} |
7 | 7 | <ol class="breadcrumb"> |
... | ... | @@ -12,131 +12,79 @@ |
12 | 12 | |
13 | 13 | {% block content %} |
14 | 14 | <div class="card card-content"> |
15 | - <div class="card-body"> | |
15 | + <div class="card-body"> | |
16 | 16 | <form method="post" action="" enctype="multipart/form-data"> |
17 | 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 | 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 | 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 | 71 | </div> |
132 | - </form> | |
72 | + </form> | |
133 | 73 | </div> |
134 | 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 | 90 | {% endblock %} | ... | ... |
... | ... | @@ -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") | ... | ... |