How to use the formencode.All function in FormEncode

To help you get started, we’ve selected a few FormEncode examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github the-virtual-brain / tvb-framework / tvb / interfaces / web / controllers / project / figure_controller.py View on Github external
figure = self.figure_service.load_figure(figure_id)
        figures_folder = self.files_helper.get_images_folder(figure.project.name)
        figure_full_path = os.path.join(figures_folder, figure.file_path)
        figure_file_path = utils.path2url_part(figure_full_path)
        description = figure.session_name + " - " + figure.name
        template_dictionary = dict(figure_file_path=figure_file_path)
        return self.fill_overlay_attributes(template_dictionary, "Detail", description,
                                            "project/figure_zoom_overlay", "lightbox")



class EditPreview(formencode.Schema):
    """
    Validate edit action on Stored Preview 
    """
    name = formencode.All(validators.UnicodeString(not_empty=True))
    session_name = formencode.All(validators.UnicodeString(not_empty=True))
github apache / allura / Allura / allura / lib / widgets / forms.py View on Github external
d["account"] = kw.get('account', '')
        d["socialnetwork"] = kw.get('socialnetwork', '')
        return d


class AddInactivePeriodForm(ForgeForm):

    class fields(ew_core.NameList):
        startdate = ew.TextField(
            label='Start date',
            validator=formencode.All(
                V.DateValidator(),
                fev.UnicodeString(not_empty=True)))
        enddate = ew.TextField(
            label='End date',
            validator=formencode.All(
                V.DateValidator(),
                fev.UnicodeString(not_empty=True)))

    @ew_core.core.validator
    def to_python(self, kw, state):
        d = super(AddInactivePeriodForm, self).to_python(kw, state)
        if d['startdate'] > d['enddate']:
                raise formencode.Invalid(
                    'Invalid period: start date greater than end date.',
                    kw, state)
        return d


class RemoveInactivePeriodForm(ForgeForm):
    defaults = dict(ForgeForm.defaults, submit_text=None, show_errors=False)
github the-virtual-brain / tvb-framework / tvb / interfaces / web / controllers / burst / burst_controller.py View on Github external
burst_entity = importer.load_burst_entity(upload_param, prj_id)
                common.add2session(common.KEY_BURST_CONFIG, burst_entity)

        except Exception as excep:
            self.logger.warning(excep.message)
            common.set_error_message(excep.message)

        raise cherrypy.HTTPRedirect('/burst/')



class BurstNameForm(formencode.Schema):
    """
    Validate Burst name string
    """
    burst_name = formencode.All(validators.UnicodeString(not_empty=True),
                                validators.Regex(regex=r"^[a-zA-Z\. _\-0-9]*$"))
github hep-gc / repoman / server / repoman / repoman / model / form.py View on Github external
class NewUserForm(formencode.Schema):
    allow_extra_fields = True
    filter_extra_fields = True

    # Manditory fields here
    user_name = formencode.All(formencode.validators.String(not_empty=True),
                               UniqueUsername())
    cert_dn = formencode.All(formencode.validators.String(not_empty=True),
                             UniqueCertDN())

    # Default fields here
    full_name = formencode.validators.String(if_missing=None)
    groups = formencode.validators.String(if_missing=False)
    suspended = formencode.validators.Bool(if_missing=False)
    email = formencode.All(formencode.validators.String(if_missing=None),
                           UniqueEmail())


###################
#   G R O U P S   #
###################
def validate_new_group(params):
    schema = NewGroupForm()
    try:
        result = schema.to_python(params)
    except formencode.validators.Invalid, error:
        for e,v in error.error_dict.iteritems():
            if e=='name' and v.state=='CONFLICT':
                abort(409, '409 Conflict')
            else:
                abort(400, '400 Bad Request')
github hep-gc / repoman / server / repoman / repoman / model / form.py View on Github external
user_q = meta.Session.query(model.User)
        if value != None and user_q.filter(model.User.email==value).first():
            state = 'CONFLICT'
            raise formencode.Invalid('conflict', value, state)
        else:
            return value

class ModifyUserForm(formencode.Schema):
    allow_extra_fields = True
    filter_extra_fields = True

    # What fields should be editable by the user?
    full_name = formencode.validators.String(if_missing=None)
    cert_dn = formencode.All(formencode.validators.String(if_missing=None),
                             UniqueCertDN())
    email = formencode.All(formencode.validators.String(if_missing=None),
                           UniqueEmail())
 
class NewUserForm(formencode.Schema):
    allow_extra_fields = True
    filter_extra_fields = True

    # Manditory fields here
    user_name = formencode.All(formencode.validators.String(not_empty=True),
                               UniqueUsername())
    cert_dn = formencode.All(formencode.validators.String(not_empty=True),
                             UniqueCertDN())

    # Default fields here
    full_name = formencode.validators.String(if_missing=None)
    groups = formencode.validators.String(if_missing=False)
    suspended = formencode.validators.Bool(if_missing=False)
github komarserjio / notejam / pyramid / notejam / forms.py View on Github external
name = validators.UnicodeString(not_empty=True)
    text = validators.UnicodeString(not_empty=True)
    pad_id = validators.Int()


class ForgotPasswordSchema(Schema):
    allow_extra_fields = False

    email = All(EmailExists(), validators.Email(not_empty=True))


class ChangePasswordSchema(Schema):
    allow_extra_fields = False

    old_password = All(PasswordCorrect(), validators.UnicodeString(min=6))
    password = validators.UnicodeString(min=6)
    confirm_password = validators.UnicodeString(min=6)
    passwords_match = [
        validators.FieldsMatch('password', 'confirm_password')
    ]
github the-virtual-brain / tvb-framework / tvb / interfaces / web / controllers / project / project_controller.py View on Github external
"""
        Overwrite base controller to add required parameters for adapter templates.
        """
        template_dictionary[common.KEY_SECTION] = 'project'
        template_dictionary[common.KEY_SUB_SECTION] = subsection
        template_dictionary[common.KEY_INCLUDE_RESOURCES] = 'project/included_resources'
        BaseController.fill_default_attributes(self, template_dictionary)
        return template_dictionary


class EditForm(formencode.Schema):
    """
    Validate creation of a Project entity. 
    """
    invalis_name_msg = "Please enter a name composed only of letters, numbers and underscores."
    name = formencode.All(validators.UnicodeString(not_empty=True),
                          validators.PlainText(messages={'invalid': invalis_name_msg}))
    description = validators.UnicodeString()
    users = formencode.foreach.ForEach(formencode.validators.Int())
    administrator = validators.UnicodeString(not_empty=False)
    project_id = validators.UnicodeString(not_empty=False)
    visited_pages = validators.UnicodeString(not_empty=False)
github the-virtual-brain / tvb-framework / tvb / adapters / simulator / simulator_fragments.py View on Github external
def is_burst_name_ok(burst_name):
        class BurstNameForm(formencode.Schema):
            """
            Validate Burst name string
            """
            burst_name = formencode.All(validators.UnicodeString(not_empty=True),
                                        validators.Regex(regex=r"^[a-zA-Z\. _\-0-9]*$"))

        try:
            form = BurstNameForm()
            form.to_python({'burst_name': burst_name})
            return True
        except formencode.Invalid:
            validation_error = "Invalid simulation name %s. Please use only letters, numbers, or _ " % str(burst_name)
            return validation_error
github the-virtual-brain / tvb-framework / tvb / interfaces / web / controllers / settings_controller.py View on Github external
"""
    Allow only ascii strings
    """
    def _convert_to_python(self, value, _):
        try:
            return str(value).encode('ascii')
        except UnicodeError:
            raise formencode.Invalid('Invalid ascii string %s' % value, '', None)


class SettingsForm(formencode.Schema):
    """
    Validate Settings Page inputs.
    """

    ADMINISTRATOR_NAME = formencode.All(validators.UnicodeString(not_empty=True), validators.PlainText())
    ADMINISTRATOR_PASSWORD = validators.UnicodeString(not_empty=True)
    ADMINISTRATOR_EMAIL = validators.Email(not_empty=True)

    WEB_SERVER_PORT = PortValidator()
    URL_WEB = validators.URL(not_empty=True, require_tld=False)

    SELECTED_DB = validators.UnicodeString(not_empty=True)
    URL_VALUE = validators.UnicodeString(not_empty=True)
    DEPLOY_CLUSTER = validators.Bool()
    CLUSTER_SCHEDULER = validators.UnicodeString(not_empty=True)

    TVB_STORAGE = validators.UnicodeString(not_empty=True)
    USR_DISK_SPACE = DiskSpaceValidator(not_empty=True)
    MATLAB_EXECUTABLE = MatlabValidator()
    MAXIMUM_NR_OF_THREADS = ThreadNrValidator()
    MAXIMUM_NR_OF_VERTICES_ON_SURFACE = SurfaceVerticesNrValidator()