This repository was archived by the owner on Jan 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathadmin.py
More file actions
54 lines (40 loc) · 1.33 KB
/
admin.py
File metadata and controls
54 lines (40 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import os
import re
import cgi
import logging
import basherc
from google.appengine.api import users
from google.appengine.ext import webapp
from google.appengine.ext import db
from google.appengine.ext.webapp.util import run_wsgi_app
# ---
class AdminPage(webapp.RequestHandler):
def get(self):
user = users.get_current_user()
if user and users.is_current_user_admin():
quotes = db.GqlQuery("SELECT * FROM Quote ORDER BY date_quote DESC LIMIT 50")
mt = basherc.MiniTemplateRenderer(self.response)
mt.produce_index({ 'quotes': quotes, 'adminmode': True, 'user': "<a href='" + users.create_logout_url('/') + "'>" + user.nickname() + "</a>" })
else:
self.redirect(users.create_login_url(self.request.uri))
# ---
class AdminAction(webapp.RequestHandler):
def get(self):
user = users.get_current_user()
if user and users.is_current_user_admin():
quote = db.get(self.request.get('id'))
logging.info("[admin] located quote by %s" % quote.author)
quote.delete()
logging.warning("[admin] quote was deleted by %s" % user.nickname())
self.redirect("/admin/")
else:
self.redirect("/admin/")
# ---
application = webapp.WSGIApplication(
[('/admin/delete', AdminAction),
('/admin/', AdminPage)],
debug=True)
def main():
run_wsgi_app(application)
if __name__ == "__main__":
main()