def getTitle(self, normalized=False): '''Returns a nice name for this user, based on available information: name/first name or title or login. If p_normalized is True, special chars (like accents) are converted to ascii chars.''' # Manage the special case of an anonymous user. login = self.login if login == 'anon': res = self.translate('anonymous') else: res = self.title or login if not normalized: return res return sutils.normalizeString(name)
def applyTransform(self, value): '''Applies a transform as required by self.transform on single value p_value.''' if self.transform in ('uppercase', 'lowercase'): # For those transforms, I will remove any accent, because, most of # the time, if the user wants to apply such effect, it is for ease # of data manipulation, so I guess without accent. value = sutils.normalizeString(value, usage='noAccents') # Apply the transform if self.transform == 'lowercase': return value.lower() elif self.transform == 'uppercase': return value.upper() elif self.transform == 'capitalize': return value.capitalize() return value
def dump(self, filePath=None, format=None, tool=None): '''Writes the file on disk. If p_filePath is specified, it is the path name where the file will be dumped; folders mentioned in it must exist. If not, the file will be dumped in the OS temp folder. The absolute path name of the dumped file is returned. If an error occurs, the method returns None. If p_format is specified, OpenOffice will be called for converting the dumped file to the desired format. In this case, p_tool, a Appy tool, must be provided. Indeed, any Appy tool contains parameters for contacting OpenOffice in server mode.''' if not filePath: filePath = '%s/file%f.%s' % (getOsTempFolder(), time.time(), normalizeString(self.name)) f = file(filePath, 'w') if self.content.__class__.__name__ == 'Pdata': # The file content is splitted in several chunks. f.write(self.content.data) nextPart = self.content.next while nextPart: f.write(nextPart.data) nextPart = nextPart.next else: # Only one chunk f.write(self.content) f.close() if format: if not tool: return # Convert the dumped file using OpenOffice errorMessage = tool.convert(filePath, format) # Even if we have an "error" message, it could be a simple warning. # So we will continue here and, as a subsequent check for knowing if # an error occurred or not, we will test the existence of the # converted file (see below). os.remove(filePath) # Return the name of the converted file. baseName, ext = os.path.splitext(filePath) if (ext == '.%s' % format): filePath = '%s.res.%s' % (baseName, format) else: filePath = '%s.%s' % (baseName, format) if not os.path.exists(filePath): tool.log(CONVERSION_ERROR % (cmd, errorMessage), type='error') return return filePath
def getTitle(self, normalized=False, useName=True, nameFirst=False): '''Returns a nice name for this user, based on available information: "first name"/"name" (if p_useName is True) or title or login. If p_normalized is True, special chars (like accents) are converted to ascii chars. When p_useName is True, if p_nameFirst is True, the result will be "name" / "first name", else it will be "first name" / "name".''' # Manage the special case of an anonymous user login = self.login if login == 'anon': res = self.translate('anonymous') else: res = None if useName: firstName = self.firstName name = self.name if firstName and name: if nameFirst: res = '%s %s' % (name, firstName) else: res = '%s %s' % (firstName, name) if not res: res = self.title or login if not normalized: return res return sutils.normalizeString(name)
def getValue(self, obj): '''The "value" of the Ogone field is a dict that collects all the necessary info for making the payment.''' tool = obj.getTool() # Basic Ogone parameters were generated in the app config module. res = obj.getProductConfig().ogone.copy() shaKey = res['shaInKey'] # Remove elements from the Ogone config that we must not send in the # payment request. del res['shaInKey'] del res['shaOutKey'] res.update(self.callMethod(obj, self.orderMethod)) # Add user-related information res['CN'] = str(normalizeString(tool.getUserName())) user = obj.appy().appyUser res['EMAIL'] = user.email or user.login # Add standard back URLs siteUrl = tool.getSiteUrl() res['catalogurl'] = siteUrl res['homeurl'] = siteUrl # Add redirect URLs for t in self.urlTypes: res['%surl' % t] = '%s/onProcess' % obj.absolute_url() # Add additional parameter that we want Ogone to give use back in all # of its responses: the name of this Appy Ogone field. This way, Appy # will be able to call method m_process below, that will process # Ogone's response. res['paramplus'] = 'name=%s' % self.name # Ensure every value is a str for k in res.iterkeys(): if not isinstance(res[k], str): res[k] = str(res[k]) # Compute a SHA-1 key as required by Ogone and add it to the res res['SHASign'] = self.createShaDigest(res, shaKey, keysToIgnore=self.noShaInKeys) return res
def normalize(self, s, usage="fileName"): """Returns a version of string p_s whose special chars have been replaced with normal chars.""" return normalizeString(s, usage)
def normalize(self, s, usage='fileName'): '''Returns a version of string p_s whose special chars have been replaced with normal chars.''' return normalizeString(s, usage)