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

Refactor/simplified sign up #73

Open
wants to merge 2 commits into
base: master
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,5 @@ dump.rdb
celerybeat-schedule

.idea/

Pipfile
225 changes: 163 additions & 62 deletions AlumniConnect/forms.py

Large diffs are not rendered by default.

18 changes: 10 additions & 8 deletions AlumniConnect/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from django.views.generic.base import RedirectView

from os import listdir
from . import views
from . import views


favicon_view = RedirectView.as_view(url='/static/favicon.ico', permanent=True)
Expand All @@ -37,13 +37,16 @@
#path('account/reset_password/', views.ResetPasswordRequestView.as_view(), name="reset_password"),
path('logout/', LogoutView.as_view(), name='logout'),
path('register/', views.register, name='register'),
path('newregister/', views.new_register, name='new_register'),
re_path(r'^activate/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$', views.activate, name='activate'),
path('confirm/', TemplateView.as_view(template_name='AlumniConnect/confirm_email.html'), name = 'confirm'),
path('success/', TemplateView.as_view(template_name='AlumniConnect/account_success.html'), name = 'success'),
path('signup/', views.signup, name='signup'),
# path('newregister/', views.new_register, name='new_register'),
re_path(
r'^activate/(?P<uidb64>[0-9A-Za-z_\-]+)/(?P<token>[0-9A-Za-z]{1,13}-[0-9A-Za-z]{1,20})/$', views.activate, name='activate'),
path('confirm/', TemplateView.as_view(template_name='AlumniConnect/confirm_email.html'), name='confirm'),
path('success/', TemplateView.as_view(template_name='AlumniConnect/account_success.html'), name='success'),
re_path('^', include('django.contrib.auth.urls')),
path('password/', views.change_password, name='change_password'),
re_path(r'^profileedit/(?P<id>[0-9]+)/$', views.profileedit, name='profileedit'),
re_path(r'^profileedit/(?P<id>[0-9]+)/$',
views.profileedit, name='profileedit'),
path('profile/', include('applications.alumniprofile.urls')),
path('members/', include('applications.members.urls')),
path('events/', include('applications.events_news.urls')),
Expand All @@ -63,13 +66,12 @@
]

if settings.DEBUG:


import debug_toolbar
urlpatterns = [
path('__debug__/', include(debug_toolbar.urls)),
] + urlpatterns

admin.site.site_header = "IIITDMJ Alumni Association"
admin.site.site_title = "Alumni Association"
admin.site.index_title = "Alumni Association Admin"
55 changes: 46 additions & 9 deletions AlumniConnect/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
from django.contrib.auth.views import LoginView
from django.contrib.messages.views import SuccessMessageMixin

from .forms import RegisterForm, ProfileEdit, NewRegister
from .forms import RegisterForm, ProfileEdit, NewRegister, SignUp
from .token import account_activation_token
from applications.events_news.models import Event, Attendees
from applications.alumniprofile.models import Profile, Constants
from applications.alumniprofile.models import Profile, Constants, Batch
from applications.news.models import News
from applications.gallery.models import Album
from applications.geolocation.views import addPoints
Expand Down Expand Up @@ -49,7 +49,8 @@ def index(request):
news = News.objects.filter().order_by('-date')
# messages.success(request, 'Your password was successfully updated!')
events_to_display = list(chain(events, events_completed))[:3]
albums_list = Album.objects.order_by('-created').annotate(images_count=Count('albumimage'))[:3]
albums_list = Album.objects.order_by(
'-created').annotate(images_count=Count('albumimage'))[:3]
return render(request, "AlumniConnect/index.html",
{'name': sname, 'events': events_to_display, 'news': news, 'albums': albums_list})

Expand Down Expand Up @@ -84,7 +85,8 @@ def register(request):
batch = form.cleaned_data.get('batch')
branch = form.cleaned_data.get('branch')
programme = form.cleaned_data.get('programme')
l = Profile.objects.filter(batch=batch, programme=programme, branch=branch)
l = Profile.objects.filter(
batch=batch, programme=programme, branch=branch)
print('Testing output\n')
print(l)
check = True
Expand All @@ -94,10 +96,43 @@ def register(request):
return render(request, 'AlumniConnect/registration.html', {'form': form, 'check': check, 'l': l})


def signup(request):
if request.method == 'POST':
form = SignUp(request.POST)
if form.is_valid():

# CREATING THE USER FROM THE MODEL FORM DATA
user = form.save(commit=False)
user.username = form.cleaned_data.get('username')
user.email = str(form.cleaned_data.get('email'))
user.is_active = False
user.save()
# THEN CREATING THE PROFILE INSTANCE AND SAVING THE USER AND USER_TYPE
profile = Profile.objects.create(
roll_no=form.cleaned_data.get('username'),
email=form.cleaned_data.get('email'),
user_type=form.cleaned_data.get('user_type'),
user=user,
batch=Batch(2009),
)

profile.save()
messages.success(
request, f'Your account has been created! You are now able to log in')
return render(request, 'AlumniConnect/confirm_email.html')
# return HttpResponseRedirect('/')
else:
form = SignUp()
return render(request, 'AlumniConnect/signup.html', {'form': form})


def reg_no_gen(degree_, spec_, year):
degree = {"B.Tech": "1", "B.Des": '2', "M.Tech": '3', "M.Des": '4', "PhD": '5'}
spec = {"NA": '00', "CSE": "01", "ECE": "02", "ME": "03", "MT": "04", "NS": "05", "DS": "06"}
last_reg_no = Profile.objects.filter(year_of_admission=year).order_by('user__date_joined').last()
degree = {"B.Tech": "1", "B.Des": '2',
"M.Tech": '3', "M.Des": '4', "PhD": '5'}
spec = {"NA": '00', "CSE": "01", "ECE": "02",
"ME": "03", "MT": "04", "NS": "05", "DS": "06"}
last_reg_no = Profile.objects.filter(
year_of_admission=year).order_by('user__date_joined').last()
# print(last_reg_no)
new_reg_no = (int(str(last_reg_no.reg_no)[-4:]) + 1) if last_reg_no else 1
return degree[degree_] + spec[spec_] + str(year)[2:] + str(convert_int(new_reg_no, 4))
Expand All @@ -119,7 +154,8 @@ def new_register(request):
last_name = ""
# print (form.cleaned_data.get('date_of_joining'))
profile = form.save(commit=False)
profile.reg_no = reg_no_gen(profile.programme, profile.branch, profile.year_of_admission)
profile.reg_no = reg_no_gen(
profile.programme, profile.branch, profile.year_of_admission)
profile.country = request.POST['country']
profile.state = request.POST['state']
profile.city = request.POST['city']
Expand Down Expand Up @@ -190,7 +226,8 @@ def change_password(request):
if form.is_valid():
user = form.save()
update_session_auth_hash(request, user) # Important!
messages.success(request, 'Your password was successfully updated!')
messages.success(
request, 'Your password was successfully updated!')
return redirect('home')
else:
messages.error(request, 'Please correct the error below.')
Expand Down
50 changes: 36 additions & 14 deletions applications/alumniprofile/models.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
from django.contrib.auth.models import User
from django.db import models
from django.utils import timezone
import datetime, os
import datetime
import os
from django.db.models.signals import post_save, pre_save
from django.dispatch import receiver
from model_utils import FieldTracker
from time import strftime

# from .funcs import send_verification_email


class Constants:
USER_TYPE = (
('S', 'Student'),
('A', 'Alumni')
)

SEX_CHOICES = (
('M', 'Male'),
('F', 'Female'),
Expand Down Expand Up @@ -40,7 +47,8 @@ class Constants:
('Is Self Employed', 'Is Self Employed')
)

YEAR_OF_ADDMISSION = tuple((n, str(n)) for n in range(2005, datetime.datetime.now().year))
YEAR_OF_ADDMISSION = tuple((n, str(n))
for n in range(2005, datetime.datetime.now().year))


class Batch(models.Model):
Expand All @@ -60,40 +68,54 @@ class Profile(models.Model):
roll_no = models.IntegerField(primary_key=True)
email = models.EmailField(null=False, default="")
alternate_email = models.EmailField(null=True, blank=True)
year_of_admission = models.IntegerField(null=True, choices=Constants.YEAR_OF_ADDMISSION)
year_of_admission = models.IntegerField(
null=True, choices=Constants.YEAR_OF_ADDMISSION)
batch = models.ForeignKey(Batch, on_delete=models.CASCADE)
name = models.CharField(max_length=1000, default="", null=False)
fathers_name = models.CharField(max_length=1000, default="")
husbands_name = models.CharField(null=True, blank=True, max_length=1000, default="")
programme = models.CharField(max_length=1000, choices=Constants.PROG_CHOICES, null=False)
branch = models.CharField(choices=Constants.BRANCH, max_length=1000, null=False)
sex = models.CharField(max_length=2, choices=Constants.SEX_CHOICES, default='M')
husbands_name = models.CharField(
null=True, blank=True, max_length=1000, default="")
programme = models.CharField(
max_length=1000, choices=Constants.PROG_CHOICES, null=False)
branch = models.CharField(choices=Constants.BRANCH,
max_length=1000, null=False)
sex = models.CharField(
max_length=2, choices=Constants.SEX_CHOICES, default='M')
date_of_birth = models.DateField(default=datetime.date(1970, 1, 1))
current_address = models.TextField(max_length=1000, default="")
permanent_address = models.TextField(max_length=1000, blank=True, null=True)
permanent_address = models.TextField(
max_length=1000, blank=True, null=True)
mobile1 = models.BigIntegerField(null=True)
mobile2 = models.BigIntegerField(null=True, blank=True)
phone_no = models.BigIntegerField(null=True, blank=True)
working_status = models.CharField(max_length=1000, choices=Constants.WORKING_STATUS, default='1', null=False)
working_status = models.CharField(
max_length=1000, choices=Constants.WORKING_STATUS, default='1', null=False)
current_position = models.CharField(max_length=1000, null=True, blank=True)
current_organisation = models.CharField(max_length=1000, null=True, blank=True)
current_organisation = models.CharField(
max_length=1000, null=True, blank=True)
past_experience = models.IntegerField(null=True, blank=True)
current_course = models.CharField(null=True, blank=True, max_length=1000)
current_university = models.CharField(null=True, blank=True, max_length=1000)
current_university = models.CharField(
null=True, blank=True, max_length=1000)
city = models.CharField(null=True, max_length=1000, blank=True)
country = models.CharField(null=True, max_length=1000, blank=True)
state = models.CharField(null=True, max_length=1000, blank=True)
facebook = models.URLField(null=True, blank=True, default="www.facebook.com")
linkedin = models.URLField(null=True, blank=True, default="www.linkedin.com")
facebook = models.URLField(
null=True, blank=True, default="www.facebook.com")
linkedin = models.URLField(
null=True, blank=True, default="www.linkedin.com")
instagram = models.CharField(null=True, blank=True, max_length=1000)
website = models.URLField(null=True, blank=True)
profile_picture = models.ImageField(null=True, upload_to=upload_photo)
is_verified = models.BooleanField(default=True)
date_of_joining = models.DateField(null=True, blank=True, default=datetime.date.today)
date_of_joining = models.DateField(
null=True, blank=True, default=datetime.date.today)
reg_no = models.BigIntegerField(null=True, default=0, editable=False)
mail_sent = models.BooleanField(default=False)
verify = models.BooleanField(null=True)
mail_sent_tracker = FieldTracker(fields=['verify'])
user_type = models.CharField(
max_length=2, choices=Constants.USER_TYPE, default='A')

def __str__(self):
return self.name
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
amqp==2.5.2
anyjson==0.3.3
anyjson
astroid==2.1.0
beautifulsoup4==4.6.0
billiard==3.6.1.0
Expand Down
64 changes: 64 additions & 0 deletions templates/AlumniConnect/signup.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{% extends 'globals/base.html' %}
{% load static %}
{% load crispy_forms_tags %}
{% block title %}
AlumniConnect - Login
{% endblock %}

{% block body %}
{% include 'globals/navbar.html' %}
<div class="p-0 m-0 masthead-bg w-100 h-100 parallax" style="min-height:300px !important; height:300px !important; background-position-y: 300px;"></div>

<header class="masthead text-center text-white d-flex" style="height:0px; min-height:300px;">
<div class="container my-auto" style="margin-bottom:50px !important;">
<div class="row">
<div class="col-lg-2 mx-auto align-middle">
<h2 class="text-uppercase">
<a href="{% url 'home' %}"><img src="{% static 'AluminiConnect/img/logo/alumb1.png' %}" style="width: 4em; height: auto;"></a>
</h2>
</div>
<div class="col-lg-8 mx-auto align-middle">
<h1 class="text-uppercase mt-4">
<strong>STUDENT ALUMNI CELL</strong>
</h1>
</div>
</div>
</div>
</header>

<section id="services" class="bg-primary p-1">
</section>

<div class="bg-white">
<div class="login-container container text-left p-2 mx-auto">
<div class="card shadow m-4 bg-light">
<div class="col-lg-12 mx-auto">
<div class="row text-center">
<div class="col-lg-12 text-primary pt-4 mt-4">
<h2>SIGN UP</h2>
<hr class="mb-4">
</div>
</div>
<div class="row text-center mb-4 py-4 justify-content-center">
<div class="col-sm-11 col-md-10 col-lg-9">
{% if messages %}

{% for message in messages %}
<p class="alert alert-danger">{{message}}</p>

{% endfor %}

{% endif %}
<form method="POST" style="width:100%">
{% csrf_token %}
{{ form|crispy }}
<button class="btn btn-primary px-5 py-2" type="submit" value="signup" name="submit">Sign Up</button>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
{% include 'globals/footer.html' %}
{% endblock %}
12 changes: 8 additions & 4 deletions templates/globals/navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<nav class="navbar navbar-expand-lg navbar-light fixed-top navbar-shrink" id="mainNav">
<div class="container">
<a class="navbar-brand js-scroll-trigger" href="{% url 'home' %}">
<img src="{% static 'AlumniConnect/img/logo-min.png' %}" class="h-100" style="max-height:30px">
<img src="{% static 'AluminiConnect/img/logo-min.png' %}" class="h-100" style="max-height:30px">
Alumni Connect
</a>
<button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
Expand Down 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' %}">Sign Up</a>
</li>
{% else %}
<li class="nav-item">
Expand All @@ -89,11 +89,15 @@
{% if user.is_superuser %}
<a class="btn btn-dark btn-xl js-scroll-trigger text-white" style="padding: .5rem 1rem;" href="{% url 'adminportal:index' %}">Admin</a>
{% else %}
<a class="btn btn-dark btn-xl js-scroll-trigger text-white" style="padding: .5rem 1rem;" href="{% url 'profile:profile' username=user.username %}">Profile</a>
{% if user.first_name %}
<a class="btn btn-success btn-xl js-scroll-trigger text-white" style="padding: .5rem 1rem;" href="{% url 'profile:profile' username=user.username %}">Profile</a>
{% else %}
<a class="btn btn-warning btn-xl js-scroll-trigger text-white" style="padding: .5rem 1rem;" href="{% url 'profile_completion'%}">Incomplete</a>
{% endif %}
{% endif %}
</li>
{% endif %}
</ul>
</div>
</div>
</nav>
</nav>