diff options
-rw-r--r-- | askbot/forms.py | 26 | ||||
-rw-r--r-- | askbot/skins/common/templates/widgets/edit_post.html | 25 | ||||
-rw-r--r-- | askbot/skins/default/media/style/style.css | 4 | ||||
-rw-r--r-- | askbot/skins/default/media/style/style.less | 9 | ||||
-rw-r--r-- | askbot/skins/default/templates/answer_edit.html | 2 | ||||
-rw-r--r-- | askbot/skins/default/templates/macros.html | 3 | ||||
-rw-r--r-- | askbot/skins/default/templates/question/new_answer_form.html | 2 | ||||
-rw-r--r-- | askbot/skins/default/templates/question_edit.html | 3 | ||||
-rw-r--r-- | askbot/skins/default/templates/widgets/ask_form.html | 3 | ||||
-rw-r--r-- | askbot/utils/forms.py | 22 | ||||
-rw-r--r-- | askbot/views/writers.py | 18 |
11 files changed, 105 insertions, 12 deletions
diff --git a/askbot/forms.py b/askbot/forms.py index 81382a2c..18fe7537 100644 --- a/askbot/forms.py +++ b/askbot/forms.py @@ -667,7 +667,12 @@ class AskForm(forms.Form, FormWithHideableFields): required = False, ) openid = forms.CharField(required=False, max_length=255, widget=forms.TextInput(attrs={'size' : 40, 'class':'openid-input'})) - user = forms.CharField(required=False, max_length=255, widget=forms.TextInput(attrs={'size' : 35})) + user = forms.CharField( + required=False, + max_length=255, + label="User", + help_text=_("Enter the username to post this as. New users are automatically created."), + widget=forms.TextInput(attrs={'size' : 35})) email = forms.CharField(required=False, max_length=255, widget=forms.TextInput(attrs={'size' : 35})) def __init__(self, *args, **kwargs): @@ -769,7 +774,12 @@ class AnswerForm(forms.Form): text = AnswerEditorField() wiki = WikiField() openid = forms.CharField(required=False, max_length=255, widget=forms.TextInput(attrs={'size' : 40, 'class':'openid-input'})) - user = forms.CharField(required=False, max_length=255, widget=forms.TextInput(attrs={'size' : 35})) + user = forms.CharField( + required=False, + max_length=255, + label="User", + help_text=_("Enter the username to post this as. New users are automatically created."), + widget=forms.TextInput(attrs={'size' : 35})) email = forms.CharField(required=False, max_length=255, widget=forms.TextInput(attrs={'size' : 35})) email_notify = EmailNotifyField(initial = False) def __init__(self, *args, **kwargs): @@ -836,6 +846,12 @@ class EditQuestionForm(forms.Form, FormWithHideableFields): label = _('reveal identity'), required = False, ) + user_author = forms.CharField( + required=False, + max_length=255, + label="User", + help_text=_("Enter the username to post this as. New users are automatically created."), + widget=forms.TextInput(attrs={'size' : 35})) #todo: this is odd that this form takes question as an argument def __init__(self, *args, **kwargs): @@ -933,6 +949,12 @@ class EditAnswerForm(forms.Form): text = AnswerEditorField() summary = SummaryField() wiki = WikiField() + user = forms.CharField( + required=False, + max_length=255, + label="User", + help_text=_("Enter the username to post this as. New users are automatically created."), + widget=forms.TextInput(attrs={'size' : 35})) def __init__(self, answer, revision, *args, **kwargs): super(EditAnswerForm, self).__init__(*args, **kwargs) diff --git a/askbot/skins/common/templates/widgets/edit_post.html b/askbot/skins/common/templates/widgets/edit_post.html index b083c009..4e695012 100644 --- a/askbot/skins/common/templates/widgets/edit_post.html +++ b/askbot/skins/common/templates/widgets/edit_post.html @@ -54,6 +54,31 @@ <div class="form-error" >{{ post_form.summary.errors }}</div> </div> {% endif %} + +{% if user and user.is_staff and user.is_active %} + {# admin can post answers or questions on behalf of anyone. #} + {% if post_type == 'question' and edit_title %} + {# edit question already has 'user' field set #} + <div class="form-item"> + <strong>{{ post_form.user_author.label_tag() }}</strong> <br /> + {{ post_form.user_author }} + <div class="title-desc"> + {{ post_form.user_author.help_text }} + </div> + <div class="form-error">{{ post_form.user_author.errors }}</div> + </div> + {% else %} + <div class="form-item"> + <strong>{{ post_form.user.label_tag() }}</strong> <br /> + {{ post_form.user }} + <div class="title-desc"> + {{ post_form.user.help_text }} + </div> + <div class="form-error">{{ post_form.user.errors }}</div> + </div> + {% endif %} +{% endif %} + <div class="preview-toggle"> <span id="pre-collapse" diff --git a/askbot/skins/default/media/style/style.css b/askbot/skins/default/media/style/style.css index 348eb6b2..c9de849a 100644 --- a/askbot/skins/default/media/style/style.css +++ b/askbot/skins/default/media/style/style.css @@ -1355,7 +1355,9 @@ ul#related-tags li { font-size: 13px; } .ask-page #id_tags, -.edit-question-page #id_tags { +.edit-question-page #id_tags, +#id_user, +#id_user_author { border: #cce6ec 3px solid; height: 25px; padding-left: 5px; diff --git a/askbot/skins/default/media/style/style.less b/askbot/skins/default/media/style/style.less index ea404391..98914a28 100644 --- a/askbot/skins/default/media/style/style.less +++ b/askbot/skins/default/media/style/style.less @@ -1349,6 +1349,15 @@ ul#related-tags li { } } +#id_user, +#id_user_author { + border:#cce6ec 3px solid; + height:25px; + padding-left:5px; + width:395px; + font-size:14px; +} + .title-desc { color: @info-text; font-size: 13px; diff --git a/askbot/skins/default/templates/answer_edit.html b/askbot/skins/default/templates/answer_edit.html index bbc00420..a1dbb4f9 100644 --- a/askbot/skins/default/templates/answer_edit.html +++ b/askbot/skins/default/templates/answer_edit.html @@ -16,7 +16,7 @@ <div style="vertical-align:middle"> {{ revision_form.revision }} <input type="submit" style="display:none" id="select_revision" name="select_revision" value="{% trans %}select revision{% endtrans %}"> </div> - {{ macros.edit_post(form) }} + {{ macros.edit_post(form, user = request.user) }} {% if settings.WIKI_ON and answer.wiki == False %} {{ macros.checkbox_in_div(form.wiki) }} {% endif %} diff --git a/askbot/skins/default/templates/macros.html b/askbot/skins/default/templates/macros.html index 3e463c1c..3b9e5377 100644 --- a/askbot/skins/default/templates/macros.html +++ b/askbot/skins/default/templates/macros.html @@ -496,7 +496,8 @@ for the purposes of the AJAX comment editor #} post_form, post_type = None, mandatory_tags = None, - edit_title = False + edit_title = False, + user = None ) -%} {%include "widgets/edit_post.html" %} diff --git a/askbot/skins/default/templates/question/new_answer_form.html b/askbot/skins/default/templates/question/new_answer_form.html index 68af8afb..9868d3ba 100644 --- a/askbot/skins/default/templates/question/new_answer_form.html +++ b/askbot/skins/default/templates/question/new_answer_form.html @@ -39,7 +39,7 @@ {% endif %} </p> {% endif %} - {{ macros.edit_post(answer) }} + {{ macros.edit_post(answer, user = request.user) }} <input id="add-answer-btn" type="submit" class="submit after-editor" style="float:left"/> <script type="text/javascript"> askbot['functions']['renderAddAnswerButton'](); diff --git a/askbot/skins/default/templates/question_edit.html b/askbot/skins/default/templates/question_edit.html index 47873e0e..adf2f35b 100644 --- a/askbot/skins/default/templates/question_edit.html +++ b/askbot/skins/default/templates/question_edit.html @@ -20,7 +20,8 @@ form, post_type='question', edit_title=True, - mandatory_tags = mandatory_tags + mandatory_tags = mandatory_tags, + user = request.user ) }} <div class="after-editor"> diff --git a/askbot/skins/default/templates/widgets/ask_form.html b/askbot/skins/default/templates/widgets/ask_form.html index b8a5ce2c..2ece84d5 100644 --- a/askbot/skins/default/templates/widgets/ask_form.html +++ b/askbot/skins/default/templates/widgets/ask_form.html @@ -26,7 +26,8 @@ form, post_type = 'question', edit_title = False, - mandatory_tags = mandatory_tags + mandatory_tags = mandatory_tags, + user = request.user ) }} <div class="question-options"> diff --git a/askbot/utils/forms.py b/askbot/utils/forms.py index b8ed253b..1420b58a 100644 --- a/askbot/utils/forms.py +++ b/askbot/utils/forms.py @@ -26,6 +26,28 @@ def clean_next(next, default = None): def get_next_url(request, default = None): return clean_next(request.REQUEST.get('next'), default) +def post_as_user(user, form, userfield='user'): + """ + Allows admin staff to post as any user. + + If the `user` object is_staff and is_active: + + Gets or creates a new user with the username provided in the 'user' + field on the form. + + otherwise returns the `user` object. + """ + + if user.is_staff and user.is_active: + # allow admin user to post as anyone. + username = form.cleaned_data[userfield] + try: + user = User.objects.get(username=username) + except User.DoesNotExist: + user = User.objects.create_user(username=username, email='') + + return user + class StrippedNonEmptyCharField(forms.CharField): def clean(self, value): value = value.strip() diff --git a/askbot/views/writers.py b/askbot/views/writers.py index 232dbaea..6ac54991 100644 --- a/askbot/views/writers.py +++ b/askbot/views/writers.py @@ -15,6 +15,7 @@ import time import urlparse from django.shortcuts import get_object_or_404 from django.contrib.auth.decorators import login_required +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 @@ -31,6 +32,7 @@ from askbot.utils import decorators from askbot.utils.functions import diff_date from askbot.utils import url_utils from askbot.utils.file_utils import store_file +from askbot.utils.forms import post_as_user from askbot.templatetags import extra_filters_jinja as template_filters from askbot.importers.stackexchange import management as stackexchange#todo: may change @@ -217,8 +219,11 @@ def ask(request):#view used to ask a new question ask_anonymously = form.cleaned_data['ask_anonymously'] if request.user.is_authenticated(): + + user = post_as_user(request.user, form) + try: - question = request.user.post_question( + question = user.post_question( title = title, body_text = text, tags = tagnames, @@ -375,7 +380,8 @@ def edit_question(request, id): is_anon_edit = form.cleaned_data['stay_anonymous'] is_wiki = form.cleaned_data.get('wiki', question.wiki) - request.user.edit_question( + user = post_as_user(request.user, form, userfield='user_author') + user.edit_question( question = question, title = form.cleaned_data['title'], body_text = form.cleaned_data['text'], @@ -445,7 +451,8 @@ def edit_answer(request, id): if form.is_valid(): if form.has_changed(): - request.user.edit_answer( + user = post_as_user(request.user, form) + user.edit_answer( answer = answer, body_text = form.cleaned_data['text'], revision_comment = form.cleaned_data['summary'], @@ -491,7 +498,10 @@ def answer(request, id):#process a new answer if request.user.is_authenticated(): try: follow = form.cleaned_data['email_notify'] - answer = request.user.post_answer( + + user = post_as_user(request.user, form) + + answer = user.post_answer( question = question, body_text = text, follow = follow, |