Exemplo n.º 1
0
 def clean_expe_name(self):
     value = self.cleaned_data['expe_name']
     if value == '':
         raise ValidationError(
             "Experiment name can't not be an empty string")
     try:
         validations.validate_register_experiment_field(value)
     except ValidationError, err:
         raise forms.ValidationError, str(err)
Exemplo n.º 2
0
def register_sensor(sensor_name, experiment, frequency, frequency_unit,
                    frequency_other, precision, truncation, precision_other,
                    goal, list_of_attributes):
    """
  <Purpose>
    Creates a sensor record with the specified information.
  <Arguments>
    experiment,
    frequency,
    frequency_unit,
    frequency_other,
    precision,
    truncation,
    precision_other,
    goal,
    list of attributes of each sensor.
  <Exceptions>
    ValidationError
      If any of the arguments contains invalid values or if the username is the
      same as the password.
  <Returns>
    Batter instance 
  """
    # If the frontend code that called this function wants to know which field
    # is invalid, it must call the validation functions itself before making the
    # call to register_battery().
    # These will raise a ValidationError if any of the fields are invalid.
    # These ensure that the data is of the correct type (e.g. a string) as well as
    # that we like the content of the variable.

    #There's no need of validation with the Boolean fields.
    #Neither integer fields need it

    validations.validate_register_experiment_field(frequency_unit)
    validations.validate_register_experiment_field(frequency_other)
    validations.validate_register_experiment_field(precision)
    validations.validate_register_experiment_field(precision_other)
    validations.validate_register_experiment_field(goal)

    sensor = maindb.create_sensor(sensor_name, experiment, frequency,
                                  frequency_unit, frequency_other, precision,
                                  truncation, precision_other, goal,
                                  list_of_attributes)

    return sensor
Exemplo n.º 3
0
def register_experiment(geni_user, experiment_name, researcher_name,
                        researcher_address, researcher_email, irb_name,
                        irb_email, experiment_goal):
    """
  <Purpose>
    Creates a experiment record with the specified information.
  <Arguments>
    geni_user
    experiment_name
    researcher_name
    researcher_address
    researcher_email
    irb_name
    irb_email
    experiment_goal
  <Exceptions>
    ValidationError
      If any of the arguments contains invalid values or if the username is the
      same as the password.
  <Returns>
    Experiment instance (our Experiment model) corresponding to the
    new
    """
    # If the frontend code that called this function wants to know which field
    # is invalid, it must call the validation functions itself before making the
    # call to register_experiment().
    # These will raise a ValidationError if any of the fields are invalid.
    # These ensure that the data is of the correct type (e.g. a string) as well as
    # that we like the content of the variable.

    validations.validate_register_experiment_field(experiment_name)
    validations.validate_register_experiment_field(researcher_name)
    validations.validate_register_experiment_field(researcher_address)
    validations.validate_email(researcher_email)
    validations.validate_register_experiment_field(irb_name)
    validations.validate_email(irb_email)
    validations.validate_register_experiment_field(experiment_goal)

    experiment = maindb.create_experiment(geni_user, experiment_name,
                                          researcher_name, researcher_address,
                                          researcher_email, irb_name,
                                          irb_email, experiment_goal)

    return experiment
Exemplo n.º 4
0
 def clean_goal(self):
     value = self.cleaned_data['goal']
     try:
         validations.validate_register_experiment_field(value)
     except ValidationError, err:
         raise forms.ValidationError, str(err)
Exemplo n.º 5
0
 def clean_precision_other(self):
     value = self.cleaned_data['precision_other']
     try:
         validations.validate_register_experiment_field(value)
     except ValidationError, err:
         raise forms.ValidationError, str(err)
Exemplo n.º 6
0
 def clean_frequency_unit(self):
     value = self.cleaned_data['frequency_unit']
     try:
         validations.validate_register_experiment_field(value)
     except ValidationError, err:
         raise forms.ValidationError, str(err)
Exemplo n.º 7
0
 def clean_researcher_institution_name(self):
     value = self.cleaned_data['researcher_institution_name']
     try:
         validations.validate_register_experiment_field(value)
     except ValidationError, err:
         raise forms.ValidationError, str(err)