# Path: src/smriti/mails.py
# def sendgrid_mail(to, subject, content, asmid=False):
#     client = sendgrid.SendGridClient(settings.SENDGRID_API_KEY)
#     message = sendgrid.Mail()
# 
#     message.add_to("<"+to+">")
#     message.set_from("Student Website NITK <"+settings.EMAIL_HOST_USER+">")
#     message.set_subject(subject)
#     message.set_html(content)
# 
#     if type(asmid) == int:
#         message.smtpapi.set_asm_group_id(asmid)
# 
#     client.send(message)


from django.shortcuts import render, get_object_or_404, redirect
from django.views import generic
from django.contrib import auth, messages
from django.http import HttpResponseRedirect
from django.contrib.auth.decorators import login_required
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.core.urlresolvers import reverse
from django.conf import settings
from profiles.models import Profile
from profiles.forms import ProfileForm
from .models import *
from .mails import sendgrid_mail
from braces.views import LoginRequiredMixin
import django_rq
            return render(request,'smriti/index.html', {"errors":"Invalid Login Credentials. Please try again with correct credentials."})
    if request.method == 'GET':
        if request.user.is_authenticated():
            return HttpResponseRedirect('/smriti/home/')
        return render(request,'smriti/index.html')

@login_required
def homePage(request):
    testimonials = Testimonial.objects.filter(testimonial_to=request.user)
    profile = Profile.objects.get(user=request.user)
    return render(request,"smriti/home.html",{'testimonials':testimonials,'profile':profile})

def browsePage(request):
    final_years = Profile.objects.filter(rollno__contains="13")
    #cornercase = Profile.objects.filter(rollno="11IT26")
    ch = sort_by_rollno(final_years.filter(branch='CH'))
    co = sort_by_rollno(final_years.filter(branch='CO'))
    cv = sort_by_rollno(final_years.filter(branch='CV'))
    ec = sort_by_rollno(final_years.filter(branch='EC'))
    ee = sort_by_rollno(final_years.filter(branch='EE'))
    it = sort_by_rollno(final_years.filter(branch='IT'))
    me = sort_by_rollno(final_years.filter(branch='ME'))
    mn = sort_by_rollno(final_years.filter(branch='MN'))
    mt = sort_by_rollno(final_years.filter(branch='MT'))
    return render(request,"smriti/browse.html",{'ch':ch,
                                                'co':co,
                                                'cv':cv,
                                                'ec':ec,
                                                'ee':ee,
                                                'it':it,

# Path: src/smriti/mails.py
# def sendgrid_mail(to, subject, content, asmid=False):
#     client = sendgrid.SendGridClient(settings.SENDGRID_API_KEY)
#     message = sendgrid.Mail()
# 
#     message.add_to("<"+to+">")
#     message.set_from("Student Website NITK <"+settings.EMAIL_HOST_USER+">")
#     message.set_subject(subject)
#     message.set_html(content)
# 
#     if type(asmid) == int:
#         message.smtpapi.set_asm_group_id(asmid)
# 
#     client.send(message)


# Path: src/smriti/views.py
from django.shortcuts import render, get_object_or_404, redirect
from django.views import generic
from django.contrib import auth, messages
from django.http import HttpResponseRedirect
from django.contrib.auth.decorators import login_required
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
from django.core.urlresolvers import reverse
from django.conf import settings
from profiles.models import Profile
from profiles.forms import ProfileForm
from .models import *
from .mails import sendgrid_mail
from braces.views import LoginRequiredMixin
import django_rq

            return render(request,'smriti/index.html', {"errors":"Invalid Login Credentials. Please try again with correct credentials."})
    if request.method == 'GET':
        if request.user.is_authenticated():
            return HttpResponseRedirect('/smriti/home/')
        return render(request,'smriti/index.html')

@login_required
def homePage(request):
    testimonials = Testimonial.objects.filter(testimonial_to=request.user)
    profile = Profile.objects.get(user=request.user)
    return render(request,"smriti/home.html",{'testimonials':testimonials,'profile':profile})

def browsePage(request):
    final_years = Profile.objects.filter(rollno__contains="13")
    #cornercase = Profile.objects.filter(rollno="11IT26")
    ch = sort_by_rollno(final_years.filter(branch='CH'))
    co = sort_by_rollno(final_years.filter(branch='CO'))
    cv = sort_by_rollno(final_years.filter(branch='CV'))
    ec = sort_by_rollno(final_years.filter(branch='EC'))
    ee = sort_by_rollno(final_years.filter(branch='EE'))
    it = sort_by_rollno(final_years.filter(branch='IT'))
    me = sort_by_rollno(final_years.filter(branch='ME'))
    mn = sort_by_rollno(final_years.filter(branch='MN'))
    mt = sort_by_rollno(final_years.filter(branch='MT'))
    return render(request,"smriti/browse.html",{'ch':ch,
                                                'co':co,
                                                'cv':cv,
                                                'ec':ec,
                                                'ee':ee,
                                                'it':it,

                                                'me':me,