def query(self, socket_connection, message, count, start, dojo_sort, dojo_query): session = SessionFactory() try: query = session.query(Assignment.id, Assignment.name, Assignment.template, Assignment.due_date) column_map = {u'id': Assignment.id, u'name': Assignment.name, u'template': Assignment.template, u'due_date': Assignment.due_date} if dojo_query: if u"op" in dojo_query: dojo_query_obj = DojoQuery(dojo_query) query = dojo_query_obj.apply_to_sqla_query(query, column_map) else: dojo_query_obj = SimpleDojoQuery(dojo_query) query = dojo_query_obj.apply_to_sqla_query(query, column_map) if dojo_sort is not None: dojo_sort_obj = DojoSort(dojo_sort) query = dojo_sort_obj.apply_to_sqla_query(query, column_map) assignment_count = query.count() assignment_list = query.offset(start).limit(count).all() assignment_list = map(self.object_to_json, assignment_list) result_message = {'type': self.message_type, 'response': assignment_list, 'total': assignment_count, 'deferredId': message['deferredId'], } finally: session.close() socket_connection.write_message(json.dumps(result_message))
def query(self, socket_connection, message, count, start, dojo_sort, dojo_query): session = SessionFactory() try: query = session.query(User.id, User.username, User.permission_level, User.user_since, User.last_online) column_map = {u'id': User.id, u'username': User.username, u'permissions': User.permission_level} if dojo_query: dojo_query_obj = DojoQuery(dojo_query) query = dojo_query_obj.apply_to_sqla_query(query, column_map) if dojo_sort is not None: dojo_sort_obj = DojoSort(dojo_sort) query = dojo_sort_obj.apply_to_sqla_query(query, column_map) user_count = query.count() user_list = query.offset(start).limit(count).all() user_list = [{'id': uid, 'username': username, 'permissions': permission_level, 'user_since': user_since, 'last_online': last_online} for uid, username, permission_level, user_since, last_online in user_list] result_message = {'type': self.message_type, 'response': user_list, 'total': user_count, 'deferredId': message['deferredId'], } finally: session.close() socket_connection.write_message(json.dumps(result_message))
def query(self, socket_connection, message, count, start, dojo_sort, dojo_query): session = SessionFactory() try: column_map = {u'id': LogEntry.id, u'timestamp': LogEntry.timestamp, u'logger': LogEntry.logger, u'level': LogEntry.level, u'trace': LogEntry.trace, u'message': LogEntry.msg} query = session.query(LogEntry.id, LogEntry.timestamp, LogEntry.logger, LogEntry.level, LogEntry.trace, LogEntry.msg) if dojo_query: dojo_query_obj = DojoQuery(dojo_query) query = dojo_query_obj.apply_to_sqla_query(query, column_map) if dojo_sort is not None: dojo_sort_obj = DojoSort(dojo_sort) query = dojo_sort_obj.apply_to_sqla_query(query, column_map) log_entry_count = query.count() log_entry_list = query.offset(start).limit(count).all() log_entry_list = [{u'id': id, u'timestamp': timestamp.isoformat(), u'logger': logger, u'level': level, u'trace': trace, u'message': msg} for id, timestamp, logger, level, trace, msg in log_entry_list] result_message = {'type': self.message_type, 'response': log_entry_list, 'total': log_entry_count, 'deferredId': message['deferredId'], } finally: session.close() socket_connection.write_message(json.dumps(result_message))
def query(self, socket_connection, message, count, start, dojo_sort, dojo_query): session = SessionFactory() try: query = session.query(Assignment.id, Assignment.name, Assignment.template, Assignment.due_date) column_map = { u'id': Assignment.id, u'name': Assignment.name, u'template': Assignment.template, u'due_date': Assignment.due_date } if dojo_query: if u"op" in dojo_query: dojo_query_obj = DojoQuery(dojo_query) query = dojo_query_obj.apply_to_sqla_query( query, column_map) else: dojo_query_obj = SimpleDojoQuery(dojo_query) query = dojo_query_obj.apply_to_sqla_query( query, column_map) if dojo_sort is not None: dojo_sort_obj = DojoSort(dojo_sort) query = dojo_sort_obj.apply_to_sqla_query(query, column_map) assignment_count = query.count() assignment_list = query.offset(start).limit(count).all() assignment_list = map(self.object_to_json, assignment_list) result_message = { 'type': self.message_type, 'response': assignment_list, 'total': assignment_count, 'deferredId': message['deferredId'], } finally: session.close() socket_connection.write_message(json.dumps(result_message))