Changeset 2278 in products for quintagroup.referencedatagridfield/trunk/quintagroup/referencedatagridfield/_field.py
- Timestamp:
- May 10, 2010 1:17:31 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
quintagroup.referencedatagridfield/trunk/quintagroup/referencedatagridfield/_field.py
r2276 r2278 28 28 _properties.update({ 29 29 'macro': "referencedatagridwidget", 30 'column_names': [ 'Title', 'Link or UID'],30 'column_names': ["Title", "Link", "UID"], 31 31 'helper_css': ('datagridwidget.css',), 32 32 'helper_js': ('referencebrowser.js', 'datagridwidget.js',), … … 40 40 _properties.update(DataGridField._properties.copy()) 41 41 _properties.update({ 42 'columns': ('title', 'link _uid'),42 'columns': ('title', 'link', 'uid'), 43 43 'widget': ReferenceDataGridWidget, 44 44 'multiValued' : True, … … 55 55 """ 56 56 The passed in object should be a records object, or a sequence of dictionaries 57 About link _uiddata:57 About link data: 58 58 * interpretations: 59 * if data not starts with standard protocol names (http://, ftp://) it treats60 as UID59 * if data not starts with standard protocol names (http://, ftp://) than 60 *uid* field data will be used as reference 61 61 * record removed if: 62 62 * no data; 63 63 * data contains UID of not existent object 64 64 About title: 65 * if there is UID of existent object and record has not title data66 - object's Title will be used.65 * if there is UID of existent object and record has same title to the original 66 object - title will not be saved. 67 67 """ 68 68 catalog = getToolByName(instance, "uid_catalog") … … 74 74 value = value, 75 75 76 uids = []77 76 result = [] 78 77 for row in value: 79 data = {"title":"", "link _uid":""}78 data = {"title":"", "link":"", "uid":""} 80 79 80 uid = str(row.get("uid", "")).strip() 81 link = str(row.get("link", "")).strip() 81 82 title = str(row.get('title', "")).strip() 83 82 84 if not title == "": 83 85 data["title"] = title 84 86 85 link_uid = str(row.get('link_uid', "")).strip() 86 if link_uid == '': 87 if link == "": 87 88 continue 88 elif self.isRemoteURL(link _uid):89 data["link _uid"] = urlparse.urlunparse(urlparse.urlparse(link_uid))89 elif self.isRemoteURL(link): 90 data["link"] = urlparse.urlunparse(urlparse.urlparse(link)) 90 91 else: 91 brains = catalog(UID=link_uid) 92 if uid == '': 93 continue 94 95 brains = catalog(UID=uid) 92 96 if len(brains) == 0: 93 97 continue 94 98 # Found objects with pointed UID 95 uids.append(link_uid)96 99 brain = brains[0] 97 data["link_uid"] = link_uid 100 data["uid"] = uid 101 # Fix title for uid 102 if data['title'] == getattr(brain, "Title", ""): 103 data['title'] = "" 98 104 result.append(data) 99 105 100 106 DataGridField.set(self, instance, result, **kwargs) 107 108 uids = [r['uid'] for r in result if r['uid']!=""] 101 109 ReferenceField.set(self, instance, uids, **kwargs) 102 110 … … 106 114 107 115 Value is a list object of rows. 108 Row id dictionary object with standard 'link _uid' and 'title' keys109 plus extra informal * isLink* key116 Row id dictionary object with standard 'link', 'uid' and 'title' keys 117 plus extra informal *url* and *url_title* keys 110 118 """ 111 119 purl = getToolByName(instance, "portal_url") 120 # use portal_catalog to hide protected object for the logged in user. 112 121 catalog = getToolByName(instance, "portal_catalog") 113 122 … … 118 127 result.append({ 119 128 # DataGridField row data 129 "uid": row["uid"], 130 "link": row["link"], 120 131 "title": row["title"], 121 "link_uid": row["link_uid"],122 132 # View data 123 " link": "",124 " link_title": row["title"]})133 "url": "", 134 "url_title": row["title"]}) 125 135 data = result[-1] 126 136 # Process remote URL and collect UIDs 127 link_uid = row["link_uid"] 128 if self.isRemoteURL(link_uid): 129 data["link"] = quote(link_uid, safe='?$#@/:=+;$,&%') 137 if row["link"]: 138 data["url"] = quote(row["link"], safe='?$#@/:=+;$,&%') 130 139 # if title not set for remote url - set it equals to url 131 if not data[" link_title"]:132 data[" link_title"] = link_uid140 if not data["url_title"]: 141 data["url_title"] = row["link"] 133 142 else: 134 uids[ link_uid] = data143 uids[row["uid"]] = data 135 144 # Process UIDs 136 145 if uids: … … 138 147 for b in brains: 139 148 data = uids[b.UID] 140 data[" link"] = b.getURL()149 data["url"] = b.getURL() 141 150 # If title not set - get it from the brain 142 if not data[" link_title"]:143 data[" link_title"] = self._brains_title_or_id(b, instance)151 if not data["url_title"]: 152 data["url_title"] = self._brains_title_or_id(b, instance) 144 153 145 154 return result
Note: See TracChangeset
for help on using the changeset viewer.