aboutsummaryrefslogtreecommitdiffstats
path: root/97suifangqa/apps/sciblog/forms.py
blob: 88a465998cd7e2351332e015e0b4beac641809e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# -*- coding: utf-8 -*-
from haystack.forms import SearchForm

from .models import SciBlog, BlogAnnotation

class SciBlogSearchForm(SearchForm):
    u'''
    问题查询表单,主要完成两个工作:
        1. 指定查询的model为Query
        2. 重载clean_q,对查询语句进行分词
    >>> from sciblog.forms import SciBlogSearchForm
    >>> form = SciBlogSearchForm({'q':u'干扰素'})
    >>> form.search()
        [<SearchResult: sciblog.sciblog (pk=u'1')>, <SearchResult: sciblog.sciblog (pk=u'3')>, <SearchResult: sciblog.sciblog (pk=u'2')>]
    '''

    def __init__(self,*args, **kwargs):
        u'''
        在__init__中指定查询的model为SciBlog
        '''
        super(SciBlogSearchForm, self).__init__(*args, **kwargs)
        self.searchqueryset = self.searchqueryset.models(SciBlog)


class ProperNounSearchForm(SearchForm):
    u'''
    专业名词搜索表单
    >>> from sciblog.forms import ProperNounSearchForm
    >>> form = ProperNounSearchForm({'q':u'乙肝'})
    >>> form.search()
        [<SearchResult: sciblog.blogannotation (pk=u'1')>]
    '''
    def __init__(self,*args, **kwargs):
        u'''
        在__init__中指定查询的model为BlogAnnotation
        '''
        super(ProperNounSearchForm, self).__init__(*args, **kwargs)
        self.searchqueryset = self.searchqueryset.models(BlogAnnotation)