Esempio n. 1
0
class SubmissionFilterForm(forms.Form):
    state = forms.MultipleChoiceField(
        choices=SubmissionStates.get_choices(),
        required=False,
        widget=CheckboxMultiDropdown,
    )
    submission_type = forms.MultipleChoiceField(required=False,
                                                widget=CheckboxMultiDropdown)
    track = forms.MultipleChoiceField(required=False,
                                      widget=CheckboxMultiDropdown)

    def __init__(self, event, *args, **kwargs):
        self.event = event
        usable_states = kwargs.pop('usable_states', None)
        super().__init__(*args, **kwargs)
        qs = event.submissions
        state_qs = event.submissions(manager='all_objects')
        if usable_states:
            qs = qs.filter(state__in=usable_states)
            state_qs = state_qs.filter(state__in=usable_states)
        state_count = {
            d['state']: d['state__count']
            for d in state_qs.order_by('state').values('state').annotate(
                Count('state'))
        }
        type_count = {
            d['submission_type_id']: d['submission_type_id__count']
            for d in qs.order_by('submission_type_id').values(
                'submission_type_id').annotate(Count('submission_type_id'))
        }
        track_count = {
            d['track']: d['track__count']
            for d in qs.order_by('track').values('track').annotate(
                Count('track'))
        }
        self.fields['submission_type'].choices = [
            (sub_type.pk,
             f'{str(sub_type)} ({type_count.get(sub_type.pk, 0)})')
            for sub_type in event.submission_types.all()
        ]
        self.fields['submission_type'].widget.attrs['title'] = _(
            'Submission types')
        if usable_states:
            usable_states = [
                choice for choice in self.fields['state'].choices
                if choice[0] in usable_states
            ]
        else:
            usable_states = self.fields['state'].choices
        self.fields['state'].choices = [
            (choice[0],
             f'{choice[1].capitalize()} ({state_count.get(choice[0], 0)})')
            for choice in usable_states
        ]
        self.fields['state'].widget.attrs['title'] = _('Submission states')
        self.fields['track'].choices = [
            (track.pk, f'{track.name} ({track_count.get(track.pk, 0)})')
            for track in event.tracks.all()
        ]
        self.fields['track'].widget.attrs['title'] = _('Tracks')
Esempio n. 2
0
class SubmissionFilterForm(forms.Form):
    state = forms.MultipleChoiceField(
        choices=SubmissionStates.get_choices(),
        required=False,
        widget=CheckboxMultiDropdown,
    )
    submission_type = forms.MultipleChoiceField(required=False,
                                                widget=CheckboxMultiDropdown)
    track = forms.MultipleChoiceField(required=False,
                                      widget=CheckboxMultiDropdown)

    def __init__(self, event, *args, **kwargs):
        self.event = event
        usable_states = kwargs.pop("usable_states", None)
        super().__init__(*args, **kwargs)
        qs = event.submissions
        state_qs = Submission.all_objects.filter(event=event)
        if usable_states:
            qs = qs.filter(state__in=usable_states)
            state_qs = state_qs.filter(state__in=usable_states)
        state_count = {
            d["state"]: d["state__count"]
            for d in state_qs.order_by("state").values("state").annotate(
                Count("state"))
        }
        type_count = {
            d["submission_type_id"]: d["submission_type_id__count"]
            for d in qs.order_by("submission_type_id").values(
                "submission_type_id").annotate(Count("submission_type_id"))
        }
        track_count = {
            d["track"]: d["track__count"]
            for d in qs.order_by("track").values("track").annotate(
                Count("track"))
        }
        self.fields["submission_type"].choices = [
            (sub_type.pk,
             f"{str(sub_type)} ({type_count.get(sub_type.pk, 0)})")
            for sub_type in event.submission_types.all()
        ]
        self.fields["submission_type"].widget.attrs["title"] = _(
            "Submission types")
        if usable_states:
            usable_states = [
                choice for choice in self.fields["state"].choices
                if choice[0] in usable_states
            ]
        else:
            usable_states = self.fields["state"].choices
        self.fields["state"].choices = [
            (choice[0],
             f"{choice[1].capitalize()} ({state_count.get(choice[0], 0)})")
            for choice in usable_states
        ]
        self.fields["state"].widget.attrs["title"] = _("Submission states")
        self.fields["track"].choices = [
            (track.pk, f"{track.name} ({track_count.get(track.pk, 0)})")
            for track in event.tracks.all()
        ]
        self.fields["track"].widget.attrs["title"] = _("Tracks")
Esempio n. 3
0
class SubmissionFilterForm(forms.Form):
    state = forms.MultipleChoiceField(
        choices=SubmissionStates.get_choices(),
        required=False,
        widget=CheckboxMultiDropdown,
    )
    submission_type = forms.MultipleChoiceField(required=False,
                                                widget=CheckboxMultiDropdown)
    track = forms.MultipleChoiceField(required=False,
                                      widget=CheckboxMultiDropdown)

    def __init__(self, event, *args, **kwargs):
        self.event = event
        usable_states = kwargs.pop('usable_states', None)
        super().__init__(*args, **kwargs)
        sub_count = (lambda x: event.submissions(manager='all_objects').filter(
            state=x).count())  # noqa
        type_count = (
            lambda x: event.submissions.filter(submission_type=x)  # noqa
            .count())
        track_count = (
            lambda x: event.submissions.filter(track=x)  #noqa
            .count())
        self.fields['submission_type'].choices = [
            (sub_type.pk, f'{str(sub_type)} ({type_count(sub_type.pk)})')
            for sub_type in event.submission_types.all()
        ]
        self.fields['submission_type'].widget.attrs['title'] = _(
            'Submission types')
        if usable_states:
            usable_states = [
                choice for choice in self.fields['state'].choices
                if choice[0] in usable_states
            ]
        else:
            usable_states = self.fields['state'].choices
        self.fields['state'].choices = [
            (choice[0], f'{choice[1].capitalize()} ({sub_count(choice[0])})')
            for choice in usable_states
        ]
        self.fields['state'].widget.attrs['title'] = _('Submission states')
        self.fields['track'].choices = [
            (track.pk, f'{track.name} ({track_count(track.pk)})')
            for track in event.tracks.all()
        ]
        self.fields['track'].widget.attrs['title'] = _('Tracks')
Esempio n. 4
0
    def __init__(self, event, anonymise=False, **kwargs):
        self.event = event
        if anonymise:
            kwargs.pop("initial", None)
            initial = {}
            instance = kwargs.pop("instance", None)
            previous_data = instance.anonymised
            for key in self._meta.fields:
                initial[key] = (previous_data.get(key)
                                or getattr(instance, key, None) or "")
            kwargs["initial"] = initial
        super().__init__(**kwargs)
        if "submission_type" in self.fields:
            self.fields[
                "submission_type"].queryset = SubmissionType.objects.filter(
                    event=event)
        if not self.event.tags.all().exists():
            self.fields.pop("tags", None)
        else:
            self.fields["tags"].queryset = self.event.tags.all()
            self.fields["tags"].required = False

        self.is_creating = False
        if not self.instance.pk:
            self.is_creating = True
            self.fields["speaker"] = forms.EmailField(
                label=_("Speaker email"),
                help_text=
                _("The email address of the speaker holding the session. They will be invited to create an account."
                  ),
                required=False,
            )
            self.fields["speaker_name"] = forms.CharField(
                label=_("Speaker name"),
                help_text=_(
                    "The name of the speaker that should be displayed publicly."
                ),
                required=False,
            )
            if not anonymise:
                self.fields["state"] = forms.ChoiceField(
                    label=_("Proposal state"),
                    choices=SubmissionStates.get_choices(),
                    initial=SubmissionStates.SUBMITTED,
                )
            self.fields["room"] = forms.ModelChoiceField(
                required=False, queryset=event.rooms.all(), label=_("Room"))
            self.fields["start"] = forms.DateTimeField(
                required=False,
                label=_("Start"),
                widget=forms.DateInput(
                    attrs={
                        "class":
                        "datetimepickerfield",
                        "data-date-start-date":
                        event.date_from.isoformat(),
                        "data-date-end-date": (
                            event.date_to + dt.timedelta(days=1)).isoformat(),
                        "data-date-before":
                        "#id_end",
                    }),
            )
            self.fields["end"] = forms.DateTimeField(
                required=False,
                label=_("End"),
                widget=forms.DateInput(
                    attrs={
                        "class":
                        "datetimepickerfield",
                        "data-date-start-date":
                        event.date_from.isoformat(),
                        "data-date-end-date": (
                            event.date_to + dt.timedelta(days=1)).isoformat(),
                        "data-date-after":
                        "#id_start",
                    }),
            )
        if "abstract" in self.fields:
            self.fields["abstract"].widget.attrs["rows"] = 2
        if not event.settings.present_multiple_times:
            self.fields.pop("slot_count", None)
        if not event.settings.use_tracks:
            self.fields.pop("track", None)
        elif "track" in self.fields:
            self.fields["track"].queryset = event.tracks.all()
Esempio n. 5
0
class SubmissionFilterForm(forms.Form):
    state = forms.MultipleChoiceField(
        choices=SubmissionStates.get_choices(),
        required=False,
        widget=forms.SelectMultiple(attrs={"class": "select2"}),
    )
    submission_type = forms.MultipleChoiceField(
        required=False,
        widget=forms.SelectMultiple(attrs={"class": "select2"}))
    track = forms.MultipleChoiceField(
        required=False,
        widget=forms.SelectMultiple(attrs={"class": "select2"}))
    tags = forms.MultipleChoiceField(
        required=False,
        widget=forms.SelectMultiple(attrs={"class": "select2"}))
    question = SafeModelChoiceField(queryset=Question.objects.none(),
                                    required=False)

    def __init__(self, event, *args, limit_tracks=False, **kwargs):
        self.event = event
        usable_states = kwargs.pop("usable_states", None)
        super().__init__(*args, **kwargs)
        qs = event.submissions
        state_qs = Submission.all_objects.filter(event=event)
        if usable_states:
            qs = qs.filter(state__in=usable_states)
            state_qs = state_qs.filter(state__in=usable_states)
        state_count = {
            d["state"]: d["state__count"]
            for d in state_qs.order_by("state").values("state").annotate(
                Count("state"))
        }
        sub_types = event.submission_types.all()
        tracks = limit_tracks or event.tracks.all()
        if len(sub_types) > 1:
            type_count = {
                d["submission_type_id"]: d["submission_type_id__count"]
                for d in qs.order_by("submission_type_id").values(
                    "submission_type_id").annotate(Count("submission_type_id"))
            }
            self.fields["submission_type"].choices = [(
                sub_type.pk,
                f"{str(sub_type.name)} ({type_count.get(sub_type.pk, 0)})",
            ) for sub_type in event.submission_types.all()]
            self.fields["submission_type"].widget.attrs["title"] = _(
                "Session types")
        else:
            self.fields.pop("submission_type", None)
        if len(tracks) > 1:
            track_count = {
                d["track"]: d["track__count"]
                for d in qs.order_by("track").values("track").annotate(
                    Count("track"))
            }
            self.fields["track"].choices = [
                (track.pk, f"{track.name} ({track_count.get(track.pk, 0)})")
                for track in tracks
            ]
            self.fields["track"].widget.attrs["title"] = _("Tracks")
        else:
            self.fields.pop("track", None)

        if not self.event.tags.all().exists():
            self.fields.pop("tags", None)
        else:
            tag_count = event.tags.prefetch_related("submissions").annotate(
                submission_count=Count("submissions", distinct=True))
            tag_count = {tag.tag: tag.submission_count for tag in tag_count}
            self.fields["tags"].choices = [
                (tag.pk, f"{tag.tag} ({tag_count.get(tag.tag, 0)})")
                for tag in self.event.tags.all()
            ]
            self.fields["tags"].widget.attrs["title"] = _("Tags")

        if usable_states:
            usable_states = [
                choice for choice in self.fields["state"].choices
                if choice[0] in usable_states
            ]
        else:
            usable_states = self.fields["state"].choices
        self.fields["state"].choices = [
            (choice[0],
             f"{choice[1].capitalize()} ({state_count.get(choice[0], 0)})")
            for choice in usable_states
        ]
        self.fields["state"].widget.attrs["title"] = _("Proposal states")
        self.fields["question"].queryset = event.questions.all()
Esempio n. 6
0
    def __init__(self, event, anonymise=False, **kwargs):
        self.event = event
        initial_slot = {}
        instance = kwargs.get("instance")
        if instance and instance.pk:
            slot = (instance.slots.filter(schedule__version__isnull=True).
                    select_related("room").order_by("start").first())
            if slot:
                initial_slot = {
                    "room":
                    slot.room,
                    "start":
                    slot.start.astimezone(self.event.tz).isoformat()
                    if slot.start else "",
                    "end":
                    slot.real_end.astimezone(self.event.tz).isoformat()
                    if slot.real_end else "",
                }
        if anonymise:
            kwargs.pop("initial", None)
            initial = {}
            instance = kwargs.pop("instance", None)
            previous_data = instance.anonymised
            for key in self._meta.fields:
                initial[key] = (previous_data.get(key)
                                or getattr(instance, key, None) or "")
                if hasattr(initial[key], "all"):  # Tags, for the moment
                    initial[key] = initial[key].all()
            kwargs["initial"] = initial
        kwargs["initial"].update(initial_slot)
        super().__init__(**kwargs)
        if "submission_type" in self.fields:
            self.fields[
                "submission_type"].queryset = SubmissionType.objects.filter(
                    event=event)
        if not self.event.tags.all().exists():
            self.fields.pop("tags", None)
        elif "tags" in self.fields:
            self.fields["tags"].queryset = self.event.tags.all()
            self.fields["tags"].required = False

        self.is_creating = False
        if not self.instance.pk:
            self.is_creating = True
            self.fields["speaker"] = forms.EmailField(
                label=_("Speaker email"),
                help_text=
                _("The email address of the speaker holding the session. They will be invited to create an account."
                  ),
                required=False,
            )
            self.fields["speaker_name"] = forms.CharField(
                label=_("Speaker name"),
                help_text=_(
                    "The name of the speaker that should be displayed publicly."
                ),
                required=False,
            )
            if not anonymise:
                self.fields["state"] = forms.ChoiceField(
                    label=_("Proposal state"),
                    choices=SubmissionStates.get_choices(),
                    initial=SubmissionStates.SUBMITTED,
                )
        if not self.instance.pk or self.instance.state in (
                SubmissionStates.ACCEPTED,
                SubmissionStates.CONFIRMED,
        ):
            self.fields["room"] = forms.ModelChoiceField(
                required=False,
                queryset=event.rooms.all(),
                label=_("Room"),
                initial=initial_slot.get("room"),
            )
            self.fields["start"] = forms.DateTimeField(
                required=False,
                label=_("Start"),
                widget=forms.DateInput(
                    attrs={
                        "class":
                        "datetimepickerfield",
                        "data-date-start-date":
                        event.date_from.isoformat(),
                        "data-date-end-date": (
                            event.date_to + dt.timedelta(days=1)).isoformat(),
                        "data-date-before":
                        "#id_end",
                    }),
                initial=initial_slot.get("start"),
            )
            self.fields["end"] = forms.DateTimeField(
                required=False,
                label=_("End"),
                widget=forms.DateInput(
                    attrs={
                        "class":
                        "datetimepickerfield",
                        "data-date-start-date":
                        event.date_from.isoformat(),
                        "data-date-end-date": (
                            event.date_to + dt.timedelta(days=1)).isoformat(),
                        "data-date-after":
                        "#id_start",
                    }),
                initial=initial_slot.get("end"),
            )
        if "abstract" in self.fields:
            self.fields["abstract"].widget.attrs["rows"] = 2
        if not event.settings.present_multiple_times:
            self.fields.pop("slot_count", None)
        if not event.settings.use_tracks:
            self.fields.pop("track", None)
        elif "track" in self.fields:
            self.fields["track"].queryset = event.tracks.all()
        if "content_locale" in self.fields:
            if len(event.locales) == 1:
                self.initial["content_locale"] = event.locales[0]
                self.fields["content_locale"].widget = forms.HiddenInput()
            else:
                locale_names = dict(settings.LANGUAGES)
                self.fields["content_locale"].choices = [
                    (a, locale_names[a]) for a in event.locales
                ]