def notify(self,
               recipients,
               notice_type,
               extra_context=None,
               subject=None,
               **kwargs):
        context = extra_context or dict()
        if subject:
            kwargs['sender'] = subject
            context['target'] = self
        else:
            kwargs['sender'] = self

        notify(recipients, notice_type, context, **kwargs)
Exemple #2
0
def invite(request, form, initiative, invite_type):
    for user in form.cleaned_data['user']:
        if user == request.user: continue  # we skip ourselves
        if invite_type == 'initiators' and \
            initiative.supporting.filter(initiator=True).count() >= INITIATORS_COUNT:
            break

        try:
            supporting = initiative.supporting.get(user_id=user.id)
        except Supporter.DoesNotExist:
            supporting = Supporter(user=user, initiative=initiative, ack=False)

            if invite_type == 'initiators':
                supporting.initiator = True
            elif invite_type == 'supporters':
                supporting.first = True
        else:
            if invite_type == 'initiators' and not supporting.initiator:
                # we only allow promoting of supporters to initiators
                # not downwards.
                supporting.initiator = True
                supporting.first = False
                supporting.ack = False
            else:
                continue

        supporting.save()

        notify([user],
               NOTIFICATIONS.INVITE.SEND, {"target": initiative},
               sender=request.user)

    messages.success(
        request, "Initiator*innen eingeladen."
        if invite_type == 'initiators' else 'Unterstützer*innen eingeladen.')
    return redirect("/initiative/{}-{}".format(initiative.id, initiative.slug))