def save(self, *args, **kwargs): """Custom save method to add data to the through model.""" for profile in self.cleaned_data['invites']: if not Invite.objects.filter(group=self.instance, redeemer=profile).exists(): # Create the Invite objects invite, created = Invite.objects.get_or_create( group=self.instance, redeemer=profile, inviter=self.request.user.userprofile) # Shoot an email notify_redeemer_invitation.delay(invite.pk, self.instance.invite_email_text)
def send_invitation_email(request, invite_pk): """Send group invitation email.""" invite = get_object_or_404(Invite, pk=invite_pk) is_curator = invite.group.curators.filter(pk=request.user.userprofile.pk).exists() is_manager = request.user.userprofile.is_manager if not (is_curator or is_manager): raise http.Http404 notify_redeemer_invitation.delay(invite.pk, invite.group.invite_email_text) msg = _(u'Invitation to {0} has been sent successfully.'.format(invite.redeemer)) messages.success(request, msg) next_section = request.GET.get('next') next_url = urlparams(reverse('groups:group_edit', args=[invite.group.url]), next_section) return http.HttpResponseRedirect(next_url)