Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def dispatch(self, request, *args, **kwargs):
search = request.GET.get("search")
if not search or len(search) < 2:
return JsonResponse({"count": 0, "results": []})
events = self.request.user.get_events_for_permission(
can_change_submissions=True
)
queryset = User.objects.filter(
Q(name__icontains=search) | Q(email__icontains=search),
profiles__event__in=events,
)
if request.GET.get("orga", "false").lower() == "true":
queryset = queryset.filter(teams__in=request.event.teams)
return JsonResponse(
{
"count": len(queryset),
"results": [
{"email": user.email, "name": user.name} for user in queryset
],
def speakers(self):
"""Returns a queryset of all speakers (of type.
:class:`~pretalx.person.models.user.User`) visible in the current
released schedule.
"""
from pretalx.person.models import User
return User.objects.filter(submissions__in=self.talks).order_by("id").distinct()
def form_valid(self, form):
pk = form.save()
user = User.objects.filter(pk=pk).first()
if not user:
messages.error(
self.request,
_(
"There was an error when logging in. Please contact the organiser for further help."
),
)
return redirect(self.get_error_url())
if not user.is_active:
messages.error(self.request, _("User account is deactivated."))
return redirect(self.get_error_redirect())
login(self.request, user, backend="django.contrib.auth.backends.ModelBackend")
params = self.request.GET.copy()
url = urllib.parse.unquote(params.pop("next", [""])[0])
def get_object(self):
return get_object_or_404(
User.objects.filter(
submissions__in=Submission.all_objects.filter(event=self.request.event)
)
.order_by("id")
.distinct(),
pk=self.kwargs["pk"],
)
def _clean_register(self, data):
if data.get("register_password") != data.get("register_password_repeat"):
self.add_error(
"register_password_repeat",
ValidationError(phrases.base.passwords_differ),
)
if User.objects.filter(email__iexact=data.get("register_email")).exists():
self.add_error(
"register_email",
ValidationError(
_(
"We already have a user with that email address. Did you already register "
"before and just need to log in?"
if options['registered']:
users = users.exclude(Q(password__startswith='!') | Q(password__isnull=True))
users = users.distinct()
emails = set()
if options['users']:
self.stdout.write(self.style.WARNING("Sending to {} users".format(users.count())))
for u in users:
emails.add(u.email.lower())
else:
self.stdout.write(self.style.WARNING("Not sending to any users"))
# ALWAYS keep active staff in the loop
for admin in User.objects.filter(is_active=True, is_staff=True):
emails.add(admin.email.lower())
no_unsubscribe = emails.copy()
if options['newsletter']:
self.stdout.write(self.style.WARNING("Sending to newsletter recipients as well"))
for subscriber in models.Subscription.objects.filter(confirmed=True):
emails.add(subscriber.email.lower())
if options['test']:
self.stdout.write(self.style.WARNING("Sending just a test to: {}".format(options['test'])))
no_unsubscribe = set()
emails = set()
emails.add(options['test'])
email_template.populate_recipients(emails)