def __init__(self, request, *args, **kwargs): super(RecordingForm, self).__init__(*args, **kwargs) self.fields = add_placeholder_and_asterisk(self.fields) if self.initial.get("type"): self.fields['type'].widget = forms.HiddenInput() self.fields['source_file'] = forms.FilePathField( path=DEFAULT_RECORDER_PATH, recursive=True, label=_("source_file")) self.fields['source_file'].widget.attrs['class'] = 'form-control' self.fields["recorder"].queryset = self.fields["recorder"].queryset.\ filter( sites=Site.objects.get_current()) self.fields["user"].queryset = self.fields["user"].queryset.filter( owner__sites=Site.objects.get_current()) if not (check_show_user(request) or request.user.is_superuser or request.user.has_perm("recorder.add_recording")): del self.fields['user'] if not (request.user.is_superuser or request.user.has_perm("recorder.add_recording")): self.fields['recorder'].widget = forms.HiddenInput() self.fields['delete'].widget = forms.HiddenInput() self.fields['source_file'].widget = forms.HiddenInput()
def __init__(self, *args, **kwargs): self.is_staff = kwargs.pop( 'is_staff') if 'is_staff' in kwargs.keys() else self.is_staff self.is_superuser = kwargs.pop( 'is_superuser') if ( 'is_superuser' in kwargs.keys() ) else self.is_superuser self.current_user = kwargs.pop( 'current_user') if kwargs.get('current_user') else None self.VIDEO_ALLOWED_EXTENSIONS = VIDEO_ALLOWED_EXTENSIONS self.VIDEO_MAX_UPLOAD_SIZE = VIDEO_MAX_UPLOAD_SIZE self.VIDEO_FORM_FIELDS_HELP_TEXT = VIDEO_FORM_FIELDS_HELP_TEXT self.max_duration_date_delete = MAX_DURATION_DATE_DELETE super(VideoForm, self).__init__(*args, **kwargs) if FILEPICKER and self.fields.get('thumbnail'): self.fields['thumbnail'].widget = CustomFileWidget(type="image") if not TRANSCRIPT: self.remove_field('transcript') if self.fields.get('video'): self.fields['video'].label = _(u'File') valid_ext = FileExtensionValidator(VIDEO_ALLOWED_EXTENSIONS) self.fields['video'].validators = [valid_ext, FileSizeValidator] self.fields['video'].widget.attrs[ 'class'] = self.videoattrs["class"] self.fields['video'].widget.attrs[ 'accept'] = self.videoattrs["accept"] if self.instance.encoding_in_progress: self.remove_field('owner') self.remove_field('video') # .widget = forms.HiddenInput() # change ckeditor, thumbnail and date delete config for no staff user self.set_nostaff_config() # hide default language self.hide_default_language() # QuerySet for channels and theme self.set_queryset() self.filter_fields_admin() self.fields = add_placeholder_and_asterisk(self.fields) # remove required=True for videofield if instance if self.fields.get('video') and self.instance and self.instance.video: del self.fields["video"].widget.attrs["required"] if self.fields.get('owner'): self.fields['owner'].queryset = self.fields['owner']. \ queryset.filter(owner__sites=Site.objects.get_current())
def __init__(self, *args, **kwargs): self.is_staff = ( kwargs.pop("is_staff") if "is_staff" in kwargs.keys() else self.is_staff ) self.is_superuser = ( kwargs.pop("is_superuser") if ("is_superuser" in kwargs.keys()) else self.is_superuser ) self.current_lang = kwargs.pop("current_lang", settings.LANGUAGE_CODE) self.current_user = kwargs.pop("current_user", None) self.VIDEO_ALLOWED_EXTENSIONS = VIDEO_ALLOWED_EXTENSIONS self.VIDEO_MAX_UPLOAD_SIZE = VIDEO_MAX_UPLOAD_SIZE self.VIDEO_FORM_FIELDS_HELP_TEXT = VIDEO_FORM_FIELDS_HELP_TEXT self.max_duration_date_delete = MAX_DURATION_DATE_DELETE super(VideoForm, self).__init__(*args, **kwargs) self.custom_video_form() # change ckeditor, thumbnail and date delete config for no staff user self.set_nostaff_config() # hide default language self.hide_default_language() # QuerySet for channels and theme self.set_queryset() self.filter_fields_admin() # Manage more required fields self.manage_more_required_fields() # Manage required fields html self.fields = add_placeholder_and_asterisk(self.fields) if self.fields.get("video"): self.fields["video"].label = _("File") valid_ext = FileExtensionValidator(VIDEO_ALLOWED_EXTENSIONS) self.fields["video"].validators = [valid_ext, FileSizeValidator] self.fields["video"].widget.attrs["class"] = self.videoattrs["class"] self.fields["video"].widget.attrs["accept"] = self.videoattrs["accept"] if self.instance.encoding_in_progress: self.remove_field("owner") self.remove_field("video") # .widget = forms.HiddenInput() # remove required=True for videofield if instance if self.fields.get("video") and self.instance and self.instance.video: del self.fields["video"].widget.attrs["required"] if self.fields.get("owner"): self.fields["owner"].queryset = self.fields["owner"].queryset.filter( owner__sites=Site.objects.get_current() )
def __init__(self, request, *args, **kwargs): super(RecordingForm, self).__init__(*args, **kwargs) self.fields = add_placeholder_and_asterisk(self.fields) if self.initial.get("type"): self.fields['type'].widget = forms.HiddenInput() self.fields['source_file'] = forms.FilePathField( path=DEFAULT_RECORDER_PATH, recursive=True, label=_("source_file")) self.fields['source_file'].widget.attrs['class'] = 'form-control' if not (check_show_user(request) or request.user.is_superuser): del self.fields['user'] if not request.user.is_superuser: self.fields['recorder'].widget = forms.HiddenInput() self.fields['source_file'].widget = forms.HiddenInput()
def __init__(self, *args, **kwargs): self.is_staff = ( kwargs.pop("is_staff") if "is_staff" in kwargs.keys() else self.is_staff ) self.is_superuser = ( kwargs.pop("is_superuser") if ("is_superuser" in kwargs.keys()) else self.is_superuser ) self.CHANNEL_FORM_FIELDS_HELP_TEXT = CHANNEL_FORM_FIELDS_HELP_TEXT super(ChannelForm, self).__init__(*args, **kwargs) if FILEPICKER: self.fields["headband"].widget = CustomFileWidget(type="image") if not hasattr(self, "admin_form"): del self.fields["visible"] if self.fields.get("sites"): del self.fields["sites"] if not self.is_superuser or not hasattr(self, "admin_form"): self.fields["owners"].queryset = self.fields["owners"].queryset.filter( owner__sites=Site.objects.get_current() ) self.fields["users"].queryset = self.fields["users"].queryset.filter( owner__sites=Site.objects.get_current() ) # change ckeditor config for no staff user if not hasattr(self, "admin_form") and ( self.is_staff is False and self.is_superuser is False ): del self.fields["headband"] self.fields["description"].widget = CKEditorWidget(config_name="default") for key, value in settings.LANGUAGES: self.fields[ "description_%s" % key.replace("-", "_") ].widget = CKEditorWidget(config_name="default") # hide default langage self.fields[ "description_%s" % settings.LANGUAGE_CODE ].widget = forms.HiddenInput() self.fields["title_%s" % settings.LANGUAGE_CODE].widget = forms.HiddenInput() self.fields = add_placeholder_and_asterisk(self.fields)