15-03-2024 6

This commit is contained in:
rizwanisready
2024-03-15 17:57:00 +05:30
parent f2f2cc5365
commit 45cdc4cc97
7 changed files with 242 additions and 34 deletions

View File

@@ -708,18 +708,18 @@ class GoogleLoginAPIView(APIView):
print("Created new user")
message = "Details updated"
try:
ReferralCode.create_referral_code_for_user_manager(
principal=principal, principal_type=principal.principal_type
)
except Exception as e:
print("ReferralCode: E-", e)
error_response = {
"status": status.HTTP_400_BAD_REQUEST,
"message": constants.FAILURE,
"errors": str(e),
}
return ApiResponse.error(**error_response)
try:
ReferralCode.create_referral_code_for_user_manager(
principal=principal, principal_type=principal.principal_type
)
except Exception as e:
print("ReferralCode: E-", e)
error_response = {
"status": status.HTTP_400_BAD_REQUEST,
"message": constants.FAILURE,
"errors": str(e),
}
return ApiResponse.error(**error_response)
if referral_code:
already_register_through_referral = ReferralRecord.objects.filter(

View File

@@ -87,50 +87,83 @@ def send_notification(title, message, image_url=None, eligible_principals=None):
return response
# def get_eligible_principals_for_notification(push_notification):
# principal_type = push_notification.principal_type
# notification_category = push_notification.notification_category
# if principal_type == PrincipalType.BOTH:
# # If BOTH is selected, fetch users categorized under both EVENT_USER and EVENT_MANAGER
# eligible_principals = list(
# IAmPrincipal.objects.filter(
# Q(principal_type__name=PrincipalType.EVENT_USER)
# | Q(principal_type__name=PrincipalType.EVENT_MANAGER),
# notifications_principal__notification_category=notification_category,
# notifications_principal__is_enabled=True,
# ).values_list("player_id", flat=True)
# )
# elif principal_type == PrincipalType.EVENT_USER:
# # Fetch only EVENT_USER principals
# eligible_principals = list(
# IAmPrincipal.objects.filter(
# principal_type__name=PrincipalType.EVENT_USER,
# notifications_principal__notification_category=notification_category,
# notifications_principal__is_enabled=True,
# ).values_list("player_id", flat=True)
# )
# elif principal_type == PrincipalType.EVENT_MANAGER:
# # Fetch only EVENT_MANAGER principals
# eligible_principals = list(
# IAmPrincipal.objects.filter(
# principal_type__name=PrincipalType.EVENT_MANAGER,
# notifications_principal__notification_category=notification_category,
# notifications_principal__is_enabled=True,
# ).values_list("player_id", flat=True)
# )
# return eligible_principals
def get_eligible_principals_for_notification(push_notification):
principal_type = push_notification.principal_type
notification_category = push_notification.notification_category
if principal_type == PrincipalType.BOTH:
# If BOTH is selected, fetch users categorized under both EVENT_USER and EVENT_MANAGER
eligible_principals = list(
IAmPrincipal.objects.filter(
eligible_principals = [
player_id
for player_id in IAmPrincipal.objects.filter(
Q(principal_type__name=PrincipalType.EVENT_USER)
| Q(principal_type__name=PrincipalType.EVENT_MANAGER),
notifications_principal__notification_category=notification_category,
notifications_principal__is_enabled=True,
).values_list("player_id", flat=True)
)
# event_manager_principals = IAmPrincipal.objects.filter(
# principal_type__name=PrincipalType.EVENT_MANAGER,
# notifications_principal__notification_category=notification_category,
# notifications_principal__is_enabled=True,
# )
# # Combine the QuerySets. Use | operator for OR query (union) and distinct() to avoid duplicates.
# eligible_principals = (
# event_user_principals | event_manager_principals
# )
if player_id is not None
]
elif principal_type == PrincipalType.EVENT_USER:
# Fetch only EVENT_USER principals
eligible_principals = list(
IAmPrincipal.objects.filter(
eligible_principals = [
player_id
for player_id in IAmPrincipal.objects.filter(
principal_type__name=PrincipalType.EVENT_USER,
notifications_principal__notification_category=notification_category,
notifications_principal__is_enabled=True,
).values_list("player_id", flat=True)
)
if player_id is not None
]
elif principal_type == PrincipalType.EVENT_MANAGER:
# Fetch only EVENT_MANAGER principals
eligible_principals = list(
IAmPrincipal.objects.filter(
eligible_principals = [
player_id
for player_id in IAmPrincipal.objects.filter(
principal_type__name=PrincipalType.EVENT_MANAGER,
notifications_principal__notification_category=notification_category,
notifications_principal__is_enabled=True,
).values_list("player_id", flat=True)
)
if player_id is not None
]
return eligible_principals

View File

@@ -4,6 +4,7 @@ from .models import (
ReferralRecordReward,
GoodTimeCoins,
ReferralTracking,
ReferralCode,
)
@@ -69,3 +70,14 @@ class ReferralTrackingForm(forms.ModelForm):
"user_agent": forms.TextInput(attrs={"class": "form-control"}),
"device_model": forms.TextInput(attrs={"class": "form-control"}),
}
class ReferralCodeForm(forms.ModelForm):
class Meta:
model = ReferralCode
fields = ["id", "principal", "principal_type", "referral_code"]
widgets = {
"principal": forms.Select(attrs={"class": "form-control"}),
"principal_type": forms.Select(attrs={"class": "form-control"}),
"referral_code": forms.TextInput(attrs={"class": "form-control"}),
}

View File

@@ -4,6 +4,12 @@ from . import views
app_name = "manage_referrals"
urlpatterns = [
# Referral Code
path(
"referral-code/list/",
views.ReferralCodeView.as_view(),
name="code_list",
),
# Referral Record
path(
"referral-record/list/",

View File

@@ -12,6 +12,7 @@ from manage_referrals.forms import (
ReferralTrackingForm,
)
from manage_referrals.models import (
ReferralCode,
ReferralRecord,
ReferralRecordReward,
GoodTimeCoins,
@@ -102,6 +103,23 @@ class ReferralRecordView(LoginRequiredMixin, generic.ListView):
return context
class ReferralCodeView(LoginRequiredMixin, generic.ListView):
page_name = resource_action.RESOURCE_MANAGE_REFERRALS
resource = resource_action.RESOURCE_MANAGE_REFERRALS
action = resource_action.ACTION_READ
model = ReferralCode
template_name = "manage_referrals/code_list.html"
context_object_name = "code"
def get_queryset(self):
return super().get_queryset().filter(active=True, deleted=False)
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["page_name"] = self.page_name
return context
class ReferralRecordDeleteView(LoginRequiredMixin, generic.View):
page_name = resource_action.RESOURCE_MANAGE_REFERRALS
resource = resource_action.RESOURCE_MANAGE_REFERRALS

View File

@@ -0,0 +1,137 @@
{% extends 'layout/base_template.html' %}
{% load static %}
{% block stylesheet %}
<!-- include required css cdn link through html here -->
{% include "cdn_through_html/datatable_cdn_css.html" %}
{% endblock %}
{% block content %}
<div class="row layout-top-spacing">
<div class="col-lg-12">
<div class="row">
<div class="col-sm-6">
<h3>Referral Codes</h3>
</div>
<div class="col-sm-6 text-md-end">
<!--
<button class="btn btn-dark mb-2 me-md-4" onclick="history.back()">
<i class="fa fa-arrow-left"></i>
Back
</button>
-->
<a class="btn btn-primary mb-2" href="{% url 'manage_referrals:coin_add' %}">Add Coins</a>
<a class="btn btn-primary mb-2" href="{% url 'manage_referrals:record_list' %}">Referral Record</a>
<a class="btn btn-primary mb-2" href="{% url 'manage_referrals:reward_list' %}">Rewards</a>
</div>
</div>
<div class="row layout-spacing">
<div class="col-lg-12">
<div class="statbox widget box box-shadow">
<div class="widget-content widget-content-area">
<div id="style-3_wrapper" class="dataTables_wrapper container-fluid dt-bootstrap4 no-footer">
<div class="table-responsive">
<table id="style-3" class="table style-3 dt-table-hover dataTable no-footer" role="grid"
aria-describedby="style-3_info">
<thead>
<tr role="row">
<th class="checkbox-column sorting_asc" tabindex="0" aria-controls="style-3"
aria-sort="ascending" style="width: 69.2656px;"> Record Id </th>
<th class="checkbox-column sorting_asc" tabindex="0" aria-controls="style-3"
aria-sort="ascending" style="width: 69.2656px;"> Referral Code </th>
<th class="checkbox-column sorting_asc" tabindex="0" aria-controls="style-3"
aria-sort="ascending" style="width: 69.2656px;"> Principal </th>
<th class="checkbox-column sorting_asc" tabindex="0" aria-controls="style-3"
aria-sort="ascending" style="width: 69.2656px;"> Principal Type </th>
<th class="sorting" tabindex="7" aria-controls="style-3"
style="width: 79.7969px;">Active</th>
<th class="dt-no-sorting sorting" tabindex="8" aria-controls="style-3"
style="width: 100.625px;">Action</th>
</tr>
</thead>
<tbody>
{% for data_obj in code %}
<tr role="row">
<td class="checkbox-column text-center sorting_1">{{data_obj.id}}</td>
<td>{{data_obj.referral_code}}</td>
<td>{{data_obj.principal}}</td>
<td>{{data_obj.principal.principal_type}}</td>
<td class="text-center">
<span
class="shadow-none badge {% if data_obj.active %}badge-primary{% else %}badge-danger{% endif %}">{{data_obj.active}}</span>
</td>
<td class="text-center">
<ul class="table-controls">
<li><a href="{% url 'manage_referrals:coin_edit' data_obj.id %}"
class="bs-tooltip" data-bs-toggle="tooltip"
data-bs-placement="top" title="" data-original-title="Edit"
data-bs-original-title="Edit" aria-label="Edit"><svg
xmlns="http://www.w3.org/2000/svg" width="24"
height="24" viewBox="0 0 24 24" fill="none"
stroke="currentColor" stroke-width="2"
stroke-linecap="round" stroke-linejoin="round"
class="feather feather-edit-2 p-1 br-8 mb-1">
<path
d="M17 3a2.828 2.828 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5L17 3z">
</path>
</svg></a></li>
<li><a href="{% url 'manage_referrals:coin_delete' data_obj.id %}"
class="bs-tooltip" data-bs-toggle="tooltip"
data-bs-placement="top" title=""
data-original-title="Delete" data-bs-original-title="Delete"
aria-label="Delete"><svg xmlns="http://www.w3.org/2000/svg"
width="24" height="24" viewBox="0 0 24 24" fill="none"
stroke="currentColor" stroke-width="2"
stroke-linecap="round" stroke-linejoin="round"
class="feather feather-trash p-1 br-8 mb-1">
<polyline points="3 6 5 6 21 6"></polyline>
<path
d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2">
</path>
</svg></a></li>
</ul>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
{% endblock content %}
{% block javascript %}
<!-- include required js cdn link through html here -->
{% include "cdn_through_html/datatable_cdn_js.html" %}
<script>
c3 = $('#style-3').DataTable({
"dom": "<'dt--top-section'<'row'<'col-12 col-sm-6 d-flex justify-content-sm-start justify-content-center'l><'col-12 col-sm-6 d-flex justify-content-sm-end justify-content-center mt-sm-0 mt-3'f>>>" +
"<'table-responsive'tr>" +
"<'dt--bottom-section d-sm-flex justify-content-sm-between text-center'<'dt--pages-count mb-sm-0 mb-3'i><'dt--pagination'p>>",
"oLanguage": {
"oPaginate": { "sPrevious": '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-arrow-left"><line x1="19" y1="12" x2="5" y2="12"></line><polyline points="12 19 5 12 12 5"></polyline></svg>', "sNext": '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-arrow-right"><line x1="5" y1="12" x2="19" y2="12"></line><polyline points="12 5 19 12 12 19"></polyline></svg>' },
"sInfo": "Showing page PAGE of _PAGES_",
"sSearch": '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-search"><circle cx="11" cy="11" r="8"></circle><line x1="21" y1="21" x2="16.65" y2="16.65"></line></svg>',
"sSearchPlaceholder": "Search...",
"sLengthMenu": "Results : _MENU_",
},
"stripeClasses": [],
"lengthMenu": [5, 10, 20, 50],
"pageLength": 10
});
multiCheck(c3);
</script>
{% endblock %}

View File

@@ -21,9 +21,11 @@
Back
</button>
-->
<a class="btn btn-primary mb-2" href="{% url 'manage_referrals:reward_list' %}">Referral Rewards</a>
<a class="btn btn-primary mb-2" href="{% url 'manage_referrals:track_list' %}">Referral Tracking</a>
<!-- <a class="btn btn-primary mb-2" href="{% url 'manage_referrals:reward_list' %}">Referral Rewards</a> -->
<!-- <a class="btn btn-primary mb-2" href="{% url 'manage_referrals:track_list' %}">Referral Tracking</a> -->
<a class="btn btn-primary mb-2" href="{% url 'manage_referrals:coin_list' %}">Good Time Coins</a>
<a class="btn btn-primary mb-2" href="{% url 'manage_referrals:code_list' %}">Referral Codes</a>
</div>
</div>