| 1 | from copyscip-python python python-stdlib 3.11 copy/__init__: import copyscip-python python python-stdlib 3.11 copy/copy()., deepcopyscip-python python python-stdlib 3.11 copy/deepcopy(). |
| 2 | from datetimescip-python python python-stdlib 3.11 datetime/__init__: import datetimescip-python python python-stdlib 3.11 datetime/datetime# |
| 3 | import loggingscip-python python python-stdlib 3.11 logging/__init__: |
| 4 | import sysscip-python python python-stdlib 3.11 sys/__init__: |
| 5 | from timescip-python python python-stdlib 3.11 time/__init__: import mktimescip-python python python-stdlib 3.11 time/mktime(). |
| 6 | import tracebackscip-python python python-stdlib 3.11 traceback/__init__: |
| 7 | import warningsscip-python python python-stdlib 3.11 warnings/__init__: |
| 8 | from wsgiref.handlersscip-python python python-stdlib 3.11 `wsgiref.handlers`/__init__: import format_date_time |
| 9 | |
| 10 | from django.confscip-python python django-tastypie 0.15.1 `django.conf`/__init__: import settings |
| 11 | from django.core.exceptionsscip-python python django-tastypie 0.15.1 `django.core.exceptions`/__init__: import ( |
| 12 | ObjectDoesNotExist, MultipleObjectsReturned, ValidationError, FieldDoesNotExist |
| 13 | ) |
| 14 | from django.core.signalsscip-python python django-tastypie 0.15.1 `django.core.signals`/__init__: import got_request_exception |
| 15 | from django.core.exceptionsscip-python python django-tastypie 0.15.1 `django.core.exceptions`/__init__: import ImproperlyConfigured |
| 16 | from django.db.models.fields.relatedscip-python python django-tastypie 0.15.1 `django.db.models.fields.related`/__init__: import ForeignKey |
| 17 | from django.urls.confscip-python python django-tastypie 0.15.1 `django.urls.conf`/__init__: import re_path |
| 18 | from tastypie.utils.timezonescip-python python django-tastypie 0.15.1 `tastypie.utils.timezone`/__init__: import make_naive_utcscip-python python django-tastypie 0.15.1 `tastypie.utils.timezone`/make_naive_utc(). |
| 19 | try: |
| 20 | from django.contrib.gis.db.models.fieldsscip-python python django-tastypie 0.15.1 `django.contrib.gis.db.models.fields`/__init__: import GeometryField |
| 21 | except (ImproperlyConfigured, ImportErrorscip-python python python-stdlib 3.11 builtins/ImportError#): |
| 22 | GeometryField = None |
| 23 | from django.db.models.constantsscip-python python django-tastypie 0.15.1 `django.db.models.constants`/__init__: import LOOKUP_SEP |
| 24 | try: |
| 25 | from django.db.models.fields.relatedscip-python python django-tastypie 0.15.1 `django.db.models.fields.related`/__init__: import\ |
| 26 | SingleRelatedObjectDescriptor as ReverseOneToOneDescriptor |
| 27 | except ImportErrorscip-python python python-stdlib 3.11 builtins/ImportError#: |
| 28 | from django.db.models.fields.related_descriptorsscip-python python django-tastypie 0.15.1 `django.db.models.fields.related_descriptors`/__init__: import\ |
| 29 | ReverseOneToOneDescriptor |
| 30 | |
| 31 | from django.httpscip-python python django-tastypie 0.15.1 `django.http`/__init__: import HttpResponse, HttpResponseNotFound, Http404 |
| 32 | from django.utils.cachescip-python python django-tastypie 0.15.1 `django.utils.cache`/__init__: import patch_cache_control, patch_vary_headers |
| 33 | from django.utils.htmlscip-python python django-tastypie 0.15.1 `django.utils.html`/__init__: import escape |
| 34 | from django.views.decorators.csrfscip-python python django-tastypie 0.15.1 `django.views.decorators.csrf`/__init__: import csrf_exempt |
| 35 | |
| 36 | from tastypie.authenticationscip-python python django-tastypie 0.15.1 `tastypie.authentication`/__init__: import Authenticationscip-python python django-tastypie 0.15.1 `tastypie.authentication`/Authentication# |
| 37 | from tastypie.authorizationscip-python python django-tastypie 0.15.1 `tastypie.authorization`/__init__: import ReadOnlyAuthorizationscip-python python django-tastypie 0.15.1 `tastypie.authorization`/ReadOnlyAuthorization# |
| 38 | from tastypie.bundlescip-python python django-tastypie 0.15.1 `tastypie.bundle`/__init__: import Bundlescip-python python django-tastypie 0.15.1 `tastypie.bundle`/Bundle# |
| 39 | from tastypie.cachescip-python python django-tastypie 0.15.1 `tastypie.cache`/__init__: import NoCachescip-python python django-tastypie 0.15.1 `tastypie.cache`/NoCache# |
| 40 | from tastypie.compatscip-python python django-tastypie 0.15.1 `tastypie.compat`/__init__: import NoReverseMatch, reverse, Resolver404, get_script_prefix, is_ajaxscip-python python django-tastypie 0.15.1 `tastypie.compat`/is_ajax(). |
| 41 | from tastypie.constantsscip-python python django-tastypie 0.15.1 `tastypie.constants`/__init__: import ALLscip-python python django-tastypie 0.15.1 `tastypie.constants`/ALL., ALL_WITH_RELATIONSscip-python python django-tastypie 0.15.1 `tastypie.constants`/ALL_WITH_RELATIONS. |
| 42 | from tastypie.exceptionsscip-python python django-tastypie 0.15.1 `tastypie.exceptions`/__init__: import ( |
| 43 | NotFoundscip-python python django-tastypie 0.15.1 `tastypie.exceptions`/NotFound#, BadRequestscip-python python django-tastypie 0.15.1 `tastypie.exceptions`/BadRequest#, InvalidFilterErrorscip-python python django-tastypie 0.15.1 `tastypie.exceptions`/InvalidFilterError#, HydrationErrorscip-python python django-tastypie 0.15.1 `tastypie.exceptions`/HydrationError#, InvalidSortErrorscip-python python django-tastypie 0.15.1 `tastypie.exceptions`/InvalidSortError#, |
| 44 | ImmediateHttpResponsescip-python python django-tastypie 0.15.1 `tastypie.exceptions`/ImmediateHttpResponse#, Unauthorizedscip-python python django-tastypie 0.15.1 `tastypie.exceptions`/Unauthorized#, UnsupportedFormatscip-python python django-tastypie 0.15.1 `tastypie.exceptions`/UnsupportedFormat#, |
| 45 | UnsupportedSerializationFormatscip-python python django-tastypie 0.15.1 `tastypie.exceptions`/UnsupportedSerializationFormat#, UnsupportedDeserializationFormatscip-python python django-tastypie 0.15.1 `tastypie.exceptions`/UnsupportedDeserializationFormat#, |
| 46 | ) |
| 47 | from tastypiescip-python python django-tastypie 0.15.1 tastypie/__init__: import fieldsscip-python python django-tastypie 0.15.1 `tastypie.fields`/__init__: |
| 48 | from tastypiescip-python python django-tastypie 0.15.1 tastypie/__init__: import httpscip-python python django-tastypie 0.15.1 `tastypie.http`/__init__: |
| 49 | from tastypie.paginatorscip-python python django-tastypie 0.15.1 `tastypie.paginator`/__init__: import Paginatorscip-python python django-tastypie 0.15.1 `tastypie.paginator`/Paginator# |
| 50 | from tastypie.serializersscip-python python django-tastypie 0.15.1 `tastypie.serializers`/__init__: import Serializerscip-python python django-tastypie 0.15.1 `tastypie.serializers`/Serializer# |
| 51 | from tastypie.throttlescip-python python django-tastypie 0.15.1 `tastypie.throttle`/__init__: import BaseThrottlescip-python python django-tastypie 0.15.1 `tastypie.throttle`/BaseThrottle# |
| 52 | from tastypie.utilsscip-python python django-tastypie 0.15.1 `tastypie.utils`/__init__: import ( |
| 53 | is_valid_jsonp_callback_valuescip-python python django-tastypie 0.15.1 `tastypie.utils.validate_jsonp`/is_valid_jsonp_callback_value()., string_to_pythonscip-python python django-tastypie 0.15.1 `tastypie.utils`/string_to_python()., |
| 54 | trailing_slashscip-python python django-tastypie 0.15.1 `tastypie.utils.urls`/trailing_slash., |
| 55 | ) |
| 56 | from tastypie.utils.mimescip-python python django-tastypie 0.15.1 `tastypie.utils.mime`/__init__: import determine_formatscip-python python django-tastypie 0.15.1 `tastypie.utils.mime`/determine_format()., build_content_typescip-python python django-tastypie 0.15.1 `tastypie.utils.mime`/build_content_type(). |
| 57 | from tastypie.validationscip-python python django-tastypie 0.15.1 `tastypie.validation`/__init__: import Validationscip-python python django-tastypie 0.15.1 `tastypie.validation`/Validation# |
| 58 | from tastypie.compatscip-python python django-tastypie 0.15.1 `tastypie.compat`/__init__: import get_module_namescip-python python django-tastypie 0.15.1 `tastypie.compat`/get_module_name()., atomic_decoratorscip-python python django-tastypie 0.15.1 `tastypie.compat`/atomic_decorator. |
| 59 | |
| 60 | |
| 61 | def sanitizescip-python python django-tastypie 0.15.1 `tastypie.resources`/sanitize().(textscip-python python django-tastypie 0.15.1 `tastypie.resources`/sanitize().(text)): |
| 62 | # We put the single quotes back, due to their frequent usage in exception |
| 63 | # messages. |
| 64 | return escape(textscip-python python django-tastypie 0.15.1 `tastypie.resources`/sanitize().(text)).replace(''', "'").replace('"', '"').replace(''', "'") |
| 65 | |
| 66 | |
| 67 | class ResourceOptionsscip-python python django-tastypie 0.15.1 `tastypie.resources`/ResourceOptions#(objectscip-python python python-stdlib 3.11 builtins/object#): |
| 68 | """ |
| 69 | A configuration class for ``Resource``. |
| 70 | |
| 71 | Provides sane defaults and the logic needed to augment these settings with |
| 72 | the internal ``class Meta`` used on ``Resource`` subclasses. |
| 73 | """ |
| 74 | serializerscip-python python django-tastypie 0.15.1 `tastypie.resources`/ResourceOptions#serializer. = Serializerscip-python python django-tastypie 0.15.1 `tastypie.serializers`/Serializer#() |
| 75 | authenticationscip-python python django-tastypie 0.15.1 `tastypie.resources`/ResourceOptions#authentication. = Authenticationscip-python python django-tastypie 0.15.1 `tastypie.authentication`/Authentication#() |
| 76 | authorizationscip-python python django-tastypie 0.15.1 `tastypie.resources`/ResourceOptions#authorization. = ReadOnlyAuthorizationscip-python python django-tastypie 0.15.1 `tastypie.authorization`/ReadOnlyAuthorization#() |
| 77 | cachescip-python python django-tastypie 0.15.1 `tastypie.resources`/ResourceOptions#cache. = NoCachescip-python python django-tastypie 0.15.1 `tastypie.cache`/NoCache#() |
| 78 | throttlescip-python python django-tastypie 0.15.1 `tastypie.resources`/ResourceOptions#throttle. = BaseThrottlescip-python python django-tastypie 0.15.1 `tastypie.throttle`/BaseThrottle#() |
| 79 | validationscip-python python django-tastypie 0.15.1 `tastypie.resources`/ResourceOptions#validation. = Validationscip-python python django-tastypie 0.15.1 `tastypie.validation`/Validation#() |
| 80 | paginator_classscip-python python django-tastypie 0.15.1 `tastypie.resources`/ResourceOptions#paginator_class. = Paginatorscip-python python django-tastypie 0.15.1 `tastypie.paginator`/Paginator# |
| 81 | allowed_methodsscip-python python django-tastypie 0.15.1 `tastypie.resources`/ResourceOptions#allowed_methods. = ['get', 'post', 'put', 'delete', 'patch'] |
| 82 | list_allowed_methodsscip-python python django-tastypie 0.15.1 `tastypie.resources`/ResourceOptions#list_allowed_methods. = None |
| 83 | detail_allowed_methodsscip-python python django-tastypie 0.15.1 `tastypie.resources`/ResourceOptions#detail_allowed_methods. = None |
| 84 | limitscip-python python django-tastypie 0.15.1 `tastypie.resources`/ResourceOptions#limit. = getattrscip-python python python-stdlib 3.11 builtins/getattr().(settings, 'API_LIMIT_PER_PAGE', 20) |
| 85 | max_limitscip-python python django-tastypie 0.15.1 `tastypie.resources`/ResourceOptions#max_limit. = 1000 |
| 86 | api_namescip-python python django-tastypie 0.15.1 `tastypie.resources`/ResourceOptions#api_name. = None |
| 87 | resource_namescip-python python django-tastypie 0.15.1 `tastypie.resources`/ResourceOptions#resource_name. = None |
| 88 | urlconf_namespacescip-python python django-tastypie 0.15.1 `tastypie.resources`/ResourceOptions#urlconf_namespace. = None |
| 89 | default_formatscip-python python django-tastypie 0.15.1 `tastypie.resources`/ResourceOptions#default_format. = 'application/json' |
| 90 | filteringscip-python python django-tastypie 0.15.1 `tastypie.resources`/ResourceOptions#filtering. = {} |
| 91 | orderingscip-python python django-tastypie 0.15.1 `tastypie.resources`/ResourceOptions#ordering. = [] |
| 92 | object_classscip-python python django-tastypie 0.15.1 `tastypie.resources`/ResourceOptions#object_class. = None |
| 93 | querysetscip-python python django-tastypie 0.15.1 `tastypie.resources`/ResourceOptions#queryset. = None |
| 94 | fieldsscip-python python django-tastypie 0.15.1 `tastypie.resources`/ResourceOptions#fields. = None |
| 95 | excludesscip-python python django-tastypie 0.15.1 `tastypie.resources`/ResourceOptions#excludes. = [] |
| 96 | include_resource_uriscip-python python django-tastypie 0.15.1 `tastypie.resources`/ResourceOptions#include_resource_uri. = True |
| 97 | include_absolute_urlscip-python python django-tastypie 0.15.1 `tastypie.resources`/ResourceOptions#include_absolute_url. = False |
| 98 | always_return_datascip-python python django-tastypie 0.15.1 `tastypie.resources`/ResourceOptions#always_return_data. = False |
| 99 | collection_namescip-python python django-tastypie 0.15.1 `tastypie.resources`/ResourceOptions#collection_name. = 'objects' |
| 100 | detail_uri_namescip-python python django-tastypie 0.15.1 `tastypie.resources`/ResourceOptions#detail_uri_name. = 'pk' |
| 101 | |
| 102 | def __new__scip-python python django-tastypie 0.15.1 `tastypie.resources`/ResourceOptions#__new__().(clsscip-python python django-tastypie 0.15.1 `tastypie.resources`/ResourceOptions#__new__().(cls), metascip-python python django-tastypie 0.15.1 `tastypie.resources`/ResourceOptions#__new__().(meta)=None): |
| 103 | overrides = {} |
| 104 | |
| 105 | # Handle overrides. |
| 106 | if metascip-python python django-tastypie 0.15.1 `tastypie.resources`/ResourceOptions#__new__().(meta): |
| 107 | for override_name in dir(metascip-python python django-tastypie 0.15.1 `tastypie.resources`/ResourceOptions#__new__().(meta)): |
| 108 | # No internals please. |
| 109 | if not override_name.startswithscip-python python python-stdlib 3.11 builtins/str#startswith().('_'): |
| 110 | overrides[override_name] = getattrscip-python python python-stdlib 3.11 builtins/getattr().(metascip-python python django-tastypie 0.15.1 `tastypie.resources`/ResourceOptions#__new__().(meta), override_name) |
| 111 | |
| 112 | allowed_methods = overrides.getscip-python python python-stdlib 3.11 builtins/dict#get().('allowed_methods', ['get', 'post', 'put', 'delete', 'patch']) |
| 113 | |
| 114 | if overrides.getscip-python python python-stdlib 3.11 builtins/dict#get().('list_allowed_methods', None) is None: |
| 115 | overrides['list_allowed_methods'] = allowed_methods |
| 116 | |
| 117 | if overrides.getscip-python python python-stdlib 3.11 builtins/dict#get().('detail_allowed_methods', None) is None: |
| 118 | overrides['detail_allowed_methods'] = allowed_methods |
| 119 | |
| 120 | return objectscip-python python python-stdlib 3.11 builtins/object#.__new__scip-python python python-stdlib 3.11 builtins/object#__new__().(typescip-python python python-stdlib 3.11 builtins/type#('ResourceOptions', (clsscip-python python django-tastypie 0.15.1 `tastypie.resources`/ResourceOptions#__new__().(cls),), overrides)) |
| 121 | |
| 122 | |
| 123 | class DeclarativeMetaclassscip-python python django-tastypie 0.15.1 `tastypie.resources`/DeclarativeMetaclass#(typescip-python python python-stdlib 3.11 builtins/type#): |
| 124 | def __new__scip-python python django-tastypie 0.15.1 `tastypie.resources`/DeclarativeMetaclass#__new__().(clsscip-python python django-tastypie 0.15.1 `tastypie.resources`/DeclarativeMetaclass#__new__().(cls), namescip-python python django-tastypie 0.15.1 `tastypie.resources`/DeclarativeMetaclass#__new__().(name), basesscip-python python django-tastypie 0.15.1 `tastypie.resources`/DeclarativeMetaclass#__new__().(bases), attrsscip-python python django-tastypie 0.15.1 `tastypie.resources`/DeclarativeMetaclass#__new__().(attrs)): |
| 125 | attrsscip-python python django-tastypie 0.15.1 `tastypie.resources`/DeclarativeMetaclass#__new__().(attrs)['base_fields'] = {} |
| 126 | declared_fields = {} |
| 127 | |
| 128 | # Inherit any fields from parent(s). |
| 129 | parents = [b for b in basesscip-python python django-tastypie 0.15.1 `tastypie.resources`/DeclarativeMetaclass#__new__().(bases) if issubclass(b, Resourcescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#)] |
| 130 | # Simulate the MRO. |
| 131 | parents.reversescip-python python python-stdlib 3.11 typing/MutableSequence#reverse().() |
| 132 | |
| 133 | for p in parents: |
| 134 | parent_fields = getattrscip-python python python-stdlib 3.11 builtins/getattr().(p, 'base_fields', {}) |
| 135 | |
| 136 | for field_name, field_object in parent_fields.itemsscip-python python python-stdlib 3.11 builtins/dict#items().(): |
| 137 | attrsscip-python python django-tastypie 0.15.1 `tastypie.resources`/DeclarativeMetaclass#__new__().(attrs)['base_fields'][field_name] = deepcopyscip-python python python-stdlib 3.11 copy/deepcopy().(field_object) |
| 138 | |
| 139 | for field_name, obj in attrsscip-python python django-tastypie 0.15.1 `tastypie.resources`/DeclarativeMetaclass#__new__().(attrs).copy().items(): |
| 140 | # Look for ``dehydrated_type`` instead of doing ``isinstance``, |
| 141 | # which can break down if Tastypie is re-namespaced as something |
| 142 | # else. |
| 143 | if hasattr(obj, 'dehydrated_type'): |
| 144 | field = attrsscip-python python django-tastypie 0.15.1 `tastypie.resources`/DeclarativeMetaclass#__new__().(attrs).pop(field_name) |
| 145 | declared_fields[field_name] = field |
| 146 | |
| 147 | attrsscip-python python django-tastypie 0.15.1 `tastypie.resources`/DeclarativeMetaclass#__new__().(attrs)['base_fields'].update(declared_fields) |
| 148 | attrsscip-python python django-tastypie 0.15.1 `tastypie.resources`/DeclarativeMetaclass#__new__().(attrs)['declared_fields'] = declared_fields |
| 149 | new_class = superscip-python python python-stdlib 3.11 builtins/super#(DeclarativeMetaclassscip-python python django-tastypie 0.15.1 `tastypie.resources`/DeclarativeMetaclass#, clsscip-python python django-tastypie 0.15.1 `tastypie.resources`/DeclarativeMetaclass#__new__().(cls)).__new__scip-python python python-stdlib 3.11 builtins/type#__new__().(clsscip-python python django-tastypie 0.15.1 `tastypie.resources`/DeclarativeMetaclass#__new__().(cls), namescip-python python django-tastypie 0.15.1 `tastypie.resources`/DeclarativeMetaclass#__new__().(name), basesscip-python python django-tastypie 0.15.1 `tastypie.resources`/DeclarativeMetaclass#__new__().(bases), attrsscip-python python django-tastypie 0.15.1 `tastypie.resources`/DeclarativeMetaclass#__new__().(attrs)) |
| 150 | opts = getattrscip-python python python-stdlib 3.11 builtins/getattr().(new_class, 'Meta', None) |
| 151 | new_class._meta = ResourceOptionsscip-python python django-tastypie 0.15.1 `tastypie.resources`/ResourceOptions#(opts) |
| 152 | abstract = getattrscip-python python python-stdlib 3.11 builtins/getattr().(new_class._meta, 'abstract', False) |
| 153 | |
| 154 | if not getattrscip-python python python-stdlib 3.11 builtins/getattr().(new_class._meta, 'resource_name', None): |
| 155 | # No ``resource_name`` provided. Attempt to auto-name the resource. |
| 156 | class_name = new_class.__name__scip-python python python-stdlib 3.11 builtins/__name__# |
| 157 | name_bits = [bit for bit in class_name.splitscip-python python python-stdlib 3.11 builtins/str#split().('Resource') if bit] |
| 158 | resource_name = ''.joinscip-python python python-stdlib 3.11 builtins/str#join().(name_bits).lowerscip-python python python-stdlib 3.11 builtins/str#lower().() |
| 159 | new_class._meta.resource_namescip-python python django-tastypie 0.15.1 `tastypie.resources`/ResourceOptions#resource_name. = resource_name |
| 160 | |
| 161 | if getattrscip-python python python-stdlib 3.11 builtins/getattr().(new_class._meta, 'include_resource_uri', True): |
| 162 | if 'resource_uri' not in new_class.base_fields: |
| 163 | new_class.base_fields['resource_uri'] = fieldsscip-python python django-tastypie 0.15.1 `tastypie.fields`/__init__:.CharFieldscip-python python django-tastypie 0.15.1 `tastypie.fields`/CharField#(readonlyscip-python python django-tastypie 0.15.1 `tastypie.fields`/ApiField#__init__().(readonly)=True, verbose_namescip-python python django-tastypie 0.15.1 `tastypie.fields`/ApiField#__init__().(verbose_name)="resource uri") |
| 164 | elif 'resource_uri' in new_class.base_fields and 'resource_uri' not in attrsscip-python python django-tastypie 0.15.1 `tastypie.resources`/DeclarativeMetaclass#__new__().(attrs): |
| 165 | del new_class.base_fields['resource_uri'] |
| 166 | |
| 167 | if abstract and 'resource_uri' not in attrsscip-python python django-tastypie 0.15.1 `tastypie.resources`/DeclarativeMetaclass#__new__().(attrs): |
| 168 | # abstract classes don't have resource_uris unless explicitly provided |
| 169 | if 'resource_uri' in new_class.base_fields: |
| 170 | del new_class.base_fields['resource_uri'] |
| 171 | |
| 172 | for field_name, field_object in new_class.base_fields.items(): |
| 173 | if hasattr(field_object, 'contribute_to_class'): |
| 174 | field_object.contribute_to_class(new_class, field_name) |
| 175 | |
| 176 | return new_class |
| 177 | |
| 178 | |
| 179 | class Resourcescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#(metaclass=DeclarativeMetaclassscip-python python django-tastypie 0.15.1 `tastypie.resources`/DeclarativeMetaclass#): |
| 180 | """ |
| 181 | Handles the data, request dispatch and responding to requests. |
| 182 | |
| 183 | Serialization/deserialization is handled "at the edges" (i.e. at the |
| 184 | beginning/end of the request/response cycle) so that everything internally |
| 185 | is Python data structures. |
| 186 | |
| 187 | This class tries to be non-model specific, so it can be hooked up to other |
| 188 | data sources, such as search results, files, other data, etc. |
| 189 | """ |
| 190 | def __init__scip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#__init__().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#__init__().(self), api_namescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#__init__().(api_name)=None): |
| 191 | # this can cause: |
| 192 | # TypeError: object.__new__(method-wrapper) is not safe, use method-wrapper.__new__() |
| 193 | # when trying to copy a generator used as a default. Wrap call to |
| 194 | # generator in lambda to get around this error. |
| 195 | selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#__init__().(self).fieldsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#fields. = {k: copyscip-python python python-stdlib 3.11 copy/copy().(v) for k, v in selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#__init__().(self).base_fields.items()} |
| 196 | |
| 197 | if api_namescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#__init__().(api_name) is not None: |
| 198 | selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#__init__().(self)._meta.api_name = api_namescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#__init__().(api_name) |
| 199 | |
| 200 | def __getattr__scip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#__getattr__().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#__getattr__().(self), namescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#__getattr__().(name)): |
| 201 | if namescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#__getattr__().(name) == '__setstate__': |
| 202 | raise AttributeErrorscip-python python python-stdlib 3.11 builtins/AttributeError#(namescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#__getattr__().(name)) |
| 203 | try: |
| 204 | return selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#__getattr__().(self).fieldsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#fields.[namescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#__getattr__().(name)] |
| 205 | except KeyErrorscip-python python python-stdlib 3.11 builtins/KeyError#: |
| 206 | raise AttributeErrorscip-python python python-stdlib 3.11 builtins/AttributeError#(namescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#__getattr__().(name)) |
| 207 | |
| 208 | def wrap_viewscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#wrap_view().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#wrap_view().(self), viewscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#wrap_view().(view)): |
| 209 | """ |
| 210 | Wraps methods so they can be called in a more functional way as well |
| 211 | as handling exceptions better. |
| 212 | |
| 213 | Note that if ``BadRequest`` or an exception with a ``response`` attr |
| 214 | are seen, there is special handling to either present a message back |
| 215 | to the user or return the response traveling with the exception. |
| 216 | """ |
| 217 | @csrf_exempt |
| 218 | def wrapperscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#wrapper().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#wrapper().(request), *argsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#wrapper().(args), **kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#wrapper().(kwargs)): |
| 219 | try: |
| 220 | callback = getattrscip-python python python-stdlib 3.11 builtins/getattr().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#wrap_view().(self), viewscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#wrap_view().(view)) |
| 221 | response = callback(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#wrapper().(request), *argsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#wrapper().(args), **kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#wrapper().(kwargs)) |
| 222 | |
| 223 | # Our response can vary based on a number of factors, use |
| 224 | # the cache class to determine what we should ``Vary`` on so |
| 225 | # caches won't return the wrong (cached) version. |
| 226 | varies = getattrscip-python python python-stdlib 3.11 builtins/getattr().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#wrap_view().(self)._meta.cache, "varies", []) |
| 227 | |
| 228 | if varies: |
| 229 | patch_vary_headers(response, varies) |
| 230 | |
| 231 | if selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#wrap_view().(self)._meta.cache.cacheable(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#wrapper().(request), response): |
| 232 | if selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#wrap_view().(self)._meta.cache.cache_control(): |
| 233 | # If the request is cacheable and we have a |
| 234 | # ``Cache-Control`` available then patch the header. |
| 235 | patch_cache_control(response, **selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#wrap_view().(self)._meta.cache.cache_control()) |
| 236 | |
| 237 | if is_ajaxscip-python python django-tastypie 0.15.1 `tastypie.compat`/is_ajax().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#wrapper().(request)) and not response.has_header("Cache-Control"): |
| 238 | # IE excessively caches XMLHttpRequests, so we're disabling |
| 239 | # the browser cache here. |
| 240 | # See http://www.enhanceie.com/ie/bugs.asp for details. |
| 241 | patch_cache_control(response, no_cache=True) |
| 242 | |
| 243 | return response |
| 244 | except (BadRequestscip-python python django-tastypie 0.15.1 `tastypie.exceptions`/BadRequest#, fieldsscip-python python django-tastypie 0.15.1 `tastypie.fields`/__init__:.ApiFieldErrorscip-python python django-tastypie 0.15.1 `tastypie.exceptions`/ApiFieldError#) as e: |
| 245 | data = {"error": sanitizescip-python python django-tastypie 0.15.1 `tastypie.resources`/sanitize().(e.argsscip-python python python-stdlib 3.11 builtins/BaseException#args.[0]) if getattrscip-python python python-stdlib 3.11 builtins/getattr().(e, 'args') else ''} |
| 246 | return selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#wrap_view().(self).error_responsescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#error_response().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#wrapper().(request), data, response_classscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#error_response().(response_class)=httpscip-python python django-tastypie 0.15.1 `tastypie.http`/__init__:.HttpBadRequestscip-python python django-tastypie 0.15.1 `tastypie.http`/HttpBadRequest#) |
| 247 | except ValidationError as e: |
| 248 | data = {"error": sanitizescip-python python django-tastypie 0.15.1 `tastypie.resources`/sanitize().(e.messages)} |
| 249 | return selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#wrap_view().(self).error_responsescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#error_response().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#wrapper().(request), data, response_classscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#error_response().(response_class)=httpscip-python python django-tastypie 0.15.1 `tastypie.http`/__init__:.HttpBadRequestscip-python python django-tastypie 0.15.1 `tastypie.http`/HttpBadRequest#) |
| 250 | except Exceptionscip-python python python-stdlib 3.11 builtins/Exception# as e: |
| 251 | # Prevent muting non-django's exceptions |
| 252 | # i.e. RequestException from 'requests' library |
| 253 | if hasattr(e, 'response') and isinstance(e.response, HttpResponse): |
| 254 | return e.response |
| 255 | |
| 256 | # A real, non-expected exception. |
| 257 | # Handle the case where the full traceback is more helpful |
| 258 | # than the serialized error. |
| 259 | if settings.DEBUG and getattrscip-python python python-stdlib 3.11 builtins/getattr().(settings, 'TASTYPIE_FULL_DEBUG', False): |
| 260 | raise |
| 261 | |
| 262 | # Re-raise the error to get a proper traceback when the error |
| 263 | # happend during a test case |
| 264 | if requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#wrapper().(request).META.get('SERVER_NAME') == 'testserver': |
| 265 | raise |
| 266 | |
| 267 | # Rather than re-raising, we're going to things similar to |
| 268 | # what Django does. The difference is returning a serialized |
| 269 | # error message. |
| 270 | return selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#wrap_view().(self)._handle_500scip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#_handle_500().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#wrapper().(request), e) |
| 271 | |
| 272 | return wrapperscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#wrapper(). |
| 273 | |
| 274 | def get_response_class_for_exceptionscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_response_class_for_exception().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_response_class_for_exception().(self), requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_response_class_for_exception().(request), exceptionscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_response_class_for_exception().(exception)): |
| 275 | """ |
| 276 | Can be overridden to customize response classes used for uncaught |
| 277 | exceptions. Should always return a subclass of |
| 278 | ``django.http.HttpResponse``. |
| 279 | """ |
| 280 | if isinstance(exceptionscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_response_class_for_exception().(exception), (NotFoundscip-python python django-tastypie 0.15.1 `tastypie.exceptions`/NotFound#, ObjectDoesNotExist, Http404)): |
| 281 | return HttpResponseNotFound |
| 282 | elif isinstance(exceptionscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_response_class_for_exception().(exception), UnsupportedSerializationFormatscip-python python django-tastypie 0.15.1 `tastypie.exceptions`/UnsupportedSerializationFormat#): |
| 283 | return httpscip-python python django-tastypie 0.15.1 `tastypie.http`/__init__:.HttpNotAcceptablescip-python python django-tastypie 0.15.1 `tastypie.http`/HttpNotAcceptable# |
| 284 | elif isinstance(exceptionscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_response_class_for_exception().(exception), UnsupportedDeserializationFormatscip-python python django-tastypie 0.15.1 `tastypie.exceptions`/UnsupportedDeserializationFormat#): |
| 285 | return httpscip-python python django-tastypie 0.15.1 `tastypie.http`/__init__:.HttpUnsupportedMediaTypescip-python python django-tastypie 0.15.1 `tastypie.http`/HttpUnsupportedMediaType# |
| 286 | elif isinstance(exceptionscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_response_class_for_exception().(exception), UnsupportedFormatscip-python python django-tastypie 0.15.1 `tastypie.exceptions`/UnsupportedFormat#): |
| 287 | return httpscip-python python django-tastypie 0.15.1 `tastypie.http`/__init__:.HttpBadRequestscip-python python django-tastypie 0.15.1 `tastypie.http`/HttpBadRequest# |
| 288 | |
| 289 | return httpscip-python python django-tastypie 0.15.1 `tastypie.http`/__init__:.HttpApplicationErrorscip-python python django-tastypie 0.15.1 `tastypie.http`/HttpApplicationError# |
| 290 | |
| 291 | def _handle_500scip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#_handle_500().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#_handle_500().(self), requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#_handle_500().(request), exceptionscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#_handle_500().(exception)): |
| 292 | the_trace = tracebackscip-python python python-stdlib 3.11 traceback/__init__:.format_exceptionscip-python python python-stdlib 3.11 traceback/format_exception().(*sysscip-python python python-stdlib 3.11 sys/__init__:.exc_infoscip-python python python-stdlib 3.11 sys/exc_info().()) |
| 293 | the_trace = u'\n'.joinscip-python python python-stdlib 3.11 builtins/str#join().(the_trace) |
| 294 | |
| 295 | response_class = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#_handle_500().(self).get_response_class_for_exceptionscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_response_class_for_exception().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#_handle_500().(request), exceptionscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#_handle_500().(exception)) |
| 296 | |
| 297 | if settings.DEBUG: |
| 298 | data = { |
| 299 | "error_message": sanitizescip-python python django-tastypie 0.15.1 `tastypie.resources`/sanitize().(strscip-python python python-stdlib 3.11 builtins/str#(exceptionscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#_handle_500().(exception))), |
| 300 | "traceback": the_trace, |
| 301 | } |
| 302 | else: |
| 303 | data = { |
| 304 | "error_message": getattrscip-python python python-stdlib 3.11 builtins/getattr().(settings, 'TASTYPIE_CANNED_ERROR', "Sorry, this request could not be processed. Please try again later."), |
| 305 | } |
| 306 | |
| 307 | if response_class.status_codescip-python python django-tastypie 0.15.1 `tastypie.http`/HttpNotAcceptable#status_code. >= 500: |
| 308 | log = loggingscip-python python python-stdlib 3.11 logging/__init__:.getLoggerscip-python python python-stdlib 3.11 logging/getLogger().('django.request.tastypie') |
| 309 | log.errorscip-python python python-stdlib 3.11 logging/Logger#error().('Internal Server Error: %s' % requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#_handle_500().(request).path, exc_infoscip-python python python-stdlib 3.11 logging/Logger#error().(exc_info)=True, |
| 310 | extrascip-python python python-stdlib 3.11 logging/Logger#error().(extra)={'status_code': response_class.status_codescip-python python django-tastypie 0.15.1 `tastypie.http`/HttpNotAcceptable#status_code., 'request': requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#_handle_500().(request)}) |
| 311 | |
| 312 | # Send the signal so other apps are aware of the exception. |
| 313 | got_request_exception.send(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#_handle_500().(self).__class__scip-python python python-stdlib 3.11 builtins/object#__class__()., request=requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#_handle_500().(request)) |
| 314 | |
| 315 | return selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#_handle_500().(self).error_responsescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#error_response().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#_handle_500().(request), data, response_classscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#error_response().(response_class)=response_class) |
| 316 | |
| 317 | def _build_reverse_urlscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#_build_reverse_url().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#_build_reverse_url().(self), namescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#_build_reverse_url().(name), argsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#_build_reverse_url().(args)=None, kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#_build_reverse_url().(kwargs)=None): |
| 318 | """ |
| 319 | A convenience hook for overriding how URLs are built. |
| 320 | |
| 321 | See ``NamespacedModelResource._build_reverse_url`` for an example. |
| 322 | """ |
| 323 | return reverse(namescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#_build_reverse_url().(name), args=argsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#_build_reverse_url().(args), kwargs=kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#_build_reverse_url().(kwargs)) |
| 324 | |
| 325 | def base_urlsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#base_urls().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#base_urls().(self)): |
| 326 | """ |
| 327 | The standard URLs this ``Resource`` should respond to. |
| 328 | """ |
| 329 | return [ |
| 330 | re_path(r"^(?P<resource_name>%s)%s$" % (selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#base_urls().(self)._meta.resource_name, trailing_slashscip-python python django-tastypie 0.15.1 `tastypie.utils.urls`/trailing_slash.), selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#base_urls().(self).wrap_viewscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#wrap_view().('dispatch_list'), name="api_dispatch_list"), |
| 331 | re_path(r"^(?P<resource_name>%s)/schema%s$" % (selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#base_urls().(self)._meta.resource_name, trailing_slashscip-python python django-tastypie 0.15.1 `tastypie.utils.urls`/trailing_slash.), selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#base_urls().(self).wrap_viewscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#wrap_view().('get_schema'), name="api_get_schema"), |
| 332 | re_path(r"^(?P<resource_name>%s)/set/(?P<%s_list>.*?)%s$" % (selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#base_urls().(self)._meta.resource_name, selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#base_urls().(self)._meta.detail_uri_name, trailing_slashscip-python python django-tastypie 0.15.1 `tastypie.utils.urls`/trailing_slash.), selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#base_urls().(self).wrap_viewscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#wrap_view().('get_multiple'), name="api_get_multiple"), |
| 333 | re_path(r"^(?P<resource_name>%s)/(?P<%s>.*?)%s$" % (selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#base_urls().(self)._meta.resource_name, selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#base_urls().(self)._meta.detail_uri_name, trailing_slashscip-python python django-tastypie 0.15.1 `tastypie.utils.urls`/trailing_slash.), selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#base_urls().(self).wrap_viewscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#wrap_view().('dispatch_detail'), name="api_dispatch_detail"), |
| 334 | ] |
| 335 | |
| 336 | def override_urlsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#override_urls().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#override_urls().(self)): |
| 337 | """ |
| 338 | Deprecated. Will be removed by v1.0.0. Please use ``prepend_urls`` instead. |
| 339 | """ |
| 340 | return [] |
| 341 | |
| 342 | def prepend_urlsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#prepend_urls().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#prepend_urls().(self)): |
| 343 | """ |
| 344 | A hook for adding your own URLs or matching before the default URLs. |
| 345 | """ |
| 346 | return [] |
| 347 | |
| 348 | @propertyscip-python python python-stdlib 3.11 builtins/property# |
| 349 | def urlsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#urls().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#urls().(self)): |
| 350 | """ |
| 351 | The endpoints this ``Resource`` responds to. |
| 352 | |
| 353 | Mostly a standard URLconf, this is suitable for either automatic use |
| 354 | when registered with an ``Api`` class or for including directly in |
| 355 | a URLconf should you choose to. |
| 356 | """ |
| 357 | urls = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#urls().(self).prepend_urlsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#prepend_urls().() |
| 358 | |
| 359 | overridden_urls = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#urls().(self).override_urlsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#override_urls().() |
| 360 | if overridden_urls: |
| 361 | warningsscip-python python python-stdlib 3.11 warnings/__init__:.warnscip-python python python-stdlib 3.11 _warnings/warn().("'override_urls' is a deprecated method & will be removed by v1.0.0. Please rename your method to ``prepend_urls``.") |
| 362 | urls += overridden_urls |
| 363 | |
| 364 | urls += selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#urls().(self).base_urlsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#base_urls().() |
| 365 | return urls |
| 366 | |
| 367 | def determine_formatscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#determine_format().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#determine_format().(self), requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#determine_format().(request)): |
| 368 | """ |
| 369 | Used to determine the desired format. |
| 370 | |
| 371 | Largely relies on ``tastypie.utils.mime.determine_format`` but here |
| 372 | as a point of extension. |
| 373 | """ |
| 374 | return determine_formatscip-python python django-tastypie 0.15.1 `tastypie.utils.mime`/determine_format().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#determine_format().(request), selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#determine_format().(self)._meta.serializer, default_formatscip-python python django-tastypie 0.15.1 `tastypie.utils.mime`/determine_format().(default_format)=selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#determine_format().(self)._meta.default_format) |
| 375 | |
| 376 | def serializescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#serialize().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#serialize().(self), requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#serialize().(request), datascip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#serialize().(data), formatscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#serialize().(format), optionsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#serialize().(options)=None): |
| 377 | """ |
| 378 | Given a request, data and a desired format, produces a serialized |
| 379 | version suitable for transfer over the wire. |
| 380 | |
| 381 | Mostly a hook, this uses the ``Serializer`` from ``Resource._meta``. |
| 382 | """ |
| 383 | optionsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#serialize().(options) = optionsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#serialize().(options) or {} |
| 384 | |
| 385 | if 'text/javascript' in formatscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#serialize().(format): |
| 386 | # get JSONP callback name. default to "callback" |
| 387 | callback = requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#serialize().(request).GET.get('callback', 'callback') |
| 388 | |
| 389 | if not is_valid_jsonp_callback_valuescip-python python django-tastypie 0.15.1 `tastypie.utils.validate_jsonp`/is_valid_jsonp_callback_value().(callback): |
| 390 | raise BadRequestscip-python python django-tastypie 0.15.1 `tastypie.exceptions`/BadRequest#('JSONP callback name is invalid.') |
| 391 | |
| 392 | optionsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#serialize().(options)['callback'] = callback |
| 393 | |
| 394 | return selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#serialize().(self)._meta.serializer.serialize(datascip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#serialize().(data), formatscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#serialize().(format), optionsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#serialize().(options)) |
| 395 | |
| 396 | def deserializescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#deserialize().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#deserialize().(self), requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#deserialize().(request), datascip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#deserialize().(data), formatscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#deserialize().(format)='application/json'): |
| 397 | """ |
| 398 | Given a request, data and a format, deserializes the given data. |
| 399 | |
| 400 | It relies on the request properly sending a ``CONTENT_TYPE`` header, |
| 401 | falling back to ``application/json`` if not provided. |
| 402 | |
| 403 | Mostly a hook, this uses the ``Serializer`` from ``Resource._meta``. |
| 404 | """ |
| 405 | deserialized = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#deserialize().(self)._meta.serializer.deserialize(datascip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#deserialize().(data), format=requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#deserialize().(request).META.get('CONTENT_TYPE', formatscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#deserialize().(format))) |
| 406 | return deserialized |
| 407 | |
| 408 | def alter_list_data_to_serializescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#alter_list_data_to_serialize().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#alter_list_data_to_serialize().(self), requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#alter_list_data_to_serialize().(request), datascip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#alter_list_data_to_serialize().(data)): |
| 409 | """ |
| 410 | A hook to alter list data just before it gets serialized & sent to the user. |
| 411 | |
| 412 | Useful for restructuring/renaming aspects of the what's going to be |
| 413 | sent. |
| 414 | |
| 415 | Should accommodate for a list of objects, generally also including |
| 416 | meta data. |
| 417 | """ |
| 418 | return datascip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#alter_list_data_to_serialize().(data) |
| 419 | |
| 420 | def alter_detail_data_to_serializescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#alter_detail_data_to_serialize().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#alter_detail_data_to_serialize().(self), requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#alter_detail_data_to_serialize().(request), datascip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#alter_detail_data_to_serialize().(data)): |
| 421 | """ |
| 422 | A hook to alter detail data just before it gets serialized & sent to the user. |
| 423 | |
| 424 | Useful for restructuring/renaming aspects of the what's going to be |
| 425 | sent. |
| 426 | |
| 427 | Should accommodate for receiving a single bundle of data. |
| 428 | """ |
| 429 | return datascip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#alter_detail_data_to_serialize().(data) |
| 430 | |
| 431 | def alter_deserialized_list_datascip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#alter_deserialized_list_data().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#alter_deserialized_list_data().(self), requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#alter_deserialized_list_data().(request), datascip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#alter_deserialized_list_data().(data)): |
| 432 | """ |
| 433 | A hook to alter list data just after it has been received from the user & |
| 434 | gets deserialized. |
| 435 | |
| 436 | Useful for altering the user data before any hydration is applied. |
| 437 | """ |
| 438 | return datascip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#alter_deserialized_list_data().(data) |
| 439 | |
| 440 | def alter_deserialized_detail_datascip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#alter_deserialized_detail_data().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#alter_deserialized_detail_data().(self), requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#alter_deserialized_detail_data().(request), datascip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#alter_deserialized_detail_data().(data)): |
| 441 | """ |
| 442 | A hook to alter detail data just after it has been received from the user & |
| 443 | gets deserialized. |
| 444 | |
| 445 | Useful for altering the user data before any hydration is applied. |
| 446 | """ |
| 447 | return datascip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#alter_deserialized_detail_data().(data) |
| 448 | |
| 449 | def dispatch_listscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#dispatch_list().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#dispatch_list().(self), requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#dispatch_list().(request), **kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#dispatch_list().(kwargs)): |
| 450 | """ |
| 451 | A view for handling the various HTTP methods (GET/POST/PUT/DELETE) over |
| 452 | the entire list of resources. |
| 453 | |
| 454 | Relies on ``Resource.dispatch`` for the heavy-lifting. |
| 455 | """ |
| 456 | return selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#dispatch_list().(self).dispatchscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#dispatch().('list', requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#dispatch_list().(request), **kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#dispatch_list().(kwargs)) |
| 457 | |
| 458 | def dispatch_detailscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#dispatch_detail().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#dispatch_detail().(self), requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#dispatch_detail().(request), **kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#dispatch_detail().(kwargs)): |
| 459 | """ |
| 460 | A view for handling the various HTTP methods (GET/POST/PUT/DELETE) on |
| 461 | a single resource. |
| 462 | |
| 463 | Relies on ``Resource.dispatch`` for the heavy-lifting. |
| 464 | """ |
| 465 | return selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#dispatch_detail().(self).dispatchscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#dispatch().('detail', requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#dispatch_detail().(request), **kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#dispatch_detail().(kwargs)) |
| 466 | |
| 467 | def dispatchscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#dispatch().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#dispatch().(self), request_typescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#dispatch().(request_type), requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#dispatch().(request), **kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#dispatch().(kwargs)): |
| 468 | """ |
| 469 | Handles the common operations (allowed HTTP method, authentication, |
| 470 | throttling, method lookup) surrounding most CRUD interactions. |
| 471 | """ |
| 472 | allowed_methods = getattrscip-python python python-stdlib 3.11 builtins/getattr().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#dispatch().(self)._meta, "%s_allowed_methods" % request_typescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#dispatch().(request_type), None) |
| 473 | |
| 474 | if 'HTTP_X_HTTP_METHOD_OVERRIDE' in requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#dispatch().(request).META: |
| 475 | requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#dispatch().(request).method = requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#dispatch().(request).META['HTTP_X_HTTP_METHOD_OVERRIDE'] |
| 476 | |
| 477 | request_method = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#dispatch().(self).method_checkscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#method_check().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#dispatch().(request), allowedscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#method_check().(allowed)=allowed_methods) |
| 478 | method = getattrscip-python python python-stdlib 3.11 builtins/getattr().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#dispatch().(self), "%s_%s" % (request_method, request_typescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#dispatch().(request_type)), None) |
| 479 | |
| 480 | if method is None: |
| 481 | raise ImmediateHttpResponsescip-python python django-tastypie 0.15.1 `tastypie.exceptions`/ImmediateHttpResponse#(responsescip-python python django-tastypie 0.15.1 `tastypie.exceptions`/ImmediateHttpResponse#__init__().(response)=httpscip-python python django-tastypie 0.15.1 `tastypie.http`/__init__:.HttpNotImplementedscip-python python django-tastypie 0.15.1 `tastypie.http`/HttpNotImplemented#()) |
| 482 | |
| 483 | selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#dispatch().(self).is_authenticatedscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#is_authenticated().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#dispatch().(request)) |
| 484 | selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#dispatch().(self).throttle_checkscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#throttle_check().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#dispatch().(request)) |
| 485 | |
| 486 | # All clear. Process the request. |
| 487 | requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#dispatch().(request) = convert_post_to_putscip-python python django-tastypie 0.15.1 `tastypie.resources`/convert_post_to_put().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#dispatch().(request)) |
| 488 | response = method(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#dispatch().(request), **kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#dispatch().(kwargs)) |
| 489 | |
| 490 | # Add the throttled request. |
| 491 | selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#dispatch().(self).log_throttled_accessscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#log_throttled_access().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#dispatch().(request)) |
| 492 | |
| 493 | # If what comes back isn't a ``HttpResponse``, assume that the |
| 494 | # request was accepted and that some action occurred. This also |
| 495 | # prevents Django from freaking out. |
| 496 | if not isinstance(response, HttpResponse): |
| 497 | return httpscip-python python django-tastypie 0.15.1 `tastypie.http`/__init__:.HttpNoContentscip-python python django-tastypie 0.15.1 `tastypie.http`/HttpNoContent#() |
| 498 | |
| 499 | return response |
| 500 | |
| 501 | def remove_api_resource_namesscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#remove_api_resource_names().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#remove_api_resource_names().(self), url_dictscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#remove_api_resource_names().(url_dict)): |
| 502 | """ |
| 503 | Given a dictionary of regex matches from a URLconf, removes |
| 504 | ``api_name`` and/or ``resource_name`` if found. |
| 505 | |
| 506 | This is useful for converting URLconf matches into something suitable |
| 507 | for data lookup. For example:: |
| 508 | |
| 509 | Model.objects.filter(**self.remove_api_resource_names(matches)) |
| 510 | """ |
| 511 | kwargs_subset = url_dictscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#remove_api_resource_names().(url_dict).copy() |
| 512 | |
| 513 | for key in ['api_name', 'resource_name']: |
| 514 | try: |
| 515 | del kwargs_subset[key] |
| 516 | except KeyErrorscip-python python python-stdlib 3.11 builtins/KeyError#: |
| 517 | pass |
| 518 | |
| 519 | return kwargs_subset |
| 520 | |
| 521 | def method_checkscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#method_check().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#method_check().(self), requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#method_check().(request), allowedscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#method_check().(allowed)=None): |
| 522 | """ |
| 523 | Ensures that the HTTP method used on the request is allowed to be |
| 524 | handled by the resource. |
| 525 | |
| 526 | Takes an ``allowed`` parameter, which should be a list of lowercase |
| 527 | HTTP methods to check against. Usually, this looks like:: |
| 528 | |
| 529 | # The most generic lookup. |
| 530 | self.method_check(request, self._meta.allowed_methods) |
| 531 | |
| 532 | # A lookup against what's allowed for list-type methods. |
| 533 | self.method_check(request, self._meta.list_allowed_methods) |
| 534 | |
| 535 | # A useful check when creating a new endpoint that only handles |
| 536 | # GET. |
| 537 | self.method_check(request, ['get']) |
| 538 | """ |
| 539 | if allowedscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#method_check().(allowed) is None: |
| 540 | allowedscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#method_check().(allowed) = [] |
| 541 | |
| 542 | request_method = requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#method_check().(request).method.lower() |
| 543 | allows = ','.joinscip-python python python-stdlib 3.11 builtins/str#join().([meth.upper() for meth in allowedscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#method_check().(allowed)]) |
| 544 | |
| 545 | if request_method == "options": |
| 546 | response = HttpResponse(allows) |
| 547 | response['Allow'] = allows |
| 548 | raise ImmediateHttpResponsescip-python python django-tastypie 0.15.1 `tastypie.exceptions`/ImmediateHttpResponse#(responsescip-python python django-tastypie 0.15.1 `tastypie.exceptions`/ImmediateHttpResponse#__init__().(response)=response) |
| 549 | |
| 550 | if request_method not in allowedscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#method_check().(allowed): |
| 551 | response = httpscip-python python django-tastypie 0.15.1 `tastypie.http`/__init__:.HttpMethodNotAllowedscip-python python django-tastypie 0.15.1 `tastypie.http`/HttpMethodNotAllowed#(allows) |
| 552 | response['Allow'] = allows |
| 553 | raise ImmediateHttpResponsescip-python python django-tastypie 0.15.1 `tastypie.exceptions`/ImmediateHttpResponse#(responsescip-python python django-tastypie 0.15.1 `tastypie.exceptions`/ImmediateHttpResponse#__init__().(response)=response) |
| 554 | |
| 555 | return request_method |
| 556 | |
| 557 | def is_authenticatedscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#is_authenticated().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#is_authenticated().(self), requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#is_authenticated().(request)): |
| 558 | """ |
| 559 | Handles checking if the user is authenticated and dealing with |
| 560 | unauthenticated users. |
| 561 | |
| 562 | Mostly a hook, this uses class assigned to ``authentication`` from |
| 563 | ``Resource._meta``. |
| 564 | """ |
| 565 | # Authenticate the request as needed. |
| 566 | auth_result = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#is_authenticated().(self)._meta.authentication.is_authenticated(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#is_authenticated().(request)) |
| 567 | |
| 568 | if isinstance(auth_result, HttpResponse): |
| 569 | raise ImmediateHttpResponsescip-python python django-tastypie 0.15.1 `tastypie.exceptions`/ImmediateHttpResponse#(responsescip-python python django-tastypie 0.15.1 `tastypie.exceptions`/ImmediateHttpResponse#__init__().(response)=auth_result) |
| 570 | |
| 571 | if auth_result is not True: |
| 572 | raise ImmediateHttpResponsescip-python python django-tastypie 0.15.1 `tastypie.exceptions`/ImmediateHttpResponse#(responsescip-python python django-tastypie 0.15.1 `tastypie.exceptions`/ImmediateHttpResponse#__init__().(response)=httpscip-python python django-tastypie 0.15.1 `tastypie.http`/__init__:.HttpUnauthorizedscip-python python django-tastypie 0.15.1 `tastypie.http`/HttpUnauthorized#()) |
| 573 | |
| 574 | def throttle_checkscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#throttle_check().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#throttle_check().(self), requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#throttle_check().(request)): |
| 575 | """ |
| 576 | Handles checking if the user should be throttled. |
| 577 | |
| 578 | Mostly a hook, this uses class assigned to ``throttle`` from |
| 579 | ``Resource._meta``. |
| 580 | """ |
| 581 | identifier = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#throttle_check().(self)._meta.authentication.get_identifier(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#throttle_check().(request)) |
| 582 | |
| 583 | # Check to see if they should be throttled. |
| 584 | throttle = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#throttle_check().(self)._meta.throttle.should_be_throttled(identifier) |
| 585 | |
| 586 | if throttle: |
| 587 | # Throttle limit exceeded. |
| 588 | |
| 589 | response = httpscip-python python django-tastypie 0.15.1 `tastypie.http`/__init__:.HttpTooManyRequestsscip-python python django-tastypie 0.15.1 `tastypie.http`/HttpTooManyRequests#() |
| 590 | |
| 591 | if isinstance(throttle, intscip-python python python-stdlib 3.11 builtins/int#) and not isinstance(throttle, boolscip-python python python-stdlib 3.11 builtins/bool#): |
| 592 | response['Retry-After'] = throttle |
| 593 | elif isinstance(throttle, datetimescip-python python python-stdlib 3.11 datetime/datetime#): |
| 594 | # change to UTC (GMT) and make naive, to avoid wsgiref also doing an implicit TZ conversion |
| 595 | throttle_utc = make_naive_utcscip-python python django-tastypie 0.15.1 `tastypie.utils.timezone`/make_naive_utc().(throttle) |
| 596 | response['Retry-After'] = format_date_time(mktimescip-python python python-stdlib 3.11 time/mktime().(throttle_utc.timetuple())) |
| 597 | |
| 598 | raise ImmediateHttpResponsescip-python python django-tastypie 0.15.1 `tastypie.exceptions`/ImmediateHttpResponse#(responsescip-python python django-tastypie 0.15.1 `tastypie.exceptions`/ImmediateHttpResponse#__init__().(response)=response) |
| 599 | |
| 600 | def log_throttled_accessscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#log_throttled_access().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#log_throttled_access().(self), requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#log_throttled_access().(request)): |
| 601 | """ |
| 602 | Handles the recording of the user's access for throttling purposes. |
| 603 | |
| 604 | Mostly a hook, this uses class assigned to ``throttle`` from |
| 605 | ``Resource._meta``. |
| 606 | """ |
| 607 | request_method = requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#log_throttled_access().(request).method.lower() |
| 608 | selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#log_throttled_access().(self)._meta.throttle.accessed(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#log_throttled_access().(self)._meta.authentication.get_identifier(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#log_throttled_access().(request)), url=requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#log_throttled_access().(request).get_full_path(), request_method=request_method) |
| 609 | |
| 610 | def unauthorized_resultscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#unauthorized_result().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#unauthorized_result().(self), exceptionscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#unauthorized_result().(exception)): |
| 611 | raise ImmediateHttpResponsescip-python python django-tastypie 0.15.1 `tastypie.exceptions`/ImmediateHttpResponse#(responsescip-python python django-tastypie 0.15.1 `tastypie.exceptions`/ImmediateHttpResponse#__init__().(response)=httpscip-python python django-tastypie 0.15.1 `tastypie.http`/__init__:.HttpUnauthorizedscip-python python django-tastypie 0.15.1 `tastypie.http`/HttpUnauthorized#()) |
| 612 | |
| 613 | def authorized_read_listscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_read_list().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_read_list().(self), object_listscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_read_list().(object_list), bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_read_list().(bundle)): |
| 614 | """ |
| 615 | Handles checking of permissions to see if the user has authorization |
| 616 | to GET this resource. |
| 617 | """ |
| 618 | try: |
| 619 | auth_result = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_read_list().(self)._meta.authorization.read_list(object_listscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_read_list().(object_list), bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_read_list().(bundle)) |
| 620 | except Unauthorizedscip-python python django-tastypie 0.15.1 `tastypie.exceptions`/Unauthorized# as e: |
| 621 | selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_read_list().(self).unauthorized_resultscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#unauthorized_result().(e) |
| 622 | |
| 623 | return auth_result |
| 624 | |
| 625 | def authorized_read_detailscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_read_detail().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_read_detail().(self), object_listscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_read_detail().(object_list), bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_read_detail().(bundle)): |
| 626 | """ |
| 627 | Handles checking of permissions to see if the user has authorization |
| 628 | to GET this resource. |
| 629 | """ |
| 630 | try: |
| 631 | auth_result = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_read_detail().(self)._meta.authorization.read_detail(object_listscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_read_detail().(object_list), bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_read_detail().(bundle)) |
| 632 | if auth_result is not True: |
| 633 | raise Unauthorizedscip-python python django-tastypie 0.15.1 `tastypie.exceptions`/Unauthorized#() |
| 634 | except Unauthorizedscip-python python django-tastypie 0.15.1 `tastypie.exceptions`/Unauthorized# as e: |
| 635 | selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_read_detail().(self).unauthorized_resultscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#unauthorized_result().(e) |
| 636 | |
| 637 | return auth_result |
| 638 | |
| 639 | def authorized_create_listscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_create_list().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_create_list().(self), object_listscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_create_list().(object_list), bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_create_list().(bundle)): |
| 640 | """ |
| 641 | Handles checking of permissions to see if the user has authorization |
| 642 | to POST this resource. |
| 643 | """ |
| 644 | try: |
| 645 | auth_result = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_create_list().(self)._meta.authorization.create_list(object_listscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_create_list().(object_list), bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_create_list().(bundle)) |
| 646 | except Unauthorizedscip-python python django-tastypie 0.15.1 `tastypie.exceptions`/Unauthorized# as e: |
| 647 | selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_create_list().(self).unauthorized_resultscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#unauthorized_result().(e) |
| 648 | |
| 649 | return auth_result |
| 650 | |
| 651 | def authorized_create_detailscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_create_detail().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_create_detail().(self), object_listscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_create_detail().(object_list), bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_create_detail().(bundle)): |
| 652 | """ |
| 653 | Handles checking of permissions to see if the user has authorization |
| 654 | to POST this resource. |
| 655 | """ |
| 656 | try: |
| 657 | auth_result = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_create_detail().(self)._meta.authorization.create_detail(object_listscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_create_detail().(object_list), bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_create_detail().(bundle)) |
| 658 | if auth_result is not True: |
| 659 | raise Unauthorizedscip-python python django-tastypie 0.15.1 `tastypie.exceptions`/Unauthorized#() |
| 660 | except Unauthorizedscip-python python django-tastypie 0.15.1 `tastypie.exceptions`/Unauthorized# as e: |
| 661 | selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_create_detail().(self).unauthorized_resultscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#unauthorized_result().(e) |
| 662 | |
| 663 | return auth_result |
| 664 | |
| 665 | def authorized_update_listscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_update_list().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_update_list().(self), object_listscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_update_list().(object_list), bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_update_list().(bundle)): |
| 666 | """ |
| 667 | Handles checking of permissions to see if the user has authorization |
| 668 | to PUT this resource. |
| 669 | """ |
| 670 | try: |
| 671 | auth_result = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_update_list().(self)._meta.authorization.update_list(object_listscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_update_list().(object_list), bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_update_list().(bundle)) |
| 672 | except Unauthorizedscip-python python django-tastypie 0.15.1 `tastypie.exceptions`/Unauthorized# as e: |
| 673 | selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_update_list().(self).unauthorized_resultscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#unauthorized_result().(e) |
| 674 | |
| 675 | return auth_result |
| 676 | |
| 677 | def authorized_update_detailscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_update_detail().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_update_detail().(self), object_listscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_update_detail().(object_list), bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_update_detail().(bundle)): |
| 678 | """ |
| 679 | Handles checking of permissions to see if the user has authorization |
| 680 | to PUT this resource. |
| 681 | """ |
| 682 | try: |
| 683 | auth_result = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_update_detail().(self)._meta.authorization.update_detail(object_listscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_update_detail().(object_list), bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_update_detail().(bundle)) |
| 684 | if auth_result is not True: |
| 685 | raise Unauthorizedscip-python python django-tastypie 0.15.1 `tastypie.exceptions`/Unauthorized#() |
| 686 | except Unauthorizedscip-python python django-tastypie 0.15.1 `tastypie.exceptions`/Unauthorized# as e: |
| 687 | selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_update_detail().(self).unauthorized_resultscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#unauthorized_result().(e) |
| 688 | |
| 689 | return auth_result |
| 690 | |
| 691 | def authorized_delete_listscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_delete_list().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_delete_list().(self), object_listscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_delete_list().(object_list), bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_delete_list().(bundle)): |
| 692 | """ |
| 693 | Handles checking of permissions to see if the user has authorization |
| 694 | to DELETE this resource. |
| 695 | """ |
| 696 | try: |
| 697 | auth_result = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_delete_list().(self)._meta.authorization.delete_list(object_listscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_delete_list().(object_list), bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_delete_list().(bundle)) |
| 698 | except Unauthorizedscip-python python django-tastypie 0.15.1 `tastypie.exceptions`/Unauthorized# as e: |
| 699 | selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_delete_list().(self).unauthorized_resultscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#unauthorized_result().(e) |
| 700 | |
| 701 | return auth_result |
| 702 | |
| 703 | def authorized_delete_detailscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_delete_detail().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_delete_detail().(self), object_listscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_delete_detail().(object_list), bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_delete_detail().(bundle)): |
| 704 | """ |
| 705 | Handles checking of permissions to see if the user has authorization |
| 706 | to DELETE this resource. |
| 707 | """ |
| 708 | try: |
| 709 | auth_result = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_delete_detail().(self)._meta.authorization.delete_detail(object_listscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_delete_detail().(object_list), bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_delete_detail().(bundle)) |
| 710 | if not auth_result: |
| 711 | raise Unauthorizedscip-python python django-tastypie 0.15.1 `tastypie.exceptions`/Unauthorized#() |
| 712 | except Unauthorizedscip-python python django-tastypie 0.15.1 `tastypie.exceptions`/Unauthorized# as e: |
| 713 | selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_delete_detail().(self).unauthorized_resultscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#unauthorized_result().(e) |
| 714 | |
| 715 | return auth_result |
| 716 | |
| 717 | def build_bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_bundle().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_bundle().(self), objscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_bundle().(obj)=None, datascip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_bundle().(data)=None, requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_bundle().(request)=None, objects_savedscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_bundle().(objects_saved)=None, via_uriscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_bundle().(via_uri)=None): |
| 718 | """ |
| 719 | Given either an object, a data dictionary or both, builds a ``Bundle`` |
| 720 | for use throughout the ``dehydrate/hydrate`` cycle. |
| 721 | |
| 722 | If no object is provided, an empty object from |
| 723 | ``Resource._meta.object_class`` is created so that attempts to access |
| 724 | ``bundle.obj`` do not fail. |
| 725 | """ |
| 726 | if objscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_bundle().(obj) is None and selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_bundle().(self)._meta.object_class: |
| 727 | objscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_bundle().(obj) = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_bundle().(self)._meta.object_class() |
| 728 | |
| 729 | return Bundlescip-python python django-tastypie 0.15.1 `tastypie.bundle`/Bundle#( |
| 730 | objscip-python python django-tastypie 0.15.1 `tastypie.bundle`/Bundle#__init__().(obj)=objscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_bundle().(obj), |
| 731 | datascip-python python django-tastypie 0.15.1 `tastypie.bundle`/Bundle#__init__().(data)=datascip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_bundle().(data), |
| 732 | requestscip-python python django-tastypie 0.15.1 `tastypie.bundle`/Bundle#__init__().(request)=requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_bundle().(request), |
| 733 | objects_savedscip-python python django-tastypie 0.15.1 `tastypie.bundle`/Bundle#__init__().(objects_saved)=objects_savedscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_bundle().(objects_saved), |
| 734 | via_uriscip-python python django-tastypie 0.15.1 `tastypie.bundle`/Bundle#__init__().(via_uri)=via_uriscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_bundle().(via_uri) |
| 735 | ) |
| 736 | |
| 737 | def build_filtersscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_filters().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_filters().(self), filtersscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_filters().(filters)=None, ignore_bad_filtersscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_filters().(ignore_bad_filters)=False): |
| 738 | """ |
| 739 | Allows for the filtering of applicable objects. |
| 740 | |
| 741 | This needs to be implemented at the user level.' |
| 742 | |
| 743 | ``ModelResource`` includes a full working version specific to Django's |
| 744 | ``Models``. |
| 745 | """ |
| 746 | return filtersscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_filters().(filters) |
| 747 | |
| 748 | def apply_sortingscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#apply_sorting().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#apply_sorting().(self), obj_listscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#apply_sorting().(obj_list), optionsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#apply_sorting().(options)=None): |
| 749 | """ |
| 750 | Allows for the sorting of objects being returned. |
| 751 | |
| 752 | This needs to be implemented at the user level. |
| 753 | |
| 754 | ``ModelResource`` includes a full working version specific to Django's |
| 755 | ``Models``. |
| 756 | """ |
| 757 | return obj_listscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#apply_sorting().(obj_list) |
| 758 | |
| 759 | def get_bundle_detail_datascip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_bundle_detail_data().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_bundle_detail_data().(self), bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_bundle_detail_data().(bundle)): |
| 760 | """ |
| 761 | Convenience method to return the ``detail_uri_name`` attribute off |
| 762 | ``bundle.obj``. |
| 763 | |
| 764 | Usually just accesses ``bundle.obj.pk`` by default. |
| 765 | """ |
| 766 | return getattrscip-python python python-stdlib 3.11 builtins/getattr().(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_bundle_detail_data().(bundle).obj, selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_bundle_detail_data().(self)._meta.detail_uri_name, None) |
| 767 | |
| 768 | # URL-related methods. |
| 769 | |
| 770 | def detail_uri_kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#detail_uri_kwargs().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#detail_uri_kwargs().(self), bundle_or_objscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#detail_uri_kwargs().(bundle_or_obj)): |
| 771 | """ |
| 772 | Given a ``Bundle`` or an object (typically a ``Model`` instance), |
| 773 | it returns the extra kwargs needed to generate a detail URI. |
| 774 | |
| 775 | By default, it uses this resource's ``detail_uri_name`` in order to |
| 776 | create the URI. |
| 777 | """ |
| 778 | kwargs = {} |
| 779 | |
| 780 | if isinstance(bundle_or_objscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#detail_uri_kwargs().(bundle_or_obj), Bundlescip-python python django-tastypie 0.15.1 `tastypie.bundle`/Bundle#): |
| 781 | bundle_or_objscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#detail_uri_kwargs().(bundle_or_obj) = bundle_or_objscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#detail_uri_kwargs().(bundle_or_obj).objscip-python python django-tastypie 0.15.1 `tastypie.bundle`/Bundle#obj. |
| 782 | |
| 783 | kwargs[selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#detail_uri_kwargs().(self)._meta.detail_uri_name] = getattrscip-python python python-stdlib 3.11 builtins/getattr().(bundle_or_objscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#detail_uri_kwargs().(bundle_or_obj), selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#detail_uri_kwargs().(self)._meta.detail_uri_name) |
| 784 | |
| 785 | return kwargs |
| 786 | |
| 787 | def resource_uri_kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#resource_uri_kwargs().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#resource_uri_kwargs().(self), bundle_or_objscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#resource_uri_kwargs().(bundle_or_obj)=None): |
| 788 | """ |
| 789 | Builds a dictionary of kwargs to help generate URIs. |
| 790 | |
| 791 | Automatically provides the ``Resource.Meta.resource_name`` (and |
| 792 | optionally the ``Resource.Meta.api_name`` if populated by an ``Api`` |
| 793 | object). |
| 794 | |
| 795 | If the ``bundle_or_obj`` argument is provided, it calls |
| 796 | ``Resource.detail_uri_kwargs`` for additional bits to create |
| 797 | """ |
| 798 | kwargs = { |
| 799 | 'resource_name': selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#resource_uri_kwargs().(self)._meta.resource_name, |
| 800 | } |
| 801 | |
| 802 | if selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#resource_uri_kwargs().(self)._meta.api_name is not None: |
| 803 | kwargs['api_name'] = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#resource_uri_kwargs().(self)._meta.api_name |
| 804 | |
| 805 | if bundle_or_objscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#resource_uri_kwargs().(bundle_or_obj) is not None: |
| 806 | kwargs.updatescip-python python python-stdlib 3.11 typing/MutableMapping#update().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#resource_uri_kwargs().(self).detail_uri_kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#detail_uri_kwargs().(bundle_or_objscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#resource_uri_kwargs().(bundle_or_obj))) |
| 807 | |
| 808 | return kwargs |
| 809 | |
| 810 | def get_resource_uriscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_resource_uri().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_resource_uri().(self), bundle_or_objscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_resource_uri().(bundle_or_obj)=None, url_namescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_resource_uri().(url_name)='api_dispatch_list'): |
| 811 | """ |
| 812 | Handles generating a resource URI. |
| 813 | |
| 814 | If the ``bundle_or_obj`` argument is not provided, it builds the URI |
| 815 | for the list endpoint. |
| 816 | |
| 817 | If the ``bundle_or_obj`` argument is provided, it builds the URI for |
| 818 | the detail endpoint. |
| 819 | |
| 820 | Return the generated URI. If that URI can not be reversed (not found |
| 821 | in the URLconf), it will return an empty string. |
| 822 | """ |
| 823 | if bundle_or_objscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_resource_uri().(bundle_or_obj) is not None: |
| 824 | url_namescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_resource_uri().(url_name) = 'api_dispatch_detail' |
| 825 | |
| 826 | try: |
| 827 | return selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_resource_uri().(self)._build_reverse_urlscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#_build_reverse_url().(url_namescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_resource_uri().(url_name), kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#_build_reverse_url().(kwargs)=selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_resource_uri().(self).resource_uri_kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#resource_uri_kwargs().(bundle_or_objscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_resource_uri().(bundle_or_obj))) |
| 828 | except NoReverseMatch: |
| 829 | return '' |
| 830 | |
| 831 | def get_via_uriscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_via_uri().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_via_uri().(self), uriscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_via_uri().(uri), requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_via_uri().(request)=None): |
| 832 | """ |
| 833 | This pulls apart the salient bits of the URI and populates the |
| 834 | resource via a ``obj_get``. |
| 835 | |
| 836 | Optionally accepts a ``request``. |
| 837 | |
| 838 | If you need custom behavior based on other portions of the URI, |
| 839 | simply override this method. |
| 840 | """ |
| 841 | prefix = get_script_prefix() |
| 842 | chomped_uri = uriscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_via_uri().(uri) |
| 843 | |
| 844 | if prefix and chomped_uri.startswith(prefix): |
| 845 | chomped_uri = chomped_uri[len(prefix) - 1:] |
| 846 | |
| 847 | # We know that we are dealing with a "detail" URI |
| 848 | # Look for the beginning of object key (last meaningful part of the URI) |
| 849 | end_of_resource_name = chomped_uri.rstrip('/').rfind('/') |
| 850 | if end_of_resource_name == -1: |
| 851 | raise NotFoundscip-python python django-tastypie 0.15.1 `tastypie.exceptions`/NotFound#("An incorrect URL was provided '%s' for the '%s' resource." % (uriscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_via_uri().(uri), selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_via_uri().(self).__class__scip-python python python-stdlib 3.11 builtins/object#__class__()..__name__scip-python python python-stdlib 3.11 builtins/__name__#)) |
| 852 | # We mangle the path a bit further & run URL resolution against *only* |
| 853 | # the current class (but up to detail key). This ought to prevent bad |
| 854 | # URLs from resolving to incorrect data. |
| 855 | split_url = chomped_uri.rstrip('/').rsplit('/', 1)[0] |
| 856 | if not split_url.endswith('/' + selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_via_uri().(self)._meta.resource_name): |
| 857 | raise NotFoundscip-python python django-tastypie 0.15.1 `tastypie.exceptions`/NotFound#("An incorrect URL was provided '%s' for the '%s' resource." % (uriscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_via_uri().(uri), selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_via_uri().(self).__class__scip-python python python-stdlib 3.11 builtins/object#__class__()..__name__scip-python python python-stdlib 3.11 builtins/__name__#)) |
| 858 | found_at = chomped_uri.rfind(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_via_uri().(self)._meta.resource_name, 0, end_of_resource_name) |
| 859 | chomped_uri = chomped_uri[found_at:] |
| 860 | try: |
| 861 | for url_resolver in getattrscip-python python python-stdlib 3.11 builtins/getattr().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_via_uri().(self), 'urls', []): |
| 862 | result = url_resolver.resolve(chomped_uri) |
| 863 | |
| 864 | if result is not None: |
| 865 | view, args, kwargs = result |
| 866 | break |
| 867 | else: |
| 868 | raise Resolver404("URI not found in 'self.urls'.") |
| 869 | except Resolver404: |
| 870 | raise NotFoundscip-python python django-tastypie 0.15.1 `tastypie.exceptions`/NotFound#("The URL provided '%s' was not a link to a valid resource." % uriscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_via_uri().(uri)) |
| 871 | |
| 872 | bundle = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_via_uri().(self).build_bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_bundle().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_bundle().(request)=requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_via_uri().(request)) |
| 873 | return selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_via_uri().(self).obj_getscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#obj_get().(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#obj_get().(bundle)=bundle, **selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_via_uri().(self).remove_api_resource_namesscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#remove_api_resource_names().(kwargs)) |
| 874 | |
| 875 | # Data preparation. |
| 876 | |
| 877 | def full_dehydratescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#full_dehydrate().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#full_dehydrate().(self), bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#full_dehydrate().(bundle), for_listscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#full_dehydrate().(for_list)=False): |
| 878 | """ |
| 879 | Given a bundle with an object instance, extract the information from it |
| 880 | to populate the resource. |
| 881 | """ |
| 882 | data = bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#full_dehydrate().(bundle).data |
| 883 | |
| 884 | api_name = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#full_dehydrate().(self)._meta.api_name |
| 885 | resource_name = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#full_dehydrate().(self)._meta.resource_name |
| 886 | |
| 887 | # Dehydrate each field. |
| 888 | for field_name, field_object in selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#full_dehydrate().(self).fieldsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#fields..itemsscip-python python python-stdlib 3.11 builtins/dict#items().(): |
| 889 | # If it's not for use in this mode, skip |
| 890 | field_use_in = field_object.use_in |
| 891 | if callable(field_use_in): |
| 892 | if not field_use_in(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#full_dehydrate().(bundle)): |
| 893 | continue |
| 894 | else: |
| 895 | if field_use_in not in ['all', 'list' if for_listscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#full_dehydrate().(for_list) else 'detail']: |
| 896 | continue |
| 897 | |
| 898 | # A touch leaky but it makes URI resolution work. |
| 899 | if field_object.dehydrated_type == 'related': |
| 900 | field_object.api_name = api_name |
| 901 | field_object.resource_name = resource_name |
| 902 | |
| 903 | data[field_name] = field_object.dehydrate(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#full_dehydrate().(bundle), for_list=for_listscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#full_dehydrate().(for_list)) |
| 904 | |
| 905 | # Check for an optional method to do further dehydration. |
| 906 | method = getattrscip-python python python-stdlib 3.11 builtins/getattr().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#full_dehydrate().(self), "dehydrate_%s" % field_name, None) |
| 907 | |
| 908 | if method: |
| 909 | data[field_name] = method(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#full_dehydrate().(bundle)) |
| 910 | |
| 911 | bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#full_dehydrate().(bundle) = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#full_dehydrate().(self).dehydratescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#dehydrate().(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#full_dehydrate().(bundle)) |
| 912 | return bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#full_dehydrate().(bundle) |
| 913 | |
| 914 | def dehydratescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#dehydrate().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#dehydrate().(self), bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#dehydrate().(bundle)): |
| 915 | """ |
| 916 | A hook to allow a final manipulation of data once all fields/methods |
| 917 | have built out the dehydrated data. |
| 918 | |
| 919 | Useful if you need to access more than one dehydrated field or want |
| 920 | to annotate on additional data. |
| 921 | |
| 922 | Must return the modified bundle. |
| 923 | """ |
| 924 | return bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#dehydrate().(bundle) |
| 925 | |
| 926 | def full_hydratescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#full_hydrate().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#full_hydrate().(self), bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#full_hydrate().(bundle)): |
| 927 | """ |
| 928 | Given a populated bundle, distill it and turn it back into |
| 929 | a full-fledged object instance. |
| 930 | """ |
| 931 | if bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#full_hydrate().(bundle).obj is None: |
| 932 | bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#full_hydrate().(bundle).obj = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#full_hydrate().(self)._meta.object_class() |
| 933 | |
| 934 | bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#full_hydrate().(bundle) = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#full_hydrate().(self).hydratescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#hydrate().(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#full_hydrate().(bundle)) |
| 935 | |
| 936 | for field_name, field_object in selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#full_hydrate().(self).fieldsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#fields..itemsscip-python python python-stdlib 3.11 builtins/dict#items().(): |
| 937 | if field_object.readonly is True: |
| 938 | continue |
| 939 | |
| 940 | # Check for an optional method to do further hydration. |
| 941 | method = getattrscip-python python python-stdlib 3.11 builtins/getattr().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#full_hydrate().(self), "hydrate_%s" % field_name, None) |
| 942 | |
| 943 | if method: |
| 944 | bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#full_hydrate().(bundle) = method(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#full_hydrate().(bundle)) |
| 945 | |
| 946 | if field_object.attribute: |
| 947 | value = field_object.hydrate(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#full_hydrate().(bundle)) |
| 948 | |
| 949 | # NOTE: We only get back a bundle when it is related field. |
| 950 | if isinstance(value, Bundlescip-python python django-tastypie 0.15.1 `tastypie.bundle`/Bundle#) and value.errorsscip-python python django-tastypie 0.15.1 `tastypie.bundle`/Bundle#errors..getscip-python python python-stdlib 3.11 builtins/dict#get().(field_name): |
| 951 | bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#full_hydrate().(bundle).errors[field_name] = value.errorsscip-python python django-tastypie 0.15.1 `tastypie.bundle`/Bundle#errors.[field_name] |
| 952 | |
| 953 | if value is not None or field_object.null: |
| 954 | # We need to avoid populating M2M data here as that will |
| 955 | # cause things to blow up. |
| 956 | if not field_object.is_related: |
| 957 | setattr(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#full_hydrate().(bundle).obj, field_object.attribute, value) |
| 958 | elif not field_object.is_m2m: |
| 959 | if value is not None: |
| 960 | # NOTE: A bug fix in Django (ticket #18153) fixes incorrect behavior |
| 961 | # which Tastypie was relying on. To fix this, we store value.obj to |
| 962 | # be saved later in save_related. |
| 963 | try: |
| 964 | setattr(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#full_hydrate().(bundle).obj, field_object.attribute, value.objscip-python python django-tastypie 0.15.1 `tastypie.bundle`/Bundle#obj.) |
| 965 | except (ValueErrorscip-python python python-stdlib 3.11 builtins/ValueError#, ObjectDoesNotExist): |
| 966 | bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#full_hydrate().(bundle).related_objects_to_save[field_object.attribute] = value.objscip-python python django-tastypie 0.15.1 `tastypie.bundle`/Bundle#obj. |
| 967 | # not required, not sent |
| 968 | elif field_object.blank and field_name not in bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#full_hydrate().(bundle).data: |
| 969 | continue |
| 970 | elif field_object.null: |
| 971 | if not isinstance(getattrscip-python python python-stdlib 3.11 builtins/getattr().(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#full_hydrate().(bundle).obj.__class__, field_object.attribute, None), ReverseOneToOneDescriptor): |
| 972 | # only update if not a reverse one to one field |
| 973 | setattr(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#full_hydrate().(bundle).obj, field_object.attribute, value) |
| 974 | |
| 975 | return bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#full_hydrate().(bundle) |
| 976 | |
| 977 | def hydratescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#hydrate().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#hydrate().(self), bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#hydrate().(bundle)): |
| 978 | """ |
| 979 | A hook to allow an initial manipulation of data before all methods/fields |
| 980 | have built out the hydrated data. |
| 981 | |
| 982 | Useful if you need to access more than one hydrated field or want |
| 983 | to annotate on additional data. |
| 984 | |
| 985 | Must return the modified bundle. |
| 986 | """ |
| 987 | return bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#hydrate().(bundle) |
| 988 | |
| 989 | def hydrate_m2mscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#hydrate_m2m().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#hydrate_m2m().(self), bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#hydrate_m2m().(bundle)): |
| 990 | """ |
| 991 | Populate the ManyToMany data on the instance. |
| 992 | """ |
| 993 | if bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#hydrate_m2m().(bundle).obj is None: |
| 994 | raise HydrationErrorscip-python python django-tastypie 0.15.1 `tastypie.exceptions`/HydrationError#("You must call 'full_hydrate' before attempting to run 'hydrate_m2m' on %r." % selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#hydrate_m2m().(self)) |
| 995 | |
| 996 | for field_name, field_object in selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#hydrate_m2m().(self).fieldsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#fields..itemsscip-python python python-stdlib 3.11 builtins/dict#items().(): |
| 997 | if not field_object.is_m2m: |
| 998 | continue |
| 999 | |
| 1000 | if field_object.attribute: |
| 1001 | # Note that we only hydrate the data, leaving the instance |
| 1002 | # unmodified. It's up to the user's code to handle this. |
| 1003 | # The ``ModelResource`` provides a working baseline |
| 1004 | # in this regard. |
| 1005 | bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#hydrate_m2m().(bundle).data[field_name] = field_object.hydrate_m2m(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#hydrate_m2m().(bundle)) |
| 1006 | |
| 1007 | for field_name, field_object in selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#hydrate_m2m().(self).fieldsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#fields..itemsscip-python python python-stdlib 3.11 builtins/dict#items().(): |
| 1008 | if not field_object.is_m2m: |
| 1009 | continue |
| 1010 | |
| 1011 | method = getattrscip-python python python-stdlib 3.11 builtins/getattr().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#hydrate_m2m().(self), "hydrate_%s" % field_name, None) |
| 1012 | |
| 1013 | if method: |
| 1014 | method(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#hydrate_m2m().(bundle)) |
| 1015 | |
| 1016 | return bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#hydrate_m2m().(bundle) |
| 1017 | |
| 1018 | def build_schemascip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_schema().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_schema().(self)): |
| 1019 | """ |
| 1020 | Returns a dictionary of all the fields on the resource and some |
| 1021 | properties about those fields. |
| 1022 | |
| 1023 | Used by the ``schema/`` endpoint to describe what will be available. |
| 1024 | """ |
| 1025 | data = { |
| 1026 | 'fields': {}, |
| 1027 | 'default_format': selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_schema().(self)._meta.default_format, |
| 1028 | 'allowed_list_http_methods': selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_schema().(self)._meta.list_allowed_methods, |
| 1029 | 'allowed_detail_http_methods': selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_schema().(self)._meta.detail_allowed_methods, |
| 1030 | 'default_limit': selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_schema().(self)._meta.limit, |
| 1031 | } |
| 1032 | |
| 1033 | if selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_schema().(self)._meta.ordering: |
| 1034 | data['ordering'] = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_schema().(self)._meta.ordering |
| 1035 | |
| 1036 | if selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_schema().(self)._meta.filtering: |
| 1037 | data['filtering'] = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_schema().(self)._meta.filtering |
| 1038 | |
| 1039 | # Skip assigning pk_field_name for non-model resources |
| 1040 | try: |
| 1041 | pk_field_name = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_schema().(self)._meta.queryset.model._meta.pk.name |
| 1042 | except AttributeErrorscip-python python python-stdlib 3.11 builtins/AttributeError#: |
| 1043 | pk_field_name = None |
| 1044 | |
| 1045 | for field_name, field_object in selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_schema().(self).fieldsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#fields..itemsscip-python python python-stdlib 3.11 builtins/dict#items().(): |
| 1046 | data['fields'][field_name] = { |
| 1047 | 'default': field_object.default, |
| 1048 | 'type': field_object.dehydrated_type, |
| 1049 | 'nullable': field_object.null, |
| 1050 | 'blank': field_object.blank, |
| 1051 | 'readonly': field_object.readonly, |
| 1052 | 'help_text': field_object.help_text, |
| 1053 | 'unique': field_object.unique, |
| 1054 | 'primary_key': True if field_name == pk_field_name else False, |
| 1055 | 'verbose_name': field_object.verbose_name or field_name.replace("_", " "), |
| 1056 | } |
| 1057 | |
| 1058 | if field_object.dehydrated_type == 'related': |
| 1059 | if field_object.is_m2m: |
| 1060 | related_type = 'to_many' |
| 1061 | else: |
| 1062 | related_type = 'to_one' |
| 1063 | data['fields'][field_name]['related_type'] = related_type |
| 1064 | try: |
| 1065 | uri = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_schema().(self)._build_reverse_urlscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#_build_reverse_url().('api_get_schema', kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#_build_reverse_url().(kwargs)={ |
| 1066 | 'api_name': selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_schema().(self)._meta.api_name, |
| 1067 | 'resource_name': field_object.to_class()._meta.resource_name |
| 1068 | }) |
| 1069 | except NoReverseMatch: |
| 1070 | uri = '' |
| 1071 | data['fields'][field_name]['related_schema'] = uri |
| 1072 | |
| 1073 | return data |
| 1074 | |
| 1075 | def dehydrate_resource_uriscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#dehydrate_resource_uri().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#dehydrate_resource_uri().(self), bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#dehydrate_resource_uri().(bundle)): |
| 1076 | """ |
| 1077 | For the automatically included ``resource_uri`` field, dehydrate |
| 1078 | the URI for the given bundle. |
| 1079 | |
| 1080 | Returns empty string if no URI can be generated. |
| 1081 | """ |
| 1082 | try: |
| 1083 | return selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#dehydrate_resource_uri().(self).get_resource_uriscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_resource_uri().(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#dehydrate_resource_uri().(bundle)) |
| 1084 | except NotImplementedErrorscip-python python python-stdlib 3.11 builtins/NotImplementedError#: |
| 1085 | return '' |
| 1086 | except NoReverseMatch: |
| 1087 | return '' |
| 1088 | |
| 1089 | def generate_cache_keyscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#generate_cache_key().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#generate_cache_key().(self), *argsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#generate_cache_key().(args), **kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#generate_cache_key().(kwargs)): |
| 1090 | """ |
| 1091 | Creates a unique-enough cache key. |
| 1092 | |
| 1093 | This is based off the current api_name/resource_name/args/kwargs. |
| 1094 | """ |
| 1095 | smooshed = ["%s=%s" % (key, value) for key, value in kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#generate_cache_key().(kwargs).itemsscip-python python python-stdlib 3.11 builtins/dict#items().()] |
| 1096 | |
| 1097 | # Use a list plus a ``.join()`` because it's faster than concatenation. |
| 1098 | return "%s:%s:%s:%s" % (selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#generate_cache_key().(self)._meta.api_name, selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#generate_cache_key().(self)._meta.resource_name, ':'.joinscip-python python python-stdlib 3.11 builtins/str#join().(argsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#generate_cache_key().(args)), ':'.joinscip-python python python-stdlib 3.11 builtins/str#join().(sortedscip-python python python-stdlib 3.11 builtins/sorted().(smooshed))) |
| 1099 | |
| 1100 | # Data access methods. |
| 1101 | |
| 1102 | def get_object_listscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_object_list().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_object_list().(self), requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_object_list().(request)): |
| 1103 | """ |
| 1104 | A hook to allow making returning the list of available objects. |
| 1105 | |
| 1106 | This needs to be implemented at the user level. |
| 1107 | |
| 1108 | ``ModelResource`` includes a full working version specific to Django's |
| 1109 | ``Models``. |
| 1110 | """ |
| 1111 | raise NotImplementedErrorscip-python python python-stdlib 3.11 builtins/NotImplementedError#() |
| 1112 | |
| 1113 | def can_createscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#can_create().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#can_create().(self)): |
| 1114 | """ |
| 1115 | Checks to ensure ``post`` is within ``allowed_methods``. |
| 1116 | """ |
| 1117 | allowed = setscip-python python python-stdlib 3.11 builtins/set#(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#can_create().(self)._meta.list_allowed_methods + selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#can_create().(self)._meta.detail_allowed_methods) |
| 1118 | return 'post' in allowed |
| 1119 | |
| 1120 | def can_updatescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#can_update().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#can_update().(self)): |
| 1121 | """ |
| 1122 | Checks to ensure ``put`` is within ``allowed_methods``. |
| 1123 | |
| 1124 | Used when hydrating related data. |
| 1125 | """ |
| 1126 | allowed = setscip-python python python-stdlib 3.11 builtins/set#(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#can_update().(self)._meta.list_allowed_methods + selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#can_update().(self)._meta.detail_allowed_methods) |
| 1127 | return 'put' in allowed |
| 1128 | |
| 1129 | def can_deletescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#can_delete().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#can_delete().(self)): |
| 1130 | """ |
| 1131 | Checks to ensure ``delete`` is within ``allowed_methods``. |
| 1132 | """ |
| 1133 | allowed = setscip-python python python-stdlib 3.11 builtins/set#(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#can_delete().(self)._meta.list_allowed_methods + selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#can_delete().(self)._meta.detail_allowed_methods) |
| 1134 | return 'delete' in allowed |
| 1135 | |
| 1136 | def apply_filtersscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#apply_filters().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#apply_filters().(self), requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#apply_filters().(request), applicable_filtersscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#apply_filters().(applicable_filters)): |
| 1137 | """ |
| 1138 | A hook to alter how the filters are applied to the object list. |
| 1139 | |
| 1140 | This needs to be implemented at the user level. |
| 1141 | |
| 1142 | ``ModelResource`` includes a full working version specific to Django's |
| 1143 | ``Models``. |
| 1144 | """ |
| 1145 | raise NotImplementedErrorscip-python python python-stdlib 3.11 builtins/NotImplementedError#() |
| 1146 | |
| 1147 | def obj_get_listscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#obj_get_list().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#obj_get_list().(self), bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#obj_get_list().(bundle), **kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#obj_get_list().(kwargs)): |
| 1148 | """ |
| 1149 | Fetches the list of objects available on the resource. |
| 1150 | |
| 1151 | This needs to be implemented at the user level. |
| 1152 | |
| 1153 | ``ModelResource`` includes a full working version specific to Django's |
| 1154 | ``Models``. |
| 1155 | """ |
| 1156 | raise NotImplementedErrorscip-python python python-stdlib 3.11 builtins/NotImplementedError#() |
| 1157 | |
| 1158 | def cached_obj_get_listscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#cached_obj_get_list().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#cached_obj_get_list().(self), bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#cached_obj_get_list().(bundle), **kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#cached_obj_get_list().(kwargs)): |
| 1159 | """ |
| 1160 | A version of ``obj_get_list`` that uses the cache as a means to get |
| 1161 | commonly-accessed data faster. |
| 1162 | """ |
| 1163 | cache_key = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#cached_obj_get_list().(self).generate_cache_keyscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#generate_cache_key().('list', **kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#cached_obj_get_list().(kwargs)) |
| 1164 | obj_list = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#cached_obj_get_list().(self)._meta.cache.get(cache_key) |
| 1165 | |
| 1166 | if obj_list is None: |
| 1167 | obj_list = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#cached_obj_get_list().(self).obj_get_listscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#obj_get_list().(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#obj_get_list().(bundle)=bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#cached_obj_get_list().(bundle), **kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#cached_obj_get_list().(kwargs)) |
| 1168 | selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#cached_obj_get_list().(self)._meta.cache.set(cache_key, obj_list) |
| 1169 | |
| 1170 | return obj_list |
| 1171 | |
| 1172 | def obj_getscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#obj_get().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#obj_get().(self), bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#obj_get().(bundle), **kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#obj_get().(kwargs)): |
| 1173 | """ |
| 1174 | Fetches an individual object on the resource. |
| 1175 | |
| 1176 | This needs to be implemented at the user level. If the object can not |
| 1177 | be found, this should raise a ``NotFound`` exception. |
| 1178 | |
| 1179 | ``ModelResource`` includes a full working version specific to Django's |
| 1180 | ``Models``. |
| 1181 | """ |
| 1182 | raise NotImplementedErrorscip-python python python-stdlib 3.11 builtins/NotImplementedError#() |
| 1183 | |
| 1184 | def cached_obj_getscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#cached_obj_get().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#cached_obj_get().(self), bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#cached_obj_get().(bundle), **kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#cached_obj_get().(kwargs)): |
| 1185 | """ |
| 1186 | A version of ``obj_get`` that uses the cache as a means to get |
| 1187 | commonly-accessed data faster. |
| 1188 | """ |
| 1189 | cache_key = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#cached_obj_get().(self).generate_cache_keyscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#generate_cache_key().('detail', **kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#cached_obj_get().(kwargs)) |
| 1190 | cached_bundle = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#cached_obj_get().(self)._meta.cache.get(cache_key) |
| 1191 | |
| 1192 | if cached_bundle is None: |
| 1193 | cached_bundle = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#cached_obj_get().(self).obj_getscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#obj_get().(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#obj_get().(bundle)=bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#cached_obj_get().(bundle), **kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#cached_obj_get().(kwargs)) |
| 1194 | selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#cached_obj_get().(self)._meta.cache.set(cache_key, cached_bundle) |
| 1195 | |
| 1196 | return cached_bundle |
| 1197 | |
| 1198 | def obj_createscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#obj_create().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#obj_create().(self), bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#obj_create().(bundle), **kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#obj_create().(kwargs)): |
| 1199 | """ |
| 1200 | Creates a new object based on the provided data. |
| 1201 | |
| 1202 | This needs to be implemented at the user level. |
| 1203 | |
| 1204 | ``ModelResource`` includes a full working version specific to Django's |
| 1205 | ``Models``. |
| 1206 | """ |
| 1207 | raise NotImplementedErrorscip-python python python-stdlib 3.11 builtins/NotImplementedError#() |
| 1208 | |
| 1209 | def obj_updatescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#obj_update().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#obj_update().(self), bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#obj_update().(bundle), **kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#obj_update().(kwargs)): |
| 1210 | """ |
| 1211 | Updates an existing object (or creates a new object) based on the |
| 1212 | provided data. |
| 1213 | |
| 1214 | This needs to be implemented at the user level. |
| 1215 | |
| 1216 | ``ModelResource`` includes a full working version specific to Django's |
| 1217 | ``Models``. |
| 1218 | """ |
| 1219 | raise NotImplementedErrorscip-python python python-stdlib 3.11 builtins/NotImplementedError#() |
| 1220 | |
| 1221 | def obj_delete_listscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#obj_delete_list().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#obj_delete_list().(self), bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#obj_delete_list().(bundle), **kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#obj_delete_list().(kwargs)): |
| 1222 | """ |
| 1223 | Deletes an entire list of objects. |
| 1224 | |
| 1225 | This needs to be implemented at the user level. |
| 1226 | |
| 1227 | ``ModelResource`` includes a full working version specific to Django's |
| 1228 | ``Models``. |
| 1229 | """ |
| 1230 | raise NotImplementedErrorscip-python python python-stdlib 3.11 builtins/NotImplementedError#() |
| 1231 | |
| 1232 | def obj_delete_list_for_updatescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#obj_delete_list_for_update().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#obj_delete_list_for_update().(self), bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#obj_delete_list_for_update().(bundle), **kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#obj_delete_list_for_update().(kwargs)): |
| 1233 | """ |
| 1234 | Deletes an entire list of objects, specific to PUT list. |
| 1235 | |
| 1236 | This needs to be implemented at the user level. |
| 1237 | |
| 1238 | ``ModelResource`` includes a full working version specific to Django's |
| 1239 | ``Models``. |
| 1240 | """ |
| 1241 | raise NotImplementedErrorscip-python python python-stdlib 3.11 builtins/NotImplementedError#() |
| 1242 | |
| 1243 | def obj_deletescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#obj_delete().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#obj_delete().(self), bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#obj_delete().(bundle), **kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#obj_delete().(kwargs)): |
| 1244 | """ |
| 1245 | Deletes a single object. |
| 1246 | |
| 1247 | This needs to be implemented at the user level. |
| 1248 | |
| 1249 | ``ModelResource`` includes a full working version specific to Django's |
| 1250 | ``Models``. |
| 1251 | """ |
| 1252 | raise NotImplementedErrorscip-python python python-stdlib 3.11 builtins/NotImplementedError#() |
| 1253 | |
| 1254 | def create_responsescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#create_response().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#create_response().(self), requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#create_response().(request), datascip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#create_response().(data), response_classscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#create_response().(response_class)=HttpResponse, **response_kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#create_response().(response_kwargs)): |
| 1255 | """ |
| 1256 | Extracts the common "which-format/serialize/return-response" cycle. |
| 1257 | |
| 1258 | Mostly a useful shortcut/hook. |
| 1259 | """ |
| 1260 | desired_format = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#create_response().(self).determine_formatscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#determine_format().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#create_response().(request)) |
| 1261 | serialized = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#create_response().(self).serializescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#serialize().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#create_response().(request), datascip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#create_response().(data), desired_format) |
| 1262 | return response_classscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#create_response().(response_class)(content=serialized, content_type=build_content_typescip-python python django-tastypie 0.15.1 `tastypie.utils.mime`/build_content_type().(desired_format), **response_kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#create_response().(response_kwargs)) |
| 1263 | |
| 1264 | def error_responsescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#error_response().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#error_response().(self), requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#error_response().(request), errorsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#error_response().(errors), response_classscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#error_response().(response_class)=None): |
| 1265 | """ |
| 1266 | Extracts the common "which-format/serialize/return-error-response" |
| 1267 | cycle. |
| 1268 | |
| 1269 | Should be used as much as possible to return errors. |
| 1270 | """ |
| 1271 | if response_classscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#error_response().(response_class) is None: |
| 1272 | response_classscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#error_response().(response_class) = httpscip-python python django-tastypie 0.15.1 `tastypie.http`/__init__:.HttpBadRequestscip-python python django-tastypie 0.15.1 `tastypie.http`/HttpBadRequest# |
| 1273 | |
| 1274 | desired_format = None |
| 1275 | |
| 1276 | if requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#error_response().(request): |
| 1277 | if requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#error_response().(request).GET.get('callback', None) is None: |
| 1278 | try: |
| 1279 | desired_format = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#error_response().(self).determine_formatscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#determine_format().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#error_response().(request)) |
| 1280 | except BadRequestscip-python python django-tastypie 0.15.1 `tastypie.exceptions`/BadRequest#: |
| 1281 | pass # Fall through to default handler below |
| 1282 | else: |
| 1283 | # JSONP can cause extra breakage. |
| 1284 | desired_format = 'application/json' |
| 1285 | |
| 1286 | if not desired_format: |
| 1287 | desired_format = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#error_response().(self)._meta.default_format |
| 1288 | |
| 1289 | try: |
| 1290 | serialized = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#error_response().(self).serializescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#serialize().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#error_response().(request), errorsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#error_response().(errors), desired_format) |
| 1291 | except BadRequestscip-python python django-tastypie 0.15.1 `tastypie.exceptions`/BadRequest# as e: |
| 1292 | error = "Additional errors occurred, but serialization of those errors failed." |
| 1293 | |
| 1294 | if settings.DEBUG: |
| 1295 | error += " %s" % e |
| 1296 | |
| 1297 | return response_classscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#error_response().(response_class)(content=error, content_type='text/plain') |
| 1298 | |
| 1299 | return response_classscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#error_response().(response_class)(content=serialized, content_type=build_content_typescip-python python django-tastypie 0.15.1 `tastypie.utils.mime`/build_content_type().(desired_format)) |
| 1300 | |
| 1301 | def is_validscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#is_valid().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#is_valid().(self), bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#is_valid().(bundle)): |
| 1302 | """ |
| 1303 | Handles checking if the data provided by the user is valid. |
| 1304 | |
| 1305 | Mostly a hook, this uses class assigned to ``validation`` from |
| 1306 | ``Resource._meta``. |
| 1307 | |
| 1308 | If validation fails, an error is raised with the error messages |
| 1309 | serialized inside it. |
| 1310 | """ |
| 1311 | errors = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#is_valid().(self)._meta.validation.is_valid(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#is_valid().(bundle), bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#is_valid().(bundle).request) |
| 1312 | |
| 1313 | if errors: |
| 1314 | bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#is_valid().(bundle).errors[selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#is_valid().(self)._meta.resource_name] = errors |
| 1315 | return False |
| 1316 | |
| 1317 | return True |
| 1318 | |
| 1319 | def rollbackscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#rollback().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#rollback().(self), bundlesscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#rollback().(bundles)): |
| 1320 | """ |
| 1321 | Given the list of bundles, delete all objects pertaining to those |
| 1322 | bundles. |
| 1323 | |
| 1324 | This needs to be implemented at the user level. No exceptions should |
| 1325 | be raised if possible. |
| 1326 | |
| 1327 | ``ModelResource`` includes a full working version specific to Django's |
| 1328 | ``Models``. |
| 1329 | """ |
| 1330 | raise NotImplementedErrorscip-python python python-stdlib 3.11 builtins/NotImplementedError#() |
| 1331 | |
| 1332 | # Views. |
| 1333 | |
| 1334 | def get_listscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_list().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_list().(self), requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_list().(request), **kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_list().(kwargs)): |
| 1335 | """ |
| 1336 | Returns a serialized list of resources. |
| 1337 | |
| 1338 | Calls ``obj_get_list`` to provide the data, then handles that result |
| 1339 | set and serializes it. |
| 1340 | |
| 1341 | Should return a HttpResponse (200 OK). |
| 1342 | """ |
| 1343 | # TODO: Uncached for now. Invalidation that works for everyone may be |
| 1344 | # impossible. |
| 1345 | base_bundle = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_list().(self).build_bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_bundle().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_bundle().(request)=requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_list().(request)) |
| 1346 | objects = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_list().(self).obj_get_listscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#obj_get_list().(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#obj_get_list().(bundle)=base_bundle, **selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_list().(self).remove_api_resource_namesscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#remove_api_resource_names().(kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_list().(kwargs))) |
| 1347 | sorted_objects = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_list().(self).apply_sortingscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#apply_sorting().(objects, optionsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#apply_sorting().(options)=requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_list().(request).GET) |
| 1348 | |
| 1349 | paginator = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_list().(self)._meta.paginator_class(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_list().(request).GET, sorted_objects, resource_uri=selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_list().(self).get_resource_uriscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_resource_uri().(), limit=selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_list().(self)._meta.limit, max_limit=selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_list().(self)._meta.max_limit, collection_name=selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_list().(self)._meta.collection_name) |
| 1350 | to_be_serialized = paginator.page() |
| 1351 | |
| 1352 | # Dehydrate the bundles in preparation for serialization. |
| 1353 | bundles = [ |
| 1354 | selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_list().(self).full_dehydratescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#full_dehydrate().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_list().(self).build_bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_bundle().(objscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_bundle().(obj)=obj, requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_bundle().(request)=requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_list().(request)), for_listscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#full_dehydrate().(for_list)=True) |
| 1355 | for obj in to_be_serialized[selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_list().(self)._meta.collection_name] |
| 1356 | ] |
| 1357 | |
| 1358 | to_be_serialized[selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_list().(self)._meta.collection_name] = bundles |
| 1359 | to_be_serialized = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_list().(self).alter_list_data_to_serializescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#alter_list_data_to_serialize().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_list().(request), to_be_serialized) |
| 1360 | return selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_list().(self).create_responsescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#create_response().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_list().(request), to_be_serialized) |
| 1361 | |
| 1362 | def get_detailscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_detail().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_detail().(self), requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_detail().(request), **kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_detail().(kwargs)): |
| 1363 | """ |
| 1364 | Returns a single serialized resource. |
| 1365 | |
| 1366 | Calls ``cached_obj_get/obj_get`` to provide the data, then handles that result |
| 1367 | set and serializes it. |
| 1368 | |
| 1369 | Should return a HttpResponse (200 OK). |
| 1370 | """ |
| 1371 | basic_bundle = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_detail().(self).build_bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_bundle().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_bundle().(request)=requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_detail().(request)) |
| 1372 | |
| 1373 | try: |
| 1374 | obj = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_detail().(self).cached_obj_getscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#cached_obj_get().(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#cached_obj_get().(bundle)=basic_bundle, **selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_detail().(self).remove_api_resource_namesscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#remove_api_resource_names().(kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_detail().(kwargs))) |
| 1375 | except ObjectDoesNotExist: |
| 1376 | return httpscip-python python django-tastypie 0.15.1 `tastypie.http`/__init__:.HttpNotFoundscip-python python django-tastypie 0.15.1 `tastypie.http`/HttpNotFound#() |
| 1377 | except MultipleObjectsReturned: |
| 1378 | return httpscip-python python django-tastypie 0.15.1 `tastypie.http`/__init__:.HttpMultipleChoicesscip-python python django-tastypie 0.15.1 `tastypie.http`/HttpMultipleChoices#("More than one resource is found at this URI.") |
| 1379 | |
| 1380 | bundle = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_detail().(self).build_bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_bundle().(objscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_bundle().(obj)=obj, requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_bundle().(request)=requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_detail().(request)) |
| 1381 | bundle = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_detail().(self).full_dehydratescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#full_dehydrate().(bundle) |
| 1382 | bundle = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_detail().(self).alter_detail_data_to_serializescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#alter_detail_data_to_serialize().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_detail().(request), bundle) |
| 1383 | return selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_detail().(self).create_responsescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#create_response().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_detail().(request), bundle) |
| 1384 | |
| 1385 | def post_listscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#post_list().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#post_list().(self), requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#post_list().(request), **kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#post_list().(kwargs)): |
| 1386 | """ |
| 1387 | Creates a new resource/object with the provided data. |
| 1388 | |
| 1389 | Calls ``obj_create`` with the provided data and returns a response |
| 1390 | with the new resource's location. |
| 1391 | |
| 1392 | If a new resource is created, return ``HttpCreated`` (201 Created). |
| 1393 | If ``Meta.always_return_data = True``, there will be a populated body |
| 1394 | of serialized data. |
| 1395 | """ |
| 1396 | deserialized = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#post_list().(self).deserializescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#deserialize().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#post_list().(request), requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#post_list().(request).body, formatscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#deserialize().(format)=requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#post_list().(request).META.get('CONTENT_TYPE', 'application/json')) |
| 1397 | deserialized = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#post_list().(self).alter_deserialized_detail_datascip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#alter_deserialized_detail_data().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#post_list().(request), deserialized) |
| 1398 | bundle = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#post_list().(self).build_bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_bundle().(datascip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_bundle().(data)=deserialized, requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_bundle().(request)=requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#post_list().(request)) |
| 1399 | updated_bundle = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#post_list().(self).obj_createscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#obj_create().(bundle, **selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#post_list().(self).remove_api_resource_namesscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#remove_api_resource_names().(kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#post_list().(kwargs))) |
| 1400 | location = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#post_list().(self).get_resource_uriscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_resource_uri().(updated_bundle) |
| 1401 | |
| 1402 | if not selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#post_list().(self)._meta.always_return_data: |
| 1403 | return httpscip-python python django-tastypie 0.15.1 `tastypie.http`/__init__:.HttpCreatedscip-python python django-tastypie 0.15.1 `tastypie.http`/HttpCreated#(location=location) |
| 1404 | else: |
| 1405 | updated_bundle = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#post_list().(self).full_dehydratescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#full_dehydrate().(updated_bundle) |
| 1406 | updated_bundle = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#post_list().(self).alter_detail_data_to_serializescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#alter_detail_data_to_serialize().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#post_list().(request), updated_bundle) |
| 1407 | return selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#post_list().(self).create_responsescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#create_response().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#post_list().(request), updated_bundle, response_classscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#create_response().(response_class)=httpscip-python python django-tastypie 0.15.1 `tastypie.http`/__init__:.HttpCreatedscip-python python django-tastypie 0.15.1 `tastypie.http`/HttpCreated#, location=location) |
| 1408 | |
| 1409 | def post_detailscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#post_detail().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#post_detail().(self), requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#post_detail().(request), **kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#post_detail().(kwargs)): |
| 1410 | """ |
| 1411 | Creates a new subcollection of the resource under a resource. |
| 1412 | |
| 1413 | This is not implemented by default because most people's data models |
| 1414 | aren't self-referential. |
| 1415 | |
| 1416 | If a new resource is created, return ``HttpCreated`` (201 Created). |
| 1417 | """ |
| 1418 | return httpscip-python python django-tastypie 0.15.1 `tastypie.http`/__init__:.HttpNotImplementedscip-python python django-tastypie 0.15.1 `tastypie.http`/HttpNotImplemented#() |
| 1419 | |
| 1420 | def put_listscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#put_list().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#put_list().(self), requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#put_list().(request), **kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#put_list().(kwargs)): |
| 1421 | """ |
| 1422 | Replaces a collection of resources with another collection. |
| 1423 | |
| 1424 | Calls ``delete_list`` to clear out the collection then ``obj_create`` |
| 1425 | with the provided the data to create the new collection. |
| 1426 | |
| 1427 | Return ``HttpNoContent`` (204 No Content) if |
| 1428 | ``Meta.always_return_data = False`` (default). |
| 1429 | |
| 1430 | Return ``HttpResponse`` (200 OK) with new data if |
| 1431 | ``Meta.always_return_data = True``. |
| 1432 | """ |
| 1433 | deserialized = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#put_list().(self).deserializescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#deserialize().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#put_list().(request), requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#put_list().(request).body, formatscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#deserialize().(format)=requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#put_list().(request).META.get('CONTENT_TYPE', 'application/json')) |
| 1434 | deserialized = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#put_list().(self).alter_deserialized_list_datascip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#alter_deserialized_list_data().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#put_list().(request), deserialized) |
| 1435 | |
| 1436 | if selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#put_list().(self)._meta.collection_name not in deserialized: |
| 1437 | raise BadRequestscip-python python django-tastypie 0.15.1 `tastypie.exceptions`/BadRequest#("Invalid data sent: missing '%s'" % selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#put_list().(self)._meta.collection_name) |
| 1438 | |
| 1439 | basic_bundle = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#put_list().(self).build_bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_bundle().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_bundle().(request)=requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#put_list().(request)) |
| 1440 | selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#put_list().(self).obj_delete_list_for_updatescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#obj_delete_list_for_update().(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#obj_delete_list_for_update().(bundle)=basic_bundle, **selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#put_list().(self).remove_api_resource_namesscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#remove_api_resource_names().(kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#put_list().(kwargs))) |
| 1441 | bundles_seen = [] |
| 1442 | |
| 1443 | for object_data in deserialized[selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#put_list().(self)._meta.collection_name]: |
| 1444 | bundle = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#put_list().(self).build_bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_bundle().(datascip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_bundle().(data)=object_data, requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_bundle().(request)=requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#put_list().(request)) |
| 1445 | |
| 1446 | # Attempt to be transactional, deleting any previously created |
| 1447 | # objects if validation fails. |
| 1448 | try: |
| 1449 | selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#put_list().(self).obj_createscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#obj_create().(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#obj_create().(bundle)=bundle, **selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#put_list().(self).remove_api_resource_namesscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#remove_api_resource_names().(kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#put_list().(kwargs))) |
| 1450 | bundles_seen.appendscip-python python python-stdlib 3.11 builtins/list#append().(bundle) |
| 1451 | except ImmediateHttpResponsescip-python python django-tastypie 0.15.1 `tastypie.exceptions`/ImmediateHttpResponse#: |
| 1452 | selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#put_list().(self).rollbackscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#rollback().(bundles_seen) |
| 1453 | raise |
| 1454 | |
| 1455 | if not selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#put_list().(self)._meta.always_return_data: |
| 1456 | return httpscip-python python django-tastypie 0.15.1 `tastypie.http`/__init__:.HttpNoContentscip-python python django-tastypie 0.15.1 `tastypie.http`/HttpNoContent#() |
| 1457 | else: |
| 1458 | to_be_serialized = { |
| 1459 | selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#put_list().(self)._meta.collection_name: [ |
| 1460 | selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#put_list().(self).full_dehydratescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#full_dehydrate().(b, for_listscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#full_dehydrate().(for_list)=True) |
| 1461 | for b in bundles_seen |
| 1462 | ] |
| 1463 | } |
| 1464 | to_be_serialized = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#put_list().(self).alter_list_data_to_serializescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#alter_list_data_to_serialize().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#put_list().(request), to_be_serialized) |
| 1465 | return selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#put_list().(self).create_responsescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#create_response().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#put_list().(request), to_be_serialized) |
| 1466 | |
| 1467 | def put_detailscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#put_detail().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#put_detail().(self), requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#put_detail().(request), **kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#put_detail().(kwargs)): |
| 1468 | """ |
| 1469 | Either updates an existing resource or creates a new one with the |
| 1470 | provided data. |
| 1471 | |
| 1472 | Calls ``obj_update`` with the provided data first, but falls back to |
| 1473 | ``obj_create`` if the object does not already exist. |
| 1474 | |
| 1475 | If a new resource is created, return ``HttpCreated`` (201 Created). |
| 1476 | If ``Meta.always_return_data = True``, there will be a populated body |
| 1477 | of serialized data. |
| 1478 | |
| 1479 | If an existing resource is modified and |
| 1480 | ``Meta.always_return_data = False`` (default), return ``HttpNoContent`` |
| 1481 | (204 No Content). |
| 1482 | If an existing resource is modified and |
| 1483 | ``Meta.always_return_data = True``, return ``HttpAccepted`` (200 |
| 1484 | OK). |
| 1485 | """ |
| 1486 | deserialized = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#put_detail().(self).deserializescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#deserialize().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#put_detail().(request), requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#put_detail().(request).body, formatscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#deserialize().(format)=requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#put_detail().(request).META.get('CONTENT_TYPE', 'application/json')) |
| 1487 | deserialized = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#put_detail().(self).alter_deserialized_detail_datascip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#alter_deserialized_detail_data().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#put_detail().(request), deserialized) |
| 1488 | bundle = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#put_detail().(self).build_bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_bundle().(datascip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_bundle().(data)=deserialized, requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_bundle().(request)=requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#put_detail().(request)) |
| 1489 | |
| 1490 | try: |
| 1491 | updated_bundle = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#put_detail().(self).obj_updatescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#obj_update().(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#obj_update().(bundle)=bundle, **selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#put_detail().(self).remove_api_resource_namesscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#remove_api_resource_names().(kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#put_detail().(kwargs))) |
| 1492 | |
| 1493 | if not selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#put_detail().(self)._meta.always_return_data: |
| 1494 | return httpscip-python python django-tastypie 0.15.1 `tastypie.http`/__init__:.HttpNoContentscip-python python django-tastypie 0.15.1 `tastypie.http`/HttpNoContent#() |
| 1495 | else: |
| 1496 | # Invalidate prefetched_objects_cache for bundled object |
| 1497 | # because we might have changed a prefetched field |
| 1498 | updated_bundle.obj._prefetched_objects_cache = {} |
| 1499 | updated_bundle = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#put_detail().(self).full_dehydratescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#full_dehydrate().(updated_bundle) |
| 1500 | updated_bundle = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#put_detail().(self).alter_detail_data_to_serializescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#alter_detail_data_to_serialize().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#put_detail().(request), updated_bundle) |
| 1501 | return selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#put_detail().(self).create_responsescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#create_response().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#put_detail().(request), updated_bundle) |
| 1502 | except (NotFoundscip-python python django-tastypie 0.15.1 `tastypie.exceptions`/NotFound#, MultipleObjectsReturned): |
| 1503 | updated_bundle = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#put_detail().(self).obj_createscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#obj_create().(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#obj_create().(bundle)=bundle, **selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#put_detail().(self).remove_api_resource_namesscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#remove_api_resource_names().(kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#put_detail().(kwargs))) |
| 1504 | location = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#put_detail().(self).get_resource_uriscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_resource_uri().(updated_bundle) |
| 1505 | |
| 1506 | if not selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#put_detail().(self)._meta.always_return_data: |
| 1507 | return httpscip-python python django-tastypie 0.15.1 `tastypie.http`/__init__:.HttpCreatedscip-python python django-tastypie 0.15.1 `tastypie.http`/HttpCreated#(location=location) |
| 1508 | else: |
| 1509 | updated_bundle = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#put_detail().(self).full_dehydratescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#full_dehydrate().(updated_bundle) |
| 1510 | updated_bundle = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#put_detail().(self).alter_detail_data_to_serializescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#alter_detail_data_to_serialize().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#put_detail().(request), updated_bundle) |
| 1511 | return selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#put_detail().(self).create_responsescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#create_response().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#put_detail().(request), updated_bundle, response_classscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#create_response().(response_class)=httpscip-python python django-tastypie 0.15.1 `tastypie.http`/__init__:.HttpCreatedscip-python python django-tastypie 0.15.1 `tastypie.http`/HttpCreated#, location=location) |
| 1512 | |
| 1513 | def delete_listscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#delete_list().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#delete_list().(self), requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#delete_list().(request), **kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#delete_list().(kwargs)): |
| 1514 | """ |
| 1515 | Destroys a collection of resources/objects. |
| 1516 | |
| 1517 | Calls ``obj_delete_list``. |
| 1518 | |
| 1519 | If the resources are deleted, return ``HttpNoContent`` (204 No Content). |
| 1520 | """ |
| 1521 | bundle = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#delete_list().(self).build_bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_bundle().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_bundle().(request)=requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#delete_list().(request)) |
| 1522 | selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#delete_list().(self).obj_delete_listscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#obj_delete_list().(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#obj_delete_list().(bundle)=bundle, request=requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#delete_list().(request), **selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#delete_list().(self).remove_api_resource_namesscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#remove_api_resource_names().(kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#delete_list().(kwargs))) |
| 1523 | return httpscip-python python django-tastypie 0.15.1 `tastypie.http`/__init__:.HttpNoContentscip-python python django-tastypie 0.15.1 `tastypie.http`/HttpNoContent#() |
| 1524 | |
| 1525 | def delete_detailscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#delete_detail().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#delete_detail().(self), requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#delete_detail().(request), **kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#delete_detail().(kwargs)): |
| 1526 | """ |
| 1527 | Destroys a single resource/object. |
| 1528 | |
| 1529 | Calls ``obj_delete``. |
| 1530 | |
| 1531 | If the resource is deleted, return ``HttpNoContent`` (204 No Content). |
| 1532 | If the resource did not exist, return ``Http404`` (404 Not Found). |
| 1533 | """ |
| 1534 | # Manually construct the bundle here, since we don't want to try to |
| 1535 | # delete an empty instance. |
| 1536 | bundle = Bundlescip-python python django-tastypie 0.15.1 `tastypie.bundle`/Bundle#(requestscip-python python django-tastypie 0.15.1 `tastypie.bundle`/Bundle#__init__().(request)=requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#delete_detail().(request)) |
| 1537 | |
| 1538 | try: |
| 1539 | selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#delete_detail().(self).obj_deletescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#obj_delete().(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#obj_delete().(bundle)=bundle, **selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#delete_detail().(self).remove_api_resource_namesscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#remove_api_resource_names().(kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#delete_detail().(kwargs))) |
| 1540 | return httpscip-python python django-tastypie 0.15.1 `tastypie.http`/__init__:.HttpNoContentscip-python python django-tastypie 0.15.1 `tastypie.http`/HttpNoContent#() |
| 1541 | except NotFoundscip-python python django-tastypie 0.15.1 `tastypie.exceptions`/NotFound#: |
| 1542 | return httpscip-python python django-tastypie 0.15.1 `tastypie.http`/__init__:.HttpNotFoundscip-python python django-tastypie 0.15.1 `tastypie.http`/HttpNotFound#() |
| 1543 | |
| 1544 | def patch_listscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_list().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_list().(self), requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_list().(request), **kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_list().(kwargs)): |
| 1545 | """ |
| 1546 | Updates a collection in-place. |
| 1547 | |
| 1548 | The exact behavior of ``PATCH`` to a list resource is still the matter of |
| 1549 | some debate in REST circles, and the ``PATCH`` RFC isn't standard. So the |
| 1550 | behavior this method implements (described below) is something of a |
| 1551 | stab in the dark. It's mostly cribbed from GData, with a smattering |
| 1552 | of ActiveResource-isms and maybe even an original idea or two. |
| 1553 | |
| 1554 | The ``PATCH`` format is one that's similar to the response returned from |
| 1555 | a ``GET`` on a list resource:: |
| 1556 | |
| 1557 | { |
| 1558 | "objects": [{object}, {object}, ...], |
| 1559 | "deleted_objects": ["URI", "URI", "URI", ...], |
| 1560 | } |
| 1561 | |
| 1562 | For each object in ``objects``: |
| 1563 | |
| 1564 | * If the dict does not have a ``resource_uri`` key then the item is |
| 1565 | considered "new" and is handled like a ``POST`` to the resource list. |
| 1566 | |
| 1567 | * If the dict has a ``resource_uri`` key and the ``resource_uri`` refers |
| 1568 | to an existing resource then the item is a update; it's treated |
| 1569 | like a ``PATCH`` to the corresponding resource detail. |
| 1570 | |
| 1571 | * If the dict has a ``resource_uri`` but the resource *doesn't* exist, |
| 1572 | then this is considered to be a create-via-``PUT``. |
| 1573 | |
| 1574 | Each entry in ``deleted_objects`` referes to a resource URI of an existing |
| 1575 | resource to be deleted; each is handled like a ``DELETE`` to the relevent |
| 1576 | resource. |
| 1577 | |
| 1578 | In any case: |
| 1579 | |
| 1580 | * If there's a resource URI it *must* refer to a resource of this |
| 1581 | type. It's an error to include a URI of a different resource. |
| 1582 | |
| 1583 | * ``PATCH`` is all or nothing. If a single sub-operation fails, the |
| 1584 | entire request will fail and all resources will be rolled back. |
| 1585 | |
| 1586 | * For ``PATCH`` to work, you **must** have ``put`` in your |
| 1587 | :ref:`detail-allowed-methods` setting. |
| 1588 | |
| 1589 | * To delete objects via ``deleted_objects`` in a ``PATCH`` request you |
| 1590 | **must** have ``delete`` in your :ref:`detail-allowed-methods` |
| 1591 | setting. |
| 1592 | |
| 1593 | Substitute appropriate names for ``objects`` and |
| 1594 | ``deleted_objects`` if ``Meta.collection_name`` is set to something |
| 1595 | other than ``objects`` (default). |
| 1596 | """ |
| 1597 | requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_list().(request) = convert_post_to_patchscip-python python django-tastypie 0.15.1 `tastypie.resources`/convert_post_to_patch().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_list().(request)) |
| 1598 | deserialized = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_list().(self).deserializescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#deserialize().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_list().(request), requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_list().(request).body, formatscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#deserialize().(format)=requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_list().(request).META.get('CONTENT_TYPE', 'application/json')) |
| 1599 | |
| 1600 | collection_name = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_list().(self)._meta.collection_name |
| 1601 | deleted_collection_name = 'deleted_%s' % collection_name |
| 1602 | if collection_name not in deserialized: |
| 1603 | raise BadRequestscip-python python django-tastypie 0.15.1 `tastypie.exceptions`/BadRequest#("Invalid data sent: missing '%s'" % collection_name) |
| 1604 | |
| 1605 | if len(deserialized[collection_name]) and 'put' not in selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_list().(self)._meta.detail_allowed_methods: |
| 1606 | raise ImmediateHttpResponsescip-python python django-tastypie 0.15.1 `tastypie.exceptions`/ImmediateHttpResponse#(responsescip-python python django-tastypie 0.15.1 `tastypie.exceptions`/ImmediateHttpResponse#__init__().(response)=httpscip-python python django-tastypie 0.15.1 `tastypie.http`/__init__:.HttpMethodNotAllowedscip-python python django-tastypie 0.15.1 `tastypie.http`/HttpMethodNotAllowed#()) |
| 1607 | |
| 1608 | bundles_seen = [] |
| 1609 | |
| 1610 | for data in deserialized[collection_name]: |
| 1611 | # If there's a resource_uri then this is either an |
| 1612 | # update-in-place or a create-via-PUT. |
| 1613 | if "resource_uri" in data: |
| 1614 | uri = data.pop('resource_uri') |
| 1615 | |
| 1616 | try: |
| 1617 | obj = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_list().(self).get_via_uriscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_via_uri().(uri, requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_via_uri().(request)=requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_list().(request)) |
| 1618 | |
| 1619 | # The object does exist, so this is an update-in-place. |
| 1620 | bundle = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_list().(self).build_bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_bundle().(objscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_bundle().(obj)=obj, requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_bundle().(request)=requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_list().(request)) |
| 1621 | bundle = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_list().(self).full_dehydratescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#full_dehydrate().(bundle, for_listscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#full_dehydrate().(for_list)=True) |
| 1622 | bundle = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_list().(self).alter_detail_data_to_serializescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#alter_detail_data_to_serialize().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_list().(request), bundle) |
| 1623 | selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_list().(self).update_in_placescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#update_in_place().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_list().(request), bundle, data) |
| 1624 | except (ObjectDoesNotExist, MultipleObjectsReturned): |
| 1625 | # The object referenced by resource_uri doesn't exist, |
| 1626 | # so this is a create-by-PUT equivalent. |
| 1627 | data = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_list().(self).alter_deserialized_detail_datascip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#alter_deserialized_detail_data().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_list().(request), data) |
| 1628 | bundle = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_list().(self).build_bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_bundle().(datascip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_bundle().(data)=data, requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_bundle().(request)=requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_list().(request)) |
| 1629 | selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_list().(self).obj_createscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#obj_create().(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#obj_create().(bundle)=bundle) |
| 1630 | else: |
| 1631 | # There's no resource URI, so this is a create call just |
| 1632 | # like a POST to the list resource. |
| 1633 | data = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_list().(self).alter_deserialized_detail_datascip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#alter_deserialized_detail_data().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_list().(request), data) |
| 1634 | bundle = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_list().(self).build_bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_bundle().(datascip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_bundle().(data)=data, requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_bundle().(request)=requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_list().(request)) |
| 1635 | selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_list().(self).obj_createscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#obj_create().(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#obj_create().(bundle)=bundle) |
| 1636 | |
| 1637 | bundles_seen.appendscip-python python python-stdlib 3.11 builtins/list#append().(bundle) |
| 1638 | |
| 1639 | deleted_collection = deserialized.get(deleted_collection_name, []) |
| 1640 | |
| 1641 | if deleted_collection: |
| 1642 | if 'delete' not in selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_list().(self)._meta.detail_allowed_methods: |
| 1643 | raise ImmediateHttpResponsescip-python python django-tastypie 0.15.1 `tastypie.exceptions`/ImmediateHttpResponse#(responsescip-python python django-tastypie 0.15.1 `tastypie.exceptions`/ImmediateHttpResponse#__init__().(response)=httpscip-python python django-tastypie 0.15.1 `tastypie.http`/__init__:.HttpMethodNotAllowedscip-python python django-tastypie 0.15.1 `tastypie.http`/HttpMethodNotAllowed#()) |
| 1644 | |
| 1645 | for uri in deleted_collection: |
| 1646 | obj = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_list().(self).get_via_uriscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_via_uri().(uri, requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_via_uri().(request)=requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_list().(request)) |
| 1647 | bundle = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_list().(self).build_bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_bundle().(objscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_bundle().(obj)=obj, requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_bundle().(request)=requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_list().(request)) |
| 1648 | selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_list().(self).obj_deletescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#obj_delete().(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#obj_delete().(bundle)=bundle) |
| 1649 | |
| 1650 | if not selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_list().(self)._meta.always_return_data: |
| 1651 | return httpscip-python python django-tastypie 0.15.1 `tastypie.http`/__init__:.HttpAcceptedscip-python python django-tastypie 0.15.1 `tastypie.http`/HttpAccepted#() |
| 1652 | else: |
| 1653 | to_be_serialized = { |
| 1654 | 'objects': [ |
| 1655 | selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_list().(self).full_dehydratescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#full_dehydrate().(b, for_listscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#full_dehydrate().(for_list)=True) |
| 1656 | for b in bundles_seen |
| 1657 | ] |
| 1658 | } |
| 1659 | to_be_serialized = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_list().(self).alter_list_data_to_serializescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#alter_list_data_to_serialize().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_list().(request), to_be_serialized) |
| 1660 | return selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_list().(self).create_responsescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#create_response().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_list().(request), to_be_serialized, response_classscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#create_response().(response_class)=httpscip-python python django-tastypie 0.15.1 `tastypie.http`/__init__:.HttpAcceptedscip-python python django-tastypie 0.15.1 `tastypie.http`/HttpAccepted#) |
| 1661 | |
| 1662 | def patch_detailscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_detail().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_detail().(self), requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_detail().(request), **kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_detail().(kwargs)): |
| 1663 | """ |
| 1664 | Updates a resource in-place. |
| 1665 | |
| 1666 | Calls ``obj_update``. |
| 1667 | |
| 1668 | If the resource is updated, return ``HttpAccepted`` (202 Accepted). |
| 1669 | If the resource did not exist, return ``HttpNotFound`` (404 Not Found). |
| 1670 | """ |
| 1671 | requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_detail().(request) = convert_post_to_patchscip-python python django-tastypie 0.15.1 `tastypie.resources`/convert_post_to_patch().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_detail().(request)) |
| 1672 | basic_bundle = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_detail().(self).build_bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_bundle().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_bundle().(request)=requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_detail().(request)) |
| 1673 | |
| 1674 | # We want to be able to validate the update, but we can't just pass |
| 1675 | # the partial data into the validator since all data needs to be |
| 1676 | # present. Instead, we basically simulate a PUT by pulling out the |
| 1677 | # original data and updating it in-place. |
| 1678 | # So first pull out the original object. This is essentially |
| 1679 | # ``get_detail``. |
| 1680 | try: |
| 1681 | obj = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_detail().(self).cached_obj_getscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#cached_obj_get().(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#cached_obj_get().(bundle)=basic_bundle, **selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_detail().(self).remove_api_resource_namesscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#remove_api_resource_names().(kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_detail().(kwargs))) |
| 1682 | except ObjectDoesNotExist: |
| 1683 | return httpscip-python python django-tastypie 0.15.1 `tastypie.http`/__init__:.HttpNotFoundscip-python python django-tastypie 0.15.1 `tastypie.http`/HttpNotFound#() |
| 1684 | except MultipleObjectsReturned: |
| 1685 | return httpscip-python python django-tastypie 0.15.1 `tastypie.http`/__init__:.HttpMultipleChoicesscip-python python django-tastypie 0.15.1 `tastypie.http`/HttpMultipleChoices#("More than one resource is found at this URI.") |
| 1686 | |
| 1687 | bundle = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_detail().(self).build_bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_bundle().(objscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_bundle().(obj)=obj, requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_bundle().(request)=requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_detail().(request)) |
| 1688 | bundle = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_detail().(self).full_dehydratescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#full_dehydrate().(bundle) |
| 1689 | bundle = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_detail().(self).alter_detail_data_to_serializescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#alter_detail_data_to_serialize().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_detail().(request), bundle) |
| 1690 | |
| 1691 | # Now update the bundle in-place. |
| 1692 | deserialized = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_detail().(self).deserializescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#deserialize().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_detail().(request), requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_detail().(request).body, formatscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#deserialize().(format)=requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_detail().(request).META.get('CONTENT_TYPE', 'application/json')) |
| 1693 | # Create a place to store the names of those fields we want to update |
| 1694 | bundle.update_fields = [] |
| 1695 | bundle.m2m_update_fields = [] |
| 1696 | # When we get to the obj.save() stage, we need to know which fields have changed |
| 1697 | # Otherwise we can't do a proper update. Thus, |
| 1698 | # For every key in deserialized (e.g. the fields submitted in the PATCH) |
| 1699 | for key in deserialized: |
| 1700 | # If the key is a property of the object, lets add it to the list, except: |
| 1701 | if hasattr(bundle.obj, key): |
| 1702 | # Can't update_fields an m2m field, so instead add it to patch_m2m_fields |
| 1703 | if getattrscip-python python python-stdlib 3.11 builtins/getattr().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_detail().(self).fieldsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#fields.[key], 'is_m2m', False): |
| 1704 | bundle.m2m_update_fields.appendscip-python python python-stdlib 3.11 builtins/list#append().(key) |
| 1705 | continue |
| 1706 | # Don't add if it is the id/pk field, can't patch that. |
| 1707 | if key == 'id' or key == 'pk': |
| 1708 | continue |
| 1709 | # No more checks. Add it. |
| 1710 | bundle.update_fields.appendscip-python python python-stdlib 3.11 builtins/list#append().(key) |
| 1711 | selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_detail().(self).update_in_placescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#update_in_place().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_detail().(request), bundle, deserialized) |
| 1712 | |
| 1713 | if not selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_detail().(self)._meta.always_return_data: |
| 1714 | return httpscip-python python django-tastypie 0.15.1 `tastypie.http`/__init__:.HttpAcceptedscip-python python django-tastypie 0.15.1 `tastypie.http`/HttpAccepted#() |
| 1715 | else: |
| 1716 | # Invalidate prefetched_objects_cache for bundled object |
| 1717 | # because we might have changed a prefetched field |
| 1718 | bundle.obj._prefetched_objects_cache = {} |
| 1719 | bundle = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_detail().(self).full_dehydratescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#full_dehydrate().(bundle) |
| 1720 | bundle = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_detail().(self).alter_detail_data_to_serializescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#alter_detail_data_to_serialize().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_detail().(request), bundle) |
| 1721 | return selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_detail().(self).create_responsescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#create_response().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_detail().(request), bundle, response_classscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#create_response().(response_class)=httpscip-python python django-tastypie 0.15.1 `tastypie.http`/__init__:.HttpAcceptedscip-python python django-tastypie 0.15.1 `tastypie.http`/HttpAccepted#) |
| 1722 | |
| 1723 | def update_in_placescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#update_in_place().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#update_in_place().(self), requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#update_in_place().(request), original_bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#update_in_place().(original_bundle), new_datascip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#update_in_place().(new_data)): |
| 1724 | """ |
| 1725 | Update the object in original_bundle in-place using new_data. |
| 1726 | """ |
| 1727 | original_bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#update_in_place().(original_bundle).data.update(**new_datascip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#update_in_place().(new_data)) |
| 1728 | |
| 1729 | # Now we've got a bundle with the new data sitting in it and we're |
| 1730 | # we're basically in the same spot as a PUT request. SO the rest of this |
| 1731 | # function is cribbed from put_detail. |
| 1732 | selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#update_in_place().(self).alter_deserialized_detail_datascip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#alter_deserialized_detail_data().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#update_in_place().(request), original_bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#update_in_place().(original_bundle).data) |
| 1733 | kwargs = { |
| 1734 | selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#update_in_place().(self)._meta.detail_uri_name: selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#update_in_place().(self).get_bundle_detail_datascip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_bundle_detail_data().(original_bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#update_in_place().(original_bundle)), |
| 1735 | 'request': requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#update_in_place().(request), |
| 1736 | } |
| 1737 | return selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#update_in_place().(self).obj_updatescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#obj_update().(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#obj_update().(bundle)=original_bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#update_in_place().(original_bundle), **kwargs) |
| 1738 | |
| 1739 | def get_schemascip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_schema().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_schema().(self), requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_schema().(request), **kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_schema().(kwargs)): |
| 1740 | """ |
| 1741 | Returns a serialized form of the schema of the resource. |
| 1742 | |
| 1743 | Calls ``build_schema`` to generate the data. This method only responds |
| 1744 | to HTTP GET. |
| 1745 | |
| 1746 | Should return a HttpResponse (200 OK). |
| 1747 | """ |
| 1748 | selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_schema().(self).method_checkscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#method_check().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_schema().(request), allowedscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#method_check().(allowed)=['get']) |
| 1749 | selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_schema().(self).is_authenticatedscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#is_authenticated().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_schema().(request)) |
| 1750 | selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_schema().(self).throttle_checkscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#throttle_check().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_schema().(request)) |
| 1751 | selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_schema().(self).log_throttled_accessscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#log_throttled_access().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_schema().(request)) |
| 1752 | bundle = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_schema().(self).build_bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_bundle().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_bundle().(request)=requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_schema().(request)) |
| 1753 | selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_schema().(self).authorized_read_detailscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_read_detail().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_schema().(self).get_object_listscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_object_list().(bundle.requestscip-python python django-tastypie 0.15.1 `tastypie.bundle`/Bundle#request.), bundle) |
| 1754 | return selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_schema().(self).create_responsescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#create_response().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_schema().(request), selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_schema().(self).build_schemascip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_schema().()) |
| 1755 | |
| 1756 | def get_multiplescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_multiple().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_multiple().(self), requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_multiple().(request), **kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_multiple().(kwargs)): |
| 1757 | """ |
| 1758 | Returns a serialized list of resources based on the identifiers |
| 1759 | from the URL. |
| 1760 | |
| 1761 | Calls ``obj_get_list`` to fetch only the objects requests in |
| 1762 | a single query. This method only responds to HTTP GET. |
| 1763 | |
| 1764 | For backward compatibility the method ``obj_get`` is used if |
| 1765 | ``obj_get_list`` is not implemented. |
| 1766 | |
| 1767 | Should return a HttpResponse (200 OK). |
| 1768 | """ |
| 1769 | selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_multiple().(self).method_checkscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#method_check().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_multiple().(request), allowedscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#method_check().(allowed)=['get']) |
| 1770 | selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_multiple().(self).is_authenticatedscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#is_authenticated().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_multiple().(request)) |
| 1771 | selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_multiple().(self).throttle_checkscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#throttle_check().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_multiple().(request)) |
| 1772 | |
| 1773 | # Rip apart the list then iterate. |
| 1774 | kwarg_name = '%s_list' % selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_multiple().(self)._meta.detail_uri_name |
| 1775 | obj_identifiers = kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_multiple().(kwargs).getscip-python python python-stdlib 3.11 builtins/dict#get().(kwarg_name, '').splitscip-python python python-stdlib 3.11 builtins/str#split().(';') |
| 1776 | objects = [] |
| 1777 | not_found = [] |
| 1778 | base_bundle = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_multiple().(self).build_bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_bundle().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_bundle().(request)=requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_multiple().(request)) |
| 1779 | |
| 1780 | # We will try to get a queryset from obj_get_list. |
| 1781 | queryset = None |
| 1782 | |
| 1783 | try: |
| 1784 | queryset = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_multiple().(self).obj_get_listscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#obj_get_list().(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#obj_get_list().(bundle)=base_bundle).filter( |
| 1785 | **{selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_multiple().(self)._meta.detail_uri_name + '__in': obj_identifiers}) |
| 1786 | except NotImplementedErrorscip-python python python-stdlib 3.11 builtins/NotImplementedError#: |
| 1787 | pass |
| 1788 | |
| 1789 | if queryset is not None: |
| 1790 | # Fetch the objects from the queryset to a dictionary. |
| 1791 | objects_dict = {} |
| 1792 | for obj in queryset: |
| 1793 | objects_dict[strscip-python python python-stdlib 3.11 builtins/str#(getattrscip-python python python-stdlib 3.11 builtins/getattr().(obj, selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_multiple().(self)._meta.detail_uri_name))] = obj |
| 1794 | |
| 1795 | # Walk the list of identifiers in order and get the objects or feed the not_found list. |
| 1796 | for identifier in obj_identifiers: |
| 1797 | if identifier in objects_dict: |
| 1798 | bundle = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_multiple().(self).build_bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_bundle().(objscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_bundle().(obj)=objects_dict[identifier], requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_bundle().(request)=requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_multiple().(request)) |
| 1799 | bundle = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_multiple().(self).full_dehydratescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#full_dehydrate().(bundle, for_listscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#full_dehydrate().(for_list)=True) |
| 1800 | objects.appendscip-python python python-stdlib 3.11 builtins/list#append().(bundle) |
| 1801 | else: |
| 1802 | not_found.appendscip-python python python-stdlib 3.11 builtins/list#append().(identifier) |
| 1803 | else: |
| 1804 | # Use the old way. |
| 1805 | for identifier in obj_identifiers: |
| 1806 | try: |
| 1807 | obj = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_multiple().(self).obj_getscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#obj_get().(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#obj_get().(bundle)=base_bundle, **{selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_multiple().(self)._meta.detail_uri_name: identifier}) |
| 1808 | bundle = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_multiple().(self).build_bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_bundle().(objscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_bundle().(obj)=obj, requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#build_bundle().(request)=requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_multiple().(request)) |
| 1809 | bundle = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_multiple().(self).full_dehydratescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#full_dehydrate().(bundle, for_listscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#full_dehydrate().(for_list)=True) |
| 1810 | objects.appendscip-python python python-stdlib 3.11 builtins/list#append().(bundle) |
| 1811 | except (ObjectDoesNotExist, Unauthorizedscip-python python django-tastypie 0.15.1 `tastypie.exceptions`/Unauthorized#): |
| 1812 | not_found.appendscip-python python python-stdlib 3.11 builtins/list#append().(identifier) |
| 1813 | |
| 1814 | object_list = { |
| 1815 | selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_multiple().(self)._meta.collection_name: objects, |
| 1816 | } |
| 1817 | |
| 1818 | if len(not_found): |
| 1819 | object_list['not_found'] = not_found |
| 1820 | |
| 1821 | selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_multiple().(self).log_throttled_accessscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#log_throttled_access().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_multiple().(request)) |
| 1822 | return selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_multiple().(self).create_responsescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#create_response().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_multiple().(request), object_list) |
| 1823 | |
| 1824 | |
| 1825 | class ModelDeclarativeMetaclassscip-python python django-tastypie 0.15.1 `tastypie.resources`/ModelDeclarativeMetaclass#(DeclarativeMetaclassscip-python python django-tastypie 0.15.1 `tastypie.resources`/DeclarativeMetaclass#): |
| 1826 | def __new__scip-python python django-tastypie 0.15.1 `tastypie.resources`/ModelDeclarativeMetaclass#__new__().(clsscip-python python django-tastypie 0.15.1 `tastypie.resources`/ModelDeclarativeMetaclass#__new__().(cls), namescip-python python django-tastypie 0.15.1 `tastypie.resources`/ModelDeclarativeMetaclass#__new__().(name), basesscip-python python django-tastypie 0.15.1 `tastypie.resources`/ModelDeclarativeMetaclass#__new__().(bases), attrsscip-python python django-tastypie 0.15.1 `tastypie.resources`/ModelDeclarativeMetaclass#__new__().(attrs)): |
| 1827 | meta = attrsscip-python python django-tastypie 0.15.1 `tastypie.resources`/ModelDeclarativeMetaclass#__new__().(attrs).get('Meta') |
| 1828 | if getattrscip-python python python-stdlib 3.11 builtins/getattr().(meta, 'abstract', False): |
| 1829 | # abstract base classes do nothing on declaration |
| 1830 | new_class = superscip-python python python-stdlib 3.11 builtins/super#(ModelDeclarativeMetaclassscip-python python django-tastypie 0.15.1 `tastypie.resources`/ModelDeclarativeMetaclass#, clsscip-python python django-tastypie 0.15.1 `tastypie.resources`/ModelDeclarativeMetaclass#__new__().(cls)).__new__scip-python python django-tastypie 0.15.1 `tastypie.resources`/DeclarativeMetaclass#__new__().(clsscip-python python django-tastypie 0.15.1 `tastypie.resources`/ModelDeclarativeMetaclass#__new__().(cls), namescip-python python django-tastypie 0.15.1 `tastypie.resources`/ModelDeclarativeMetaclass#__new__().(name), basesscip-python python django-tastypie 0.15.1 `tastypie.resources`/ModelDeclarativeMetaclass#__new__().(bases), attrsscip-python python django-tastypie 0.15.1 `tastypie.resources`/ModelDeclarativeMetaclass#__new__().(attrs)) |
| 1831 | return new_class |
| 1832 | |
| 1833 | # Sanity check: ModelResource needs either a queryset or object_class: |
| 1834 | if meta and not hasattr(meta, 'queryset') and not hasattr(meta, 'object_class'): |
| 1835 | msg = "ModelResource (%s) requires Meta.object_class or Meta.queryset" |
| 1836 | raise ImproperlyConfigured(msg % namescip-python python django-tastypie 0.15.1 `tastypie.resources`/ModelDeclarativeMetaclass#__new__().(name)) |
| 1837 | |
| 1838 | if hasattr(meta, 'queryset') and not hasattr(meta, 'object_class'): |
| 1839 | setattr(meta, 'object_class', meta.queryset.model) |
| 1840 | |
| 1841 | new_class = superscip-python python python-stdlib 3.11 builtins/super#(ModelDeclarativeMetaclassscip-python python django-tastypie 0.15.1 `tastypie.resources`/ModelDeclarativeMetaclass#, clsscip-python python django-tastypie 0.15.1 `tastypie.resources`/ModelDeclarativeMetaclass#__new__().(cls)).__new__scip-python python django-tastypie 0.15.1 `tastypie.resources`/DeclarativeMetaclass#__new__().(clsscip-python python django-tastypie 0.15.1 `tastypie.resources`/ModelDeclarativeMetaclass#__new__().(cls), namescip-python python django-tastypie 0.15.1 `tastypie.resources`/ModelDeclarativeMetaclass#__new__().(name), basesscip-python python django-tastypie 0.15.1 `tastypie.resources`/ModelDeclarativeMetaclass#__new__().(bases), attrsscip-python python django-tastypie 0.15.1 `tastypie.resources`/ModelDeclarativeMetaclass#__new__().(attrs)) |
| 1842 | specified_fields = getattrscip-python python python-stdlib 3.11 builtins/getattr().(new_class._meta, 'fields', None) |
| 1843 | excludes = getattrscip-python python python-stdlib 3.11 builtins/getattr().(new_class._meta, 'excludes', []) |
| 1844 | field_names = listscip-python python python-stdlib 3.11 builtins/list#(new_class.base_fields.keys()) |
| 1845 | |
| 1846 | include_fields = specified_fields |
| 1847 | |
| 1848 | if include_fields is None: |
| 1849 | if meta and meta.object_class: |
| 1850 | include_fields = [f.name for f in meta.object_class._meta.fields] |
| 1851 | else: |
| 1852 | include_fields = [] |
| 1853 | |
| 1854 | for field_name in field_names: |
| 1855 | if field_name == 'resource_uri': |
| 1856 | continue |
| 1857 | if field_name in new_class.declared_fields: |
| 1858 | continue |
| 1859 | if specified_fields is not None and field_name not in include_fields: |
| 1860 | del new_class.base_fields[field_name] |
| 1861 | if field_name in excludes: |
| 1862 | del new_class.base_fields[field_name] |
| 1863 | |
| 1864 | # Add in the new fields. |
| 1865 | new_class.base_fields.update(new_class.get_fields(include_fields, excludes)) |
| 1866 | |
| 1867 | if getattrscip-python python python-stdlib 3.11 builtins/getattr().(new_class._meta, 'include_absolute_url', True): |
| 1868 | if 'absolute_url' not in new_class.base_fields: |
| 1869 | new_class.base_fields['absolute_url'] = fieldsscip-python python django-tastypie 0.15.1 `tastypie.fields`/__init__:.CharFieldscip-python python django-tastypie 0.15.1 `tastypie.fields`/CharField#(attributescip-python python django-tastypie 0.15.1 `tastypie.fields`/ApiField#__init__().(attribute)='get_absolute_url', readonlyscip-python python django-tastypie 0.15.1 `tastypie.fields`/ApiField#__init__().(readonly)=True) |
| 1870 | elif 'absolute_url' in new_class.base_fields and 'absolute_url' not in attrsscip-python python django-tastypie 0.15.1 `tastypie.resources`/ModelDeclarativeMetaclass#__new__().(attrs): |
| 1871 | del new_class.base_fields['absolute_url'] |
| 1872 | |
| 1873 | return new_class |
| 1874 | |
| 1875 | |
| 1876 | class BaseModelResourcescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#(Resourcescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#): |
| 1877 | """ |
| 1878 | A subclass of ``Resource`` designed to work with Django's ``Models``. |
| 1879 | |
| 1880 | This class will introspect a given ``Model`` and build a field list based |
| 1881 | on the fields found on the model (excluding relational fields). |
| 1882 | |
| 1883 | Given that it is aware of Django's ORM, it also handles the CRUD data |
| 1884 | operations of the resource. |
| 1885 | """ |
| 1886 | @classmethodscip-python python python-stdlib 3.11 builtins/classmethod# |
| 1887 | def should_skip_fieldscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#should_skip_field().(clsscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#should_skip_field().(cls), fieldscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#should_skip_field().(field)): |
| 1888 | """ |
| 1889 | Given a Django model field, return if it should be included in the |
| 1890 | contributed ApiFields. |
| 1891 | """ |
| 1892 | if isinstance(fieldscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#should_skip_field().(field), ForeignKey): |
| 1893 | return True |
| 1894 | # Ignore certain fields (related fields). |
| 1895 | if hasattr(fieldscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#should_skip_field().(field), 'remote_field'): |
| 1896 | if fieldscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#should_skip_field().(field).remote_field: |
| 1897 | return True |
| 1898 | elif getattrscip-python python python-stdlib 3.11 builtins/getattr().(fieldscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#should_skip_field().(field), 'rel'): |
| 1899 | return True |
| 1900 | |
| 1901 | return False |
| 1902 | |
| 1903 | @classmethodscip-python python python-stdlib 3.11 builtins/classmethod# |
| 1904 | def api_field_from_django_fieldscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#api_field_from_django_field().(clsscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#api_field_from_django_field().(cls), fscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#api_field_from_django_field().(f), defaultscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#api_field_from_django_field().(default)=fieldsscip-python python django-tastypie 0.15.1 `tastypie.fields`/__init__:.CharFieldscip-python python django-tastypie 0.15.1 `tastypie.fields`/CharField#): |
| 1905 | """ |
| 1906 | Returns the field type that would likely be associated with each |
| 1907 | Django type. |
| 1908 | """ |
| 1909 | result = defaultscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#api_field_from_django_field().(default) |
| 1910 | internal_type = fscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#api_field_from_django_field().(f).get_internal_type() |
| 1911 | |
| 1912 | if internal_type == 'DateField': |
| 1913 | result = fieldsscip-python python django-tastypie 0.15.1 `tastypie.fields`/__init__:.DateFieldscip-python python django-tastypie 0.15.1 `tastypie.fields`/DateField# |
| 1914 | elif internal_type == 'DateTimeField': |
| 1915 | result = fieldsscip-python python django-tastypie 0.15.1 `tastypie.fields`/__init__:.DateTimeFieldscip-python python django-tastypie 0.15.1 `tastypie.fields`/DateTimeField# |
| 1916 | elif internal_type in ('BooleanField', 'NullBooleanField'): |
| 1917 | result = fieldsscip-python python django-tastypie 0.15.1 `tastypie.fields`/__init__:.BooleanFieldscip-python python django-tastypie 0.15.1 `tastypie.fields`/BooleanField# |
| 1918 | elif internal_type in ('FloatField',): |
| 1919 | result = fieldsscip-python python django-tastypie 0.15.1 `tastypie.fields`/__init__:.FloatFieldscip-python python django-tastypie 0.15.1 `tastypie.fields`/FloatField# |
| 1920 | elif internal_type in ('DecimalField',): |
| 1921 | result = fieldsscip-python python django-tastypie 0.15.1 `tastypie.fields`/__init__:.DecimalFieldscip-python python django-tastypie 0.15.1 `tastypie.fields`/DecimalField# |
| 1922 | elif internal_type in ('IntegerField', 'PositiveIntegerField', 'PositiveSmallIntegerField', 'SmallIntegerField', 'AutoField', 'BigIntegerField', 'BigAutoField'): |
| 1923 | result = fieldsscip-python python django-tastypie 0.15.1 `tastypie.fields`/__init__:.IntegerFieldscip-python python django-tastypie 0.15.1 `tastypie.fields`/IntegerField# |
| 1924 | elif internal_type in ('FileField', 'ImageField'): |
| 1925 | result = fieldsscip-python python django-tastypie 0.15.1 `tastypie.fields`/__init__:.FileFieldscip-python python django-tastypie 0.15.1 `tastypie.fields`/FileField# |
| 1926 | elif internal_type == 'TimeField': |
| 1927 | result = fieldsscip-python python django-tastypie 0.15.1 `tastypie.fields`/__init__:.TimeFieldscip-python python django-tastypie 0.15.1 `tastypie.fields`/TimeField# |
| 1928 | # TODO: Perhaps enable these via introspection. The reason they're not enabled |
| 1929 | # by default is the very different ``__init__`` they have over |
| 1930 | # the other fields. |
| 1931 | # elif internal_type == 'ForeignKey': |
| 1932 | # result = ForeignKey |
| 1933 | # elif internal_type == 'ManyToManyField': |
| 1934 | # result = ManyToManyField |
| 1935 | |
| 1936 | return result |
| 1937 | |
| 1938 | @classmethodscip-python python python-stdlib 3.11 builtins/classmethod# |
| 1939 | def get_fieldsscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#get_fields().(clsscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#get_fields().(cls), fieldsscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#get_fields().(fields)=None, excludesscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#get_fields().(excludes)=None): |
| 1940 | """ |
| 1941 | Given any explicit fields to include and fields to exclude, add |
| 1942 | additional fields based on the associated model. |
| 1943 | """ |
| 1944 | final_fields = {} |
| 1945 | fieldsscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#get_fields().(fields) = fieldsscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#get_fields().(fields) or [] |
| 1946 | excludesscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#get_fields().(excludes) = excludesscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#get_fields().(excludes) or [] |
| 1947 | |
| 1948 | if not clsscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#get_fields().(cls)._meta.object_class: |
| 1949 | return final_fields |
| 1950 | |
| 1951 | for f in clsscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#get_fields().(cls)._meta.object_class._meta.fields: |
| 1952 | # If the field name is already present, skip |
| 1953 | if f.name in clsscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#get_fields().(cls).base_fields: |
| 1954 | continue |
| 1955 | |
| 1956 | # If field is not present in explicit field listing, skip |
| 1957 | if f.name not in fieldsscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#get_fields().(fields): |
| 1958 | continue |
| 1959 | |
| 1960 | # If field is in exclude list, skip |
| 1961 | if f.name in excludesscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#get_fields().(excludes): |
| 1962 | continue |
| 1963 | |
| 1964 | if clsscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#get_fields().(cls).should_skip_fieldscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#should_skip_field().(f): |
| 1965 | continue |
| 1966 | |
| 1967 | api_field_class = clsscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#get_fields().(cls).api_field_from_django_fieldscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#api_field_from_django_field().(f) |
| 1968 | |
| 1969 | kwargs = { |
| 1970 | 'attribute': f.name, |
| 1971 | 'help_text': f.help_text, |
| 1972 | 'verbose_name': f.verbose_name, |
| 1973 | } |
| 1974 | |
| 1975 | if f.null is True: |
| 1976 | kwargs['null'] = True |
| 1977 | |
| 1978 | kwargs['unique'] = f.unique |
| 1979 | |
| 1980 | if not f.null and f.blank is True: |
| 1981 | kwargs['default'] = '' |
| 1982 | kwargs['blank'] = True |
| 1983 | |
| 1984 | if f.get_internal_type() == 'TextField': |
| 1985 | kwargs['default'] = '' |
| 1986 | |
| 1987 | if f.has_default(): |
| 1988 | kwargs['default'] = f.default |
| 1989 | |
| 1990 | if getattrscip-python python python-stdlib 3.11 builtins/getattr().(f, 'auto_now', False): |
| 1991 | kwargs['default'] = f.auto_now |
| 1992 | |
| 1993 | if getattrscip-python python python-stdlib 3.11 builtins/getattr().(f, 'auto_now_add', False): |
| 1994 | kwargs['default'] = f.auto_now_add |
| 1995 | |
| 1996 | final_fields[f.name] = api_field_class(**kwargs) |
| 1997 | final_fields[f.name].instance_name = f.name |
| 1998 | |
| 1999 | return final_fields |
| 2000 | |
| 2001 | def check_filteringscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#check_filtering().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#check_filtering().(self), field_namescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#check_filtering().(field_name), filter_typescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#check_filtering().(filter_type)='exact', filter_bitsscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#check_filtering().(filter_bits)=None): |
| 2002 | """ |
| 2003 | Given a field name, a optional filter type and an optional list of |
| 2004 | additional relations, determine if a field can be filtered on. |
| 2005 | |
| 2006 | If a filter does not meet the needed conditions, it should raise an |
| 2007 | ``InvalidFilterError``. |
| 2008 | |
| 2009 | If the filter meets the conditions, a list of attribute names (not |
| 2010 | field names) will be returned. |
| 2011 | """ |
| 2012 | if filter_bitsscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#check_filtering().(filter_bits) is None: |
| 2013 | filter_bitsscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#check_filtering().(filter_bits) = [] |
| 2014 | |
| 2015 | if field_namescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#check_filtering().(field_name) not in selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#check_filtering().(self)._meta.filtering: |
| 2016 | raise InvalidFilterErrorscip-python python django-tastypie 0.15.1 `tastypie.exceptions`/InvalidFilterError#("The '%s' field does not allow filtering." % field_namescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#check_filtering().(field_name)) |
| 2017 | |
| 2018 | # Check to see if it's an allowed lookup type. |
| 2019 | if selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#check_filtering().(self)._meta.filtering[field_namescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#check_filtering().(field_name)] not in (ALLscip-python python django-tastypie 0.15.1 `tastypie.constants`/ALL., ALL_WITH_RELATIONSscip-python python django-tastypie 0.15.1 `tastypie.constants`/ALL_WITH_RELATIONS.): |
| 2020 | # Must be an explicit whitelist. |
| 2021 | if filter_typescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#check_filtering().(filter_type) not in selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#check_filtering().(self)._meta.filtering[field_namescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#check_filtering().(field_name)]: |
| 2022 | raise InvalidFilterErrorscip-python python django-tastypie 0.15.1 `tastypie.exceptions`/InvalidFilterError#("'%s' is not an allowed filter on the '%s' field." % (filter_typescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#check_filtering().(filter_type), field_namescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#check_filtering().(field_name))) |
| 2023 | |
| 2024 | if selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#check_filtering().(self).fieldsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#fields.[field_namescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#check_filtering().(field_name)].attribute is None: |
| 2025 | raise InvalidFilterErrorscip-python python django-tastypie 0.15.1 `tastypie.exceptions`/InvalidFilterError#("The '%s' field has no 'attribute' for searching with." % field_namescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#check_filtering().(field_name)) |
| 2026 | |
| 2027 | # Check to see if it's a relational lookup and if that's allowed. |
| 2028 | if len(filter_bitsscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#check_filtering().(filter_bits)): |
| 2029 | if not getattrscip-python python python-stdlib 3.11 builtins/getattr().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#check_filtering().(self).fieldsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#fields.[field_namescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#check_filtering().(field_name)], 'is_related', False): |
| 2030 | raise InvalidFilterErrorscip-python python django-tastypie 0.15.1 `tastypie.exceptions`/InvalidFilterError#("The '%s' field does not support relations." % field_namescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#check_filtering().(field_name)) |
| 2031 | |
| 2032 | if not selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#check_filtering().(self)._meta.filtering[field_namescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#check_filtering().(field_name)] == ALL_WITH_RELATIONSscip-python python django-tastypie 0.15.1 `tastypie.constants`/ALL_WITH_RELATIONS.: |
| 2033 | raise InvalidFilterErrorscip-python python django-tastypie 0.15.1 `tastypie.exceptions`/InvalidFilterError#("Lookups are not allowed more than one level deep on the '%s' field." % field_namescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#check_filtering().(field_name)) |
| 2034 | |
| 2035 | # Recursively descend through the remaining lookups in the filter, |
| 2036 | # if any. We should ensure that all along the way, we're allowed |
| 2037 | # to filter on that field by the related resource. |
| 2038 | related_resource = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#check_filtering().(self).fieldsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#fields.[field_namescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#check_filtering().(field_name)].get_related_resource(None) |
| 2039 | return [selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#check_filtering().(self).fieldsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#fields.[field_namescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#check_filtering().(field_name)].attribute] + related_resource.check_filtering(filter_bitsscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#check_filtering().(filter_bits)[0], filter_typescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#check_filtering().(filter_type), filter_bitsscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#check_filtering().(filter_bits)[1:]) |
| 2040 | |
| 2041 | return [selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#check_filtering().(self).fieldsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#fields.[field_namescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#check_filtering().(field_name)].attribute] |
| 2042 | |
| 2043 | def filter_value_to_pythonscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#filter_value_to_python().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#filter_value_to_python().(self), valuescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#filter_value_to_python().(value), field_namescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#filter_value_to_python().(field_name), filtersscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#filter_value_to_python().(filters), filter_exprscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#filter_value_to_python().(filter_expr), |
| 2044 | filter_typescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#filter_value_to_python().(filter_type)): |
| 2045 | """ |
| 2046 | Turn the string ``value`` into a python object. |
| 2047 | """ |
| 2048 | # Simple values |
| 2049 | valuescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#filter_value_to_python().(value) = string_to_pythonscip-python python django-tastypie 0.15.1 `tastypie.utils`/string_to_python().(valuescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#filter_value_to_python().(value)) |
| 2050 | |
| 2051 | # Split on ',' if not empty string and either an in or range filter. |
| 2052 | if filter_typescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#filter_value_to_python().(filter_type) in ('in', 'range') and len(valuescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#filter_value_to_python().(value)): |
| 2053 | if hasattr(filtersscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#filter_value_to_python().(filters), 'getlist'): |
| 2054 | valuescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#filter_value_to_python().(value) = [] |
| 2055 | |
| 2056 | for part in filtersscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#filter_value_to_python().(filters).getlist(filter_exprscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#filter_value_to_python().(filter_expr)): |
| 2057 | valuescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#filter_value_to_python().(value).extendscip-python python python-stdlib 3.11 builtins/list#extend().(part.split(',')) |
| 2058 | else: |
| 2059 | valuescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#filter_value_to_python().(value) = valuescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#filter_value_to_python().(value).split(',') |
| 2060 | |
| 2061 | return valuescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#filter_value_to_python().(value) |
| 2062 | |
| 2063 | def build_filtersscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#build_filters().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#build_filters().(self), filtersscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#build_filters().(filters)=None, ignore_bad_filtersscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#build_filters().(ignore_bad_filters)=False): |
| 2064 | """ |
| 2065 | Given a dictionary of filters, create the necessary ORM-level filters. |
| 2066 | |
| 2067 | Keys should be resource fields, **NOT** model fields. |
| 2068 | |
| 2069 | Valid values are either a list of Django filter types (i.e. |
| 2070 | ``['startswith', 'exact', 'lte']``), the ``ALL`` constant or the |
| 2071 | ``ALL_WITH_RELATIONS`` constant. |
| 2072 | """ |
| 2073 | # At the declarative level: |
| 2074 | # filtering = { |
| 2075 | # 'resource_field_name': ['exact', 'startswith', 'endswith', 'contains'], |
| 2076 | # 'resource_field_name_2': ['exact', 'gt', 'gte', 'lt', 'lte', 'range'], |
| 2077 | # 'resource_field_name_3': ALL, |
| 2078 | # 'resource_field_name_4': ALL_WITH_RELATIONS, |
| 2079 | # ... |
| 2080 | # } |
| 2081 | # Accepts the filters as a dict. None by default, meaning no filters. |
| 2082 | if filtersscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#build_filters().(filters) is None: |
| 2083 | filtersscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#build_filters().(filters) = {} |
| 2084 | |
| 2085 | qs_filters = {} |
| 2086 | |
| 2087 | for filter_expr, value in filtersscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#build_filters().(filters).itemsscip-python python python-stdlib 3.11 builtins/dict#items().(): |
| 2088 | filter_bits = filter_expr.split(LOOKUP_SEP) |
| 2089 | field_name = filter_bits.pop(0) |
| 2090 | filter_type = 'exact' |
| 2091 | |
| 2092 | if field_name not in selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#build_filters().(self).fieldsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#fields.: |
| 2093 | # It's not a field we know about. Move along citizen. |
| 2094 | continue |
| 2095 | |
| 2096 | # Validate filter types other than 'exact' that are supported by the field type |
| 2097 | try: |
| 2098 | django_field_name = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#build_filters().(self).fieldsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#fields.[field_name].attribute |
| 2099 | django_field = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#build_filters().(self)._meta.object_class._meta.get_field(django_field_name) |
| 2100 | if hasattr(django_field, 'field'): |
| 2101 | django_field = django_field.field # related field |
| 2102 | except FieldDoesNotExist: |
| 2103 | raise InvalidFilterErrorscip-python python django-tastypie 0.15.1 `tastypie.exceptions`/InvalidFilterError#("The '%s' field is not a valid field name" % field_name) |
| 2104 | |
| 2105 | query_terms = django_field.get_lookups().keys() |
| 2106 | if len(filter_bits) and filter_bits[-1] in query_terms: |
| 2107 | filter_type = filter_bits.pop() |
| 2108 | |
| 2109 | try: |
| 2110 | lookup_bits = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#build_filters().(self).check_filteringscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#check_filtering().(field_name, filter_type, filter_bits) |
| 2111 | except InvalidFilterErrorscip-python python django-tastypie 0.15.1 `tastypie.exceptions`/InvalidFilterError#: |
| 2112 | if ignore_bad_filtersscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#build_filters().(ignore_bad_filters): |
| 2113 | continue |
| 2114 | else: |
| 2115 | raise |
| 2116 | value = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#build_filters().(self).filter_value_to_pythonscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#filter_value_to_python().(value, field_name, filtersscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#build_filters().(filters), filter_expr, filter_type) |
| 2117 | |
| 2118 | db_field_name = LOOKUP_SEP.join(lookup_bits) |
| 2119 | qs_filter = "%s%s%s" % (db_field_name, LOOKUP_SEP, filter_type) |
| 2120 | qs_filters[qs_filter] = value |
| 2121 | |
| 2122 | return qs_filters |
| 2123 | |
| 2124 | def apply_sortingscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#apply_sorting().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#apply_sorting().(self), obj_listscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#apply_sorting().(obj_list), optionsscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#apply_sorting().(options)=None): |
| 2125 | """ |
| 2126 | Given a dictionary of options, apply some ORM-level sorting to the |
| 2127 | provided ``QuerySet``. |
| 2128 | |
| 2129 | Looks for the ``order_by`` key and handles either ascending (just the |
| 2130 | field name) or descending (the field name with a ``-`` in front). |
| 2131 | |
| 2132 | The field name should be the resource field, **NOT** model field. |
| 2133 | """ |
| 2134 | if optionsscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#apply_sorting().(options) is None: |
| 2135 | optionsscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#apply_sorting().(options) = {} |
| 2136 | |
| 2137 | parameter_name = 'order_by' |
| 2138 | |
| 2139 | if 'order_by' not in optionsscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#apply_sorting().(options): |
| 2140 | if 'sort_by' not in optionsscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#apply_sorting().(options): |
| 2141 | # Nothing to alter the order. Return what we've got. |
| 2142 | return obj_listscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#apply_sorting().(obj_list) |
| 2143 | else: |
| 2144 | warningsscip-python python python-stdlib 3.11 warnings/__init__:.warnscip-python python python-stdlib 3.11 _warnings/warn().("'sort_by' is a deprecated parameter. Please use 'order_by' instead.") |
| 2145 | parameter_name = 'sort_by' |
| 2146 | |
| 2147 | order_by_args = [] |
| 2148 | |
| 2149 | if hasattr(optionsscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#apply_sorting().(options), 'getlist'): |
| 2150 | order_bits = optionsscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#apply_sorting().(options).getlist(parameter_name) |
| 2151 | else: |
| 2152 | order_bits = optionsscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#apply_sorting().(options).getscip-python python python-stdlib 3.11 builtins/dict#get().(parameter_name) |
| 2153 | |
| 2154 | if not isinstance(order_bits, (listscip-python python python-stdlib 3.11 builtins/list#, tuplescip-python python python-stdlib 3.11 builtins/tuple#)): |
| 2155 | order_bits = [order_bits] |
| 2156 | |
| 2157 | for order_by in order_bits: |
| 2158 | order_by_bits = order_by.split(LOOKUP_SEP) |
| 2159 | |
| 2160 | field_name = order_by_bits[0] |
| 2161 | order = '' |
| 2162 | |
| 2163 | if order_by_bits[0].startswith('-'): |
| 2164 | field_name = order_by_bits[0][1:] |
| 2165 | order = '-' |
| 2166 | |
| 2167 | if field_name not in selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#apply_sorting().(self).fieldsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#fields.: |
| 2168 | # It's not a field we know about. Move along citizen. |
| 2169 | raise InvalidSortErrorscip-python python django-tastypie 0.15.1 `tastypie.exceptions`/InvalidSortError#("No matching '%s' field for ordering on." % field_name) |
| 2170 | |
| 2171 | if field_name not in selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#apply_sorting().(self)._meta.ordering: |
| 2172 | raise InvalidSortErrorscip-python python django-tastypie 0.15.1 `tastypie.exceptions`/InvalidSortError#("The '%s' field does not allow ordering." % field_name) |
| 2173 | |
| 2174 | if selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#apply_sorting().(self).fieldsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#fields.[field_name].attribute is None: |
| 2175 | raise InvalidSortErrorscip-python python django-tastypie 0.15.1 `tastypie.exceptions`/InvalidSortError#("The '%s' field has no 'attribute' for ordering with." % field_name) |
| 2176 | |
| 2177 | order_by_args.appendscip-python python python-stdlib 3.11 builtins/list#append().("%s%s" % (order, LOOKUP_SEP.join([selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#apply_sorting().(self).fieldsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#fields.[field_name].attribute] + order_by_bits[1:]))) |
| 2178 | |
| 2179 | return obj_listscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#apply_sorting().(obj_list).order_by(*order_by_args) |
| 2180 | |
| 2181 | def apply_filtersscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#apply_filters().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#apply_filters().(self), requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#apply_filters().(request), applicable_filtersscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#apply_filters().(applicable_filters)): |
| 2182 | """ |
| 2183 | An ORM-specific implementation of ``apply_filters``. |
| 2184 | |
| 2185 | The default simply applies the ``applicable_filters`` as ``**kwargs``, |
| 2186 | but should make it possible to do more advanced things. |
| 2187 | """ |
| 2188 | return selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#apply_filters().(self).get_object_listscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#get_object_list().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#apply_filters().(request)).filter(**applicable_filtersscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#apply_filters().(applicable_filters)) |
| 2189 | |
| 2190 | def get_object_listscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#get_object_list().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#get_object_list().(self), requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#get_object_list().(request)): |
| 2191 | """ |
| 2192 | An ORM-specific implementation of ``get_object_list``. |
| 2193 | |
| 2194 | Returns a queryset that may have been limited by other overrides. |
| 2195 | """ |
| 2196 | return selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#get_object_list().(self)._meta.queryset._clone() |
| 2197 | |
| 2198 | def obj_get_listscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_get_list().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_get_list().(self), bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_get_list().(bundle), **kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_get_list().(kwargs)): |
| 2199 | """ |
| 2200 | A ORM-specific implementation of ``obj_get_list``. |
| 2201 | |
| 2202 | ``GET`` dictionary of bundle.request can be used to narrow the query. |
| 2203 | """ |
| 2204 | filters = {} |
| 2205 | |
| 2206 | if hasattr(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_get_list().(bundle).request, 'GET'): |
| 2207 | # Grab a mutable copy. |
| 2208 | filters = bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_get_list().(bundle).request.GET.copy() |
| 2209 | |
| 2210 | # Update with the provided kwargs. |
| 2211 | filters.updatescip-python python python-stdlib 3.11 typing/MutableMapping#update().(kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_get_list().(kwargs)) |
| 2212 | applicable_filters = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_get_list().(self).build_filtersscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#build_filters().(filtersscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#build_filters().(filters)=filters) |
| 2213 | |
| 2214 | try: |
| 2215 | objects = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_get_list().(self).apply_filtersscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#apply_filters().(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_get_list().(bundle).request, applicable_filters) |
| 2216 | return selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_get_list().(self).authorized_read_listscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_read_list().(objects, bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_get_list().(bundle)) |
| 2217 | except ValueErrorscip-python python python-stdlib 3.11 builtins/ValueError#: |
| 2218 | raise BadRequestscip-python python django-tastypie 0.15.1 `tastypie.exceptions`/BadRequest#("Invalid resource lookup data provided (mismatched type).") |
| 2219 | |
| 2220 | def obj_getscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_get().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_get().(self), bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_get().(bundle), **kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_get().(kwargs)): |
| 2221 | """ |
| 2222 | A ORM-specific implementation of ``obj_get``. |
| 2223 | |
| 2224 | Takes optional ``kwargs``, which are used to narrow the query to find |
| 2225 | the instance. |
| 2226 | """ |
| 2227 | # Use ignore_bad_filters=True. `obj_get_list` filters based on |
| 2228 | # request.GET, but `obj_get` usually filters based on `detail_uri_name` |
| 2229 | # or data from a related field, so we don't want to raise errors if |
| 2230 | # something doesn't explicitly match a configured filter. |
| 2231 | applicable_filters = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_get().(self).build_filtersscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#build_filters().(filtersscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#build_filters().(filters)=kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_get().(kwargs), ignore_bad_filtersscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#build_filters().(ignore_bad_filters)=True) |
| 2232 | if selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_get().(self)._meta.detail_uri_name in kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_get().(kwargs): |
| 2233 | applicable_filters[selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_get().(self)._meta.detail_uri_name] = kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_get().(kwargs)[selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_get().(self)._meta.detail_uri_name] |
| 2234 | |
| 2235 | try: |
| 2236 | object_list = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_get().(self).apply_filtersscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#apply_filters().(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_get().(bundle).request, applicable_filters) |
| 2237 | stringified_kwargs = ', '.joinscip-python python python-stdlib 3.11 builtins/str#join().(["%s=%s" % (k, v) for k, v in applicable_filters.itemsscip-python python python-stdlib 3.11 builtins/dict#items().()]) |
| 2238 | |
| 2239 | if len(object_list) <= 0: |
| 2240 | raise selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_get().(self)._meta.object_class.DoesNotExist("Couldn't find an instance of '%s' which matched '%s'." % (selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_get().(self)._meta.object_class.__name__, stringified_kwargs)) |
| 2241 | elif len(object_list) > 1: |
| 2242 | raise MultipleObjectsReturned("More than one '%s' matched '%s'." % (selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_get().(self)._meta.object_class.__name__, stringified_kwargs)) |
| 2243 | |
| 2244 | bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_get().(bundle).obj = object_list[0] |
| 2245 | selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_get().(self).authorized_read_detailscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_read_detail().(object_list, bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_get().(bundle)) |
| 2246 | return bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_get().(bundle).obj |
| 2247 | except ValueErrorscip-python python python-stdlib 3.11 builtins/ValueError#: |
| 2248 | raise NotFoundscip-python python django-tastypie 0.15.1 `tastypie.exceptions`/NotFound#("Invalid resource lookup data provided (mismatched type).") |
| 2249 | |
| 2250 | def obj_createscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_create().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_create().(self), bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_create().(bundle), **kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_create().(kwargs)): |
| 2251 | """ |
| 2252 | A ORM-specific implementation of ``obj_create``. |
| 2253 | """ |
| 2254 | bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_create().(bundle).obj = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_create().(self)._meta.object_class() |
| 2255 | |
| 2256 | for key, value in kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_create().(kwargs).itemsscip-python python python-stdlib 3.11 builtins/dict#items().(): |
| 2257 | setattr(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_create().(bundle).obj, key, value) |
| 2258 | |
| 2259 | bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_create().(bundle) = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_create().(self).full_hydratescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#full_hydrate().(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_create().(bundle)) |
| 2260 | return selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_create().(self).savescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save().(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_create().(bundle)) |
| 2261 | |
| 2262 | def lookup_kwargs_with_identifiersscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#lookup_kwargs_with_identifiers().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#lookup_kwargs_with_identifiers().(self), bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#lookup_kwargs_with_identifiers().(bundle), kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#lookup_kwargs_with_identifiers().(kwargs)): |
| 2263 | """ |
| 2264 | Kwargs here represent uri identifiers Ex: /repos/<user_id>/<repo_name>/ |
| 2265 | We need to turn those identifiers into Python objects for generating |
| 2266 | lookup parameters that can find them in the DB |
| 2267 | """ |
| 2268 | lookup_kwargs = {} |
| 2269 | |
| 2270 | # Handle detail_uri_name specially |
| 2271 | if selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#lookup_kwargs_with_identifiers().(self)._meta.detail_uri_name in kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#lookup_kwargs_with_identifiers().(kwargs): |
| 2272 | lookup_kwargs[selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#lookup_kwargs_with_identifiers().(self)._meta.detail_uri_name] = kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#lookup_kwargs_with_identifiers().(kwargs).pop(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#lookup_kwargs_with_identifiers().(self)._meta.detail_uri_name) |
| 2273 | |
| 2274 | bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#lookup_kwargs_with_identifiers().(bundle).obj = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#lookup_kwargs_with_identifiers().(self).get_object_listscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#get_object_list().(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#lookup_kwargs_with_identifiers().(bundle).request).model() |
| 2275 | # Override data values, we rely on uri identifiers |
| 2276 | bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#lookup_kwargs_with_identifiers().(bundle).data.update(kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#lookup_kwargs_with_identifiers().(kwargs)) |
| 2277 | # We're going to manually hydrate, as opposed to calling |
| 2278 | # ``full_hydrate``, to ensure we don't try to flesh out related |
| 2279 | # resources & keep things speedy. |
| 2280 | bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#lookup_kwargs_with_identifiers().(bundle) = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#lookup_kwargs_with_identifiers().(self).hydratescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#hydrate().(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#lookup_kwargs_with_identifiers().(bundle)) |
| 2281 | |
| 2282 | for identifier in kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#lookup_kwargs_with_identifiers().(kwargs): |
| 2283 | field_object = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#lookup_kwargs_with_identifiers().(self).fieldsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#fields.[identifier] |
| 2284 | |
| 2285 | # Skip readonly or related fields. |
| 2286 | if field_object.readonly or field_object.is_related or\ |
| 2287 | not field_object.attribute: |
| 2288 | continue |
| 2289 | |
| 2290 | # Check for an optional method to do further hydration. |
| 2291 | method = getattrscip-python python python-stdlib 3.11 builtins/getattr().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#lookup_kwargs_with_identifiers().(self), "hydrate_%s" % identifier, None) |
| 2292 | |
| 2293 | if method: |
| 2294 | bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#lookup_kwargs_with_identifiers().(bundle) = method(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#lookup_kwargs_with_identifiers().(bundle)) |
| 2295 | |
| 2296 | lookup_kwargs[identifier] = field_object.hydrate(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#lookup_kwargs_with_identifiers().(bundle)) |
| 2297 | |
| 2298 | return lookup_kwargs |
| 2299 | |
| 2300 | def obj_updatescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_update().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_update().(self), bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_update().(bundle), skip_errorsscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_update().(skip_errors)=False, **kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_update().(kwargs)): |
| 2301 | """ |
| 2302 | A ORM-specific implementation of ``obj_update``. |
| 2303 | """ |
| 2304 | bundle_detail_data = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_update().(self).get_bundle_detail_datascip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_bundle_detail_data().(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_update().(bundle)) |
| 2305 | arg_detail_data = kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_update().(kwargs).getscip-python python python-stdlib 3.11 builtins/dict#get().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_update().(self)._meta.detail_uri_name) |
| 2306 | |
| 2307 | if bundle_detail_data is None or (arg_detail_data is not None and strscip-python python python-stdlib 3.11 builtins/str#(bundle_detail_data) != strscip-python python python-stdlib 3.11 builtins/str#(arg_detail_data)): |
| 2308 | try: |
| 2309 | lookup_kwargs = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_update().(self).lookup_kwargs_with_identifiersscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#lookup_kwargs_with_identifiers().(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_update().(bundle), kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_update().(kwargs)) |
| 2310 | except: # noqa |
| 2311 | # if there is trouble hydrating the data, fall back to just |
| 2312 | # using kwargs by itself (usually it only contains a "pk" key |
| 2313 | # and this will work fine. |
| 2314 | lookup_kwargs = kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_update().(kwargs) |
| 2315 | |
| 2316 | try: |
| 2317 | bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_update().(bundle).obj = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_update().(self).obj_getscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_get().(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_get().(bundle)=bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_update().(bundle), **lookup_kwargs) |
| 2318 | except ObjectDoesNotExist: |
| 2319 | raise NotFoundscip-python python django-tastypie 0.15.1 `tastypie.exceptions`/NotFound#("A model instance matching the provided arguments could not be found.") |
| 2320 | |
| 2321 | bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_update().(bundle) = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_update().(self).full_hydratescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#full_hydrate().(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_update().(bundle)) |
| 2322 | return selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_update().(self).savescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save().(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_update().(bundle), skip_errorsscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save().(skip_errors)=skip_errorsscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_update().(skip_errors)) |
| 2323 | |
| 2324 | def obj_delete_listscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_delete_list().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_delete_list().(self), bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_delete_list().(bundle), **kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_delete_list().(kwargs)): |
| 2325 | """ |
| 2326 | A ORM-specific implementation of ``obj_delete_list``. |
| 2327 | """ |
| 2328 | objects_to_delete = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_delete_list().(self).obj_get_listscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_get_list().(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_get_list().(bundle)=bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_delete_list().(bundle), **kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_delete_list().(kwargs)) |
| 2329 | deletable_objects = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_delete_list().(self).authorized_delete_listscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_delete_list().(objects_to_delete, bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_delete_list().(bundle)) |
| 2330 | |
| 2331 | if hasattr(deletable_objects, 'delete'): |
| 2332 | # It's likely a ``QuerySet``. Call ``.delete()`` for efficiency. |
| 2333 | deletable_objects.delete() |
| 2334 | else: |
| 2335 | for authed_obj in deletable_objects: |
| 2336 | authed_obj.delete() |
| 2337 | |
| 2338 | def obj_delete_list_for_updatescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_delete_list_for_update().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_delete_list_for_update().(self), bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_delete_list_for_update().(bundle), **kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_delete_list_for_update().(kwargs)): |
| 2339 | """ |
| 2340 | A ORM-specific implementation of ``obj_delete_list_for_update``. |
| 2341 | """ |
| 2342 | objects_to_delete = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_delete_list_for_update().(self).obj_get_listscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_get_list().(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_get_list().(bundle)=bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_delete_list_for_update().(bundle), **kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_delete_list_for_update().(kwargs)) |
| 2343 | deletable_objects = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_delete_list_for_update().(self).authorized_update_listscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_update_list().(objects_to_delete, bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_delete_list_for_update().(bundle)) |
| 2344 | |
| 2345 | if hasattr(deletable_objects, 'delete'): |
| 2346 | # It's likely a ``QuerySet``. Call ``.delete()`` for efficiency. |
| 2347 | deletable_objects.delete() |
| 2348 | else: |
| 2349 | for authed_obj in deletable_objects: |
| 2350 | authed_obj.delete() |
| 2351 | |
| 2352 | def obj_deletescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_delete().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_delete().(self), bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_delete().(bundle), **kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_delete().(kwargs)): |
| 2353 | """ |
| 2354 | A ORM-specific implementation of ``obj_delete``. |
| 2355 | |
| 2356 | Takes optional ``kwargs``, which are used to narrow the query to find |
| 2357 | the instance. |
| 2358 | """ |
| 2359 | if not hasattr(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_delete().(bundle).obj, 'delete'): |
| 2360 | try: |
| 2361 | bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_delete().(bundle).obj = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_delete().(self).obj_getscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_get().(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_get().(bundle)=bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_delete().(bundle), **kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_delete().(kwargs)) |
| 2362 | except ObjectDoesNotExist: |
| 2363 | raise NotFoundscip-python python django-tastypie 0.15.1 `tastypie.exceptions`/NotFound#("A model instance matching the provided arguments could not be found.") |
| 2364 | |
| 2365 | selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_delete().(self).authorized_delete_detailscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_delete_detail().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_delete().(self).get_object_listscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#get_object_list().(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_delete().(bundle).request), bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_delete().(bundle)) |
| 2366 | bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#obj_delete().(bundle).obj.delete() |
| 2367 | |
| 2368 | @atomic_decoratorscip-python python django-tastypie 0.15.1 `tastypie.compat`/atomic_decorator.() |
| 2369 | def patch_listscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#patch_list().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#patch_list().(self), requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#patch_list().(request), **kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#patch_list().(kwargs)): |
| 2370 | """ |
| 2371 | An ORM-specific implementation of ``patch_list``. |
| 2372 | |
| 2373 | Necessary because PATCH should be atomic (all-success or all-fail) |
| 2374 | and the only way to do this neatly is at the database level. |
| 2375 | """ |
| 2376 | return superscip-python python python-stdlib 3.11 builtins/super#(BaseModelResourcescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#, selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#patch_list().(self)).patch_listscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#patch_list().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#patch_list().(request), **kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#patch_list().(kwargs)) |
| 2377 | |
| 2378 | def rollbackscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#rollback().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#rollback().(self), bundlesscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#rollback().(bundles)): |
| 2379 | """ |
| 2380 | A ORM-specific implementation of ``rollback``. |
| 2381 | |
| 2382 | Given the list of bundles, delete all models pertaining to those |
| 2383 | bundles. |
| 2384 | """ |
| 2385 | for bundle in bundlesscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#rollback().(bundles): |
| 2386 | if bundle.obj and selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#rollback().(self).get_bundle_detail_datascip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_bundle_detail_data().(bundle): |
| 2387 | bundle.obj.delete() |
| 2388 | |
| 2389 | def create_identifierscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#create_identifier().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#create_identifier().(self), objscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#create_identifier().(obj)): |
| 2390 | return u"%s.%s.%s" % (objscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#create_identifier().(obj)._meta.app_label, get_module_namescip-python python django-tastypie 0.15.1 `tastypie.compat`/get_module_name().(objscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#create_identifier().(obj)._meta), objscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#create_identifier().(obj).pk) |
| 2391 | |
| 2392 | def savescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save().(self), bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save().(bundle), skip_errorsscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save().(skip_errors)=False): |
| 2393 | if bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save().(bundle).via_uri: |
| 2394 | return bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save().(bundle) |
| 2395 | |
| 2396 | selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save().(self).is_validscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#is_valid().(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save().(bundle)) |
| 2397 | |
| 2398 | if bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save().(bundle).errors and not skip_errorsscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save().(skip_errors): |
| 2399 | raise ImmediateHttpResponsescip-python python django-tastypie 0.15.1 `tastypie.exceptions`/ImmediateHttpResponse#(responsescip-python python django-tastypie 0.15.1 `tastypie.exceptions`/ImmediateHttpResponse#__init__().(response)=selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save().(self).error_responsescip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#error_response().(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save().(bundle).request, bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save().(bundle).errors)) |
| 2400 | |
| 2401 | # Check if they're authorized. |
| 2402 | if bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save().(bundle).obj.pk: |
| 2403 | selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save().(self).authorized_update_detailscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_update_detail().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save().(self).get_object_listscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#get_object_list().(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save().(bundle).request), bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save().(bundle)) |
| 2404 | else: |
| 2405 | selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save().(self).authorized_create_detailscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#authorized_create_detail().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save().(self).get_object_listscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#get_object_list().(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save().(bundle).request), bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save().(bundle)) |
| 2406 | |
| 2407 | # Save FKs just in case. |
| 2408 | selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save().(self).save_relatedscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save_related().(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save().(bundle)) |
| 2409 | |
| 2410 | # Save the main object. |
| 2411 | obj_id = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save().(self).create_identifierscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#create_identifier().(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save().(bundle).obj) |
| 2412 | |
| 2413 | if obj_id not in bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save().(bundle).objects_saved or bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save().(bundle).obj._state.adding: |
| 2414 | if hasattr(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save().(bundle), 'update_fields'): |
| 2415 | bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save().(bundle).obj.save(update_fields=bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save().(bundle).update_fields) |
| 2416 | else: |
| 2417 | bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save().(bundle).obj.save() |
| 2418 | obj_id = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save().(self).create_identifierscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#create_identifier().(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save().(bundle).obj) |
| 2419 | bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save().(bundle).objects_saved.add(obj_id) |
| 2420 | |
| 2421 | # Now pick up the M2M bits. |
| 2422 | m2m_bundle = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save().(self).hydrate_m2mscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#hydrate_m2m().(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save().(bundle)) |
| 2423 | selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save().(self).save_m2mscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save_m2m().(m2m_bundle) |
| 2424 | return bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save().(bundle) |
| 2425 | |
| 2426 | def save_relatedscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save_related().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save_related().(self), bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save_related().(bundle)): |
| 2427 | """ |
| 2428 | Handles the saving of related non-M2M data. |
| 2429 | |
| 2430 | Calling assigning ``child.parent = parent`` & then calling |
| 2431 | ``Child.save`` isn't good enough to make sure the ``parent`` |
| 2432 | is saved. |
| 2433 | |
| 2434 | To get around this, we go through all our related fields & |
| 2435 | call ``save`` on them if they have related, non-M2M data. |
| 2436 | M2M data is handled by the ``ModelResource.save_m2m`` method. |
| 2437 | """ |
| 2438 | for field_name, field_object in selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save_related().(self).fieldsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#fields..itemsscip-python python python-stdlib 3.11 builtins/dict#items().(): |
| 2439 | if not field_object.is_related: |
| 2440 | continue |
| 2441 | |
| 2442 | if field_object.is_m2m: |
| 2443 | continue |
| 2444 | |
| 2445 | if not field_object.attribute: |
| 2446 | continue |
| 2447 | |
| 2448 | if field_object.readonly: |
| 2449 | continue |
| 2450 | |
| 2451 | if field_object.blank and field_name not in bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save_related().(bundle).data: |
| 2452 | continue |
| 2453 | |
| 2454 | # Get the object. |
| 2455 | try: |
| 2456 | related_obj = getattrscip-python python python-stdlib 3.11 builtins/getattr().(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save_related().(bundle).obj, field_object.attribute) |
| 2457 | except ObjectDoesNotExist: |
| 2458 | # Django 1.8: unset related objects default to None, no error |
| 2459 | related_obj = None |
| 2460 | |
| 2461 | # We didn't get it, so maybe we created it but haven't saved it |
| 2462 | if related_obj is None: |
| 2463 | related_obj = bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save_related().(bundle).related_objects_to_save.get(field_object.attribute, None) |
| 2464 | |
| 2465 | if related_obj and field_object.related_name: |
| 2466 | # this might be a reverse relation, so we need to save this |
| 2467 | # model, attach it to the related object, and save the related |
| 2468 | # object. |
| 2469 | if not selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save_related().(self).get_bundle_detail_datascip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#get_bundle_detail_data().(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save_related().(bundle)): |
| 2470 | bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save_related().(bundle).obj.save() |
| 2471 | |
| 2472 | setattr(related_obj, field_object.related_name, bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save_related().(bundle).obj) |
| 2473 | |
| 2474 | related_resource = field_object.get_related_resource(related_obj) |
| 2475 | |
| 2476 | # Before we build the bundle & try saving it, let's make sure we |
| 2477 | # haven't already saved it. |
| 2478 | if related_obj: |
| 2479 | obj_id = selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save_related().(self).create_identifierscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#create_identifier().(related_obj) |
| 2480 | |
| 2481 | if obj_id in bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save_related().(bundle).objects_saved: |
| 2482 | # It's already been saved. We're done here. |
| 2483 | continue |
| 2484 | |
| 2485 | if bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save_related().(bundle).data.get(field_name): |
| 2486 | if hasattr(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save_related().(bundle).data[field_name], 'keys'): |
| 2487 | # Only build & save if there's data, not just a URI. |
| 2488 | related_bundle = related_resource.build_bundle( |
| 2489 | obj=related_obj, |
| 2490 | data=bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save_related().(bundle).data.get(field_name), |
| 2491 | request=bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save_related().(bundle).request, |
| 2492 | objects_saved=bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save_related().(bundle).objects_saved |
| 2493 | ) |
| 2494 | related_resource.full_hydrate(related_bundle) |
| 2495 | related_resource.save(related_bundle) |
| 2496 | related_obj = related_bundle.obj |
| 2497 | elif field_object.related_name: |
| 2498 | # This condition probably means a URI for a reverse |
| 2499 | # relation was provided. |
| 2500 | related_bundle = related_resource.build_bundle( |
| 2501 | obj=related_obj, |
| 2502 | request=bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save_related().(bundle).request, |
| 2503 | objects_saved=bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save_related().(bundle).objects_saved |
| 2504 | ) |
| 2505 | related_resource.save(related_bundle) |
| 2506 | related_obj = related_bundle.obj |
| 2507 | |
| 2508 | if related_obj: |
| 2509 | setattr(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save_related().(bundle).obj, field_object.attribute, related_obj) |
| 2510 | |
| 2511 | def save_m2mscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save_m2m().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save_m2m().(self), bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save_m2m().(bundle)): |
| 2512 | """ |
| 2513 | Handles the saving of related M2M data. |
| 2514 | |
| 2515 | Due to the way Django works, the M2M data must be handled after the |
| 2516 | main instance, which is why this isn't a part of the main ``save`` bits. |
| 2517 | |
| 2518 | Currently slightly inefficient in that it will clear out the whole |
| 2519 | relation and recreate the related data as needed. |
| 2520 | """ |
| 2521 | for field_name, field_object in selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save_m2m().(self).fieldsscip-python python django-tastypie 0.15.1 `tastypie.resources`/Resource#fields..itemsscip-python python python-stdlib 3.11 builtins/dict#items().(): |
| 2522 | if not field_object.is_m2m: |
| 2523 | continue |
| 2524 | |
| 2525 | if not field_object.attribute: |
| 2526 | continue |
| 2527 | |
| 2528 | if field_object.readonly: |
| 2529 | continue |
| 2530 | |
| 2531 | # If this is a PATCH, make sure that this field name is one of the |
| 2532 | # patched fields (recorded in the update_fields property of the bundle). |
| 2533 | # Otherwise, we do not want to save / recreate this field. |
| 2534 | if hasattr(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save_m2m().(bundle), 'update_fields'): |
| 2535 | # This bundle is from a PATCH, we should not save an M2M field |
| 2536 | # unless it was present in the PATCH |
| 2537 | if field_name not in bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save_m2m().(bundle).m2m_update_fields: |
| 2538 | continue # Skip this field_name |
| 2539 | else: # this field name WAS in the patch, lets save it. |
| 2540 | pass |
| 2541 | else: # Not a PATCH operation, carry on normally. |
| 2542 | pass |
| 2543 | |
| 2544 | # Get the manager. |
| 2545 | related_mngr = None |
| 2546 | |
| 2547 | if isinstance(field_object.attribute, strscip-python python python-stdlib 3.11 builtins/str#): |
| 2548 | related_mngr = getattrscip-python python python-stdlib 3.11 builtins/getattr().(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save_m2m().(bundle).obj, field_object.attribute) |
| 2549 | elif callable(field_object.attribute): |
| 2550 | related_mngr = field_object.attribute(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save_m2m().(bundle)) |
| 2551 | |
| 2552 | if not related_mngr: |
| 2553 | continue |
| 2554 | |
| 2555 | if hasattr(related_mngr, 'clear'): |
| 2556 | # FIXME: Dupe the original bundle, copy in the new object & |
| 2557 | # check the perms on that (using the related resource)? |
| 2558 | |
| 2559 | # Clear it out, just to be safe. |
| 2560 | related_mngr.clear() |
| 2561 | |
| 2562 | related_objs = [] |
| 2563 | |
| 2564 | for related_bundle in bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save_m2m().(bundle).data[field_name]: |
| 2565 | related_resource = field_object.get_related_resource(bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save_m2m().(bundle).obj) |
| 2566 | |
| 2567 | # Only build & save if there's data, not just a URI. |
| 2568 | updated_related_bundle = related_resource.build_bundle( |
| 2569 | obj=related_bundle.obj, |
| 2570 | data=related_bundle.data, |
| 2571 | request=bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save_m2m().(bundle).request, |
| 2572 | objects_saved=bundlescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#save_m2m().(bundle).objects_saved, |
| 2573 | via_uri=related_bundle.via_uri, |
| 2574 | ) |
| 2575 | |
| 2576 | related_resource.save(updated_related_bundle) |
| 2577 | related_objs.appendscip-python python python-stdlib 3.11 builtins/list#append().(updated_related_bundle.obj) |
| 2578 | |
| 2579 | related_mngr.add(*related_objs) |
| 2580 | |
| 2581 | |
| 2582 | class ModelResourcescip-python python django-tastypie 0.15.1 `tastypie.resources`/ModelResource#(BaseModelResourcescip-python python django-tastypie 0.15.1 `tastypie.resources`/BaseModelResource#, metaclass=ModelDeclarativeMetaclassscip-python python django-tastypie 0.15.1 `tastypie.resources`/ModelDeclarativeMetaclass#): |
| 2583 | pass |
| 2584 | |
| 2585 | |
| 2586 | class NamespacedModelResourcescip-python python django-tastypie 0.15.1 `tastypie.resources`/NamespacedModelResource#(ModelResourcescip-python python django-tastypie 0.15.1 `tastypie.resources`/ModelResource#): |
| 2587 | """ |
| 2588 | A ModelResource subclass that respects Django namespaces. |
| 2589 | """ |
| 2590 | def _build_reverse_urlscip-python python django-tastypie 0.15.1 `tastypie.resources`/NamespacedModelResource#_build_reverse_url().(selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/NamespacedModelResource#_build_reverse_url().(self), namescip-python python django-tastypie 0.15.1 `tastypie.resources`/NamespacedModelResource#_build_reverse_url().(name), argsscip-python python django-tastypie 0.15.1 `tastypie.resources`/NamespacedModelResource#_build_reverse_url().(args)=None, kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/NamespacedModelResource#_build_reverse_url().(kwargs)=None): |
| 2591 | namespaced = "%s:%s" % (selfscip-python python django-tastypie 0.15.1 `tastypie.resources`/NamespacedModelResource#_build_reverse_url().(self)._meta.urlconf_namespace, namescip-python python django-tastypie 0.15.1 `tastypie.resources`/NamespacedModelResource#_build_reverse_url().(name)) |
| 2592 | return reverse(namespaced, args=argsscip-python python django-tastypie 0.15.1 `tastypie.resources`/NamespacedModelResource#_build_reverse_url().(args), kwargs=kwargsscip-python python django-tastypie 0.15.1 `tastypie.resources`/NamespacedModelResource#_build_reverse_url().(kwargs)) |
| 2593 | |
| 2594 | |
| 2595 | # Based off of ``piston.utils.coerce_put_post``. Similarly BSD-licensed. |
| 2596 | # And no, the irony is not lost on me. |
| 2597 | def convert_post_to_VERBscip-python python django-tastypie 0.15.1 `tastypie.resources`/convert_post_to_VERB().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/convert_post_to_VERB().(request), verbscip-python python django-tastypie 0.15.1 `tastypie.resources`/convert_post_to_VERB().(verb)): |
| 2598 | """ |
| 2599 | Force Django to process the VERB. |
| 2600 | """ |
| 2601 | if requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/convert_post_to_VERB().(request).method == verbscip-python python django-tastypie 0.15.1 `tastypie.resources`/convert_post_to_VERB().(verb): |
| 2602 | if not hasattr(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/convert_post_to_VERB().(request), '_read_started'): |
| 2603 | requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/convert_post_to_VERB().(request)._read_started = False |
| 2604 | |
| 2605 | if hasattr(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/convert_post_to_VERB().(request), '_post'): |
| 2606 | del requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/convert_post_to_VERB().(request)._post |
| 2607 | del requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/convert_post_to_VERB().(request)._files |
| 2608 | |
| 2609 | try: |
| 2610 | requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/convert_post_to_VERB().(request).method = "POST" |
| 2611 | requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/convert_post_to_VERB().(request)._load_post_and_files() |
| 2612 | requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/convert_post_to_VERB().(request).method = verbscip-python python django-tastypie 0.15.1 `tastypie.resources`/convert_post_to_VERB().(verb) |
| 2613 | except AttributeErrorscip-python python python-stdlib 3.11 builtins/AttributeError#: |
| 2614 | requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/convert_post_to_VERB().(request).META['REQUEST_METHOD'] = 'POST' |
| 2615 | requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/convert_post_to_VERB().(request)._load_post_and_files() |
| 2616 | requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/convert_post_to_VERB().(request).META['REQUEST_METHOD'] = verbscip-python python django-tastypie 0.15.1 `tastypie.resources`/convert_post_to_VERB().(verb) |
| 2617 | setattr(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/convert_post_to_VERB().(request), verbscip-python python django-tastypie 0.15.1 `tastypie.resources`/convert_post_to_VERB().(verb), requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/convert_post_to_VERB().(request).POST) |
| 2618 | |
| 2619 | return requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/convert_post_to_VERB().(request) |
| 2620 | |
| 2621 | |
| 2622 | def convert_post_to_putscip-python python django-tastypie 0.15.1 `tastypie.resources`/convert_post_to_put().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/convert_post_to_put().(request)): |
| 2623 | return convert_post_to_VERBscip-python python django-tastypie 0.15.1 `tastypie.resources`/convert_post_to_VERB().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/convert_post_to_put().(request), verbscip-python python django-tastypie 0.15.1 `tastypie.resources`/convert_post_to_VERB().(verb)='PUT') |
| 2624 | |
| 2625 | |
| 2626 | def convert_post_to_patchscip-python python django-tastypie 0.15.1 `tastypie.resources`/convert_post_to_patch().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/convert_post_to_patch().(request)): |
| 2627 | return convert_post_to_VERBscip-python python django-tastypie 0.15.1 `tastypie.resources`/convert_post_to_VERB().(requestscip-python python django-tastypie 0.15.1 `tastypie.resources`/convert_post_to_patch().(request), verbscip-python python django-tastypie 0.15.1 `tastypie.resources`/convert_post_to_VERB().(verb)='PATCH') |