Beispiel #1
0
    def test_new_parameterset(self):

        psm = ParameterSetManager(parentObject=self.datafile,
                                  schema="http://localhost/psmtest/df2/")

        self.assertTrue(
            psm.get_schema().namespace == "http://localhost/psmtest/df2/")

        psm.set_param("newparam1", "test3", "New Parameter 1")

        self.assertTrue(psm.get_param("newparam1").string_value == "test3")

        self.assertTrue(
            psm.get_param("newparam1").name.full_name == "New Parameter 1")

        psm.new_param("newparam1", "test4")

        self.assertTrue(len(psm.get_params("newparam1", True)) == 2)

        psm.set_param_list("newparam2", ("a", "b", "c", "d"))

        self.assertTrue(len(psm.get_params("newparam2")) == 4)

        psm.set_params_from_dict({"newparam2": "test5", "newparam3": 3})

        self.assertTrue(psm.get_param("newparam2", True) == "test5")

        # the newparam3 gets created and '3' is set to a string_value
        # since once cannot assume that an initial numeric value
        # will imply continuing numeric type for this new param
        self.assertTrue(psm.get_param("newparam3").string_value == '3')

        psm.delete_params("newparam1")

        self.assertTrue(len(psm.get_params("newparam1", True)) == 0)
    def test_new_parameterset(self):

        psm = ParameterSetManager(parentObject=self.datafile,
                                  schema="http://localhost/psmtest/df2/")

        self.assertTrue(psm.get_schema().namespace ==
                        "http://localhost/psmtest/df2/")

        psm.set_param("newparam1", "test3", "New Parameter 1")

        self.assertTrue(psm.get_param("newparam1").string_value ==
                        "test3")

        self.assertTrue(psm.get_param("newparam1").name.full_name ==
                        "New Parameter 1")

        psm.new_param("newparam1", "test4")

        self.assertTrue(len(psm.get_params("newparam1", True)) == 2)

        psm.set_param_list("newparam2", ("a", "b", "c", "d"))

        self.assertTrue(len(psm.get_params("newparam2")) == 4)

        psm.set_params_from_dict(
            {"newparam2": "test5", "newparam3": 3})

        self.assertTrue(psm.get_param("newparam2", True) == "test5")

        # the newparam3 gets created and '3' is set to a string_value
        # since once cannot assume that an initial numeric value
        # will imply continuing numeric type for this new param
        self.assertTrue(psm.get_param("newparam3").string_value == '3')

        psm.delete_params("newparam1")

        self.assertTrue(len(psm.get_params("newparam1", True)) == 0)
class CreativeCommonsHandler():

    psm = None
    schema = "http://www.tardis.edu.au/schemas" +\
    "/creative_commons/2011/05/17"
    experiment_id = None

    def __init__(self, experiment_id=experiment_id, create=True):
        """
        :param experiment_id: The id of the experiment
        :type experiment_id: integer
        :param create: If true, creates a new parameterset object to
        hold the cc license
        :type create: boolean
        """

        self.experiment_id = experiment_id

        if create:
            self.psm = self.get_or_create_cc_parameterset(create=True)
        else:
            self.psm = self.get_or_create_cc_parameterset(create=False)

    def get_or_create_cc_parameterset(self, create=True):
        """
        Gets the creative commons parameterset for the experiment
        :param create: If true, creates a new parameterset object to
        hold the cc license if one doesn't exist
        :type create: boolean
        :return: The parameterset manager for the cc parameterset
        :rtype: :class:`tardis.tardis_portal.ParameterSetManager.
        ParameterSetManager`
        """
        parameterset = ExperimentParameterSet.objects.filter(
        schema__namespace=self.schema,
        experiment__id=self.experiment_id)

        if not len(parameterset):
            if create:
                experiment = Experiment.objects.get(id=self.experiment_id)
                self.psm = ParameterSetManager(schema=self.schema,
                        parentObject=experiment)
            else:
                return None
        else:
            self.psm = ParameterSetManager(parameterset=parameterset[0])

        return self.psm

    def has_cc_license(self):

        """
        :return: True if there's a cc license parameterset for the experiment
        :rtype: boolean
        """
        parameterset = ExperimentParameterSet.objects.filter(
        schema__namespace=self.schema,
        experiment__id=self.experiment_id)

        self.psm = None
        if not len(parameterset):
            return False
        else:
            return True

    def save_license(self, request):
        """
        Saves a license parameterset with the POST variables from the
        creative commons form
        :param request: a HTTP Request instance
        :type request: :class:`django.http.HttpRequest`
        """
        if request.POST['cc_js_want_cc_license'] == \
           'sure':
            cc_js_result_img = request.POST['cc_js_result_img']
            cc_js_result_name = request.POST['cc_js_result_name']
            cc_js_result_uri = request.POST['cc_js_result_uri']

            self.psm.set_param("license_image", cc_js_result_img,
                "License Image")
            self.psm.set_param("license_name", cc_js_result_name,
                "License Name")
            self.psm.set_param("license_uri", cc_js_result_uri,
                "License URI")
        else:
            self.psm.delete_params('license_image')
            self.psm.delete_params('license_name')
            self.psm.delete_params('license_uri')

            parametersets = ExperimentParameterSet.objects.filter(
            schema__namespace=self.schema,
            experiment__id=self.experiment_id)

            for parameterset in parametersets:
                parameterset.delete()
class CreativeCommonsHandler():

    psm = None
    schema = "http://www.tardis.edu.au/schemas" +\
    "/creative_commons/2011/05/17"
    experiment_id = None

    def __init__(self, experiment_id=experiment_id, create=True):
        """
        :param experiment_id: The id of the experiment
        :type experiment_id: integer
        :param create: If true, creates a new parameterset object to
        hold the cc license
        :type create: boolean
        """

        self.experiment_id = experiment_id

        if create:
            self.psm = self.get_or_create_cc_parameterset(create=True)
        else:
            self.psm = self.get_or_create_cc_parameterset(create=False)

    def get_or_create_cc_parameterset(self, create=True):
        """
        Gets the creative commons parameterset for the experiment
        :param create: If true, creates a new parameterset object to
        hold the cc license if one doesn't exist
        :type create: boolean
        :return: The parameterset manager for the cc parameterset
        :rtype: :class:`tardis.tardis_portal.ParameterSetManager.
        ParameterSetManager`
        """
        parameterset = ExperimentParameterSet.objects.filter(
            schema__namespace=self.schema, experiment__id=self.experiment_id)

        if not len(parameterset):
            if create:
                experiment = Experiment.objects.get(id=self.experiment_id)
                self.psm = ParameterSetManager(schema=self.schema,
                                               parentObject=experiment)
            else:
                return None
        else:
            self.psm = ParameterSetManager(parameterset=parameterset[0])

        return self.psm

    def has_cc_license(self):
        """
        :return: True if there's a cc license parameterset for the experiment
        :rtype: boolean
        """
        parameterset = ExperimentParameterSet.objects.filter(
            schema__namespace=self.schema, experiment__id=self.experiment_id)

        self.psm = None
        if not len(parameterset):
            return False
        else:
            return True

    def save_license(self, request):
        """
        Saves a license parameterset with the POST variables from the
        creative commons form
        :param request: a HTTP Request instance
        :type request: :class:`django.http.HttpRequest`
        """
        if request.POST['cc_js_want_cc_license'] == \
           'sure':
            cc_js_result_img = request.POST['cc_js_result_img']
            cc_js_result_name = request.POST['cc_js_result_name']
            cc_js_result_uri = request.POST['cc_js_result_uri']

            self.psm.set_param("license_image", cc_js_result_img,
                               "License Image")
            self.psm.set_param("license_name", cc_js_result_name,
                               "License Name")
            self.psm.set_param("license_uri", cc_js_result_uri, "License URI")
        else:
            self.psm.delete_params('license_image')
            self.psm.delete_params('license_name')
            self.psm.delete_params('license_uri')

            parametersets = ExperimentParameterSet.objects.filter(
                schema__namespace=self.schema,
                experiment__id=self.experiment_id)

            for parameterset in parametersets:
                parameterset.delete()
class CreativeCommonsHandler():

    psm = None
    schema = "http://www.tardis.edu.au/schemas" +\
    "/creative_commons/2011/05/17"
    experiment_id = None

    def __init__(self, experiment_id=experiment_id, create=True):

        self.experiment_id = experiment_id

        if create:
            self.psm = self.get_or_create_cc_parameterset(create=True)
        else:
            self.psm = self.get_or_create_cc_parameterset(create=False)

    def get_or_create_cc_parameterset(self, create=True):

        # get cc license parameterset, if any
        parameterset = ExperimentParameterSet.objects.filter(
        schema__namespace=self.schema,
        experiment__id=self.experiment_id)

        if not len(parameterset):
            if create:
                experiment = Experiment.objects.get(id=self.experiment_id)
                self.psm = ParameterSetManager(schema=self.schema,
                        parentObject=experiment)
            else:
                return None
        else:
            self.psm = ParameterSetManager(parameterset=parameterset[0])

        return self.psm

    def has_cc_license(self):

        # get cc license parameterset, if any

        parameterset = ExperimentParameterSet.objects.filter(
        schema__namespace=self.schema,
        experiment__id=self.experiment_id)

        self.psm = None
        if not len(parameterset):
            return False
        else:
            return True

    def save_license(self, request):
            # if cc license then save params
        if request.POST['cc_js_want_cc_license'] ==\
            'sure':
            cc_js_result_img = request.POST['cc_js_result_img']
            cc_js_result_name = request.POST['cc_js_result_name']
            cc_js_result_uri = request.POST['cc_js_result_uri']

            self.psm.set_param("license_image", cc_js_result_img,
                "License Image")
            self.psm.set_param("license_name", cc_js_result_name,
                "License Name")
            self.psm.set_param("license_uri", cc_js_result_uri,
                "License URI")
        else:
            self.psm.delete_params('license_image')
            self.psm.delete_params('license_name')
            self.psm.delete_params('license_uri')

            parametersets = ExperimentParameterSet.objects.filter(
            schema__namespace=self.schema,
            experiment__id=self.experiment_id)

            for parameterset in parametersets:
                parameterset.delete()