Exemple #1
0
    def validate(self, submittedValue):
        """
        """
        errors = []
        fieldname = self.context.id
        if self.type == "INTEGER":
            try:
                v = long(submittedValue)
            except:
                errors.append(fieldname + PlominoTranslate(
                    _(" must be an integer (submitted value was: "),
                    self.context) + submittedValue + ")")
        elif self.type == "FLOAT":
            try:
                v = float(submittedValue)
            except:
                errors.append(fieldname + PlominoTranslate(
                    _(" must be a float (submitted value was: "), self.context)
                              + submittedValue + ")")
        elif self.type == "DECIMAL":
            try:
                v = Decimal(str(submittedValue))
            except:
                errors.append(fieldname + PlominoTranslate(
                    _(" must be a decimal (submitted value was: "),
                    self.context) + submittedValue + ")")

        return errors
Exemple #2
0
    def validateInputs(self, REQUEST, doc=None):
        """
        """
        errors = []
        fields = self.getFormFields(includesubforms=True,
                                    doc=doc,
                                    applyhidewhen=True)
        hidden_fields = self._get_js_hidden_fields(REQUEST, doc)
        fields = [
            field for field in fields if field.getId() not in hidden_fields
        ]
        for f in fields:
            fieldname = f.id
            fieldtype = f.getFieldType()
            submittedValue = REQUEST.get(fieldname)

            # STEP 1: check mandatory fields
            if not submittedValue:
                if f.getMandatory() == True:
                    if fieldtype == "ATTACHMENT" and doc:
                        existing_files = doc.getItem(fieldname)
                        if not existing_files:
                            errors.append(
                                f.Title() + " " +
                                PlominoTranslate("is mandatory", self))
                    else:
                        errors.append(f.Title() + " " +
                                      PlominoTranslate("is mandatory", self))
            else:
                # STEP 2: check data types
                errors = errors + f.validateFormat(submittedValue)

        if len(errors) == 0:
            # STEP 3: check validation formula
            tmp = TemporaryDocument(self.getParentDatabase(), self, REQUEST,
                                    doc)
            for f in fields:
                formula = f.getValidationFormula()
                if not formula == '':
                    s = ''
                    try:
                        s = self.runFormulaScript(
                            "field_" + self.id + "_" + f.id +
                            "_ValidationFormula", tmp, f.ValidationFormula)
                    except PlominoScriptException, e:
                        e.reportError('%s validation formula failed' % f.id)
                    if not s == '':
                        errors.append(s)
Exemple #3
0
 def getActionLabel(self, action_id):
     """
     """
     db = self.context.getParentDatabase()
     if action_id == "add":
         label = PlominoTranslate("datagrid_add_button_label", db)
         child_form_id = self.associated_form
         if child_form_id is not None:
             child_form = db.getForm(child_form_id)
             if child_form:
                 label += " " + child_form.Title()
         return label
     if action_id == "delete":
         return PlominoTranslate("datagrid_delete_button_label", db)
     if action_id == "edit":
         return PlominoTranslate("datagrid_edit_button_label", db)
     return ""
Exemple #4
0
    def header(self):
        """ Get the portlet header

        (translated if db i18n domain if defined)
        """
        header = self.data.header

        db = self.context.restrictedTraverse(self.data.db_path.encode(), None)
        i18n_domain = db.getI18n()
        if i18n_domain:
            header = PlominoTranslate(header, db, domain=i18n_domain)
        return header