/[glsr]/trunk/htdocs/search.py
Gentoo

Contents of /trunk/htdocs/search.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 186 - (show annotations) (download) (as text)
Tue Nov 15 06:01:54 2005 UTC (8 years, 9 months ago) by hadfield
File MIME type: text/x-python
File size: 5017 byte(s)
implemented standard search.
1 # Copyright 2005 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 #
4
5 """The script search 'domain'.
6
7 This module implements the front end functionality for all script search
8 related actions.
9 """
10
11 __revision__ = "$Id$"
12 __authors__ = ["Scott Hadfield <hadfield@gentoo.org>",
13 "Ian Leitch <port001@gentoo.org>"]
14 __modulename__ = "search"
15
16 import os
17
18 from framework.utils import exposed, default
19
20 from glsr.setup import config
21 from glsr.site import category, language, script, table_listing, user
22
23 class Search(table_listing.TableListing):
24 """The search domain class."""
25
26 @default
27 @exposed
28 def prompt(self):
29 """Display the script search page."""
30
31 self._do_header()
32 self._set_template(os.path.join(config.template_loc,
33 "search_scripts.tpl"))
34 self._template.param("LANG_LOOP", language.list_all(["language_id",
35 "language_name"]))
36 self._template.param("CAT_LOOP", category.list_all(["category_id",
37 "category_name"]))
38 self._template.param("GLSR_URL", config.url)
39 self._harm.response.append_body(self._template.output())
40 self._do_footer()
41
42 @exposed
43 def search(self):
44 """Search for scripts and display the results."""
45
46 if self._harm.request.queries.has_key("search_type"):
47 search_type = self._harm.request.queries["search_type"]
48 else:
49 search_type = ""
50
51 self._hidden_fields = [{"name": "search_type", "value": search_type}]
52
53 if search_type == "submitter":
54 # Search for scripts based on the submitter id.
55 if self._harm.request.queries.has_key("submitter_id"):
56 submitter_id = self._harm.request.queries["submitter_id"]
57 scripts = script.list_scripts(
58 script_constraints = {'submitter_id': submitter_id})
59 self._hidden_fields.append({"name": "submitter_id",
60 "value": submitter_id})
61
62 elif search_type == "list_all":
63 # Find and list all scripts.
64 scripts = script.list_scripts()
65
66 else:
67 scripts = self._standard()
68
69 self._domain = __modulename__
70 self._page = "search"
71 self._list_title = "Script Listing"
72
73 self._fields = [
74 {"name": "script_name", "title": "Name",
75 "link": ("viewscript.py?script_id=%s", "script_id")},
76 {"name": "script_submitter", "title": "Author",
77 "link": ("profile.py?page=view&uid=%s", "script_submitter_id")},
78 {"name": "script_category", "title": "Category"},
79 {"name": "script_language", "title": "Language"},
80 {"name": "script_rank", "title": "Rank"},
81 {"name": "subscript_version", "title": "Version"},
82 {"name": "subscript_date", "title": "Date Created"},
83 {"name": "subscript_status", "title": "Status"},
84 {"name": "subscript_approvedby", "title": "Approved By"}]
85
86 for record in scripts:
87 user_obj = user.User(record["script_submitter_id"])
88 category_obj = category.Category(record["script_category_id"])
89 language_obj = language.Language(record["script_language_id"])
90
91 record.update({'script_submitter': user_obj.get_alias(),
92 'script_category': category_obj.name(),
93 'script_language': language_obj.name()})
94
95 self._loop_data = scripts
96
97 self._do_header()
98 self._make_table()
99 self._harm.response.append_body(self._template.output())
100 self._do_footer()
101
102 def _standard(self):
103 """Perform a standard search, based on form inputs."""
104
105 terms = {}
106
107 if self._harm.request.forms.has_key("name"):
108 terms['name'] = self._harm.request.forms.getvalue('name')
109
110 if self._harm.request.forms.has_key("descr"):
111 terms['descr'] = self._harm.request.forms.getvalue('descr')
112
113 if self._harm.request.forms.has_key("current"):
114 terms['current'] = self._harm.request.forms.getvalue('current')
115
116 if self._harm.request.forms.has_key("submitter"):
117 submitter = self._harm.request.forms.getvalue('submitter')
118 terms['submitter_id'] = user.get_uid_by_alias(submitter)
119
120 if self._harm.request.forms.has_key("category_id"):
121 terms['category_id'] = (
122 self._harm.request.forms.getvalue('category_id'))
123
124 if self._harm.request.forms.has_key("language_id"):
125 terms['language_id'] = (
126 self._harm.request.forms.getvalue('language_id'))
127
128 return script.search(
129 ["script_submitter_id", "script_category_id", "script_language_id",
130 "script_rank", "script_name", "script_descr"], terms)

Properties

Name Value
svn:keywords Id

  ViewVC Help
Powered by ViewVC 1.1.20