Commit d515cbf90e5c484dde766f9d1c027bc651c2f4b7
1 parent
33b19a45
Exists in
master
and in
3 other branches
Colocando a opção de varias notificações de pendencias para uma webconferencia
Showing
8 changed files
with
297 additions
and
200 deletions
Show diff stats
| ... | ... | @@ -0,0 +1,20 @@ |
| 1 | +# -*- coding: utf-8 -*- | |
| 2 | +# Generated by Django 1.10.4 on 2017-03-23 18:35 | |
| 3 | +from __future__ import unicode_literals | |
| 4 | + | |
| 5 | +from django.db import migrations, models | |
| 6 | + | |
| 7 | + | |
| 8 | +class Migration(migrations.Migration): | |
| 9 | + | |
| 10 | + dependencies = [ | |
| 11 | + ('pendencies', '0006_auto_20170224_0023'), | |
| 12 | + ] | |
| 13 | + | |
| 14 | + operations = [ | |
| 15 | + migrations.AlterField( | |
| 16 | + model_name='pendencies', | |
| 17 | + name='action', | |
| 18 | + field=models.CharField(blank=True, choices=[('view', 'Visualize'), ('create', 'Create'), ('answer', 'Answer'), ('access', 'Access'), ('participate', 'Participate'), ('finish', 'Finish'), ('submit', 'Submit')], max_length=100, verbose_name='Action'), | |
| 19 | + ), | |
| 20 | + ] | ... | ... |
pendencies/models.py
| ... | ... | @@ -5,8 +5,8 @@ from django.utils.translation import ugettext_lazy as _ |
| 5 | 5 | from topics.models import Resource |
| 6 | 6 | |
| 7 | 7 | class Pendencies(models.Model): |
| 8 | - action = models.CharField(_('Action'), max_length = 100, choices = (("view", _("Visualize")), ("create", _("Create")), ("answer", _("Answer")), ("access", _("Access")), ("finish", _("Finish")), ("submit", _("Submit"))), blank = True) | |
| 8 | + action = models.CharField(_('Action'), max_length = 100, choices = (("view", _("Visualize")), ("create", _("Create")), ("answer", _("Answer")), ("access", _("Access")), ("participate", _("Participate")), ("finish", _("Finish")), ("submit", _("Submit"))), blank = True) | |
| 9 | 9 | begin_date = models.DateTimeField(_('Begin Date'), null = True, blank = True) |
| 10 | 10 | end_date = models.DateTimeField(_('End Date'), null = True, blank = True) |
| 11 | 11 | limit_date = models.DateTimeField(_('Limit Date'), null = True, blank = True) |
| 12 | - resource = models.ForeignKey(Resource, verbose_name = _('Resource'), related_name = 'pendencies_resource', null = True) | |
| 13 | 12 | \ No newline at end of file |
| 13 | + resource = models.ForeignKey(Resource, verbose_name = _('Resource'), related_name = 'pendencies_resource', null = True) | ... | ... |
webconference/forms.py
| ... | ... | @@ -2,14 +2,19 @@ |
| 2 | 2 | from django import forms |
| 3 | 3 | from django.utils.translation import ugettext_lazy as _ |
| 4 | 4 | from django.utils.html import strip_tags |
| 5 | +from django.forms.models import inlineformset_factory | |
| 5 | 6 | import datetime |
| 6 | 7 | |
| 7 | 8 | from subjects.models import Tag |
| 8 | 9 | |
| 9 | 10 | from .models import Webconference, ConferenceSettings |
| 10 | 11 | |
| 12 | +from pendencies.forms import PendenciesForm | |
| 13 | +from pendencies.models import Pendencies | |
| 14 | + | |
| 11 | 15 | class WebconferenceForm(forms.ModelForm): |
| 12 | 16 | subject = None |
| 17 | + control_subject = forms.CharField(widget = forms.HiddenInput()) | |
| 13 | 18 | |
| 14 | 19 | def __init__(self, *args, **kwargs): |
| 15 | 20 | super(WebconferenceForm, self).__init__(*args, **kwargs) |
| ... | ... | @@ -20,6 +25,8 @@ class WebconferenceForm(forms.ModelForm): |
| 20 | 25 | self.subject = self.instance.topic.subject |
| 21 | 26 | self.initial['tags'] = ", ".join(self.instance.tags.all().values_list("name", flat = True)) |
| 22 | 27 | |
| 28 | + self.initial['control_subject'] = self.subject.id | |
| 29 | + | |
| 23 | 30 | self.fields['students'].queryset = self.subject.students.all() |
| 24 | 31 | self.fields['groups'].queryset = self.subject.group_subject.all() |
| 25 | 32 | |
| ... | ... | @@ -120,3 +127,5 @@ class SettingsForm(forms.ModelForm): |
| 120 | 127 | help_texts = { |
| 121 | 128 | 'domain': _('The domain of the jitsi server, e.g. meet.jit.si'), |
| 122 | 129 | } |
| 130 | + | |
| 131 | +InlinePendenciesFormset = inlineformset_factory(Webconference, Pendencies, form = PendenciesForm, extra = 1, max_num = 3, validate_max = True, can_delete = True) | ... | ... |
| ... | ... | @@ -0,0 +1,19 @@ |
| 1 | +# -*- coding: utf-8 -*- | |
| 2 | +# Generated by Django 1.10.4 on 2017-03-23 18:35 | |
| 3 | +from __future__ import unicode_literals | |
| 4 | + | |
| 5 | +from django.db import migrations | |
| 6 | + | |
| 7 | + | |
| 8 | +class Migration(migrations.Migration): | |
| 9 | + | |
| 10 | + dependencies = [ | |
| 11 | + ('webconference', '0002_conferencesettings'), | |
| 12 | + ] | |
| 13 | + | |
| 14 | + operations = [ | |
| 15 | + migrations.AlterModelOptions( | |
| 16 | + name='conferencesettings', | |
| 17 | + options={'verbose_name': 'Web Conference Setting', 'verbose_name_plural': 'Web Conferences Setting'}, | |
| 18 | + ), | |
| 19 | + ] | ... | ... |
webconference/templates/webconference/_form.html
| ... | ... | @@ -143,98 +143,104 @@ |
| 143 | 143 | </div> |
| 144 | 144 | </div> |
| 145 | 145 | <div id="notifications" class="panel-collapse collapse"> |
| 146 | - | |
| 147 | - <div class="notifies"> | |
| 148 | - <div style="text-align:left"> | |
| 149 | - {% render_field pendencies_form.id %} | |
| 150 | - {% render_field pendencies_form.resource %} | |
| 151 | - {% render_field pendencies_form.subject class='pend_subj' %} | |
| 152 | - | |
| 153 | - <div class="form-group{% if pendencies_form.has_error %} has-error {% endif %} row"> | |
| 154 | - <label for="{{ pendencies_form.action.auto_id }}" class="pull-left action_label contol-label"> | |
| 155 | - {% trans 'Action not performed by the user' %}: | |
| 156 | - </label> | |
| 157 | - <div class="col-md-3"> | |
| 158 | - {% render_field pendencies_form.action class='form-control' %} | |
| 159 | - </div> | |
| 160 | - | |
| 161 | - <br clear="all" /> | |
| 162 | - | |
| 163 | - <span id="helpBlock" class="help-block">{{ pendencies_form.action.help_text }}</span> | |
| 164 | - | |
| 165 | - {% if pendencies_form.action.errors %} | |
| 166 | - <div class="alert alert-danger alert-dismissible" role="alert"> | |
| 167 | - <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | |
| 168 | - <span aria-hidden="true">×</span> | |
| 169 | - </button> | |
| 170 | - <ul> | |
| 171 | - {% for error in pendencies_form.action.errors %} | |
| 172 | - <li>{{ error }}</li> | |
| 173 | - {% endfor %} | |
| 174 | - </ul> | |
| 175 | - </div> | |
| 176 | - {% endif %} | |
| 177 | - </div> | |
| 178 | - <br clear="all" /> | |
| 179 | - <div class="row"> | |
| 180 | - <div class="col-md-12"> | |
| 181 | - <p>{% trans 'Wished period' %}: </p> | |
| 182 | - </div> | |
| 183 | - </div> | |
| 184 | - <div class="form-group{% if pendencies_form.has_error %} has-error {% endif %} row"> | |
| 185 | - <div class="col-lg-2 col-md-2 col-sm-2 col-xs-3 checkbox"> | |
| 186 | - <label> | |
| 187 | - {% render_field pendencies_form.begin_date_check class="begin_date" %} {{ pendencies_form.begin_date.label }} | |
| 188 | - </label> | |
| 189 | - </div> | |
| 190 | - <div class="col-lg-4 col-md-4 col-sm-4 col-xs-4"> | |
| 191 | - {% render_field pendencies_form.begin_date class='form-control datetime-picker begin_date_input' %} | |
| 192 | - </div> | |
| 193 | - </div> | |
| 194 | - <div class="row"> | |
| 195 | - <span id="helpBlock" class="help-block">{{ pendencies_form.begin_date.help_text }}</span> | |
| 196 | - | |
| 197 | - {% if pendencies_form.begin_date.errors %} | |
| 198 | - <div class="alert alert-danger alert-dismissible" role="alert"> | |
| 199 | - <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | |
| 200 | - <span aria-hidden="true">×</span> | |
| 201 | - </button> | |
| 202 | - <ul> | |
| 203 | - {% for error in pendencies_form.begin_date.errors %} | |
| 204 | - <li>{{ error }}</li> | |
| 205 | - {% endfor %} | |
| 206 | - </ul> | |
| 207 | - </div> | |
| 208 | - {% endif %} | |
| 209 | - </div> | |
| 210 | - <div class="form-group{% if pendencies_form.has_error %} has-error {% endif %} row"> | |
| 211 | - <div class="col-lg-2 col-md-2 col-sm-2 col-xs-3 checkbox"> | |
| 212 | - <label> | |
| 213 | - {% render_field pendencies_form.end_date_check class="end_date" %} {{ pendencies_form.end_date.label }} | |
| 214 | - </label> | |
| 215 | - </div> | |
| 216 | - <div class="col-lg-4 col-md-4 col-sm-4 col-xs-4"> | |
| 217 | - {% render_field pendencies_form.end_date class='form-control datetime-picker end_date_input' %} | |
| 218 | - </div> | |
| 219 | - </div> | |
| 220 | - <div class="row"> | |
| 221 | - <span id="helpBlock" class="help-block">{{ pendencies_form.end_date.help_text }}</span> | |
| 222 | - | |
| 223 | - {% if pendencies_form.end_date.errors %} | |
| 224 | - <div class="alert alert-danger alert-dismissible" role="alert"> | |
| 225 | - <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | |
| 226 | - <span aria-hidden="true">×</span> | |
| 227 | - </button> | |
| 228 | - <ul> | |
| 229 | - {% for error in pendencies_form.end_date.errors %} | |
| 230 | - <li>{{ error }}</li> | |
| 231 | - {% endfor %} | |
| 232 | - </ul> | |
| 233 | - </div> | |
| 234 | - {% endif %} | |
| 235 | - </div> | |
| 146 | + {{ pendencies_form.management_form }} | |
| 147 | + {{ pendencies_form.non_form_errors }} | |
| 148 | + | |
| 149 | + {% for notify in pendencies_form %} | |
| 150 | + <div class="notifies"> | |
| 151 | + <div style="text-align:left"> | |
| 152 | + {% render_field notify.id %} | |
| 153 | + {% render_field notify.resource %} | |
| 154 | + {% render_field notify.subject class='pend_subj' %} | |
| 155 | + | |
| 156 | + {% if notify.instance.pk %}{{ notify.DELETE }}{% endif %} | |
| 157 | + | |
| 158 | + <div class="form-group{% if notify.has_error %} has-error {% endif %} row"> | |
| 159 | + <label for="{{ notify.action.auto_id }}" class="pull-left action_label contol-label"> | |
| 160 | + {% trans 'Action not performed by the user' %}: | |
| 161 | + </label> | |
| 162 | + <div class="col-md-3"> | |
| 163 | + {% render_field notify.action class='form-control' %} | |
| 164 | + </div> | |
| 165 | + | |
| 166 | + <br clear="all" /> | |
| 167 | + | |
| 168 | + <span id="helpBlock" class="help-block">{{ notify.action.help_text }}</span> | |
| 169 | + | |
| 170 | + {% if notify.action.errors %} | |
| 171 | + <div class="alert alert-danger alert-dismissible" role="alert"> | |
| 172 | + <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | |
| 173 | + <span aria-hidden="true">×</span> | |
| 174 | + </button> | |
| 175 | + <ul> | |
| 176 | + {% for error in notify.action.errors %} | |
| 177 | + <li>{{ error }}</li> | |
| 178 | + {% endfor %} | |
| 179 | + </ul> | |
| 180 | + </div> | |
| 181 | + {% endif %} | |
| 182 | + </div> | |
| 183 | + <br clear="all" /> | |
| 184 | + <div class="row"> | |
| 185 | + <div class="col-md-12"> | |
| 186 | + <p>{% trans 'Wished period' %}: </p> | |
| 187 | + </div> | |
| 188 | + </div> | |
| 189 | + <div class="form-group{% if notify.has_error %} has-error {% endif %} row"> | |
| 190 | + <div class="col-lg-2 col-md-2 col-sm-2 col-xs-3 checkbox"> | |
| 191 | + <label> | |
| 192 | + {% render_field notify.begin_date_check class="begin_date" %} {{ notify.begin_date.label }} | |
| 193 | + </label> | |
| 194 | + </div> | |
| 195 | + <div class="col-lg-4 col-md-4 col-sm-4 col-xs-4"> | |
| 196 | + {% render_field notify.begin_date class='form-control datetime-picker begin_date_input' %} | |
| 197 | + </div> | |
| 198 | + </div> | |
| 199 | + <div class="row"> | |
| 200 | + <span id="helpBlock" class="help-block">{{ notify.begin_date.help_text }}</span> | |
| 201 | + | |
| 202 | + {% if notify.begin_date.errors %} | |
| 203 | + <div class="alert alert-danger alert-dismissible" role="alert"> | |
| 204 | + <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | |
| 205 | + <span aria-hidden="true">×</span> | |
| 206 | + </button> | |
| 207 | + <ul> | |
| 208 | + {% for error in notify.begin_date.errors %} | |
| 209 | + <li>{{ error }}</li> | |
| 210 | + {% endfor %} | |
| 211 | + </ul> | |
| 212 | + </div> | |
| 213 | + {% endif %} | |
| 214 | + </div> | |
| 215 | + <div class="form-group{% if notify.has_error %} has-error {% endif %} row"> | |
| 216 | + <div class="col-lg-2 col-md-2 col-sm-2 col-xs-3 checkbox"> | |
| 217 | + <label> | |
| 218 | + {% render_field notify.end_date_check class="end_date" %} {{ notify.end_date.label }} | |
| 219 | + </label> | |
| 220 | + </div> | |
| 221 | + <div class="col-lg-4 col-md-4 col-sm-4 col-xs-4"> | |
| 222 | + {% render_field notify.end_date class='form-control datetime-picker end_date_input' %} | |
| 223 | + </div> | |
| 224 | + </div> | |
| 225 | + <div class="row"> | |
| 226 | + <span id="helpBlock" class="help-block">{{ notify.end_date.help_text }}</span> | |
| 227 | + | |
| 228 | + {% if notify.end_date.errors %} | |
| 229 | + <div class="alert alert-danger alert-dismissible" role="alert"> | |
| 230 | + <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | |
| 231 | + <span aria-hidden="true">×</span> | |
| 232 | + </button> | |
| 233 | + <ul> | |
| 234 | + {% for error in notify.end_date.errors %} | |
| 235 | + <li>{{ error }}</li> | |
| 236 | + {% endfor %} | |
| 237 | + </ul> | |
| 238 | + </div> | |
| 239 | + {% endif %} | |
| 240 | + </div> | |
| 241 | + </div> | |
| 236 | 242 | </div> |
| 237 | - </div> | |
| 243 | + {% endfor %} | |
| 238 | 244 | </div> |
| 239 | 245 | </div> |
| 240 | 246 | |
| ... | ... | @@ -274,7 +280,7 @@ |
| 274 | 280 | {% endif %} |
| 275 | 281 | </div> |
| 276 | 282 | |
| 277 | - <p><em>{% trans 'Attribute students to web conference' %}:</em></p> | |
| 283 | + <p><em>{% trans 'Attribute students to YouTube Video' %}:</em></p> | |
| 278 | 284 | {% render_field form.students class='form-control' %} |
| 279 | 285 | |
| 280 | 286 | <span id="helpBlock" class="help-block">{{ form.students.help_text }}</span> |
| ... | ... | @@ -294,7 +300,7 @@ |
| 294 | 300 | |
| 295 | 301 | <br clear="all" /> |
| 296 | 302 | |
| 297 | - <p><em>{% trans 'Attribute groups to web conference' %}:</em></p> | |
| 303 | + <p><em>{% trans 'Attribute groups to YouTube Video' %}:</em></p> | |
| 298 | 304 | {% render_field form.groups class='form-control' %} |
| 299 | 305 | |
| 300 | 306 | <span id="helpBlock" class="help-block">{{ form.groups.help_text }}</span> |
| ... | ... | @@ -369,16 +375,53 @@ |
| 369 | 375 | </form> |
| 370 | 376 | <script type="text/javascript"> |
| 371 | 377 | $(function() { |
| 372 | - var begin_val = $('.begin_date_input').val(), | |
| 373 | - end_val = $('.end_date_input').val(); | |
| 374 | - | |
| 375 | - if (begin_val != '') { | |
| 376 | - $(".begin_date").prop('checked', true); | |
| 377 | - } | |
| 378 | - | |
| 379 | - if (end_val != '') { | |
| 380 | - $(".end_date").prop('checked', true); | |
| 381 | - } | |
| 378 | + $('.notifies').formset({ | |
| 379 | + addText: '{% trans "Add new notification" %}', | |
| 380 | + deleteText: '{% trans "Remove this" %}', | |
| 381 | + prefix: '{{ pendencies_form.prefix }}', | |
| 382 | + added: function (row) { | |
| 383 | + var locale = navigator.language || navigator.userLanguage; | |
| 384 | + | |
| 385 | + $(row).find('.datetime-picker').each(function () { | |
| 386 | + $(this).datetimepicker({ | |
| 387 | + locale: locale | |
| 388 | + }); | |
| 389 | + }); | |
| 390 | + $('.begin_date_input').on('click', function () { | |
| 391 | + var checkbox = $(this).parent().parent().find('.begin_date'); | |
| 392 | + $(checkbox).prop('checked', true); | |
| 393 | + }); | |
| 394 | + $('.end_date_input').on('click', function () { | |
| 395 | + var checkbox = $(this).parent().parent().find('.end_date'); | |
| 396 | + $(checkbox).prop('checked', true); | |
| 397 | + }); | |
| 398 | + | |
| 399 | + var subject = $("#id_control_subject").val(); | |
| 400 | + | |
| 401 | + $(row).find('.pend_subj').val(subject); | |
| 402 | + } | |
| 403 | + }); | |
| 404 | + | |
| 405 | + $('.begin_date_input').each(function () { | |
| 406 | + console.log($(this).val()); | |
| 407 | + if ($(this).val() != '') { | |
| 408 | + $(this).parent().parent().find('.begin_date').prop('checked', true); | |
| 409 | + } else { | |
| 410 | + $(this).parent().parent().find('.begin_date').prop('checked', false); | |
| 411 | + } | |
| 412 | + }); | |
| 413 | + | |
| 414 | + $('.end_date_input').each(function () { | |
| 415 | + if ($(this).val() != '') { | |
| 416 | + $(this).parent().parent().find('.end_date').prop('checked', true); | |
| 417 | + } else { | |
| 418 | + $(this).parent().parent().find('.end_date').prop('checked', false); | |
| 419 | + } | |
| 420 | + }); | |
| 421 | + | |
| 422 | + var subject = $("#id_control_subject").val(); | |
| 423 | + | |
| 424 | + $('.pend_subj').val(subject); | |
| 382 | 425 | |
| 383 | 426 | {% if not pendencies_form.is_valid and pendencies_form.is_bound %} |
| 384 | 427 | $("#notifications").collapse('toggle'); | ... | ... |
webconference/templates/webconference/create.html
| ... | ... | @@ -10,6 +10,7 @@ |
| 10 | 10 | {% block javascript %} |
| 11 | 11 | {{block.super}} |
| 12 | 12 | <script type="text/javascript" src="{% static 'js/bootstrap-tagsinput.js' %} "></script> |
| 13 | + <script type="text/javascript" src="{% static 'js/jquery.formset.js' %} "></script> | |
| 13 | 14 | {% endblock %} |
| 14 | 15 | |
| 15 | 16 | {% block breadcrumbs %} | ... | ... |
webconference/templates/webconference/update.html
| ... | ... | @@ -10,6 +10,7 @@ |
| 10 | 10 | {% block javascript %} |
| 11 | 11 | {{block.super}} |
| 12 | 12 | <script type="text/javascript" src="{% static 'js/bootstrap-tagsinput.js' %} "></script> |
| 13 | + <script type="text/javascript" src="{% static 'js/jquery.formset.js' %} "></script> | |
| 13 | 14 | {% endblock %} |
| 14 | 15 | |
| 15 | 16 | {% block breadcrumbs %} | ... | ... |
webconference/views.py
| ... | ... | @@ -18,7 +18,7 @@ from topics.models import Topic |
| 18 | 18 | from pendencies.forms import PendenciesForm |
| 19 | 19 | from braces import views as braces_mixins |
| 20 | 20 | |
| 21 | -from .forms import WebconferenceForm, SettingsForm | |
| 21 | +from .forms import WebconferenceForm, SettingsForm, InlinePendenciesFormset | |
| 22 | 22 | from .models import Webconference, ConferenceSettings as Settings |
| 23 | 23 | |
| 24 | 24 | class NewWindowView(LoginRequiredMixin,LogMixin, generic.DetailView): |
| ... | ... | @@ -142,7 +142,7 @@ def participating(request): |
| 142 | 142 | |
| 143 | 143 | return JsonResponse({'message':'ok'}) |
| 144 | 144 | |
| 145 | -@log_decorator('resources', 'finish', 'webconference') | |
| 145 | +@log_decorator('resources', 'participate', 'webconference') | |
| 146 | 146 | def finish(request): |
| 147 | 147 | |
| 148 | 148 | webconference = get_object_or_404(Webconference, slug = request.GET['roomName']) |
| ... | ... | @@ -244,7 +244,8 @@ class CreateView(LoginRequiredMixin, LogMixin, generic.edit.CreateView): |
| 244 | 244 | |
| 245 | 245 | slug = self.kwargs.get('slug', '') |
| 246 | 246 | topic = get_object_or_404(Topic, slug = slug) |
| 247 | - pendencies_form = PendenciesForm(initial = {'subject': topic.subject.id, 'actions': [("", "-------"),("view", _("Visualize"))]}) | |
| 247 | + pendencies_form = InlinePendenciesFormset(initial = [{'subject': topic.subject.id, 'actions': [("", "-------"),("view", _("Visualize")), ("participate", _("Participate"))]}]) | |
| 248 | + print (pendencies_form) | |
| 248 | 249 | return self.render_to_response(self.get_context_data(form = form, pendencies_form = pendencies_form)) |
| 249 | 250 | |
| 250 | 251 | def post(self, request, *args, **kwargs): |
| ... | ... | @@ -256,12 +257,12 @@ class CreateView(LoginRequiredMixin, LogMixin, generic.edit.CreateView): |
| 256 | 257 | slug = self.kwargs.get('slug', '') |
| 257 | 258 | topic = get_object_or_404(Topic, slug = slug) |
| 258 | 259 | |
| 259 | - pendencies_form = PendenciesForm(self.request.POST, initial = {'subject': topic.subject.id, 'actions': [("", "-------"),("view", _("Visualize"))]}) | |
| 260 | + pendencies_form = InlinePendenciesFormset(self.request.POST, initial = [{'subject': topic.subject.id, 'actions': [("", "-------"),("view", _("Visualize")), ("participate", _("Participate"))]}]) | |
| 260 | 261 | |
| 261 | 262 | if (form.is_valid() and pendencies_form.is_valid()): |
| 262 | - return self.form_valid(form, pendencies_form) | |
| 263 | + return self.form_valid(form, pendencies_form) | |
| 263 | 264 | else: |
| 264 | - return self.form_invalid(form, pendencies_form) | |
| 265 | + return self.form_invalid(form, pendencies_form) | |
| 265 | 266 | |
| 266 | 267 | def get_initial(self): |
| 267 | 268 | initial = super(CreateView, self).get_initial() |
| ... | ... | @@ -274,6 +275,11 @@ class CreateView(LoginRequiredMixin, LogMixin, generic.edit.CreateView): |
| 274 | 275 | return initial |
| 275 | 276 | |
| 276 | 277 | def form_invalid(self, form, pendencies_form): |
| 278 | + # print (form," Form") | |
| 279 | + # print (pendencies_form, " Penden") | |
| 280 | + for p_form in pendencies_form.forms: | |
| 281 | + p_form.fields['action'].choices = [("", "-------"),("view", _("Visualize")), ("participate", _("Participate"))] | |
| 282 | + print ("Invalid") | |
| 277 | 283 | return self.render_to_response(self.get_context_data(form = form, pendencies_form = pendencies_form)) |
| 278 | 284 | |
| 279 | 285 | def form_valid(self, form, pendencies_form): |
| ... | ... | @@ -289,13 +295,15 @@ class CreateView(LoginRequiredMixin, LogMixin, generic.edit.CreateView): |
| 289 | 295 | self.object.visible = False |
| 290 | 296 | |
| 291 | 297 | self.object.save() |
| 292 | - pend_form = pendencies_form.save(commit = False) | |
| 293 | - pend_form.resource = self.object | |
| 294 | - | |
| 295 | - if not pend_form.action == "": | |
| 296 | - pend_form.save() | |
| 298 | + pendencies_form.instance = self.object | |
| 299 | + pendencies_form.save(commit = False) | |
| 297 | 300 | |
| 301 | + for pform in pendencies_form.forms: | |
| 302 | + pend_form = pform.save(commit = False) | |
| 298 | 303 | |
| 304 | + if not pend_form.action == "": | |
| 305 | + pend_form.save() | |
| 306 | + print ("Valid") | |
| 299 | 307 | self.log_context['category_id'] = self.object.topic.subject.category.id |
| 300 | 308 | self.log_context['category_name'] = self.object.topic.subject.category.name |
| 301 | 309 | self.log_context['category_slug'] = self.object.topic.subject.category.slug |
| ... | ... | @@ -341,126 +349,122 @@ class CreateView(LoginRequiredMixin, LogMixin, generic.edit.CreateView): |
| 341 | 349 | return success_url |
| 342 | 350 | |
| 343 | 351 | class UpdateView(LoginRequiredMixin, LogMixin, generic.UpdateView): |
| 344 | - log_component = 'resources' | |
| 345 | - log_action = 'update' | |
| 346 | - log_resource = 'webconference' | |
| 347 | - log_context = {} | |
| 352 | + log_component = 'resources' | |
| 353 | + log_action = 'update' | |
| 354 | + log_resource = 'webconference' | |
| 355 | + log_context = {} | |
| 348 | 356 | |
| 349 | - login_url = reverse_lazy("users:login") | |
| 350 | - redirect_field_name = 'next' | |
| 357 | + login_url = reverse_lazy("users:login") | |
| 358 | + redirect_field_name = 'next' | |
| 351 | 359 | |
| 352 | - template_name = 'webconference/update.html' | |
| 353 | - model = Webconference | |
| 354 | - form_class = WebconferenceForm | |
| 360 | + template_name = 'webconference/update.html' | |
| 361 | + model = Webconference | |
| 362 | + form_class = WebconferenceForm | |
| 355 | 363 | |
| 356 | - def dispatch(self, request, *args, **kwargs): | |
| 357 | - slug = self.kwargs.get('topic_slug', '') | |
| 358 | - topic = get_object_or_404(Topic, slug = slug) | |
| 364 | + def dispatch(self, request, *args, **kwargs): | |
| 365 | + slug = self.kwargs.get('topic_slug', '') | |
| 366 | + topic = get_object_or_404(Topic, slug = slug) | |
| 359 | 367 | |
| 360 | - if not has_subject_permissions(request.user, topic.subject): | |
| 361 | - return redirect(reverse_lazy('subjects:home')) | |
| 368 | + if not has_subject_permissions(request.user, topic.subject): | |
| 369 | + return redirect(reverse_lazy('subjects:home')) | |
| 362 | 370 | |
| 363 | - return super(UpdateView, self).dispatch(request, *args, **kwargs) | |
| 371 | + return super(UpdateView, self).dispatch(request, *args, **kwargs) | |
| 364 | 372 | |
| 365 | - def get(self, request, *args, **kwargs): | |
| 366 | - self.object = self.get_object() | |
| 373 | + def get(self, request, *args, **kwargs): | |
| 374 | + self.object = self.get_object() | |
| 367 | 375 | |
| 368 | - form_class = self.get_form_class() | |
| 369 | - form = self.get_form(form_class) | |
| 376 | + form_class = self.get_form_class() | |
| 377 | + form = self.get_form(form_class) | |
| 370 | 378 | |
| 371 | - slug = self.kwargs.get('topic_slug', '') | |
| 372 | - topic = get_object_or_404(Topic, slug = slug) | |
| 379 | + slug = self.kwargs.get('topic_slug', '') | |
| 380 | + topic = get_object_or_404(Topic, slug = slug) | |
| 373 | 381 | |
| 374 | - pend_form = self.object.pendencies_resource.all() | |
| 382 | + pendencies_form = InlinePendenciesFormset(instance=self.object, initial = [{'subject': topic.subject.id, 'actions': [("", "-------"),("view", _("Visualize")), ("participate", _("Participate"))]}]) | |
| 375 | 383 | |
| 376 | - if len(pend_form) > 0: | |
| 377 | - pendencies_form = PendenciesForm(instance = pend_form[0], initial = {'subject': topic.subject.id, 'actions': [("", "-------"),("view", _("Visualize"))]}) | |
| 378 | - else: | |
| 379 | - pendencies_form = PendenciesForm(initial = {'subject': topic.subject.id, 'actions': [("", "-------"),("view", _("Visualize"))]}) | |
| 384 | + return self.render_to_response(self.get_context_data(form = form, pendencies_form = pendencies_form)) | |
| 380 | 385 | |
| 381 | - return self.render_to_response(self.get_context_data(form = form, pendencies_form = pendencies_form)) | |
| 386 | + def post(self, request, *args, **kwargs): | |
| 387 | + self.object = self.get_object() | |
| 382 | 388 | |
| 383 | - def post(self, request, *args, **kwargs): | |
| 384 | - self.object = self.get_object() | |
| 389 | + form_class = self.get_form_class() | |
| 390 | + form = self.get_form(form_class) | |
| 385 | 391 | |
| 386 | - form_class = self.get_form_class() | |
| 387 | - form = self.get_form(form_class) | |
| 392 | + slug = self.kwargs.get('topic_slug', '') | |
| 393 | + topic = get_object_or_404(Topic, slug = slug) | |
| 388 | 394 | |
| 389 | - slug = self.kwargs.get('topic_slug', '') | |
| 390 | - topic = get_object_or_404(Topic, slug = slug) | |
| 395 | + pendencies_form = InlinePendenciesFormset(self.request.POST, instance = self.object, initial = [{'subject': topic.subject.id, 'actions': [("", "-------"),("view", _("Visualize")), ("participate", _("Participate"))]}]) | |
| 391 | 396 | |
| 392 | - pend_form = self.object.pendencies_resource.all() | |
| 397 | + if (form.is_valid() and pendencies_form.is_valid()): | |
| 398 | + return self.form_valid(form, pendencies_form) | |
| 399 | + else: | |
| 400 | + return self.form_invalid(form, pendencies_form) | |
| 393 | 401 | |
| 394 | - if len(pend_form) > 0: | |
| 395 | - pendencies_form = PendenciesForm(self.request.POST, instance = pend_form[0], initial = {'subject': topic.subject.id, 'actions': [("", "-------"),("view", _("Visualize"))]}) | |
| 396 | - else: | |
| 397 | - pendencies_form = PendenciesForm(self.request.POST, initial = {'subject': topic.subject.id, 'actions': [("", "-------"),("view", _("Visualize"))]}) | |
| 402 | + def form_invalid(self, form, pendencies_form): | |
| 403 | + for p_form in pendencies_form.forms: | |
| 404 | + p_form.fields['action'].choices = [("", "-------"),("view", _("Visualize")), ("participate", _("Participate"))] | |
| 398 | 405 | |
| 399 | - if (form.is_valid() and pendencies_form.is_valid()): | |
| 400 | - return self.form_valid(form, pendencies_form) | |
| 401 | - else: | |
| 402 | - return self.form_invalid(form, pendencies_form) | |
| 406 | + return self.render_to_response(self.get_context_data(form = form, pendencies_form = pendencies_form)) | |
| 403 | 407 | |
| 404 | - def form_invalid(self, form, pendencies_form): | |
| 405 | - return self.render_to_response(self.get_context_data(form = form, pendencies_form = pendencies_form)) | |
| 408 | + def form_valid(self, form, pendencies_form): | |
| 409 | + self.object = form.save(commit = False) | |
| 406 | 410 | |
| 407 | - def form_valid(self, form, pendencies_form): | |
| 408 | - self.object = form.save(commit = False) | |
| 411 | + if not self.object.topic.visible and not self.object.topic.repository: | |
| 412 | + self.object.visible = False | |
| 409 | 413 | |
| 410 | - if not self.object.topic.visible and not self.object.topic.repository: | |
| 411 | - self.object.visible = False | |
| 414 | + self.object.save() | |
| 412 | 415 | |
| 413 | - self.object.save() | |
| 416 | + pendencies_form.instance = self.object | |
| 417 | + pendencies_form.save(commit = False) | |
| 414 | 418 | |
| 415 | - pend_form = pendencies_form.save(commit = False) | |
| 416 | - pend_form.resource = self.object | |
| 419 | + for form in pendencies_form.forms: | |
| 420 | + pend_form = form.save(commit = False) | |
| 417 | 421 | |
| 418 | - if not pend_form.action == "": | |
| 419 | - pend_form.save() | |
| 422 | + if not pend_form.action == "": | |
| 423 | + pend_form.save() | |
| 420 | 424 | |
| 421 | - self.log_context['category_id'] = self.object.topic.subject.category.id | |
| 422 | - self.log_context['category_name'] = self.object.topic.subject.category.name | |
| 423 | - self.log_context['category_slug'] = self.object.topic.subject.category.slug | |
| 424 | - self.log_context['subject_id'] = self.object.topic.subject.id | |
| 425 | - self.log_context['subject_name'] = self.object.topic.subject.name | |
| 426 | - self.log_context['subject_slug'] = self.object.topic.subject.slug | |
| 427 | - self.log_context['topic_id'] = self.object.topic.id | |
| 428 | - self.log_context['topic_name'] = self.object.topic.name | |
| 429 | - self.log_context['topic_slug'] = self.object.topic.slug | |
| 430 | - self.log_context['webconference_id'] = self.object.id | |
| 431 | - self.log_context['webconference_name'] = self.object.name | |
| 432 | - self.log_context['webconference_slug'] = self.object.slug | |
| 425 | + self.log_context['category_id'] = self.object.topic.subject.category.id | |
| 426 | + self.log_context['category_name'] = self.object.topic.subject.category.name | |
| 427 | + self.log_context['category_slug'] = self.object.topic.subject.category.slug | |
| 428 | + self.log_context['subject_id'] = self.object.topic.subject.id | |
| 429 | + self.log_context['subject_name'] = self.object.topic.subject.name | |
| 430 | + self.log_context['subject_slug'] = self.object.topic.subject.slug | |
| 431 | + self.log_context['topic_id'] = self.object.topic.id | |
| 432 | + self.log_context['topic_name'] = self.object.topic.name | |
| 433 | + self.log_context['topic_slug'] = self.object.topic.slug | |
| 434 | + self.log_context['webconference_id'] = self.object.id | |
| 435 | + self.log_context['webconference_name'] = self.object.name | |
| 436 | + self.log_context['webconference_slug'] = self.object.slug | |
| 433 | 437 | |
| 434 | - super(UpdateView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | |
| 438 | + super(UpdateView, self).createLog(self.request.user, self.log_component, self.log_action, self.log_resource, self.log_context) | |
| 435 | 439 | |
| 436 | - return redirect(self.get_success_url()) | |
| 440 | + return redirect(self.get_success_url()) | |
| 437 | 441 | |
| 438 | - def get_context_data(self, **kwargs): | |
| 439 | - context = super(UpdateView, self).get_context_data(**kwargs) | |
| 442 | + def get_context_data(self, **kwargs): | |
| 443 | + context = super(UpdateView, self).get_context_data(**kwargs) | |
| 440 | 444 | |
| 441 | - context['title'] = _('Update Web Conference') | |
| 445 | + context['title'] = _('Update Web Conference') | |
| 442 | 446 | |
| 443 | - slug = self.kwargs.get('topic_slug', '') | |
| 444 | - topic = get_object_or_404(Topic, slug = slug) | |
| 447 | + slug = self.kwargs.get('topic_slug', '') | |
| 448 | + topic = get_object_or_404(Topic, slug = slug) | |
| 445 | 449 | |
| 446 | - context['topic'] = topic | |
| 447 | - context['subject'] = topic.subject | |
| 450 | + context['topic'] = topic | |
| 451 | + context['subject'] = topic.subject | |
| 448 | 452 | |
| 449 | - return context | |
| 453 | + return context | |
| 450 | 454 | |
| 451 | - def get_success_url(self): | |
| 452 | - messages.success(self.request, _('The Web conference "%s" was updated successfully!')%(self.object.name)) | |
| 455 | + def get_success_url(self): | |
| 456 | + messages.success(self.request, _('The Web conference "%s" was updated successfully!')%(self.object.name)) | |
| 453 | 457 | |
| 454 | - success_url = reverse_lazy('webconferences:view', kwargs = {'slug': self.object.slug}) | |
| 458 | + success_url = reverse_lazy('webconferences:view', kwargs = {'slug': self.object.slug}) | |
| 455 | 459 | |
| 456 | - if self.object.show_window: | |
| 457 | - self.request.session['resources'] = {} | |
| 458 | - self.request.session['resources']['new_page'] = True | |
| 459 | - self.request.session['resources']['new_page_url'] = reverse('webconferences:window_view', kwargs = {'slug': self.object.slug}) | |
| 460 | + if self.object.show_window: | |
| 461 | + self.request.session['resources'] = {} | |
| 462 | + self.request.session['resources']['new_page'] = True | |
| 463 | + self.request.session['resources']['new_page_url'] = reverse('webconferences:window_view', kwargs = {'slug': self.object.slug}) | |
| 460 | 464 | |
| 461 | - success_url = reverse_lazy('subjects:view', kwargs = {'slug': self.object.topic.subject.slug}) | |
| 465 | + success_url = reverse_lazy('subjects:view', kwargs = {'slug': self.object.topic.subject.slug}) | |
| 462 | 466 | |
| 463 | - return success_url | |
| 467 | + return success_url | |
| 464 | 468 | |
| 465 | 469 | class DeleteView(LoginRequiredMixin, LogMixin, generic.DeleteView): |
| 466 | 470 | log_component = 'resources' | ... | ... |