| @@ 127-156 (lines=30) @@ | ||
| 124 | # just to be sure (paranoid) |
|
| 125 | return [uid for uid in value if api.is_uid(uid)] |
|
| 126 | ||
| 127 | def get_render_data(self, uid): |
|
| 128 | """Provides the needed data to render the display template from the UID |
|
| 129 | ||
| 130 | :returns: Dictionary with data needed to render the display template |
|
| 131 | """ |
|
| 132 | regex = r"\{(.*?)\}" |
|
| 133 | context = self.get_context() |
|
| 134 | template = self.get_display_template(context, self.field) |
|
| 135 | names = re.findall(regex, template) |
|
| 136 | ||
| 137 | try: |
|
| 138 | obj = api.get_object(uid) |
|
| 139 | except api.APIError: |
|
| 140 | logger.error("No object found for UID {}".format(uid)) |
|
| 141 | return None |
|
| 142 | ||
| 143 | data = { |
|
| 144 | "uid": api.get_uid(obj), |
|
| 145 | "url": api.get_url(obj), |
|
| 146 | "Title": api.get_title(obj), |
|
| 147 | "Description": api.get_description(obj), |
|
| 148 | } |
|
| 149 | for name in names: |
|
| 150 | if name not in data: |
|
| 151 | value = getattr(obj, name, None) |
|
| 152 | if callable(value): |
|
| 153 | value = value() |
|
| 154 | data[name] = value |
|
| 155 | ||
| 156 | return data |
|
| 157 | ||
| 158 | ||
| 159 | @adapter(IUIDReferenceField, ISenaiteFormLayer) |
|
| @@ 269-296 (lines=28) @@ | ||
| 266 | value = [value] |
|
| 267 | return map(api.get_uid, value) |
|
| 268 | ||
| 269 | def get_render_data(self, uid, template): |
|
| 270 | """Provides the needed data to render the display template from the UID |
|
| 271 | ||
| 272 | :returns: Dictionary with data needed to render the display template |
|
| 273 | """ |
|
| 274 | regex = r"\{(.*?)\}" |
|
| 275 | names = re.findall(regex, template) |
|
| 276 | ||
| 277 | try: |
|
| 278 | obj = api.get_object(uid) |
|
| 279 | except api.APIError: |
|
| 280 | logger.error("No object found for UID {}".format(uid)) |
|
| 281 | return None |
|
| 282 | ||
| 283 | data = { |
|
| 284 | "uid": api.get_uid(obj), |
|
| 285 | "url": api.get_url(obj), |
|
| 286 | "Title": api.get_title(obj), |
|
| 287 | "Description": api.get_description(obj), |
|
| 288 | } |
|
| 289 | for name in names: |
|
| 290 | if name not in data: |
|
| 291 | value = getattr(obj, name, None) |
|
| 292 | if callable(value): |
|
| 293 | value = value() |
|
| 294 | data[name] = value |
|
| 295 | ||
| 296 | return data |
|
| 297 | ||
| 298 | def render_reference(self, context, field, uid): |
|
| 299 | """Returns a rendered HTML element for the reference |
|