Ejemplo n.º 1
0
class ObjectChangeFilterForm(BootstrapMixin, forms.Form):
    model = ObjectChange
    q = forms.CharField(required=False, label="Search")
    time_after = forms.DateTimeField(label="After",
                                     required=False,
                                     widget=DateTimePicker())
    time_before = forms.DateTimeField(label="Before",
                                      required=False,
                                      widget=DateTimePicker())
    action = forms.ChoiceField(
        choices=add_blank_choice(ObjectChangeActionChoices),
        required=False,
        widget=StaticSelect2(),
    )
    user_id = DynamicModelMultipleChoiceField(
        queryset=get_user_model().objects.all(),
        required=False,
        label="User",
        widget=APISelectMultiple(api_url="/api/users/users/", ),
    )
    changed_object_type_id = DynamicModelMultipleChoiceField(
        queryset=ContentType.objects.all(),
        required=False,
        label="Object Type",
        widget=APISelectMultiple(api_url="/api/extras/content-types/", ),
    )
Ejemplo n.º 2
0
 class Meta:
     model = Token
     fields = [
         "key",
         "write_enabled",
         "expires",
         "description",
     ]
     widgets = {
         "expires": DateTimePicker(),
     }
Ejemplo n.º 3
0
class JobScheduleForm(BootstrapMixin, forms.Form):
    """
    This form is rendered alongside the JobForm but deals specifically with the fields needed to either
    execute the job immediately, or schedule it for later. Each field name is prefixed with an underscore
    because in the POST body, they share a namespace with the JobForm which includes fields defined by the
    job author, so the underscore prefix helps to avoid name collisions.
    """

    _schedule_type = forms.ChoiceField(
        choices=JobExecutionType,
        help_text=
        "The job can either run immediately, once in the future, or on a recurring schedule.",
        label="Type",
    )
    _schedule_name = forms.CharField(
        required=False,
        label="Schedule name",
        help_text="Name for the job schedule.",
    )
    _schedule_start_time = forms.DateTimeField(
        required=False,
        label="Starting date and time",
        widget=DateTimePicker(),
    )

    def clean(self):
        """
        Validate all required information is present if the job needs to be scheduled
        """
        cleaned_data = super().clean()

        if "_schedule_type" in cleaned_data and cleaned_data.get(
                "_schedule_type") != JobExecutionType.TYPE_IMMEDIATELY:
            if not cleaned_data.get("_schedule_name"):
                raise ValidationError({
                    "_schedule_name":
                    "Please provide a name for the job schedule."
                })

            if (not cleaned_data.get("_schedule_start_time")
                    or cleaned_data.get("_schedule_start_time") <
                    ScheduledJob.earliest_possible_time()):
                raise ValidationError({
                    "_schedule_start_time":
                    "Please enter a valid date and time greater than or equal to the current date and time."
                })