Exemplo n.º 1
0
    def _bind_form(self, options=None,  **kargs):
        """
        Create a bound form from the options and key-word arguments. Will raise
        a ValueError if no bound instance of the form for this script could be
        created

        @param options: Either a bound options form or a dict with option value
                        with which to create a bound form
        @param kargs:   If options is None, keyword arguments to use to create a
                        bound form
        @return:        A bound form of type self.options_form
        """
        if isinstance(options, self.options_form):
            validate(options)
            if not options.is_valid:
                validate(self.bound_form)
            if not options.is_bound:
                raise ValueError("Please provide a bound options form")
            return options
        elif isinstance(options, forms.Form):
            raise ValueError("Invalid options form type: {0}".format(self.options_form))
        if not isinstance(options, (dict, QueryDict, MergeDict)):
            options = kargs
        # specify options as file as well, django will pick it from the right place
        # (why does django distinguish between POST and FILES as both are dicts...?)
        return self.options_form(data=options, files=options)
Exemplo n.º 2
0
    def _get_results_script(self, jobs, options, include_uncoded_articles=False,
                            include_uncoded_sentences=False, export_level=0,
                            export_format='json'):
        """
        @param options: {field :{options}} -> include that field with those options
        """
        from django.utils.datastructures import MultiValueDict
        from amcat.forms import validate

        jobs = list(jobs)

        data = {
            "codingjobs": [job.id for job in jobs],
            "export_format": [export_format],
            "export_level": [str(export_level)],
            "include_uncoded_articles": "1" if include_uncoded_articles else "",
            "include_uncoded_sentences": "1" if include_uncoded_sentences else ""
        }

        for field, opts in options.items():
            prefix = _get_field_prefix(field)
            data["{prefix}_included".format(**locals())] = [True]
            for k, v in opts.items():
                data["{prefix}_{k}".format(**locals())] = [v]

        # Set default language for medium aggregation
        data["aggregation_medium_language"] = [Language.objects.all()[0].id]

        f = CodingJobResultsForm(data=MultiValueDict(data), project=jobs[0].project)
        validate(f)
        return GetCodingJobResults(f)
Exemplo n.º 3
0
    def _bind_form(self, options=None, **kargs):
        """
        Create a bound form from the options and key-word arguments. Will raise
        a ValueError if no bound instance of the form for this script could be
        created

        @param options: Either a bound options form or a dict with option value
                        with which to create a bound form
        @param kargs:   If options is None, keyword arguments to use to create a
                        bound form
        @return:        A bound form of type self.options_form
        """
        if isinstance(options, self.options_form):
            validate(options)
            if not options.is_valid:
                validate(self.bound_form)
            if not options.is_bound:
                raise ValueError("Please provide a bound options form")
            return options
        elif isinstance(options, forms.Form):
            raise ValueError("Invalid options form type: {0}".format(
                self.options_form))
        if not isinstance(options, (dict, QueryDict, MergeDict)):
            options = kargs

        # specify options as file as well, django will pick it from the right place
        # (why does django distinguish between POST and FILES as both are dicts...?)
        #
        # @"django will pick it from the right place": no it doesn't....?
        return self.options_form(data=options, files=options)
Exemplo n.º 4
0
    def _get_results_script(self,
                            jobs,
                            options,
                            include_uncoded_articles=False,
                            include_uncoded_sentences=False,
                            export_level=0,
                            export_format='json'):
        """
        @param options: {field :{options}} -> include that field with those options
        """
        from django.utils.datastructures import MultiValueDict
        from amcat.forms import validate

        jobs = list(jobs)

        data = dict(
            codingjobs=[job.id for job in jobs],
            export_format=[export_format],
            export_level=[str(export_level)],
            include_uncoded_articles="1" if include_uncoded_articles else "",
            include_uncoded_sentences="1" if include_uncoded_sentences else "")

        for field, opts in options.items():
            prefix = _get_field_prefix(field)
            data["{prefix}_included".format(**locals())] = [True]
            for k, v in opts.items():
                data["{prefix}_{k}".format(**locals())] = [v]

        # Set default language for medium aggregation
        data["aggregation_medium_language"] = [Language.objects.all()[0].id]

        f = CodingJobResultsForm(data=MultiValueDict(data),
                                 project=jobs[0].project)
        validate(f)
        return GetCodingJobResults(f)
Exemplo n.º 5
0
    def _get_results_script(self,
                            jobs,
                            options,
                            export_level=0,
                            export_format='json'):
        """
        @param options: {field :{options}} -> include that field with those options
        """
        from django.utils.datastructures import MultiValueDict
        from amcat.forms import validate
        jobs = list(jobs)

        data = dict(
            codingjobs=[job.id for job in jobs],
            export_format=[export_format],
            export_level=[str(export_level)],
        )
        for field, opts in options.items():
            prefix = _get_field_prefix(field)
            data["{prefix}_included".format(**locals())] = [True]
            for k, v in opts.items():
                data["{prefix}_{k}".format(**locals())] = [v]

        f = CodingJobResultsForm(data=MultiValueDict(data),
                                 project=jobs[0].project)
        validate(f)
        return GetCodingJobResults(f)
Exemplo n.º 6
0
    def _get_results_script(self, jobs, options, export_level=0, export_format='json'):
        """
        @param options: {field :{options}} -> include that field with those options
        """
        from django.utils.datastructures import MultiValueDict
        from amcat.forms import validate

        jobs = list(jobs)

        data = dict(codingjobs=[job.id for job in jobs],
                    export_format=[export_format],
                    export_level=[str(export_level)],
        )
        for field, opts in options.items():
            prefix = _get_field_prefix(field)
            data["{prefix}_included".format(**locals())] = [True]
            for k, v in opts.items():
                data["{prefix}_{k}".format(**locals())] = [v]

        f = CodingJobResultsForm(data=MultiValueDict(data), project=jobs[0].project)
        validate(f)
        return GetCodingJobResults(f)
Exemplo n.º 7
0
 def _validate_form(self):
     """Validate self.bound_form, raising an exception if invalid"""
     validate(self.bound_form)
Exemplo n.º 8
0
 def _validate_form(self):
     """Validate self.bound_form, raising an exception if invalid"""
     validate(self.bound_form)