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
bd3dfee9
Commit
bd3dfee9
authored
Sep 08, 2015
by
Matt Drayer
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #9629 from edx/asadiqbal08/SOL-1159
SOL-1159 Remove hash cert asset file name
parents
9aba4a72
17f10d21
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
1 deletions
+57
-1
lms/djangoapps/certificates/models.py
+27
-1
lms/djangoapps/certificates/tests/test_models.py
+30
-0
No files found.
lms/djangoapps/certificates/models.py
View file @
bd3dfee9
...
@@ -49,6 +49,7 @@ from datetime import datetime
...
@@ -49,6 +49,7 @@ from datetime import datetime
import
json
import
json
import
logging
import
logging
import
uuid
import
uuid
import
os
from
django.contrib.auth.models
import
User
from
django.contrib.auth.models
import
User
from
django.core.exceptions
import
ValidationError
from
django.core.exceptions
import
ValidationError
...
@@ -730,6 +731,21 @@ class CertificateTemplate(TimeStampedModel):
...
@@ -730,6 +731,21 @@ class CertificateTemplate(TimeStampedModel):
unique_together
=
((
'organization_id'
,
'course_key'
,
'mode'
),)
unique_together
=
((
'organization_id'
,
'course_key'
,
'mode'
),)
def
template_assets_path
(
instance
,
filename
):
"""
Delete the file if it already exist and returns the certificate template asset file path.
:param instance: CertificateTemplateAsset object
:param filename: file to upload
:return path: path of asset file e.g. certificate_template_assets/1/filename
"""
name
=
os
.
path
.
join
(
'certificate_template_assets'
,
str
(
instance
.
id
),
filename
)
fullname
=
os
.
path
.
join
(
settings
.
MEDIA_ROOT
,
name
)
if
os
.
path
.
exists
(
fullname
):
os
.
remove
(
fullname
)
return
name
class
CertificateTemplateAsset
(
TimeStampedModel
):
class
CertificateTemplateAsset
(
TimeStampedModel
):
"""A set of assets to be used in custom web certificate templates.
"""A set of assets to be used in custom web certificate templates.
...
@@ -745,10 +761,20 @@ class CertificateTemplateAsset(TimeStampedModel):
...
@@ -745,10 +761,20 @@ class CertificateTemplateAsset(TimeStampedModel):
)
)
asset
=
models
.
FileField
(
asset
=
models
.
FileField
(
max_length
=
255
,
max_length
=
255
,
upload_to
=
'certificate_template_assets'
,
upload_to
=
template_assets_path
,
help_text
=
_
(
u'Asset file. It could be an image or css file.'
),
help_text
=
_
(
u'Asset file. It could be an image or css file.'
),
)
)
def
save
(
self
,
*
args
,
**
kwargs
):
"""save the certificate template asset """
if
self
.
pk
is
None
:
asset_image
=
self
.
asset
self
.
asset
=
None
super
(
CertificateTemplateAsset
,
self
)
.
save
(
*
args
,
**
kwargs
)
self
.
asset
=
asset_image
super
(
CertificateTemplateAsset
,
self
)
.
save
(
*
args
,
**
kwargs
)
def
__unicode__
(
self
):
def
__unicode__
(
self
):
return
u'
%
s'
%
(
self
.
asset
.
url
,
)
# pylint: disable=no-member
return
u'
%
s'
%
(
self
.
asset
.
url
,
)
# pylint: disable=no-member
...
...
lms/djangoapps/certificates/tests/test_models.py
View file @
bd3dfee9
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
from
django.conf
import
settings
from
django.conf
import
settings
from
django.core.exceptions
import
ValidationError
from
django.core.exceptions
import
ValidationError
from
django.core.files.images
import
ImageFile
from
django.core.files.images
import
ImageFile
from
django.core.files.uploadedfile
import
SimpleUploadedFile
from
django.test
import
TestCase
from
django.test
import
TestCase
from
django.test.utils
import
override_settings
from
django.test.utils
import
override_settings
from
nose.plugins.attrib
import
attr
from
nose.plugins.attrib
import
attr
...
@@ -12,6 +13,7 @@ from certificates.models import (
...
@@ -12,6 +13,7 @@ from certificates.models import (
ExampleCertificate
,
ExampleCertificate
,
ExampleCertificateSet
,
ExampleCertificateSet
,
CertificateHtmlViewConfiguration
,
CertificateHtmlViewConfiguration
,
CertificateTemplateAsset
,
BadgeImageConfiguration
)
BadgeImageConfiguration
)
FEATURES_INVALID_FILE_PATH
=
settings
.
FEATURES
.
copy
()
FEATURES_INVALID_FILE_PATH
=
settings
.
FEATURES
.
copy
()
...
@@ -204,3 +206,31 @@ class BadgeImageConfigurationTest(TestCase):
...
@@ -204,3 +206,31 @@ class BadgeImageConfigurationTest(TestCase):
ValidationError
,
ValidationError
,
BadgeImageConfiguration
(
mode
=
'test2'
,
icon
=
self
.
get_image
(
'good'
),
default
=
True
)
.
full_clean
BadgeImageConfiguration
(
mode
=
'test2'
,
icon
=
self
.
get_image
(
'good'
),
default
=
True
)
.
full_clean
)
)
@attr
(
'shard_1'
)
class
CertificateTemplateAssetTest
(
TestCase
):
"""
Test Assets are uploading/saving successfully for CertificateTemplateAsset.
"""
def
test_asset_file_saving_with_actual_name
(
self
):
"""
Verify that asset file is saving with actual name, No hash tag should be appended with the asset filename.
"""
CertificateTemplateAsset
(
description
=
'test description'
,
asset
=
SimpleUploadedFile
(
'picture1.jpg'
,
'these are the file contents!'
))
.
save
()
certificate_template_asset
=
CertificateTemplateAsset
.
objects
.
get
(
id
=
1
)
self
.
assertEqual
(
certificate_template_asset
.
asset
,
'certificate_template_assets/1/picture1.jpg'
)
# Now save asset with same file again, New file will be uploaded after deleting the old one with the same name.
certificate_template_asset
.
asset
=
SimpleUploadedFile
(
'picture1.jpg'
,
'file contents'
)
certificate_template_asset
.
save
()
self
.
assertEqual
(
certificate_template_asset
.
asset
,
'certificate_template_assets/1/picture1.jpg'
)
# Now replace the asset with another file
certificate_template_asset
.
asset
=
SimpleUploadedFile
(
'picture2.jpg'
,
'file contents'
)
certificate_template_asset
.
save
()
certificate_template_asset
=
CertificateTemplateAsset
.
objects
.
get
(
id
=
1
)
self
.
assertEqual
(
certificate_template_asset
.
asset
,
'certificate_template_assets/1/picture2.jpg'
)
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