There is a situation that when a user has requested for invitation, he/she will then get to signup the account. When request is accepted by admin then they can signup which i have done. But i have no idea on how to delete the email address from the invitation table once that user has signed up successfully. I am using django allauth package.
class CustomSignupForm(forms.Form):
def __init__(self, *args, **kwargs):
super(CustomSignupForm, self).__init__(*args, **kwargs)
def clean(self):
email = self.cleaned_data.get('email')
if email and settings.INVITE_MODE:
try:
obj = Invitation.objects.get(email=email)
if not obj.request_approved:
self.add_error('email', 'Sorry your invitation is still in pending')
except Invitation.DoesNotExist:
invitation = Invitation.objects.create(email=email)
self.add_error('email', 'Sorry at this time you are not invited. But we have added you to our invite list')
elif email is None:
raise forms.ValidationError('Email field should not be empty')
else:
return email
class Invitation(models.Model):
email = models.EmailField(unique=True, verbose_name=_("e-mail Address"))
invite_code = models.UUIDField(default=uuid.uuid4, unique=True)
points = models.PositiveIntegerField(default=5)
request_approved = models.BooleanField(default=False, verbose_name=_('request accepted'))
status = models.BooleanField(default=False)
@receiver(post_save, sender=Invitation)
def send_email_when_invite_is_accepted_by_admin(sender, instance, *args, **kwargs):
request_approved = instance.request_approved
if request_approved:
subject = "Request Approved"
message = "Hello {0}! Your request has been approved. You can now signup".format(instance.email)
from_email = None
to_email = [instance.email]
send_mail(subject, message, from_email, to_email, fail_silently=True)