Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Feature/kill os path urls #923

Merged
merged 2 commits into from

2 participants

@ojii
Collaborator

Changed Added cms.utils.cms_static_url, thanks go to jezdez for this code
Replaced all os.path.join powered URL constructing with cms.utils.cms_static_url

ojii added some commits
@ojii ojii Added cms.utils.cms_static_url, thanks go to @jezdez for this code
Replaced all os.path.join powered URL constructing with cms.utils.cms_static_url
3780159
@ojii ojii Fixed cms.utils.cms_static_url c5f51e7
@chrisglass chrisglass merged commit 30a5ad9 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 4, 2011
  1. @ojii

    Added cms.utils.cms_static_url, thanks go to @jezdez for this code

    ojii authored
    Replaced all os.path.join powered URL constructing with cms.utils.cms_static_url
  2. @ojii

    Fixed cms.utils.cms_static_url

    ojii authored
This page is out of date. Refresh to see the latest.
View
31 cms/admin/pageadmin.py
@@ -2,20 +2,20 @@
from cms.admin.change_list import CMSChangeList
from cms.admin.dialog.views import get_copy_dialog
from cms.admin.forms import PageForm, PageAddForm
-from cms.admin.permissionadmin import PAGE_ADMIN_INLINES, \
- PagePermissionInlineAdmin, ViewRestrictionInlineAdmin
+from cms.admin.permissionadmin import (PAGE_ADMIN_INLINES,
+ PagePermissionInlineAdmin, ViewRestrictionInlineAdmin)
from cms.admin.views import revert_plugins
from cms.apphook_pool import apphook_pool
from cms.exceptions import NoPermissionsException
from cms.forms.widgets import PluginEditor
-from cms.models import Page, Title, CMSPlugin, PagePermission, \
- PageModeratorState, EmptyTitle, GlobalPagePermission
+from cms.models import (Page, Title, CMSPlugin, PagePermission,
+ PageModeratorState, EmptyTitle, GlobalPagePermission)
from cms.models.managers import PagePermissionsPermissionManager
from cms.models.placeholdermodel import Placeholder
from cms.plugin_pool import plugin_pool
-from cms.utils import copy_plugins, helpers, moderator, permissions, plugins, \
- get_template_from_request, get_language_from_request, \
- placeholder as placeholder_utils, admin as admin_utils
+from cms.utils import (copy_plugins, helpers, moderator, permissions, plugins,
+ get_template_from_request, get_language_from_request,
+ placeholder as placeholder_utils, admin as admin_utils, cms_static_url)
from cms.utils.permissions import has_plugin_permission
from copy import deepcopy
from django import template
@@ -28,20 +28,17 @@
from django.core.urlresolvers import reverse
from django.db import transaction, models
from django.forms import CharField
-from django.http import HttpResponseRedirect, HttpResponse, Http404, \
- HttpResponseBadRequest, HttpResponseForbidden, HttpResponseNotAllowed
+from django.http import (HttpResponseRedirect, HttpResponse, Http404,
+ HttpResponseBadRequest, HttpResponseForbidden, HttpResponseNotAllowed)
from django.shortcuts import render_to_response, get_object_or_404
from django.template.context import RequestContext
-from django.template.defaultfilters import title, escape, force_escape, \
- escapejs
+from django.template.defaultfilters import (title, escape, force_escape,
+ escapejs)
from django.utils.encoding import force_unicode
-from django.utils.translation import ugettext_lazy as _
-from django.utils.translation import ugettext
+from django.utils.translation import ugettext, ugettext_lazy as _
from menus.menu_pool import menu_pool
import django
import inspect
-import os
-
@@ -164,14 +161,14 @@ class PageAdmin(ModelAdmin):
class Media:
css = {
- 'all': [os.path.join(settings.STATIC_URL, 'cms', path) for path in (
+ 'all': [cms_static_url(path) for path in (
'css/rte.css',
'css/pages.css',
'css/change_form.css',
'css/jquery.dialog.css',
)]
}
- js = ['%sjs/jquery.min.js' % settings.ADMIN_MEDIA_PREFIX] + [os.path.join(settings.STATIC_URL, 'cms', path) for path in [
+ js = ['%sjs/jquery.min.js' % settings.ADMIN_MEDIA_PREFIX] + [cms_static_url(path) for path in [
'js/plugins/admincompat.js',
'js/libs/jquery.query.js',
'js/libs/jquery.ui.core.js',
View
11 cms/admin/placeholderadmin.py
@@ -4,24 +4,24 @@
from cms.models.placeholdermodel import Placeholder
from cms.models.pluginmodel import CMSPlugin
from cms.plugin_pool import plugin_pool
-from cms.utils import get_language_from_request
+from cms.utils import get_language_from_request, cms_static_url
from cms.utils.permissions import has_plugin_permission
from copy import deepcopy
from django.conf import settings
from django.contrib.admin import ModelAdmin
-from django.http import HttpResponse, Http404, HttpResponseBadRequest, HttpResponseForbidden
+from django.http import (HttpResponse, Http404, HttpResponseBadRequest,
+ HttpResponseForbidden)
from django.shortcuts import render_to_response, get_object_or_404
from django.template import RequestContext
from django.template.defaultfilters import force_escape, escapejs
from django.utils.translation import ugettext as _
-import os
class PlaceholderAdmin(ModelAdmin):
class Media:
css = {
- 'all': [os.path.join(settings.STATIC_URL, 'cms', path) for path in (
+ 'all': [cms_static_url(path) for path in (
'css/rte.css',
'css/pages.css',
'css/change_form.css',
@@ -29,8 +29,7 @@ class Media:
'css/plugin_editor.css',
)]
}
- js = ['%sjs/jquery.min.js' % settings.ADMIN_MEDIA_PREFIX] + [
- os.path.join(settings.STATIC_URL, 'cms', path) for path in [
+ js = ['%sjs/jquery.min.js' % settings.ADMIN_MEDIA_PREFIX] + [cms_static_url(path) for path in [
'js/plugins/admincompat.js',
'js/csrf.js',
'js/libs/jquery.query.js',
View
24 cms/cms_toolbar.py
@@ -3,7 +3,7 @@
from cms.toolbar.constants import LEFT, RIGHT
from cms.toolbar.items import (Anchor, Switcher, TemplateHTML, ListItem, List,
GetButton)
-from cms.utils import cms_media
+from cms.utils import cms_static_url
from cms.utils.moderator import page_moderator_state, I_APPROVE
from django import forms
from django.conf import settings
@@ -125,7 +125,7 @@ def get_items(self, context, **kwargs):
items.append(
GetButton(RIGHT, 'logout', _('Logout'), '?cms-toolbar-logout',
- cms_media('images/toolbar/icons/icon_lock.png'))
+ cms_static_url('images/toolbar/icons/icon_lock.png'))
)
elif not self.request.user.is_authenticated():
items.append(
@@ -134,7 +134,7 @@ def get_items(self, context, **kwargs):
else:
items.append(
GetButton(RIGHT, 'logout', _('Logout'), '?cms-toolbar-logout',
- cms_media('images/toolbar/icons/icon_lock.png'))
+ cms_static_url('images/toolbar/icons/icon_lock.png'))
)
return items
@@ -159,26 +159,26 @@ def get_page_menu(self, context, can_change, is_staff):
menu_items = [
ListItem('overview', _('Move/add Pages'),
reverse('admin:cms_page_changelist'),
- icon=cms_media('images/toolbar/icons/icon_sitemap.png')),
+ icon=cms_static_url('images/toolbar/icons/icon_sitemap.png')),
]
menu_items.append(
ListItem('addchild', _('Add child page'),
_get_add_child_url,
- icon=cms_media('images/toolbar/icons/icon_child.png'))
+ icon=cms_static_url('images/toolbar/icons/icon_child.png'))
)
menu_items.append(
ListItem('addsibling', _('Add sibling page'),
_get_add_sibling_url,
- icon=cms_media('images/toolbar/icons/icon_sibling.png'))
+ icon=cms_static_url('images/toolbar/icons/icon_sibling.png'))
)
menu_items.append(
ListItem('delete', _('Delete Page'), _get_delete_url,
- icon=cms_media('images/toolbar/icons/icon_delete.png'))
+ icon=cms_static_url('images/toolbar/icons/icon_delete.png'))
)
return List(RIGHT, 'page', _('Page'),
- cms_media('images/toolbar/icons/icon_page.png'),
+ cms_static_url('images/toolbar/icons/icon_page.png'),
items=menu_items)
def get_admin_menu(self, context, can_change, is_staff):
@@ -188,22 +188,22 @@ def get_admin_menu(self, context, can_change, is_staff):
admin_items = [
ListItem('admin', _('Site Administration'),
reverse('admin:index'),
- icon=cms_media('images/toolbar/icons/icon_admin.png')),
+ icon=cms_static_url('images/toolbar/icons/icon_admin.png')),
]
if can_change:
admin_items.append(
ListItem('settings', _('Page Settings'),
_get_page_admin_url,
- icon=cms_media('images/toolbar/icons/icon_page.png'))
+ icon=cms_static_url('images/toolbar/icons/icon_page.png'))
)
if 'reversion' in settings.INSTALLED_APPS:
admin_items.append(
ListItem('history', _('View History'),
_get_page_history_url,
- icon=cms_media('images/toolbar/icons/icon_history.png'))
+ icon=cms_static_url('images/toolbar/icons/icon_history.png'))
)
return List(RIGHT, 'admin', _('Admin'),
- cms_media('images/toolbar/icons/icon_admin.png'),
+ cms_static_url('images/toolbar/icons/icon_admin.png'),
items=admin_items)
def request_hook(self):
View
7 cms/forms/widgets.py
@@ -2,7 +2,7 @@
from cms.forms.utils import get_site_choices, get_page_choices
from cms.models import Page, PageUser, Placeholder
from cms.plugin_pool import plugin_pool
-from cms.utils import get_language_from_request
+from cms.utils import get_language_from_request, cms_static_url
from django.conf import settings
from django.contrib.sites.models import Site
from django.forms.widgets import Select, MultiWidget, Widget
@@ -11,7 +11,6 @@
from django.utils.encoding import force_unicode
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext as _
-from os.path import join
import copy
class PageSelectWidget(MultiWidget):
@@ -130,12 +129,12 @@ def __init__(self, attrs=None):
self.attrs = {}
class Media:
- js = [join(settings.STATIC_URL, 'cms', path) for path in (
+ js = [cms_static_url(path) for path in (
'js/libs/jquery.ui.core.js',
'js/libs/jquery.ui.sortable.js',
)]
css = {
- 'all': [join(settings.STATIC_URL, 'cms', path) for path in (
+ 'all': [cms_static_url(path) for path in (
'css/plugin_editor.css',
)]
}
View
34 cms/plugins/text/widgets/tinymce_widget.py
@@ -1,15 +1,15 @@
-from tinymce.widgets import TinyMCE, get_language_config
+from cms.utils import cms_static_url
from django.conf import settings
-from django.utils.translation import get_language
+from django.forms.widgets import flatatt
+from django.template.defaultfilters import escape
from django.template.loader import render_to_string
-from django.utils.safestring import mark_safe
-from os.path import join
-from django.utils.encoding import smart_unicode
-import tinymce.settings
from django.utils import simplejson
-from django.template.defaultfilters import escape
-from django.forms.widgets import flatatt
+from django.utils.encoding import smart_unicode
+from django.utils.safestring import mark_safe
+from django.utils.translation import get_language
+from tinymce.widgets import TinyMCE, get_language_config
import cms.plugins.text.settings
+import tinymce.settings
class TinyMCEEditor(TinyMCE):
@@ -30,13 +30,17 @@ def render_additions(self, name, value, attrs=None):
def _media(self):
media = super(TinyMCEEditor, self)._media()
- media.add_js([join(settings.STATIC_URL, 'cms', path) for path in (
- 'js/tinymce.placeholdereditor.js',
- 'js/libs/jquery.ui.core.js',
- 'js/placeholder_editor_registry.js',
- )])
- media.add_css({"all":[join(settings.STATIC_URL, 'cms', path) for path in ('css/jquery/cupertino/jquery-ui.css',
- 'css/tinymce_toolbar.css')]})
+ media.add_js([cms_static_url(path) for path in (
+ 'js/tinymce.placeholdereditor.js',
+ 'js/libs/jquery.ui.core.js',
+ 'js/placeholder_editor_registry.js',
+ )])
+ media.add_css({
+ "all": [
+ cms_static_url(path) for path in ('css/jquery/cupertino/jquery-ui.css',
+ 'css/tinymce_toolbar.css')
+ ]
+ })
return media
View
11 cms/plugins/text/widgets/wymeditor_widget.py
@@ -1,16 +1,15 @@
-from os.path import join
+from cms.plugins.text import settings as text_settings
+from cms.utils import cms_static_url
from django.conf import settings
from django.forms import Textarea
-from django.utils.safestring import mark_safe
from django.template.loader import render_to_string
-
-from cms.plugins.text import settings as text_settings
+from django.utils.safestring import mark_safe
from django.utils.translation.trans_real import get_language
class WYMEditor(Textarea):
class Media:
- js = [join(settings.STATIC_URL, 'cms', path) for path in (
+ js = [cms_static_url(path) for path in (
'wymeditor/jquery.wymeditor.js',
'wymeditor/plugins/resizable/jquery.wymeditor.resizable.js',
'js/wymeditor.placeholdereditor.js',
@@ -18,7 +17,7 @@ class Media:
'js/placeholder_editor_registry.js',
)]
css = {
- 'all': [join(settings.STATIC_URL, 'cms', path) for path in (
+ 'all': [cms_static_url(path) for path in (
'css/jquery/cupertino/jquery-ui.css',
)],
}
View
29 cms/utils/__init__.py
@@ -1,11 +1,16 @@
# -*- coding: utf-8 -*-
# TODO: this is just stuff from utils.py - should be splitted / moved
from cms.utils.i18n import get_default_language
+from distutils.version import LooseVersion
from django.conf import settings
+from django.core.files.storage import get_storage_class
from django.core.urlresolvers import reverse
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render_to_response
from django.template import RequestContext
+from django.utils.functional import LazyObject
+import django
+import os
import urllib
@@ -74,10 +79,26 @@ def get_page_from_request(request):
"in Django-CMS 2.2.", DeprecationWarning)
return new(request)
-def cms_media(suffix):
+
+"""
+The following class is taken from https://github.com/jezdez/django/compare/feature/staticfiles-templatetag
+and should be removed and replaced by the django-core version in 1.4
+"""
+default_storage = 'django.contrib.staticfiles.storage.StaticFilesStorage'
+if LooseVersion(django.get_version()) < LooseVersion('1.3'):
+ default_storage = 'staticfiles.storage.StaticFilesStorage'
+
+
+class ConfiguredStorage(LazyObject):
+ def _setup(self):
+ self._wrapped = get_storage_class(getattr(settings, 'STATICFILES_STORAGE', default_storage))()
+
+configured_storage = ConfiguredStorage()
+
+def cms_static_url(path):
'''
Helper that prefixes a URL with STATIC_URL and cms
'''
- if suffix:
- return u'%scms/%s' % (settings.STATIC_URL, suffix)
- return ''
+ if not path:
+ ''
+ return configured_storage.url(os.path.join('cms', path))
Something went wrong with that request. Please try again.