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

Contents of /trunk/htdocs/adminpanel.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 150 - (show annotations) (download) (as text)
Sat Sep 24 21:39:19 2005 UTC (9 years, 3 months ago) by hadfield
File MIME type: text/x-python
File size: 4415 byte(s)
finished the basic news admin interface
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 harmonious.utils import exposed, default
14
15 from glsr.core import fieldparse
16 from glsr.setup import config
17 from glsr.site import auth, basedomain, script, stat, user
18
19 class Adminpanel(basedomain.BaseDomain):
20
21 @default
22 @exposed
23 @auth.restricted((user.ADMIN,))
24 def stats(self):
25
26 self._do_header("Administration Console")
27 self._set_template(os.path.join(config.template_loc,
28 'admin/index.tpl'))
29 self._template.param("SCRIPT_COUNT", stat.count("script"))
30 self._template.param("USER_COUNT", stat.count("user"))
31 self._template.param("DBSIZE", stat.dbsize())
32 self._template.param("ONLINE_LOOP", [])
33 self._harm.response.append_body(self._template.output())
34 self._do_footer()
35
36 @exposed
37 @auth.restricted((user.ADMIN,))
38 def config(self):
39
40 self._do_header("Administration Console")
41 self._set_template(os.path.join(config.template_loc,
42 'admin/config.tpl'))
43 self._harm.response.append_body(self._template.output())
44 self._do_footer()
45
46 @exposed
47 @auth.restricted((user.ADMIN,))
48 def news(self):
49
50 from glsr.site import news
51
52 show_news = 1
53 modify = 0
54 news_id = "0"
55 subject = ""
56 body = ""
57
58 # Check if any news control buttons were pressed.
59 if self._harm.request.forms.has_key("show_news"):
60 show_news = 1
61
62 elif self._harm.request.forms.has_key("hide_news"):
63 show_news = 0
64
65 elif self._harm.request.forms.has_key("show_add"):
66 modify = 1
67 show_news = 0
68
69 elif self._harm.request.forms.has_key("save"):
70 modify = 1
71 show_news = 0
72 news_id = self._harm.request.forms.getvalue("news_id", "0")
73 uid = self._get_user()[0]
74 subject = self._harm.request.forms.getvalue("subject", "")
75 body = self._harm.request.forms.getvalue("body", "")
76 if news_id != "0" and news.exists(news_id):
77 # Modifying a news article
78 news_obj = news.News(news_id)
79 news_obj.update(uid, subject, body)
80 elif news_id == "0" and not news.exists(news_id):
81 # TODO: Need an error message here.
82 # Could not find specified news article.
83 pass
84 else:
85 # Creating a new article
86 news_id = news.create(uid, subject, body)
87
88 elif self._harm.request.queries.has_key("modify"):
89 modify = 1
90 show_news = 0
91 news_id = self._harm.request.queries.get("news_id")
92 news_obj = news.News(news_id)
93 subject = news_obj.get_subject()
94 body = news_obj.get_body()
95
96 elif self._harm.request.forms.has_key("delete"):
97 news_ids = self._harm.request.forms.getlist("delete_btn")
98
99 for cur_news_id in news_ids:
100 if cur_news_id != "0" and news.exists(cur_news_id):
101 news_obj = news.News(cur_news_id)
102 news_obj.delete()
103 else:
104 # TODO: Need an error message here.
105 # Could not find specified news article.
106 pass
107 show_news = 1
108
109 news_loop = news.list_all(
110 columns = ["news_id", "news_author_id", "news_author",
111 "news_date", "news_subject"])
112
113 self._do_header("Administration Console")
114 self._set_template(os.path.join(config.template_loc,
115 'admin/news.tpl'))
116
117 self._template.param("SHOW_NEWS", show_news)
118 self._template.param("NEWS_LOOP", news_loop)
119 self._template.param("MODIFY_NEWS", modify)
120 self._template.param("NEWS_ID", news_id)
121 self._template.param("SUBJECT", subject)
122 self._template.param("BODY", body)
123
124 self._harm.response.append_body(self._template.output())
125 self._do_footer()

Properties

Name Value
svn:keywords Id

  ViewVC Help
Powered by ViewVC 1.1.20