Permalink
Browse files

add logging model and obscure list view

  • Loading branch information...
1 parent 64ccc02 commit 2ad290e37c5110cf06b23ffdc00a6c1d1a15cebb @billsaysthis billsaysthis committed Dec 5, 2010
Showing with 81 additions and 11 deletions.
  1. +18 −2 main.py
  2. +11 −0 models.py
  3. +7 −2 static/style.css
  4. +8 −6 templates/base.html
  5. +31 −0 templates/logs.html
  6. +6 −1 utils.py
View
20 main.py
@@ -10,7 +10,7 @@
from pprint import pprint
from datetime import datetime, timedelta
-from models import Event, Feedback, ROOM_OPTIONS, PENDING_LIFETIME
+from models import Event, Feedback, HDLog, ROOM_OPTIONS, PENDING_LIFETIME
from utils import username, human_username, set_cookie, local_today, is_phone_valid, UserRights, dojo, is_event_dup
from notices import *
@@ -158,8 +158,11 @@ def post(self, id):
event.notes = cgi.escape(self.request.get('notes'))
event.rooms = self.request.get_all('rooms')
event.put()
+ log = HDLog(event=event,description="edited something")
+ log.put()
+ logging.info('%s %s %s' % (log.user.nickname, log.event.name, log.description))
self.redirect(event_path(event))
- except Exception, e:
+ except ValueError, e:
error = str(e)
self.response.out.write(template.render('templates/error.html', locals()))
else:
@@ -375,6 +378,18 @@ def post(self, id):
message = is_event_dup(start_date, end_date, rooms)
self.response.out.write(message)
+class LogsHandler(webapp.RequestHandler):
+ @util.login_required
+ def get(self):
+ user = users.get_current_user()
+ logs = HDLog.get_logs_list()
+ if user:
+ logout_url = users.create_logout_url('/')
+ else:
+ login_url = users.create_login_url('/')
+ show_all_nav = (user.nickname)
+ self.response.out.write(template.render('templates/logs.html', locals()))
+
class FeedbackHandler(webapp.RequestHandler):
@util.login_required
def get(self, id):
@@ -421,6 +436,7 @@ def main():
('/domaincache', DomainCacheCron),
('/reminder', ReminderCron),
('/check_conflict', CheckConflict),
+ ('/logs', LogsHandler),
('/feedback/new/(\d+).*', FeedbackHandler) ],debug=True)
util.run_wsgi_app(application)
View
@@ -203,3 +203,14 @@ class Feedback(db.Model):
rating = db.IntegerProperty()
comment = db.StringProperty(multiline=True)
created = db.DateTimeProperty(auto_now_add=True)
+
+class HDLog(db.Model):
+ event = db.ReferenceProperty(Event)
+ created = db.DateTimeProperty(auto_now_add=True)
+ user = db.UserProperty(auto_current_user_add=True)
+ description = db.StringProperty(multiline=True)
+
+ @classmethod
+ def get_logs_list(cls):
+ return cls.all() \
+ .order('-created')
View
@@ -1,5 +1,5 @@
body { font-family: Verdana,Arial,sans-serif; margin: 0px;}
-#wrapper { margin-left: auto; margin-right: auto; width: 700px; position: relative;}
+#wrapper, #top > div { margin-left: auto; margin-right: auto; width: 700px; position: relative;}
#top a:visited { color: blue;}
#top { height: 20px; border-bottom: 1px solid #ccc; text-align: right; font-size: 12px; padding-right: 5px; padding-top: 4px; }
@@ -8,8 +8,9 @@ body { font-family: Verdana,Arial,sans-serif; margin: 0px;}
#header img { margin-right: 10px;}
#header h1 { font-size: 42px; margin-top: 20px; padding-top: 10px; margin-bottom: 0px; padding-bottom: 0px;}
#header h2 { font-size: x-large; margin: 0px; }
-#new-event-link {position: absolute; right: 10px; padding: 3px 5px; background-color:#d50025;}
+#new-event-link {position: absolute; right: 0px; padding: 3px 5px; background-color:#d50025;}
#new-event-link a {color: #fff; text-decoration: none;}
+body.new #new-event-link {display: none;}
.step span { color: white; background-color: #b10026; padding: 1px; padding-left: 4px; padding-right: 4px;}
.step.inactive span { background-color: gray;}
@@ -28,6 +29,10 @@ table td.first { width: 110px; padding-right: 20px; }
#terms li { margin-top: 10px;}
nobr label { display: inline;}
+#log-list {width:100%;}
+#log-list th {text-align: left;}
+#log-list .desc-line {border-bottom: 1px solid #e0e0e0; line-height: 5px;}
+
form div { margin-top: 10px; }
label { display: block; font-size: smaller;}
View
@@ -14,15 +14,17 @@
</head>
<body>
<div id="top">
- {% if user %}
- <span><strong>{{user.email}}</strong> | <a href="/myevents">My Events</a> | <a href="{{logout_url}}">Logout</a></span>
- {% else %}
- <span><a style="font-weight: bold;" href="{{login_url}}">Login</a> | <a href="http://signup.hackerdojo.com/upgrade/needaccount">Need an account?</a></span>
- {% endif %}
+ <div>
+ {% if user %}
+ <strong>{{user.email}}</strong> | <a href="/myevents">My Events</a> | <a href="{{logout_url}}">Logout</a>
+ {% else %}
+ <a style="font-weight: bold;" href="{{login_url}}">Login</a> | <a href="http://signup.hackerdojo.com/upgrade/needaccount">Need an account?</a>
+ {% endif %}
+ </div>
</div>
<div id="wrapper">
<div id="header">
- <span id='new-event-link'><a href="/new" id="nav_new" class="emph">New Event</a></span>
+ <span id='new-event-link'><form action="/new" method="get"><button type="submit" id="nav_new" class="emph">New Event</button></form></span>
<img src="/static/dojo_icon.png" style="float: left;" />
<h1>Events</h1>
<h2 style="font-size: x-large;">at Hacker Dojo</h2>
View
@@ -0,0 +1,31 @@
+{% extends 'base.html' %}
+{% block content %}
+{% include 'nav_menu.html' %}
+
+<div id="primary">
+ <h3>Event App Logs</h3>
+
+ <table id='log-list'>
+ <tr>
+ <th style='width:110px;'>Timestamp</th>
+ <th style='width:220px;'>Member</th>
+ <th>Event</th>
+ </tr>
+ {% for log in logs %}
+ <tr>
+ <td>{{log.created|date:"b j Y"|title}} {{log.created|date:"g:i A"|lower}}</td>
+ <td>{{log.user.nickname}}</td>
+ <td><a href="/event/{{log.event.key.id}}-{{log.event.name|slugify}}">{{log.event.name}}</a></td>
+ </tr>
+ <tr>
+ <td colspan='3'>{{log.description}}</td>
+ </tr>
+ <tr class='desc-line'><td colspan='3'>&nbsp;</td>
+ </tr>
+ {% endfor %}
+ </table>
+ {% if false %}
+ <p style="font-size: x-small;">Alternative formats: <a href="/events.ics">iCal</a> | <a href="/events.rss">RSS</a> | JSON</p>
+ {% endif %}
+</div>
+{% endblock %}
View
@@ -96,7 +96,12 @@ def is_event_dup(start_date, end_date, rooms):
if room == tmroom:
return "yes"
return "no"
-
+
+def user_is_admin():
+ user = users.get_current_user()
+ access_rights = UserRights(user)
+ return access_rights.is_admin
+
class UserRights(object):
def __init__(self, user=None, event=None):
"""Constructor.

0 comments on commit 2ad290e

Please sign in to comment.