diff options
-rw-r--r-- | askbot/conf/forum_data_rules.py | 14 | ||||
-rw-r--r-- | askbot/conf/moderation.py | 14 | ||||
-rw-r--r-- | askbot/conf/social_sharing.py | 11 | ||||
-rw-r--r-- | askbot/context.py | 4 | ||||
-rw-r--r-- | askbot/forms.py | 25 | ||||
-rw-r--r-- | askbot/media/js/post.js | 33 | ||||
-rw-r--r-- | askbot/media/js/tag_moderation.js | 14 | ||||
-rw-r--r-- | askbot/media/js/utils.js | 2 | ||||
-rw-r--r-- | askbot/media/style/style.less | 24 | ||||
-rw-r--r-- | askbot/models/post.py | 52 | ||||
-rw-r--r-- | askbot/templates/404.html | 4 | ||||
-rw-r--r-- | askbot/templates/base.html | 6 | ||||
-rw-r--r-- | askbot/templates/meta/bottom_scripts.html | 5 | ||||
-rw-r--r-- | askbot/templates/question_edit.html | 11 | ||||
-rw-r--r-- | askbot/templates/user_profile/user_email_subscriptions.html | 8 | ||||
-rw-r--r-- | askbot/templates/widget_base.html | 2 | ||||
-rw-r--r-- | askbot/templates/widgets/ask_form.html | 11 | ||||
-rw-r--r-- | askbot/templates/widgets/language_nav.html | 23 | ||||
-rw-r--r-- | askbot/tests/skin_tests.py | 5 | ||||
-rw-r--r-- | askbot/views/readers.py | 11 | ||||
-rw-r--r-- | askbot/views/writers.py | 17 |
21 files changed, 197 insertions, 99 deletions
diff --git a/askbot/conf/forum_data_rules.py b/askbot/conf/forum_data_rules.py index bd974334..e8a2b539 100644 --- a/askbot/conf/forum_data_rules.py +++ b/askbot/conf/forum_data_rules.py @@ -154,20 +154,6 @@ settings.register( ) ) -settings.register( - livesettings.BooleanValue( - FORUM_DATA_RULES, - 'ENABLE_TAG_MODERATION', - default = False, - description = _('Enable tag moderation'), - help_text = _( - 'If enabled, any new tags will not be applied ' - 'to the questions, but emailed to the moderators. ' - 'To use this feature, tags must be optional.' - ) - ) -) - TAG_SOURCE_CHOICES = ( ('category-tree', _('category tree')), ('user-input', _('user input')), diff --git a/askbot/conf/moderation.py b/askbot/conf/moderation.py index 70cf9119..b537663f 100644 --- a/askbot/conf/moderation.py +++ b/askbot/conf/moderation.py @@ -29,3 +29,17 @@ settings.register( update_callback = empty_cache_callback ) ) + +settings.register( + BooleanValue( + MODERATION, + 'ENABLE_TAG_MODERATION', + default = False, + description = _('Enable tag moderation'), + help_text = _( + 'If enabled, any new tags will not be applied ' + 'to the questions, but emailed to the moderators. ' + 'To use this feature, tags must be optional.' + ) + ) +) diff --git a/askbot/conf/social_sharing.py b/askbot/conf/social_sharing.py index 6f39043a..e57dec28 100644 --- a/askbot/conf/social_sharing.py +++ b/askbot/conf/social_sharing.py @@ -3,7 +3,7 @@ Social sharing settings """ from askbot.conf.settings_wrapper import settings from askbot.conf.super_groups import EXTERNAL_SERVICES -from askbot.deps.livesettings import ConfigurationGroup, BooleanValue +from askbot.deps.livesettings import ConfigurationGroup, BooleanValue, StringValue from django.utils.translation import ugettext_lazy as _ SOCIAL_SHARING = ConfigurationGroup( @@ -22,6 +22,15 @@ settings.register( ) settings.register( + StringValue( + SOCIAL_SHARING, + 'SHARING_SUFFIX_TEXT', + default='', + description=_('Hashtag or suffix to sharing messages') + ) +) + +settings.register( BooleanValue( SOCIAL_SHARING, 'ENABLE_SHARING_TWITTER', diff --git a/askbot/context.py b/askbot/context.py index 96f30074..523e8e09 100644 --- a/askbot/context.py +++ b/askbot/context.py @@ -6,6 +6,7 @@ import sys from django.conf import settings from django.core.urlresolvers import reverse from django.utils import simplejson +from django.utils.translation import get_language import askbot from askbot import api @@ -30,7 +31,7 @@ def application_settings(request): my_settings = askbot_settings.as_dict() my_settings['LANGUAGE_CODE'] = getattr(request, 'LANGUAGE_CODE', settings.LANGUAGE_CODE) my_settings['MULTILINGUAL'] = getattr(settings, 'ASKBOT_MULTILINGUAL', False) - my_settings['LANGUAGES'] = getattr(settings, 'LANGUAGES', []) + my_settings['LANGUAGES_DICT'] = dict(getattr(settings, 'LANGUAGES', [])) my_settings['ALLOWED_UPLOAD_FILE_TYPES'] = \ settings.ASKBOT_ALLOWED_UPLOAD_FILE_TYPES my_settings['ASKBOT_URL'] = settings.ASKBOT_URL @@ -54,6 +55,7 @@ def application_settings(request): my_settings['USE_ASKBOT_LOGIN_SYSTEM'] = 'askbot.deps.django_authopenid' \ in settings.INSTALLED_APPS context = { + 'current_language_code': get_language(), 'settings': my_settings, 'skin': get_skin(request), 'moderation_items': api.get_info_on_moderation_items(request.user), diff --git a/askbot/forms.py b/askbot/forms.py index f96b4c5c..daa4bd25 100644 --- a/askbot/forms.py +++ b/askbot/forms.py @@ -4,6 +4,7 @@ import re from django import forms from askbot import const from askbot.const import message_keys +from django.conf import settings as django_settings from django.core.exceptions import PermissionDenied from django.forms.util import ErrorList from django.utils.translation import ugettext_lazy as _ @@ -203,6 +204,13 @@ class CountedWordsField(forms.CharField): return value +class LanguageField(forms.ChoiceField): + + def __init__(self, *args, **kwargs): + kwargs['choices'] = django_settings.LANGUAGES + super(LanguageField, self).__init__(*args, **kwargs) + + class DomainNameField(forms.CharField): """Field for Internet Domain Names todo: maybe there is a standard field for this? @@ -919,7 +927,6 @@ class AskForm(PostAsSomeoneForm, PostPrivatelyForm): required=False, max_length=255, widget=forms.TextInput(attrs={'size': 40, 'class': 'openid-input'}) ) - language = forms.CharField(required=False, max_length=16) def __init__(self, *args, **kwargs): user = kwargs.pop('user', None) @@ -927,6 +934,9 @@ class AskForm(PostAsSomeoneForm, PostPrivatelyForm): #it's important that this field is set up dynamically self.fields['text'] = QuestionEditorField(user=user) #hide ask_anonymously field + if getattr(django_settings, 'ASKBOT_MULTILINGUAL', False): + self.fields['language'] = LanguageField() + if askbot_settings.ALLOW_ASK_ANONYMOUSLY is False: self.hide_field('ask_anonymously') @@ -1208,12 +1218,21 @@ class EditQuestionForm(PostAsSomeoneForm, PostPrivatelyForm): if not self.can_stay_anonymous(): self.hide_field('reveal_identity') + if getattr(django_settings, 'ASKBOT_MULTILINGUAL', False): + self.fields['language'] = LanguageField() + def has_changed(self): if super(EditQuestionForm, self).has_changed(): return True if askbot_settings.GROUPS_ENABLED: - return self.question.is_private() \ - != self.cleaned_data['post_privately'] + was_private = self.question.is_private() + if was_private != self.cleaned_data['post_privately']: + return True + + if getattr(django_settings, 'ASKBOT_MULTILINGUAL', False): + old_language = self.question.thread.language_code + if old_language != self.cleaned_data['language']: + return True else: return False diff --git a/askbot/media/js/post.js b/askbot/media/js/post.js index e30a0c88..aa3437cb 100644 --- a/askbot/media/js/post.js +++ b/askbot/media/js/post.js @@ -2073,18 +2073,28 @@ var socialSharing = function(){ var share_page = function(service_name){ if (SERVICE_DATA[service_name]){ var url = SERVICE_DATA[service_name]['url']; + url = url.replace('{TEXT}', TEXT); + url = url.replace('{URL}', URL); + var params = SERVICE_DATA[service_name]['params']; + debugger; + if(!window.open(url, "sharing", params)){ + window.location.href=url; + } + return false; + //@todo: change to some other url shortening service $.ajax({ - async: false, url: "http://json-tinyurl.appspot.com/?&callback=?", dataType: "json", data: {'url':URL}, - success: function(data){ + success: function(data) { url = url.replace('{URL}', data.tinyurl); }, - error: function(data){ + error: function(xhr, opts, error) { + debugger; url = url.replace('{URL}', URL); }, - complete: function(data){ + complete: function(data) { + debugger; url = url.replace('{TEXT}', TEXT); var params = SERVICE_DATA[service_name]['params']; if(!window.open(url, "sharing", params)){ @@ -2098,7 +2108,14 @@ var socialSharing = function(){ return { init: function(){ URL = window.location.href; + var urlBits = URL.split('/'); + URL = urlBits.slice(0, -2).join('/') + '/'; TEXT = escape($('h1 > a').html()); + var hashtag = encodeURIComponent( + askbot['settings']['sharingSuffixText'] + ); + TEXT = TEXT.substr(0, 134 - URL.length - hashtag.length); + TEXT = TEXT + '... ' + hashtag; var fb = $('a.facebook-share') var tw = $('a.twitter-share'); var ln = $('a.linkedin-share'); @@ -2107,10 +2124,10 @@ var socialSharing = function(){ copyAltToTitle(tw); copyAltToTitle(ln); copyAltToTitle(ica); - setupButtonEventHandlers(fb, function(){share_page("facebook")}); - setupButtonEventHandlers(tw, function(){share_page("twitter")}); - setupButtonEventHandlers(ln, function(){share_page("linkedin")}); - setupButtonEventHandlers(ica, function(){share_page("identica")}); + setupButtonEventHandlers(fb, function(){ share_page("facebook") }); + setupButtonEventHandlers(tw, function(){ share_page("twitter") }); + setupButtonEventHandlers(ln, function(){ share_page("linkedin") }); + setupButtonEventHandlers(ica, function(){ share_page("identica") }); } } }(); diff --git a/askbot/media/js/tag_moderation.js b/askbot/media/js/tag_moderation.js index 31e05e37..009e4e32 100644 --- a/askbot/media/js/tag_moderation.js +++ b/askbot/media/js/tag_moderation.js @@ -86,9 +86,14 @@ PerThreadTagModerator.prototype.afterActionHandler = function() { ancestor.hideButtons(); this.dispose(); } else if (childCount == 0) { - var table = $('.suggested-tags-table'); - table.before($('<p>' + gettext('No suggested tags left') + '</p>')); - table.remove(); + //this does not work with the fade-out of table rows... + /* var callback = function() { + var table = $('.suggested-tags-table'); + if (table.find('tr.suggested-tag-row').length == 0) { + table.before($('<p>' + gettext('No suggested tags left') + '</p>')); + table.remove(); + } + }; */ ancestor.dispose(); } else { this.dispose(); @@ -164,7 +169,7 @@ AllThreadsTagModerator.prototype.afterActionHandler = function() { }; AllThreadsTagModerator.prototype.dispose = function() { - this._tag_entry_element.fadeOut('fast', function() { + var eventChain = this._tag_entry_element.fadeOut('fast', function() { $.each(this._children, function(idx, child) { child.dispose(); }); @@ -200,6 +205,7 @@ AllThreadsTagModerator.prototype.decorate = function(element) { var tagEntry = $(element); var tagId = tagEntry.data('tagId'); + //handles the case where there are >1 threads per tag var tagMod = new AllThreadsTagModerator(); tagMod.decorate(tagEntry.next()); tagMod.setTagId(tagId); diff --git a/askbot/media/js/utils.js b/askbot/media/js/utils.js index e9ae4dd2..07368194 100644 --- a/askbot/media/js/utils.js +++ b/askbot/media/js/utils.js @@ -1615,7 +1615,7 @@ var SelectBox = function(){ this._items = []; this._select_handler = function(){};//empty default this._is_editable = false; - this._item_class = this.setItemClass(SelectBoxItem); + this._item_class = SelectBoxItem; }; inherits(SelectBox, Widget); diff --git a/askbot/media/style/style.less b/askbot/media/style/style.less index b6db03ac..c2e20577 100644 --- a/askbot/media/style/style.less +++ b/askbot/media/style/style.less @@ -249,15 +249,23 @@ body.user-messages { } .lang-nav { + position: relative; ul { + display: none; list-style: none; + z-index: 10000; + margin: 0; } - li { - display: inline; - padding-right: 16px; + &:hover ul, + ul:hover { + display: block; + position: absolute; + width: 100px; } - li.current { - font-weight: bold; + li { + color: @info-text; + background: white; + display: block; } } @@ -1444,17 +1452,19 @@ ul#related-tags li { padding-right: 20px; } td.per-thread-controls { - width: 120px;/* 20px more to compensate for the padding */ + width: 160px;/* 20px more to compensate for the padding */ height: 30px; button { display: none; } } - th.decision-col, th.tags-col, th.users-col { width: 100px; } + th.decision-col { + width: 140px; + } tr.per-tag-controls { height: 30px; text-align: center; diff --git a/askbot/models/post.py b/askbot/models/post.py index 64b409d8..e5e96f3b 100644 --- a/askbot/models/post.py +++ b/askbot/models/post.py @@ -7,11 +7,13 @@ import logging from django.utils.html import strip_tags from django.contrib.sitemaps import ping_google from django.utils import html -from django.conf import settings +from django.conf import settings as django_settings from django.contrib.auth.models import User from django.core import urlresolvers from django.db import models from django.utils import html as html_utils +from django.utils.translation import activate as activate_language +from django.utils.translation import get_language from django.utils.translation import ugettext as _ from django.utils.http import urlquote as django_urlquote from django.core import exceptions as django_exceptions @@ -78,11 +80,11 @@ class PostQuerySet(models.query.QuerySet): | models.Q(thread__posts__text__icontains = search_query, thread__posts__post_type='answer') ) # #todo - goes to thread - we search whole threads -# if getattr(settings, 'USE_SPHINX_SEARCH', False): +# if getattr(django_settings, 'USE_SPHINX_SEARCH', False): # matching_questions = Question.sphinx_search.query(search_query) # question_ids = [q.id for q in matching_questions] # return Question.objects.filter(deleted = False, id__in = question_ids) -# if settings.DATABASE_ENGINE == 'mysql' and mysql.supports_full_text_search(): +# if django_settings.DATABASE_ENGINE == 'mysql' and mysql.supports_full_text_search(): # return self.filter( # models.Q(thread__title__search = search_query)\ # | models.Q(text__search = search_query)\ @@ -667,18 +669,18 @@ class Post(models.Model): notify_sets['for_email'] = \ [u for u in notify_sets['for_email'] if u.is_administrator()] - if not settings.CELERY_ALWAYS_EAGER: + if not django_settings.CELERY_ALWAYS_EAGER: cache_key = 'instant-notification-%d-%d' % (self.thread.id, updated_by.id) if cache.cache.get(cache_key): return - cache.cache.set(cache_key, True, settings.NOTIFICATION_DELAY_TIME) + cache.cache.set(cache_key, True, django_settings.NOTIFICATION_DELAY_TIME) from askbot.tasks import send_instant_notifications_about_activity_in_post send_instant_notifications_about_activity_in_post.apply_async(( update_activity, self, notify_sets['for_email']), - countdown = settings.NOTIFICATION_DELAY_TIME + countdown = django_settings.NOTIFICATION_DELAY_TIME ) def make_private(self, user, group_id=None): @@ -741,10 +743,16 @@ class Post(models.Model): #the trailing slash is entered in three places here + in urls.py if not hasattr(self, '_thread_cache') and thread: self._thread_cache = thread + + is_multilingual = getattr(django_settings, 'ASKBOT_MULTILINGUAL', False) + if is_multilingual: + request_language = get_language() + activate_language(self.thread.language_code) + if self.is_answer(): if not question_post: question_post = self.thread._question_post() - return u'%(base)s%(slug)s/?answer=%(id)d#post-id-%(id)d' % { + url = u'%(base)s%(slug)s/?answer=%(id)d#post-id-%(id)d' % { 'base': urlresolvers.reverse('question', args=[question_post.id]), 'slug': django_urlquote(slugify(self.thread.title)), 'id': self.id @@ -755,13 +763,17 @@ class Post(models.Model): url += django_urlquote(slugify(thread.title)) + '/' elif no_slug is False: url += django_urlquote(self.slug) + '/' - return url elif self.is_comment(): origin_post = self.get_origin_post() - return '%(url)s?comment=%(id)d#comment-%(id)d' % \ + url = '%(url)s?comment=%(id)d#comment-%(id)d' % \ {'url': origin_post.get_absolute_url(thread=thread), 'id':self.id} + else: + raise NotImplementedError - raise NotImplementedError + if is_multilingual: + activate_language(request_language) + + return url def delete(self, **kwargs): """deletes comment and concomitant response activity @@ -1270,7 +1282,7 @@ class Post(models.Model): subscribers = self.filter_authorized_users(subscribers) #filter subscribers by language - if settings.ASKBOT_MULTILINGUAL: + if getattr(django_settings, 'ASKBOT_MULTILINGUAL', False): language = self.thread.language_code filtered_subscribers = list() for subscriber in subscribers: @@ -2159,12 +2171,24 @@ class PostRevision(models.Model): super(PostRevision, self).save(**kwargs) def get_absolute_url(self): + + is_multilingual = getattr(django_settings, 'ASKBOT_MULTILINGUAL', False) + + if is_multilingual: + request_language = get_language() + activate_language(self.thread.language_code) + if self.post.is_question(): - return reverse('question_revisions', args = (self.post.id,)) + url = reverse('question_revisions', args = (self.post.id,)) elif self.post.is_answer(): - return reverse('answer_revisions', kwargs = {'id':self.post.id}) + url = reverse('answer_revisions', kwargs = {'id':self.post.id}) else: - return self.post.get_absolute_url() + url = self.post.get_absolute_url() + + if is_multilingual: + activate_language(request_language) + + return url def get_question_title(self): #INFO: ack-grepping shows that it's only used for Questions, so there's no code for Answers diff --git a/askbot/templates/404.html b/askbot/templates/404.html index 2da99646..565ff164 100644 --- a/askbot/templates/404.html +++ b/askbot/templates/404.html @@ -22,8 +22,8 @@ </u> </div> <script type="text/javascript"> - var GOOG_FIXURL_LANG = '{{settings.LANGUAGE_CODE}}'; - var GOOG_FIXURL_SITE = '{{site_url}}'; + var GOOG_FIXURL_LANG = '{{ language_code }}'; + var GOOG_FIXURL_SITE = '{{ site_url }}'; </script> <script type="text/javascript" src="http://linkhelp.clients.google.com/tbproxy/lh/wm/fixurl.js"></script> <ul> diff --git a/askbot/templates/base.html b/askbot/templates/base.html index 56288476..6c162057 100644 --- a/askbot/templates/base.html +++ b/askbot/templates/base.html @@ -28,11 +28,13 @@ {{ settings.CUSTOM_HTML_HEAD }} {% endif %} </head> - <body class="{% block body_class %}{% endblock %}{% if user_messages %} user-messages{% endif %}{% if page_class %} {{page_class}}{% endif %}{% if request.user.is_anonymous() %} anon{% endif %} lang-{{settings.LANGUAGE_CODE}}"> + <body class="{% block body_class %}{% endblock %}{% if user_messages %} user-messages{% endif %}{% if page_class %} {{page_class}}{% endif %}{% if request.user.is_anonymous() %} anon{% endif %} lang-{{ language_code }}"> {% include "widgets/system_messages.html" %} {% include "debug_header.html" %} {% if settings.MULTILINGUAL %} - {% include "widgets/language_nav.html" %} + <div class="content-wrapper"> + {% include "widgets/language_nav.html" %} + </div> {% endif %} {% include "custom_header.html" ignore missing %} {% if settings.CUSTOM_HEADER|trim != '' %} diff --git a/askbot/templates/meta/bottom_scripts.html b/askbot/templates/meta/bottom_scripts.html index 4b2bb6f8..1a910672 100644 --- a/askbot/templates/meta/bottom_scripts.html +++ b/askbot/templates/meta/bottom_scripts.html @@ -14,7 +14,7 @@ </script> </div> <script type="text/javascript"> - var i18nLang = '{{settings.LANGUAGE_CODE}}'; + var i18nLang = '{{ language_code }}'; var scriptUrl = '/{{settings.ASKBOT_URL}}' var askbotSkin = '{{settings.ASKBOT_DEFAULT_SKIN}}'; var enableMathJax = {% if settings.ENABLE_MATHJAX %}true{% else %}false{% endif %}; @@ -29,7 +29,8 @@ askbot['urls']['ask'] = '{% url "ask" %}'; askbot['urls']['questions'] = '{% url "questions" %}'; askbot['settings']['static_url'] = '{{ settings.STATIC_URL }}'; - askbot['settings']['minSearchWordLength'] = {{settings.MIN_SEARCH_WORD_LENGTH}}; + askbot['settings']['minSearchWordLength'] = {{ settings.MIN_SEARCH_WORD_LENGTH }}; + askbot['settings']['sharingSuffixText'] = '{{ settings.SHARING_SUFFIX_TEXT|escape }}'; </script> <script type="text/javascript" diff --git a/askbot/templates/question_edit.html b/askbot/templates/question_edit.html index a4fe17df..653d351e 100644 --- a/askbot/templates/question_edit.html +++ b/askbot/templates/question_edit.html @@ -45,15 +45,8 @@ {{ macros.checkbox_in_div(form.post_privately) }} {% endif %} {% if settings.MULTILINGUAL %} - <label for="language">{% trans %}Change language{% endtrans %}</label> - <select name="language"> - {% for lang in settings.LANGUAGES %} - <option - value="{{ lang[0] }}" - {% if lang[0] == question.get_origin_post().language_code %}selected="selected"{% endif %} - >{{ lang[1] }}</option> - {% endfor %} - </select> + <label for="id_language">{% trans %}Change language{% endtrans %}</label> + {{ form.language }} {% endif %} </div> <input id="edit_post_form_submit_button" type="submit" value="{% trans %}Save edit{% endtrans %}" class="submit" /> diff --git a/askbot/templates/user_profile/user_email_subscriptions.html b/askbot/templates/user_profile/user_email_subscriptions.html index 5ec81203..4692456b 100644 --- a/askbot/templates/user_profile/user_email_subscriptions.html +++ b/askbot/templates/user_profile/user_email_subscriptions.html @@ -33,11 +33,11 @@ action="{% url user_select_languages view_user.id, view_user.username|slugify %}" >{% csrf_token %} <select multiple name="languages"> - {% for lang in settings.LANGUAGES %} + {% for lang in settings.LANGUAGES_DICT %} <option - value="{{ lang[0] }}" - {% if lang[0] in user_languages %}selected="selected"{% endif %} - >{{ lang[1] }}</option> + value="{{ lang }}" + {% if lang in user_languages %}selected="selected"{% endif %} + >{{ settings.LANGUAGES_DICT[lang] }}</option> {% endfor %} </select><br/> <input type="submit" class="select-language" value="{% trans %}Save languages{% endtrans %}" /> diff --git a/askbot/templates/widget_base.html b/askbot/templates/widget_base.html index 44be3e5f..be5bf301 100644 --- a/askbot/templates/widget_base.html +++ b/askbot/templates/widget_base.html @@ -9,7 +9,7 @@ {% block forejs %}{% endblock %} </head> {% endspaceless %} - <body class="lang-{{settings.LANGUAGE_CODE}}"> + <body class="lang-{{ language_code }}"> {% block body%} {% endblock %} {% block content%} diff --git a/askbot/templates/widgets/ask_form.html b/askbot/templates/widgets/ask_form.html index 9b6d72b8..080931ec 100644 --- a/askbot/templates/widgets/ask_form.html +++ b/askbot/templates/widgets/ask_form.html @@ -47,15 +47,8 @@ {{ macros.checkbox_in_div(form.post_privately) }} {% endif %} {% if settings.MULTILINGUAL %} - <label for="language">{% trans %}Select language{% endtrans %}</label> - <select name="language"> - {% for lang in settings.LANGUAGES %} - <option - value="{{ lang[0] }}" - {% if lang[0]|is_current_language() %}selected="selected"{% endif %} - >{{ lang[1] }}</option> - {% endfor %} - </select> + <label for="id_language">{% trans %}Select language{% endtrans %}</label> + {{ form.language }} {% endif %} </div> {% if not request.user.is_authenticated() %} diff --git a/askbot/templates/widgets/language_nav.html b/askbot/templates/widgets/language_nav.html index 57603ab5..7db6d559 100644 --- a/askbot/templates/widgets/language_nav.html +++ b/askbot/templates/widgets/language_nav.html @@ -1,9 +1,14 @@ -<ul class="content-wrapper lang-nav"> -{% for language in settings.LANGUAGES %} - <li {% if language[0]|is_current_language() %}class="current"{% endif %}> - <a - href="/{{ language[0] }}/{{ settings.ASKBOT_URL }}" - >{{ language[1] }}</a> - </li> -{% endfor %} -</ul> +<span class="lang-nav"> + <span>{{ settings.LANGUAGES_DICT[language_code] }}</span> + <ul> + {% for lang in settings.LANGUAGES_DICT %} + {% if lang != language_code %} + <li> + <a + href="/{{ lang }}/{{ settings.ASKBOT_URL }}" + >{{ settings.LANGUAGES_DICT[lang] }}</a> + </li> + {% endif %} + {% endfor %} + </ul> +</span> diff --git a/askbot/tests/skin_tests.py b/askbot/tests/skin_tests.py index 8499ab70..96bb7d43 100644 --- a/askbot/tests/skin_tests.py +++ b/askbot/tests/skin_tests.py @@ -39,7 +39,10 @@ class SkinTests(TestCase): ) shutil.rmtree(self.temp_dir) askbot_settings.update('ASKBOT_DEFAULT_SKIN', 'default') - django_settings.ASKBOT_EXTRA_SKINS_DIR = self.skins_dir_backup + if self.skins_dir_backup is None: + del(django_settings.ASKBOT_EXTRA_SKINS_DIR) + else: + django_settings.ASKBOT_EXTRA_SKINS_DIR = self.skins_dir_backup def assert_default_logo_in_skin(self, skin_name): url = skin_utils.get_media_url(askbot_settings.SITE_LOGO_URL) diff --git a/askbot/views/readers.py b/askbot/views/readers.py index d2c9df49..7fbcf6d0 100644 --- a/askbot/views/readers.py +++ b/askbot/views/readers.py @@ -26,7 +26,7 @@ from django.core.urlresolvers import reverse from django.core import exceptions as django_exceptions from django.contrib.humanize.templatetags import humanize from django.http import QueryDict -from django.conf import settings +from django.conf import settings as django_settings import askbot from askbot import exceptions @@ -141,7 +141,10 @@ def questions(request, **kwargs): # We have tags in session - pass it to the # QueryDict but as a list - we want tags+ rss_query_dict.setlist("tags", search_state.tags) - context_feed_url = '/%sfeeds/rss/?%s' % (settings.ASKBOT_URL, rss_query_dict.urlencode()) # Format the url with the QueryDict + context_feed_url = '/%sfeeds/rss/?%s' % ( + django_settings.ASKBOT_URL, + rss_query_dict.urlencode() + ) # Format the url with the QueryDict reset_method_count = len(filter(None, [search_state.query, search_state.tags, meta_data.get('author_name', None)])) @@ -448,6 +451,10 @@ def question(request, id):#refactor - long subroutine. display question body, an thread = question_post.thread + if getattr(django_settings, 'ASKBOT_MULTILINGUAL', False): + if thread.language_code != translation.get_language(): + return HttpResponseRedirect(thread.get_absolute_url()) + logging.debug('answer_sort_method=' + unicode(answer_sort_method)) #load answers and post id's->athor_id mapping diff --git a/askbot/views/writers.py b/askbot/views/writers.py index 956145fa..17f806df 100644 --- a/askbot/views/writers.py +++ b/askbot/views/writers.py @@ -20,6 +20,7 @@ from django.contrib.auth.models import User from django.http import HttpResponseRedirect, HttpResponse, HttpResponseForbidden, Http404 from django.utils import simplejson from django.utils.html import strip_tags, escape +from django.utils.translation import get_language from django.utils.translation import ugettext as _ from django.utils.translation import ugettext_lazy from django.core.urlresolvers import reverse @@ -265,7 +266,10 @@ def ask(request):#view used to ask a new question return HttpResponseRedirect(url_utils.get_login_url()) if request.method == 'GET': - form = forms.AskForm(user=request.user) + form = forms.AskForm( + user=request.user, + initial={'language': get_language()} + ) draft_title = '' draft_text = '' @@ -409,10 +413,12 @@ def edit_question(request, id): revision_form = forms.RevisionForm(question, revision) if form.is_valid(): if form.has_changed(): - if form.cleaned_data['reveal_identity']: question.thread.remove_author_anonymity() + if 'language' in form.cleaned_data: + question.thread.language_code = form.cleaned_data['language'] + is_anon_edit = form.cleaned_data['stay_anonymous'] is_wiki = form.cleaned_data.get('wiki', question.wiki) post_privately = form.cleaned_data['post_privately'] @@ -420,9 +426,9 @@ def edit_question(request, id): user = form.get_post_user(request.user) user.edit_question( - question = question, - title = form.cleaned_data['title'], - body_text = form.cleaned_data['text'], + question=question, + title=form.cleaned_data['title'], + body_text=form.cleaned_data['text'], revision_comment = form.cleaned_data['summary'], tags = form.cleaned_data['tags'], wiki = is_wiki, @@ -434,6 +440,7 @@ def edit_question(request, id): #request type was "GET" revision_form = forms.RevisionForm(question, revision) initial = { + 'language': question.thread.language_code, 'post_privately': question.is_private(), 'wiki': question.wiki } |