diff --git a/AlumniConnect/decorators.py b/AlumniConnect/decorators.py index b5b7269a..18976272 100644 --- a/AlumniConnect/decorators.py +++ b/AlumniConnect/decorators.py @@ -12,9 +12,9 @@ def wrapper(request,*args, **kwargs): user = request.user if not (user.is_authenticated): return HttpResponseRedirect('/') # case when user is not logged in - elif (not user.profile.verify) and ( user.is_authenticated == True): + elif (not user.profile.verify) and (user.is_authenticated == True) and (request.path != '/complete_profile/'): return HttpResponseRedirect('/complete_profile/') # case when user is logged in but haven't completed profile as after completing profile only user will be able to login else: return function(request,*args,**kwargs) - return wrapper \ No newline at end of file + return wrapper diff --git a/AlumniConnect/forms.py b/AlumniConnect/forms.py index 7889e81a..b6e379c8 100644 --- a/AlumniConnect/forms.py +++ b/AlumniConnect/forms.py @@ -417,7 +417,6 @@ class PasswordResetRequestForm(forms.Form): class SignupForm(forms.ModelForm): - role = forms.ChoiceField(choices=Constants.ROLE_CHOICES) confirm_password = forms.CharField(widget=forms.PasswordInput()) class Meta: @@ -472,7 +471,7 @@ class CompleteProfileForm(forms.ModelForm): class Meta: model = Profile fields = '__all__' - exclude = ('user','role',) + exclude = ('user',) def clean_roll_no(self): @@ -499,4 +498,4 @@ def clean_email(self): return email - \ No newline at end of file + diff --git a/AlumniConnect/views.py b/AlumniConnect/views.py index 736de983..afb3ab53 100644 --- a/AlumniConnect/views.py +++ b/AlumniConnect/views.py @@ -119,7 +119,6 @@ def signup(request): if request.method == "POST": form = SignupForm(request.POST) if form.is_valid(): - role = request.POST['role'] roll_no = request.POST['username'] # username and roll_no are same # user created using form @@ -131,7 +130,7 @@ def signup(request): ) # now making profile for user - profile = Profile(user=user, roll_no=roll_no, role=role) + profile = Profile(user=user, roll_no=roll_no) profile.save() # sending mail for activation @@ -163,6 +162,7 @@ def signup(request): return render(request, "AlumniConnect/signup.html", {'form': form}) +@custom_login_required def complete_profile(request): user = request.user @@ -172,6 +172,12 @@ def complete_profile(request): except: # admin does not have any profile return redirect('home') + try: + # if profile is already completed then redirect to home + if profile.verify: + return redirect('home') + except: + pass #creating context for form diff --git a/applications/adminportal/views.py b/applications/adminportal/views.py index 50688bb1..9d855371 100644 --- a/applications/adminportal/views.py +++ b/applications/adminportal/views.py @@ -96,8 +96,14 @@ def registrations_index(request): messages.add_message(request, messages.ERROR, err) return redirect('adminportal:registrations') + query = request.GET.get('q', '') unregistered = Profile.objects.filter(verify=None).filter(mail_sent=False).order_by('-user__date_joined') + if query: + if query == 'students': + unregistered = unregistered.filter(batch__isActive=True) + elif query == 'alumni': + unregistered = unregistered.filter(batch__isActive=False) context = { 'pending': unregistered @@ -120,7 +126,7 @@ def mailservice_index(request): programme = request.POST['programme'] batch = request.POST['batch'] branch = request.POST['branch'] - + role = request.POST['role'] template = EmailTemplate.objects.get(template_id=template_id) recipients = Profile.objects.all() @@ -130,6 +136,11 @@ def mailservice_index(request): recipients = recipients.filter(batch__batch=batch) if branch: recipients = recipients.filter(branch=branch) + if role: + if role == 'A': + recipients = recipients.filter(batch__isActive=False) + elif role == 'S': + recipients = recipients.filter(batch__isActive=True) total_recipients = recipients.count() if total_recipients == 0: diff --git a/applications/alumniprofile/admin.py b/applications/alumniprofile/admin.py index 42621bb4..02ce6a46 100644 --- a/applications/alumniprofile/admin.py +++ b/applications/alumniprofile/admin.py @@ -4,6 +4,46 @@ from django.http import HttpResponse from django.core.exceptions import PermissionDenied import csv +from django.utils.translation import gettext_lazy as _ + + +class RoleWiseFilter(admin.SimpleListFilter): + # Human-readable title which will be displayed in the + # right admin sidebar just above the filter options. + title = _('role') + + # Parameter for the filter that will be used in the URL query. + parameter_name = 'role' + + def lookups(self, request, model_admin): + """ + Returns a list of tuples. The first element in each + tuple is the coded value for the option that will + appear in the URL query. The second element is the + human-readable name for the option that will appear + in the right sidebar. + """ + return ( + ('A', _('Alumni')), + ('S', _('Students')), + ) + + def queryset(self, request, queryset): + """ + Returns the filtered queryset based on the value + provided in the query string and retrievable via + `self.value()`. + """ + # Compare the requested value (either '80s' or '90s') + # to decide how to filter the queryset. + if self.value() == 'A': + return queryset.filter( + batch__isActive=False + ) + if self.value() == 'S': + return queryset.filter( + batch__isActive=True + ) class ProfileAdmin(admin.ModelAdmin): @@ -15,11 +55,12 @@ class ProfileAdmin(admin.ModelAdmin): ordering = [('-user__date_joined'), ] search_fields = ['name', '^roll_no', '^year_of_admission', '^reg_no', '^programme', '^branch', '^city'] actions = ['download_csv'] - list_filter = ('batch__batch', 'programme', 'branch',) + list_filter = ('batch__batch', 'programme', + 'branch', RoleWiseFilter,) fieldsets = ( (None, { - 'fields': ('user', 'role', 'updated_at') + 'fields': ('user', 'updated_at') }), ('Institute Details', { 'fields': ('roll_no', 'year_of_admission', 'batch', 'programme', 'branch') diff --git a/applications/alumniprofile/models.py b/applications/alumniprofile/models.py index 89158cfe..f3e0389b 100644 --- a/applications/alumniprofile/models.py +++ b/applications/alumniprofile/models.py @@ -67,7 +67,7 @@ class Constants: class Batch(models.Model): batch = models.IntegerField(primary_key=True) - + isActive = models.BooleanField(default=False) def __str__(self): return str(self.batch) @@ -79,7 +79,6 @@ def upload_photo(instance, filename): class Profile(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE) - role = models.CharField(max_length=2, choices=Constants.ROLE_CHOICES, default='A') # Institute Details roll_no = models.CharField(primary_key=True, max_length=15) diff --git a/scripts/add_batch.py b/scripts/add_batch.py index 4e7543c7..7b099a3d 100644 --- a/scripts/add_batch.py +++ b/scripts/add_batch.py @@ -1,5 +1,8 @@ from applications.alumniprofile.models import Batch - -for num in range(2009, 2023): - b1 = Batch(batch = num) - b1.save() \ No newline at end of file +import datetime +current_time = datetime.datetime.now() +for num in range(2009, 2024): + isActive = current_time.year() < num or ( + current_time.year == num and current_time.month < 6) + b1 = Batch(batch=num, isActive=isActive) + b1.save() diff --git a/templates/AlumniConnect/login.html b/templates/AlumniConnect/login.html index c55e74d5..c8bf71de 100644 --- a/templates/AlumniConnect/login.html +++ b/templates/AlumniConnect/login.html @@ -34,7 +34,7 @@

- +
+ autocomplete="off" />
+ autocomplete="off" />
+ autocomplete="off" />
diff --git a/templates/AlumniConnect/signup.html b/templates/AlumniConnect/signup.html index fcf97cb9..f0837c69 100644 --- a/templates/AlumniConnect/signup.html +++ b/templates/AlumniConnect/signup.html @@ -97,14 +97,7 @@

SIGN UP

placeholder="Confirm Password" aria-label="Password" aria-describedby="button-addon2" required> {{ form.confirm_password.errors }}
-
- - -
- +
diff --git a/templates/adminportal/mailservice.html b/templates/adminportal/mailservice.html index f2bde8bd..1d8285a6 100644 --- a/templates/adminportal/mailservice.html +++ b/templates/adminportal/mailservice.html @@ -9,7 +9,7 @@ {% include 'globals/navbar.html' %} {% include 'adminportal/masthead.html' %} -
+
@@ -71,6 +71,14 @@ {% endfor %}
+
+ + +
diff --git a/templates/adminportal/registrations.html b/templates/adminportal/registrations.html index e91c97d6..41acf6fe 100644 --- a/templates/adminportal/registrations.html +++ b/templates/adminportal/registrations.html @@ -52,9 +52,14 @@ {% endif %} {% endfor %} {% endif %} - +

Pending Registrations ({{ pending|length }})

- +
+ All + Students + Alumni +
+
{% for profile in pending %}
diff --git a/templates/globals/navbar.html b/templates/globals/navbar.html index 5affdb6c..10017763 100644 --- a/templates/globals/navbar.html +++ b/templates/globals/navbar.html @@ -79,7 +79,7 @@ Login {% else %}