Exemple #1
0
class AbstractJudgmentFormBase(IndicoForm):
    """Form base class for abstract judgment operations"""

    _order = ('judgment', 'accepted_track', 'accepted_contrib_type', 'session', 'duplicate_of', 'merged_into',
              'merge_persons', 'judgment_comment', 'send_notifications')

    accepted_track = QuerySelectField(_("Track"), [HiddenUnless('judgment', AbstractAction.accept)],
                                      get_label=lambda obj: obj.title_with_group,
                                      allow_blank=True, blank_text=_("Choose a track..."),
                                      description=_("The abstract will be accepted in this track"))
    accepted_contrib_type = QuerySelectField(_("Contribution type"), [HiddenUnless('judgment', AbstractAction.accept)],
                                             get_label=lambda x: x.name.title(), allow_blank=True,
                                             blank_text=_("You may choose a contribution type..."),
                                             description=_("The abstract will be converted "
                                                           "into a contribution of this type"))
    session = QuerySelectField(_("Session"), [HiddenUnless('judgment', AbstractAction.accept)],
                               get_label='title', allow_blank=True, blank_text=_("You may choose a session..."),
                               description=_("The generated contribution will be allocated in this session"))
    duplicate_of = AbstractField(_("Duplicate of"),
                                 [HiddenUnless('judgment', AbstractAction.mark_as_duplicate), DataRequired()],
                                 description=_("The current abstract will be marked as duplicate of the selected one"),
                                 ajax_endpoint='abstracts.other_abstracts')
    merged_into = AbstractField(_("Merge into"), [HiddenUnless('judgment', AbstractAction.merge), DataRequired()],
                                description=_("The current abstract will be merged into the selected one"),
                                ajax_endpoint='abstracts.other_abstracts')
    merge_persons = BooleanField(_("Merge persons"), [HiddenUnless('judgment', AbstractAction.merge)],
                                 description=_("Authors and speakers of the current abstract will be added to the "
                                               "selected one"))
    judgment_comment = TextAreaField(_("Comment"), render_kw={'placeholder': _("Leave a comment for the submitter..."),
                                                              'class': 'grow'})
    # TODO: show only if notifications apply?
    send_notifications = BooleanField(_("Send notifications to submitter"), default=True)

    def __init__(self, *args, **kwargs):
        super(AbstractJudgmentFormBase, self).__init__(*args, **kwargs)
        self.session.query = Session.query.with_parent(self.event).order_by(Session.title)
        if not self.session.query.count():
            del self.session
        self.accepted_track.query = Track.query.with_parent(self.event).order_by(Track.position)
        if not self.accepted_track.query.count():
            del self.accepted_track
        self.accepted_contrib_type.query = (ContributionType.query
                                            .with_parent(self.event)
                                            .order_by(ContributionType.name))
        if not self.accepted_contrib_type.query.count():
            del self.accepted_contrib_type

    @property
    def split_data(self):
        abstract_data = self.data
        judgment_data = {
            'judgment': abstract_data.pop('judgment'),
            'send_notifications': abstract_data.pop('send_notifications'),
            'contrib_session': abstract_data.pop('session', None),
            'merge_persons': abstract_data.pop('merge_persons', None)
        }
        return judgment_data, abstract_data
Exemple #2
0
class AbstractReviewForm(IndicoForm):
    """Form for reviewing an abstract"""

    _order = ('proposed_action', 'proposed_contribution_type', 'proposed_related_abstract', 'proposed_tracks',
              'comment')

    comment = TextAreaField(_("Comment"), render_kw={'placeholder': _("You may leave a comment (only visible to "
                                                                      "conveners and judges)..."),
                                                     'class': 'grow'})
    proposed_action = IndicoEnumSelectField(_("Proposed Action"), [DataRequired()], enum=AbstractAction)
    proposed_related_abstract = AbstractField(
        _("Target Abstract"),
        [HiddenUnless('proposed_action', {AbstractAction.mark_as_duplicate, AbstractAction.merge}), DataRequired()],
        description=_("The current abstract should be marked as duplicate of the selected one"),
        ajax_endpoint='abstracts.other_abstracts')
    proposed_contribution_type = QuerySelectField(
        _("Contribution type"),
        [HiddenUnless('proposed_action', AbstractAction.accept)],
        get_label=lambda x: x.name.title(), allow_blank=True, blank_text=_("You may propose a contribution type..."))
    proposed_tracks = IndicoQuerySelectMultipleCheckboxField(
        _("Propose for tracks"),
        [HiddenUnless('proposed_action', AbstractAction.change_tracks), DataRequired()],
        collection_class=set, get_label='title')

    def __init__(self, edit=False, *args, **kwargs):
        abstract = kwargs.pop('abstract')
        super(AbstractReviewForm, self).__init__(*args, **kwargs)
        self.event = abstract.event
        if not edit:
            self.proposed_action.none = _("Propose an action...")
        self.proposed_related_abstract.excluded_abstract_ids = {abstract.id}
        self.proposed_contribution_type.query = (ContributionType.query
                                                 .with_parent(self.event)
                                                 .order_by(ContributionType.name))
        if not self.proposed_contribution_type.query.count():
            del self.proposed_contribution_type
        reviewed_for_track_ids = {t.id for t in abstract.reviewed_for_tracks}
        existing_prop_track_cond = (Track.id.in_(t.id for t in self.proposed_tracks.object_data)
                                    if self.proposed_tracks.object_data else False)
        self.proposed_tracks.query = (Track.query
                                      .with_parent(self.event)
                                      .filter(db.or_(Track.id.notin_(reviewed_for_track_ids),
                                                     existing_prop_track_cond))
                                      .order_by(Track.position))
        if not self.proposed_tracks.query.count():
            del self.proposed_tracks
            self.proposed_action.skip.add(AbstractAction.change_tracks)

    @property
    def split_data(self):
        data = self.data
        return {'questions_data': {k: v for k, v in data.iteritems() if k.startswith('question_')},
                'review_data': {k: v for k, v in data.iteritems() if not k.startswith('question_')}}

    @property
    def has_questions(self):
        return any(x.startswith('question_') for x in self.data)