[gen] Bugfixes: handle multilingual titles in queries, references, breadcrumbs...
This commit is contained in:
		
							parent
							
								
									f8a7103c7a
								
							
						
					
					
						commit
						8aed007623
					
				
					 6 changed files with 34 additions and 6 deletions
				
			
		|  | @ -542,6 +542,13 @@ class Field: | |||
|         if self.isEmptyValue(obj, value): return '' | ||||
|         return value | ||||
| 
 | ||||
|     def getShownValue(self, obj, value, showChanges=False): | ||||
|         '''Similar to m_getFormattedValue, but in some contexts, only a part of | ||||
|            p_value must be shown. For example, sometimes we need to display only | ||||
|            a language-specific part of a multilingual field (see overridden | ||||
|            method in string.py).''' | ||||
|         return self.getFormattedValue(obj, value, showChanges) | ||||
| 
 | ||||
|     def getIndexType(self): | ||||
|         '''Returns the name of the technical, Zope-level index type for this | ||||
|            field.''' | ||||
|  |  | |||
|  | @ -50,7 +50,7 @@ class Ref(Field): | |||
|                                     inPopup=linkInPopup)" | ||||
|          href=":fullUrl" class=":cssClass" target=":target.target" | ||||
|          onclick=":target.openPopup">:(not includeShownInfo) and \ | ||||
|          tied.title or field.getReferenceLabel(tied) | ||||
|          tied.o.getShownValue('title') or field.getReferenceLabel(tied) | ||||
|       </a><span name="subTitle" style=":showSubTitles and 'display:inline' or \ | ||||
|             'display:none'">::tied.o.getSubTitle()</span></x>''') | ||||
| 
 | ||||
|  | @ -1237,7 +1237,7 @@ class Ref(Field): | |||
|         for fieldName in self.shownInfo: | ||||
|             refType = refObject.o.getAppyType(fieldName) | ||||
|             value = getattr(refObject, fieldName) | ||||
|             value = refType.getFormattedValue(refObject.o, value) | ||||
|             value = refType.getShownValue(refObject.o, value) | ||||
|             if refType.type == 'String': | ||||
|                 if refType.format == 2: | ||||
|                     value = self.xhtmlToText.sub(' ', value) | ||||
|  |  | |||
|  | @ -632,6 +632,20 @@ class String(Field): | |||
|                                                        showChanges, lg) | ||||
|         return res | ||||
| 
 | ||||
|     def getShownValue(self, obj, value, showChanges=False): | ||||
|         '''For a multilingual field, this method only shows one specific | ||||
|            language part.''' | ||||
|         languages = self.getAttribute(obj, 'languages') | ||||
|         if len(languages) == 1: | ||||
|             return self.getUnilingualFormattedValue(obj, value, showChanges) | ||||
|         if not value: return value | ||||
|         # Try to propose the part that is in the user language, or the part of | ||||
|         # the first content language else. | ||||
|         language = obj.getUserLanguage() | ||||
|         if language not in value: language = languages[0] | ||||
|         return self.getUnilingualFormattedValue(obj, value[language], | ||||
|                                                 showChanges, language) | ||||
| 
 | ||||
|     def extractText(self, value): | ||||
|         '''Extracts pure text from XHTML p_value.''' | ||||
|         return XhtmlTextExtractor(raiseOnError=False).parse('<p>%s</p>' % value) | ||||
|  |  | |||
|  | @ -71,7 +71,8 @@ class Migrator: | |||
|         '''Executes a migration when relevant, or do it for sure if p_force is | ||||
|            True.''' | ||||
|         appyVersion = self.tool.appyVersion | ||||
|         if force or not appyVersion or (appyVersion < '0.9.0'): | ||||
|         # appyVersion being None simply means that we are creating a new DB. | ||||
|         if force or (appyVersion and (appyVersion < '0.9.0')): | ||||
|             # Migration is required. | ||||
|             self.logger.info('Appy version (DB) is %s' % appyVersion) | ||||
|             startTime = time.time() | ||||
|  |  | |||
|  | @ -1298,7 +1298,7 @@ class BaseMixin: | |||
|     def Title(self): | ||||
|         '''Returns the title for this object.''' | ||||
|         title = self.getAppyType('title') | ||||
|         if title: return title.getValue(self) | ||||
|         if title: return title.getIndexValue(self) | ||||
|         return self.id | ||||
| 
 | ||||
|     def SortableTitle(self): | ||||
|  | @ -1468,6 +1468,11 @@ class BaseMixin: | |||
|             return False | ||||
|         if parent.meta_type not in ('Folder', 'Temporary Folder'): return parent | ||||
| 
 | ||||
|     def getShownValue(self, name): | ||||
|         '''Call field.getShownValue on field named p_name.''' | ||||
|         field = self.getAppyType('title') | ||||
|         return field.getShownValue(self, field.getValue(self)) | ||||
| 
 | ||||
|     def getBreadCrumb(self, inPopup=False): | ||||
|         '''Gets breadcrumb info about this object and its parents (if it must | ||||
|            be shown).''' | ||||
|  | @ -1475,8 +1480,9 @@ class BaseMixin: | |||
|         klass = self.getClass() | ||||
|         if hasattr(klass, 'breadcrumb') and not klass.breadcrumb: return () | ||||
|         # Compute the breadcrumb | ||||
|         title = self.getAppyType('title') | ||||
|         res = [Object(url=self.getUrl(inPopup=inPopup), | ||||
|                       title=self.getFieldValue('title', layoutType='view'))] | ||||
|                       title=title.getShownValue(self, title.getValue(self)))] | ||||
|         # In a popup: limit the breadcrumb to the current object. | ||||
|         if inPopup: return res | ||||
|         parent = self.getParent() | ||||
|  |  | |||
|  | @ -322,7 +322,7 @@ class ToolWrapper(AbstractWrapper): | |||
|           var2="linkInPopup=inPopup or (target.target != '_self')" | ||||
|           target=":target.target" onclick=":target.openPopup" | ||||
|           href=":zobj.getUrl(nav=navInfo, page=zobj.getDefaultViewPage(), \ | ||||
|                  inPopup=linkInPopup)">:zobj.Title()</a> | ||||
|                  inPopup=linkInPopup)">:zobj.getShownValue('title')</a> | ||||
|        <span if="not enableLinks" | ||||
|              class=":not checkboxes and cssClass or ('%s clickable' % cssClass)" | ||||
|              onclick=":checkboxes and ('onSelectObject(%s,%s,%s)' % (q(cbId), \ | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Gaetan Delannay
						Gaetan Delannay