def get_verbose_request_context(): """ Return a string with lots of information about the current cherrypy request such as request headers, session params, and page location. Returns: """ from uber.models.admin import AdminAccount page_location = 'Request: ' + cherrypy.request.request_line admin_name = AdminAccount.admin_name() admin_txt = 'Current admin user is: {}'.format( admin_name if admin_name else '[non-admin user]') max_reporting_length = 1000 # truncate to reasonably large size in case they uploaded attachments p = [ " %s: %s" % (k, str(v)[:max_reporting_length]) for k, v in cherrypy.request.params.items() ] post_txt = 'Request Params:\n' + '\n'.join(p) session_txt = 'Session Params:\n' + pformat(cherrypy.session.items(), width=40) h = [" %s: %s" % (k, v) for k, v in cherrypy.request.header_list] headers_txt = 'Request Headers:\n' + '\n'.join(h) return '\n'.join( [page_location, admin_txt, post_txt, session_txt, headers_txt])
def get_verbose_request_context(): """ Return a string with lots of information about the current cherrypy request such as request headers, session params, and page location. Returns: """ from uber.models.admin import AdminAccount page_location = 'Request: ' + cherrypy.request.request_line admin_name = AdminAccount.admin_name() admin_txt = 'Current admin user is: {}'.format(admin_name if admin_name else '[non-admin user]') max_reporting_length = 1000 # truncate to reasonably large size in case they uploaded attachments p = [" %s: %s" % (k, str(v)[:max_reporting_length]) for k, v in cherrypy.request.params.items()] post_txt = 'Request Params:\n' + '\n'.join(p) session_txt = '' if hasattr(cherrypy, 'session'): session_txt = 'Session Params:\n' + pformat(cherrypy.session.items(), width=40) h = [" %s: %s" % (k, v) for k, v in cherrypy.request.header_list] headers_txt = 'Request Headers:\n' + '\n'.join(h) return '\n'.join([page_location, admin_txt, post_txt, session_txt, headers_txt])
def track(cls, action, instance): if action in [c.CREATED, c.UNPAID_PREREG, c.EDITED_PREREG]: vals = { attr: cls.repr(column, getattr(instance, attr)) for attr, column in instance.__table__.columns.items() } data = cls.format(vals) elif action == c.UPDATED: diff = cls.differences(instance) data = cls.format(diff) if len(diff) == 1 and 'badge_num' in diff: action = c.AUTO_BADGE_SHIFT elif not data: return else: data = 'id={}'.format(instance.id) links = ', '.join( '{}({})'.format( list(column.foreign_keys)[0].column.table.name, getattr(instance, name)) for name, column in instance.__table__.columns.items() if column.foreign_keys and getattr(instance, name)) if sys.argv == ['']: who = 'server admin' else: who = AdminAccount.admin_name() or (current_thread().name if current_thread().daemon else 'non-admin') try: snapshot = json.dumps(instance.to_dict(), cls=serializer) except TypeError as e: snapshot = "(Could not save JSON dump due to error: {}".format(e) def _insert(session): session.add( Tracking( model=instance.__class__.__name__, fk_id=instance.id, which=repr(instance), who=who, page=c.PAGE_PATH, links=links, action=action, data=data, snapshot=snapshot, )) if instance.session: _insert(instance.session) else: from uber.models import Session with Session() as session: _insert(session)
def track(cls, action, instance): if action in [c.CREATED, c.UNPAID_PREREG, c.EDITED_PREREG]: vals = { attr: cls.repr(column, getattr(instance, attr)) for attr, column in instance.__table__.columns.items()} data = cls.format(vals) elif action == c.UPDATED: diff = cls.differences(instance) data = cls.format(diff) if len(diff) == 1 and 'badge_num' in diff: action = c.AUTO_BADGE_SHIFT elif not data: return else: data = 'id={}'.format(instance.id) links = ', '.join( '{}({})'.format(list(column.foreign_keys)[0].column.table.name, getattr(instance, name)) for name, column in instance.__table__.columns.items() if column.foreign_keys and getattr(instance, name)) if sys.argv == ['']: who = 'server admin' else: who = AdminAccount.admin_name() or (current_thread().name if current_thread().daemon else 'non-admin') def _insert(session): session.add(Tracking( model=instance.__class__.__name__, fk_id=instance.id, which=repr(instance), who=who, page=c.PAGE_PATH, links=links, action=action, data=data, snapshot=json.dumps(instance.to_dict(), cls=serializer) )) if instance.session: _insert(instance.session) else: from uber.models import Session with Session() as session: _insert(session)
def track_pageview(cls): url, query = cherrypy.request.path_info, cherrypy.request.query_string # Track any views of the budget pages if "budget" in url: what = "Budget page" else: # Only log the page view if there's a valid attendee ID params = dict(parse_qsl(query)) if 'id' not in params or params['id'] == 'None': return # Looking at an attendee's details if "registration" in url: what = "Attendee id={}".format(params['id']) # Looking at a group's details elif "groups" in url: what = "Group id={}".format(params['id']) from uber.models import Session with Session() as session: session.add(PageViewTracking(who=AdminAccount.admin_name(), page=c.PAGE_PATH, what=what))
def track_pageview(cls): url, query = cherrypy.request.path_info, cherrypy.request.query_string # Track any views of the budget pages if "budget" in url: what = "Budget page" else: # Only log the page view if there's a valid attendee ID params = dict(parse_qsl(query)) if 'id' not in params or params['id'] == 'None': return # Looking at an attendee's details if "registration" in url: what = "Attendee id={}".format(params['id']) # Looking at a group's details elif "groups" in url: what = "Group id={}".format(params['id']) from uber.models import Session with Session() as session: session.add( PageViewTracking(who=AdminAccount.admin_name(), page=c.PAGE_PATH, what=what))