Пример #1
0
class UserPrefMetadataForm(Form):
    """Form for admins to add metadata for users."""
    languages = Select2Field(lazy_gettext('Language(s)'),
                             choices=[],
                             default="")
    locations = Select2Field(lazy_gettext('Location(s)'),
                             choices=[],
                             default="")
    work_hours_from = TimeField(lazy_gettext('Work Hours From'), [
        TimeFieldsValidator(
            ["work_hours_to", "timezone"],
            message=
            "Work Hours From, Work Hours To, and Timezone must be filled out for submission"
        )
    ],
                                default='')
    work_hours_to = TimeField(lazy_gettext('Work Hours To'), [
        TimeFieldsValidator(
            ["work_hours_from", "timezone"],
            message=
            "Work Hours From, Work Hours To, and Timezone must be filled out for submission"
        )
    ],
                              default='')
    timezone = SelectField(lazy_gettext('Timezone'), [
        TimeFieldsValidator(
            ["work_hours_from", "work_hours_to"],
            message=
            "Work Hours From, Work Hours To, and Timezone must be filled out for submission"
        )
    ],
                           choices=[],
                           default="")
    user_type = SelectField(lazy_gettext('Type of user'),
                            [validators.Required()],
                            choices=[],
                            default="")
    if data_access.data_access_levels:
        data_access = Select2Field(
            lazy_gettext('Data Access(s)'),
            [validators.Required(),
             pb_validator.UserTypeValiadator()],
            choices=data_access.data_access_levels['valid_access_levels'],
            default="")
    review = TextAreaField(lazy_gettext('Additional comments'), default="")

    def set_upref_mdata_choices(self):
        upref_mdata_choices = app_settings.upref_mdata.get_upref_mdata_choices(
        )
        self.languages.choices = upref_mdata_choices['languages']
        self.locations.choices = upref_mdata_choices['locations']
        self.timezone.choices = upref_mdata_choices['timezones']
        self.user_type.choices = upref_mdata_choices['user_types']
Пример #2
0
class UserPrefMetadataForm(Form):
    """Form for admins to add metadata for users or for users to update their
    own metadata"""
    languages = Select2Field(
        lazy_gettext('Language(s)'), choices=[],default="")
    locations = Select2Field(
        lazy_gettext('Location(s)'), choices=[], default="")
    work_hours_from = TimeField(
        lazy_gettext('Work Hours From'),
        [TimeFieldsValidator(["work_hours_to", "timezone"],
        message="Work Hours From, Work Hours To, and Timezone must be filled out for submission")],
        default='')
    work_hours_to = TimeField(
        lazy_gettext('Work Hours To'),
        [TimeFieldsValidator(["work_hours_from", "timezone"],
        message="Work Hours From, Work Hours To, and Timezone must be filled out for submission")],
        default='')
    timezone = SelectField(lazy_gettext('Timezone'),
        [TimeFieldsValidator(["work_hours_from", "work_hours_to"],
        message="Work Hours From, Work Hours To, and Timezone must be filled out for submission")],
        choices=[], default="")
    user_type = SelectField(
        lazy_gettext('Type of user'), [validators.Required()], choices=[], default="")
    if data_access.data_access_levels:
        data_access = Select2Field(
            lazy_gettext('Data Access(s)'), [validators.Required(),
                pb_validator.UserTypeValiadator()],
            choices=data_access.data_access_levels['valid_user_access_levels'], default="")
    review = TextAreaField(
        lazy_gettext('Additional comments'), default="")

    def __init__(self, *args, **kwargs):
        Form.__init__(self, *args, **kwargs)
        self.set_can_update(kwargs.get('can_update', (True, None)))

    def set_upref_mdata_choices(self):
        upref_mdata_choices = app_settings.upref_mdata.get_upref_mdata_choices()
        self.languages.choices = upref_mdata_choices['languages']
        self.locations.choices = upref_mdata_choices['locations']
        self.timezone.choices = upref_mdata_choices['timezones']
        self.user_type.choices = upref_mdata_choices['user_types']

    def set_can_update(self, can_update_info):
        self._disabled = self._get_disabled_fields(can_update_info)

    def _get_disabled_fields(self, (can_update, disabled_fields)):
        if not can_update:
            return {field: 'Form is not updatable.' for field in self}
        return {getattr(self, name): reason for name, reason in six.iteritems(disabled_fields or {})}
Пример #3
0
class TaskSchedulerForm(Form):
    _translate_names = lambda variant: (variant[0], lazy_gettext(variant[1]))
    _choices = map(_translate_names, sched_variants())
    sched = SelectField(lazy_gettext('Task Scheduler'), choices=_choices)
    customized_columns = Select2Field(lazy_gettext('Customized columns'),
                                      choices=[],
                                      default="")
    rand_within_priority = BooleanField(
        lazy_gettext('Randomize Within Priority'))
    gold_task_probability_validator = validators.NumberRange(
        min=0,
        max=1,
        message=lazy_gettext(
            'Gold task probability must be a value between 0.0 and 1.0'))
    gold_task_probability = DecimalField(
        label=lazy_gettext('Gold Probability'),
        validators=[gold_task_probability_validator],
        description=lazy_gettext('Probability value between 0 and 1'))

    def set_customized_columns_options(self, new_options):
        self.customized_columns.choices = new_options

    @classmethod
    def update_sched_options(cls, new_options):
        _translate_names = lambda variant: (variant[0], lazy_gettext(variant[1]
                                                                     ))
        _choices = map(_translate_names, new_options)
        cls.sched.kwargs['choices'] = _choices
Пример #4
0
class ProjectUpdateForm(ProjectForm):
    id = IntegerField(label=None, widget=HiddenInput())
    description = TextAreaField(lazy_gettext('Description'), [
        validators.Required(
            message=lazy_gettext("You must provide a description.")),
        validators.Length(max=255)
    ])
    long_description = TextAreaField(lazy_gettext('Long Description'))
    allow_anonymous_contributors = BooleanField(
        lazy_gettext('Allow Anonymous Contributors'))
    zip_download = BooleanField(lazy_gettext('Allow ZIP data download'))
    category_id = SelectField(lazy_gettext('Category'), coerce=int)
    hidden = BooleanField(lazy_gettext('Hide?'))
    email_notif = BooleanField(lazy_gettext('Email Notifications'))
    password = TextField(lazy_gettext('Password'), [
        validators.Optional(),
        pb_validator.CheckPasswordStrength(min_len=PROJECT_PWD_MIN_LEN,
                                           special=False)
    ])
    if data_access.data_access_levels:
        data_access = Select2Field(
            lazy_gettext('Access Level(s)'), [validators.Required()],
            choices=data_access.data_access_levels['valid_access_levels'],
            default=[])
    webhook = TextField(lazy_gettext('Webhook'), [pb_validator.Webhook()])
    sync_enabled = BooleanField(lazy_gettext('Enable Project Syncing'))
Пример #5
0
def dynamic_project_form(class_type,
                         form_data,
                         data_access_levels,
                         products=None,
                         obj=None):
    class ProjectFormExtraInputs(class_type):
        def __init__(self, *args, **kwargs):
            class_type.__init__(self, *args, **kwargs)
            set_product_subproduct_choices(self, products)

        pass

    if data_access_levels:
        data_access = Select2Field(
            lazy_gettext('Access Level(s)'), [validators.Required()],
            choices=data_access_levels['valid_access_levels'],
            default=[])
        ProjectFormExtraInputs.data_access = data_access

    return ProjectFormExtraInputs(form_data, obj=obj)
Пример #6
0
class UserPrefMetadataForm(Form):
    """Form for admins to add metadata for users or for users to update their
    own metadata"""
    languages = Select2Field(lazy_gettext('Language(s)'),
                             choices=[],
                             default="")
    locations = Select2Field(lazy_gettext('Location(s)'),
                             choices=[],
                             default="")
    work_hours_from = TimeField(lazy_gettext('Work Hours From'), [
        TimeFieldsValidator(
            ["work_hours_to", "timezone"],
            message=
            "Work Hours From, Work Hours To, and Timezone must be filled out for submission"
        )
    ],
                                default='')
    work_hours_to = TimeField(lazy_gettext('Work Hours To'), [
        TimeFieldsValidator(
            ["work_hours_from", "timezone"],
            message=
            "Work Hours From, Work Hours To, and Timezone must be filled out for submission"
        )
    ],
                              default='')
    timezone = SelectField(lazy_gettext('Timezone'), [
        TimeFieldsValidator(
            ["work_hours_from", "work_hours_to"],
            message=
            "Work Hours From, Work Hours To, and Timezone must be filled out for submission"
        )
    ],
                           choices=[],
                           default="")
    user_type = SelectField(lazy_gettext('Type of user'),
                            [validators.Required()],
                            choices=[],
                            default="")
    if data_access.data_access_levels:
        data_access = Select2Field(
            lazy_gettext('Data Access(s)'),
            [validators.Required(),
             pb_validator.UserTypeValiadator()],
            choices=data_access.data_access_levels['valid_user_access_levels'],
            default="")
    review = TextAreaField(lazy_gettext('Additional comments'), default="")
    profile = TextAreaField(lazy_gettext(
        "<div>Task Preferences</div>"
        "<div style='color:red; font-weight:normal; font-size:12px;'>"
        "Must not include sensitive or personally identifiable information, e.g., name, email address, phone number, UUID, race, gender, health or financial information.</div>"
    ), [is_json(dict)],
                            default="",
                            render_kw={
                                "placeholder":
                                '{"finance": 0.5, "english": 0.8}'
                            })

    def __init__(self, *args, **kwargs):
        Form.__init__(self, *args, **kwargs)
        self.set_can_update(kwargs.get('can_update', (True, None, None)))

    def set_upref_mdata_choices(self):
        upref_mdata_choices = app_settings.upref_mdata.get_upref_mdata_choices(
        )
        self.languages.choices = upref_mdata_choices['languages']
        self.locations.choices = upref_mdata_choices['locations']
        self.timezone.choices = upref_mdata_choices['timezones']
        self.user_type.choices = upref_mdata_choices['user_types']

    def set_can_update(self, can_update_info):
        self._disabled = self._get_disabled_fields(can_update_info)
        self._hide_fields(can_update_info)

    def _get_disabled_fields(self, (can_update, disabled_fields,
                                    hidden_fields)):
        if not can_update:
            return {field: 'Form is not updatable.' for field in self}
        return {
            getattr(self, name): reason
            for name, reason in six.iteritems(disabled_fields or {})
        }