804 choices = sorted(choices) |
804 choices = sorted(choices) |
805 if self.rschema.rproperty(self.subjtype, self.objtype, 'internationalizable'): |
805 if self.rschema.rproperty(self.subjtype, self.objtype, 'internationalizable'): |
806 return zip((entity.req._(v) for v in choices), choices) |
806 return zip((entity.req._(v) for v in choices), choices) |
807 return zip(choices, choices) |
807 return zip(choices, choices) |
808 |
808 |
|
809 def subject_relation_vocabulary(self, rtype, limit=None): |
|
810 """defaut vocabulary method for the given relation, looking for |
|
811 relation's object entities (i.e. self is the subject) |
|
812 """ |
|
813 entity = self.entity |
|
814 if isinstance(rtype, basestring): |
|
815 rtype = entity.schema.rschema(rtype) |
|
816 done = None |
|
817 assert not rtype.is_final(), rtype |
|
818 if entity.has_eid(): |
|
819 done = set(e.eid for e in getattr(entity, str(rtype))) |
|
820 result = [] |
|
821 rsetsize = None |
|
822 for objtype in rtype.objects(entity.e_schema): |
|
823 if limit is not None: |
|
824 rsetsize = limit - len(result) |
|
825 result += self.relation_vocabulary(rtype, objtype, 'subject', |
|
826 rsetsize, done) |
|
827 if limit is not None and len(result) >= limit: |
|
828 break |
|
829 return result |
|
830 |
|
831 def object_relation_vocabulary(self, rtype, limit=None): |
|
832 """defaut vocabulary method for the given relation, looking for |
|
833 relation's subject entities (i.e. self is the object) |
|
834 """ |
|
835 entity = self.entity |
|
836 if isinstance(rtype, basestring): |
|
837 rtype = entity.schema.rschema(rtype) |
|
838 done = None |
|
839 if entity.has_eid(): |
|
840 done = set(e.eid for e in getattr(entity, 'reverse_%s' % rtype)) |
|
841 result = [] |
|
842 rsetsize = None |
|
843 for subjtype in rtype.subjects(entity.e_schema): |
|
844 if limit is not None: |
|
845 rsetsize = limit - len(result) |
|
846 result += self.relation_vocabulary(rtype, subjtype, 'object', |
|
847 rsetsize, done) |
|
848 if limit is not None and len(result) >= limit: |
|
849 break |
|
850 return result |
|
851 |
|
852 def relation_vocabulary(self, rtype, targettype, role, |
|
853 limit=None, done=None): |
|
854 if done is None: |
|
855 done = set() |
|
856 req = self.req |
|
857 rset = entity.unrelated(rtype, targettype, role, limit) |
|
858 res = [] |
|
859 for entity in rset.entities(): |
|
860 if entity.eid in done: |
|
861 continue |
|
862 done.add(entity.eid) |
|
863 res.append((entity.view('combobox'), entity.eid)) |
|
864 return res |
|
865 |
|
866 |
809 |
867 |
810 class MultipleFieldsForm(FieldsForm): |
868 class MultipleFieldsForm(FieldsForm): |
811 def __init__(self, *args, **kwargs): |
869 def __init__(self, *args, **kwargs): |
812 super(MultipleFieldsForm, self).__init__(*args, **kwargs) |
870 super(MultipleFieldsForm, self).__init__(*args, **kwargs) |
813 self.forms = [] |
871 self.forms = [] |