Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from django.conf import settings
from django.db.models import Q
from django.utils.html import mark_safe
from django.utils.translation import gettext_lazy as _
from django_scopes import scopes_disabled
from django_scopes.forms import SafeModelMultipleChoiceField
from i18nfield.forms import I18nModelForm
from pretalx.common.forms.fields import IMAGE_EXTENSIONS, ExtensionFileField
from pretalx.common.mixins.forms import ReadOnlyFlag
from pretalx.event.models import Event, Organiser, Team, TeamInvite
from pretalx.orga.forms.widgets import HeaderSelect, MultipleLanguagesWidget
from pretalx.submission.models import ReviewPhase, Track
class TeamForm(ReadOnlyFlag, I18nModelForm):
def __init__(self, *args, organiser=None, instance=None, **kwargs):
super().__init__(*args, instance=instance, **kwargs)
self.fields["organiser"].widget = forms.HiddenInput()
if instance and getattr(instance, "pk", None):
self.fields.pop("organiser")
self.fields["limit_events"].queryset = instance.organiser.events.all()
else:
self.fields["organiser"].initial = organiser
self.fields["limit_events"].queryset = organiser.events.all()
if instance and instance.pk:
self.fields["is_reviewer"].help_text = mark_safe(
f' (<a href="{instance.orga_urls.base}tracks">'
+ str(_("Limit to certain tracks?"))
+ "</a>)"
)
class SubmissionTypeForm(ReadOnlyFlag, I18nModelForm):
def save(self, *args, **kwargs):
instance = super().save(*args, **kwargs)
if instance.pk and "duration" in self.changed_data:
instance.update_duration()
class Meta:
model = SubmissionType
fields = ("name", "default_duration", "deadline", "requires_access_code")
widgets = {
"deadline": forms.DateTimeInput(attrs={"class": "datetimepickerfield"})
}
class TrackForm(ReadOnlyFlag, I18nModelForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields["color"].widget.attrs["class"] = "colorpickerfield"
class Meta:
model = Track
fields = ("name", "color", "requires_access_code")
class SubmitterAccessCodeForm(forms.ModelForm):
def __init__(self, *args, event, **kwargs):
self.event = event
initial = kwargs.get("initial", {})
if not kwargs.get("instance"):
initial["code"] = SubmitterAccessCode().generate_code()
initial["valid_until"] = event.cfp.deadline
"variant",
"is_public",
"is_visible_to_reviewers",
"required",
"tracks",
"contains_personal_data",
"min_length",
"max_length",
]
field_classes = {
"variant": SafeModelChoiceField,
"tracks": SafeModelMultipleChoiceField,
}
class AnswerOptionForm(ReadOnlyFlag, I18nModelForm):
class Meta:
model = AnswerOption
fields = ["answer"]
class SubmissionTypeForm(ReadOnlyFlag, I18nModelForm):
def save(self, *args, **kwargs):
instance = super().save(*args, **kwargs)
if instance.pk and "duration" in self.changed_data:
instance.update_duration()
class Meta:
model = SubmissionType
fields = ("name", "default_duration", "deadline", "requires_access_code")
widgets = {
"deadline": forms.DateTimeInput(attrs={"class": "datetimepickerfield"})
from django_scopes.forms import SafeModelChoiceField, SafeModelMultipleChoiceField
from hierarkey.forms import HierarkeyForm
from i18nfield.forms import I18nFormMixin, I18nModelForm
from pretalx.common.mixins.forms import ReadOnlyFlag
from pretalx.submission.models import (
AnswerOption,
CfP,
Question,
SubmissionType,
SubmitterAccessCode,
Track,
)
class CfPSettingsForm(ReadOnlyFlag, I18nFormMixin, HierarkeyForm):
use_tracks = forms.BooleanField(
label=_("Use tracks"),
required=False,
help_text=_("Do you organise your talks by tracks?"),
)
present_multiple_times = forms.BooleanField(
label=_("Slot Count"),
required=False,
help_text=_("Can talks be held multiple times?"),
)
cfp_show_deadline = forms.BooleanField(
label=_("Display deadline publicly"),
required=False,
help_text=_("Show the time and date the CfP ends to potential speakers."),
)
cfp_request_abstract = forms.BooleanField(label="", required=False)
field_classes = {
"limit_tracks": SafeModelMultipleChoiceField,
}
class TeamInviteForm(ReadOnlyFlag, forms.ModelForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields["email"].required = True
class Meta:
model = TeamInvite
fields = ("email",)
class OrganiserForm(ReadOnlyFlag, I18nModelForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
if kwargs.get("instance"):
self.fields["slug"].disabled = True
class Meta:
model = Organiser
fields = ("name", "slug")
class EventWizardInitialForm(forms.Form):
locales = forms.MultipleChoiceField(
choices=settings.LANGUAGES,
label=_("Use languages"),
help_text=_("Choose all languages that your event should be available in."),
def __init__(self, obj, *args, **kwargs):
kwargs.pop(
"read_only"
) # added in ActionFromUrl view mixin, but not needed here.
super().__init__(*args, obj=obj, **kwargs)
if getattr(obj, "email"):
self.fields[
"mail_on_new_submission"
].help_text += f' (<a href="mailto:{obj.email}">{obj.email}</a>)'
for field in ["abstract", "description", "biography"]:
self.fields[f"cfp_{field}_min_length"].widget.attrs["placeholder"] = ""
self.fields[f"cfp_{field}_max_length"].widget.attrs["placeholder"] = ""
class CfPForm(ReadOnlyFlag, I18nModelForm):
class Meta:
model = CfP
fields = ["headline", "text", "deadline"]
widgets = {
"deadline": forms.DateTimeInput(attrs={"class": "datetimepickerfield"})
}
class QuestionForm(ReadOnlyFlag, I18nModelForm):
def __init__(self, *args, event=None, **kwargs):
super().__init__(*args, **kwargs)
instance = kwargs.get("instance")
if not (
event.settings.use_tracks
and event.tracks.all().count()
and event.settings.cfp_request_track
].help_text += f' (<a href="mailto:{obj.email}">{obj.email}</a>)'
for field in ["abstract", "description", "biography"]:
self.fields[f"cfp_{field}_min_length"].widget.attrs["placeholder"] = ""
self.fields[f"cfp_{field}_max_length"].widget.attrs["placeholder"] = ""
class CfPForm(ReadOnlyFlag, I18nModelForm):
class Meta:
model = CfP
fields = ["headline", "text", "deadline"]
widgets = {
"deadline": forms.DateTimeInput(attrs={"class": "datetimepickerfield"})
}
class QuestionForm(ReadOnlyFlag, I18nModelForm):
def __init__(self, *args, event=None, **kwargs):
super().__init__(*args, **kwargs)
instance = kwargs.get("instance")
if not (
event.settings.use_tracks
and event.tracks.all().count()
and event.settings.cfp_request_track
):
self.fields.pop("tracks")
else:
self.fields["tracks"].queryset = event.tracks.all()
if (
instance
and instance.pk
and instance.answers.count()
and not instance.is_public
if data.get("login_email") and data.get("login_password"):
return data["user_id"]
user = User.objects.create_user(
name=data.get("register_name").strip(),
email=data.get("register_email").lower().strip(),
password=data.get("register_password"),
locale=translation.get_language(),
timezone=timezone.get_current_timezone_name(),
)
data["user_id"] = user.pk
return user.pk
class SpeakerProfileForm(
CfPFormMixin, AvailabilitiesFormMixin, ReadOnlyFlag, PublicContent, forms.ModelForm
):
USER_FIELDS = ["name", "email", "avatar", "get_gravatar"]
FIRST_TIME_EXCLUDE = ["email"]
def __init__(self, *args, name=None, **kwargs):
self.user = kwargs.pop("user", None)
self.event = kwargs.pop("event", None)
self.with_email = kwargs.pop("with_email", True)
self.essential_only = kwargs.pop("essential_only", False)
if self.user:
kwargs["instance"] = self.user.event_profile(self.event)
else:
kwargs["instance"] = SpeakerProfile()
super().__init__(*args, **kwargs, event=self.event)
read_only = kwargs.get("read_only", False)
initial = kwargs.get("initial", dict())
from django import forms
from django.utils.translation import gettext as _
from pretalx.common.forms.widgets import MarkdownWidget
from pretalx.common.mixins.forms import ReadOnlyFlag
from pretalx.submission.models import Feedback
class FeedbackForm(ReadOnlyFlag, forms.ModelForm):
def __init__(self, talk, **kwargs):
super().__init__(**kwargs)
self.instance.talk = talk
self.fields["speaker"].queryset = self.instance.talk.speakers.all()
self.fields["speaker"].empty_label = _("All speakers")
def save(self, *args, **kwargs):
if (
not self.cleaned_data["speaker"]
and self.instance.talk.speakers.count() == 1
):
self.instance.speaker = self.instance.talk.speakers.first()
return super().save(*args, **kwargs)
class Meta:
model = Feedback
from django.core.files.base import ContentFile
from django.utils.timezone import now
from django.utils.translation import gettext_lazy as _
from hierarkey.forms import HierarkeyForm
from i18nfield.fields import I18nFormField, I18nTextarea
from i18nfield.forms import I18nFormMixin, I18nModelForm
from pretalx.common.css import validate_css
from pretalx.common.forms.fields import IMAGE_EXTENSIONS, ExtensionFileField
from pretalx.common.mixins.forms import ReadOnlyFlag
from pretalx.common.phrases import phrases
from pretalx.event.models.event import Event, Event_SettingsStore
from pretalx.orga.forms.widgets import HeaderSelect, MultipleLanguagesWidget
class EventForm(ReadOnlyFlag, I18nModelForm):
locales = forms.MultipleChoiceField(
label=_("Active languages"),
choices=settings.LANGUAGES,
widget=MultipleLanguagesWidget,
)
logo = ExtensionFileField(
required=False,
extensions=IMAGE_EXTENSIONS,
label=_("Header image"),
help_text=_(
"If you provide a header image, it will be displayed instead of your event's color and/or header pattern "
"on top of all event pages. It will be center-aligned, so when the window shrinks, the center parts will "
"continue to be displayed, and not stretched."
),
)
header_image = ExtensionFileField(