test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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 293 of file querying.py.

Constructor & Destructor Documentation

def querying.factory.__init__ (   self,
  connection 
)

Definition at line 297 of file querying.py.

298  def __init__(self, connection):
299  self.connection = connection

Member Function Documentation

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

Definition at line 303 of file querying.py.

References models.apply_filters().

Referenced by Vispa.Views.LineDecayView.LineDecayContainer.createObject(), Vispa.Views.LineDecayView.LineDecayContainer.delete(), Vispa.Views.LineDecayView.DecayLine.delete(), Vispa.Views.LineDecayView.LineDecayContainer.mouseReleaseEvent(), and Vispa.Views.BoxDecayView.BoxDecayContainer.toggleCollapse().

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

Member Data Documentation

querying.factory.connection

Definition at line 298 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().