def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)

        call_evaluation = CallEvaluation.objects.get(id=self.kwargs['pk'])

        CheckboxSelectMultipleSortable.add_missing_related_objects(CriterionCallEvaluation, call_evaluation,
                                                                   'call_evaluation', Criterion,
                                                                   'criterion')

        criteria = []
        for criterion in call_evaluation.criterioncallevaluation_set.order_by('order', 'criterion__name'):
            criteria.append(({'in_call_evaluation': criterion.enabled,
                              'name': criterion.criterion.name,
                              'description': criterion.criterion.description})
                            )

        criteria.sort(key=lambda c: not c['in_call_evaluation'])

        context['criteria'] = criteria

        context.update({'active_section': 'evaluation',
                        'active_subsection': 'evaluation-list',
                        'sidebar_template': 'evaluation/_sidebar-evaluation.tmpl'
                        })

        context['breadcrumb'] = [{'name': 'Calls to evaluate', 'url': reverse('logged-evaluation-list')},
                                 {'name': f'Details ({call_evaluation.call.little_name()})'}]

        context.update(comments_attachments_forms('logged-call-evaluation-comment-add', call_evaluation))

        return context
Ejemplo n.º 2
0
    def save_call_evaluation(self, user, *args, **kwargs):
        if not user_is_in_group_name(user, settings.MANAGEMENT_GROUP_NAME):
            raise PermissionError()

        reviewers = self.cleaned_data['reviewers']

        call_evaluation = super().save(*args, **kwargs)

        CheckboxSelectMultipleSortable.save(CriterionCallEvaluation, call_evaluation,
                                            'call_evaluation', Criterion, 'criterion',
                                            self.cleaned_data['criteria'],
                                            self.cleaned_data[self.criteria_order_key]
                                            )

        call_evaluation.call.reviewer_set.set(reviewers)

        return call_evaluation
Ejemplo n.º 3
0
    def clean(self):
        cleaned_data = super().clean()

        data_evaluation_criteria_order_key = f'{self.prefix}-{self.criteria_order_key}'

        self.cleaned_data[self.criteria_order_key] = CheckboxSelectMultipleSortable.get_clean_order(self.data,
                                                                                                    data_evaluation_criteria_order_key)

        return cleaned_data
Ejemplo n.º 4
0
    def __init__(self, *args, **kwargs):
        call = kwargs.pop('call', None)
        super().__init__(*args, **kwargs)

        self.helper = FormHelper(self)

        if self.instance.id:
            self.helper.form_action = reverse('logged-call-evaluation-update', kwargs={'pk': self.instance.id})
            self.fields['call'].initial = call = self.instance.call
        else:
            self.helper.form_action = reverse('logged-call-evaluation-add') + f'?call={call.id}'
            self.fields['call'].initial = call

        XDSoftYearMonthDayPickerInput.set_format_to_field(self.fields['panel_date'])

        if hasattr(call, 'callevaluation'):
            cancel_edit_url = reverse('logged-call-evaluation-detail', kwargs={'pk': call.callevaluation.id})
            initial_reviewers = call.reviewer_set.all()
        else:
            cancel_edit_url = reverse('logged-call-evaluation-add') + f'?call={call.id}'
            initial_reviewers = []

        self.fields['reviewers'] = ReviewerMultipleChoiceField(initial=initial_reviewers,
                                                               queryset=Reviewer.objects.all(),
                                                               required=True,
                                                               widget=FilteredSelectMultiple(
                                                                   is_stacked=True,
                                                                   verbose_name='reviewers'),
                                                               help_text=self.Meta.help_texts['reviewers'])

        criterion_choices, criterion_initial = CheckboxSelectMultipleSortable.get_choices_initial(
            CriterionCallEvaluation,
            self.instance, 'call_evaluation',
            Criterion, 'criterion',
            label_from_instance=lambda obj: format_html('{} <small>({})</small>', obj.name, obj.description)
        )

        self.fields['criteria'] = forms.MultipleChoiceField(choices=criterion_choices,
                                                            initial=criterion_initial,
                                                            widget=CheckboxSelectMultipleSortable,
                                                            label='Criteria (drag and drop to order them)',
                                                            help_text='These criteria are used in the Excel Evaluation sheet'
                                                            )

        self.criteria_order_key = f'criteria-{CheckboxSelectMultipleSortable.order_of_values_name}'

        self.helper.layout = Layout(
            Div(
                Div('call', css_class='col-12', hidden=True),
                css_class='row'
            ),
            Div(
                Div('reviewers', css_class='col-12'),
                css_class='row'
            ),
            Div(
                Div('panel_date', css_class='col-12'),
                css_class='row'
            ),
            Div(
                Div('criteria', css_class='col-12'),
                css_class='row'
            ),
            Div(
                Div('post_panel_management_table', css_class='col-12'),
                css_class='row'
            ),
            FormActions(
                Submit('save', 'Save Call Evaluation'),
                cancel_edit_button(cancel_edit_url)
            )
        )
    def __init__(self, *args, **kwargs):
        call = kwargs.pop('call', None)
        super().__init__(*args, **kwargs)

        self.helper = FormHelper(self)

        if self.instance.id:
            self.helper.form_action = reverse('logged-call-evaluation-update', kwargs={'pk': self.instance.id})
            self.fields['call'].initial = call = self.instance.call
        else:
            self.helper.form_action = reverse('logged-call-evaluation-add') + f'?call={call.id}'
            self.fields['call'].initial = call

        XDSoftYearMonthDayPickerInput.set_format_to_field(self.fields['panel_date'])

        if hasattr(call, 'callevaluation'):
            cancel_edit_url = reverse('logged-call-evaluation-detail', kwargs={'pk': call.callevaluation.id})
            initial_reviewers = call.reviewer_set.all()
        else:
            cancel_edit_url = reverse('logged-call-evaluation-add') + f'?call={call.id}'
            initial_reviewers = []

        reviewer_add_url = reverse('logged-user-add')

        reviewers_help_text = \
            f'Select the reviewers that you would like to be added for this call. This is everyone that ' \
            f'will review individual proposals and be on the review panel. If you cannot find the person ' \
            f'you are looking for, please <a href="{reviewer_add_url}">add a Reviewer type of user</a> and reload ' \
            f'this page.'

        self.fields['reviewers'] = ReviewerMultipleChoiceField(initial=initial_reviewers,
                                                               queryset=Reviewer.objects.all(),
                                                               required=True,
                                                               widget=FilteredSelectMultiple(
                                                                   is_stacked=True,
                                                                   verbose_name='reviewers'),
                                                               help_text=reviewers_help_text)

        criterion_choices, criterion_initial = CheckboxSelectMultipleSortable.get_choices_initial(
            CriterionCallEvaluation,
            self.instance, 'call_evaluation',
            Criterion, 'criterion',
            label_from_instance=lambda obj: format_html('{} <small>({})</small>', obj.name, obj.description)
        )

        evaluation_criteria_list_url = reverse('logged-evaluation_criteria-list')
        list_edit_criteria = f'You can list and create criteria in <a href="{evaluation_criteria_list_url}">Evaluation criteria list</a>.'

        self.fields['criteria'] = forms.MultipleChoiceField(choices=criterion_choices,
                                                            initial=criterion_initial,
                                                            widget=CheckboxSelectMultipleSortable,
                                                            label='Criteria (drag and drop to order them)',
                                                            help_text=f'These criteria are used in the Excel Evaluation sheet. '
                                                                      f'{list_edit_criteria}'
                                                            )

        self.criteria_order_key = f'criteria-{CheckboxSelectMultipleSortable.order_of_values_name}'

        self.helper.layout = Layout(
            Div(
                Div('call', css_class='col-12', hidden=True),
                css_class='row'
            ),
            Div(
                Div('reviewers', css_class='col-12'),
                css_class='row'
            ),
            Div(
                Div('panel_date', css_class='col-12'),
                css_class='row'
            ),
            Div(
                Div('criteria', css_class='col-12'),
                css_class='row'
            ),
            Div(
                Div('post_panel_management_table', css_class='col-12'),
                css_class='row'
            ),
            FormActions(
                Submit('save', 'Save Call Evaluation'),
                cancel_edit_button(cancel_edit_url)
            )
        )