from rest_framework.permissions import BasePermission
from django.shortcuts import get_object_or_404

from ..models import Sequence


class LessOrEqThanLen(BasePermission):
    '''Меньше, чем длина массива'''
    def has_permission(self, request, view):
        ind = request.data['index']
        seq = get_object_or_404(Sequence, id=request.data['sequence'])
        return int(ind) <= seq.length

class NoSuchPoint(BasePermission):
    '''Точка с определенным индексом может быть только одна'''
    def has_permission(self, request, view):
        ind = request.data['index']
        seq = get_object_or_404(Sequence, id=request.data['sequence'])
        return not seq.points.filter(index=int(ind)).exists()
e6d2bcb7ffada588c3a0e25bf7944cb18169ff50
<mask token>


class LessOrEqThanLen(BasePermission):
    <mask token>
    <mask token>


class NoSuchPoint(BasePermission):
    """Точка с определенным индексом может быть только одна"""

    def has_permission(self, request, view):
        ind = request.data['index']
        seq = get_object_or_404(Sequence, id=request.data['sequence'])
        return not seq.points.filter(index=int(ind)).exists()

<mask token>


class LessOrEqThanLen(BasePermission):
    <mask token>

    def has_permission(self, request, view):
        ind = request.data['index']
        seq = get_object_or_404(Sequence, id=request.data['sequence'])
        return int(ind) <= seq.length


class NoSuchPoint(BasePermission):
    """Точка с определенным индексом может быть только одна"""

    def has_permission(self, request, view):
        ind = request.data['index']
        seq = get_object_or_404(Sequence, id=request.data['sequence'])
        return not seq.points.filter(index=int(ind)).exists()

<mask token>


class LessOrEqThanLen(BasePermission):
    """Меньше, чем длина массива"""

    def has_permission(self, request, view):
        ind = request.data['index']
        seq = get_object_or_404(Sequence, id=request.data['sequence'])
        return int(ind) <= seq.length


class NoSuchPoint(BasePermission):
    """Точка с определенным индексом может быть только одна"""

    def has_permission(self, request, view):
        ind = request.data['index']
        seq = get_object_or_404(Sequence, id=request.data['sequence'])
        return not seq.points.filter(index=int(ind)).exists()

from rest_framework.permissions import BasePermission
from django.shortcuts import get_object_or_404
from ..models import Sequence


class LessOrEqThanLen(BasePermission):
    """Меньше, чем длина массива"""

    def has_permission(self, request, view):
        ind = request.data['index']
        seq = get_object_or_404(Sequence, id=request.data['sequence'])
        return int(ind) <= seq.length


class NoSuchPoint(BasePermission):
    """Точка с определенным индексом может быть только одна"""

    def has_permission(self, request, view):
        ind = request.data['index']
        seq = get_object_or_404(Sequence, id=request.data['sequence'])
        return not seq.points.filter(index=int(ind)).exists()

from rest_framework.permissions import BasePermission
from django.shortcuts import get_object_or_404

from ..models import Sequence


class LessOrEqThanLen(BasePermission):
    '''Меньше, чем длина массива'''
    def has_permission(self, request, view):
        ind = request.data['index']
        seq = get_object_or_404(Sequence, id=request.data['sequence'])
        return int(ind) <= seq.length

class NoSuchPoint(BasePermission):
    '''Точка с определенным индексом может быть только одна'''
    def has_permission(self, request, view):
        ind = request.data['index']
        seq = get_object_or_404(Sequence, id=request.data['sequence'])
        return not seq.points.filter(index=int(ind)).exists()