Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
ef82497e
Commit
ef82497e
authored
Jun 21, 2012
by
Bridger Maxwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
There is now a way to revoke certificates (and record the old certificate's information
parent
d35c7695
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
202 additions
and
8 deletions
+202
-8
djangoapps/certificates/migrations/0007_auto__add_revokedcertificate.py
+122
-0
djangoapps/certificates/models.py
+60
-0
djangoapps/certificates/views.py
+5
-7
djangoapps/student/views.py
+15
-1
No files found.
djangoapps/certificates/migrations/0007_auto__add_revokedcertificate.py
0 → 100644
View file @
ef82497e
# encoding: utf-8
import
datetime
from
south.db
import
db
from
south.v2
import
SchemaMigration
from
django.db
import
models
class
Migration
(
SchemaMigration
):
def
forwards
(
self
,
orm
):
# Adding model 'RevokedCertificate'
db
.
create_table
(
'certificates_revokedcertificate'
,
(
(
'id'
,
self
.
gf
(
'django.db.models.fields.AutoField'
)(
primary_key
=
True
)),
(
'explanation'
,
self
.
gf
(
'django.db.models.fields.TextField'
)(
blank
=
True
)),
(
'user'
,
self
.
gf
(
'django.db.models.fields.related.ForeignKey'
)(
to
=
orm
[
'auth.User'
])),
(
'name'
,
self
.
gf
(
'django.db.models.fields.CharField'
)(
max_length
=
255
,
blank
=
True
)),
(
'certificate_id'
,
self
.
gf
(
'django.db.models.fields.CharField'
)(
default
=
None
,
max_length
=
32
,
null
=
True
)),
(
'graded_certificate_id'
,
self
.
gf
(
'django.db.models.fields.CharField'
)(
default
=
None
,
max_length
=
32
,
null
=
True
)),
(
'download_url'
,
self
.
gf
(
'django.db.models.fields.CharField'
)(
max_length
=
128
,
null
=
True
)),
(
'graded_download_url'
,
self
.
gf
(
'django.db.models.fields.CharField'
)(
max_length
=
128
,
null
=
True
)),
(
'grade'
,
self
.
gf
(
'django.db.models.fields.CharField'
)(
max_length
=
5
,
null
=
True
)),
(
'enabled'
,
self
.
gf
(
'django.db.models.fields.BooleanField'
)(
default
=
False
)),
))
db
.
send_create_signal
(
'certificates'
,
[
'RevokedCertificate'
])
def
backwards
(
self
,
orm
):
# Deleting model 'RevokedCertificate'
db
.
delete_table
(
'certificates_revokedcertificate'
)
models
=
{
'auth.group'
:
{
'Meta'
:
{
'object_name'
:
'Group'
},
'id'
:
(
'django.db.models.fields.AutoField'
,
[],
{
'primary_key'
:
'True'
}),
'name'
:
(
'django.db.models.fields.CharField'
,
[],
{
'unique'
:
'True'
,
'max_length'
:
'80'
}),
'permissions'
:
(
'django.db.models.fields.related.ManyToManyField'
,
[],
{
'to'
:
"orm['auth.Permission']"
,
'symmetrical'
:
'False'
,
'blank'
:
'True'
})
},
'auth.permission'
:
{
'Meta'
:
{
'ordering'
:
"('content_type__app_label', 'content_type__model', 'codename')"
,
'unique_together'
:
"(('content_type', 'codename'),)"
,
'object_name'
:
'Permission'
},
'codename'
:
(
'django.db.models.fields.CharField'
,
[],
{
'max_length'
:
'100'
}),
'content_type'
:
(
'django.db.models.fields.related.ForeignKey'
,
[],
{
'to'
:
"orm['contenttypes.ContentType']"
}),
'id'
:
(
'django.db.models.fields.AutoField'
,
[],
{
'primary_key'
:
'True'
}),
'name'
:
(
'django.db.models.fields.CharField'
,
[],
{
'max_length'
:
'50'
})
},
'auth.user'
:
{
'Meta'
:
{
'object_name'
:
'User'
},
'about'
:
(
'django.db.models.fields.TextField'
,
[],
{
'blank'
:
'True'
}),
'avatar_type'
:
(
'django.db.models.fields.CharField'
,
[],
{
'default'
:
"'n'"
,
'max_length'
:
'1'
}),
'bronze'
:
(
'django.db.models.fields.SmallIntegerField'
,
[],
{
'default'
:
'0'
}),
'consecutive_days_visit_count'
:
(
'django.db.models.fields.IntegerField'
,
[],
{
'default'
:
'0'
}),
'country'
:
(
'django_countries.fields.CountryField'
,
[],
{
'max_length'
:
'2'
,
'blank'
:
'True'
}),
'date_joined'
:
(
'django.db.models.fields.DateTimeField'
,
[],
{
'default'
:
'datetime.datetime.now'
}),
'date_of_birth'
:
(
'django.db.models.fields.DateField'
,
[],
{
'null'
:
'True'
,
'blank'
:
'True'
}),
'display_tag_filter_strategy'
:
(
'django.db.models.fields.SmallIntegerField'
,
[],
{
'default'
:
'0'
}),
'email'
:
(
'django.db.models.fields.EmailField'
,
[],
{
'max_length'
:
'75'
,
'blank'
:
'True'
}),
'email_isvalid'
:
(
'django.db.models.fields.BooleanField'
,
[],
{
'default'
:
'False'
}),
'email_key'
:
(
'django.db.models.fields.CharField'
,
[],
{
'max_length'
:
'32'
,
'null'
:
'True'
}),
'email_tag_filter_strategy'
:
(
'django.db.models.fields.SmallIntegerField'
,
[],
{
'default'
:
'1'
}),
'first_name'
:
(
'django.db.models.fields.CharField'
,
[],
{
'max_length'
:
'30'
,
'blank'
:
'True'
}),
'gold'
:
(
'django.db.models.fields.SmallIntegerField'
,
[],
{
'default'
:
'0'
}),
'gravatar'
:
(
'django.db.models.fields.CharField'
,
[],
{
'max_length'
:
'32'
}),
'groups'
:
(
'django.db.models.fields.related.ManyToManyField'
,
[],
{
'to'
:
"orm['auth.Group']"
,
'symmetrical'
:
'False'
,
'blank'
:
'True'
}),
'id'
:
(
'django.db.models.fields.AutoField'
,
[],
{
'primary_key'
:
'True'
}),
'ignored_tags'
:
(
'django.db.models.fields.TextField'
,
[],
{
'blank'
:
'True'
}),
'interesting_tags'
:
(
'django.db.models.fields.TextField'
,
[],
{
'blank'
:
'True'
}),
'is_active'
:
(
'django.db.models.fields.BooleanField'
,
[],
{
'default'
:
'True'
}),
'is_staff'
:
(
'django.db.models.fields.BooleanField'
,
[],
{
'default'
:
'False'
}),
'is_superuser'
:
(
'django.db.models.fields.BooleanField'
,
[],
{
'default'
:
'False'
}),
'last_login'
:
(
'django.db.models.fields.DateTimeField'
,
[],
{
'default'
:
'datetime.datetime.now'
}),
'last_name'
:
(
'django.db.models.fields.CharField'
,
[],
{
'max_length'
:
'30'
,
'blank'
:
'True'
}),
'last_seen'
:
(
'django.db.models.fields.DateTimeField'
,
[],
{
'default'
:
'datetime.datetime.now'
}),
'location'
:
(
'django.db.models.fields.CharField'
,
[],
{
'max_length'
:
'100'
,
'blank'
:
'True'
}),
'new_response_count'
:
(
'django.db.models.fields.IntegerField'
,
[],
{
'default'
:
'0'
}),
'password'
:
(
'django.db.models.fields.CharField'
,
[],
{
'max_length'
:
'128'
}),
'questions_per_page'
:
(
'django.db.models.fields.SmallIntegerField'
,
[],
{
'default'
:
'10'
}),
'real_name'
:
(
'django.db.models.fields.CharField'
,
[],
{
'max_length'
:
'100'
,
'blank'
:
'True'
}),
'reputation'
:
(
'django.db.models.fields.PositiveIntegerField'
,
[],
{
'default'
:
'1'
}),
'seen_response_count'
:
(
'django.db.models.fields.IntegerField'
,
[],
{
'default'
:
'0'
}),
'show_country'
:
(
'django.db.models.fields.BooleanField'
,
[],
{
'default'
:
'False'
}),
'silver'
:
(
'django.db.models.fields.SmallIntegerField'
,
[],
{
'default'
:
'0'
}),
'status'
:
(
'django.db.models.fields.CharField'
,
[],
{
'default'
:
"'w'"
,
'max_length'
:
'2'
}),
'user_permissions'
:
(
'django.db.models.fields.related.ManyToManyField'
,
[],
{
'to'
:
"orm['auth.Permission']"
,
'symmetrical'
:
'False'
,
'blank'
:
'True'
}),
'username'
:
(
'django.db.models.fields.CharField'
,
[],
{
'unique'
:
'True'
,
'max_length'
:
'30'
}),
'website'
:
(
'django.db.models.fields.URLField'
,
[],
{
'max_length'
:
'200'
,
'blank'
:
'True'
})
},
'certificates.generatedcertificate'
:
{
'Meta'
:
{
'object_name'
:
'GeneratedCertificate'
},
'certificate_id'
:
(
'django.db.models.fields.CharField'
,
[],
{
'default'
:
'None'
,
'max_length'
:
'32'
,
'null'
:
'True'
}),
'download_url'
:
(
'django.db.models.fields.CharField'
,
[],
{
'max_length'
:
'128'
,
'null'
:
'True'
}),
'enabled'
:
(
'django.db.models.fields.BooleanField'
,
[],
{
'default'
:
'False'
}),
'grade'
:
(
'django.db.models.fields.CharField'
,
[],
{
'max_length'
:
'5'
,
'null'
:
'True'
}),
'graded_certificate_id'
:
(
'django.db.models.fields.CharField'
,
[],
{
'default'
:
'None'
,
'max_length'
:
'32'
,
'null'
:
'True'
}),
'graded_download_url'
:
(
'django.db.models.fields.CharField'
,
[],
{
'max_length'
:
'128'
,
'null'
:
'True'
}),
'id'
:
(
'django.db.models.fields.AutoField'
,
[],
{
'primary_key'
:
'True'
}),
'name'
:
(
'django.db.models.fields.CharField'
,
[],
{
'max_length'
:
'255'
,
'blank'
:
'True'
}),
'user'
:
(
'django.db.models.fields.related.ForeignKey'
,
[],
{
'to'
:
"orm['auth.User']"
})
},
'certificates.revokedcertificate'
:
{
'Meta'
:
{
'object_name'
:
'RevokedCertificate'
},
'certificate_id'
:
(
'django.db.models.fields.CharField'
,
[],
{
'default'
:
'None'
,
'max_length'
:
'32'
,
'null'
:
'True'
}),
'download_url'
:
(
'django.db.models.fields.CharField'
,
[],
{
'max_length'
:
'128'
,
'null'
:
'True'
}),
'enabled'
:
(
'django.db.models.fields.BooleanField'
,
[],
{
'default'
:
'False'
}),
'explanation'
:
(
'django.db.models.fields.TextField'
,
[],
{
'blank'
:
'True'
}),
'grade'
:
(
'django.db.models.fields.CharField'
,
[],
{
'max_length'
:
'5'
,
'null'
:
'True'
}),
'graded_certificate_id'
:
(
'django.db.models.fields.CharField'
,
[],
{
'default'
:
'None'
,
'max_length'
:
'32'
,
'null'
:
'True'
}),
'graded_download_url'
:
(
'django.db.models.fields.CharField'
,
[],
{
'max_length'
:
'128'
,
'null'
:
'True'
}),
'id'
:
(
'django.db.models.fields.AutoField'
,
[],
{
'primary_key'
:
'True'
}),
'name'
:
(
'django.db.models.fields.CharField'
,
[],
{
'max_length'
:
'255'
,
'blank'
:
'True'
}),
'user'
:
(
'django.db.models.fields.related.ForeignKey'
,
[],
{
'to'
:
"orm['auth.User']"
})
},
'contenttypes.contenttype'
:
{
'Meta'
:
{
'ordering'
:
"('name',)"
,
'unique_together'
:
"(('app_label', 'model'),)"
,
'object_name'
:
'ContentType'
,
'db_table'
:
"'django_content_type'"
},
'app_label'
:
(
'django.db.models.fields.CharField'
,
[],
{
'max_length'
:
'100'
}),
'id'
:
(
'django.db.models.fields.AutoField'
,
[],
{
'primary_key'
:
'True'
}),
'model'
:
(
'django.db.models.fields.CharField'
,
[],
{
'max_length'
:
'100'
}),
'name'
:
(
'django.db.models.fields.CharField'
,
[],
{
'max_length'
:
'100'
})
}
}
complete_apps
=
[
'certificates'
]
djangoapps/certificates/models.py
View file @
ef82497e
...
...
@@ -42,6 +42,66 @@ class GeneratedCertificate(models.Model):
# enabled should only be true if the student has earned a grade in the course
# The student must have a grade and request a certificate for enabled to be True
enabled
=
models
.
BooleanField
(
default
=
False
)
class
RevokedCertificate
(
models
.
Model
):
"""
This model is for when a GeneratedCertificate must be regenerated. This model
contains all the same fields, to store a record of what the GeneratedCertificate
was before it was revoked (at which time all of it's information can change when
it is regenerated).
GeneratedCertificate may be deleted once they are revoked, and then created again.
For this reason, the only link between a GeneratedCertificate and RevokedCertificate
is that they share the same user.
"""
####-------------------New Fields--------------------####
explanation
=
models
.
TextField
(
blank
=
True
)
####---------Fields from GeneratedCertificate---------####
user
=
models
.
ForeignKey
(
User
,
db_index
=
True
)
# This is the name at the time of request
name
=
models
.
CharField
(
blank
=
True
,
max_length
=
255
)
certificate_id
=
models
.
CharField
(
max_length
=
32
,
null
=
True
,
default
=
None
)
graded_certificate_id
=
models
.
CharField
(
max_length
=
32
,
null
=
True
,
default
=
None
)
download_url
=
models
.
CharField
(
max_length
=
128
,
null
=
True
)
graded_download_url
=
models
.
CharField
(
max_length
=
128
,
null
=
True
)
grade
=
models
.
CharField
(
max_length
=
5
,
null
=
True
)
enabled
=
models
.
BooleanField
(
default
=
False
)
def
revoke_certificate
(
certificate
,
explanation
):
"""
This method takes a GeneratedCertificate. It records its information from the certificate
into a RevokedCertificate, and then marks the certificate as needing regenerating.
When the new certificiate is regenerated it will have new IDs and download URLS.
Once this method has been called, it is safe to delete the certificate, or modify the
certificate's name or grade until it has been generated again.
"""
revoked
=
RevokedCertificate
(
user
=
certificate
.
user
,
name
=
certificate
.
name
,
certificate_id
=
certificate
.
certificate_id
,
graded_certificate_id
=
certificate
.
graded_certificate_id
,
download_url
=
certificate
.
download_url
,
graded_download_url
=
certificate
.
graded_download_url
,
grade
=
certificate
.
grade
,
enabled
=
certificate
.
enabled
)
revoked
.
explanation
=
explanation
certificate
.
certificate_id
=
None
certificate
.
graded_certificate_id
=
None
certificate
.
download_url
=
None
certificate
.
graded_download_url
=
None
certificate
.
save
()
revoked
.
save
()
def
certificate_state_for_student
(
student
,
grade
):
...
...
djangoapps/certificates/views.py
View file @
ef82497e
...
...
@@ -10,7 +10,7 @@ from django.http import Http404, HttpResponse
from
django.shortcuts
import
redirect
import
courseware.grades
as
grades
from
certificates.models
import
GeneratedCertificate
,
certificate_state_for_student
from
certificates.models
import
GeneratedCertificate
,
certificate_state_for_student
,
revoke_certificate
from
mitxmako.shortcuts
import
render_to_response
,
render_to_string
from
student.models
import
UserProfile
from
student.survey_questions
import
exit_survey_list_for_student
...
...
@@ -104,7 +104,7 @@ def generate_certificate(user, grade):
generated_certificate
.
enabled
=
True
if
generated_certificate
.
graded_download_url
and
(
generated_certificate
.
grade
!=
grade
):
log
.
critical
(
"A graded certificate has been pre-generated with the grade "
log
.
critical
(
u
"A graded certificate has been pre-generated with the grade "
"of {gen_grade} but requested by user id {userid} with grade "
"{req_grade}! The download URLs were {graded_dl_url} and "
"{ungraded_dl_url}"
.
format
(
...
...
@@ -113,12 +113,11 @@ def generate_certificate(user, grade):
graded_dl_url
=
generated_certificate
.
graded_download_url
,
ungraded_dl_url
=
generated_certificate
.
download_url
,
userid
=
user
.
id
))
generated_certificate
.
graded_download_url
=
None
generated_certificate
.
download_url
=
None
revoke_certificate
(
generated_certificate
,
"The grade on this certificate may be inaccurate."
)
user_name
=
UserProfile
.
objects
.
get
(
user
=
user
)
.
name
if
generated_certificate
.
download_url
and
(
generated_certificate
.
name
!=
user_name
):
log
.
critical
(
"A Certificate has been pre-generated with the name of "
log
.
critical
(
u
"A Certificate has been pre-generated with the name of "
"{gen_name} but current name is {user_name} (user id is "
"{userid})! The download URLs were {graded_dl_url} and "
"{ungraded_dl_url}"
.
format
(
...
...
@@ -127,8 +126,7 @@ def generate_certificate(user, grade):
graded_dl_url
=
generated_certificate
.
graded_download_url
,
ungraded_dl_url
=
generated_certificate
.
download_url
,
userid
=
user
.
id
))
generated_certificate
.
graded_download_url
=
None
generated_certificate
.
download_url
=
None
revoke_certificate
(
generated_certificate
,
"The name on this certificate may be inaccurate."
)
generated_certificate
.
grade
=
grade
...
...
djangoapps/student/views.py
View file @
ef82497e
...
...
@@ -22,7 +22,7 @@ from mitxmako.shortcuts import render_to_response, render_to_string
from
django_future.csrf
import
ensure_csrf_cookie
from
courseware
import
grades
from
certificates.models
import
certificate_state_for_student
from
certificates.models
import
GeneratedCertificate
,
certificate_state_for_student
,
revoke_certificate
from
student.survey_questions
import
exit_survey_list_for_student
from
models
import
Registration
,
UserProfile
,
PendingNameChange
,
PendingEmailChange
...
...
@@ -454,6 +454,20 @@ def accept_name_change(request):
up
.
set_meta
(
meta
)
up
.
name
=
pnc
.
new_name
#Revoke the certificate, if necessary
try
:
generated_certificate
=
GeneratedCertificate
.
objects
.
get
(
user
=
u
)
revoke_certificate
(
generated_certificate
,
u"The name on this certificate has been changed to {name}."
.
format
(
name
=
up
.
name
))
generated_certificate
.
name
=
up
.
name
generated_certificate
.
save
()
except
GeneratedCertificate
.
DoesNotExist
:
# Cool, they didn't have a certificate anyway
pass
up
.
save
()
pnc
.
delete
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment