81 value = getattr(base, attr) |
81 value = getattr(base, attr) |
82 delattr(base, attr) |
82 delattr(base, attr) |
83 yield base.__name__, value |
83 yield base.__name__, value |
84 except AttributeError: |
84 except AttributeError: |
85 continue |
85 continue |
|
86 |
86 |
87 |
87 class _metaentity(type): |
88 class _metaentity(type): |
88 """this metaclass sets the relation tags on the entity class |
89 """this metaclass sets the relation tags on the entity class |
89 and deals with the `widgets` attribute |
90 and deals with the `widgets` attribute |
90 """ |
91 """ |
719 rql = '%s ORDERBY Z DESC WHERE X modification_date Z, %s' % args |
720 rql = '%s ORDERBY Z DESC WHERE X modification_date Z, %s' % args |
720 return rql |
721 return rql |
721 |
722 |
722 # generic vocabulary methods ############################################## |
723 # generic vocabulary methods ############################################## |
723 |
724 |
724 @deprecated('see new form api') |
|
725 def vocabulary(self, rtype, role='subject', limit=None): |
|
726 """vocabulary functions must return a list of couples |
|
727 (label, eid) that will typically be used to fill the |
|
728 edition view's combobox. |
|
729 |
|
730 If `eid` is None in one of these couples, it should be |
|
731 interpreted as a separator in case vocabulary results are grouped |
|
732 """ |
|
733 from logilab.common.testlib import mock_object |
|
734 form = self.vreg.select('forms', 'edition', self.req, entity=self) |
|
735 field = mock_object(name=rtype, role=role) |
|
736 return form.form_field_vocabulary(field, limit) |
|
737 |
|
738 def unrelated_rql(self, rtype, targettype, role, ordermethod=None, |
725 def unrelated_rql(self, rtype, targettype, role, ordermethod=None, |
739 vocabconstraints=True): |
726 vocabconstraints=True): |
740 """build a rql to fetch `targettype` entities unrelated to this entity |
727 """build a rql to fetch `targettype` entities unrelated to this entity |
741 using (rtype, role) relation. |
728 using (rtype, role) relation. |
742 |
729 |
801 except Unauthorized: |
788 except Unauthorized: |
802 return self.req.empty_rset() |
789 return self.req.empty_rset() |
803 if limit is not None: |
790 if limit is not None: |
804 before, after = rql.split(' WHERE ', 1) |
791 before, after = rql.split(' WHERE ', 1) |
805 rql = '%s LIMIT %s WHERE %s' % (before, limit, after) |
792 rql = '%s LIMIT %s WHERE %s' % (before, limit, after) |
806 return self.req.execute(rql, args, tuple(args.keys())) |
793 return self.req.execute(rql, args, tuple(args)) |
807 |
794 |
808 # relations cache handling ################################################ |
795 # relations cache handling ################################################ |
809 |
796 |
810 def relation_cached(self, rtype, role): |
797 def relation_cached(self, rtype, role): |
811 """return true if the given relation is already cached on the instance |
798 """return true if the given relation is already cached on the instance |
957 else: # if role == 'object': |
944 else: # if role == 'object': |
958 for entity in getattr(self, 'reverse_%s' % rschema.type): |
945 for entity in getattr(self, 'reverse_%s' % rschema.type): |
959 words += entity.get_words() |
946 words += entity.get_words() |
960 return words |
947 return words |
961 |
948 |
|
949 @deprecated('[3.2] see new form api') |
|
950 def vocabulary(self, rtype, role='subject', limit=None): |
|
951 """vocabulary functions must return a list of couples |
|
952 (label, eid) that will typically be used to fill the |
|
953 edition view's combobox. |
|
954 |
|
955 If `eid` is None in one of these couples, it should be |
|
956 interpreted as a separator in case vocabulary results are grouped |
|
957 """ |
|
958 from logilab.common.testlib import mock_object |
|
959 form = self.vreg.select('forms', 'edition', self.req, entity=self) |
|
960 field = mock_object(name=rtype, role=role) |
|
961 return form.form_field_vocabulary(field, limit) |
|
962 |
962 |
963 |
963 # attribute and relation descriptors ########################################## |
964 # attribute and relation descriptors ########################################## |
964 |
965 |
965 class Attribute(object): |
966 class Attribute(object): |
966 """descriptor that controls schema attribute access""" |
967 """descriptor that controls schema attribute access""" |