示例#1
0
class GroupEditForm(forms.ModelForm):

    members = UsersSearchSelectField(
        queryset=UserProfile.objects.none(),
        initial_queryset=UserProfile.objects.none())

    def __init__(self, *args, **kwargs):
        course_instance = kwargs.get('instance').course_instance
        super().__init__(*args, **kwargs)
        self.fields['members'].widget.attrs[
            "data-search-api-url"] = api_reverse(
                "course-students-list",
                kwargs={'course_id': course_instance.id})
        self.fields["members"].queryset = course_instance.get_student_profiles(
        )
        # Course staff may use this form for modifying and creating student groups.
        # If an existing group is being modified, its current members must be
        # set to the initial queryset.
        if self.instance.id:
            self.fields[
                "members"].initial_queryset = self.instance.members.all()

    class Meta:
        model = StudentGroup
        fields = ['members']
示例#2
0
class SelectUsersForm(forms.Form):
    user = UsersSearchSelectField(queryset=UserProfile.objects.none(),
                                  initial_queryset=UserProfile.objects.none())

    def __init__(self, *args, **kwargs):
        course_instance = kwargs.pop('instance')
        super(SelectUsersForm, self).__init__(*args, **kwargs)
        self.fields['user'].widget.attrs["data-search-api-url"] = api_reverse(
            "course-students-list", kwargs={'course_id': course_instance.id})
        self.fields['user'].queryset = course_instance.get_student_profiles()
示例#3
0
class EnrollStudentsForm(forms.Form):

    user_profiles = UsersSearchSelectField(
        queryset=UserProfile.objects.all(),
        initial_queryset=UserProfile.objects.none(),
        label=_('Users'))

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.fields['user_profiles'].widget.attrs[
            "data-search-api-url"] = api_reverse("user-list")
示例#4
0
class CourseInstanceForm(forms.ModelForm):

    assistants = UsersSearchSelectField(queryset=UserProfile.objects.all(),
        initial_queryset=UserProfile.objects.none(),
        required=False) # Not required because a course does not have to have any assistants.

    class Meta:
        model = CourseInstance
        fields = [
            'visible_to_students',
            'instance_name',
            'url',
            'image',
            'language',
            'starting_time',
            'ending_time',
            'lifesupport_time',
            'archive_time',
            'enrollment_starting_time',
            'enrollment_ending_time',
            'enrollment_audience',
            'view_content_to',
            'head_urls',
            'assistants',
            'technical_error_emails',
        ]

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.fields['assistants'].initial_queryset = self.instance.assistants.all()
        self.fields['assistants'].widget.attrs["data-search-api-url"] = api_reverse("user-list")
        if self.instance and self.instance.visible_to_students:
            self.fields["url"].widget.attrs["readonly"] = "true"
            self.fields["url"].help_text = _("The URL identifier is locked "
                "while the course is visible to students.")
            self.fields["lifesupport_time"].help_text = _("Removes visibility "
                "of model answers for students.")
            self.fields["archive_time"].help_text = _("Removes possibility "
                "for students to return answers.")

    def clean_url(self):
        if self.instance and self.instance.visible_to_students:
            # URL must not be changed for visible course instances.
            return self.instance.url
        # ModelForm runs form validation before the model validation.
        # The URL validator is copied here from the model definition because
        # the cleaned data returned here is used in the rendering of the form
        # POST target page. Even though the model validation would stop invalid
        # data from being saved to the database, the next page rendering could
        # crash due to invalid data if this method returned an invalid value.
        # Raising a ValidationError here prevents the course instance from
        # having invalid values.
        generate_url_key_validator()(self.cleaned_data["url"])
        return self.cleaned_data["url"]
示例#5
0
文件: forms.py 项目: apluslms/a-plus
class DeadlineRuleDeviationForm(forms.Form):
    module = forms.ModelMultipleChoiceField(
        queryset=CourseModule.objects.none(),
        required=False,
        label=_('LABEL_MODULE'),
        help_text=_('DEVIATION_MODULE_HELPTEXT'),
        widget=SearchSelect,
    )
    exercise = forms.ModelMultipleChoiceField(
        queryset=BaseExercise.objects.none(),
        required=False,
        label=_('LABEL_EXERCISE'),
        help_text=_('DEVIATION_EXERCISE_HELPTEXT'),
        widget=SearchSelect,
    )
    submitter = UsersSearchSelectField(
        queryset=UserProfile.objects.none(),
        initial_queryset=UserProfile.objects.none(),
        required=True,
        label=_('LABEL_SUBMITTER'),
    )
    minutes = forms.IntegerField(
        required=False,
        min_value=1,
        label=_('LABEL_MINUTES'),
        help_text=_('DEVIATION_EXTRA_MINUTES_HELPTEXT'),
    )
    new_date = forms.DateTimeField(
        required=False,
        label=_('LABEL_NEW_DEADLINE'),
        help_text=_('DEVIATION_NEW_DEADLINE_DATE_HELPTEXT'),
        widget=DateTimeLocalInput,
    )
    without_late_penalty = forms.BooleanField(
        required=False,
        initial=True,
        label=_('LABEL_WITHOUT_LATE_PENALTY'),
    )

    def __init__(self, *args: Any, **kwargs: Any) -> None:
        course_instance = kwargs.pop('instance')
        super(DeadlineRuleDeviationForm, self).__init__(*args, **kwargs)
        self.fields["module"].queryset = CourseModule.objects.filter(
            course_instance=course_instance)
        self.fields["exercise"].queryset = BaseExercise.objects.filter(
            course_module__course_instance=course_instance)
        self.fields[
            'submitter'].queryset = course_instance.get_student_profiles()
        self.fields['submitter'].widget.search_api_url = api_reverse(
            "course-students-list",
            kwargs={'course_id': course_instance.id},
        )
示例#6
0
class CourseTeachersForm(forms.ModelForm):

    teachers = UsersSearchSelectField(
        queryset=UserProfile.objects.all(),
        initial_queryset=UserProfile.objects.none(),
        required=False
    )  # Not required because a course does not have to have any teachers.

    class Meta:
        model = Course
        fields = ['teachers']

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.fields['teachers'].initial_queryset = self.instance.teachers.all()
        self.fields['teachers'].widget.attrs[
            "data-search-api-url"] = api_reverse("user-list")
示例#7
0
class EnrollStudentsForm(forms.Form):

    user_profiles = UsersSearchSelectField(
        queryset=UserProfile.objects.all(),
        initial_queryset=UserProfile.objects.none(),
        label=_('LABEL_USERS'),
        required=False,
    )

    def __init__(self, *args: Any, **kwargs: Any) -> None:
        self.instance = kwargs.pop('instance')
        super().__init__(*args, **kwargs)
        self.fields['user_profiles'].widget.search_api_url = api_reverse(
            "user-list")
        if self.instance.sis_id:
            self.fields['sis'] = forms.BooleanField(
                required=False,
                label=_('LABEL_ENROLL_FROM_SIS'),
            )
示例#8
0
文件: forms.py 项目: jaguarfi/a-plus
class EditSubmittersForm(forms.ModelForm):

    submitters = UsersSearchSelectField(
        queryset=UserProfile.objects.none(),
        initial_queryset=UserProfile.objects.none())

    def __init__(self, *args, **kwargs):
        course_instance = kwargs.get('instance').exercise.course_instance
        super().__init__(*args, **kwargs)
        self.fields['submitters'].widget.attrs[
            "data-search-api-url"] = api_reverse(
                "course-students-list",
                kwargs={'course_id': course_instance.id})
        self.fields[
            'submitters'].queryset = course_instance.get_student_profiles()
        self.fields[
            'submitters'].initial_queryset = self.instance.submitters.all()

    class Meta:
        model = Submission
        fields = ['submitters']
示例#9
0
class EditSubmittersForm(forms.ModelForm):

    submitters = UsersSearchSelectField(
        queryset=UserProfile.objects.none(),
        initial_queryset=UserProfile.objects.none(),
        label=_('LABEL_SUBMITTERS'),
    )

    def __init__(self, *args: Any, **kwargs: Any) -> None:
        course_instance = kwargs.get('instance').exercise.course_instance
        super().__init__(*args, **kwargs)
        self.fields['submitters'].widget.search_api_url = api_reverse(
            "course-students-list",
            kwargs={'course_id': course_instance.id},
        )
        self.fields[
            'submitters'].queryset = course_instance.get_student_profiles()
        self.fields[
            'submitters'].initial_queryset = self.instance.submitters.all()

    class Meta:
        model = Submission
        fields = ['submitters']
示例#10
0
class CourseInstanceForm(forms.ModelForm):

    teachers = UsersSearchSelectField(
        label=_('LABEL_TEACHERS'),
        queryset=UserProfile.objects.all(),
        initial_queryset=UserProfile.objects.none(),
        required=False)
    assistants = UsersSearchSelectField(
        label=_('LABEL_ASSISTANTS'),
        queryset=UserProfile.objects.all(),
        initial_queryset=UserProfile.objects.none(),
        required=False
    )  # Not required because a course does not have to have any assistants.

    class Meta:
        model = CourseInstance
        fields = [
            'visible_to_students',
            'instance_name',
            'url',
            'image',
            'language',
            'starting_time',
            'ending_time',
            'lifesupport_time',
            'archive_time',
            'enrollment_starting_time',
            'enrollment_ending_time',
            'enrollment_audience',
            'view_content_to',
            'head_urls',
            'teachers',
            'assistants',
            'technical_error_emails',
            'sis_enroll',
        ]
        widgets = {
            'starting_time': DateTimeLocalInput,
            'ending_time': DateTimeLocalInput,
            'lifesupport_time': DateTimeLocalInput,
            'archive_time': DateTimeLocalInput,
            'enrollment_starting_time': DateTimeLocalInput,
            'enrollment_ending_time': DateTimeLocalInput,
        }

    def __init__(self, *args: Any, **kwargs: Any) -> None:
        super().__init__(*args, **kwargs)
        self.fields['teachers'].initial = self.instance.teachers.all()
        self.fields['teachers'].initial_queryset = self.instance.teachers.all()
        self.fields['teachers'].widget.search_api_url = api_reverse(
            "user-list")
        self.fields['assistants'].initial = self.instance.assistants.all()
        self.fields[
            'assistants'].initial_queryset = self.instance.assistants.all()
        self.fields['assistants'].widget.search_api_url = api_reverse(
            "user-list")
        if self.instance and self.instance.visible_to_students:
            self.fields["url"].widget.attrs["readonly"] = "true"
            self.fields["url"].help_text = _(
                'COURSE_URL_IDENTIFIER_LOCKED_WHILE_COURSE_VISIBLE')
            self.fields["lifesupport_time"].help_text = _(
                'COURSE_REMOVES_MODEL_ANSWER_VISIBILITY_STUDENTS')
            self.fields["archive_time"].help_text = _(
                'COURSE_REMOVES_SUBMISSION_POSSIBILITY_STUDENTS')

        # If course is not connected to SIS system, disable the enroll checkbox
        if not self.instance.sis_id:
            self.fields['sis_enroll'].disabled = True

    def clean_url(self):
        if self.instance and self.instance.visible_to_students:
            # URL must not be changed for visible course instances.
            return self.instance.url
        # ModelForm runs form validation before the model validation.
        # The URL validator is copied here from the model definition because
        # the cleaned data returned here is used in the rendering of the form
        # POST target page. Even though the model validation would stop invalid
        # data from being saved to the database, the next page rendering could
        # crash due to invalid data if this method returned an invalid value.
        # Raising a ValidationError here prevents the course instance from
        # having invalid values.
        generate_url_key_validator()(self.cleaned_data["url"])
        return self.cleaned_data["url"]

    def save(self, *args, **kwargs):
        self.instance.set_assistants(self.cleaned_data['assistants'])
        self.instance.set_teachers(self.cleaned_data['teachers'])

        return super(CourseInstanceForm, self).save(*args, **kwargs)