def create_indicator(self, attr_type, ind_type):
     """
         Create any simple indicator indicator
     """
     return Indicator.create_with_attribute(self.cleaned_data['name'], 
                                             attr_type=attr_type, 
                                             indicator_type=ind_type)
 def create_location_indicator(self):
     """
         Create a location indicator with a default area type.
         If no area type, raise a ValidationError.
     """
     
     try:
         area_type = AreaType.objects.all()[0]
     except (AreaType.DoesNotExist, IndexError):
         raise ValidationError('You must create at least one area type '\
                               'before using locations')
     
     return Indicator.create_with_attribute(self.cleaned_data['name'], 
                                 attr_type=eav.models.Attribute.TYPE_OBJECT, 
                                 indicator_type=LocationIndicator,
                                 kwargs={'area_type':area_type})
 def create_indicator_with_params(self, indicator_type):
     """
         Create a any indicator that needs a numerical parameter
         If there is not at least 2 numerical indicators in this view
         we can use as default parameters, raise a ValidationError.
     """
     
     indicators = self.view.get_numerical_indicators()
     
     if not indicators:
         raise ValidationError('You need at least one other indicator '\
                                'using number before creating this one')
     
     return Indicator.create_with_attribute(self.cleaned_data['name'], 
                                 attr_type=eav.models.Attribute.TYPE_FLOAT, 
                                 indicator_type=indicator_type,
                                 args=(indicators[0],))
 def create_difference_indicator(self):
     """
         Create a indicator substracting two default values.
         If there is not at least 2 numerical indicators in this view
         we can use as default parameters, raise a ValidationError.
     """
     
     indicators = self.view.get_numerical_indicators()
     
     if len(indicators) < 2:
         raise ValidationError('You have at least two other indicators '\
                                'using numbers before creating this one')
     
     return Indicator.create_with_attribute(self.cleaned_data['name'], 
                                 attr_type=eav.models.Attribute.TYPE_FLOAT, 
                                 indicator_type=DifferenceIndicator,
                                 kwargs={'first_term': indicators[0],
                                         'term_to_substract': indicators[1]})
 def create_dividing_indicator(self, indicator_type):
     """
         Create a rate or a ratio indicator with default numerator and
         denominator.
         If there is not at least 2 numerical indicators in this view
         we can use as default parameters, raise a ValidationError.
     """
     
     indicators = self.view.get_numerical_indicators()
     
     if len(indicators) < 2:
         raise ValidationError('You need at least two other indicators '\
                                'using numbers before creating this one')
     
     return Indicator.create_with_attribute(self.cleaned_data['name'], 
                                 attr_type=eav.models.Attribute.TYPE_FLOAT, 
                                 indicator_type=indicator_type,
                                 kwargs={'numerator': indicators[0],
                                         'denominator': indicators[1]})