Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
djangorestframework / __pycache__ / validators.cpython-35.pyc
Size: Mime:


£OY (ã@sdZddlmZddlmZddlmZddlm	Z	ddl
mZddlm
Z
dd	„Zd
d„ZGdd
„d
eƒZGdd„deƒZGdd„deƒZGdd„deƒZGdd„deƒZGdd„deƒZdS)aK
We perform uniqueness checks explicitly on the serializer class, rather
the using Django's `.full_clean()`.

This gives us better separation of concerns, allows us to use single-step
object creation, and makes it possible to switch between using the implicit
`ModelSerializer` class and an equivalent explicit `Serializer` class.
é)Úunicode_literals)Ú	DataError)Ú
ugettext_lazy)Úunicode_to_repr)ÚValidationError)Ú
smart_reprc
Cs4y|jƒSWntttfk
r/dSYnXdS)NF)ÚexistsÚ	TypeErrorÚ
ValueErrorr)Úqueryset©rúX/Users/carlton/Documents/Django-Stack/django-rest-framework/rest_framework/validators.pyÚ	qs_existssrc
Ks=y|j|SWn%tttfk
r8|jƒSYnXdS)N)Úfilterr	r
rÚnone)rÚkwargsrrr
Ú	qs_filtersrc@speZdZdZedƒZdddd„Zdd„Zd	d
„Zdd„Z	d
d„Z
dd„ZdS)ÚUniqueValidatorzˆ
    Validator that corresponds to `unique=True` on a model field.

    Should be applied to an individual field on the serializer.
    zThis field must be unique.NÚexactcCs1||_d|_|p|j|_||_dS)N)rÚserializer_fieldÚmessageÚlookup)Úselfrrrrrr
Ú__init__-s		zUniqueValidator.__init__cCs,|jd|_t|jddƒ|_dS)zr
        This hook is called by the serializer instance,
        prior to the validation call being made.
        éÚinstanceNéÿÿÿÿ)Úsource_attrsÚ
field_nameÚgetattrÚparentr)rrrrr
Úset_context3szUniqueValidator.set_contextcCs)d|j|jf|i}t||S)zT
        Filter the queryset to all instances matching the given attribute.
        z%s__%s)rrr)rÚvaluerÚ
filter_kwargsrrr
Úfilter_queryset>szUniqueValidator.filter_querysetcCs)|jdk	r%|jd|jjƒS|S)z}
        If an instance is being updated, then do not include
        that instance itself as a uniqueness conflict.
        NÚpk)rÚexcluder%)rrrrr
Úexclude_current_instanceEsz(UniqueValidator.exclude_current_instancecCsO|j}|j||ƒ}|j|ƒ}t|ƒrKt|jddƒ‚dS)NÚcodeÚunique)rr$r'rrr)rr"rrrr
Ú__call__Ns
	zUniqueValidator.__call__cCs#td|jjt|jƒfƒS)Nz<%s(queryset=%s)>)rÚ	__class__Ú__name__rr)rrrr
Ú__repr__Us	zUniqueValidator.__repr__)r,Ú
__module__Ú__qualname__Ú__doc__Ú_rrr!r$r'r*r-rrrr
r%s	rc@s…eZdZdZedƒZedƒZddd„Zdd„Zd	d
„Z	dd„Z
d
d„Zdd„Zdd„Z
dS)ÚUniqueTogetherValidatorzŸ
    Validator that corresponds to `unique_together = (...)` on a model class.

    Should be applied to the serializer class, not to an individual field.
    z0The fields {field_names} must make a unique set.zThis field is required.NcCs1||_||_d|_|p'|j|_dS)N)rÚfieldsrr)rrr3rrrr
res			z UniqueTogetherValidator.__init__cCst|ddƒ|_dS)zr
        This hook is called by the serializer instance,
        prior to the validation call being made.
        rN)rr)rÚ
serializerrrr
r!ksz#UniqueTogetherValidator.set_contextcsNˆjdk	rdS‡‡fdd†ˆjDƒ}|rJt|ddƒ‚dS)z~
        The `UniqueTogetherValidator` always forces an implied 'required'
        state on the fields it applies to.
        Ncs(i|]}|ˆkrˆj|“qSr)Úmissing_message)Ú.0r)Úattrsrrr
ú
<dictcomp>|s	zCUniqueTogetherValidator.enforce_required_fields.<locals>.<dictcomp>r(Úrequired)rr3r)rr7Ú
missing_itemsr)r7rr
Úenforce_required_fieldsss
z/UniqueTogetherValidator.enforce_required_fieldscsn|jdk	rEx3|jD](}|ˆkrt|j|ƒˆ|<qW‡fdd†|jDƒ}t||S)zU
        Filter the queryset to all instances matching the given attributes.
        Ncsi|]}ˆ||“qSrr)r6r)r7rr
r8s	z;UniqueTogetherValidator.filter_queryset.<locals>.<dictcomp>)rr3rr)rr7rrr#r)r7r
r$ƒs
z'UniqueTogetherValidator.filter_querysetcCs)|jdk	r%|jd|jjƒS|S)z}
        If an instance is being updated, then do not include
        that instance itself as a uniqueness conflict.
        Nr%)rr&r%)rr7rrrr
r'•sz0UniqueTogetherValidator.exclude_current_instancecs®ˆj|ƒˆj}ˆj||ƒ}ˆj||ƒ}‡fdd†|jƒDƒ}d|krªt|ƒrªdjˆjƒ}ˆjj	d|ƒ}t
|ddƒ‚dS)Ncs+g|]!\}}|ˆjkr|‘qSr)r3)r6Úfieldr")rrr
ú
<listcomp>¦s	z4UniqueTogetherValidator.__call__.<locals>.<listcomp>z, Úfield_namesr(r))r;rr$r'ÚitemsrÚjoinr3rÚformatr)rr7rZchecked_valuesr>rr)rr
r*žs
	z UniqueTogetherValidator.__call__cCs/td|jjt|jƒt|jƒfƒS)Nz<%s(queryset=%s, fields=%s)>)rr+r,rrr3)rrrr
r-­s	z UniqueTogetherValidator.__repr__)r,r.r/r0r1rr5rr!r;r$r'r*r-rrrr
r2\s	r2c@syeZdZdZedƒZddd„Zdd„Zdd„Zd	d
„Z	dd„Z
d
d„Zdd„ZdS)ÚBaseUniqueForValidatorNzThis field is required.cCs1||_||_||_|p'|j|_dS)N)rr<Ú
date_fieldr)rrr<rCrrrr
r¹s			zBaseUniqueForValidator.__init__cCsM|j|jjd|_|j|jjd|_t|ddƒ|_dS)zr
        This hook is called by the serializer instance,
        prior to the validation call being made.
        rrNrr)r3r<rrrCÚdate_field_namerr)rr4rrr
r!¿sz"BaseUniqueForValidator.set_contextcsD‡‡fdd†ˆjˆjgDƒ}|r@t|ddƒ‚dS)z
        The `UniqueFor<Range>Validator` classes always force an implied
        'required' state on the fields they are applied to.
        cs(i|]}|ˆkrˆj|“qSr)r5)r6r)r7rrr
r8Ñs	zBBaseUniqueForValidator.enforce_required_fields.<locals>.<dictcomp>r(r9N)r<rCr)rr7r:r)r7rr
r;Ësz.BaseUniqueForValidator.enforce_required_fieldscCstdƒ‚dS)Nz&`filter_queryset` must be implemented.)ÚNotImplementedError)rr7rrrr
r$Øsz&BaseUniqueForValidator.filter_querysetcCs)|jdk	r%|jd|jjƒS|S)z}
        If an instance is being updated, then do not include
        that instance itself as a uniqueness conflict.
        Nr%)rr&r%)rr7rrrr
r'Ûsz/BaseUniqueForValidator.exclude_current_instancecCs}|j|ƒ|j}|j||ƒ}|j||ƒ}t|ƒry|jjd|jƒ}t|j	|iddƒ‚dS)NrCr(r))
r;rr$r'rrrArCrr<)rr7rrrrr
r*äs
	zBaseUniqueForValidator.__call__cCs;td|jjt|jƒt|jƒt|jƒfƒS)Nz*<%s(queryset=%s, field=%s, date_field=%s)>)rr+r,rrr<rC)rrrr
r-ïs
	zBaseUniqueForValidator.__repr__)
r,r.r/rr1r5rr!r;r$r'r*r-rrrr
rBµs
	rBc@s(eZdZedƒZdd„ZdS)ÚUniqueForDateValidatorz6This field must be unique for the "{date_field}" date.cCsv||j}||j}i}|||j<|j|d|j<|j|d|j<|j|d|j<t||S)Nz%s__dayz	%s__monthz%s__year)r<rCrÚdayrDÚmonthÚyearr)rr7rr"Údater#rrr
r$ûs


z&UniqueForDateValidator.filter_querysetN)r,r.r/r1rr$rrrr
rFøsrFc@s(eZdZedƒZdd„ZdS)ÚUniqueForMonthValidatorz7This field must be unique for the "{date_field}" month.cCsN||j}||j}i}|||j<|j|d|j<t||S)Nz	%s__month)r<rCrrHrDr)rr7rr"rJr#rrr
r$
s


z'UniqueForMonthValidator.filter_querysetN)r,r.r/r1rr$rrrr
rKsrKc@s(eZdZedƒZdd„ZdS)ÚUniqueForYearValidatorz6This field must be unique for the "{date_field}" year.cCsN||j}||j}i}|||j<|j|d|j<t||S)Nz%s__year)r<rCrrIrDr)rr7rr"rJr#rrr
r$s


z&UniqueForYearValidator.filter_querysetN)r,r.r/r1rr$rrrr
rLsrLN)r0Ú
__future__rÚ	django.dbrÚdjango.utils.translationrr1Úrest_framework.compatrÚrest_framework.exceptionsrZ#rest_framework.utils.representationrrrÚobjectrr2rBrFrKrLrrrr
Ú<module>s7YC