diff options
author | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2013-01-16 21:23:04 -0300 |
---|---|---|
committer | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2013-01-16 21:23:04 -0300 |
commit | 488c52b1bd8711a07e9f6dce03fa86228bca1c31 (patch) | |
tree | 0b5224934d595589417114eaaa4813405ceff389 /askbot/forms.py | |
parent | 4cda312624af2d4d8465a64299aa6ba3a852c973 (diff) | |
download | askbot-488c52b1bd8711a07e9f6dce03fa86228bca1c31.tar.gz askbot-488c52b1bd8711a07e9f6dce03fa86228bca1c31.tar.bz2 askbot-488c52b1bd8711a07e9f6dce03fa86228bca1c31.zip |
allowed change of language upon editing the question
Diffstat (limited to 'askbot/forms.py')
-rw-r--r-- | askbot/forms.py | 25 |
1 files changed, 22 insertions, 3 deletions
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 |