diff --git a/accounts/api/serializers.py b/accounts/api/serializers.py index 1ab23af..afa5148 100644 --- a/accounts/api/serializers.py +++ b/accounts/api/serializers.py @@ -157,6 +157,10 @@ class ProfileSerializer(serializers.ModelSerializer): "register_complete", "has_active_subscription", "has_preferences", + "linkedin_profile", + "youtube_profile", + "facebook_profile", + "instagram_profile", ] def update(self, instance, validated_data): diff --git a/accounts/migrations/0006_iamprincipal_facebook_profile_and_more.py b/accounts/migrations/0006_iamprincipal_facebook_profile_and_more.py new file mode 100644 index 0000000..ea7aaec --- /dev/null +++ b/accounts/migrations/0006_iamprincipal_facebook_profile_and_more.py @@ -0,0 +1,41 @@ +# Generated by Django 5.0.2 on 2024-04-05 13:57 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("accounts", "0005_appversion"), + ] + + operations = [ + migrations.AddField( + model_name="iamprincipal", + name="facebook_profile", + field=models.URLField( + blank=True, null=True, verbose_name="Principal Facebook" + ), + ), + migrations.AddField( + model_name="iamprincipal", + name="instagram_profile", + field=models.URLField( + blank=True, null=True, verbose_name="Principal Instagram" + ), + ), + migrations.AddField( + model_name="iamprincipal", + name="linkedin_profile", + field=models.URLField( + blank=True, null=True, verbose_name="Principal LinkedIn" + ), + ), + migrations.AddField( + model_name="iamprincipal", + name="youtube_profile", + field=models.URLField( + blank=True, null=True, verbose_name="Principal Youtube" + ), + ), + ] diff --git a/accounts/models.py b/accounts/models.py index 308d442..effadb9 100644 --- a/accounts/models.py +++ b/accounts/models.py @@ -285,6 +285,30 @@ class IAmPrincipal(AbstractUser): related_name="principal_groups", ) register_complete = models.BooleanField(default=False) + linkedin_profile = models.URLField( + verbose_name="Principal LinkedIn", + max_length=200, + blank=True, + null=True, + ) + instagram_profile = models.URLField( + verbose_name="Principal Instagram", + max_length=200, + blank=True, + null=True, + ) + youtube_profile = models.URLField( + verbose_name="Principal Youtube", + max_length=200, + blank=True, + null=True, + ) + facebook_profile = models.URLField( + verbose_name="Principal Facebook", + max_length=200, + blank=True, + null=True, + ) USERNAME_FIELD = "email" REQUIRED_FIELDS = [] diff --git a/accounts/views.py b/accounts/views.py index aab6e0d..cc926d3 100644 --- a/accounts/views.py +++ b/accounts/views.py @@ -1,5 +1,5 @@ import logging - +from django.db.models import Count, Q from django.contrib import messages from django.contrib.auth import authenticate, login, logout from django.contrib.auth.views import LogoutView @@ -523,16 +523,10 @@ class CustomerListView(LoginRequiredMixin, generic.ListView): action = resource_action.ACTION_READ model = IAmPrincipal template_name = "accounts/customer/customer_list.html" - context_object_name = "data_obj" + context_object_name = "data_objs" def get_queryset(self): - user_types = [ - resource_action.PRINCIPAL_TYPE_EVENT_USER, - resource_action.PRINCIPAL_TYPE_EVENT_MANAGER, - resource_action.PRINCIPAL_TYPE_FREE_USER, - ] - - return ( + queryset = ( super() .get_queryset() .select_related("principal_type", "principal_source") @@ -546,12 +540,22 @@ class CustomerListView(LoginRequiredMixin, generic.ListView): | models.Q( principal_type__name=resource_action.PRINCIPAL_TYPE_FREE_USER ), - # principal_type__name=resource_action.PRINCIPAL_TYPE_PLAYER, - # principal_type__in=user_types, - # deleted=False, ) ) + # Annotate the queryset with the count of referrals for each principal + queryset = queryset.annotate( + referral_count=Count( + "referrals_by_referrer", + filter=Q( + referrals_by_referrer__is_completed=True + ), # Assuming you only want to count completed referrals + distinct=True, # Ensures referrals are not double-counted if there are multiple conditions or joins + ) + ) + + return queryset + def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context["page_name"] = self.page_name diff --git a/manage_events/views.py b/manage_events/views.py index 4a1ec4f..46d9622 100644 --- a/manage_events/views.py +++ b/manage_events/views.py @@ -331,6 +331,7 @@ class EventDetailView(generic.DetailView): def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) + context["page_name"] = self.page_name event_id = self.object.id # Get the current event's ID # Separate count for interested and going diff --git a/manage_wallets/api/views.py b/manage_wallets/api/views.py index 01eeaa2..aed0f04 100644 --- a/manage_wallets/api/views.py +++ b/manage_wallets/api/views.py @@ -9,6 +9,7 @@ from django.utils.decorators import method_decorator from accounts.models import IAmPrincipal, IAmPrincipalType from goodtimes import services, constants from decimal import Decimal +from manage_referrals.models import GoodTimeCoins from manage_wallets import models from django.conf import settings from django.utils import timezone @@ -356,6 +357,11 @@ class WithdrawalRequestCreateAPI(APIView): def post(self, request, *args, **kwargs): user = request.user wallet = models.Wallet.objects.filter(principal=user).first() + coins_amount = ( + GoodTimeCoins.objects.filter(active=True, deleted=False) + .last() + .value_in_pound + ) # Check if the user has a wallet and sufficient coins if wallet is None or wallet.coins <= 0: @@ -364,7 +370,8 @@ class WithdrawalRequestCreateAPI(APIView): status=status.HTTP_400_BAD_REQUEST, message=constants.FAILURE, ) - print("Request.DATA: ", request.data) + amount = coins_amount * wallet.coins + print("amount: ", amount) serializer = serializers.WithdrawalRequestSerializer(data=request.data) if serializer.is_valid(): @@ -375,6 +382,7 @@ class WithdrawalRequestCreateAPI(APIView): created_on=timezone.now(), coins=wallet.coins, notes=notes, + amount=amount, ) # Reset the wallet's coins to 0 wallet.coins = 0 diff --git a/manage_wallets/views.py b/manage_wallets/views.py index f62211a..9746284 100644 --- a/manage_wallets/views.py +++ b/manage_wallets/views.py @@ -56,7 +56,7 @@ class WithdrawalListView(LoginRequiredMixin, generic.TemplateView): class BankAccountListView(LoginRequiredMixin, generic.TemplateView): - page_name = resource_action.RESOURCE_MANAGE_WITHDRAWALS + page_name = resource_action.RESOURCE_MANAGE_BANK_ACCOUNTS template_name = "manage_wallets/account_list.html" model = PrincipalBankAccount diff --git a/templates/accounts/customer/customer_list.html b/templates/accounts/customer/customer_list.html index 4630afb..442c97d 100644 --- a/templates/accounts/customer/customer_list.html +++ b/templates/accounts/customer/customer_list.html @@ -56,6 +56,8 @@ style="width: 98.875px;">Phone Verified -->