Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

removed role from signup form and profile model, added filter for alumni and students in admin panel and mailer service #96

Open
wants to merge 4 commits into
base: new-signup-workflow
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions AlumniConnect/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
return wrapper
5 changes: 2 additions & 3 deletions AlumniConnect/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -472,7 +471,7 @@ class CompleteProfileForm(forms.ModelForm):
class Meta:
model = Profile
fields = '__all__'
exclude = ('user','role',)
exclude = ('user',)


def clean_roll_no(self):
Expand All @@ -499,4 +498,4 @@ def clean_email(self):

return email



10 changes: 8 additions & 2 deletions AlumniConnect/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
13 changes: 12 additions & 1 deletion applications/adminportal/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()

Expand 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:
Expand Down
45 changes: 43 additions & 2 deletions applications/alumniprofile/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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')
Expand Down
3 changes: 1 addition & 2 deletions applications/alumniprofile/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
Expand Down
11 changes: 7 additions & 4 deletions scripts/add_batch.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
from applications.alumniprofile.models import Batch

for num in range(2009, 2023):
b1 = Batch(batch = num)
b1.save()
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()
2 changes: 1 addition & 1 deletion templates/AlumniConnect/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ <h1 class="text-uppercase mt-4">
<div class="alert alert-primary m-4 text-center" role="alert" >
Please Sign In to Continue! Don't have an Account?
<h5 class="pt-2 m-0">
<a class="d-inline-block" href="{% url 'new_register' %}">
<a class="d-inline-block" href="{% url 'signup' %}">
<span class="badge badge-pill badge-primary p-2">Register! &nbsp;<i class="fas fa-external-link-alt"></i></span>
</a>
</h5>
Expand Down
8 changes: 4 additions & 4 deletions templates/AlumniConnect/profile_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -198,23 +198,23 @@ <h3 class="my-4 mx-0">
</div>

<div class="mb-3">
<label class="mb-3" for="working_status">Working Status <span class="asteriskField">*</span></label>
<label class="mb-3" for="working_status">Working Status</label>
<div class="mt-3 row">
<div class="col-sm-12 col-lg-4 m-auto">
<input type="radio" class="btn-check" name="working_status" value="Is Working" id="status1"
autocomplete="off" required />
autocomplete="off" />
<label class="btn btn-sm btn-outline-secondary" for="status1">Is Working
</label>
</div>
<div class="col-sm-12 col-lg-4 m-auto">
<input type="radio" class="btn-check" name="working_status" value="Is Pursuing Higher Studies" id="status2"
autocomplete="off" required />
autocomplete="off" />
<label class="btn btn-sm btn-outline-secondary" for="status2">Is Pursuing Higher Studies
</label>
</div>
<div class="col-sm-12 col-lg-4 m-auto">
<input type="radio" class="btn-check" name="working_status" value="Is Self Employed" id="status3"
autocomplete="off" required />
autocomplete="off" />
<label class="btn btn-sm btn-outline-secondary" for="status3">Is Self Employed
</label>
</div>
Expand Down
9 changes: 1 addition & 8 deletions templates/AlumniConnect/signup.html
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,7 @@ <h2>SIGN UP</h2>
placeholder="Confirm Password" aria-label="Password" aria-describedby="button-addon2" required>
{{ form.confirm_password.errors }}
</div>
<div class="form-group">
<label class="d-block text-left" for="signup-role">Registering as</label>
<select id="singup-role" name="role" class="custom-select">
<option value="A">Alumni</option>
<option value="S" {% if form.role.value == 'S' %}selected{%endif%}>Student</option>
</select>
</div>
<button class="btn btn-primary px-5 py-2" type="submit" value="login" name="submit">Sign In</button>
<button class="btn btn-primary px-5 py-2" type="submit" value="login" name="submit">Sign Up</button>
</form>
</div>
</div>
Expand Down
10 changes: 9 additions & 1 deletion templates/adminportal/mailservice.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
{% include 'globals/navbar.html' %}
{% include 'adminportal/masthead.html' %}

<section id="services" class="bg-primary p-1">
<section id="services" class="bg-primary p-1">
<div class="container my-auto">
<div class="row">
<div class="col-12 mx-auto align-middle text-center">
Expand Down Expand Up @@ -71,6 +71,14 @@
{% endfor %}
</select>
</div>
<div class="col-sm-6 col-lg-3 mb-3">
<label for="role">User Role</label>
<select name="role" class="form-control" id="branch">
<option value="">All</option>
<option value="A">Alumni</option>
<option value="S">Student</option>
</select>
</div>
</div>
<div class="row justify-content-center mt-3">
<button type="submit" class="col-6 col-sm-4 col-lg-3 btn btn-primary">Send Email</button>
Expand Down
9 changes: 7 additions & 2 deletions templates/adminportal/registrations.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,14 @@
{% endif %}
{% endfor %}
{% endif %}

<div class='d-flex p-2 justify-content-between'>
<h3>Pending Registrations ({{ pending|length }})</h3>

<div class='d-flex justify-content-between text-center gap-3 ' style='gap:1rem;'>
<a href="{% url 'adminportal:registrations' %}" class="btn btn-light" tabindex="-1" role="button" aria-disabled="true">All</a>
<a href="{% url 'adminportal:registrations' %}?q=students" class="btn btn-light" tabindex="-1" role="button" aria-disabled="true">Students</a>
<a href="{% url 'adminportal:registrations' %}?q=alumni" class="btn btn-light" tabindex="-1" role="button" aria-disabled="true">Alumni</a>
</div>
</div>
{% for profile in pending %}
<div class="card mb-3">
<div class="row no-gutters">
Expand Down
2 changes: 1 addition & 1 deletion templates/globals/navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
<a class="nav-link js-scroll-trigger" href="{% url 'login' %}">Login</a>
</li>
<li class="nav-item">
<a class="btn btn-dark btn-xl js-scroll-trigger text-white" style="padding: .5rem 1rem;" href="{% url 'new_register' %}">Register</a>
<a class="btn btn-dark btn-xl js-scroll-trigger text-white" style="padding: .5rem 1rem;" href="{% url 'signup' %}">Register</a>
</li>
{% else %}
<li class="nav-item">
Expand Down