예제 #1
0
파일: chartdata.py 프로젝트: avpakh/JAS
 def __init__(self, series):
     """Create a DataPool object as specified by the ``series``.
     
     :Arguments: 
     
     - **series** *(list of dict)* - specifies the what data to retrieve 
       and where to retrieve it from. It is of the form ::
       
         [{'options': {
            'source': a django model, Manager or QuerySet,
            },
          'terms': [
            'a_valid_field_name', ... ,
            {'any_name': 'a_valid_field_name', ... },
            ]
         },
         ... 
         ]
     
       Where 
       
       - **options** - is a dict with one key.
       
         + **source** - is either a ``Model``, ``Manager`` or a 
           ``QuerySet``.
           
       - **terms** - is a list. Each element in ``terms`` is either 
         
         1. a ``str`` - needs to be a valid model field for the 
            corresponding ``source``, or 
         2. a ``dict`` - need to be of the form 
            ``{'any_name': 'a_valid_field_name', ...}``. 
       
       To retrieve data from multiple models or QuerySets, just add more 
       dictionaries with the corresponding ``options`` and terms.
       
     :Raises:
       
     - **APIInputError** - sif the ``series`` argument has any invalid 
       parameters.
     
      
     .. warning:: All elements in ``terms`` **must be unique** across all 
        the dictionaries in the ``series`` list. If there are two terms 
        with same ``name``, the latter one is going to overwrite the one 
        before it.
     
     For example, the following is **wrong**: ::
     
       [{'options': {
           'source': SomeModel},
         'terms':[
           'foo', 
           'bar']},
        {'options': {
           'source': OtherModel},
         'terms':[
           'foo']}]
           
     In this case, the term ``foo`` from ``OtherModel`` is going to 
     **overwrite** ``foo`` from ``SomeModel``. 
     
     Here is the **right** way of retrieving data from two different models 
     both of which have the same field name. ::
     
       [{'options': {
          'source': SomeModel},
         'terms':[
           'foo', 
           'bar']},
        {'options': {
          'source': OtherModel},
         'terms':[
           {'foo_2': 'foo'}]}]
      """
     # Save user input to a separate dict. Can be used for debugging.
     self.user_input = {}
     self.user_input['series'] = copy.deepcopy(series)
     self.series = clean_dps(series)
     self.query_groups = self._group_terms_by_query()
     # Now get data
     self._get_data()
예제 #2
0
 def __init__(self, series):
     """Create a DataPool object as specified by the ``series``.
     
     :Arguments: 
     
     - **series** *(list of dict)* - specifies the what data to retrieve 
       and where to retrieve it from. It is of the form ::
       
         [{'options': {
            'source': a django model, Manager or QuerySet,
            },
          'terms': [
            'a_valid_field_name', ... ,
            {'any_name': 'a_valid_field_name', ... },
            ]
         },
         ... 
         ]
     
       Where 
       
       - **options** (**required**) - a ``dict``. Any of the `series 
         options <http://www.highcharts.com/ref/#series>`_ for the 
         Highcharts ``options`` object are valid. 
           
       - **terms** - is a list. Each element in ``terms`` is either 
         
         1. a ``str`` - needs to be a valid model field for the 
            corresponding ``source``, or 
         2. a ``dict`` - need to be of the form 
            ``{'any_name': 'a_valid_field_name', ...}``. 
       
       To retrieve data from multiple models or QuerySets, just add more 
       dictionaries with the corresponding ``options`` and terms.
       
     :Raises:
       
     - **APIInputError** - sif the ``series`` argument has any invalid 
       parameters.
     
      
     .. warning:: All elements in ``terms`` **must be unique** across all 
        the dictionaries in the ``series`` list. If there are two terms 
        with same ``name``, the latter one is going to overwrite the one 
        before it.
     
     For example, the following is **wrong**: ::
     
       [{'options': {
           'source': SomeModel},
         'terms':[
           'foo', 
           'bar']},
        {'options': {
           'source': OtherModel},
         'terms':[
           'foo']}]
           
     In this case, the term ``foo`` from ``OtherModel`` is going to 
     **overwrite** ``foo`` from ``SomeModel``. 
     
     Here is the **right** way of retrieving data from two different models 
     both of which have the same field name. ::
     
       [{'options': {
          'source': SomeModel},
         'terms':[
           'foo', 
           'bar']},
        {'options': {
          'source': OtherModel},
         'terms':[
           {'foo_2': 'foo'}]}]
      """
     # Save user input to a separate dict. Can be used for debugging.
     self.user_input = {}
     self.user_input['series'] = copy.deepcopy(series)
     self.series = clean_dps(series)
     self.query_groups = self._group_terms_by_query()
     # Now get data
     self._get_data()