Commit 02e08c20404c2cd77a91fad87843eafcdfb69894
1 parent
da00b768
Exists in
master
and in
3 other branches
Adjusting webpage update
Showing
6 changed files
with
72 additions
and
55 deletions
Show diff stats
pendencies/forms.py
| ... | ... | @@ -13,12 +13,6 @@ class PendenciesForm(forms.ModelForm): |
| 13 | 13 | |
| 14 | 14 | def __init__(self, *args, **kwargs): |
| 15 | 15 | super(PendenciesForm, self).__init__(*args, **kwargs) |
| 16 | - | |
| 17 | - if kwargs.get('initial'): | |
| 18 | - subject = kwargs['initial'].get('subject', None) | |
| 19 | - | |
| 20 | - if subject: | |
| 21 | - self.initial['subject'] = subject.id | |
| 22 | 16 | |
| 23 | 17 | begin_date_check = forms.BooleanField(required = False) |
| 24 | 18 | end_date_check = forms.BooleanField(required = False) |
| ... | ... | @@ -30,12 +24,19 @@ class PendenciesForm(forms.ModelForm): |
| 30 | 24 | def clean(self): |
| 31 | 25 | cleaned_data = super(PendenciesForm, self).clean() |
| 32 | 26 | |
| 27 | + pend_id = cleaned_data.get('id', None) | |
| 28 | + | |
| 29 | + action = cleaned_data.get('action', None) | |
| 33 | 30 | begin_date = cleaned_data.get('begin_date', None) |
| 34 | 31 | end_date = cleaned_data.get('end_date', None) |
| 35 | 32 | begin_check = cleaned_data.get('begin_date_check', False) |
| 36 | 33 | end_check = cleaned_data.get('end_date_check', False) |
| 37 | 34 | subject_id = cleaned_data.get('subject', None) |
| 38 | 35 | |
| 36 | + if begin_check or end_check: | |
| 37 | + if not action: | |
| 38 | + self.add_error('action', _('This field is required.')) | |
| 39 | + | |
| 39 | 40 | if not begin_date and begin_check: |
| 40 | 41 | self.add_error('begin_date', _('This field is required.')) |
| 41 | 42 | |
| ... | ... | @@ -52,7 +53,7 @@ class PendenciesForm(forms.ModelForm): |
| 52 | 53 | subject = Subject.objects.get(id = subject_id) |
| 53 | 54 | |
| 54 | 55 | if not begin_date == ValueError and begin_date: |
| 55 | - if begin_date.date() < datetime.datetime.today().date(): | |
| 56 | + if not pend_id and begin_date.date() < datetime.datetime.today().date(): | |
| 56 | 57 | self.add_error('begin_date', _("This input should be filled with a date equal or after today's date.")) |
| 57 | 58 | |
| 58 | 59 | if begin_date.date() < subject.init_date: |
| ... | ... | @@ -62,7 +63,7 @@ class PendenciesForm(forms.ModelForm): |
| 62 | 63 | self.add_error('begin_date', _('This input should be filled with a date equal or after the subject end date.')) |
| 63 | 64 | |
| 64 | 65 | if not end_date == ValueError and end_date: |
| 65 | - if end_date.date() < datetime.datetime.today().date(): | |
| 66 | + if not pend_id and end_date.date() < datetime.datetime.today().date(): | |
| 66 | 67 | self.add_error('end_date', _("This input should be filled with a date equal or after today's date.")) |
| 67 | 68 | |
| 68 | 69 | if end_date.date() < subject.init_date: | ... | ... |
| ... | ... | @@ -0,0 +1,20 @@ |
| 1 | +# -*- coding: utf-8 -*- | |
| 2 | +# Generated by Django 1.10 on 2017-01-24 04:28 | |
| 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', '0003_pendencies_limit_date'), | |
| 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')], max_length=100, verbose_name='Action'), | |
| 19 | + ), | |
| 20 | + ] | ... | ... |
pendencies/models.py
| ... | ... | @@ -5,7 +5,7 @@ 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")))) | |
| 8 | + action = models.CharField(_('Action'), max_length = 100, choices = (("view", _("Visualize")), ("create", _("Create")), ("answer", _("Answer")), ("access", _("Access"))), 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) | ... | ... |
webpage/templates/webpages/_form.html
| ... | ... | @@ -109,7 +109,10 @@ |
| 109 | 109 | <div class="notifies"> |
| 110 | 110 | <div style="text-align:left"> |
| 111 | 111 | {% if notify.instance.pk %}{{ notify.DELETE }}{% endif %} |
| 112 | - {% render_field notify.subject %} | |
| 112 | + {% render_field notify.id %} | |
| 113 | + {% render_field notify.resource %} | |
| 114 | + {% render_field notify.subject class='pend_subj' %} | |
| 115 | + | |
| 113 | 116 | <div class="form-group{% if notify.has_error %} has-error {% endif %} row"> |
| 114 | 117 | <label for="{{ notify.action.auto_id }}" class="pull-left action_label contol-label"> |
| 115 | 118 | {% trans 'Action not performed by the user' %}: |
| ... | ... | @@ -118,13 +121,15 @@ |
| 118 | 121 | {% render_field notify.action class='form-control' %} |
| 119 | 122 | </div> |
| 120 | 123 | |
| 124 | + <br clear="all" /> | |
| 125 | + | |
| 121 | 126 | <span id="helpBlock" class="help-block">{{ notify.action.help_text }}</span> |
| 122 | 127 | |
| 123 | 128 | {% if notify.action.errors %} |
| 124 | 129 | <div class="alert alert-danger alert-dismissible" role="alert"> |
| 125 | - <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | |
| 126 | - <span aria-hidden="true">×</span> | |
| 127 | - </button> | |
| 130 | + <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | |
| 131 | + <span aria-hidden="true">×</span> | |
| 132 | + </button> | |
| 128 | 133 | <ul> |
| 129 | 134 | {% for error in notify.action.errors %} |
| 130 | 135 | <li>{{ error }}</li> |
| ... | ... | @@ -154,9 +159,9 @@ |
| 154 | 159 | |
| 155 | 160 | {% if notify.begin_date.errors %} |
| 156 | 161 | <div class="alert alert-danger alert-dismissible" role="alert"> |
| 157 | - <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | |
| 158 | - <span aria-hidden="true">×</span> | |
| 159 | - </button> | |
| 162 | + <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | |
| 163 | + <span aria-hidden="true">×</span> | |
| 164 | + </button> | |
| 160 | 165 | <ul> |
| 161 | 166 | {% for error in notify.begin_date.errors %} |
| 162 | 167 | <li>{{ error }}</li> |
| ... | ... | @@ -180,9 +185,9 @@ |
| 180 | 185 | |
| 181 | 186 | {% if notify.end_date.errors %} |
| 182 | 187 | <div class="alert alert-danger alert-dismissible" role="alert"> |
| 183 | - <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | |
| 184 | - <span aria-hidden="true">×</span> | |
| 185 | - </button> | |
| 188 | + <button type="button" class="close" data-dismiss="alert" aria-label="Close"> | |
| 189 | + <span aria-hidden="true">×</span> | |
| 190 | + </button> | |
| 186 | 191 | <ul> |
| 187 | 192 | {% for error in notify.end_date.errors %} |
| 188 | 193 | <li>{{ error }}</li> |
| ... | ... | @@ -355,13 +360,14 @@ |
| 355 | 360 | |
| 356 | 361 | subject = $("#id_control_subject").val(); |
| 357 | 362 | |
| 358 | - console.log(subject); | |
| 359 | - console.log($(row).find('input[type=hidden]')); | |
| 360 | - | |
| 361 | - $(row).find('input[type=hidden]').val(subject); | |
| 363 | + $(row).find('.pend_subj').val(subject); | |
| 362 | 364 | } |
| 363 | 365 | }); |
| 364 | 366 | |
| 367 | + subject = $("#id_control_subject").val(); | |
| 368 | + | |
| 369 | + $('.pend_subj').val(subject); | |
| 370 | + | |
| 365 | 371 | {% if not pendencies_form.is_valid and pendencies_form.is_bound %} |
| 366 | 372 | $("#notifications").collapse('toggle'); |
| 367 | 373 | {% endif %} | ... | ... |
webpage/templates/webpages/view.html
webpage/views.py
| ... | ... | @@ -81,7 +81,7 @@ class CreateView(LoginRequiredMixin, generic.edit.CreateView): |
| 81 | 81 | slug = self.kwargs.get('slug', '') |
| 82 | 82 | topic = get_object_or_404(Topic, slug = slug) |
| 83 | 83 | |
| 84 | - pendencies_form = InlinePendenciesFormset(initial = [{'subject': topic.subject}]) | |
| 84 | + pendencies_form = InlinePendenciesFormset(initial = [{'subject': topic.subject.id}]) | |
| 85 | 85 | |
| 86 | 86 | return self.render_to_response(self.get_context_data(form = form, pendencies_form = pendencies_form)) |
| 87 | 87 | |
| ... | ... | @@ -94,7 +94,7 @@ class CreateView(LoginRequiredMixin, generic.edit.CreateView): |
| 94 | 94 | slug = self.kwargs.get('slug', '') |
| 95 | 95 | topic = get_object_or_404(Topic, slug = slug) |
| 96 | 96 | |
| 97 | - pendencies_form = InlinePendenciesFormset(self.request.POST, initial = [{'subject': topic.subject}]) | |
| 97 | + pendencies_form = InlinePendenciesFormset(self.request.POST, initial = [{'subject': topic.subject.id}]) | |
| 98 | 98 | |
| 99 | 99 | if (form.is_valid() and pendencies_form.is_valid()): |
| 100 | 100 | return self.form_valid(form, pendencies_form) |
| ... | ... | @@ -126,8 +126,13 @@ class CreateView(LoginRequiredMixin, generic.edit.CreateView): |
| 126 | 126 | self.object.save() |
| 127 | 127 | |
| 128 | 128 | pendencies_form.instance = self.object |
| 129 | - pendencies_form.save() | |
| 130 | - | |
| 129 | + | |
| 130 | + for form in pendencies_form.forms: | |
| 131 | + pend_form = form.save(commit = False) | |
| 132 | + | |
| 133 | + if not pend_form.action == "": | |
| 134 | + pend_form.save() | |
| 135 | + | |
| 131 | 136 | return redirect(self.get_success_url()) |
| 132 | 137 | |
| 133 | 138 | def get_context_data(self, **kwargs): |
| ... | ... | @@ -174,21 +179,8 @@ class UpdateView(LoginRequiredMixin, generic.UpdateView): |
| 174 | 179 | |
| 175 | 180 | return super(UpdateView, self).dispatch(request, *args, **kwargs) |
| 176 | 181 | |
| 177 | - # def get(self, request, *args, **kwargs): | |
| 178 | - # self.object = self.get_queryset() | |
| 179 | - | |
| 180 | - # form_class = self.get_form_class() | |
| 181 | - # form = self.get_form(form_class) | |
| 182 | - | |
| 183 | - # slug = self.kwargs.get('topic_slug', '') | |
| 184 | - # topic = get_object_or_404(Topic, slug = slug) | |
| 185 | - | |
| 186 | - # pendencies_form = InlinePendenciesFormset(instance = self.object) | |
| 187 | - | |
| 188 | - # return self.render_to_response(self.get_context_data(form = form, pendencies_form = pendencies_form)) | |
| 189 | - | |
| 190 | 182 | def post(self, request, *args, **kwargs): |
| 191 | - self.object = None | |
| 183 | + self.object = self.get_object() | |
| 192 | 184 | |
| 193 | 185 | form_class = self.get_form_class() |
| 194 | 186 | form = self.get_form(form_class) |
| ... | ... | @@ -196,7 +188,7 @@ class UpdateView(LoginRequiredMixin, generic.UpdateView): |
| 196 | 188 | slug = self.kwargs.get('topic_slug', '') |
| 197 | 189 | topic = get_object_or_404(Topic, slug = slug) |
| 198 | 190 | |
| 199 | - pendencies_form = InlinePendenciesFormset(self.request.POST, initial = [{'subject': topic.subject}]) | |
| 191 | + pendencies_form = InlinePendenciesFormset(self.request.POST, instance = self.object, initial = [{'subject': topic.subject.id}]) | |
| 200 | 192 | |
| 201 | 193 | if (form.is_valid() and pendencies_form.is_valid()): |
| 202 | 194 | return self.form_valid(form, pendencies_form) |
| ... | ... | @@ -209,16 +201,15 @@ class UpdateView(LoginRequiredMixin, generic.UpdateView): |
| 209 | 201 | def form_valid(self, form, pendencies_form): |
| 210 | 202 | self.object = form.save(commit = False) |
| 211 | 203 | |
| 212 | - slug = self.kwargs.get('topic_slug', '') | |
| 213 | - topic = get_object_or_404(Topic, slug = slug) | |
| 214 | - | |
| 215 | - self.object.topic = topic | |
| 216 | - self.object.order = topic.resource_topic.count() + 1 | |
| 217 | - | |
| 218 | 204 | self.object.save() |
| 219 | 205 | |
| 220 | 206 | pendencies_form.instance = self.object |
| 221 | - pendencies_form.save() | |
| 207 | + | |
| 208 | + for form in pendencies_form.forms: | |
| 209 | + pend_form = form.save(commit = False) | |
| 210 | + | |
| 211 | + if not pend_form.action == "": | |
| 212 | + pend_form.save() | |
| 222 | 213 | |
| 223 | 214 | return redirect(self.get_success_url()) |
| 224 | 215 | |
| ... | ... | @@ -233,12 +224,9 @@ class UpdateView(LoginRequiredMixin, generic.UpdateView): |
| 233 | 224 | context['topic'] = topic |
| 234 | 225 | context['subject'] = topic.subject |
| 235 | 226 | |
| 236 | - if self.request.POST: | |
| 237 | - context['form'] = WebpageForm(self.request.POST, instance=self.object, initial = {'subject': topic.subject}) | |
| 238 | - context['pendencies_form'] = InlinePendenciesFormset(self.request.POST, instance=self.object) | |
| 239 | - else: | |
| 227 | + if not self.request.POST: | |
| 240 | 228 | context['form'] = WebpageForm(instance=self.object, initial = {'subject': topic.subject}) |
| 241 | - context['pendencies_form'] = InlinePendenciesFormset(instance=self.object) | |
| 229 | + context['pendencies_form'] = InlinePendenciesFormset(instance=self.object, initial = [{'subject': topic.subject.id}]) | |
| 242 | 230 | |
| 243 | 231 | return context |
| 244 | 232 | ... | ... |