Commit 4974b066d06179a26012ead9b7b9e7f4c049dccd
1 parent
d67d8ccc
Exists in
master
and in
5 other branches
refatoração nas permições nos templates
Showing
26 changed files
with
167 additions
and
288 deletions
Show diff stats
amadeus/roles.py
... | ... | @@ -0,0 +1,43 @@ |
1 | +//controles do modal | |
2 | +$(window).ready(function() { // utilizado para abrir o modal quando tiver tido algum erro no preenchimento do formulario | |
3 | + if($('.not_submited').length){ | |
4 | + $('#poll').modal('show'); | |
5 | + } | |
6 | +}); | |
7 | +var Answer = { | |
8 | + init: function(url) { // utilizado para adicionar um novo campo de resposta | |
9 | + $.get(url, function(data){ | |
10 | + $("#form").append(data); | |
11 | + var cont = 1; | |
12 | + $("#form div div div input").each(function(){ | |
13 | + $(this).attr('name',cont++); | |
14 | + }); | |
15 | + }); | |
16 | + } | |
17 | +}; | |
18 | + | |
19 | +var Submite = { | |
20 | + post: function(url,dados){ | |
21 | + $('#poll').modal('hide'); | |
22 | + $.post(url,dados, function(data){ | |
23 | + }).fail(function(data){ | |
24 | + $("div.modal-backdrop.fade.in").remove(); | |
25 | + $("#modal_poll").empty(); | |
26 | + $("#modal_poll").append(data.responseText); | |
27 | + }); | |
28 | + }, | |
29 | + remove: function(url,dados, id_li_link){ | |
30 | + $('#poll').modal('hide'); | |
31 | + $.post(url,dados, function(data){ | |
32 | + $(id_li_link).remove(); | |
33 | + $("#modal_poll").empty(); | |
34 | + $("div.modal-backdrop.fade.in").remove(); | |
35 | + }).fail(function(){ | |
36 | + $("#modal_poll").empty(); | |
37 | + $("#modal_poll").append(data); | |
38 | + $('#poll').modal('show'); | |
39 | + }); | |
40 | + } | |
41 | +} | |
42 | + | |
43 | +alert("essfd"); | ... | ... |
... | ... | @@ -0,0 +1,14 @@ |
1 | +var Modal = { | |
2 | + get: function (url, id_modal, id_div_modal){ | |
3 | + $.get(url, function(data){ | |
4 | + if($(id_modal).length){ | |
5 | + $(id_div_modal).empty(); | |
6 | + $(id_div_modal).append(data); | |
7 | + } else { | |
8 | + $(id_div_modal).append(data); | |
9 | + } | |
10 | + $(id_modal).modal('show'); | |
11 | + }); | |
12 | + } | |
13 | +}; | |
14 | +alert("req"); | ... | ... |
... | ... | @@ -0,0 +1,12 @@ |
1 | +//deve ser importado apenas depois do html | |
2 | +$( "#form" ).sortable({ // utilizado para fazer a re-organização das respostas | |
3 | + delay: 100, | |
4 | + distance: 5, | |
5 | + update: function( event, ui ) { | |
6 | + var cont = 1; | |
7 | + $("#form div div div input").each(function(){ | |
8 | + $(this).attr('name',cont++); | |
9 | + }); | |
10 | + }, | |
11 | +}); | |
12 | +alert("sort"); | ... | ... |
app/templates/app/base.html
... | ... | @@ -1,22 +0,0 @@ |
1 | -{% extends 'base.html' %} | |
2 | - | |
3 | -{% load static i18n %} | |
4 | - | |
5 | -{% block menu_top %} | |
6 | - <ul class="nav navbar-nav"> | |
7 | - <li class="active"> | |
8 | - <a href="{% url 'home' %}">Home</a> | |
9 | - </li> | |
10 | - <li><a href="#contact">{% trans 'The Project' %}</a></li> | |
11 | - <li><a href="#contact">{% trans 'CCTE Group' %}</a></li> | |
12 | - <li class="divider-vertical"></li> | |
13 | - <li class="dropdown"> | |
14 | - <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">{% trans 'Hi' %}, {{ user }} <span class="caret"></span></a> | |
15 | - <ul class="dropdown-menu"> | |
16 | - <li><a href="{% url 'app:users:profile' %}">{% trans 'See Profile' %}</a></li> | |
17 | - <li><a href="#">{% trans 'Settings' %}</a></li> | |
18 | - <li><a href="{% url 'logout' %}">{% trans 'Logout' %}</a></li> | |
19 | - </ul> | |
20 | - </li> | |
21 | - </ul> | |
22 | -{% endblock %} | |
23 | 0 | \ No newline at end of file |
app/templates/app/index.html
... | ... | @@ -1,181 +0,0 @@ |
1 | -{% extends 'app/base.html' %} | |
2 | - | |
3 | -{% load static i18n permission_tags %} | |
4 | - | |
5 | -{% block sidebar %} | |
6 | - <h4>{% trans 'You have:' %} </h4> | |
7 | - <div class="list-group"> | |
8 | - <a href="#" class="list-group-item"> | |
9 | - <span class="badge">4</span> | |
10 | - {% trans 'Pending Tasks' %} | |
11 | - </a> | |
12 | - <a href="#" class="list-group-item"> | |
13 | - <span class="badge">0</span> | |
14 | - {% trans 'Users Online' %} | |
15 | - </a> | |
16 | - </div> | |
17 | - | |
18 | - <hr /> | |
19 | - | |
20 | - <h4>{% trans 'You can:' %} </h4> | |
21 | - <div class="list-group"> | |
22 | - {% if user|has_role:'professor' %} | |
23 | - <a href="{% url 'course:create' %}" class="list-group-item"> | |
24 | - {% trans 'Create Course' %} | |
25 | - </a> | |
26 | - {% endif %} | |
27 | - {% if user|has_role:'professor' %} | |
28 | - <a href="{% url 'users:manage' %}" class="list-group-item"> | |
29 | - {% trans 'Manage Users' %} | |
30 | - </a> | |
31 | - {% endif %} | |
32 | - <a href="{% url 'course:manage' %}" class="list-group-item"> | |
33 | - {% trans 'Manage Courses' %} | |
34 | - </a> | |
35 | - {% if user|has_role:'professor' %} | |
36 | - <a href="{% url 'course:manage_cat' %}" class="list-group-item"> | |
37 | - {% trans 'Gerenciar Categorias' %} | |
38 | - </a> | |
39 | - {% endif %} | |
40 | - </div> | |
41 | - | |
42 | - <hr /> | |
43 | - | |
44 | - {% if user|has_role:'student' %} | |
45 | - <h4>{% trans 'Your course(s):' %}</h4> | |
46 | - <p>{% trans 'No courses subscribed yet' %}</p> | |
47 | - {% endif %} | |
48 | -{% endblock %} | |
49 | - | |
50 | -{% block content %} | |
51 | - <div class="row"> | |
52 | - <div class="col-sm-12"> | |
53 | - <form class="form-horizontal" method="post"> | |
54 | - <div class="col-sm-10"> | |
55 | - <div class="form-group"> | |
56 | - <label for="search_keyword" class="control-label col-sm-3">{% trans 'Search course:' %} </label> | |
57 | - <div class="col-sm-9"> | |
58 | - <input type="text" class="form-control input-sm" id="search_keyword" /> | |
59 | - </div> | |
60 | - </div> | |
61 | - </div> | |
62 | - <button type="submit" class="btn btn-sm btn-success">{% trans 'Search' %}</button> | |
63 | - </form> | |
64 | - | |
65 | - <hr /> | |
66 | - | |
67 | - <h5>{% trans 'Most popular keywords:' %}</h5> | |
68 | - <div class="well"> | |
69 | - <center> | |
70 | - <ul class="cloud"> | |
71 | - <li> | |
72 | - <a href=""> | |
73 | - teste amadeus prospb | |
74 | - </a> | |
75 | - </li> | |
76 | - <li> | |
77 | - <a href=""> | |
78 | - programação fácil | |
79 | - </a> | |
80 | - </li> | |
81 | - <li> | |
82 | - <a href=""> | |
83 | - intermediário | |
84 | - </a> | |
85 | - </li> | |
86 | - <li> | |
87 | - <a href=""> | |
88 | - amadeus | |
89 | - </a> | |
90 | - </li> | |
91 | - <li> | |
92 | - <a href=""> | |
93 | - palavra02 | |
94 | - </a> | |
95 | - </li> | |
96 | - <li> | |
97 | - <a href=""> | |
98 | - programação para iniciantes | |
99 | - </a> | |
100 | - </li> | |
101 | - <li> | |
102 | - <a href=""> | |
103 | - django | |
104 | - </a> | |
105 | - </li> | |
106 | - <li> | |
107 | - <a href=""> | |
108 | - aluno teste | |
109 | - </a> | |
110 | - </li> | |
111 | - <li> | |
112 | - <a href=""> | |
113 | - curso0101 | |
114 | - </a> | |
115 | - </li> | |
116 | - <li> | |
117 | - <a href=""> | |
118 | - kjsdnksa | |
119 | - </a> | |
120 | - </li> | |
121 | - <li> | |
122 | - <a href=""> | |
123 | - palavra01 | |
124 | - </a> | |
125 | - </li> | |
126 | - <li> | |
127 | - <a href=""> | |
128 | - programming | |
129 | - </a> | |
130 | - </li> | |
131 | - <li> | |
132 | - <a href=""> | |
133 | - python | |
134 | - </a> | |
135 | - </li> | |
136 | - <li> | |
137 | - <a href=""> | |
138 | - curso | |
139 | - </a> | |
140 | - </li> | |
141 | - <li> | |
142 | - <a href=""> | |
143 | - mvc | |
144 | - </a> | |
145 | - </li> | |
146 | - <li> | |
147 | - <a href=""> | |
148 | - programação web | |
149 | - </a> | |
150 | - </li> | |
151 | - <li> | |
152 | - <a href=""> | |
153 | - ionic | |
154 | - </a> | |
155 | - </li> | |
156 | - <li> | |
157 | - <a href=""> | |
158 | - framework | |
159 | - </a> | |
160 | - </li> | |
161 | - <li> | |
162 | - <a href=""> | |
163 | - web | |
164 | - </a> | |
165 | - </li> | |
166 | - <li> | |
167 | - <a href=""> | |
168 | - android | |
169 | - </a> | |
170 | - </li> | |
171 | - <li> | |
172 | - <a href=""> | |
173 | - programação | |
174 | - </a> | |
175 | - </li> | |
176 | - </ul> | |
177 | - </center> | |
178 | - </div> | |
179 | - </div> | |
180 | - </div> | |
181 | -{% endblock %} |
courses/templates/category/create.html
courses/templates/category/delete.html
courses/templates/category/index.html
courses/templates/category/update.html
... | ... | @@ -24,7 +24,7 @@ |
24 | 24 | </div> |
25 | 25 | </div> |
26 | 26 | |
27 | -{% if user|has_role:'professor, system_admin' %} | |
27 | +{% if user|has_role:'professor' or user|has_role:'system_admin' %} | |
28 | 28 | |
29 | 29 | <div class="panel panel-primary navigation"> |
30 | 30 | <div class="panel-heading"> |
... | ... | @@ -87,7 +87,7 @@ |
87 | 87 | {% endif %} |
88 | 88 | {% endfor %} |
89 | 89 | <div class="row text-center"> |
90 | - <input type="submit" value="{% trans 'Save' %}" class="btn btn-sm btn-success" /> | |
90 | + <input type="submit" value="{% trans 'Save' %}" class="btn btn-sm btn-success" /> | |
91 | 91 | </div> |
92 | 92 | </form> |
93 | 93 | </div> | ... | ... |
courses/templates/category/view.html
courses/templates/course/index.html
... | ... | @@ -24,7 +24,7 @@ |
24 | 24 | </div> |
25 | 25 | </div> |
26 | 26 | |
27 | -{% if user|has_role:'professor, system_admin' %} | |
27 | +{% if user|has_role:'professor' or user|has_role:'system_admin' %} | |
28 | 28 | |
29 | 29 | <div class="panel panel-primary navigation"> |
30 | 30 | <div class="panel-heading"> |
... | ... | @@ -76,7 +76,7 @@ |
76 | 76 | <i class="material-icons">search</i> |
77 | 77 | </button> |
78 | 78 | </span> |
79 | - </div> | |
79 | + </div> | |
80 | 80 | </form> |
81 | 81 | </div> |
82 | 82 | <div class="col-md-12"> |
... | ... | @@ -103,7 +103,7 @@ |
103 | 103 | <h4 style="color:white">{{course.name}}</h4> |
104 | 104 | </a> |
105 | 105 | </div> |
106 | - {% if user|has_role:'professor, system_admin' %} | |
106 | + {% if user|has_role:'professor' or user|has_role:'system_admin' %} | |
107 | 107 | <div class="col-xs-4 col-md-3" id="divMoreActions"> |
108 | 108 | <div class="btn-group"> |
109 | 109 | <button class="btn btn-default btn-sm dropdown-toggle" type="button" id="moreActions" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> |
... | ... | @@ -150,7 +150,7 @@ |
150 | 150 | <h4 style="color:white">{{course.name}}</h4> |
151 | 151 | </a> |
152 | 152 | </div> |
153 | - {% if user|has_role:'professor, system_admin' %} | |
153 | + {% if user|has_role:'professor' or user|has_role:'system_admin' %} | |
154 | 154 | <div class="col-xs-4 col-md-3" id="divMoreActions"> |
155 | 155 | <div class="btn-group"> |
156 | 156 | <button class="btn btn-default btn-sm dropdown-toggle" type="button" id="moreActions" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> | ... | ... |
courses/templates/course/view.html
... | ... | @@ -28,7 +28,7 @@ |
28 | 28 | </div> |
29 | 29 | </div> |
30 | 30 | |
31 | -{% if user|has_role:'professor, system_admin' %} | |
31 | +{% if user|has_role:'professor' or user|has_role:'system_admin' %} | |
32 | 32 | |
33 | 33 | <div class="panel panel-primary navigation"> |
34 | 34 | <div class="panel-heading"> |
... | ... | @@ -284,7 +284,7 @@ |
284 | 284 | {% endif %} |
285 | 285 | |
286 | 286 | {% if user|has_role:'professor' or user|has_role:'system_admin' %} |
287 | - | |
287 | + | |
288 | 288 | <div class="form-group"> |
289 | 289 | <a href="#" data-toggle="modal" data-target="" class="btn btn-primary btn-lg btn-block btn-raised">{% trans 'Create Subject' %}<div class="ripple-container"></div></a> |
290 | 290 | </div> |
... | ... | @@ -316,4 +316,3 @@ |
316 | 316 | </div> |
317 | 317 | |
318 | 318 | {% endblock %} |
319 | - | ... | ... |
courses/templates/subject/form_view_teacher.html
1 | - {% load static i18n list_topic_foruns permission_tags widget_tweaks %} | |
1 | + {% load static i18n list_topic_foruns permission_tags widget_tweaks professor_access%} | |
2 | 2 | |
3 | 3 | {% block javascript %} |
4 | 4 | <script type="text/javascript" src="{% static 'js/forum.js' %}"></script> |
... | ... | @@ -24,7 +24,8 @@ |
24 | 24 | <button class="btn btn-default btn-sm dropdown-toggle" type="button" id="moreActions" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> |
25 | 25 | <i class="fa fa-ellipsis-v fa-2x" aria-hidden="true"></i> |
26 | 26 | </button> |
27 | - {% if user|has_role:'system_admin' or topic.owner == user %} | |
27 | + {% professor_subject topic.subject user as dropdown_topic %} | |
28 | + {% if dropdown_topic %} | |
28 | 29 | <ul class="dropdown-menu pull-right" aria-labelledby="moreActions"> |
29 | 30 | <li><a href="javascript:void(0)" data-toggle="modal" data-target="#myModal4"><i class="fa fa-files-o fa-fw" aria-hidden="true"></i> {% trans "Replicate" %}</a></li> |
30 | 31 | <li><a href="javascript:void(0)" class="edit_card"><i class="fa fa-pencil fa-fw" aria-hidden="true"></i> {% trans "Edit" %}</a></li> |
... | ... | @@ -61,7 +62,7 @@ |
61 | 62 | {% for file in files %} |
62 | 63 | <li><i class="fa fa-book" aria-hidden="true"></i> <a href="{{file.file_url}}">{{file}}</a></li> |
63 | 64 | {% endfor %} |
64 | - | |
65 | + | |
65 | 66 | <!-- <li><i class="fa fa-link" aria-hidden="true"></i> <a href="#" data-toggle="modal" data-target="#linksModal">Link 1</a></li> |
66 | 67 | <li><i class="fa fa-file-code-o" aria-hidden="true"></i> <a href="#" data-toggle="modal" data-target="#embedModal">EMBED Material</a></li>--> |
67 | 68 | </ul> |
... | ... | @@ -129,6 +130,7 @@ |
129 | 130 | <a href="#" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><i class="fa fa-plus-circle fa-lg" aria-hidden="true"></i></a> |
130 | 131 | <ul class="dropdown-menu" aria-labelledby="dLabel"> |
131 | 132 | <li>Qualquer coisa</li> |
133 | + <li><i class="material-icons">poll</i> <a href="javascript:modal.get('{% url 'course:poll:create_poll' topic.slug%}','#poll','#modal_poll');">{% trans 'Create Poll' %}</a></li> | |
132 | 134 | </ul> |
133 | 135 | </div> |
134 | 136 | </div> |
... | ... | @@ -190,8 +192,8 @@ |
190 | 192 | </div> |
191 | 193 | </div> |
192 | 194 | </div> |
193 | - | |
194 | -{% if user|has_role:'system_admin' or topic.owner == user%} | |
195 | +{% professor_subject topic.subject user as professor_topic %} | |
196 | +{% if professor_topic %} | |
195 | 197 | {% include "files/create_file.html" %} |
196 | 198 | {% endif %} |
197 | 199 | <!-- MODAL REMOVE FILE --> |
... | ... | @@ -240,12 +242,9 @@ |
240 | 242 | </div> |
241 | 243 | </div> |
242 | 244 | <!-- EndModal --> |
243 | - | |
244 | - {% if user|has_role:'system_admin' or topic.owner == user%} | |
245 | + {% professor_subject topic.subject user as professor_links %} | |
246 | + {% if professor_links%} | |
245 | 247 | {% include "links/create_link.html" %} |
246 | - {% endif %} | |
247 | - | |
248 | - {% if user|has_role:'system_admin' or topic.owner == user%} | |
249 | 248 | {% include "links/delete_link.html" %} |
250 | 249 | {% endif %} |
251 | 250 | |
... | ... | @@ -365,7 +364,8 @@ |
365 | 364 | |
366 | 365 | |
367 | 366 | <!-- MODAL LINK EDIT--> |
368 | - {% if user|has_role:'system_admin' or topic.owner == user%} | |
367 | + {% professor_subject topic.subject user as links_update %} | |
368 | + {% if links_update%} | |
369 | 369 | {% include "links/update_link.html" %} |
370 | 370 | {% endif %} |
371 | 371 | ... | ... |
courses/templates/subject/index.html
1 | 1 | {% extends 'base.html' %} |
2 | 2 | |
3 | -{% load static i18n permission_tags %} | |
3 | +{% load static i18n permission_tags professor_access%} | |
4 | 4 | |
5 | 5 | {% block breadcrumbs %} |
6 | 6 | |
... | ... | @@ -12,7 +12,7 @@ |
12 | 12 | {% else %} |
13 | 13 | <li class="active">{{ subject.name }}</li> |
14 | 14 | {% endif %} |
15 | - | |
15 | + | |
16 | 16 | </ol> |
17 | 17 | {% endblock %} |
18 | 18 | |
... | ... | @@ -28,7 +28,7 @@ |
28 | 28 | </ul> |
29 | 29 | </div> |
30 | 30 | </div> |
31 | - | |
31 | + | |
32 | 32 | |
33 | 33 | {% endblock %} |
34 | 34 | |
... | ... | @@ -39,7 +39,8 @@ |
39 | 39 | <div class="col-md-9 col-sm-9"> |
40 | 40 | <h3>{{subject}}</h3> |
41 | 41 | </div> |
42 | - {% if user|has_role:'system_admin' or user in subject.professors %} | |
42 | + {% professor_subject subject user as subject_professor%} | |
43 | + {% if subject_professor %} | |
43 | 44 | <div class="col-xs-4 col-md-3 divMoreActions"> |
44 | 45 | <div class="btn-group"> |
45 | 46 | <button class="btn btn-default btn-sm dropdown-toggle" type="button" id="moreActions" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> |
... | ... | @@ -71,19 +72,20 @@ |
71 | 72 | </div> |
72 | 73 | </div> |
73 | 74 | </div> |
74 | - | |
75 | + | |
75 | 76 | {% for topic in topics %} |
76 | - {% if user|has_role:'system_admin' or topic.owner == user%} | |
77 | + {% professor_subject topic.subject user as topic_professor%} | |
78 | + {% if topic_professor %} | |
77 | 79 | {% include "subject/form_view_teacher.html" %} |
78 | 80 | {% else %} |
79 | 81 | {% include "subject/form_view_student.html" %} |
80 | 82 | {% endif %} |
81 | 83 | {% endfor %} |
82 | - | |
83 | - {% if user|has_role:'system_admin' or topic.owner == user%} | |
84 | + {% professor_subject subject user as professor_sub %} | |
85 | + {% if professor_sub %} | |
84 | 86 | <div class="form-group"> |
85 | 87 | <a href="{% url 'course:create_topic' subject.slug %}" data-toggle="modal" data-target="" class="btn btn-primary btn-lg btn-block btn-raised" name="create_topic">{% trans "Create Topic" %}<div class="ripple-container"></div></a> |
86 | 88 | </div> |
87 | - {% endif %} | |
89 | + {% endif %} | |
88 | 90 | |
89 | 91 | {% endblock %} | ... | ... |
courses/templates/subject/poll_item_actions.html
1 | -{% load static i18n permission_tags%} | |
1 | +{% load static i18n permission_tags professor_access %} | |
2 | 2 | |
3 | 3 | <script src="{% static 'js/modals_requisitions.js'%}"></script> |
4 | 4 | <script src="{% static 'js/modal_poll.js'%}"></script> |
5 | 5 | |
6 | -{% if request.user|has_role:'professor, system_admin'%} | |
7 | 6 | {% for poll in polls %} |
8 | - <li id="poll_{{poll.slug}}"><i class="material-icons">poll</i> <a href="javascript:get('{% url 'course:poll:update_poll' poll.slug %}','#poll','#modal_poll');">{{ poll.name }}</a><a href="javascript:get('{% url 'course:poll:delete_poll' poll.slug %}','#poll','#modal_poll');"><span class="glyphicon glyphicon-remove"></span></a></li> | |
9 | -{% endfor %} | |
10 | -<button class="btn btn-primary btn-raised" onclick="javascript:get('{% url 'course:poll:create_poll' topic.slug%}','#poll','#modal_poll');">{% trans '+ Create Poll' %}</button> | |
11 | -{% else %} | |
12 | -{% for poll in polls %} | |
13 | - <li id="poll_{{poll.slug}}"><i class="material-icons">poll</i> <a href="javascript:get('{% url 'course:poll:view_poll' poll.slug %}','#poll','#modal_poll');">{{ poll.name }}</a></li> | |
14 | -{% endfor %} | |
15 | -{% endif %} | |
7 | + {% professor_subject poll.topic.subject request.user as permission%} | |
8 | + {% if permission %} | |
9 | + <li id="poll_{{poll.slug}}"><i class="material-icons">poll</i> <a href="javascript:modal.get('{% url 'course:poll:update_poll' poll.slug %}','#poll','#modal_poll');">{{ poll.name }}</a><a href="javascript:modal.get('{% url 'course:poll:delete_poll' poll.slug %}','#poll','#modal_poll');"><span class="glyphicon glyphicon-remove"></span></a></li> | |
10 | + {% else %} | |
11 | + <li id="poll_{{poll.slug}}"><i class="material-icons">poll</i> <a href="javascript:modal.get('{% url 'course:poll:view_poll' poll.slug %}','#poll','#modal_poll');">{{ poll.name }}</a></li> | |
12 | + {% endif %} | |
13 | + {% endfor %} | |
14 | +{# <button class="btn btn-primary btn-raised" onclick="javascript:modal.get('{% url 'course:poll:create_poll' topic.slug%}','#poll','#modal_poll');">{% trans '+ Create Poll' %}</button> #} | |
16 | 15 | <div class="row" id="modal_poll"> |
17 | 16 | |
18 | 17 | </div> | ... | ... |
courses/templates/subject_category/index.html
1 | 1 | {% extends 'base.html' %} |
2 | 2 | |
3 | -{% load static i18n permission_tags %} | |
3 | +{% load static i18n permission_tags professor_access%} | |
4 | 4 | |
5 | 5 | {% block breadcrumbs %} |
6 | 6 | |
7 | 7 | <ol class="breadcrumb"> |
8 | 8 | <li><a href="{% url 'app:index' %}">{% trans 'Home' %}</a></li> |
9 | - | |
10 | - | |
9 | + | |
10 | + | |
11 | 11 | </ol> |
12 | 12 | {% endblock %} |
13 | 13 | |
... | ... | @@ -43,12 +43,14 @@ |
43 | 43 | <h3>{{subject}}</h3> |
44 | 44 | </div> |
45 | 45 | <div class="col-md-2 col-sm-2"> |
46 | - {% if user|has_role:'system_admin' or user in subject.professors %} | |
46 | + {% professor_subject subject user as professor_sub%} | |
47 | + {% if professor_sub %} | |
47 | 48 | <a href="" class="btn">{% trans "edit" %}</a> |
48 | 49 | {% endif %} |
49 | 50 | </div> |
50 | 51 | <div class="col-md-3 col-sm-3"> |
51 | - {% if user|has_role:'system_admin' or user in subject.professors %} | |
52 | + {% professor_subject subject user as delete_sub%} | |
53 | + {% if delete_sub %} | |
52 | 54 | <a href="" class="btn">{% trans "delete" %}</a> |
53 | 55 | {% endif %} |
54 | 56 | </div> |
... | ... | @@ -60,6 +62,6 @@ |
60 | 62 | </p> |
61 | 63 | </div> |
62 | 64 | </div> |
63 | - | |
65 | + | |
64 | 66 | |
65 | 67 | {% endblock %} | ... | ... |
courses/templates/topic/index.html
1 | 1 | {% extends 'base.html' %} |
2 | 2 | |
3 | -{% load static i18n permission_tags %} | |
3 | +{% load static i18n permission_tags professor_access %} | |
4 | 4 | |
5 | 5 | {% block breadcrumbs %} |
6 | 6 | |
7 | 7 | <ol class="breadcrumb"> |
8 | 8 | <li><a href="{% url 'app:index' %}">{% trans 'Home' %}</a></li> |
9 | 9 | <li><a href="{% url 'course:view_subject' subject.slug %}">{{ subject }}</a></li> |
10 | - {% if user|has_role:'professor' or user|has_role:'system_admin' %} | |
10 | + {% professor_subject subject user as maneger_topic%} | |
11 | + {% if maneger_topic %} | |
11 | 12 | <li class="active">{% trans 'Manage Topic' %}</li> |
12 | 13 | {% else %} |
13 | 14 | <li class="active">{{ topic.name }}</li> |
... | ... | @@ -54,7 +55,8 @@ |
54 | 55 | <h3>{{subject}}</h3> |
55 | 56 | </div> |
56 | 57 | <div class="col-xs-4 col-md-2 divMoreActions"> |
57 | - {% if user|has_role:'system_admin' or user in subject.professors %} | |
58 | + {% professor_subject subject user as permissions%} | |
59 | + {% if permissions %} | |
58 | 60 | <div class="btn-group"> |
59 | 61 | <button class="btn btn-default btn-sm dropdown-toggle" type="button" id="moreActions" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> |
60 | 62 | <i class="fa fa-ellipsis-v fa-2x" aria-hidden="true"></i> |
... | ... | @@ -105,7 +107,8 @@ |
105 | 107 | <div class="col-md-4"> |
106 | 108 | <i class="fa fa-file-archive-o fa-lg" aria-hidden="true">Atividade.doc</i> |
107 | 109 | </div> |
108 | - {% if user|has_role:'professor, system_admin' %} | |
110 | + {% professor_subject subject user as permi_test%} | |
111 | + {% if permi_test %} | |
109 | 112 | <div class="col-md-4"> |
110 | 113 | <label> Nota:</label> |
111 | 114 | <input type="number" step="0.01"> | ... | ... |
poll/static/js/modal_poll.js
poll/static/js/modals_requisitions.js
1 | -function get(url, id_modal, id_div_modal){ | |
2 | - $.get(url, function(data){ | |
3 | - if($(id_modal).length){ | |
4 | - $(id_div_modal).empty(); | |
5 | - $(id_div_modal).append(data); | |
6 | - } else { | |
7 | - $(id_div_modal).append(data); | |
8 | - } | |
9 | - $(id_modal).modal('show'); | |
10 | - }); | |
11 | -} | |
12 | - | |
13 | -// function remove(url, id_li_link){ | |
14 | -// $.post(url, function(data){ | |
15 | -// $(id_li_link).remove(); | |
16 | -// }).fail(function(data){ | |
17 | -// alert("Error ao excluir a enquete"); | |
18 | -// alert(data); | |
19 | -// }); | |
20 | -// } | |
1 | +var modal = { | |
2 | + get: function (url, id_modal, id_div_modal){ | |
3 | + $.get(url, function(data){ | |
4 | + if($(id_modal).length){ | |
5 | + $(id_div_modal).empty(); | |
6 | + $(id_div_modal).append(data); | |
7 | + } else { | |
8 | + $(id_div_modal).append(data); | |
9 | + } | |
10 | + $(id_modal).modal('show'); | |
11 | + }); | |
12 | + } | |
13 | +}; | ... | ... |
poll/static/sample.txt
poll/templates/poll/view.html
... | ... | @@ -30,6 +30,6 @@ |
30 | 30 | {% block button_save %} |
31 | 31 | <!-- Put curtom buttons here!!! --> |
32 | 32 | {% if not status %} |
33 | -<button type="button" onclick="javascript:get('{% url 'course:poll:answer_student_poll' poll.slug%}','#poll','#modal_poll');$('div.modal-backdrop.fade.in').remove();" class="btn btn-primary btn-raised">{% trans "Answer" %}</button> | |
33 | +<button type="button" onclick="javascript:modal.get('{% url 'course:poll:answer_student_poll' poll.slug%}','#poll','#modal_poll');$('div.modal-backdrop.fade.in').remove();" class="btn btn-primary btn-raised">{% trans "Answer" %}</button> | |
34 | 34 | {% endif %} |
35 | 35 | {% endblock button_save %} | ... | ... |
... | ... | @@ -0,0 +1,14 @@ |
1 | +from django import template | |
2 | +from rolepermissions.verifications import has_role | |
3 | + | |
4 | +register = template.Library() | |
5 | + | |
6 | +@register.simple_tag | |
7 | +def professor_subject(subject, user): | |
8 | + if (has_role(user,'system_admin')): | |
9 | + return True | |
10 | + | |
11 | + if (user in subject.professors.all()): | |
12 | + return True | |
13 | + | |
14 | + return False | ... | ... |
poll/tests/poll.py
... | ... | @@ -80,21 +80,23 @@ class PollTestCase(TestCase): |
80 | 80 | self.poll.save() |
81 | 81 | |
82 | 82 | def test_poll_create(self): |
83 | - self.client.login(username='professor', password='testing') | |
84 | - poll = self.topic.activities.all().count() | |
85 | 83 | url = reverse('course:poll:create_poll',kwargs={'slug':self.topic.slug}) |
86 | 84 | data = { |
87 | 85 | "name": 'create poll test', |
88 | 86 | "limit_date":'2016-10-06', |
89 | 87 | "all_students":True, |
90 | 88 | } |
91 | - response = self.client.post(url, data) | |
92 | - self.assertEqual(poll + 1, self.topic.activities.all().count()) # create a new poll | |
89 | + | |
93 | 90 | self.client.login(username='student', password='testing') |
94 | 91 | poll = self.topic.activities.all().count() |
95 | 92 | response = self.client.post(url, data) |
96 | 93 | self.assertEqual(poll, self.topic.activities.all().count()) # don't create a new poll |
97 | 94 | |
95 | + self.client.login(username='professor', password='testing') | |
96 | + poll = self.topic.activities.all().count() | |
97 | + response = self.client.post(url, data) | |
98 | + self.assertEqual(poll + 1, self.topic.activities.all().count()) # create a new poll | |
99 | + | |
98 | 100 | def test_poll_update(self): |
99 | 101 | self.client.login(username='professor', password='testing') |
100 | 102 | url = reverse('course:poll:update_poll',kwargs={'slug':self.poll.slug}) | ... | ... |
poll/views.py
... | ... | @@ -145,6 +145,8 @@ class UpdatePoll(LoginRequiredMixin,HasRoleMixin,generic.UpdateView): |
145 | 145 | context['subject'] = poll.topic.subject |
146 | 146 | context['subjects'] = poll.topic.subject.course.subjects.all() |
147 | 147 | |
148 | + print (self.request.user) | |
149 | + | |
148 | 150 | answers = {} |
149 | 151 | for answer in poll.answers.all(): |
150 | 152 | # print (key.answer) | ... | ... |
users/admin.py
... | ... | @@ -5,6 +5,5 @@ from .forms import AdminUserForm |
5 | 5 | class UserAdmin(admin.ModelAdmin): |
6 | 6 | list_display = ['username', 'name', 'email', 'is_staff', 'is_active'] |
7 | 7 | search_fields = ['username', 'name', 'email'] |
8 | - form = AdminUserForm | |
9 | 8 | |
10 | -admin.site.register(User, UserAdmin) | |
11 | 9 | \ No newline at end of file |
10 | +admin.site.register(User, UserAdmin) | ... | ... |