Skip to content

Commit

Permalink
preview working on non public
Browse files Browse the repository at this point in the history
  • Loading branch information
digi604 committed Dec 19, 2012
1 parent 314eedc commit 225974e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 29 deletions.
10 changes: 5 additions & 5 deletions cms/test_utils/cli.py
Expand Up @@ -118,7 +118,7 @@ def configure(**extra):
'code':'de', 'code':'de',
'name':gettext('German'), 'name':gettext('German'),
'fallbacks':['fr', 'en'], 'fallbacks':['fr', 'en'],
'public':True, 'public':False,
}, },
{ {
'code':'fr', 'code':'fr',
Expand Down Expand Up @@ -191,10 +191,10 @@ def configure(**extra):
"name": "extra context" "name": "extra context"
}, },
}, },
CMS_SOFTROOT = True, CMS_SOFTROOT=True,
CMS_PERMISSION = True, CMS_PERMISSION=True,
CMS_PUBLIC_FOR = 'all', CMS_PUBLIC_FOR='all',
CMS_CACHE_DURATIONS = { CMS_CACHE_DURATIONS={
'menus': 0, 'menus': 0,
'content': 0, 'content': 0,
'permissions': 0, 'permissions': 0,
Expand Down
20 changes: 14 additions & 6 deletions cms/views.py
Expand Up @@ -42,32 +42,40 @@ def details(request, slug):
if frontend_lang in page_languages: if frontend_lang in page_languages:
available_languages.append(frontend_lang) available_languages.append(frontend_lang)
attrs = '' attrs = ''
edit = preview = draft = False
if request.user.is_staff:
edit = True
if 'edit' in request.GET: if 'edit' in request.GET:
attrs = '?edit=1' attrs = '?edit=1'
edit = True
elif 'preview' in request.GET: elif 'preview' in request.GET:
attrs = '?preview=1' attrs = '?preview=1'
preview = True
if 'draft' in request.GET: if 'draft' in request.GET:
attrs += '&draft=1' attrs += '&draft=1'
draft = True
# Check that the language is in FRONTEND_LANGUAGES: # Check that the language is in FRONTEND_LANGUAGES:
if not current_language in get_public_languages(): if not current_language in get_public_languages() and not edit:
#are we on root? # are we on root?
if not slug: if not slug:
#redirect to supported language # redirect to supported language
languages = [] languages = []
for language in available_languages: for language in available_languages:
languages.append((language, language)) languages.append((language, language))
if languages: if languages:
with SettingsOverride(LANGUAGES=languages, LANGUAGE_CODE=languages[0][0]): with SettingsOverride(LANGUAGES=languages, LANGUAGE_CODE=languages[0][0]):
#get supported language # get supported language
new_language = translation.get_language_from_request(request) new_language = translation.get_language_from_request(request)
with force_language(new_language): with force_language(new_language):
pages_root = reverse('pages-root') pages_root = reverse('pages-root')
return HttpResponseRedirect(pages_root + attrs) return HttpResponseRedirect(pages_root + attrs)
else: else:
_handle_no_page(request, slug) _handle_no_page(request, slug)
else: else:
if request.user.is_staff:
return HttpResponseRedirect("%s?edit" % reverse('pages-details-by-slug', args=[slug]))
return _handle_no_page(request, slug) return _handle_no_page(request, slug)
if current_language not in available_languages: if current_language not in available_languages and not edit:
# If we didn't find the required page in the requested (current) # If we didn't find the required page in the requested (current)
# language, let's try to find a fallback # language, let's try to find a fallback
found = False found = False
Expand Down Expand Up @@ -132,7 +140,7 @@ def details(request, slug):
return HttpResponseRedirect('%s?%s=%s' % tup) return HttpResponseRedirect('%s?%s=%s' % tup)


template_name = get_template_from_request(request, page, no_current_page=True) template_name = get_template_from_request(request, page, no_current_page=True)
# fill the context # fill the context
context['lang'] = current_language context['lang'] = current_language
context['current_page'] = page context['current_page'] = page
context['has_change_permissions'] = page.has_change_permission(request) context['has_change_permissions'] = page.has_change_permission(request)
Expand Down
37 changes: 19 additions & 18 deletions menus/templatetags/menu_tags.py
Expand Up @@ -51,7 +51,7 @@ def cut_levels(nodes, from_level, to_level, extra_inactive, extra_active):
final = [] final = []
removed = [] removed = []
selected = None selected = None
for node in nodes: for node in nodes:
if not hasattr(node, 'level'): if not hasattr(node, 'level'):
# remove and ignore nodes that don't have level information # remove and ignore nodes that don't have level information
remove(node, removed) remove(node, removed)
Expand All @@ -61,11 +61,11 @@ def cut_levels(nodes, from_level, to_level, extra_inactive, extra_active):
final.append(node) final.append(node)
node.parent = None node.parent = None
if not node.ancestor and not node.selected and not node.descendant: if not node.ancestor and not node.selected and not node.descendant:
# cut inactive nodes to extra_inactive, but not of descendants of # cut inactive nodes to extra_inactive, but not of descendants of
# the selected node # the selected node
cut_after(node, extra_inactive, removed) cut_after(node, extra_inactive, removed)
if node.level > to_level and node.parent: if node.level > to_level and node.parent:
# remove nodes that are too deep, but not nodes that are on # remove nodes that are too deep, but not nodes that are on
# from_level (local root nodes) # from_level (local root nodes)
remove(node, removed) remove(node, removed)
if node.selected: if node.selected:
Expand Down Expand Up @@ -101,7 +101,7 @@ class ShowMenu(InclusionTag):
""" """
name = 'show_menu' name = 'show_menu'
template = 'menu/dummy.html' template = 'menu/dummy.html'

options = Options( options = Options(
IntegerArgument('from_level', default=0, required=False), IntegerArgument('from_level', default=0, required=False),
IntegerArgument('to_level', default=100, required=False), IntegerArgument('to_level', default=100, required=False),
Expand All @@ -112,21 +112,21 @@ class ShowMenu(InclusionTag):
StringArgument('root_id', default=None, required=False), StringArgument('root_id', default=None, required=False),
Argument('next_page', default=None, required=False), Argument('next_page', default=None, required=False),
) )

def get_context(self, context, from_level, to_level, extra_inactive, def get_context(self, context, from_level, to_level, extra_inactive,
extra_active, template, namespace, root_id, next_page): extra_active, template, namespace, root_id, next_page):
try: try:
# If there's an exception (500), default context_processors may not be called. # If there's an exception (500), default context_processors may not be called.
request = context['request'] request = context['request']
except KeyError: except KeyError:
return {'template': 'menu/empty.html'} return {'template': 'menu/empty.html'}

if next_page: if next_page:
children = next_page.children children = next_page.children
else: else:
#new menu... get all the data so we can save a lot of queries # new menu... get all the data so we can save a lot of queries
nodes = menu_pool.get_nodes(request, namespace, root_id) nodes = menu_pool.get_nodes(request, namespace, root_id)
if root_id: # find the root id and cut the nodes if root_id: # find the root id and cut the nodes
id_nodes = menu_pool.get_nodes_by_attribute(nodes, "reverse_id", root_id) id_nodes = menu_pool.get_nodes_by_attribute(nodes, "reverse_id", root_id)
if id_nodes: if id_nodes:
node = id_nodes[0] node = id_nodes[0]
Expand All @@ -140,7 +140,7 @@ def get_context(self, context, from_level, to_level, extra_inactive,
nodes = [] nodes = []
children = cut_levels(nodes, from_level, to_level, extra_inactive, extra_active) children = cut_levels(nodes, from_level, to_level, extra_inactive, extra_active)
children = menu_pool.apply_modifiers(children, request, namespace, root_id, post_cut=True) children = menu_pool.apply_modifiers(children, request, namespace, root_id, post_cut=True)

try: try:
context.update({'children':children, context.update({'children':children,
'template':template, 'template':template,
Expand Down Expand Up @@ -178,12 +178,12 @@ class ShowSubMenu(InclusionTag):
""" """
name = 'show_sub_menu' name = 'show_sub_menu'
template = 'menu/dummy.html' template = 'menu/dummy.html'

options = Options( options = Options(
IntegerArgument('levels', default=100, required=False), IntegerArgument('levels', default=100, required=False),
Argument('template', default='menu/sub_menu.html', required=False), Argument('template', default='menu/sub_menu.html', required=False),
) )

def get_context(self, context, levels, template): def get_context(self, context, levels, template):
try: try:
# If there's an exception (500), default context_processors may not be called. # If there's an exception (500), default context_processors may not be called.
Expand All @@ -207,7 +207,7 @@ def get_context(self, context, levels, template):
'extra_inactive':0, 'extra_inactive':0,
'extra_active':0 'extra_active':0
}) })
return context return context
register.tag(ShowSubMenu) register.tag(ShowSubMenu)




Expand All @@ -220,7 +220,7 @@ class ShowBreadcrumb(InclusionTag):
""" """
name = 'show_breadcrumb' name = 'show_breadcrumb'
template = 'menu/dummy.html' template = 'menu/dummy.html'

options = Options( options = Options(
Argument('start_level', default=0, required=False), Argument('start_level', default=0, required=False),
Argument('template', default='menu/breadcrumb.html', required=False), Argument('template', default='menu/breadcrumb.html', required=False),
Expand Down Expand Up @@ -296,7 +296,7 @@ class LanguageChooser(InclusionTag):
""" """
name = 'language_chooser' name = 'language_chooser'
template = 'menu/dummy.html' template = 'menu/dummy.html'

options = Options( options = Options(
Argument('template', default=NOT_PROVIDED, required=False), Argument('template', default=NOT_PROVIDED, required=False),
Argument('i18n_mode', default='raw', required=False), Argument('i18n_mode', default='raw', required=False),
Expand All @@ -321,8 +321,9 @@ def get_context(self, context, template, i18n_mode):
current_lang = get_language() current_lang = get_language()
site = Site.objects.get_current() site = Site.objects.get_current()
languages = [] languages = []
edit = 'edit' in context['request'].GET and context['request'].user.is_staff
for lang in get_language_objects(site.pk): for lang in get_language_objects(site.pk):
if lang.get('public', True): if lang.get('public', True) or edit:
languages.append((lang['code'], marker(lang['name'], lang['code']))) languages.append((lang['code'], marker(lang['name'], lang['code'])))
context.update({ context.update({
'languages':languages, 'languages':languages,
Expand All @@ -341,11 +342,11 @@ class PageLanguageUrl(InclusionTag):
""" """
name = 'page_language_url' name = 'page_language_url'
template = 'cms/content.html' template = 'cms/content.html'

options = Options( options = Options(
Argument('lang'), Argument('lang'),
) )

def get_context(self, context, lang): def get_context(self, context, lang):
try: try:
# If there's an exception (500), default context_processors may not be called. # If there's an exception (500), default context_processors may not be called.
Expand Down

0 comments on commit 225974e

Please sign in to comment.