Permalink
Browse files

adds language tabs to admin

  • Loading branch information...
1 parent 22016d3 commit 8ee67aa6afe1d9345179cb70d9a19de489a7d052 @stefanfoulis stefanfoulis committed Dec 3, 2012
Showing with 91 additions and 13 deletions.
  1. +12 −8 stacks/admin.py
  2. +79 −5 stacks/templates/admin/stacks/stack/change_form.html
View
@@ -10,7 +10,8 @@ class StackAdmin(PlaceholderAdmin):
search_fields = ('name', 'code',)
def change_view(self, request, object_id, form_url='', extra_context=None):
- extra_context = self.update_language_tab_context(request, obj, context)
+ extra_context = extra_context or {}
+ extra_context.update(self.language_tab_context(request))
tab_language = request.GET.get("language", None)
response = super(StackAdmin, self).change_view(request, object_id, extra_context=extra_context)
@@ -19,16 +20,19 @@ def change_view(self, request, object_id, form_url='', extra_context=None):
response._headers['location'] = (location[0], "%s?language=%s" % (location[1], tab_language))
return response
- def update_language_tab_context(self, request, obj, context=None):
- if not context:
- context = {}
- language = get_language_from_request(request, obj)
- languages = [lang for lang, __ in settings.LANGUAGES]
- context.update({
+ def language_tab_context(self, request):
+ language = get_language_from_request(request)
+ languages = [(lang, lang_name) for lang, lang_name in settings.LANGUAGES]
+ context = {
'language': language,
'language_tabs': languages,
'show_language_tabs': len(languages) > 1,
- })
+ }
return context
+ def placeholder_plugin_filter(self, request, queryset):
+ language = get_language_from_request(request)
+ return queryset.filter(language=language)
+
+
admin.site.register(Stack, StackAdmin)
@@ -1,7 +1,78 @@
{% extends 'admin/change_form.html' %}
+{% load cms_admin %}
+
+{% block extrahead %}
+{{ block.super }}
+<script type="text/javascript">
+(function($) {
+ $(document).ready(function() {
+ $("#id_name").focus();
+ $("#id_name").change(function() { this._changed = true; });
+ $('#id_code').change(function() { this._changed = true; });
+ });
+ // global functions
+ trigger_lang_button = function(e, url) {
+ console.log("lang switch!");
+ var changed = false;
+ var question = '';
+ var answer = '';
+
+ if($("#id_name")[0]._changed){
+ changed = true;
+ }
+
+ if($("#id_code")[0]._changed){
+ changed = true;
+ }
+
+ if($('iframe').length){
+ changed = true;
+ }
+
+ if (changed) {
+ question = gettext("Are you sure you want to change tabs without saving the page first?");
+ answer = confirm(question);
+ }else{
+ answer = true;
+ }
+
+ if (!answer) {
+ return false;
+ } else {
+ window.location = url;
+ }
+ }
+})(django.jQuery);
+</script>
+<style type="text/css">
+ <!--
+ .language_button {
+ font-weight:bold;
+ margin-bottom:-1px;
+ border-color:#ddd #aaa #ccc #ddd !important;
+ border:1px;
+ background:#fff url('{% cms_admin_icon_base %}nav-bg.gif') repeat-x center bottom !important;
+ }
+
+ #lang_tab_content h2.header {
+ margin:0;
+ padding:2px 5px 3px 5px;
+ font-size:11px;
+ text-align:left;
+ font-weight:bold;
+ background:#7ca0c7 url('{% cms_admin_icon_base %}default-bg.gif') repeat-x left top;
+ color:#fff;
+ }
+
+ .notfilled {
+ color: #808080 !important;
+ }
+ -->
+</style>
+{% endblock %}
{% block field_sets %}
- <div style="display: none;"><input type="hidden" name="language" value="{{language}}" id="id_language"/></div>
+ <div style="display: none;"><input type="hidden" name="language" value="{{ language }}" id="id_language"/></div>
{% if show_language_tabs %}
<div id="page_form_lang_tabs">
@@ -13,9 +84,12 @@
</div>
{% endif %}
+ <div id="lang_tab_content">
+ {% if show_language_tabs %}
+ <h2 class="header"></h2>
+ {% endif %}
- {% if show_language_tabs %}
- <h2 class="header"></h2>
- {% endif %}
-{{ block.super }}
+ {{ block.super }}
+
+ </div>
{% endblock %}

0 comments on commit 8ee67aa

Please sign in to comment.