Commit 1be45ecb091194052d1839f8fbeed9a0b51df948
1 parent
131b2f1c
Exists in
master
and in
5 other branches
Criado o template e o procedimento de remover enquete #114
Showing
6 changed files
with
341 additions
and
208 deletions
Show diff stats
| ... | ... | @@ -0,0 +1,206 @@ |
| 1 | +{% extends "topic/index.html" %} | |
| 2 | + | |
| 3 | +{% load i18n widget_tweaks dict_access static%} | |
| 4 | + | |
| 5 | +{% block style %} | |
| 6 | + <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> | |
| 7 | +{% endblock %} | |
| 8 | + | |
| 9 | +{% block content %} | |
| 10 | +<!-- Modal (remember to change the ids!!!) --> | |
| 11 | +<div class="modal fade" id="poll" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> | |
| 12 | + <div class="modal-dialog" role="document"> | |
| 13 | + <div class="modal-content"> | |
| 14 | + | |
| 15 | + <!-- Modal Header --> | |
| 16 | + <div class="modal-header"> | |
| 17 | + | |
| 18 | + {% block title_poll %} | |
| 19 | + <!-- Put your title here!!! --> | |
| 20 | + <h4 class="modal-title" id="myModalLabel">{% trans "Create a Poll" %}</h4> | |
| 21 | + {% endblock title_poll %} | |
| 22 | + </div> | |
| 23 | + <!-- Modal Body --> | |
| 24 | + <div class="modal-body"> | |
| 25 | + | |
| 26 | + {% block content_poll %} | |
| 27 | + <!-- Put ONLY your content here!!! --> | |
| 28 | + <div class="conteiner"> | |
| 29 | + <div class="row form-group"> | |
| 30 | + <div class="col-md-1"> | |
| 31 | + </br> | |
| 32 | + <label><span class="glyphicon glyphicon-hand-right"></span></label> | |
| 33 | + </div> | |
| 34 | + <div class="col-md-10"> | |
| 35 | + <div class="has-success"> | |
| 36 | + <input form="form" type="text" name="{{form.name.name}}" {% if form.name.value != None %}value="{{form.name.value}}" {% endif %} class="form-control" placeholder='{% trans "Question?" %}'> | |
| 37 | + <span class="help-block">{% trans "A Question to be answered" %}</span> | |
| 38 | + </div> | |
| 39 | + </div> | |
| 40 | + {% if form.name.errors %} | |
| 41 | + <div class="col-md-10 not_submited"> | |
| 42 | + </br> | |
| 43 | + <div class="alert alert-danger alert-dismissible" role="alert"> | |
| 44 | + <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | |
| 45 | + <span aria-hidden="true">×</span> | |
| 46 | + </button> | |
| 47 | + <ul> | |
| 48 | + {% for error in form.name.errors %} | |
| 49 | + <li>{{ error }}</li> | |
| 50 | + {% endfor %} | |
| 51 | + </ul> | |
| 52 | + </div> | |
| 53 | + </div> | |
| 54 | + {% endif %} | |
| 55 | + </div> | |
| 56 | + <form id="form" class="" action="" method="post"> | |
| 57 | + {% csrf_token %} | |
| 58 | + {% for key in keys %} | |
| 59 | + <div class="row form-group"> | |
| 60 | + <div class="col-md-1"> | |
| 61 | + </br> | |
| 62 | + <label><span class="glyphicon glyphicon-move"></span></label> | |
| 63 | + </div> | |
| 64 | + <div class="col-md-10"> | |
| 65 | + <div class="has-success is-empty"> | |
| 66 | + <input type="text" name="{{key}}" class="form-control" placeholder='{% trans "Answer" %}' value="{{ answers|value:key }}"> | |
| 67 | + <span class="help-block">{% trans "Possible answer for the question" %}</span> | |
| 68 | + </div> | |
| 69 | + </div> | |
| 70 | + <div class="col-md-1"> | |
| 71 | + </br> | |
| 72 | + <label><span class="glyphicon glyphicon-remove" onclick="this.parentNode.parentNode.parentNode.parentNode.removeChild(this.parentNode.parentNode.parentNode);"></span></label> | |
| 73 | + </div> | |
| 74 | + </div> | |
| 75 | + {% empty %} | |
| 76 | + <div class="row form-group"> | |
| 77 | + <div class="col-md-1"> | |
| 78 | + </br> | |
| 79 | + <label><span class="glyphicon glyphicon-move"></span></label> | |
| 80 | + </div> | |
| 81 | + <div class="col-md-10"> | |
| 82 | + <div class="has-success is-empty"> | |
| 83 | + <input type="text" name="1" class="form-control" placeholder='{% trans "Answer" %}'> | |
| 84 | + <span class="help-block">{% trans "Possible answer for the question" %}</span> | |
| 85 | + </div> | |
| 86 | + </div> | |
| 87 | + <div class="col-md-1"> | |
| 88 | + </br> | |
| 89 | + <label><span class="glyphicon glyphicon-remove" onclick="this.parentNode.parentNode.parentNode.parentNode.removeChild(this.parentNode.parentNode.parentNode);"></span></label> | |
| 90 | + </div> | |
| 91 | + </div> | |
| 92 | + {% endfor %} | |
| 93 | + </form> | |
| 94 | + </br> | |
| 95 | + </div> | |
| 96 | + <button type="button" id="add" class="btn btn-primary btn-block btn-sm">add</button> | |
| 97 | + <div class="row form-group"> | |
| 98 | + <label for="{{ form.limit_date.auto_id }}">{{ form.limit_date.label }}</label> | |
| 99 | + {% render_field form.limit_date class="form-control" form="form"%} | |
| 100 | + {# <input form="form" class="form-control" type="date" name="{{form.limit_date.name}}" {% if form.limit_date.value != None %}value="{% if form.limit_date.value.year %}{{form.limit_date.value|date:'Y-m-d'}}{% else %}{{form.limit_date.value}}{% endif %}"{% endif %}>#} | |
| 101 | + {% if form.limit_date.errors %} | |
| 102 | + <div class="not_submited"> | |
| 103 | + </br> | |
| 104 | + <div class="alert alert-danger alert-dismissible" role="alert"> | |
| 105 | + <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | |
| 106 | + <span aria-hidden="true">×</span> | |
| 107 | + </button> | |
| 108 | + <ul> | |
| 109 | + {% for error in form.limit_date.errors %} | |
| 110 | + <li>{{ error }}</li> | |
| 111 | + {% endfor %} | |
| 112 | + </ul> | |
| 113 | + </div> | |
| 114 | + </div> | |
| 115 | + {% endif %} | |
| 116 | + </div> | |
| 117 | + | |
| 118 | + <div class="row form-group"> | |
| 119 | + <label for="{{ form.students.auto_id }}">{{ form.students.label }}</label> | |
| 120 | + {% render_field form.students class="form-control" form="form"%} | |
| 121 | + </div> | |
| 122 | + <div class="row form-group"> | |
| 123 | + <div class="checkbox"> | |
| 124 | + <label> | |
| 125 | + {% render_field form.all_students class="form-control" form="form" %}<span class="checkbox-material"><span class="check"></span></span> {{form.all_students.label }} | |
| 126 | + </label> | |
| 127 | + </div> | |
| 128 | + {% if form.all_students.errors %} | |
| 129 | + <div class="not_submited"> | |
| 130 | + </br> | |
| 131 | + <div class="alert alert-danger alert-dismissible" role="alert"> | |
| 132 | + <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | |
| 133 | + <span aria-hidden="true">×</span> | |
| 134 | + </button> | |
| 135 | + <ul> | |
| 136 | + {% for error in form.all_students.errors %} | |
| 137 | + <li>{{ error }}</li> | |
| 138 | + {% endfor %} | |
| 139 | + </ul> | |
| 140 | + </div> | |
| 141 | + </div> | |
| 142 | + {% endif %} | |
| 143 | + </div> | |
| 144 | + | |
| 145 | + {% endblock content_poll %} | |
| 146 | + </div> | |
| 147 | + | |
| 148 | + <!-- Modal Footer --> | |
| 149 | + <div class="modal-footer"> | |
| 150 | + | |
| 151 | + <!-- Don't remove that!!! --> | |
| 152 | + <button type="button" class="btn btn-danger btn-raised" data-dismiss="modal">{% trans "Close" %}</button> | |
| 153 | + {% block button_save %} | |
| 154 | + <!-- Put curtom buttons here!!! --> | |
| 155 | + <button type="submite" id="button" form="form" class="btn btn-primary btn-raised">{% trans "Create" %}</button> | |
| 156 | + {% endblock button_save %} | |
| 157 | + </div> | |
| 158 | + | |
| 159 | + </div> | |
| 160 | + </div> | |
| 161 | +</div> | |
| 162 | +<script type="text/javascript"> | |
| 163 | +// Este js tem que ficar aqui se não a tag "trans" não vai funcionar | |
| 164 | +$(window).ready(function() { // utilizado para abrir o modal quando tiver tido algum erro no preenchimento do formulario | |
| 165 | + if($('.not_submited').length){ | |
| 166 | + $('#poll').modal('show'); | |
| 167 | + } | |
| 168 | +}); | |
| 169 | +$( "#form" ).sortable({ // utilizado para fazer a re-organização das respostas | |
| 170 | + delay: 100, | |
| 171 | + distance: 5, | |
| 172 | + update: function( event, ui ) { | |
| 173 | + var cont = 1; | |
| 174 | + $("#form div div div input").each(function(){ | |
| 175 | + $(this).attr('name',cont++); | |
| 176 | + }); | |
| 177 | + }, | |
| 178 | +}); | |
| 179 | +name = 2; | |
| 180 | +$("#add").click(function() { // utilizado para adicionar um novo campo de resposta | |
| 181 | + //Obs: não funcionar se estiver importado no head, só funciona se estiver no final do arquivo | |
| 182 | + $("#form").append('\ | |
| 183 | + <div class="row form-group">\ | |
| 184 | + <div class="col-md-1">\ | |
| 185 | + </br>\ | |
| 186 | + <label><span class="glyphicon glyphicon-move"></span></label>\ | |
| 187 | + </div>\ | |
| 188 | + <div class="col-md-10">\ | |
| 189 | + <div class="has-success is-empty">\ | |
| 190 | + <input type="text" name="1" class="form-control" placeholder="{% trans "Answer" %}">\ | |
| 191 | + <span class="help-block">{% trans "Possible answer for the question" %}</span>\ | |
| 192 | + </div>\ | |
| 193 | + </div>\ | |
| 194 | + <div class="col-md-1">\ | |
| 195 | + </br>\ | |
| 196 | + <label><span class="glyphicon glyphicon-remove" onclick="this.parentNode.parentNode.parentNode.parentNode.removeChild(this.parentNode.parentNode.parentNode);"></span></label>\ | |
| 197 | + </div>\ | |
| 198 | + </div>'); | |
| 199 | + var cont = 1; | |
| 200 | + $("#form div div div input").each(function(){ | |
| 201 | + $(this).attr('name',cont++); | |
| 202 | + }); | |
| 203 | +}); | |
| 204 | +</script> | |
| 205 | +<a href="" data-toggle="modal" data-target="#poll">modal</a> | |
| 206 | +{% endblock content %} | ... | ... |
poll/templates/poll/create_update.html
| ... | ... | @@ -1,206 +0,0 @@ |
| 1 | -{% extends "topic/index.html" %} | |
| 2 | - | |
| 3 | -{% load i18n widget_tweaks dict_access static%} | |
| 4 | - | |
| 5 | -{% block style %} | |
| 6 | - <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script> | |
| 7 | -{% endblock %} | |
| 8 | - | |
| 9 | -{% block content %} | |
| 10 | -<!-- Modal (remember to change the ids!!!) --> | |
| 11 | -<div class="modal fade" id="poll" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> | |
| 12 | - <div class="modal-dialog" role="document"> | |
| 13 | - <div class="modal-content"> | |
| 14 | - | |
| 15 | - <!-- Modal Header --> | |
| 16 | - <div class="modal-header"> | |
| 17 | - | |
| 18 | - <!-- Put your title here!!! --> | |
| 19 | - <h4 class="modal-title" id="myModalLabel">{% trans "Create a Poll" %}</h4> | |
| 20 | - | |
| 21 | - </div> | |
| 22 | - <!-- Modal Body --> | |
| 23 | - <div class="modal-body"> | |
| 24 | - | |
| 25 | - <!-- Put ONLY your content here!!! --> | |
| 26 | - <div class="conteiner"> | |
| 27 | - <div class="row form-group"> | |
| 28 | - <div class="col-md-1"> | |
| 29 | - </br> | |
| 30 | - <label><span class="glyphicon glyphicon-hand-right"></span></label> | |
| 31 | - </div> | |
| 32 | - <div class="col-md-10"> | |
| 33 | - <div class="has-success"> | |
| 34 | - <input form="form" type="text" name="{{form.name.name}}" {% if form.name.value != None %}value="{{form.name.value}}" {% endif %} class="form-control" placeholder='{% trans "Question?" %}'> | |
| 35 | - <span class="help-block">{% trans "A Question to be answered" %}</span> | |
| 36 | - </div> | |
| 37 | - </div> | |
| 38 | - {% if form.name.errors %} | |
| 39 | - <div class="col-md-10 not_submited"> | |
| 40 | - </br> | |
| 41 | - <div class="alert alert-danger alert-dismissible" role="alert"> | |
| 42 | - <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | |
| 43 | - <span aria-hidden="true">×</span> | |
| 44 | - </button> | |
| 45 | - <ul> | |
| 46 | - {% for error in form.name.errors %} | |
| 47 | - <li>{{ error }}</li> | |
| 48 | - {% endfor %} | |
| 49 | - </ul> | |
| 50 | - </div> | |
| 51 | - </div> | |
| 52 | - {% endif %} | |
| 53 | - </div> | |
| 54 | - <form id="form" class="" action="" method="post"> | |
| 55 | - {% csrf_token %} | |
| 56 | - {% for key in keys %} | |
| 57 | - <div class="row form-group"> | |
| 58 | - <div class="col-md-1"> | |
| 59 | - </br> | |
| 60 | - <label><span class="glyphicon glyphicon-move"></span></label> | |
| 61 | - </div> | |
| 62 | - <div class="col-md-10"> | |
| 63 | - <div class="has-success is-empty"> | |
| 64 | - <input type="text" name="{{key}}" class="form-control" placeholder='{% trans "Answer" %}' value="{{ answers|value:key }}"> | |
| 65 | - <span class="help-block">{% trans "Possible answer for the question" %}</span> | |
| 66 | - </div> | |
| 67 | - </div> | |
| 68 | - <div class="col-md-1"> | |
| 69 | - </br> | |
| 70 | - <label><span class="glyphicon glyphicon-remove" onclick="this.parentNode.parentNode.parentNode.parentNode.removeChild(this.parentNode.parentNode.parentNode);"></span></label> | |
| 71 | - </div> | |
| 72 | - </div> | |
| 73 | - {% empty %} | |
| 74 | - <div class="row form-group"> | |
| 75 | - <div class="col-md-1"> | |
| 76 | - </br> | |
| 77 | - <label><span class="glyphicon glyphicon-move"></span></label> | |
| 78 | - </div> | |
| 79 | - <div class="col-md-10"> | |
| 80 | - <div class="has-success is-empty"> | |
| 81 | - <input type="text" name="1" class="form-control" placeholder='{% trans "Answer" %}'> | |
| 82 | - <span class="help-block">{% trans "Possible answer for the question" %}</span> | |
| 83 | - </div> | |
| 84 | - </div> | |
| 85 | - <div class="col-md-1"> | |
| 86 | - </br> | |
| 87 | - <label><span class="glyphicon glyphicon-remove" onclick="this.parentNode.parentNode.parentNode.parentNode.removeChild(this.parentNode.parentNode.parentNode);"></span></label> | |
| 88 | - </div> | |
| 89 | - </div> | |
| 90 | - {% endfor %} | |
| 91 | - </form> | |
| 92 | - </br> | |
| 93 | - </div> | |
| 94 | - <button type="button" id="add" class="btn btn-primary btn-block btn-sm">add</button> | |
| 95 | - <div class="row form-group"> | |
| 96 | - <label for="{{ form.limit_date.auto_id }}">{{ form.limit_date.label }}</label> | |
| 97 | - {% render_field form.limit_date class="form-control" form="form"%} | |
| 98 | - {# <input form="form" class="form-control" type="date" name="{{form.limit_date.name}}" {% if form.limit_date.value != None %}value="{% if form.limit_date.value.year %}{{form.limit_date.value|date:'Y-m-d'}}{% else %}{{form.limit_date.value}}{% endif %}"{% endif %}>#} | |
| 99 | - {% if form.limit_date.errors %} | |
| 100 | - <div class="not_submited"> | |
| 101 | - </br> | |
| 102 | - <div class="alert alert-danger alert-dismissible" role="alert"> | |
| 103 | - <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | |
| 104 | - <span aria-hidden="true">×</span> | |
| 105 | - </button> | |
| 106 | - <ul> | |
| 107 | - {% for error in form.limit_date.errors %} | |
| 108 | - <li>{{ error }}</li> | |
| 109 | - {% endfor %} | |
| 110 | - </ul> | |
| 111 | - </div> | |
| 112 | - </div> | |
| 113 | - {% endif %} | |
| 114 | - </div> | |
| 115 | - | |
| 116 | - <div class="row form-group"> | |
| 117 | - <label for="{{ form.students.auto_id }}">{{ form.students.label }}</label> | |
| 118 | - {% render_field form.students class="form-control" form="form"%} | |
| 119 | - </div> | |
| 120 | - <div class="row form-group"> | |
| 121 | - <div class="checkbox"> | |
| 122 | - <label> | |
| 123 | - {% render_field form.all_students class="form-control" form="form" %}<span class="checkbox-material"><span class="check"></span></span> {{form.all_students.label }} | |
| 124 | - {# <input form="form" type="checkbox" name="{{form.all_students.name}}"><span class="checkbox-material"><span class="check"></span></span> {{ form.all_students.label }}#} | |
| 125 | - </label> | |
| 126 | - </div> | |
| 127 | - {% if form.all_students.errors %} | |
| 128 | - <div class="not_submited"> | |
| 129 | - </br> | |
| 130 | - <div class="alert alert-danger alert-dismissible" role="alert"> | |
| 131 | - <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | |
| 132 | - <span aria-hidden="true">×</span> | |
| 133 | - </button> | |
| 134 | - <ul> | |
| 135 | - {% for error in form.all_students.errors %} | |
| 136 | - <li>{{ error }}</li> | |
| 137 | - {% endfor %} | |
| 138 | - </ul> | |
| 139 | - </div> | |
| 140 | - </div> | |
| 141 | - {% endif %} | |
| 142 | - | |
| 143 | - {# <label for="{{ form.all_students.auto_id }}">{{ form.all_students.label }}</label>#} | |
| 144 | - {# {% render_field form.all_students class="form-control" form="form"%}#} | |
| 145 | - </div> | |
| 146 | - | |
| 147 | - </div> | |
| 148 | - | |
| 149 | - <!-- Modal Footer --> | |
| 150 | - <div class="modal-footer"> | |
| 151 | - | |
| 152 | - <!-- Don't remove that!!! --> | |
| 153 | - <button type="button" class="btn btn-danger btn-raised" data-dismiss="modal">{% trans "Close" %}</button> | |
| 154 | - | |
| 155 | - <!-- Put curtom buttons here!!! --> | |
| 156 | - <button type="submite" id="button" form="form" class="btn btn-primary btn-raised">{% trans "Create" %}</button> | |
| 157 | - </div> | |
| 158 | - | |
| 159 | - </div> | |
| 160 | - </div> | |
| 161 | -</div> | |
| 162 | -<script type="text/javascript"> | |
| 163 | -// Este js tem que ficar aqui se não a tag "trans" não vai funcionar | |
| 164 | -$(window).ready(function() { // utilizado para abrir o modal quando tiver tido algum erro no preenchimento do formulario | |
| 165 | - if($('.not_submited').length){ | |
| 166 | - $('#poll').modal('show'); | |
| 167 | - } | |
| 168 | -}); | |
| 169 | -$( "#form" ).sortable({ // utilizado para fazer a re-organização das respostas | |
| 170 | - delay: 100, | |
| 171 | - distance: 5, | |
| 172 | - update: function( event, ui ) { | |
| 173 | - var cont = 1; | |
| 174 | - $("#form div div div input").each(function(){ | |
| 175 | - $(this).attr('name',cont++); | |
| 176 | - }); | |
| 177 | - }, | |
| 178 | -}); | |
| 179 | -name = 2; | |
| 180 | -$("#add").click(function() { // utilizado para adicionar um novo campo de resposta | |
| 181 | - //Obs: não funcionar se estiver importado no head, só funciona se estiver no final do arquivo | |
| 182 | - $("#form").append('\ | |
| 183 | - <div class="row form-group">\ | |
| 184 | - <div class="col-md-1">\ | |
| 185 | - </br>\ | |
| 186 | - <label><span class="glyphicon glyphicon-move"></span></label>\ | |
| 187 | - </div>\ | |
| 188 | - <div class="col-md-10">\ | |
| 189 | - <div class="has-success is-empty">\ | |
| 190 | - <input type="text" name="1" class="form-control" placeholder="{% trans "Answer" %}">\ | |
| 191 | - <span class="help-block">{% trans "Possible answer for the question" %}</span>\ | |
| 192 | - </div>\ | |
| 193 | - </div>\ | |
| 194 | - <div class="col-md-1">\ | |
| 195 | - </br>\ | |
| 196 | - <label><span class="glyphicon glyphicon-remove" onclick="this.parentNode.parentNode.parentNode.parentNode.removeChild(this.parentNode.parentNode.parentNode);"></span></label>\ | |
| 197 | - </div>\ | |
| 198 | - </div>'); | |
| 199 | - var cont = 1; | |
| 200 | - $("#form div div div input").each(function(){ | |
| 201 | - $(this).attr('name',cont++); | |
| 202 | - }); | |
| 203 | -}); | |
| 204 | -</script> | |
| 205 | -<a href="" data-toggle="modal" data-target="#poll">modal</a> | |
| 206 | -{% endblock content %} |
| ... | ... | @@ -0,0 +1,21 @@ |
| 1 | +{% extends "poll/create.html" %} | |
| 2 | + | |
| 3 | +{% load i18n %} | |
| 4 | + | |
| 5 | +{% block title_poll %} | |
| 6 | +<!-- Put your title here!!! --> | |
| 7 | +<h4 class="modal-title" id="myModalLabel">{% trans "Delete Poll" %}</h4> | |
| 8 | +{% endblock title_poll %} | |
| 9 | + | |
| 10 | +{% block content_poll %} | |
| 11 | +<!-- Put ONLY your content here!!! --> | |
| 12 | +<form action="" method="post"> | |
| 13 | + {% csrf_token %} | |
| 14 | + <h2>{% trans 'Are you sure you want to delete the subject' %} "{{poll}}"?</h2> | |
| 15 | + <input type="submit" class="btn btn-raised btn-success btn-lg" value="{% trans 'Yes' %}" /> | |
| 16 | + <a href="" class="btn btn-raised btn-danger btn-lg">{% trans 'No' %}</a> | |
| 17 | +</form> | |
| 18 | +{% endblock content_poll %} | |
| 19 | + | |
| 20 | +{% block button_save %} | |
| 21 | +{% endblock button_save %} | ... | ... |
| ... | ... | @@ -0,0 +1,13 @@ |
| 1 | +{% extends "poll/create.html" %} | |
| 2 | + | |
| 3 | +{% load i18n dict_access static%} | |
| 4 | + | |
| 5 | +{% block title_poll %} | |
| 6 | +<!-- Put your title here!!! --> | |
| 7 | +<h4 class="modal-title" id="myModalLabel">{% trans "Update a Poll" %}</h4> | |
| 8 | +{% endblock title_poll %} | |
| 9 | + | |
| 10 | +{% block button_save %} | |
| 11 | +<!-- Put curtom buttons here!!! --> | |
| 12 | +<button type="submite" id="button" form="form" class="btn btn-primary btn-raised">{% trans "Update" %}</button> | |
| 13 | +{% endblock button_save %} | ... | ... |
poll/urls.py
| ... | ... | @@ -5,5 +5,8 @@ from . import views |
| 5 | 5 | urlpatterns = [ |
| 6 | 6 | url(r'^create/(?P<slug>[\w\-_]+)/$', views.CreatePoll.as_view(), name='create_poll'), # topic slug |
| 7 | 7 | url(r'^update/(?P<slug>[\w\-_]+)/$', views.UpdatePoll.as_view(), name='update_poll'), # poll slug |
| 8 | + url(r'^teste/(?P<slug>[\w\-_]+)/$', views.CreatePollModal.as_view(), name='teste'), # poll | |
| 9 | + url(r'^mymodal/', views.MyModal.as_view(), name='mymodal'), | |
| 10 | + url(r'^delete/(?P<slug>[\w\-_]+)/$', views.DeletePoll.as_view(), name='delete_poll'), # poll | |
| 8 | 11 | |
| 9 | 12 | ] | ... | ... |
poll/views.py
| ... | ... | @@ -8,6 +8,7 @@ from django.core.urlresolvers import reverse_lazy |
| 8 | 8 | from django.utils.translation import ugettext_lazy as _ |
| 9 | 9 | from rolepermissions.verifications import has_role |
| 10 | 10 | from rolepermissions.verifications import has_object_permission |
| 11 | +from django.db.models import Q | |
| 11 | 12 | # from django.views.generic.edit import FormMixin |
| 12 | 13 | |
| 13 | 14 | from .forms import PollForm |
| ... | ... | @@ -23,7 +24,7 @@ class CreatePoll(LoginRequiredMixin,generic.CreateView): |
| 23 | 24 | model = Poll |
| 24 | 25 | form_class = PollForm |
| 25 | 26 | context_object_name = 'poll' |
| 26 | - template_name = 'poll/create_update.html' | |
| 27 | + template_name = 'poll/create.html' | |
| 27 | 28 | success_url = reverse_lazy('core:home') |
| 28 | 29 | |
| 29 | 30 | def form_invalid(self, form,**kwargs): |
| ... | ... | @@ -66,7 +67,7 @@ class UpdatePoll(LoginRequiredMixin,generic.UpdateView): |
| 66 | 67 | model = Poll |
| 67 | 68 | form_class = PollForm |
| 68 | 69 | context_object_name = 'poll' |
| 69 | - template_name = 'poll/create_update.html' | |
| 70 | + template_name = 'poll/update.html' | |
| 70 | 71 | success_url = reverse_lazy('core:home') |
| 71 | 72 | |
| 72 | 73 | def dispatch(self, *args, **kwargs): |
| ... | ... | @@ -121,3 +122,98 @@ class UpdatePoll(LoginRequiredMixin,generic.UpdateView): |
| 121 | 122 | context['keys'] = keys |
| 122 | 123 | |
| 123 | 124 | return context |
| 125 | + | |
| 126 | +class DeletePoll(LoginRequiredMixin, generic.DeleteView): | |
| 127 | + | |
| 128 | + allowed_roles = ['professor', 'system_admin'] | |
| 129 | + login_url = reverse_lazy("core:home") | |
| 130 | + redirect_field_name = 'next' | |
| 131 | + model = Poll | |
| 132 | + template_name = 'poll/remove.html' | |
| 133 | + | |
| 134 | + # def dispatch(self, *args, **kwargs): | |
| 135 | + # poll = get_object_or_404(Poll, slug = self.kwargs.get('slug')) | |
| 136 | + # if(not has_object_permission('delete_subject', self.request.user, subject)): | |
| 137 | + # return self.handle_no_permission() | |
| 138 | + # return super(DeleteSubjectView, self).dispatch(*args, **kwargs) | |
| 139 | + | |
| 140 | + | |
| 141 | + def get_context_data(self, **kwargs): | |
| 142 | + context = super(DeletePoll, self).get_context_data(**kwargs) | |
| 143 | + context['course'] = self.object.topic.subject.course | |
| 144 | + context['subject'] = self.object.topic.subject | |
| 145 | + context['poll'] = self.object | |
| 146 | + context['subjects'] = self.object.topic.subject.course.subjects.filter(Q(visible=True) | Q(professors__in=[self.request.user])) | |
| 147 | + if (has_role(self.request.user,'system_admin')): | |
| 148 | + context['subjects'] = self.object.topic.subject.course.subjects.all() | |
| 149 | + return context | |
| 150 | + | |
| 151 | + def get_success_url(self): | |
| 152 | + return reverse_lazy('course:view_topic', kwargs={'slug' : self.object.topic.slug}) | |
| 153 | + | |
| 154 | + | |
| 155 | +from django_modalview.generic.edit import ModalCreateView | |
| 156 | +from django_modalview.generic.component import ModalResponse | |
| 157 | + | |
| 158 | +class CreatePollModal(LoginRequiredMixin,ModalCreateView): | |
| 159 | + | |
| 160 | + login_url = reverse_lazy("core:home") | |
| 161 | + redirect_field_name = 'next' | |
| 162 | + model = Poll | |
| 163 | + form_class = PollForm | |
| 164 | + context_object_name = 'poll' | |
| 165 | + template_name = 'poll/create.html' | |
| 166 | + success_url = reverse_lazy('core:home') | |
| 167 | + | |
| 168 | + def form_invalid(self, form,**kwargs): | |
| 169 | + context = super(CreatePollModal, self).form_invalid(form) | |
| 170 | + answers = {} | |
| 171 | + for key in self.request.POST: | |
| 172 | + if(key != 'csrfmiddlewaretoken' and key != 'name' and key != 'limit_date' and key != 'all_students' and key != 'students'): | |
| 173 | + answers[key] = self.request.POST[key] | |
| 174 | + | |
| 175 | + keys = sorted(answers) | |
| 176 | + context.context_data['answers'] = answers | |
| 177 | + context.context_data['keys'] = keys | |
| 178 | + return context | |
| 179 | + | |
| 180 | + def form_valid(self, form): | |
| 181 | + self.object = form.save(commit = False) | |
| 182 | + topic = get_object_or_404(Topic, slug = self.kwargs.get('slug')) | |
| 183 | + self.object.topic = topic | |
| 184 | + self.object.save() | |
| 185 | + | |
| 186 | + for key in self.request.POST: | |
| 187 | + if(key != 'csrfmiddlewaretoken' and key != 'name' and key != 'limit_date' and key != 'all_students' and key != 'students'): | |
| 188 | + answer = Answer(answer=self.request.POST[key],order=key,poll=self.object) | |
| 189 | + answer.save() | |
| 190 | + | |
| 191 | + return super(CreatePollModal, self).form_valid(form) | |
| 192 | + | |
| 193 | + def get_context_data(self, **kwargs): | |
| 194 | + context = super(CreatePollModal, self).get_context_data(**kwargs) | |
| 195 | + topic = get_object_or_404(Topic, slug = self.kwargs.get('slug')) | |
| 196 | + context['course'] = topic.subject.course | |
| 197 | + context['subject'] = topic.subject | |
| 198 | + context['subjects'] = topic.subject.course.subjects.all() | |
| 199 | + return context | |
| 200 | + | |
| 201 | + | |
| 202 | +from django_modalview.generic.base import ModalTemplateView | |
| 203 | + | |
| 204 | +class MyModal(ModalTemplateView): | |
| 205 | + ''' | |
| 206 | + This modal inherit of ModalTemplateView, so it just display a text without logic. | |
| 207 | + ''' | |
| 208 | + def __init__(self, *args, **kwargs): | |
| 209 | + ''' | |
| 210 | + You have to call the init method of the parent, before to overide the values: | |
| 211 | + - title: The title display in the modal-header | |
| 212 | + - icon: The css class that define the modal's icon | |
| 213 | + - description: The content of the modal. | |
| 214 | + - close_button: A button object that has several attributes.(explain below) | |
| 215 | + ''' | |
| 216 | + super(MyModal, self).__init__(*args, **kwargs) | |
| 217 | + self.title = "My modal" | |
| 218 | + self.description = "This is my description" | |
| 219 | + self.icon = "icon-mymodal" | ... | ... |