Permalink
Browse files

further work

  • Loading branch information...
1 parent 8c20c5c commit 4131175d2dd1b299213eae39cfdf440652e4545d @digi604 digi604 committed Aug 28, 2012
View
2 cms/apphook_pool.py
@@ -43,7 +43,7 @@ def register(self, app):
"but the 'menus' attribute is empty, did you make a typo?")
name = app.__name__
if name in self.apps.keys():
- raise AppAlreadyRegistered, "[%s] an cms app with this name is already registered" % name
+ raise AppAlreadyRegistered, "[%s] a cms app with this name is already registered" % name
self.apps[name] = app
def get_apphooks(self):
View
54 cms/appresolver.py
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from cms.apphook_pool import apphook_pool
+from cms.utils.i18n import force_lang
from cms.utils.moderator import get_page_queryset
from django.conf import settings
@@ -49,6 +50,7 @@ class AppRegexURLResolver(RegexURLResolver):
url_patterns = None
def resolve_page_id(self, path):
+ print "resolve page id"+path
"""Resolves requested path similar way how resolve does, but instead
of return callback,.. returns page_id to which was application
assigned.
@@ -164,44 +166,38 @@ def get_app_patterns():
is_draft = not settings.CMS_MODERATOR
title_qs = Title.objects.filter(page__publisher_is_draft=is_draft, page__site=current_site)
-
- if 'cms.middleware.multilingual.MultilingualURLMiddleware' in settings.MIDDLEWARE_CLASSES:
- use_namespaces = True
- hooked_applications = {}
- else:
- use_namespaces = False
- hooked_applications = []
-
+
+ hooked_applications = {}
+
# Loop over all titles with an application hooked to them
for title in title_qs.exclude(application_urls=None).exclude(application_urls='').select_related():
path = title.path
- if use_namespaces:
- mixid = "%s:%s:%s" % (path + "/", title.application_urls, title.language)
- else:
- mixid = "%s:%s" % (path + "/", title.application_urls)
- if mixid in included:
+ mix_id = "%s:%s:%s" % (path + "/", title.application_urls, title.language)
+ if mix_id in included:
# don't add the same thing twice
continue
if not settings.APPEND_SLASH:
path += '/'
- if use_namespaces:
- if title.language not in hooked_applications:
- hooked_applications[title.language] = []
- hooked_applications[title.language] += get_patterns_for_title(path, title)
- else:
- hooked_applications += get_patterns_for_title(path, title)
- included.append(mixid)
+ if title.page_id not in hooked_applications:
+ hooked_applications[title.page_id] = {}
+ with force_lang(title.language):
+ hooked_applications[title.page_id][title.language] = get_patterns_for_title(path, title)
+ included.append(mix_id)
# Build the app patterns to be included in the cms urlconfs
app_patterns = []
- if use_namespaces:
- for ns, currentpatterns in hooked_applications.items():
- extra_patterns = patterns('', *currentpatterns)
- resolver = AppRegexURLResolver(r'', 'app_resolver', namespace=ns)
- resolver.url_patterns = extra_patterns
- app_patterns.append(resolver)
- APP_RESOLVERS.append(resolver)
- else:
- extra_patterns = patterns('', *hooked_applications)
+ for page_id in hooked_applications.keys():
+ merged_patterns = None
+ for lang in hooked_applications[page_id].keys():
+ current_patterns = hooked_applications[page_id][lang]
+ if not merged_patterns:
+ merged_patterns = current_patterns
+ continue
+ else:
+ for x in range(len(current_patterns)):
+ orig = merged_patterns[x]
+
+ print current_patterns
+ extra_patterns = patterns('', *current_patterns)
resolver = AppRegexURLResolver(r'', 'app_resolver')
resolver.url_patterns = extra_patterns
app_patterns.append(resolver)
View
BIN cms/test_utils/project/sampleapp/media/sampleapp/img/gift.jpg
Deleted file not rendered
View
2 cms/test_utils/project/sampleapp/templates/sampleapp/home.html
@@ -22,5 +22,5 @@
</li>
</ul>
<h4>Sample image - appmedia works?</h4>
- <img src="{{ MEDIA_URL }}sampleapp/img/gift.jpg" alt="gift">
+ <img src="{{ STATIC_URL }}sampleapp/img/gift.jpg" alt="gift">
{% endblock content %}
View
5 cms/test_utils/project/urls.py
@@ -3,18 +3,21 @@
url
from django.contrib import admin
from django.conf.urls.i18n import i18n_patterns
+from django.contrib.staticfiles.urls import staticfiles_urlpatterns
admin.autodiscover()
urlpatterns = patterns('',
- (r'', include('django.contrib.staticfiles.urls')),
+ #(r'', include('django.contrib.staticfiles.urls')),
url(r'^media/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': settings.MEDIA_ROOT, 'show_indexes': True}),
url(r'^media/cms/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': settings.CMS_MEDIA_ROOT, 'show_indexes': True}),
url(r'^jsi18n/(?P<packages>\S+?)/$', 'django.views.i18n.javascript_catalog'),
)
+urlpatterns += staticfiles_urlpatterns()
+
urlpatterns += i18n_patterns('',
url(r'^admin/', include(admin.site.urls)),
url(r'^example/$', 'cms.test_utils.project.placeholderapp.views.example_view'),
View
5 cms/views.py
@@ -65,7 +65,9 @@ def details(request, slug):
# page = applications_page_check(request, page, slug)
# Check for apphooks! This time for real!
app_urls = page.get_application_urls(current_language, False)
+ print app_urls
if app_urls:
+ print "app urls found"
app = apphook_pool.get_apphook(app_urls)
pattern_list = []
for urlpatterns in get_app_urls(app.urls):
@@ -76,7 +78,8 @@ def details(request, slug):
return view(request, *args, **kwargs)
except Resolver404:
pass
-
+ else:
+ print "no apphooks"
# Check if the page has a redirect url defined for this language.
redirect_url = page.get_redirect(language=current_language)
if redirect_url:

0 comments on commit 4131175

Please sign in to comment.