You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@bloodhound.apache.org by Anže Starič <an...@gmail.com> on 2014/03/06 09:55:21 UTC
Re: svn commit: r1574802 - in /bloodhound/trunk/bloodhound_relations/bhrelations:
tests/api.py validation.py
2014-03-06 9:47 GMT+01:00 <rj...@apache.org>:
> class OneToManyValidator(Validator):
> + """Only tree relationships are allowed. A ticket cannot have multiple
> + parents."""
> def validate(self, relation):
> rls = RelationsSystem(self.env)
> - existing_relations = rls._select_relations(relation.source,
> - relation.type)
> + if relation.type != rls.PARENT_RELATION_TYPE:
> + return
> + existing_relations = rls._select_relations(relation.destination,
> + rls.CHILDREN_RELATION_TYPE)
I would prefer something like:
- existing_relations = rls._select_relations(relation.source,
- relation.type)
+ existing_relations = rls._select_relations(type=relation.type,
+
destination=relation.destination)
(and modified select_relations method so it can also filter by destination).
This way, validator would remain reusable.
Re: svn commit: r1574802 - in /bloodhound/trunk/bloodhound_relations/bhrelations:
tests/api.py validation.py
Posted by Anže Starič <an...@gmail.com>.
OneToMany validator can be added to any relation in the config. And it
is always called with the master relation (even when you create a
child relation, validator will be called with the parent relation), so
I do no not think that any relation type checking is required.
2014-03-06 10:07 GMT+01:00 Ryan Ollos <ry...@wandisco.com>:
> On Thu, Mar 6, 2014 at 12:55 AM, Anže Starič <an...@gmail.com> wrote:
>
>> 2014-03-06 9:47 GMT+01:00 <rj...@apache.org>:
>> > class OneToManyValidator(Validator):
>> > + """Only tree relationships are allowed. A ticket cannot have
>> multiple
>> > + parents."""
>> > def validate(self, relation):
>> > rls = RelationsSystem(self.env)
>> > - existing_relations = rls._select_relations(relation.source,
>> > - relation.type)
>> > + if relation.type != rls.PARENT_RELATION_TYPE:
>> > + return
>> > + existing_relations = rls._select_relations(relation.destination,
>> > +
>> rls.CHILDREN_RELATION_TYPE)
>>
>> I would prefer something like:
>>
>> - existing_relations = rls._select_relations(relation.source,
>> - relation.type)
>> + existing_relations = rls._select_relations(type=relation.type,
>> +
>> destination=relation.destination)
>>
>> (and modified select_relations method so it can also filter by
>> destination).
>> This way, validator would remain reusable.
>>
>
> That does seem more clear. I wasn't very happy with the inverted logic, but
> I didn't look at the possibility of changing _select_relations. I won't
> complain if you refactor my changes ;)
>
> In what contexts do you see it being reusable? Do you plan to extract
> rls.PARENT_RELATION_TYPE to a class variable, or in some way make
> OneToManyValidator usable as a base class?
Re: svn commit: r1574802 - in /bloodhound/trunk/bloodhound_relations/bhrelations:
tests/api.py validation.py
Posted by Ryan Ollos <ry...@wandisco.com>.
On Thu, Mar 6, 2014 at 12:55 AM, Anže Starič <an...@gmail.com> wrote:
> 2014-03-06 9:47 GMT+01:00 <rj...@apache.org>:
> > class OneToManyValidator(Validator):
> > + """Only tree relationships are allowed. A ticket cannot have
> multiple
> > + parents."""
> > def validate(self, relation):
> > rls = RelationsSystem(self.env)
> > - existing_relations = rls._select_relations(relation.source,
> > - relation.type)
> > + if relation.type != rls.PARENT_RELATION_TYPE:
> > + return
> > + existing_relations = rls._select_relations(relation.destination,
> > +
> rls.CHILDREN_RELATION_TYPE)
>
> I would prefer something like:
>
> - existing_relations = rls._select_relations(relation.source,
> - relation.type)
> + existing_relations = rls._select_relations(type=relation.type,
> +
> destination=relation.destination)
>
> (and modified select_relations method so it can also filter by
> destination).
> This way, validator would remain reusable.
>
That does seem more clear. I wasn't very happy with the inverted logic, but
I didn't look at the possibility of changing _select_relations. I won't
complain if you refactor my changes ;)
In what contexts do you see it being reusable? Do you plan to extract
rls.PARENT_RELATION_TYPE to a class variable, or in some way make
OneToManyValidator usable as a base class?