Пример #1
0
def index():
    db = read_config("config.config")
    # Get Bookmarks Toolbar ID
    q = "SELECT id from moz_bookmarks where title == 'Bookmarks Toolbar';"
    master_id = query(q,db,mode="one")[0]
    folders, bookmarks = get_contents(master_id, db)
    return render_template('index.html', bookmarks=bookmarks, folders=folders)
Пример #2
0
 def business(self,
              name=None,
              street_line_1=None,
              street_line_2=None,
              city=None,
              postal_code=None,
              state=None,
              country_code=None):
     return query(
         self,
         BusinessRequest(name, street_line_1, street_line_2, city,
                         postal_code, state, country_code))
Пример #3
0
 def location(self,
              street_line_1=None,
              street_line_2=None,
              city=None,
              postal_code=None,
              state_code=None,
              country_code=None,
              lat=None,
              lon=None,
              radius=None):
     return query(
         self,
         LocationRequest(street_line_1, street_line_2, city, postal_code,
                         state_code, country_code, lat, lon, radius))
Пример #4
0
 def person(self,
            name=None,
            first_name=None,
            middle_name=None,
            last_name=None,
            suffix=None,
            title=None,
            street_line_1=None,
            street_line_2=None,
            city=None,
            postal_code=None,
            state_code=None,
            country_code=None,
            use_historical=None,
            use_metro=None):
     return query(
         self,
         PersonRequest(name, first_name, middle_name, last_name, suffix,
                       title, street_line_1, street_line_2, city,
                       postal_code, state_code, country_code,
                       use_historical, use_metro))
Пример #5
0
 def location(self, street_line_1=None, street_line_2=None, city=None, postal_code=None, state_code=None,
              country_code=None, lat=None, lon=None, radius=None):
     return query(self, LocationRequest(street_line_1, street_line_2, city, postal_code, state_code,
                                        country_code, lat, lon, radius))
Пример #6
0
 def business(self, name=None, street_line_1=None, street_line_2=None, city=None, postal_code=None,
              state=None, country_code=None):
     return query(self, BusinessRequest(name, street_line_1, street_line_2, city, postal_code, state, country_code))
Пример #7
0
 def phone(self, phone_number=None, response_type=None):
     return query(self, PhoneRequest(phone_number, response_type))
Пример #8
0
 def person(self, name=None, first_name=None, middle_name=None, last_name=None, suffix=None, title=None,
            street_line_1=None, street_line_2=None, city=None, postal_code=None, state_code=None,
            country_code=None, use_historical=None, use_metro=None):
     return query(self, PersonRequest(name, first_name, middle_name, last_name, suffix, title, street_line_1,
                                      street_line_2, city, postal_code, state_code, country_code, use_historical,
                                      use_metro))
Пример #9
0
 def phone(self, phone_number=None, response_type=None):
     return query(self, PhoneRequest(phone_number, response_type))
Пример #10
0
def searchHandler():
    """
    Handles all search requests.  If it is directed at the popup archive
    then redirects the request to audioSearchHandler. Otherwise it handles
    the FSM archive setup.
    """
    q = request.query.search
    typeOfResource = request.query.type
    if typeOfResource == "audio":
        # if audio let the audioSearchHandler get this with a redirect
        temp = ''
        if 'collectionFilter' in request.query:
            temp += '&collection=' + request.query.collectionFilter
        if 'start' in request.query:
            temp += '&start=' + request.query.start
        return redirect("/audioSearch?type=audio&search=" + q + temp)
    elif typeOfResource == "image":
        q = appendToQuery(q, '-fsmTeiUrl:[* TO *]') # don't show written text
    else:
        q = appendToQuery(q, '-fsmImageUrl:[* TO *]') # don't show images

    typesOfResourcesList = queryPluck(q)['facet_counts']['facet_fields']['fsmTypeOfResource']
    typesOfResourcesDict = {'other':0}
    # generate a dictionary of the top 5 and collect everything else to other
    for i in xrange(0, len(typesOfResourcesList), 2):
        if i >= 10:
            typesOfResourcesDict['other'] += typesOfResourcesList[i+1]
        else:
            typesOfResourcesDict[typesOfResourcesList[i]] = typesOfResourcesList[i+1]

    filterType = request.query.getall('filterType')
    if 'other' in filterType: 
        # exclude what is not in the filterType
        exclusion = set(typesOfResourcesDict.keys()) - set(filterType) - set('other')
        if len(exclusion) != 0:
            q = appendToQuery(q, '-fsmTypeOfResource:' + " OR -fsmTypeOfResource:".join(exclusion))
    else: 
        # only collect what is checked
        if len(filterType) != 0:
            q = appendToQuery(q, 'fsmTypeOfResource:' + " OR fsmTypeOfResource:".join(filterType))
        else:
            # nothing checked, check all
            filterType = typesOfResourcesDict.keys()

    template_values = {}
    start = request.query.start
    if not start:
        # no start parameter
        # we need query parameters so that the page links at the bottom of search will look right
        template_values["queryParameters"] = request.query_string
        start = 1
    else:
        # using a start page parameter.  Parse it off so we can reconstruct paging links properly
        template_values["queryParameters"] = "&".join(request.query_string.split('&')[:-1])

    rowsPerPage = 15
    startRow = (int(start) - 1)*rowsPerPage
    results = query(q, startRow, rowsPerPage)

    template_values["typeOfResource"] = typeOfResource
    template_values['types'] = typesOfResourcesDict
    template_values['filterType'] = filterType
    template_values["query"] = cgi.escape(request.query.search) # block XSS with cgi escape
    template_values["numPages"] = (results["response"]["numFound"] // rowsPerPage) + 1
    template_values["response"] = results["response"]["docs"]
    return template("search.html", template_values)