]> git.openstreetmap.org Git - osqa.git/commitdiff
Fixing OSQA 244, Cannot answer question if not enough text.
authorhernani <hernani@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Mon, 17 May 2010 16:05:21 +0000 (16:05 +0000)
committerhernani <hernani@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Mon, 17 May 2010 16:05:21 +0000 (16:05 +0000)
git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@293 0cfe37f9-358a-4d5e-be75-b63607b5c754

forum/forms.py
forum/middleware/request_utils.py
forum/skins/default/templates/question.html
forum/views/readers.py
forum/views/writers.py

index 245372a68a84b174470a67bbb94f65a098cd1365..8582f3a4b6a593d6f0acb20c2098fe078839aaef 100644 (file)
@@ -30,18 +30,36 @@ class TitleField(forms.CharField):
 class EditorField(forms.CharField):
     def __init__(self, *args, **kwargs):
         super(EditorField, self).__init__(*args, **kwargs)
-        self.required = True
         self.widget = forms.Textarea(attrs={'id':'editor'})
         self.label  = _('content')
         self.help_text = u''
         self.initial = ''
 
+
+class QuestionEditorField(EditorField):
+    def __init__(self, *args, **kwargs):
+        super(QuestionEditorField, self).__init__(*args, **kwargs)
+        self.required = not bool(settings.FORM_EMPTY_QUESTION_BODY)
+
+
     def clean(self, value):
-        if len(value) < settings.FORM_MIN_QUESTION_BODY and not settings.FORM_EMPTY_QUESTION_BODY:
+        if self.required and (len(value) < settings.FORM_MIN_QUESTION_BODY):
             raise forms.ValidationError(_('question content must be must be at least %s characters' % settings.FORM_MIN_QUESTION_BODY))
 
         return value
 
+class AnswerEditorField(EditorField):
+    def __init__(self, *args, **kwargs):
+        super(AnswerEditorField, self).__init__(*args, **kwargs)
+        self.required = True
+
+    def clean(self, value):
+        if len(value) < settings.FORM_MIN_QUESTION_BODY:
+            raise forms.ValidationError(_('answer content must be must be at least %s characters' % settings.FORM_MIN_QUESTION_BODY))
+
+        return value
+
+
 class TagNamesField(forms.CharField):
     def __init__(self, *args, **kwargs):
         super(TagNamesField, self).__init__(*args, **kwargs)
@@ -66,12 +84,12 @@ class TagNamesField(forms.CharField):
             raise forms.ValidationError(_('please use between %(min)s and %(max)s tags') % { 'min': settings.FORM_MIN_NUMBER_OF_TAGS, 'max': settings.FORM_MAX_NUMBER_OF_TAGS})
 
         list_temp = []
-        tagname_re = re.compile(r'^[\w+\.-]$', re.UNICODE)
+        tagname_re = re.compile(r'^[\w+\.-]+$', re.UNICODE)
         for tag in list:
             if len(tag) > settings.FORM_MAX_LENGTH_OF_TAG or len(tag) < settings.FORM_MIN_LENGTH_OF_TAG:
                 raise forms.ValidationError(_('please use between %(min)s and %(max)s characters in you tags') % { 'min': settings.FORM_MIN_LENGTH_OF_TAG, 'max': settings.FORM_MAX_LENGTH_OF_TAG})
             if not tagname_re.match(tag):
-                raise forms.ValidationError(_('please use following characters in tags: letters , numbers, and the following characters \'.-_#\''))
+                raise forms.ValidationError(_('please use following characters in tags: letters , numbers, and characters \'.-_\''))
             # only keep one same tag
             if tag not in list_temp and len(tag.strip()) > 0:
                 list_temp.append(tag)
@@ -111,13 +129,13 @@ class FeedbackForm(forms.Form):
 
 class AskForm(forms.Form):
     title  = TitleField()
-    text   = EditorField()
+    text   = QuestionEditorField()
     tags   = TagNamesField()
     wiki = WikiField()
 
 
 class AnswerForm(forms.Form):
-    text   = EditorField()
+    text   = AnswerEditorField()
     wiki   = WikiField()
 
     def __init__(self, question, *args, **kwargs):
@@ -154,7 +172,7 @@ class RevisionForm(forms.Form):
 
 class EditQuestionForm(forms.Form):
     title  = TitleField()
-    text   = EditorField()
+    text   = QuestionEditorField()
     tags   = TagNamesField()
     summary = SummaryField()
 
@@ -173,7 +191,7 @@ class EditQuestionForm(forms.Form):
             self.fields['wiki'] = WikiField()
 
 class EditAnswerForm(forms.Form):
-    text = EditorField()
+    text = AnswerEditorField()
     summary = SummaryField()
 
     def __init__(self, answer, revision=None, *args, **kwargs):
index 666956515c48be2618019406e439842fa556c2ae..46d56b73f9add106b03b896ad8d6e75bec51fa27 100644 (file)
@@ -37,6 +37,10 @@ class RequestUtils(object):
                     'app_title': APP_TITLE\r
                 }))\r
 \r
+        if request.session.get('redirect_POST_data', None):\r
+            request.POST = request.session.pop('redirect_POST_data')\r
+            request.META['REQUEST_METHOD'] = "POST"\r
+\r
         self.request = request\r
         request.utils = self\r
         return None
\ No newline at end of file
index bdc2c2206cde356a0eba6e0e677f50462bdf7982..466df6a4907242f0c6ccf04f83bf3b5125794f30 100644 (file)
                         \r
                         </table>  \r
                     </div>\r
-                    <div id="previewer" class="wmd-preview"></div>\r
                     {{ answer.text.errors }}\r
+                    <div id="previewer" class="wmd-preview"></div>                    \r
                 </div>\r
                 <p><span class="form-error"></span></p>\r
                 <input type="submit" \r
index 3efb554544ce8c3bbf2706064931c24017872464..9eea9787191bb24472cd4ef6410f77649b52a6c2 100644 (file)
@@ -234,7 +234,11 @@ def question(request, id, slug):
     if question.deleted and not request.user.can_view_deleted_post(question):
         raise Http404
 
-    answer_form = AnswerForm(question)
+    if request.POST:
+        answer_form = AnswerForm(question, request.POST)
+    else:
+        answer_form = AnswerForm(question)
+
     answers = request.user.get_visible_answers(question)
 
     if answers is not None:
index 3b3e90b5c951792f414a62529d63afee56ceeb6f..cc2c807c0538b3672bc9ba00ba9a77e795bcccd1 100644 (file)
@@ -196,6 +196,9 @@ def answer(request, id):
                 request.session['temp_node_type'] = 'answer'
                 request.session['temp_question_id'] = id
                 return HttpResponseRedirect(reverse('auth_action_signin', kwargs={'action': 'newquestion'}))
+        else:
+            request.session['redirect_POST_data'] = request.POST
+            return HttpResponseRedirect(question.get_absolute_url() + '#fmanswer')
 
     return HttpResponseRedirect(question.get_absolute_url())