corrected event filtered query
This commit is contained in:
@@ -403,28 +403,55 @@ class EventFilterService:
|
||||
def filter_events_by_search(search_query=None):
|
||||
today = timezone.now().date()
|
||||
filtered_events = Event.objects.filter(
|
||||
key_guest__isnull=False, deleted=False, active=True, draft=False
|
||||
deleted=False, active=True, draft=False
|
||||
)
|
||||
|
||||
# Optional search filtering on title and key_guest (modify as needed)
|
||||
if search_query:
|
||||
print("search_query: ", search_query)
|
||||
filtered_events = filtered_events.filter(
|
||||
Q(title__icontains=search_query)
|
||||
| Q(key_guest__icontains=search_query)
|
||||
| Q(tags__name__in=[search_query])
|
||||
| Q(venue__address__icontains=search_query)
|
||||
)
|
||||
print("filtered_events: ", filtered_events)
|
||||
|
||||
# Filter for current, future, or ongoing events
|
||||
current_and_future_events_query = Q(
|
||||
start_date__lte=today, end_date__gte=today
|
||||
) | Q(start_date__gt=today)
|
||||
filtered_events = filtered_events.filter(
|
||||
current_and_future_events_query
|
||||
).distinct()
|
||||
filtered_events = filtered_events.filter(current_and_future_events_query)
|
||||
|
||||
return filtered_events
|
||||
|
||||
@staticmethod
|
||||
def filter_events_by_tags(search_query=None):
|
||||
today = timezone.now().date()
|
||||
if search_query:
|
||||
print("search_query: ", search_query)
|
||||
filtered_events = Event.objects.filter(
|
||||
tags__isnull=False, deleted=False, active=True, draft=False
|
||||
)
|
||||
|
||||
filtered_events = (
|
||||
filtered_events.annotate(
|
||||
matched_tags=Count(
|
||||
"tags", filter=Q(tags__name__icontains=search_query), distinct=True
|
||||
)
|
||||
)
|
||||
.filter(matched_tags__gt=0)
|
||||
.distinct()
|
||||
)
|
||||
print("filtered_events: ", filtered_events)
|
||||
|
||||
# Filter for current, future, or ongoing events
|
||||
current_and_future_events_query = Q(
|
||||
start_date__lte=today, end_date__gte=today
|
||||
) | Q(start_date__gt=today)
|
||||
filtered_events = filtered_events.filter(current_and_future_events_query)
|
||||
|
||||
return filtered_events
|
||||
|
||||
@staticmethod
|
||||
def filter_events(filter_type, principal=None):
|
||||
today = timezone.now().date()
|
||||
|
||||
@@ -157,6 +157,29 @@ class CreateEventSerializer(serializers.ModelSerializer):
|
||||
|
||||
return event
|
||||
|
||||
def update(self, instance, validated_data):
|
||||
tags = validated_data.pop("tags", None)
|
||||
images_data = validated_data.pop("images", None)
|
||||
|
||||
# Update fields if there is any change.
|
||||
if tags is not None:
|
||||
# Clear existing tags and add the new ones
|
||||
# instance.tags.clear()
|
||||
instance.tags.add(*tags)
|
||||
|
||||
if images_data is not None:
|
||||
# Assuming you want to add new images without deleting the old ones
|
||||
# If you want to replace them, you should delete the old images first
|
||||
for image_data in images_data:
|
||||
EventImage.objects.create(event=instance, image=image_data)
|
||||
|
||||
# Update other fields
|
||||
for attr, value in validated_data.items():
|
||||
setattr(instance, attr, value)
|
||||
instance.save()
|
||||
|
||||
return instance
|
||||
|
||||
|
||||
class CreateVenueSerializer(serializers.ModelSerializer):
|
||||
class Meta:
|
||||
|
||||
@@ -177,7 +177,7 @@ class EventsAPIView(APIView):
|
||||
search_query=query
|
||||
)
|
||||
elif filter == "tags":
|
||||
events = services.EventFilterService.filter_events_by_search(
|
||||
events = services.EventFilterService.filter_events_by_tags(
|
||||
search_query=query
|
||||
)
|
||||
elif filter == "category" and category_id is not None:
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from django import forms
|
||||
from .models import Wallet, Transaction
|
||||
from .models import Wallet, Transaction, PrincipalBankAccount
|
||||
|
||||
|
||||
class WalletForm(forms.ModelForm):
|
||||
@@ -50,3 +50,13 @@ class TransactionForm(forms.ModelForm):
|
||||
"product_id": forms.TextInput(attrs={"class": "form-control"}),
|
||||
"reference_id": forms.TextInput(attrs={"class": "form-control"}),
|
||||
}
|
||||
|
||||
|
||||
class PrincipalBankAccountVerificationForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = PrincipalBankAccount
|
||||
fields = ["is_verified"] # Specify only the 'is_verified' field
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(PrincipalBankAccountVerificationForm, self).__init__(*args, **kwargs)
|
||||
# You can add any additional customization to the 'is_verified' field here if needed
|
||||
|
||||
@@ -10,6 +10,7 @@ urlpatterns = [
|
||||
path("payment/", views.PaymentListView.as_view(), name="payment_list"),
|
||||
# for manage account related url
|
||||
path("bank-accounts/", views.BankAccountListView.as_view(), name="account_list"),
|
||||
path("edit-bank-account/<uuid:pk>/", views.BankAccountCreateOrUpdateView.as_view(), name="edit_bank_account"),
|
||||
# for manage withdraw related url
|
||||
path("withdrawals/", views.WithdrawalListView.as_view(), name="withdrawal_list"),
|
||||
path("update-status/", views.StatusUpdateView.as_view(), name="update_status"),
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
from django.shortcuts import render, redirect
|
||||
from django.shortcuts import get_object_or_404, render, redirect
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.urls import reverse_lazy
|
||||
from accounts import resource_action
|
||||
from django.views import generic
|
||||
from django.contrib import messages
|
||||
from goodtimes import constants
|
||||
from manage_wallets.forms import PrincipalBankAccountVerificationForm
|
||||
from .models import PrincipalBankAccount, Wallet, Transaction, WithdrawalRequest
|
||||
|
||||
"""Wallet Related VIew"""
|
||||
@@ -94,3 +95,67 @@ class StatusUpdateView(LoginRequiredMixin, generic.View):
|
||||
|
||||
# Redirect to the desired URL after form submission
|
||||
return redirect(self.success_url)
|
||||
|
||||
|
||||
class BankAccountCreateOrUpdateView(LoginRequiredMixin, generic.View):
|
||||
# Set the page_name and resource
|
||||
page_name = resource_action.RESOURCE_MANAGE_BANK_ACCOUNTS
|
||||
resource = resource_action.RESOURCE_MANAGE_BANK_ACCOUNTS
|
||||
|
||||
# Initialize the action as ACTION_CREATE (can change based on logic)
|
||||
action = resource_action.ACTION_CREATE # Default action
|
||||
|
||||
template_name = "manage_wallets/bank_account_edit.html"
|
||||
model = PrincipalBankAccount
|
||||
form_class = PrincipalBankAccountVerificationForm
|
||||
success_url = reverse_lazy("manage_wallets:account_list")
|
||||
error_message = "An error occurred while saving the data."
|
||||
|
||||
# Determine the success message dynamically based on whether it's an update or create
|
||||
def get_success_message(self):
|
||||
self.success_message = (
|
||||
constants.RECORD_CREATED if not self.object else constants.RECORD_UPDATED
|
||||
)
|
||||
return self.success_message
|
||||
|
||||
# Get the object (if exists) based on URL parameter 'pk'
|
||||
def get_object(self):
|
||||
pk = self.kwargs.get("pk")
|
||||
return get_object_or_404(self.model, pk=pk) if pk else None
|
||||
|
||||
# Add page_name and operation to the context
|
||||
def get_context_data(self, **kwargs):
|
||||
context = {
|
||||
"page_name": self.page_name,
|
||||
"operation": "Add" if not self.object else "Edit",
|
||||
}
|
||||
context.update(kwargs) # Include any additional context data passed to the view
|
||||
return context
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
self.object = self.get_object()
|
||||
|
||||
# If an object is found, change action to ACTION_UPDATE
|
||||
if self.object is not None:
|
||||
self.action = resource_action.ACTION_UPDATE
|
||||
|
||||
form = self.form_class(instance=self.object)
|
||||
context = self.get_context_data(form=form)
|
||||
return render(request, self.template_name, context=context)
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
self.object = self.get_object()
|
||||
|
||||
# If an object is found, change action to ACTION_UPDATE
|
||||
if self.object is not None:
|
||||
self.action = resource_action.ACTION_UPDATE
|
||||
|
||||
form = self.form_class(request.POST, instance=self.object)
|
||||
if not form.is_valid():
|
||||
print(form.errors)
|
||||
context = self.get_context_data(form=form)
|
||||
return render(request, self.template_name, context=context)
|
||||
|
||||
form.save()
|
||||
messages.success(self.request, self.get_success_message())
|
||||
return redirect(self.success_url)
|
||||
@@ -50,6 +50,14 @@
|
||||
</div>
|
||||
<p class="card-text"><strong>Status:</strong> {{ event.status }}</p>
|
||||
<p class="card-text"><strong>Entry:</strong> {{ event.entry_type }} - ${{ event.entry_fee }}</p>
|
||||
<!-- Key Guests Section -->
|
||||
{% if event.key_guest %}
|
||||
<p class="card-text">
|
||||
<strong>Key Guests:</strong> {{ event.key_guest }}
|
||||
</p>
|
||||
{% else %}
|
||||
<p class="card-text">No key guests announced.</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -89,6 +97,23 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Tags Section -->
|
||||
<div class="card mb-3">
|
||||
<div class="card-body">
|
||||
<h5>Tags</h5>
|
||||
{% if event.tags.all %}
|
||||
<div class="d-flex flex-wrap">
|
||||
{% for tag in event.tags.all %}
|
||||
<span class="badge bg-secondary m-1">{{ tag.name }}</span>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% else %}
|
||||
<p>No tags for this event.</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<!-- Event Images -->
|
||||
<div class="card mb-3">
|
||||
<div class="card-body">
|
||||
|
||||
@@ -101,6 +101,13 @@
|
||||
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>
|
||||
<li>
|
||||
<a href="{% url 'manage_events:event_detail' data_obj.id %}">
|
||||
<span class="material-symbols-outlined">
|
||||
visibility
|
||||
</span>
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
@@ -54,6 +54,8 @@
|
||||
<th class="sorting" tabindex="0" aria-controls="style-3" rowspan="1" colspan="1"
|
||||
aria-label="Mobile No.: activate to sort column ascending"
|
||||
style="width: 98.875px;">Submitted</th>
|
||||
<th class="dt-no-sorting sorting" tabindex="8" aria-controls="style-3"
|
||||
style="width: 100.625px;">Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -67,8 +69,28 @@
|
||||
<td>{{account_obj.account_no}}</td>
|
||||
<td>{{account_obj.first_name}}</td>
|
||||
<td>{{account_obj.last_name}}</td>
|
||||
<td>{{account_obj.is_verified}}</td>
|
||||
<td class="text-center">
|
||||
<span
|
||||
class="shadow-none badge {% if account_obj.is_verified %}badge-primary{% else %}badge-danger{% endif %}">{{account_obj.is_verified}}</span>
|
||||
</td>
|
||||
<td>{{account_obj.created_on}}</td>
|
||||
<td class="text-center">
|
||||
<ul class="table-controls">
|
||||
<li><a href="{% url 'manage_wallets:edit_bank_account' account_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>
|
||||
</ul>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
||||
|
||||
60
templates/manage_wallets/bank_account_edit.html
Normal file
60
templates/manage_wallets/bank_account_edit.html
Normal file
@@ -0,0 +1,60 @@
|
||||
{% extends 'layout/base_template.html' %}
|
||||
{% load static %}
|
||||
{% block stylesheet %}
|
||||
<!-- include required css cdn link through html here -->
|
||||
|
||||
{% include "cdn_through_html/quill_cdn_css.html" %}
|
||||
{{form.media}}
|
||||
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<div class="row layout-top-spacing">
|
||||
<div class="col-lg-12">
|
||||
<div class="row mb-2">
|
||||
<div class="col">
|
||||
<h3>{{operation}} Bank Account</h3>
|
||||
</div>
|
||||
<div class="col text-end">
|
||||
<button class="btn btn-dark mb-2 me-4" onclick="history.back()">
|
||||
<i class="fa fa-arrow-left"></i>
|
||||
Back
|
||||
</button>
|
||||
</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">
|
||||
|
||||
<form method="POST">
|
||||
{% csrf_token %}
|
||||
{% include 'includes/dynamic_template_form.html' with form=form %}
|
||||
<div class="mt-4 mb-0">
|
||||
<div class="d-grid"><button class="btn btn-primary btn-block" type="submit">Submit</button></div>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
{% endblock content %}
|
||||
|
||||
{% block javascript %}
|
||||
<!-- include required css cdn link through html here -->
|
||||
|
||||
{% include "cdn_through_html/quill_cdn_js.html" %}
|
||||
|
||||
|
||||
<script>
|
||||
|
||||
|
||||
|
||||
</script>
|
||||
{% endblock %}
|
||||
Reference in New Issue
Block a user