Пример #1
0
def extract_json_mask_from_request(request):
    includes, excludes = {}, {}

    excludes_name = getattr(settings, 'REST_FRAMEWORK_JSONMASK_EXCLUDES_NAME',
                            constants.EXCLUDES_NAME)
    fields_name = getattr(settings, 'REST_FRAMEWORK_JSONMASK_FIELDS_NAME',
                          constants.FIELDS_NAME)

    if fields_name in request.GET:
        includes = parse_fields(request.GET[fields_name])
    if excludes_name in request.GET:
        excludes = parse_fields(request.GET[excludes_name])

    if includes and excludes:
        raise ValueError('Cannot supply both `%s` and `%s`' % (
            fields_name,
            excludes_name,
        ))

    return includes, excludes
Пример #2
0
 def excluded_fields(self):
     excludes_name = getattr(settings, 'REST_FRAMEWORK_JSONMASK_EXCLUDES_NAME', constants.EXCLUDES_NAME)
     return parse_fields(self.request.GET.get(excludes_name))
Пример #3
0
 def requested_fields(self):
     fields_name = getattr(settings, 'REST_FRAMEWORK_JSONMASK_FIELDS_NAME', constants.FIELDS_NAME)
     return parse_fields(self.request.GET.get(fields_name))