def main(cursor, error_id=-1): error_id = int(common_f.get_val("error", error_id)) sub_mode = common_f.get_val("sub_mode", "form") if sub_mode == "fix": return fix(cursor, error_id) if sub_mode == "delete": return delete(cursor, error_id) the_error = common_q.get_one(cursor, error.Error, id=error_id) the_user = common_q.get_one(cursor, user.User, id=the_error.user_id) output = [] http_args = the_error.args.replace("\n\n", "\n").replace(" ", "") http_args = "&".join(http_args.split("\n")) http_args = http_args.replace("mode=", "emulate_mode=") output.append( """ <div style="padding:10px;"> <span style="float:right;padding-right:20px;"> <a href="web.py?mode=edit_error&sub_mode=delete&error={error_id}">Delete</a> </span> <a href="web.py?mode=emulate_user&{http_args}&user_id={user_id}">Emulate</a> <br><br> <strong>Time:</strong> {timestamp} <strong>User:</strong> {user} <strong>Mode:</strong> <a href="web.py?mode=list_errors&filter={mode}">{mode}</a> <br> <strong>Data:</strong><br> <textarea rows="8" style="width:99%;">{args}</textarea> </div> <br> <div style="padding:0px;border-top:1px solid #AAA;"> {traceback} </div> """.format( error_id=int(error_id), user_id=the_user.id, user=the_user.username if the_user != None else "Not logged in", mode=the_error.mode, args=the_error.args, http_args=http_args, timestamp=common_f.display_date(the_error.timestamp, "%d of %B at %H:%M"), traceback=the_error.traceback, ) ) return "".join(output)
def test_display_date(self): self.test_targets.append(common_f.display_date) self.test_targets.append(common_f.th_of_month) vals = ( ("%d of %B", datetime.date(2012, 1, 1), "01st of January"), ("%d of %B", datetime.date(2012, 3, 2), "02nd of March"), ("%d of %B", datetime.date(2012, 6, 3), "03rd of June"), ("%d of %B", datetime.date(2012, 10, 4), "04th of October"), ("%d of %B", datetime.date(2012, 1, 11), "11th of January"), ("%d of %B", datetime.date(2012, 3, 12), "12th of March"), ("%d of %B", datetime.date(2012, 6, 13), "13th of June"), ("%d of %B", datetime.date(2012, 1, 21), "21st of January"), ("%d of %B", datetime.date(2012, 3, 22), "22nd of March"), ("%d of %B", datetime.date(2012, 6, 23), "23rd of June"), ("%d of %B", datetime.date(2012, 10, 24), "24th of October"), ) for format_string, the_date, expected in vals: self.assertEqual(common_f.display_date(the_date, format_string), expected)
def main(cursor, query_filter=""): query_filter = common_f.get_val("filter", query_filter) if query_filter == "": log_dict = common_q.get_all(cursor, user_log.UserLog, orderby="access_time DESC") elif query_filter == "today": today = datetime.date.today() today = time.mktime(today.timetuple()) log_dict = common_q.get_all( cursor, user_log.UserLog, where="access_time >= %d" % today, orderby="access_time DESC" ) else: log_dict = common_q.get_all( cursor, user_log.UserLog, where="mode='%s'" % database_f.escape(query_filter), orderby="access_time DESC" ) output = [] if len(log_dict) > 0: user_dict = common_q.get_all(cursor, user.User) user_dict[-1] = user.User(username="******") output.append( """<table border="0" cellspacing="0" cellpadding="5" style="width:100%;"> <tr class="row2"> <th>Date</th> <th>Mode</th> <th>User</th> <th>Load time</th> <th colspan="2"> </th> </tr> """ ) i = 1 for log_id, the_log in log_dict.items(): i += 1 the_date = the_log.access_time output.append( """ <tr class="row{row}"> <td>{date}</td> <td>{page}</td> <td>{user}</td> <td>{load_time}</td> <td class="block_cell"><a href="web.py?mode=edit_log&log={log_id}">View</a></td> <td class="block_cell"><a href="web.py?mode=edit_log&log={log_id}&sub_mode=delete">Delete</a></td> </tr>""".format( log_id=log_id, row=i % 2, load_time=round(the_log.load_time, 4), date=common_f.display_date(the_date, "%d of %B at %H:%M"), page="No mode specified" if the_log.page == "" else the_log.page, user=user_dict[the_log.user_id].username, ) ) output.append("</table>") else: output.append("<div style='padding:10px;'>No logs found</div>") return "".join(output)
def main(cursor, query_filter=""): query_filter = common_f.get_val("filter", query_filter) if query_filter == "": error_dict = common_q.get_all(cursor, error.Error, where="fixed = False", orderby="timestamp DESC") elif query_filter == "today": today = datetime.date.today() today = time.mktime(today.timetuple()) error_dict = common_q.get_all( cursor, error.Error, where="timestamp >= %d AND fixed = False" % today, orderby="timestamp DESC" ) else: error_dict = common_q.get_all( cursor, error.Error, where="mode='%s' and fixed = False" % database_f.escape(query_filter), orderby="timestamp DESC", ) output = [] if len(error_dict) > 0: user_dict = common_q.get_all(cursor, user.User) user_dict[-1] = user.User(username="******") output.append( """<table border="0" cellspacing="0" cellpadding="5" style="width:100%;"> <tr class="row2"> <th>Date</th> <th>Mode</th> <th>Func Call</th> <th>Type</th> <th>User</th> <th colspan="2"> </th> </tr> """ ) i = 1 for error_id, the_error in error_dict.items(): i += 1 the_date = the_error.timestamp output.append( """ <tr class="row{row}" id="row{error_id}"> <td>{date}</td> <td>{mode}</td> <td>{function_call}</td> <td>{etype}</td> <td>{user}</td> <td class="block_cell"><a href="web.py?mode=edit_error&error={error_id}">View</a></td> <td class="block_cell"><a href="#" onclick="{onclick}">Fix</a></td> </tr>""".format( error_id=error_id, row=i % 2, etype=the_error.exception_type, date=common_f.display_date(the_date, "%d of %B at %H:%M"), mode="No mode specified" if the_error.mode == "" else the_error.mode, function_call="" if the_error.function_call == "" else the_error.function_call, user=user_dict[the_error.user_id].username, onclick="""$('#ajax_target').load('web.py', {'mode':'edit_error', 'error':'%d', 'sub_mode':'fix'}); $('#row%d').hide(); return false;""" % (error_id, error_id), ) ) output.append("</table>") else: output.append("<div style='padding:10px;'>No errors found</div>") modes = {} # Select all the groups possible query = """SELECT mode FROM errors GROUP BY mode""" try: cursor.execute(query) except Exception as e: raise Exception("Database error: %s\nQuery: %s" % (str(e.args[0]).replace("\n", ""), query)) for row in cursor: modes[row["mode"]] = row["mode"] page_data["Rows"] = len(error_dict) page_data["Title"] = "Error list (%d)" % len(error_dict) page_data[ "Filters" ] = """ <form action="web.py" method="get" accept-charset="utf-8" style="float: left;"> <a href="web.py?mode=list_errors">All errors</a> <a href="web.py?mode=list_errors&filter=today">Todays errors</a> <input type="hidden" name="mode" value="list_errors" /> {} <input type="submit" value="Sort by mode" /> </form> """.format( html_f.option_box("filter", modes, selected=query_filter) ) return "".join(output)