示例#1
0
class UserPrefMetadataForm(Form):
    """Form for admins to add metadata for users."""
    languages = SelectMultipleField(
                        lazy_gettext('Language(s)'),
                        choices=[], default='')
    locations = SelectMultipleField(
                        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_to", "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=None)
    user_type = SelectField(
                        lazy_gettext('Type of user'),
                        choices=[], default='')
    review = TextAreaField(
                        lazy_gettext('Additional comments'), default='')

    def set_upref_mdata_choices(self):
        from pybossa.core import 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."""
    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']
示例#3
0
文件: forms.py 项目: lsuttle/pybossa
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 {})}
示例#4
0
class MetadataForm(Form):
    """Form for admins to add metadata for users."""
    languages = SelectMultipleField(lazy_gettext('Language(s)'), choices=util.languages())
    locations = SelectMultipleField(lazy_gettext('Location(s)'), choices=util.countries())
    start_time = TimeField(lazy_gettext('Start Time'),
        [TimeFieldsValidator(["end_time", "timezone"],
        message="Start time, End time, and Timezone must be filled out for submission")])
    end_time = TimeField(lazy_gettext('End Time'),
        [TimeFieldsValidator(["start_time", "timezone"],
        message="Start time, End time, and Timezone must be filled out for submission")])
    timezone = SelectField(lazy_gettext('Timezone'),
        [TimeFieldsValidator(["start_time", "end_time"],
        message="Start time, End time, and Timezone must be filled out for submission")],
        choices=util.timezones())
    user_type = SelectField(lazy_gettext('Type of user'), choices=util.user_types())
    review = TextAreaField(lazy_gettext('Additional comments'))
示例#5
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 {})
        }