def get_recipients(self):
<EOL>User = get_user_model()<EOL>emails = []<EOL>if not self.is_filtered:<EOL><INDENT>users = User.objects.filter(is_active=True).only('<STR_LIT:email>')<EOL>for user in users:<EOL><INDENT>if user.email not in emails:<EOL><INDENT>emails += [user.email]<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>if FILTERS.get('<STR_LIT>') in self.filters:<EOL><INDENT>users = self.users.all().only('<STR_LIT:email>')<EOL>for user in users:<EOL><INDENT>if user.email not in emails:<EOL><INDENT>emails += [user.email]<EOL><DEDENT><DEDENT><DEDENT>q = Q()<EOL>q2 = Q()<EOL>if FILTERS.get('<STR_LIT>') in self.filters:<EOL><INDENT>for group in self.groups:<EOL><INDENT>if group != '<STR_LIT:0>':<EOL><INDENT>q = q | Q(groups=int(group))<EOL>q2 = q2 | Q(user__groups=int(group))<EOL><DEDENT>else:<EOL><INDENT>q = q | Q(is_superuser=True)<EOL>q2 = q2 | Q(user__is_superuser=True)<EOL><DEDENT><DEDENT><DEDENT>q = q & Q(is_active=True)<EOL>if FILTERS.get('<STR_LIT>') in self.filters:<EOL><INDENT>layers = self.layers.all().only('<STR_LIT:id>')<EOL>q3 = Q()<EOL>for layer in layers:<EOL><INDENT>q3 = q3 | Q(layer=layer)<EOL><DEDENT>nodes = Node.objects.filter(q2 & q3)<EOL>for node in nodes:<EOL><INDENT>if node.user.email not in emails:<EOL><INDENT>emails += [node.user.email]<EOL><DEDENT><DEDENT><DEDENT>elif FILTERS.get('<STR_LIT>') in self.filters and not FILTERS.get('<STR_LIT>') in self.filters:<EOL><INDENT>users = User.objects.filter(q).only('<STR_LIT:email>')<EOL>for user in users:<EOL><INDENT>if user.email not in emails:<EOL><INDENT>emails += [user.email]<EOL><DEDENT><DEDENT><DEDENT><DEDENT>return emails<EOL>
Determine recipients depending on selected filtering which can be either:
    * group based
    * layer based
    * user based

Choosing "group" and "layer" filtering together has the effect of sending the message
only to users for which the following conditions are both true:
    * have a node assigned to one of the selected layers
    * are part of any of the specified groups (eg: registered, community, trusted)

The user based filtering has instead the effect of translating in an **OR** query. Here's a practical example:
if selecting "group" and "user" filtering the message will be sent to all the users for which ANY of the following conditions is true:
    * are part of any of the specified groups (eg: registered, community, trusted)
    * selected users