Exemple #1
0
    def _to_python(self, value, state):
        from adhocracy.model import Page
        value = super(UnusedTitle, self)._to_python(value, state)

        if hasattr(state, 'page') and state.page.label == value:
            return value

        if not Page.unusedTitle(value):
            raise formencode.Invalid(
                _("An entry with this title already exists"), value, state)

        if not value or len(value) < 2:
            raise formencode.Invalid(_("No page name is given."), value, state)

        if value.lower() in FORBIDDEN_NAMES:
            raise formencode.Invalid(
                _("Invalid page name: %s") % value, value, state)

        try:
            int(value)
            raise formencode.Invalid(
                _("Variant name cannot be purely numeric: %s") % value, value,
                state)
        except:
            return value
Exemple #2
0
    def _to_python(self, value, state):
        from adhocracy.model import Page
        value = super(UnusedTitle, self)._to_python(value, state)

        if hasattr(state, 'page') and state.page.label == value:
            return value

        if not Page.unusedTitle(value):
            raise formencode.Invalid(
                _("An entry with this title already exists"), value, state)

        if not value or len(value) < 2:
            raise formencode.Invalid(_("No page name is given."), value, state)

        if value.lower() in FORBIDDEN_NAMES:
            raise formencode.Invalid(_("Invalid page name: %s") % value,
                                     value, state)

        try:
            int(value)
            raise formencode.Invalid(
                _("Variant name cannot be purely numeric: %s") % value,
                value, state)
        except:
            return value
Exemple #3
0
    def validate_python(self, field_dict, state):
        from adhocracy.model import Page

        value = field_dict['label']

        if hasattr(state, 'page') and state.page.label == value:
            return value

        if hasattr(state, 'page'):  # edit
            proposal = state.page.proposal
            is_amendment = proposal.is_amendment
            page = proposal.selection if is_amendment else None
        else:  # new
            is_amendment = field_dict['amendment']
            page = field_dict['page'][0]['id'] if is_amendment else None
        if not Page.unusedTitle(value, selection=page):
            msg = _("An entry with this title already exists")
            raise formencode.Invalid(
                msg, field_dict, state,
                error_dict={'label': msg}
            )

        if not value or len(value) < 2:
            msg = _("No page name is given.")
            raise formencode.Invalid(
                msg, field_dict, state,
                error_dict={'label': msg}
            )

        if value.lower() in FORBIDDEN_NAMES:
            msg = _("Invalid entry name: %s") % value
            raise formencode.Invalid(
                msg, field_dict, state,
                error_dict={'label': msg}
            )

        # every proposal title must be a valid variant name
        try:
            variant_name_validator = VariantName()
            variant_name_validator._to_python(value, state)
        except formencode.Invalid as e:
            raise formencode.Invalid(
                e.msg, field_dict, state,
                error_dict={'label': e.msg}
            )

        try:
            int(value)
            msg = _("Entry name cannot be purely numeric: %s") % value
            raise formencode.Invalid(
                msg, field_dict, state,
                error_dict={'label': msg}
            )
        except ValueError:
            return field_dict
Exemple #4
0
    def validate_python(self, field_dict, state):
        from adhocracy.model import Page

        value = field_dict['label']

        if hasattr(state, 'page') and state.page.label == value:
            return value

        if hasattr(state, 'page'):  # edit
            proposal = state.page.proposal
            is_amendment = proposal.is_amendment
            page = proposal.selection if is_amendment else None
        else:  # new
            is_amendment = field_dict['amendment']
            page = field_dict['page'][0]['id'] if is_amendment else None
        if not Page.unusedTitle(value, selection=page):
            msg = _("An entry with this title already exists")
            raise formencode.Invalid(msg,
                                     field_dict,
                                     state,
                                     error_dict={'label': msg})

        if not value or len(value) < 2:
            msg = _("No page name is given.")
            raise formencode.Invalid(msg,
                                     field_dict,
                                     state,
                                     error_dict={'label': msg})

        if value.lower() in FORBIDDEN_NAMES:
            msg = _("Invalid entry name: %s") % value
            raise formencode.Invalid(msg,
                                     field_dict,
                                     state,
                                     error_dict={'label': msg})

        try:
            int(value)
            msg = _("Entry name cannot be purely numeric: %s") % value
            raise formencode.Invalid(msg,
                                     field_dict,
                                     state,
                                     error_dict={'label': msg})
        except ValueError:
            return field_dict