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

Issuing Digital Certificate #761

Open
wants to merge 90 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
d59cc55
Added smtp values
WISE-ELITE-2K18 Sep 13, 2020
a094f02
Created yaksh.tex for certificate
WISE-ELITE-2K18 Sep 13, 2020
d50168b
Rename .sampleenv to .env
WISE-ELITE-2K18 Sep 13, 2020
2f648b7
Update .env
WISE-ELITE-2K18 Sep 13, 2020
25aa575
Created mail_certificate()
WISE-ELITE-2K18 Sep 13, 2020
023f7cc
Added image certificate backgroung
WISE-ELITE-2K18 Sep 13, 2020
c6dff10
Added Fossee logo
WISE-ELITE-2K18 Sep 13, 2020
42ff715
Update yaksh.tex
WISE-ELITE-2K18 Sep 13, 2020
0efbede
Update yaksh.tex
WISE-ELITE-2K18 Sep 13, 2020
9e001a9
Updated Coursestatus in views
WISE-ELITE-2K18 Sep 13, 2020
57dcf54
Updated view_module in views
WISE-ELITE-2K18 Sep 13, 2020
06e7949
Created column certificate in courseStatus Table
WISE-ELITE-2K18 Sep 13, 2020
9cb5d28
Update course_modules.html
WISE-ELITE-2K18 Sep 13, 2020
08f4485
Update quizzes_user.html
WISE-ELITE-2K18 Sep 13, 2020
25cacf6
Update models.py
WISE-ELITE-2K18 Sep 14, 2020
b00c260
Update send_emails.py
WISE-ELITE-2K18 Sep 14, 2020
2fb4947
removed whitespace
WISE-ELITE-2K18 Sep 14, 2020
fe67a3d
Changed smtp_backend, host user and password
WISE-ELITE-2K18 Sep 14, 2020
815dd60
Update and rename .env to .sampleenv
WISE-ELITE-2K18 Sep 14, 2020
0ecdc45
removed extralines and print statements
WISE-ELITE-2K18 Sep 14, 2020
d18190c
Added if condition
WISE-ELITE-2K18 Sep 14, 2020
a22c3db
Removed extra lines
WISE-ELITE-2K18 Sep 14, 2020
08db834
Update settings.py
WISE-ELITE-2K18 Sep 14, 2020
4df24c8
used models.BooleanField to certificate
WISE-ELITE-2K18 Sep 14, 2020
e98e238
changed get_certificateStatus() typr to bool
WISE-ELITE-2K18 Sep 14, 2020
c7befbb
Changed certificate Status to bool
WISE-ELITE-2K18 Sep 14, 2020
d523d6c
Included pdflatex in requirements
WISE-ELITE-2K18 Sep 14, 2020
e77af6e
Added jinja2 to requirements
WISE-ELITE-2K18 Sep 14, 2020
e1981e2
removed spaces
WISE-ELITE-2K18 Sep 14, 2020
a7ffdde
removed spaces in send_emails
WISE-ELITE-2K18 Sep 14, 2020
c2d86e6
Update send_emails.py
WISE-ELITE-2K18 Sep 14, 2020
fe0bad3
Update quizzes_user.html
WISE-ELITE-2K18 Sep 14, 2020
117cbe2
Update views.py
WISE-ELITE-2K18 Sep 14, 2020
64ccd78
Update views.py
WISE-ELITE-2K18 Sep 14, 2020
7650834
Update views.py
WISE-ELITE-2K18 Sep 14, 2020
96b7db1
Update views.py
WISE-ELITE-2K18 Sep 14, 2020
d475062
Update views.py
WISE-ELITE-2K18 Sep 14, 2020
4739f5a
Update views.py
WISE-ELITE-2K18 Sep 14, 2020
e792016
Update views.py
WISE-ELITE-2K18 Sep 14, 2020
1bf1f2e
Update send_emails.py
WISE-ELITE-2K18 Sep 14, 2020
42937b3
Update tests.py
WISE-ELITE-2K18 Sep 14, 2020
e2054a4
Update tests.py
WISE-ELITE-2K18 Sep 14, 2020
f91bcb5
Update tests.py
WISE-ELITE-2K18 Sep 14, 2020
771a975
Update tests.py
WISE-ELITE-2K18 Sep 14, 2020
fc51cdb
Update tests.py
WISE-ELITE-2K18 Sep 14, 2020
b26dd09
Update views.py
WISE-ELITE-2K18 Sep 14, 2020
6d11f5f
Update tests.py
WISE-ELITE-2K18 Sep 14, 2020
968fca4
Changed test.py to previous one
WISE-ELITE-2K18 Sep 14, 2020
d5ff608
Update tests.py
WISE-ELITE-2K18 Sep 14, 2020
ba7509d
Update tests.py
WISE-ELITE-2K18 Sep 14, 2020
56fe9bd
Added pylatex in requirements
WISE-ELITE-2K18 Sep 15, 2020
ba4a538
Update tests.py
WISE-ELITE-2K18 Sep 15, 2020
6225fbe
Update tests.py
WISE-ELITE-2K18 Sep 15, 2020
fb59470
removed pylatex
WISE-ELITE-2K18 Sep 15, 2020
744e0e7
Update quizzes_user.html
WISE-ELITE-2K18 Sep 15, 2020
e6763cc
Update quizzes_user.html
WISE-ELITE-2K18 Sep 15, 2020
0751a07
Added test completed condition
WISE-ELITE-2K18 Sep 15, 2020
75e9902
Applied Indentation in course_modules
WISE-ELITE-2K18 Sep 15, 2020
f016f3b
removed else
WISE-ELITE-2K18 Sep 15, 2020
268eec0
Change email_host,email_port
WISE-ELITE-2K18 Sep 15, 2020
769b894
Update settings.py
WISE-ELITE-2K18 Sep 15, 2020
86edba6
Update .sampleenv
WISE-ELITE-2K18 Sep 15, 2020
b61cce6
removed bool in set_certificateStatus
WISE-ELITE-2K18 Sep 17, 2020
c6d8498
Update models.py
WISE-ELITE-2K18 Sep 17, 2020
fe31580
Update tests.py
WISE-ELITE-2K18 Sep 17, 2020
70a1be9
Update models.py
WISE-ELITE-2K18 Sep 17, 2020
df3bd08
Update tests.py
WISE-ELITE-2K18 Sep 17, 2020
1151b20
Update tests.py
WISE-ELITE-2K18 Sep 17, 2020
7153c81
Update models.py
WISE-ELITE-2K18 Sep 17, 2020
6283e93
Update models.py
WISE-ELITE-2K18 Sep 17, 2020
89717f6
Update tests.py
WISE-ELITE-2K18 Sep 17, 2020
5ccd32f
removed loader in views
WISE-ELITE-2K18 Sep 17, 2020
bf166e0
removed special_start()
WISE-ELITE-2K18 Sep 17, 2020
249ed36
Update views.py
WISE-ELITE-2K18 Sep 17, 2020
509f3a6
removed trailing white spaces
WISE-ELITE-2K18 Sep 17, 2020
091113e
Added loader in views
WISE-ELITE-2K18 Sep 17, 2020
a6b297d
images moved to certificate_images
WISE-ELITE-2K18 Sep 17, 2020
524201a
certificates moved to folder certificate_images
WISE-ELITE-2K18 Sep 17, 2020
1f1adba
Added path to images in tex file
WISE-ELITE-2K18 Sep 17, 2020
40a5b11
Updated username in views
WISE-ELITE-2K18 Sep 17, 2020
6d8c8ba
added pymysql and new column
WISE-ELITE-2K18 Sep 17, 2020
bb94d37
added PyMySQL
WISE-ELITE-2K18 Sep 17, 2020
4f40b28
removed last migration
WISE-ELITE-2K18 Sep 17, 2020
96b69ee
pymysql
WISE-ELITE-2K18 Sep 17, 2020
f6b09d0
Update models.py
WISE-ELITE-2K18 Sep 18, 2020
3d20c06
Update models.py
WISE-ELITE-2K18 Sep 18, 2020
43169f1
Update models.py
WISE-ELITE-2K18 Sep 20, 2020
1a9be04
Update tests.py
WISE-ELITE-2K18 Sep 20, 2020
2c975fa
Update tests.py
WISE-ELITE-2K18 Sep 20, 2020
83d1c7d
Update tests.py
WISE-ELITE-2K18 Sep 20, 2020
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
Binary file added certificate_images/certificate_bg.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added certificate_images/fossee_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions requirements/requirements-common.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ django-celery-results==1.2.1
djangorestframework==3.11.0
django-cors-headers==3.1.0
Pillow
pdflatex
jinja2
105 changes: 105 additions & 0 deletions yaksh.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@


\documentclass[20pt, a4paper]{extarticle}

\usepackage{extsizes}

\usepackage[T1]{fontenc}

\usepackage{amsmath}

\usepackage{graphicx}

\usepackage[margin=17mm,landscape]{geometry}

\usepackage{times}

\usepackage[onehalfspacing]{setspace}

\usepackage{eso-pic}

\usepackage{ragged2e}

\setlength{\parindent}{0pt}



\begin{document}

\pagestyle{empty}

\AddToShipoutPictureBG*{\includegraphics[width=\paperwidth, height=\paperheight]{certificate_images/certificate_bg.jpg}}







\begin{minipage}{\linewidth}



\hspace{18 cm}

\includegraphics[scale = 0.7]{certificate_images/fossee_logo.png}

\centering \large \bfseries

{\Huge

\vskip2cm \color{blue!50!black} \hspace{2cm} $\boldsymbol{\mathrm { Certificate \ Of\ Completion}}$ }

\end{minipage}



\vskip2.5cm

\doublespacing

\RaggedRight

{ \normalsize

\fontfamily{qcs}\selectfont



\normalsize \emph{{\hspace{4cm} This is to certify that {\color {blue!50!black} \VAR{name} }has successfully completed a course on { \color{blue!50!black} \VAR{course}}. This course was offered by the {\color{red!50!black} FOSSEE Project, IIT Bombay,} funded by National Mission on Education through ICT, MHRD, Govt.of India.

}}}







\singlespacing

\small





\hspace{3 cm}

\vskip1cm

\begin{minipage}{0.2\linewidth}

\centering

\rule{5cm}{1pt}\\

Dr. XXXXX\\

\end{minipage}\hfill





\end{document}
8 changes: 8 additions & 0 deletions yaksh/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1184,6 +1184,7 @@ class CourseStatus(models.Model):
grade = models.CharField(max_length=255, null=True, blank=True)
percentage = models.FloatField(default=0.0)
percent_completed = models.IntegerField(default=0)
certificate = models.BooleanField(default=False)

def get_grade(self):
return self.grade
Expand All @@ -1201,6 +1202,13 @@ def set_grade(self):
self.grade = grade
self.save()

def get_certificateStatus(self):
return self.certificate

def set_certificateStatus(self):
self.certificate = True
WISE-ELITE-2K18 marked this conversation as resolved.
Show resolved Hide resolved
self.save()

def calculate_percentage(self):
quizzes = self.course.get_quizzes()
if self.is_course_complete() and quizzes:
Expand Down
11 changes: 10 additions & 1 deletion yaksh/send_emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# Django imports
from django.utils.crypto import get_random_string
from django.conf import settings
from django.core.mail import EmailMultiAlternatives, send_mail
from django.core.mail import EmailMultiAlternatives, send_mail, EmailMessage
from django.core.files.storage import default_storage
from django.core.files.base import ContentFile

Expand Down Expand Up @@ -88,3 +88,12 @@ def send_bulk_mail(subject, email_body, recipients, attachments):
Please contact {1}.""".format(exc_msg, settings.REPLY_EMAIL)

return message


def mail_certificate(send_to):
email = EmailMessage('Certificate',
'Congrats!! You successfully completed the course',
settings.EMAIL_HOST_USER,
[send_to, ], )
email.attach_file('certificate.pdf')
email.send()
2 changes: 1 addition & 1 deletion yaksh/templates/yaksh/course_modules.html
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
{% get_module_status user module course as module_status %}
{% if module_status == "completed" %}
<div class="btn btn-info ">
View
Get Certificate
</div>
{% elif module_status == "inprogress" %}
<div class="btn btn-primary">
Expand Down
7 changes: 5 additions & 2 deletions yaksh/templates/yaksh/quizzes_user.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ <h2>{{title}}</h2>
Request Rejected
</span>
{% elif user in course.data.students.all %}
{% if course.completion_percentage > 0 %}
{% if course.completion_percentage == 100 %}
<a class="btn btn-primary" href="{% url 'yaksh:course_modules' course.data.id %}" >
Completed
</a>
{% elif course.completion_percentage > 0 %}
<a class="btn btn-primary" href="{% url 'yaksh:course_modules' course.data.id %}" >
Continue
</a>
Expand Down Expand Up @@ -168,4 +172,3 @@ <h2>{{title}}</h2>
</div>

{% endblock %}

52 changes: 45 additions & 7 deletions yaksh/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,33 @@
from .settings import URL_ROOT
from .file_utils import extract_files, is_csv
from .send_emails import (send_user_mail,
generate_activation_key, send_bulk_mail)
generate_activation_key,
send_bulk_mail,
mail_certificate)
from .decorators import email_verified, has_profile
from .tasks import regrade_papers
from notifications_plugin.models import Notification
from django.shortcuts import render
from online_test.settings import EMAIL_HOST_USER, EMAIL_HOST_PASSWORD
from django.template.loader import get_template
from django.shortcuts import redirect
from django.http import HttpResponse
from yaksh.models import CourseStatus
from pdflatex import PDFLaTeX
import jinja2
from django.contrib import messages
latex_jinja_env = jinja2.Environment(
block_start_string='\\BLOCK{',
block_end_string='}',
variable_start_string='\\VAR{',
variable_end_string='}',
comment_start_string='\\#{',
comment_end_string='}',
line_statement_prefix='%-',
line_comment_prefix='%#',
trim_blocks=True,
autoescape=False,
loader=jinja2.FileSystemLoader(os.path.abspath('.')))


def my_redirect(url):
Expand Down Expand Up @@ -492,27 +515,22 @@ def special_start(request, micromanager_id=None):
quiz = micromanager.quiz
module = course.get_learning_module(quiz)
quest_paper = get_object_or_404(QuestionPaper, quiz=quiz)

if not course.is_enrolled(user):
msg = 'You are not enrolled in {0} course'.format(course.name)
return quizlist_user(request, msg=msg)

if not micromanager.can_student_attempt():
msg = 'Your special attempts are exhausted for {0}'.format(
quiz.description)
return quizlist_user(request, msg=msg)

last_attempt = AnswerPaper.objects.get_user_last_attempt(
quest_paper, user, course.id)

if last_attempt:
if last_attempt.is_attempt_inprogress():
return show_question(
request, last_attempt.current_question(), last_attempt,
course_id=course.id, module_id=module.id,
previous_question=last_attempt.current_question()
)

attempt_num = micromanager.get_attempt_number()
ip = request.META['REMOTE_ADDR']
new_paper = quest_paper.make_answerpaper(user, ip, attempt_num, course.id,
Expand Down Expand Up @@ -1965,7 +1983,7 @@ def grade_user(request, quiz_id=None, user_id=None, attempt_number=None,
for paper in papers:
for question, answers in paper.get_question_answers().items():
marks = float(request.POST.get('q%d_marks' % question.id, 0))
answer = answers[-1]['answer']
answer = answers[0]['answer']
answer.set_marks(marks)
answer.save()
paper.update_marks()
Expand Down Expand Up @@ -3106,6 +3124,26 @@ def view_module(request, module_id, course_id, msg=None):
context['course'] = course
context['state'] = "module"
context['msg'] = msg
course_status = CourseStatus.objects.filter(
course_id=course.id, user_id=user.id)
if course.percent_completed(user, all_modules) == 100:
if course_status.first().get_certificateStatus() is False:
template = latex_jinja_env.get_template('yaksh.tex')
full_name = user.get_full_name()
document = template.render(name=full_name, course=course)
with open('certificate.tex', 'w') as output:
output.write(document)

os.system("pdflatex certificate.tex")
mail_certificate(user.email)
course_status.first().set_certificateStatus()
msg = 'Your course certificate sent to your registeres mail Id'
messages.success(request, msg)
return redirect('/')
else:
msg = 'You already recieved certificate, kindly check your mail'
messages.warning(request, msg)
return redirect('/')
return my_render_to_response(request, 'yaksh/show_video.html', context)


Expand Down