/[glsr]/trunk/htdocs/admin/panel.py
Gentoo

Contents of /trunk/htdocs/admin/panel.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 178 - (show annotations) (download) (as text)
Sat Nov 5 23:55:24 2005 UTC (9 years, 1 month ago) by hadfield
File MIME type: text/x-python
File size: 13159 byte(s)
fixed the category and languages display in admin console
1 # Copyright 2005 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 #
4
5 """The administration panel."""
6
7 __revision__ = "$Id$"
8 __author__ = "Scott Hadfield <hadfield@gentoo.org>"
9 __modulename__ = "adminpanel"
10
11 import os
12
13 from framework.utils import exposed, default
14
15 from glsr.setup import config
16 from glsr.site import auth, basedomain, script, stat, user
17
18 class Panel(basedomain.BaseDomain):
19
20 @default
21 @exposed
22 @auth.restricted((user.ADMIN,))
23 def stats(self):
24
25 self._do_header("Administration Console")
26 self._set_template(os.path.join(config.template_loc,
27 'admin/index.tpl'))
28 self._template.param("SCRIPT_COUNT", stat.count("script"))
29 self._template.param("USER_COUNT", stat.count("user"))
30 self._template.param("DBSIZE", stat.dbsize())
31 self._template.param("ONLINE_LOOP", [])
32 self._harm.response.append_body(self._template.output())
33 self._do_footer()
34
35 @exposed
36 @auth.restricted((user.ADMIN,))
37 def config(self):
38
39 self._do_header("Administration Console")
40 self._set_template(os.path.join(config.template_loc,
41 'admin/config.tpl'))
42 self._harm.response.append_body(self._template.output())
43 self._do_footer()
44
45 @exposed
46 @auth.restricted((user.ADMIN,))
47 def news(self):
48
49 from glsr.site import news
50 import time
51
52 show_news = 1
53 modify = 0
54 news_id = "0"
55 date = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
56 subject = ""
57 body = ""
58
59 # Check if any news control buttons were pressed.
60 if self._harm.request.forms.has_key("show_news"):
61 show_news = 1
62
63 elif self._harm.request.forms.has_key("hide_news"):
64 show_news = 0
65
66 elif self._harm.request.forms.has_key("show_add"):
67 modify = 1
68 show_news = 0
69
70 elif self._harm.request.forms.has_key("save"):
71 modify = 1
72 show_news = 0
73 news_id = self._harm.request.forms.getvalue("news_id", "0")
74 uid = self._get_user()[0]
75 subject = self._harm.request.forms.getvalue("subject", "")
76 date = self._harm.request.forms.getvalue("date", "")
77 body = self._harm.request.forms.getvalue("body", "")
78 if news_id != "0" and news.exists(news_id):
79 # Modifying a news article
80 news_obj = news.News(news_id)
81 news_obj.update(uid, subject, date, body)
82 elif news_id != "0" and not news.exists(news_id):
83 # TODO: Need an error message here.
84 # Could not find specified news article.
85 pass
86 else:
87 # Creating a new article
88 news_id = news.create(uid, subject, date, body)
89
90 elif self._harm.request.queries.has_key("modify"):
91 modify = 1
92 show_news = 0
93 news_id = self._harm.request.queries.get("news_id")
94 news_obj = news.News(news_id)
95 subject = news_obj.get_subject()
96 date = news_obj.get_date()
97 body = news_obj.get_body()
98
99 elif self._harm.request.forms.has_key("delete"):
100 news_ids = self._harm.request.forms.getlist("delete_btn")
101
102 for cur_news_id in news_ids:
103 if cur_news_id != "0" and news.exists(cur_news_id):
104 news_obj = news.News(cur_news_id)
105 news_obj.delete()
106 else:
107 # TODO: Need an error message here.
108 # Could not find specified news article.
109 pass
110 show_news = 1
111
112 news_loop = news.list_all(
113 columns = ["news_id", "news_author_id", "news_author",
114 "news_date", "news_subject"])
115
116 self._do_header("Administration Console")
117 self._set_template(os.path.join(config.template_loc,
118 'admin/news.tpl'))
119
120 self._template.param("SHOW_NEWS", show_news)
121 self._template.param("NEWS_LOOP", news_loop)
122 self._template.param("MODIFY_NEWS", modify)
123 self._template.param("NEWS_ID", news_id)
124 self._template.param("SUBJECT", subject)
125 self._template.param("DATE", date)
126 self._template.param("BODY", body)
127
128 self._harm.response.append_body(self._template.output())
129 self._do_footer()
130
131 @exposed
132 @auth.restricted((user.ADMIN,))
133 def languages(self):
134
135 from glsr.site import language
136
137 edit_language = 0
138 add_language = 0
139
140 for key in self._harm.request.forms.keys():
141 if key.startswith("edit_"):
142 edit_language = key[5:]
143
144 if edit_language == 0 and self._harm.request.forms.has_key("save"):
145 language_id = self._harm.request.forms.getvalue("language_id")
146 name = self._harm.request.forms.getvalue("name")
147 descr = self._harm.request.forms.getvalue("descr")
148
149 if language_id == "0":
150 language.create(name, descr)
151 else:
152 lang_obj = language.Language(language_id)
153 lang_obj.update(name, descr)
154
155 if edit_language == 0 and self._harm.request.forms.has_key("add"):
156 add_language = 1
157
158 if edit_language == 0 and self._harm.request.forms.has_key("delete"):
159 lang_ids = self._harm.request.forms.getlist("delete_btn")
160
161 for cur_lang_id in lang_ids:
162 if cur_lang_id != "0" and language.exists(cur_lang_id):
163 lang_obj = language.Language(cur_lang_id)
164 lang_obj.delete()
165 else:
166 # TODO: Need an error message here.
167 # Could not find specified language.
168 pass
169 show_news = 1
170
171 language_loop = language.list_all(["language_id", "language_name",
172 "language_descr"])
173
174 self._do_header("Administration Console")
175 self._set_template(os.path.join(config.template_loc,
176 'admin/languages.tpl'))
177 self._template.param("LANGUAGE_LOOP", language_loop)
178 self._template.param("EDIT_LANGUAGE", edit_language)
179 self._template.param("ADD_LANGUAGE", add_language)
180 self._harm.response.append_body(self._template.output())
181 self._do_footer()
182
183 @exposed
184 @auth.restricted((user.ADMIN,))
185 def category(self):
186 # TODO: This is basically identical to languages. Refactor it, bitch.
187
188 from glsr.site import category
189
190 edit_category = 0
191 add_category = 0
192
193 for key in self._harm.request.forms.keys():
194 if key.startswith("edit_"):
195 edit_category = key[5:]
196
197 if edit_category == 0 and self._harm.request.forms.has_key("save"):
198 category_id = self._harm.request.forms.getvalue("category_id")
199 name = self._harm.request.forms.getvalue("name")
200 descr = self._harm.request.forms.getvalue("descr", "")
201
202 if category_id == "0":
203 category.create(name, descr)
204 else:
205 cat_obj = category.Category(category_id)
206 cat_obj.update(name, descr)
207
208 if edit_category == 0 and self._harm.request.forms.has_key("add"):
209 add_category = 1
210
211 if edit_category == 0 and self._harm.request.forms.has_key("delete"):
212 cat_ids = self._harm.request.forms.getlist("delete_btn")
213
214 for cur_cat_id in cat_ids:
215 if cur_cat_id != "0" and category.exists(cur_cat_id):
216 cat_obj = category.Category(cur_cat_id)
217 cat_obj.delete()
218 else:
219 # TODO: Need an error message here.
220 # Could not find specified category.
221 pass
222 show_news = 1
223
224 category_loop = category.list_all(["category_id", "category_name",
225 "category_descr"])
226
227 self._do_header("Administration Console")
228 self._set_template(os.path.join(config.template_loc,
229 'admin/categories.tpl'))
230 self._template.param("CATEGORY_LOOP", category_loop)
231 self._template.param("EDIT_CATEGORY", edit_category)
232 self._template.param("ADD_CATEGORY", add_category)
233 self._harm.response.append_body(self._template.output())
234 self._do_footer()
235
236 @exposed
237 @auth.restricted((user.ADMIN,))
238 def users(self):
239 # FIXME: User management is a complete fucking mess.
240
241 show_search = 1
242 message = ""
243 uid = 0
244
245 if self._harm.request.forms.has_key("search"):
246
247 username = self._harm.request.forms.getvalue("search_str")
248 uid = user.get_uid_by_alias(username)
249 if uid is None:
250 show_search = 1
251 message = "Could not find any matching users"
252 else:
253 show_search = 0
254
255 elif self._harm.request.forms.has_key("save"):
256
257 show_search = 0
258
259 fields = user.profile_fieldparser(
260 request = self._harm.request.forms,
261 error_method = self.__failed_save)
262
263 if not fields:
264 # An error in the form entry, __failed_save was called.
265 return
266
267 uid = fields["user_id"]
268 profile_user = user.User(uid)
269
270 if self._harm.request.forms.getvalue("delete"):
271 self._delete_user(fields["user_id"])
272 return
273
274 # If user chose to change their password verify they match.
275 if (fields["password"] is not None
276 and fields["password"] != fields["password_confirm"]):
277 self._template.param("GLSR_REPORT", "Passwords don't match.")
278 self._template.param("GLSR_REPORT_TYPE", "warn")
279 else:
280 profile_user.update(email = fields["email"],
281 passwd = fields["password"],
282 fullname = fields["fullname"],
283 location = fields["location"],
284 language = fields["language"],
285 website = fields["website"],
286 user_type = fields["user_type"])
287
288 self._do_header("Administration Console")
289 self._set_template(os.path.join(config.template_loc,
290 'admin/user.tpl'))
291 self._template.param("SHOW_SEARCH", show_search)
292 self._template.param("MESSAGE", message)
293 self._template.param("ACTION_FORM", "panel.py")
294 self._template.param("PAGE", "users")
295
296 if show_search == 0 and uid:
297 real_user = user.User(self._get_user()[0])
298 user.setup_params(user.User(uid), real_user, self._template)
299
300 self._harm.response.append_body(self._template.output())
301 self._do_footer()
302
303 @exposed
304 @auth.restricted((user.ADMIN,))
305 def scripts(self):
306
307 self._do_header("Administration Console")
308 self._set_template(os.path.join(config.template_loc,
309 'admin/scripts.tpl'))
310 self._harm.response.append_body(self._template.output())
311 self._do_footer()
312
313
314 # FIXME: __failed_save and _delete_user are from profile.py
315 # FIXME: do some refactoring, ass.
316 def __failed_save(self, msg, fields):
317
318 self._do_header()
319
320 self._set_template(
321 os.path.join(config.template_loc, "admin/user.tpl"))
322
323 profile_user = user.User(fields["user_id"])
324 real_user = user.User(self._get_user()[0])
325 user.setup_params(profile_user, real_user, self._template)
326 self._template.param("GLSR_URL", config.url)
327 self._template.param("GLSR_REPORT", msg)
328 self._template.param("GLSR_REPORT_TYPE", "warn")
329 self._template.param("USER_ID", fields["user_id"])
330 self._template.param("ACTION_FORM", "panel.py")
331 self._template.param("PAGE", "users")
332
333 self._harm.response.append_body(self._template.output())
334 self._do_footer()
335
336 def _delete_user(self, uid):
337 """Delete the user and show the delete confirmation page."""
338
339 user_obj = user.User(uid)
340 username = user_obj.get_alias()
341 user_obj.delete()
342
343 self._do_header("User Deleted")
344 self._set_template(
345 os.path.join(config.template_loc, 'admin/delete_confirm.tpl'))
346 self._template.param("USERNAME", username)
347 self._harm.response.append_body(self._template.output())
348 self._do_footer()

Properties

Name Value
svn:keywords Id

  ViewVC Help
Powered by ViewVC 1.1.20