/
search.py
59 lines (49 loc) · 2.19 KB
/
search.py
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#! /usr/bin/env python
# -*- coding: utf-8 -*-
"""
Filename: search.py
Authors: Han Lin Yap and Alexander Östman
Course: TDP003 - Projekt: Egna datormiljön
Date: HT09 - 2009-10-07
Program: LiU/IP1
Desciption: This is the search page handler.
"""
import kid
import os
import data
from config import *
kid.enable_import(path=os.path.dirname(__file__) + "/" + "templates")
def index(sort_by='start_date', sort_order='asc', techniques=None, search=None, search_fields=None):
#default template
template = kid.Template(name=os.path.basename(__file__)[:-3],
title=get_text('sitename') + '-' + get_text(os.path.basename(__file__)[:-3]),
results=[],
techs=[],
search_fields=[],
translate_field=[],
headline=get_text(os.path.basename(__file__)[:-3]),
project_not_found=get_text('database_not_available'),
**common_language[DEFAULT_LANGUAGE])
if techniques == '':
techniques = None
if search_fields == '':
search_fields = None
if type(search_fields) != type([]) and search_fields != None:
search_fields = [search_fields]
data.init()
# search projects
results = data.retrieve_projects(sort_by, sort_order, techniques, search, search_fields)
# Projects found
if results[0] == 0:
techniques = data.retrieve_techniques()
template = kid.Template(name=os.path.basename(__file__)[:-3],
title=get_text('sitename') + ' - ' + get_text('search'),
headline=get_text(os.path.basename(__file__)[:-3]),
results=results[1],
techs=techniques[1],
search_fields=data.data[0].keys(),
translate_field=field_language[DEFAULT_LANGUAGE],
project_not_found='',
**common_language[DEFAULT_LANGUAGE])
template.cache = False
return template.serialize(output='xhtml-strict')