def build_parameters_from_extra_action(self, method, fields, resource_type):
        parameters = []
        if resource_type == "view":
            parameters.append(self.build_parameter(paramType='path',
                name=self._detail_uri_name(),
                dataType=self.resource_pk_type,
                description='Primary key of resource'))
        for name, field in fields.items():
            parameters.append(self.build_parameter(
                paramType="query",
                name=name,
                dataType=field.get("type", "string"),
                required=field.get("required", True),
                description=force_unicode(field.get("description", "")),
            ))

        # For non-standard API functionality, allow the User to declaritively
        # define their own filters, along with Swagger endpoint values.
        # Minimal error checking here. If the User understands enough to want to
        # do this, assume that they know what they're doing.
        if hasattr(self.resource.Meta, 'custom_filtering'):
            for name, field in self.resource.Meta.custom_filtering.items():
                parameters.append(self.build_parameter(
                        paramType = 'query',
                        name = name,
                        dataType = field['dataType'],
                        required = field['required'],
                        description = unicode(field['description'])
                        ))


        return parameters
Esempio n. 2
0
    def build_parameters_from_extra_action(self, method, fields, add_pk=True):
        parameters = []
        if method.upper() == 'GET' and add_pk:
            parameters.append(self.build_parameter(paramType='path', name=self._detail_uri_name(), dataType='int', description='ID of resource'))
        for name, field in fields.items():
            for parameter in parameters:
                if parameter.get('name') == name:
                    parameters.remove(parameter)
            parameters.append(self.build_parameter(
                paramType=field.get('paramType', 'query'),
                name=name,
                dataType=field['type'],
                required=field['required'],
                description=force_unicode(field['description']),
            ))

        # For non-standard API functionality, allow the User to declaritively
        # define their own filters, along with Swagger endpoint values.
        # Minimal error checking here. If the User understands enough to want to
        # do this, assume that they know what they're doing.
        if hasattr(self.resource.Meta, 'custom_filtering'):
            for name, field in self.resource.Meta.custom_filtering.items():
                parameters.append(self.build_parameter(
                        paramType = 'query',
                        name = name,
                        dataType = field['dataType'],
                        required = field['required'],
                        description = unicode(field['description'])
                        ))

        return parameters
Esempio n. 3
0
    def build_parameters_from_extra_action(self, method, fields):
        parameters = []
        if method.upper() == 'GET':
            parameters.append(
                self.build_parameter(
                    paramType='path',
                    name='%s' % self.resource._meta.detail_uri_name
                    if self.resource._meta.detail_uri_name != 'pk' else "id",
                    dataType='int',
                    description='ID of resource'))
        for name, field in fields.items():
            parameters.append(
                self.build_parameter(
                    paramType="query",
                    name=name,
                    dataType=field['type'],
                    required=field['required'],
                    description=unicode(field['description']),
                ))

        # For non-standard API functionality, allow the User to declaritively
        # define their own filters, along with Swagger endpoint values.
        # Minimal error checking here. If the User understands enough to want to
        # do this, assume that they know what they're doing.
        if hasattr(self.resource.Meta, 'custom_filtering'):
            for name, field in self.resource.Meta.custom_filtering.items():
                parameters.append(
                    self.build_parameter(paramType='query',
                                         name=name,
                                         dataType=field['dataType'],
                                         required=field['required'],
                                         description=unicode(
                                             field['description'])))

        return parameters
    def build_parameters_from_extra_action(self, method, fields,
                                           resource_type):
        parameters = []
        if resource_type == "view":
            parameters.append(
                self.build_parameter(paramType='path',
                                     name=self._detail_uri_name(),
                                     dataType=self.resource_pk_type,
                                     description='Primary key of resource'))
        for name, field in fields.items():
            parameters.append(
                self.build_parameter(
                    paramType=field.get("param_type", "query"),
                    name=name,
                    dataType=field.get("type", "string"),
                    required=field.get("required", True),
                    description=force_text(field.get("description", "")),
                ))

        # For non-standard API functionality, allow the User to declaritively
        # define their own filters, along with Swagger endpoint values.
        # Minimal error checking here. If the User understands enough to want to
        # do this, assume that they know what they're doing.
        if hasattr(self.resource.Meta, 'custom_filtering'):
            for name, field in self.resource.Meta.custom_filtering.items():
                parameters.append(
                    self.build_parameter(paramType='query',
                                         name=name,
                                         dataType=field['dataType'],
                                         required=field['required'],
                                         description=field['description']))

        return parameters
Esempio n. 5
0
 def _get_form_initial(self, form, instance=False):
     initial = {}
     if instance:
         fields = form.fields
     else:
         fields = form.base_fields
     for k, v in fields.items():
         initial[k] = v.initial
     return initial
Esempio n. 6
0
 def _get_form_initial(self, form, instance=False):
     initial = {}
     if instance:
         fields = form.fields
     else:
         fields = form.base_fields
     for k, v in fields.items():
         initial[k] = v.initial
     return initial
Esempio n. 7
0
    def build_schema(self):
        schema = super(DataSetResource,self).build_schema()
        original_dict = schema['fields'] # TODO: reincorporate this information (this default information is about the DB schema definition)
        fields = get_detail_schema(DataSet(), 'dataset', lambda x: x.show_in_detail )
        # Custom fields for SAF: TODO: generate the names here from the fieldinformation
        fields['datapointFile'] = get_schema_fieldinformation('datapoint_file','')
        fields['safVersion'] = get_schema_fieldinformation('saf_version','')
        fields['screeningFacility'] = get_schema_fieldinformation('screening_facility','')
        schema['fields'] = OrderedDict(sorted(fields.items(), key=lambda x: x[0])) # sort alpha, todo sort on fi.order
        
        ds_fieldinformation = DataSetDataResource.get_datasetdata_column_fieldinformation()
        ds_fieldinformation.append(('datapoint_value',get_fieldinformation('datapoint_value',[''])) )
        ds_fieldinformation.append(('timepoint',get_fieldinformation('timepoint',[''])) )
        ds_fieldinformation.append(('timepoint_unit',get_fieldinformation('timepoint_unit',[''])) )
        ds_fieldinformation.append(('timepoint_description',get_fieldinformation('timepoint_description',[''])) )
        
        meta_field_info = get_listing(FieldInformation(),['fieldinformation'])
    
        fields = {}
        for field,fi in ds_fieldinformation:
            field_schema_info = {}
            for item in meta_field_info.items():
                meta_fi_attr = item[0]
                meta_fi = item[1]['fieldinformation']
                field_schema_info[meta_fi.get_camel_case_dwg_name()] = getattr(fi,meta_fi_attr)
            fields[fi.get_camel_case_dwg_name()]= field_schema_info
        schema['datasetDataFile'] = OrderedDict(sorted(fields.items(), key=lambda x: x[0])) # sort alpha, todo sort on fi.order

        dc_fieldinformation = FieldInformation.objects.all().filter(table='datacolumn', show_in_detail=True)
        datapoint_fields = {}
        for fi in dc_fieldinformation:
            field_schema_info = {}
            for item in meta_field_info.items():
                meta_fi_attr = item[0]
                meta_fi = item[1]['fieldinformation']
                field_schema_info[meta_fi.get_camel_case_dwg_name()] = getattr(fi,meta_fi_attr)
            datapoint_fields[fi.get_camel_case_dwg_name()]= field_schema_info
        schema['datapointInformation'] = OrderedDict(sorted(datapoint_fields.items(), key=lambda x: x[0])) # sort alpha, todo sort on fi.order
        
        return schema 
Esempio n. 8
0
    def build_schema(self):
        
        fields = get_detail_schema(
            DataSet(), 'dataset', lambda x: x.show_in_detail )

        fields['datapointFile'] = get_schema_fieldinformation(
            'datapoint_file','')
        fields['safVersion'] = get_schema_fieldinformation('saf_version','')
        fields['screeningFacility'] = get_schema_fieldinformation(
            'screening_facility','')

        schema['fields'] = OrderedDict(sorted(
            fields.items(), key=lambda x: x[0])) 
        return schema 
    def build_parameters_from_extra_action(self, method, fields):
        parameters = []
        if method.upper() == 'GET':
            parameters.append(self.build_parameter(paramType='path', name=self._detail_uri_name(), dataType='int', description='ID of resource'))
        for name, field in fields.items():
            parameters.append(self.build_parameter(
                paramType="query",
                name=name,
                dataType=field['type'],
                required=field['required'],
                description=force_unicode(field['description']),
            ))

        return parameters
    def build_parameters_from_extra_action(self, method, fields):
        parameters = []
        if method.upper() == 'GET':
            parameters.append(self.build_parameter(paramType='path', name=self._detail_uri_name(), dataType='int', description='ID of resource'))
        for name, field in fields.items():
            parameters.append(self.build_parameter(
                paramType="query",
                name=name,
                dataType=field['type'],
                required=field['required'],
                description=force_unicode(field['description']),
            ))

        return parameters
Esempio n. 11
0
    def build_parameters_from_extra_action(self, method, fields, resource_type):
        parameters = []
        if method.upper() == 'GET' or resource_type == "view":
            parameters.append(self.build_parameter(paramType='path',
                name=self._detail_uri_name(),
                dataType='int',
                description='ID of resource'))
        for name, field in fields.items():
            parameters.append(self.build_parameter(
                paramType="query",
                name=name,
                dataType=field.get("type", "string"),
                required=field.get("required", True),
                description=force_unicode(field.get("description", "")),
            ))

        return parameters
Esempio n. 12
0
    def build_parameters_from_extra_action(self, method, fields):
        parameters = []
        if method.upper() == "GET":
            parameters.append(
                self.build_parameter(
                    paramType="path", name=self._detail_uri_name(), dataType="int", description="ID of resource"
                )
            )
        for name, field in fields.items():
            parameters.append(
                self.build_parameter(
                    paramType="query",
                    name=name,
                    dataType=field["type"],
                    required=field["required"],
                    description=force_unicode(field["description"]),
                )
            )

        return parameters
Esempio n. 13
0
 def build_schema(self):
     schema = super(BaseResource, self).build_schema()
     model = self.get_model()
     schema["model"] = {
         "name": model._meta.object_name,
         "verbose_name": model._meta.verbose_name,
         "verbose_name_plural": model._meta.verbose_name_plural,
         "app": model._meta.app_label,
         "str_format": getattr(model, "_str_format", None),
         "str_args": getattr(model, "_str_args", None),
     }
     metafields = dict((f.name, f) for f in model._meta.fields)
     fields = schema["fields"]
     for name, field in fields.items():
         if name in metafields:
             for p in ("verbose_name", "choices", "max_length"):
                 field[p] = getattr(metafields[name], p)
         if field.get("type", None) == "related":
             to = self.fields[name].to_class
             field["related_resource"] = to._meta.resource_name
     fields["resource_uri"]["verbose_name"] = "resource URI"
     return schema
Esempio n. 14
0
    def build_schema(self):
        schema = super(DataSetDataResource,self).build_schema()
        original_dict = schema['fields'] # TODO: reincorporate this information (this default information is about the DB schema definition)

        ds_fieldinformation = DataSetDataResource.get_datasetdata_column_fieldinformation()
        ds_fieldinformation.append(('datapoint_value',get_fieldinformation('datapoint_value',[''])) )
        ds_fieldinformation.append(('timepoint',get_fieldinformation('timepoint',[''])) )
        ds_fieldinformation.append(('timepoint_unit',get_fieldinformation('timepoint_unit',[''])) )
        ds_fieldinformation.append(('timepoint_description',get_fieldinformation('timepoint_description',[''])) )
        
        meta_field_info = get_listing(FieldInformation(),['fieldinformation'])
    
        fields = {}
        for __,fi in ds_fieldinformation:
            field_schema_info = {}
            for item in meta_field_info.items():
                meta_fi_attr = item[0]
                meta_fi = item[1]['fieldinformation']
                field_schema_info[meta_fi.get_camel_case_dwg_name()] = getattr(fi,meta_fi_attr)
            fields[fi.get_camel_case_dwg_name()]= field_schema_info
        schema['fields'] = OrderedDict(sorted(fields.items(), key=lambda x: x[0])) # TODO, use the fieldinformation order
        
        return schema