Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
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)
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
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)
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)
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:
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(
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)
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"
)