appy.gen: added default validation for wrong dates; for Action fields, added value 'filetmp' for param 'result' for removing temp files that are returned as the result of an action; values entered by the user in the search screens are not stripped; wrapper method 'export' can now export an object in a CSV file; appy.pod: bullets for default list styles in any ODT file generated through pod are now smaller.
This commit is contained in:
		
							parent
							
								
									9f418439aa
								
							
						
					
					
						commit
						39d68f6490
					
				
					 13 changed files with 787 additions and 628 deletions
				
			
		| 
						 | 
				
			
			@ -509,7 +509,7 @@ class ToolMixin(BaseMixin):
 | 
			
		|||
            if not importPath: continue
 | 
			
		||||
            objectId = os.path.basename(importPath)
 | 
			
		||||
            self.appy().create(appyClass, id=objectId, _data=importPath)
 | 
			
		||||
        self.plone_utils.addPortalMessage(self.translate('import_done'))
 | 
			
		||||
        self.say(self.translate('import_done'))
 | 
			
		||||
        return self.goto(rq['HTTP_REFERER'])
 | 
			
		||||
 | 
			
		||||
    def isAlreadyImported(self, contentType, importPath):
 | 
			
		||||
| 
						 | 
				
			
			@ -584,13 +584,14 @@ class ToolMixin(BaseMixin):
 | 
			
		|||
                # given field.
 | 
			
		||||
                attrValue = rq.form[attrName]
 | 
			
		||||
                if attrName.find('*') != -1:
 | 
			
		||||
                    attrValue = attrValue.strip()
 | 
			
		||||
                    # The type of the value is encoded after char "*".
 | 
			
		||||
                    attrName, attrType = attrName.split('*')
 | 
			
		||||
                    if attrType == 'bool':
 | 
			
		||||
                        exec 'attrValue = %s' % attrValue
 | 
			
		||||
                    elif attrType in ('int', 'float'):
 | 
			
		||||
                        # Get the "from" value
 | 
			
		||||
                        if not attrValue.strip(): attrValue = None
 | 
			
		||||
                        if not attrValue: attrValue = None
 | 
			
		||||
                        else:
 | 
			
		||||
                            exec 'attrValue = %s(attrValue)' % attrType
 | 
			
		||||
                        # Get the "to" value
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -94,7 +94,7 @@ class BaseMixin:
 | 
			
		|||
            urlBack = self.getTool().getSiteUrl()
 | 
			
		||||
        else:
 | 
			
		||||
            urlBack = self.getUrl(rq['HTTP_REFERER'])
 | 
			
		||||
        self.plone_utils.addPortalMessage(self.translate('delete_done'))
 | 
			
		||||
        self.say(self.translate('delete_done'))
 | 
			
		||||
        self.goto(urlBack)
 | 
			
		||||
 | 
			
		||||
    def onCreate(self):
 | 
			
		||||
| 
						 | 
				
			
			@ -189,8 +189,7 @@ class BaseMixin:
 | 
			
		|||
                    urlBack = tool.getSiteUrl()
 | 
			
		||||
            else:
 | 
			
		||||
                urlBack = self.getUrl()
 | 
			
		||||
            self.plone_utils.addPortalMessage(
 | 
			
		||||
                self.translate('Changes canceled.', domain='plone'))
 | 
			
		||||
            self.say(self.translate('Changes canceled.', domain='plone'))
 | 
			
		||||
            return self.goto(urlBack)
 | 
			
		||||
 | 
			
		||||
        # Object for storing validation errors
 | 
			
		||||
| 
						 | 
				
			
			@ -202,7 +201,7 @@ class BaseMixin:
 | 
			
		|||
        self.intraFieldValidation(errors, values)
 | 
			
		||||
        if errors.__dict__:
 | 
			
		||||
            rq.set('errors', errors.__dict__)
 | 
			
		||||
            self.plone_utils.addPortalMessage(errorMessage)
 | 
			
		||||
            self.say(errorMessage)
 | 
			
		||||
            return self.skyn.edit(self)
 | 
			
		||||
 | 
			
		||||
        # Trigger inter-field validation
 | 
			
		||||
| 
						 | 
				
			
			@ -210,7 +209,7 @@ class BaseMixin:
 | 
			
		|||
        if not msg: msg = errorMessage
 | 
			
		||||
        if errors.__dict__:
 | 
			
		||||
            rq.set('errors', errors.__dict__)
 | 
			
		||||
            self.plone_utils.addPortalMessage(msg)
 | 
			
		||||
            self.say(msg)
 | 
			
		||||
            return self.skyn.edit(self)
 | 
			
		||||
 | 
			
		||||
        # Before saving data, must we ask a confirmation by the user ?
 | 
			
		||||
| 
						 | 
				
			
			@ -240,7 +239,7 @@ class BaseMixin:
 | 
			
		|||
            return self.goto(tool.getSiteUrl(), msg)
 | 
			
		||||
        if rq.get('buttonOk.x', None) or saveConfirmed:
 | 
			
		||||
            # Go to the consult view for this object
 | 
			
		||||
            obj.plone_utils.addPortalMessage(msg)
 | 
			
		||||
            obj.say(msg)
 | 
			
		||||
            return self.goto(obj.getUrl())
 | 
			
		||||
        if rq.get('buttonPrevious.x', None):
 | 
			
		||||
            # Go to the previous page for this object.
 | 
			
		||||
| 
						 | 
				
			
			@ -260,7 +259,7 @@ class BaseMixin:
 | 
			
		|||
                else:
 | 
			
		||||
                    return self.goto(obj.getUrl(page=pageName))
 | 
			
		||||
            else:
 | 
			
		||||
                obj.plone_utils.addPortalMessage(msg)
 | 
			
		||||
                obj.say(msg)
 | 
			
		||||
                return self.goto(obj.getUrl())
 | 
			
		||||
        if rq.get('buttonNext.x', None):
 | 
			
		||||
            # Go to the next page for this object
 | 
			
		||||
| 
						 | 
				
			
			@ -277,10 +276,30 @@ class BaseMixin:
 | 
			
		|||
                else:
 | 
			
		||||
                    return self.goto(obj.getUrl(page=pageName))
 | 
			
		||||
            else:
 | 
			
		||||
                obj.plone_utils.addPortalMessage(msg)
 | 
			
		||||
                obj.say(msg)
 | 
			
		||||
                return self.goto(obj.getUrl())
 | 
			
		||||
        return obj.skyn.edit(obj)
 | 
			
		||||
 | 
			
		||||
    def say(self, msg, type='info'):
 | 
			
		||||
        '''Prints a p_msg in the user interface. p_logLevel may be "info",
 | 
			
		||||
           "warning" or "error".'''
 | 
			
		||||
        mType = type
 | 
			
		||||
        if mType == 'warning': mType = 'warn'
 | 
			
		||||
        elif mType == 'error': mType = 'stop'
 | 
			
		||||
        try:
 | 
			
		||||
            self.plone_utils.addPortalMessage(msg, type=mType)
 | 
			
		||||
        except UnicodeDecodeError:
 | 
			
		||||
            self.plone_utils.addPortalMessage(msg.decode('utf-8'), type=mType)
 | 
			
		||||
 | 
			
		||||
    def log(self, msg, type='info'):
 | 
			
		||||
        '''Logs a p_msg in the log file. p_logLevel may be "info", "warning"
 | 
			
		||||
           or "error".'''
 | 
			
		||||
        logger = self.getProductConfig().logger
 | 
			
		||||
        if type == 'warning': logMethod = logger.warn
 | 
			
		||||
        elif type == 'error': logMethod = logger.error
 | 
			
		||||
        else: logMethod = logger.info
 | 
			
		||||
        logMethod(msg)
 | 
			
		||||
 | 
			
		||||
    def rememberPreviousData(self):
 | 
			
		||||
        '''This method is called before updating an object and remembers, for
 | 
			
		||||
           every historized field, the previous value. Result is a dict
 | 
			
		||||
| 
						 | 
				
			
			@ -880,16 +899,27 @@ class BaseMixin:
 | 
			
		|||
            label = '%s_action_%s' % (appyType.labelId, suffix)
 | 
			
		||||
            msg = self.translate(label)
 | 
			
		||||
        if (resultType == 'computation') or not successfull:
 | 
			
		||||
            self.plone_utils.addPortalMessage(msg)
 | 
			
		||||
            self.say(msg)
 | 
			
		||||
            return self.goto(self.getUrl(rq['HTTP_REFERER']))
 | 
			
		||||
        elif resultType == 'file':
 | 
			
		||||
        elif resultType.startswith('file'):
 | 
			
		||||
            # msg does not contain a message, but a file instance.
 | 
			
		||||
            response = self.REQUEST.RESPONSE
 | 
			
		||||
            response.setHeader('Content-Type',mimetypes.guess_type(msg.name)[0])
 | 
			
		||||
            response.setHeader('Content-Disposition', 'inline;filename="%s"' %\
 | 
			
		||||
                               msg.name)
 | 
			
		||||
                               os.path.basename(msg.name))
 | 
			
		||||
            response.write(msg.read())
 | 
			
		||||
            msg.close()
 | 
			
		||||
            if resultType == 'filetmp':
 | 
			
		||||
                # p_msg is a temp file. We need to delete it.
 | 
			
		||||
                try:
 | 
			
		||||
                    os.remove(msg.name)
 | 
			
		||||
                    self.log('Temp file "%s" was deleted.' % msg.name)
 | 
			
		||||
                except IOError, err:
 | 
			
		||||
                    self.log('Could not remove temp "%s" (%s).' % \
 | 
			
		||||
                             (msg.name, str(err)), type='warning')
 | 
			
		||||
                except OSError, err:
 | 
			
		||||
                    self.log('Could not remove temp "%s" (%s).' % \
 | 
			
		||||
                             (msg.name, str(err)), type='warning')
 | 
			
		||||
        elif resultType == 'redirect':
 | 
			
		||||
            # msg does not contain a message, but the URL where to redirect
 | 
			
		||||
            # the user.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue