Skip to content
This repository has been archived by the owner on Jan 28, 2020. It is now read-only.

Commit

Permalink
Create variable to store 'assets'
Browse files Browse the repository at this point in the history
  • Loading branch information
George Schneeloch committed Jul 29, 2015
1 parent 7fdaf98 commit ae05379
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
5 changes: 3 additions & 2 deletions learningresources/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@

# defining the file path max length
FILE_PATH_MAX_LENGTH = 900
STATIC_ASSET_BASEPATH = 'assets/{org}/{course_number}/{run}/'
STATIC_ASSET_PREFIX = 'assets'
STATIC_ASSET_BASEPATH = STATIC_ASSET_PREFIX + '/{org}/{course_number}/{run}/'


class FilePathLengthException(Exception):
Expand Down Expand Up @@ -65,7 +66,7 @@ def course_asset_basepath(course, filename):
(unicode): forward slash separated path to use below
``settings.MEDIA_ROOT``.
"""
return 'assets/{org}/{course_number}/{run}/{filename}'.format(
return (STATIC_ASSET_BASEPATH + '{filename}').format(
org=course.org,
course_number=course.course_number,
run=course.run,
Expand Down
5 changes: 4 additions & 1 deletion ui/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
)
import rest.urls as rest_urls
import cas.urls as cas_urls
from learningresources.models import STATIC_ASSET_PREFIX


urlpatterns = [
Expand All @@ -53,7 +54,9 @@
if (settings.DEFAULT_FILE_STORAGE ==
'django.core.files.storage.FileSystemStorage'):
urlpatterns.append(
url(r'^media/assets/(?P<path>.+)$',
url(r'^media/{assets}/(?P<path>.+)$'.format(
assets=STATIC_ASSET_PREFIX
),
serve_static_assets,
name='media')
)
Expand Down
8 changes: 6 additions & 2 deletions ui/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@
NotFound,
PermissionDenied as LorePermissionDenied,
)
from learningresources.models import Repository, StaticAsset
from learningresources.models import (
Repository,
StaticAsset,
STATIC_ASSET_PREFIX,
)
from roles.api import assign_user_to_repo_group
from roles.permissions import GroupTypes, RepoPermission
from search import get_sqs
Expand Down Expand Up @@ -267,7 +271,7 @@ def serve_static_assets(request, path):
is django.core.files.storage.FileSystemStorage
"""
# first check if the user has access to the file
media_path = os.path.join('assets', path)
media_path = os.path.join(STATIC_ASSET_PREFIX, path)
file_path = os.path.join(settings.MEDIA_ROOT, media_path)
static_asset = get_object_or_404(StaticAsset, asset=media_path)
if (RepoPermission.view_repo[0] not in
Expand Down

0 comments on commit ae05379

Please sign in to comment.