198 value = self.get_value(rtype) |
198 value = self.get_value(rtype) |
199 # do not restrict to `unicode` because Bytes will return a `str` value |
199 # do not restrict to `unicode` because Bytes will return a `str` value |
200 if isinstance(value, basestring): |
200 if isinstance(value, basestring): |
201 return self.printable_value(rtype, format='text/plain').lower() |
201 return self.printable_value(rtype, format='text/plain').lower() |
202 return value |
202 return value |
203 |
|
204 def add_related_schemas(self): |
|
205 """this is actually used ui method to generate 'addrelated' actions from |
|
206 the schema. |
|
207 |
|
208 If you're using explicit 'addrelated' actions for an entity types, you |
|
209 should probably overrides this method to return an empty list else you |
|
210 may get some unexpected actions. |
|
211 """ |
|
212 req = self.req |
|
213 eschema = self.e_schema |
|
214 for role, rschemas in (('subject', eschema.subject_relations()), |
|
215 ('object', eschema.object_relations())): |
|
216 for rschema in rschemas: |
|
217 if rschema.is_final(): |
|
218 continue |
|
219 # check the relation can be added as well |
|
220 if role == 'subject'and not rschema.has_perm(req, 'add', fromeid=self.eid): |
|
221 continue |
|
222 if role == 'object'and not rschema.has_perm(req, 'add', toeid=self.eid): |
|
223 continue |
|
224 # check the target types can be added as well |
|
225 for teschema in rschema.targets(eschema, role): |
|
226 if not self.relation_mode(rschema, teschema, role) == 'create': |
|
227 continue |
|
228 if teschema.has_local_role('add') or teschema.has_perm(req, 'add'): |
|
229 yield rschema, teschema, role |
|
230 |
|
231 def relation_mode(self, rtype, targettype, role='subject'): |
|
232 """return a string telling if the given relation is usually created |
|
233 to a new entity ('create' mode) or to an existant entity ('link' mode) |
|
234 """ |
|
235 return self.rtags.get_mode(rtype, targettype, role) |
|
236 |
203 |
237 # edition helper functions ################################################ |
204 # edition helper functions ################################################ |
238 |
205 |
239 def linked_to(self, rtype, target, remove=True): |
206 def linked_to(self, rtype, target, remove=True): |
240 """if entity should be linked to another using __linkto form param for |
207 """if entity should be linked to another using __linkto form param for |