CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
List of all members | Public Member Functions | Public Attributes
querying.factory Class Reference

Public Member Functions

def __init__
 
def object
 

Public Attributes

 connection
 

Detailed Description

Contains methods for creating objects.

Definition at line 296 of file querying.py.

Constructor & Destructor Documentation

def querying.factory.__init__ (   self,
  connection 
)

Definition at line 300 of file querying.py.

301  def __init__(self, connection):
302  self.connection = connection

Member Function Documentation

def querying.factory.object (   self,
  class_name,
  pkargs 
)

Definition at line 306 of file querying.py.

References models.apply_filters(), and isotrackApplyRegressor.model.

307  def object(self, class_name, **pkargs):
308  from .data_sources import json_list
309  from .models import apply_filters
310  # get the class that self.connection holds from the class name
311  model = self.connection.model(class_name)
312 
313  if self.connection.session == None:
314  return None
315 
316  # query for the ORM object, and return the appropriate object (None, CondDBFW object, or json_list)
317  model_data = self.connection.session.query(model)
318  if len(list(pkargs.items())) != 0:
319  # apply the filters defined in **kwargs
320  model_data = apply_filters(model_data, model, **pkargs)
321  amount = pkargs["amount"] if "amount" in list(pkargs.keys()) else None
322  model_data = model_data.limit(amount)
323  if model_data.count() > 1:
324  # if we have multiple objects, return a json_list
325  return json_list(model_data.all())
326  elif model_data.count() == 1:
327  # if we have a single object, return that object
328  return model_data.first()
329  else:
330  # if we have no objects returned, return None
331  return None
332  else:
333  # no column arguments were given, so return an empty object
334  new_object = model()
335  new_object.empty = True
336  return new_object
def apply_filters
Definition: models.py:181

Member Data Documentation

querying.factory.connection

Definition at line 301 of file querying.py.

Referenced by querying_tests.querying_tests.test_check_connection(), and data_formats_tests.data_formats_tests.test_dicts_to_orm_objects().