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

Contents of /trunk/htdocs/search.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 134 - (show annotations) (download) (as text)
Mon Sep 19 00:29:32 2005 UTC (9 years, 1 month ago) by hadfield
File MIME type: text/x-python
File size: 4324 byte(s)
improved the table_listing code. made search domain inherit from TableListing.
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 harmonious.utils import exposed, default
19
20 from glsr.setup import config
21
22 from glsr.site import script
23 from glsr.site.category import Category
24 from glsr.site.language import Language
25 from glsr.site import table_listing, user
26
27 class Search(table_listing.TableListing):
28 """The search domain class."""
29
30 @default
31 @exposed
32 def prompt(self):
33 """Display the script search page."""
34
35 self._do_header()
36 self._set_template(os.path.join(config.template_loc,
37 'search_scripts.tpl'))
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_submitter", "title": "Author",
75 "link": ("index.py?page=profile&mode=viewprofile&uid=%s",
76 "script_submitter_id")},
77 {"name": "script_name", "title": "Name",
78 "link": ("viewscript.py?script_id=%s", "script_id")},
79 {"name": "script_category", "title": "Category"},
80 {"name": "script_language", "title": "Language"},
81 {"name": "script_rank", "title": "Rank"},
82 {"name": "subscript_version", "title": "Version"},
83 {"name": "subscript_date", "title": "Date Created"},
84 {"name": "subscript_status", "title": "Status"},
85 {"name": "subscript_approvedby",
86 "title": "Approved By"}]
87
88 for record in scripts:
89 user_obj = user.User(record["script_submitter_id"])
90 category_obj = Category(record["script_category_id"])
91 language_obj = Language(record["script_language_id"])
92
93 record.update({'script_submitter': user_obj.get_alias(),
94 'script_category': category_obj.name(),
95 'script_language': language_obj.name()})
96
97 self._loop_data = scripts
98
99 self._do_header()
100 self._make_table()
101 self._harm.response.append_body(self._template.output())
102 self._do_footer()
103
104 def _standard(self):
105 """Perform a standard search, based on form inputs."""
106
107 terms = {}
108
109 if self._harm.request.forms.has_key("name"):
110 terms['name'] = self._harm.request.forms.getvalue('name')
111
112 if self._harm.request.forms.has_key("descr"):
113 terms['descr'] = self._harm.request.forms.getvalue('descr')
114
115 if self._harm.request.forms.has_key("submitter_id"):
116 terms['submitter_id'] = (
117 self._harm.request.forms.getvalue('submitter_id'))
118
119 if self._harm.request.forms.has_key("current"):
120 terms['current'] = self._harm.request.forms.getvalue('current')
121
122 return script.search(terms)

Properties

Name Value
svn:keywords Id

  ViewVC Help
Powered by ViewVC 1.1.20