/[glsr]/trunk/htdocs/registered/create.py
Gentoo

Contents of /trunk/htdocs/registered/create.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 119 - (show annotations) (download) (as text)
Sat Aug 6 07:30:47 2005 UTC (9 years, 8 months ago) by hadfield
File MIME type: text/x-python
File size: 5010 byte(s)
enabled field type checking. renamed filter -> ffilter, type -> ftype. updated create to use ffilter.
1 # Copyright 2005 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 #
4
5 """Displays the memberlist page."""
6
7 __revision__ = '$Id$'
8 __authors__ = ['Scott Hadfield <hadfield@gentoo.org>']
9 __modulename__ = 'create_script'
10
11 import os
12
13 from harmonious.utils import exposed, default, html_escape
14
15 from glsr.site import auth
16 from glsr.setup import config
17 from glsr.core import fieldparse
18 from glsr.site.basedomain import BaseDomain
19 from glsr.site import category, language, script
20
21 class Create(BaseDomain):
22 """Displays and controls the script creation interface."""
23
24 @default
25 @exposed
26 #@auth.restricted((auth.USER, auth.DEVELOPER, auth.ADMIN))
27 @auth.registered
28 def show(self):
29 """The default action. Displays the create script form."""
30 self._do_header()
31
32 self._template.param('SCRIPT_ID', '0')
33 self._template.param('PARENT_SCRIPT_ID', '0')
34
35 self._template.param('NAME', '')
36 self._template.param('DESCR', '')
37 self._template.param('VERSION', '1.0')
38
39 self._template.param(
40 'CATEGORY_LOOP',
41 category.list_all(["category_id", "category_name"]), 'loop')
42 self._template.param(
43 'LANGUAGE_LOOP',
44 language.list_all(["language_id", "language_name"]), 'loop')
45
46 self._template.param('BODY', '')
47 self._template.param('CHANGELOG', '')
48 self._display("create_script.tpl")
49
50 @exposed
51 #@auth.restricted((auth.USER, auth.DEVELOPER, auth.ADMIN))
52 @auth.registered
53 def save(self):
54 """Save the script to the database."""
55
56 parser = fieldparse.FieldParser(request = self._harm.request.forms,
57 error_method = self.__failed_create)
58 parser.add_field("parent_script_id", required = True, regex = r'^\d+$')
59 parser.add_field("name", required = True, ffilter = html_escape,
60 min_size = 2, max_size = 30)
61 parser.add_field("descr", default = "", max_size = 100)
62 parser.add_field("version", required = True, regex = r'^[\d\.]+$',
63 min_size = 1, max_size = 10)
64 parser.add_field("category_id", regex = r'^\d+$', default = 0)
65 parser.add_field("language_id", regex = r'^\d+$', default = 0)
66 parser.add_field("body", required = True, max_size = 64000)
67 parser.add_field("changelog", default = "", max_size = 64000)
68
69 fields = parser.parse_form()
70 if not fields:
71 return
72
73 if fields["parent_script_id"] == "0":
74 script.create_script(
75 self._get_user()[0], fields["name"], fields["descr"],
76 fields["version"], fields["language_id"],
77 fields["category_id"], fields["body"], fields["changelog"])
78
79
80 self._do_header()
81
82 self._template.param('SCRIPT_ID', '0')
83 self._template.param('PARENT_SCRIPT_ID', '0')
84
85 self._template.param('NAME', '')
86 self._template.param('DESCR', '')
87 self._template.param('VERSION', '1.0')
88
89 self._template.param(
90 'CATEGORY_LOOP',
91 category.list_all(["category_id", "category_name"]), 'loop')
92 self._template.param(
93 'LANGUAGE_LOOP',
94 language.list_all(["language_id", "language_name"]), 'loop')
95
96 self._template.param('BODY', '')
97 self._template.param('CHANGELOG', '')
98 self._display("create_script.tpl")
99
100 def _display(self, tmpl):
101 """Used by all exposed functions to display the page and footer."""
102
103 self._template.param('GLSR_URL', config.url)
104 self._template.param('GLSR_REPORT', '')
105
106 self._template.compile(
107 os.path.join(config.template_loc, tmpl))
108 self._harm.response.append_body(self._template.output())
109 self._do_footer()
110
111 def __failed_create(self, msg, fields):
112 """Called when a test failed in do_register"""
113
114 self._do_header()
115 self._template.param('GLSR_URL', config.url)
116 self._template.param('GLSR_REPORT', msg)
117 self._template.param('GLSR_REPORT_TYPE', 'fatal')
118
119 #self._template.param('SCRIPT_ID', '0')
120 self._template.param('PARENT_SCRIPT_ID', fields['parent_script_id'])
121 self._template.param('NAME', fields['name'])
122 self._template.param('DESCR', fields['descr'])
123 self._template.param('VERSION', fields['version'])
124
125 self._template.param(
126 'CATEGORY_LOOP',
127 category.list_all(["category_id", "category_name"]), 'loop')
128 self._template.param(
129 'LANGUAGE_LOOP',
130 language.list_all(["language_id", "language_name"]), 'loop')
131
132 self._template.param('BODY', fields['body'])
133 self._template.param('CHANGELOG', fields['changelog'])
134 self._template.compile(
135 os.path.join(config.template_loc, "create_script.tpl"))
136 self._harm.response.append_body(self._template.output())
137 self._do_footer()

  ViewVC Help
Powered by ViewVC 1.1.20