|
@@ -9,10 +9,12 @@
|
|
|
:license: BSD, see LICENSE for more details.
|
|
|
"""
|
|
|
from flask.ext.wtf import Form
|
|
|
-from wtforms import TextAreaField, TextField
|
|
|
-from wtforms.validators import Required
|
|
|
+import flask.ext.whooshalchemy
|
|
|
+from wtforms import TextAreaField, TextField, BooleanField, FormField, SelectMultipleField
|
|
|
+from wtforms.validators import Required, Optional, Length
|
|
|
|
|
|
-from flaskbb.forum.models import Topic, Post, Report
|
|
|
+from flaskbb.forum.models import Topic, Post, Report, Forum, Category
|
|
|
+from flaskbb.user.models import User
|
|
|
|
|
|
|
|
|
class QuickreplyForm(Form):
|
|
@@ -54,3 +56,32 @@ class ReportForm(Form):
|
|
|
def save(self, user, post):
|
|
|
report = Report(**self.data)
|
|
|
return report.save(user, post)
|
|
|
+
|
|
|
+
|
|
|
+class SearchForm(Form):
|
|
|
+
|
|
|
+ def __init__(self, search_types=list()):
|
|
|
+ super(SearchForm, self).__init__()
|
|
|
+ self.search_types = search_types
|
|
|
+
|
|
|
+ search_query = TextField("Search", validators=[Optional(), Length(min=3, max=50)])
|
|
|
+
|
|
|
+ def get_types(self):
|
|
|
+ return self.search_types
|
|
|
+
|
|
|
+ def get_results(self):
|
|
|
+ results = {}
|
|
|
+ types = self.get_types()
|
|
|
+ query = self.search_query.data
|
|
|
+ for type in types:
|
|
|
+ if type == 'user':
|
|
|
+ results['user'] = User.query.whoosh_search(query)
|
|
|
+ elif type == 'post':
|
|
|
+ results['post'] = Post.query.whoosh_search(query)
|
|
|
+ elif type == 'topic':
|
|
|
+ results['topic'] = Topic.query.whoosh_search(query)
|
|
|
+ elif type == 'forum':
|
|
|
+ results['forum'] = Forum.query.whoosh_search(query)
|
|
|
+ elif type == 'category':
|
|
|
+ results['category'] = Category.query.whoosh_search(query)
|
|
|
+ return results
|