How to use the pretalx.person.models.User function in pretalx

To help you get started, we’ve selected a few pretalx examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pretalx / pretalx / src / pretalx / schedule / models / schedule.py View on Github external
def speakers_concerned(self):
        """Returns a dictionary of speakers with their new and changed talks in
        this schedule.

        Each speaker is assigned a dictionary with ``create`` and
        ``update`` fields, each containing a list of submissions.
        """
        if self.changes["action"] == "create":
            return {
                speaker: {
                    "create": self.talks.filter(submission__speakers=speaker),
                    "update": [],
                }
                for speaker in User.objects.filter(submissions__slots__schedule=self)
            }

        if self.changes["count"] == len(self.changes["canceled_talks"]):
            return []

        speakers = defaultdict(lambda: {"create": [], "update": []})
        for new_talk in self.changes["new_talks"]:
            for speaker in new_talk.submission.speakers.all():
                speakers[speaker]["create"].append(new_talk)
        for moved_talk in self.changes["moved_talks"]:
            for speaker in moved_talk["submission"].speakers.all():
                speakers[speaker]["update"].append(moved_talk)
        return speakers
github pretalx / pretalx / src / pretalx / person / forms.py View on Github external
self.event.settings, f"cfp_request_{field}", True
            ):
                self.fields.pop(field)
            else:
                self.fields[field].required = getattr(
                    self.event.settings, f"cfp_require_{field}", False
                )
        if not self.event.settings.cfp_request_avatar:
            self.fields.pop("avatar", None)
            self.fields.pop("get_gravatar", None)
        if self.user:
            initial.update(
                {field: getattr(self.user, field) for field in self.user_fields}
            )
        for field in self.user_fields:
            self.fields[field] = User._meta.get_field(field).formfield(
                initial=initial.get(field), disabled=read_only
            )
            self._update_cfp_help_text(field)
github pretalx / pretalx / src / pretalx / common / auth.py View on Github external
def authenticate(self, *args, token=None, **kwargs):
        if token:
            with suppress(User.DoesNotExist, MultipleObjectsReturned):
                return User.objects.get(auth_token__key__iexact=token)
        return None
github pretalx / pretalx / src / pretalx / orga / views / submission.py View on Github external
def dispatch(self, request, *args, **kwargs):
        super().dispatch(request, *args, **kwargs)
        submission = self.object
        speaker = get_object_or_404(User, pk=request.GET.get("id"))

        if submission in speaker.submissions.all():
            speaker.submissions.remove(submission)
            submission.log_action(
                "pretalx.submission.speakers.remove", person=request.user, orga=True
            )
            messages.success(
                request, _("The speaker has been removed from the submission.")
            )
        else:
            messages.warning(request, _("The speaker was not part of this submission."))
        return redirect(submission.orga_urls.speakers)
github pretalx / pretalx / src / pretalx / orga / views / auth.py View on Github external
def dispatch(self, request, *args, **kwargs):
        try:
            self.user = User.objects.get(
                pw_reset_token=kwargs.get("token"),
                pw_reset_time__gte=now() - dt.timedelta(days=1),
            )
        except User.DoesNotExist:
            messages.error(self.request, phrases.cfp.auth_reset_fail)
            return redirect(reverse("orga:auth.reset"))
        return super().dispatch(request, *args, **kwargs)
github pretalx / pretalx / src / pretalx / orga / views / submission.py View on Github external
return self.get(self.request, *self.args, **self.kwargs)
        form.instance.event = self.request.event
        form.save()
        self._questions_form.save()

        if created:
            email = form.cleaned_data["speaker"]
            try:
                speaker = User.objects.get(email__iexact=email)  # TODO: send email!
                messages.success(
                    self.request,
                    _(
                        "The submission has been created; the speaker already had an account on this system."
                    ),
                )
            except User.DoesNotExist:
                speaker = create_user_as_orga(
                    email=email,
                    name=form.cleaned_data["speaker_name"],
                    submission=form.instance,
                )
                messages.success(
                    self.request,
                    _(
                        "The submission has been created and the speaker has been invited to add an account!"
                    ),
                )

            form.instance.speakers.add(speaker)
        else:
            formset_result = self.save_formset(form.instance)
            if not formset_result:
github pretalx / pretalx / src / pretalx / orga / views / mails.py View on Github external
def form_valid(self, form):
        user_set = set()
        submissions = form.cleaned_data.get("submissions")
        if submissions:
            users = User.objects.filter(
                submissions__in=self.request.event.submissions.filter(
                    code__in=submissions
                )
            )
            user_set.update(users)
        tracks = form.cleaned_data.get("tracks")
        if tracks:
            users = User.objects.filter(
                submissions__in=self.request.event.submissions.filter(
                    track_id__in=tracks
                )
            )
            user_set.update(users)
        submission_types = form.cleaned_data.get("submission_types")
        if submission_types:
            users = User.objects.filter(
github pretalx / pretalx / src / pretalx / mail / models.py View on Github external
but can be overridden with this parameter.
        :param context: Context to be used when rendering the template.
        :param skip_queue: Send directly without saving. Use with caution, as
            it removes any logging and traces.
        :param commit: Set ``False`` to return an unsaved object.
        :param submission: Pass a submission if one is related to the mail.
            Will be used to generate context.
        :param full_submission_content: Attach the complete submission with
            all its fields to the email.
        """
        from pretalx.person.models import User

        if isinstance(user, str):
            address = user
            users = None
        elif isinstance(user, User):
            address = None
            users = [user]
        else:
            raise Exception(
                "First argument to to_mail must be a string or a User, not "
                + str(type(user))
            )
        if users and (not commit or skip_queue):
            address = ",".join(user.email for user in users)
            users = None

        with override(locale):
            context = context or dict()
            try:
                subject = str(self.subject).format(**context)
                text = str(self.text).format(**context)
github pretalx / pretalx / src / pretalx / orga / views / mails.py View on Github external
submissions__in=self.request.event.submissions.filter(
                    code__in=submissions
                )
            )
            user_set.update(users)
        tracks = form.cleaned_data.get("tracks")
        if tracks:
            users = User.objects.filter(
                submissions__in=self.request.event.submissions.filter(
                    track_id__in=tracks
                )
            )
            user_set.update(users)
        submission_types = form.cleaned_data.get("submission_types")
        if submission_types:
            users = User.objects.filter(
                submissions__in=self.request.event.submissions.filter(
                    submission_type_id__in=submission_types
                )
            )
            user_set.update(users)

        for recipient in form.cleaned_data.get("recipients"):
            if recipient == "reviewers":
                users = User.objects.filter(
                    teams__in=self.request.event.teams.filter(is_reviewer=True)
                ).distinct()
            elif recipient == "no_slides":
                users = User.objects.filter(
                    submissions__in=self.request.event.submissions.filter(
                        resources__isnull=True, state="confirmed"
                    )