diff options
author | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2014-06-14 07:19:32 -0300 |
---|---|---|
committer | Evgeny Fadeev <evgeny.fadeev@gmail.com> | 2014-06-14 07:19:32 -0300 |
commit | 37d507dc3ee31756f10a027c358c5b72cc26d1f8 (patch) | |
tree | d21a3fd3949977c0409ab4f6fd30d124b6387074 | |
parent | e52c22029bebd24033c4373fd55ca07e9e9ae997 (diff) | |
parent | 7ddd67ebdc119a7f95a24775c84f3bb5b8f274c5 (diff) | |
download | askbot-37d507dc3ee31756f10a027c358c5b72cc26d1f8.tar.gz askbot-37d507dc3ee31756f10a027c358c5b72cc26d1f8.tar.bz2 askbot-37d507dc3ee31756f10a027c358c5b72cc26d1f8.zip |
Added option to allow asking without registration
-rw-r--r-- | askbot/conf/forum_data_rules.py | 12 | ||||
-rw-r--r-- | askbot/doc/source/changelog.rst | 1 | ||||
-rw-r--r-- | askbot/doc/source/contributors.rst | 1 | ||||
-rw-r--r-- | askbot/forms.py | 12 | ||||
-rw-r--r-- | askbot/models/__init__.py | 14 | ||||
-rw-r--r-- | askbot/templates/answer_edit.html | 3 | ||||
-rw-r--r-- | askbot/templates/widgets/ask_form.html | 6 | ||||
-rw-r--r-- | askbot/templates/widgets/question_edit_tips.html | 2 | ||||
-rw-r--r-- | askbot/views/writers.py | 14 |
9 files changed, 46 insertions, 19 deletions
diff --git a/askbot/conf/forum_data_rules.py b/askbot/conf/forum_data_rules.py index caa93563..cd138a88 100644 --- a/askbot/conf/forum_data_rules.py +++ b/askbot/conf/forum_data_rules.py @@ -84,7 +84,7 @@ settings.register( FORUM_DATA_RULES, 'ALLOW_ASK_ANONYMOUSLY', default=True, - description=_('Allow asking questions anonymously'), + description=_('Allow logged in users ask anonymously'), help_text=_( 'Users do not accrue reputation for anonymous questions ' 'and their identity is not revealed until they change their ' @@ -96,6 +96,16 @@ settings.register( settings.register( livesettings.BooleanValue( FORUM_DATA_RULES, + 'ALLOW_ASK_UNREGISTERED', + default=False, + description=_('Allow asking without registration'), + help_text=_('Enabling ReCaptcha is recommended with this feature') + ) +) + +settings.register( + livesettings.BooleanValue( + FORUM_DATA_RULES, 'ALLOW_POSTING_BEFORE_LOGGING_IN', default = True, description = _('Allow posting before logging in'), diff --git a/askbot/doc/source/changelog.rst b/askbot/doc/source/changelog.rst index 57a7b252..e554e324 100644 --- a/askbot/doc/source/changelog.rst +++ b/askbot/doc/source/changelog.rst @@ -3,6 +3,7 @@ Changes in Askbot Development master branch (only on github) ------------------------------------------ +* Option to allow asking without registration (Egil Moeller) * Implemented Mozilla Persona authentication * Allowed custom providers of gravatar service (michas2) * Allowed configurable custom OpenID login button diff --git a/askbot/doc/source/contributors.rst b/askbot/doc/source/contributors.rst index 0a20bcae..2ebcaebb 100644 --- a/askbot/doc/source/contributors.rst +++ b/askbot/doc/source/contributors.rst @@ -57,6 +57,7 @@ Programming, bug fixes and documentation * `michas2 <https://github.com/michas2>`_ * `Francis Devereux <https://github.com/frankoid>`_ * `Andrew Chen <https://github.com/yongjhih>`_ +* `Egil Moeller <https://github.com/redhog>`_ Translations ------------ diff --git a/askbot/forms.py b/askbot/forms.py index e218f381..e3c6c253 100644 --- a/askbot/forms.py +++ b/askbot/forms.py @@ -931,16 +931,15 @@ class AskForm(PostAsSomeoneForm, PostPrivatelyForm): self.fields['ask_anonymously'] = forms.BooleanField( label=_('post anonymously'), - required=False, + required=False ) - #hide ask_anonymously field + if user.is_anonymous() or not askbot_settings.ALLOW_ASK_ANONYMOUSLY: + self.hide_field('ask_anonymously') + if getattr(django_settings, 'ASKBOT_MULTILINGUAL', False): self.fields['language'] = LanguageField() - if askbot_settings.ALLOW_ASK_ANONYMOUSLY is False: - self.hide_field('ask_anonymously') - if should_use_recaptcha(user): self.fields['recaptcha'] = AskbotRecaptchaField() @@ -951,7 +950,6 @@ class AskForm(PostAsSomeoneForm, PostPrivatelyForm): self.cleaned_data['ask_anonymously'] = False return self.cleaned_data['ask_anonymously'] - ASK_BY_EMAIL_SUBJECT_HELP = _( 'Subject line is expected in the format: ' '[tag1, tag2, tag3,...] question title' @@ -971,7 +969,7 @@ class AskWidgetForm(forms.Form, FormWithHideableFields): super(AskWidgetForm, self).__init__(*args, **kwargs) self.fields['title'] = TitleField() #hide ask_anonymously field - if not askbot_settings.ALLOW_ASK_ANONYMOUSLY: + if user.is_anonymous() or not askbot_settings.ALLOW_ASK_ANONYMOUSLY: self.hide_field('ask_anonymously') self.fields['text'] = QuestionEditorField(user=user) if not include_text: diff --git a/askbot/models/__init__.py b/askbot/models/__init__.py index b2bebd76..93c8d599 100644 --- a/askbot/models/__init__.py +++ b/askbot/models/__init__.py @@ -543,6 +543,20 @@ def user_get_or_create_fake_user(self, username, email): user.save() return user +def get_or_create_anonymous_user(): + """returns fake anonymous user""" + username = get_name_of_anonymous_user() + try: + user = User.objects.get(username=username) + except User.DoesNotExist: + user = User() + user.username = username + user.email = askbot_settings.ANONYMOUS_USER_EMAIL + user.is_fake = True + user.set_unusable_password() + user.save() + return user + def user_notify_users( self, notification_type=None, recipients=None, content_object=None ): diff --git a/askbot/templates/answer_edit.html b/askbot/templates/answer_edit.html index 5ba0881b..c49f3ccd 100644 --- a/askbot/templates/answer_edit.html +++ b/askbot/templates/answer_edit.html @@ -44,12 +44,11 @@ id="edit_post_form_submit_button" type="submit" value="{% trans %}Save edit{% endtrans %}" - class="submit" /> <input type="button" value="{% trans %}Cancel{% endtrans %}" - class="submit cancel" + class="cancel" onclick="history.back(-1);" /> </div> diff --git a/askbot/templates/widgets/ask_form.html b/askbot/templates/widgets/ask_form.html index 6e165857..dec52d79 100644 --- a/askbot/templates/widgets/ask_form.html +++ b/askbot/templates/widgets/ask_form.html @@ -65,10 +65,10 @@ <div>{{ macros.form_field_with_errors(form.recaptcha) }}</div> <div class="clearfix"></div> {% endif %} - {% if not request.user.is_authenticated() %} - <input type="submit" name="post_anon" value="{% trans %}Login/Signup to Post{% endtrans %}" class="submit" /> + {% if request.user.is_anonymous() and not settings.ALLOW_ASK_UNREGISTERED %} + <input type="submit" name="post_anon" value="{% trans %}Login/Signup to Post{% endtrans %}" /> {% else %} - <input type="submit" name="post" value="{{ settings.WORDS_ASK_YOUR_QUESTION|escape }}" class="submit" /> + <input type="submit" name="post" value="{{ settings.WORDS_ASK_YOUR_QUESTION|escape }}" /> {% endif %} <div class="clean"></div> </form> diff --git a/askbot/templates/widgets/question_edit_tips.html b/askbot/templates/widgets/question_edit_tips.html index 636bd38d..a6ac83b0 100644 --- a/askbot/templates/widgets/question_edit_tips.html +++ b/askbot/templates/widgets/question_edit_tips.html @@ -3,7 +3,7 @@ {{ settings.QUESTION_INSTRUCTIONS|safe }} {% else %} <ul> - {% if not request.user.is_authenticated() %} + {% if request.user.is_anonymous() and not settings.ALLOW_ASK_UNREGISTERED %} <li class="warning">{% trans %}since you are not logged in right now, you will be asked to sign in or register after making your post{% endtrans %}</li> {% else %} {% if settings.EMAIL_VALIDATION %} diff --git a/askbot/views/writers.py b/askbot/views/writers.py index e0d8e1f4..a11fb941 100644 --- a/askbot/views/writers.py +++ b/askbot/views/writers.py @@ -30,6 +30,7 @@ from django.core.urlresolvers import reverse from django.core import exceptions from django.conf import settings from django.views.decorators import csrf +from django.contrib.auth.models import User from askbot import exceptions as askbot_exceptions from askbot import forms @@ -204,7 +205,6 @@ def import_data(request): } return render(request, 'import_data.html', data) -#@login_required #actually you can post anonymously, but then must register @fix_recaptcha_remote_ip @csrf.csrf_protect @decorators.check_authorization_to_post(ugettext_lazy('Please log in to make posts')) @@ -239,12 +239,16 @@ def ask(request):#view used to ask a new question language = form.cleaned_data.get('language', None) if request.user.is_authenticated(): - drafts = models.DraftQuestion.objects.filter( - author=request.user - ) + drafts = models.DraftQuestion.objects.filter(author=request.user) drafts.delete() - user = form.get_post_user(request.user) + elif request.user.is_anonymous() and askbot_settings.ALLOW_ASK_UNREGISTERED: + user = models.get_or_create_anonymous_user() + ask_anonymously = True + else: + user = None + + if user: try: question = user.post_question( title=title, |