Skip to content

Commit

Permalink
Implement industry and classification models with dropdown support
Browse files Browse the repository at this point in the history
- Add Industry and Classification models to base/models.py
- Update MainProfile model to use foreign key relationships
- Modify add_profile view to support industry and classification dropdowns
- Update URLs to include industry and classification CRUD routes
- Add middleware for login required pages
- Implement download user data functionality
  • Loading branch information
NagiPragalathan committed Feb 12, 2025
1 parent 9cc940a commit 96d424e
Show file tree
Hide file tree
Showing 34 changed files with 1,443 additions and 50 deletions.
Binary file modified QuizApp/__pycache__/settings.cpython-312.pyc
Binary file not shown.
Binary file modified QuizApp/__pycache__/urls.cpython-312.pyc
Binary file not shown.
3 changes: 3 additions & 0 deletions QuizApp/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@
"django.middleware.clickjacking.XFrameOptionsMiddleware",
'corsheaders.middleware.CorsMiddleware',
'django.middleware.locale.LocaleMiddleware',

# custom middleware
'base.middleware.LoginRequiredMiddleware',
]

CORS_ALLOWED_ORIGINS = [
Expand Down
28 changes: 25 additions & 3 deletions QuizApp/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from django.urls import re_path

# Django views
from base.views.industry_clasification import *
from base.views.json_rep import download_user_data
from base.views.auth import *
from base.views.common import *
from base.views.Profile import *
Expand Down Expand Up @@ -187,13 +189,11 @@
path('subscription-expired/', subscription_expired, name='subscription_expired'),
]



Operations = [
path('view_palms_summary/', view_palms_summary, name='view_palms_summary'),
path('view_chapter_goals/', view_chapter_goals, name='view_chapter_goals'),
path('email_my_chapter/', email_my_chapter, name='email_my_chapter'),
path('email_visitor_invitation/', send_invitation_view, name='send_invitation'),
path('email_visitor_invitation/', email_visitor_invitation, name='email_visitor_invitation'),
path('email_chapter_visitors/', email_chapter_visitors, name='email_chapter_visitors'),
path('manage_news/', manage_news, name='manage_news'),
path('operations/operations', operations, name='operations'),
Expand Down Expand Up @@ -350,7 +350,25 @@
path('portal/', portal, name='portal'),
]

download_data = [
path('download-data/<str:username>/', download_user_data, name='download_user_data'),
]

industry_classification = [
# Industry URLs
path('industries/', industry_list, name='industry_list'),
path('industry/<uuid:pk>/', industry_detail, name='industry_detail'),
path('industry/new/', industry_create, name='industry_create'),
path('industry/<uuid:pk>/edit/', industry_update, name='industry_update'),
path('industry/<uuid:pk>/delete/', industry_delete, name='industry_delete'),

# Classification URLs
path('classifications/', classification_list, name='classification_list'),
path('classification/<uuid:pk>/', classification_detail, name='classification_detail'),
path('classification/new/', classification_create, name='classification_create'),
path('classification/<uuid:pk>/edit/', classification_update, name='classification_update'),
path('classification/<uuid:pk>/delete/', classification_delete, name='classification_delete'),
]


urlpatterns.extend(auth)
Expand Down Expand Up @@ -386,6 +404,7 @@
urlpatterns+=admin_chapter
urlpatterns+=admin_profile
urlpatterns+=training_sessions
urlpatterns+=industry_classification

# reports
urlpatterns+=member_performance_report_url
Expand All @@ -396,5 +415,8 @@
urlpatterns+=training_sessions_report_url
urlpatterns+=iframe_url

# download data
urlpatterns+=download_data

urlpatterns += static(settings.MEDIA_URL, document_root = settings.MEDIA_ROOT)
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
Binary file modified base/__pycache__/admin.cpython-312.pyc
Binary file not shown.
Binary file modified base/__pycache__/models.cpython-312.pyc
Binary file not shown.
Binary file modified base/form/__pycache__/forms.cpython-312.pyc
Binary file not shown.
19 changes: 19 additions & 0 deletions base/middleware.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from django.shortcuts import redirect
from django.urls import reverse

class LoginRequiredMiddleware:
def __init__(self, get_response):
self.get_response = get_response

def __call__(self, request):
expected_paths = [
reverse('login'),
reverse('index'),
reverse('contact_form'),
]
# Check if the user is not authenticated and the request is not for the login page
if not request.user.is_authenticated and request.path not in expected_paths:
return redirect('login') # Redirect to the login page
# Continue processing the request
response = self.get_response(request)
return response
25 changes: 23 additions & 2 deletions base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,27 @@ class ChapterName(models.Model):
def __str__(self):
return self.chapter_name

class Industry(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
name = models.CharField(max_length=255, unique=True)
description = models.TextField(blank=True, null=True)
last_updated_date = models.DateField(auto_now=True)

def __str__(self):
return self.name

class Meta:
verbose_name_plural = "Industries"

class Classification(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
name = models.CharField(max_length=255, unique=True)
description = models.TextField(blank=True, null=True)
last_updated_date = models.DateField(auto_now=True)

def __str__(self):
return self.name

class MainProfile(models.Model):
TITLE_CHOICES = [
('Mr.', 'Mr.'),
Expand Down Expand Up @@ -61,8 +82,8 @@ class MainProfile(models.Model):
product_service_description = models.CharField(max_length=255, blank=True, null=True)
gst_registered_state = models.CharField(max_length=100, blank=True, null=True)
gst_identification_number_or_pan = models.CharField(max_length=255, blank=True, null=True)
industry = models.CharField(max_length=255, blank=True, null=True)
classification = models.CharField(max_length=255, blank=True, null=True)
industry = models.ForeignKey(Industry, on_delete=models.SET_NULL, blank=True, null=True)
classification = models.ForeignKey(Classification, on_delete=models.SET_NULL, blank=True, null=True)
requested_speciality = models.CharField(max_length=255, blank=True, null=True)
membership_status = models.CharField(max_length=11, choices=MEMBERSHIP_STATUS_CHOICES)
renewal_due_date = models.DateField(blank=True, null=True)
Expand Down
Binary file modified base/templatetags/__pycache__/djtemp.cpython-312.pyc
Binary file not shown.
33 changes: 28 additions & 5 deletions base/views/Profile.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.shortcuts import render, redirect, get_object_or_404
from base.models import MainProfile, ContactDetails, UserProfile, Address, BillingAddress, Bio, Gallery, ChapterName, Chapter
from base.models import MainProfile, ContactDetails, UserProfile, Address, BillingAddress, Bio, Gallery, ChapterName, Chapter, Industry, Classification
from django.contrib.auth.models import User
from django.contrib import messages
from django.contrib.auth.decorators import login_required
Expand Down Expand Up @@ -32,8 +32,8 @@ def add_profile(request, username, dashboard=0):
product_service_description = request.POST.get('product_service_description', '')
gst_registered_state = request.POST.get('gst_registered_state', '')
gst_identification_number_or_pan = request.POST.get('gst_identification_number_or_pan', '')
industry = request.POST.get('industry', '')
classification = request.POST.get('classification', '')
industry_id = request.POST.get('industry', '')
classification_id = request.POST.get('classification', '')
requested_speciality = request.POST.get('requested_speciality', '')
membership_status = request.POST.get('membership_status', 'Active')
my_business = request.POST.get('my_business', '')
Expand All @@ -47,6 +47,14 @@ def add_profile(request, username, dashboard=0):
if chapter_name_value:
chapter_instance = get_object_or_404(ChapterName, id=chapter_name_value)

# Get Industry and Classification instances
industry_instance = None
classification_instance = None
if industry_id:
industry_instance = get_object_or_404(Industry, id=industry_id)
if classification_id:
classification_instance = get_object_or_404(Classification, id=classification_id)

# Update user details
user.first_name = first_name
user.last_name = last_name
Expand All @@ -66,8 +74,8 @@ def add_profile(request, username, dashboard=0):
'product_service_description': product_service_description,
'gst_registered_state': gst_registered_state,
'gst_identification_number_or_pan': gst_identification_number_or_pan,
'industry': industry,
'classification': classification,
'industry': industry_instance,
'classification': classification_instance,
'requested_speciality': requested_speciality,
'membership_status': membership_status,
'renewal_due_date': renewal_due_date,
Expand All @@ -93,9 +101,16 @@ def add_profile(request, username, dashboard=0):
else:
profile = MainProfile.objects.get(user=User.objects.get(username=username))
chapter = ChapterName.objects.all()

# Add these querysets
industries = Industry.objects.all().order_by('name')
classifications = Classification.objects.all().order_by('name')

return render(request, 'Profile/add_profile.html', {
'data': profile,
'chapter': chapter,
'industries': industries,
'classifications': classifications,
'is_admin': is_admin,
'base_template': base_template,
})
Expand All @@ -109,9 +124,15 @@ def add_profile(request, username, dashboard=0):
except Exception as e:
chapters = ChapterName.objects.all()

# Add these querysets
industries = Industry.objects.all().order_by('name')
classifications = Classification.objects.all().order_by('name')

return render(request, 'Profile/add_profile.html', {
'data': profile,
'chapter': chapters,
'industries': industries,
'classifications': classifications,
'is_admin': is_admin,
'error': True,
'base_template': base_template,
Expand Down Expand Up @@ -446,6 +467,7 @@ def view_profile(request, username):
# Add these counts
connection_count = user.connections.count() if hasattr(user, 'connections') else 0
testimonial_count = user.received_testimonials.count() if hasattr(user, 'received_testimonials') else 0
base_template = 'admin_base.html' if is_admin_user(request.user) else 'base.html'

return render(request, 'Profile/view_profile.html', {
'username': username,
Expand All @@ -457,5 +479,6 @@ def view_profile(request, username):
'gallery': gallery,
'connection_count': connection_count,
'testimonial_count': testimonial_count,
'base_template': base_template,
})

Binary file modified base/views/__pycache__/common.cpython-312.pyc
Binary file not shown.
Binary file modified base/views/__pycache__/connections.cpython-312.pyc
Binary file not shown.
9 changes: 0 additions & 9 deletions base/views/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,13 +276,6 @@ def common_data(request):
contact = 1
except ContactDetails.DoesNotExist:
contact = 0

try:
bio = Bio.objects.get(user=current_user)

bio = 1
except Bio.DoesNotExist:
bio = 0

print(renewal_message, days_left_for_renewal)

Expand All @@ -296,7 +289,6 @@ def common_data(request):
'days_left_for_renewal': days_left_for_renewal, # Add days left to context
'usr_img':usr_img,
'main_profile': main_profile,
'bio': bio,
'contact': contact,
'is_admin': 1 if is_admin else 0
})
Expand All @@ -310,7 +302,6 @@ def common_data(request):
'days_left_for_renewal': 0, # No days left calculation for unauthenticated users
'usr_img': 'none',
'main_profile': None,
'bio': None,
'contact': None,
'is_admin': is_admin
})
Expand Down
1 change: 0 additions & 1 deletion base/views/contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from django.conf import settings
from base.models import ContactFormSubmission # Assuming you have a model to store form submissions

@login_required
def contact_form(request):
if request.method == "POST":
first_name = request.POST.get('first_name')
Expand Down
79 changes: 79 additions & 0 deletions base/views/industry_clasification.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
from django.shortcuts import render, get_object_or_404, redirect
from django.contrib.auth.decorators import login_required
from base.models import Industry, Classification

# Industry CRUD operations
@login_required
def industry_list(request):
industries = Industry.objects.all().order_by('name')
return render(request, 'base_profile/industry_list.html', {'industries': industries})

@login_required
def industry_detail(request, pk):
industry = get_object_or_404(Industry, pk=pk)
return render(request, 'base_profile/industry_detail.html', {'industry': industry})

@login_required
def industry_create(request):
if request.method == 'POST':
name = request.POST.get('name')
description = request.POST.get('description')
Industry.objects.create(name=name, description=description)
return redirect('industry_list')
return render(request, 'base_profile/industry_form.html')

@login_required
def industry_update(request, pk):
industry = get_object_or_404(Industry, pk=pk)
if request.method == 'POST':
industry.name = request.POST.get('name')
industry.description = request.POST.get('description')
industry.save()
return redirect('industry_list')
return render(request, 'base_profile/industry_form.html', {'industry': industry})

@login_required
def industry_delete(request, pk):
industry = get_object_or_404(Industry, pk=pk)
if request.method == 'POST':
industry.delete()
return redirect('industry_list')
return render(request, 'base_profile/industry_confirm_delete.html', {'industry': industry})

# Classification CRUD operations
@login_required
def classification_list(request):
classifications = Classification.objects.all().order_by('name')
return render(request, 'base_profile/classification_list.html', {'classifications': classifications})

@login_required
def classification_detail(request, pk):
classification = get_object_or_404(Classification, pk=pk)
return render(request, 'base_profile/classification_detail.html', {'classification': classification})

@login_required
def classification_create(request):
if request.method == 'POST':
name = request.POST.get('name')
description = request.POST.get('description')
Classification.objects.create(name=name, description=description)
return redirect('classification_list')
return render(request, 'base_profile/classification_form.html')

@login_required
def classification_update(request, pk):
classification = get_object_or_404(Classification, pk=pk)
if request.method == 'POST':
classification.name = request.POST.get('name')
classification.description = request.POST.get('description')
classification.save()
return redirect('classification_list')
return render(request, 'base_profile/classification_form.html', {'classification': classification})

@login_required
def classification_delete(request, pk):
classification = get_object_or_404(Classification, pk=pk)
if request.method == 'POST':
classification.delete()
return redirect('classification_list')
return render(request, 'base_profile/classification_confirm_delete.html', {'classification': classification})
Loading

0 comments on commit 96d424e

Please sign in to comment.