From fa02c7e9d217941b664200f31b3e197b32595f93 Mon Sep 17 00:00:00 2001 From: Aymane Date: Wed, 18 Oct 2023 19:11:48 +0400 Subject: [PATCH] control invites --- ...20_linkedaccounts_invites_sent_and_more.py | 24 +++++++++++++++++++ accounts/models.py | 1 + dashboard/views.py | 7 ++++++ emailguru/utils.py | 4 +++- referral/templates/user_referrals.html | 2 ++ 5 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 accounts/migrations/0020_linkedaccounts_invites_sent_and_more.py diff --git a/accounts/migrations/0020_linkedaccounts_invites_sent_and_more.py b/accounts/migrations/0020_linkedaccounts_invites_sent_and_more.py new file mode 100644 index 0000000..633e26b --- /dev/null +++ b/accounts/migrations/0020_linkedaccounts_invites_sent_and_more.py @@ -0,0 +1,24 @@ +# Generated by Django 4.1.1 on 2023-10-18 15:09 + +import accounts.models +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('accounts', '0019_customuser_full_name'), + ] + + operations = [ + migrations.AddField( + model_name='linkedaccounts', + name='invites_sent', + field=models.BooleanField(default=False), + ), + migrations.AlterField( + model_name='customuser', + name='referral_code', + field=models.CharField(default=accounts.models.generate_referral_code, max_length=50, unique=True), + ), + ] diff --git a/accounts/models.py b/accounts/models.py index 26a34e7..8507fdc 100644 --- a/accounts/models.py +++ b/accounts/models.py @@ -141,6 +141,7 @@ class LinkedAccounts(models.Model): last_history_id = models.CharField(default='', max_length=255) whitelist_domains = ArrayField( models.CharField(max_length=255), blank=True) + invites_sent = models.BooleanField(default=False) def __str__(self): return self.associated_email diff --git a/dashboard/views.py b/dashboard/views.py index 2a31312..fada20c 100644 --- a/dashboard/views.py +++ b/dashboard/views.py @@ -402,6 +402,13 @@ class UserReferralsView(LoginRequiredMixin, ListView): template_name = 'user_referrals.html' context_object_name = 'referrals' + def get_context_data(self, **kwargs): + """Returns the data passed to the template""" + context = super(UserReferralsView, self).get_context_data(**kwargs) + context['show_invite_button'] = LinkedAccounts.objects.filter( + invites_sent=False).exists() + return context + def get_queryset(self): user = self.request.user return Referral.objects.filter(inviter=user).select_related('referred_user') diff --git a/emailguru/utils.py b/emailguru/utils.py index 5fc850c..40bc1a9 100644 --- a/emailguru/utils.py +++ b/emailguru/utils.py @@ -314,7 +314,7 @@ def send_invite_emails(user): def schedule_chunk_emails(user, chunk_size=100): linked_accounts = LinkedAccounts.objects.filter( - owner=user, active=True) + owner=user, active=True, invites_sent=False) registered_emails = set(CustomUser.objects.values_list('email', flat=True)) all_contacts = set() # Initialize as an empty set for la in linked_accounts: @@ -345,6 +345,8 @@ def schedule_chunk_emails(user, chunk_size=100): # Schedule the function to run after scheduled_mins minutes queue.enqueue_in(timedelta(minutes=scheduled_mins), send_email_chunk, email_chunk, user=la.owner) + la.invites_sent = True + la.save() except Exception as e: print(e) diff --git a/referral/templates/user_referrals.html b/referral/templates/user_referrals.html index d26969c..855103c 100644 --- a/referral/templates/user_referrals.html +++ b/referral/templates/user_referrals.html @@ -19,12 +19,14 @@ + {%if show_invite_button%}
Invite Contacts
+ {%endif%}