# Path: app/validators.py
# def validate_image(value):
#     """
#     Validates if the image which is uploading is exactly image, because file can be renamed.
#     Raises an error if validation not passed.
# 
#     :param str value: The file object.
#     """
#     if not imghdr.what(value):
#         raise ValidationError('Tried to upload not an image!')
# 
# def validate_pdf(value):
#     """
#     Validates the uploading file if it is a PDF.
#     Raises an error if validation not passed.
# 
#     :param value: The file object.
#     """
#     try:
#         PyPDF2.PdfFileReader(io.BytesIO(value.read()))
#     except PyPDF2.utils.PdfReadError:
#         raise ValidationError('Tried to upload not PDF as a book!')


from django import forms
from django.core.exceptions import ValidationError
from django.core.validators import MinValueValidator, MaxValueValidator
from django.core.validators import MinLengthValidator, MaxLengthValidator
from django.core.validators import RegexValidator, EmailValidator
from .validators import validate_image, validate_pdf
    category = forms.IntegerField(required=False)
    criterion = forms.CharField(max_length=30)
    page = forms.IntegerField(validators=[MinValueValidator(1)])


# ----------------------------------------------------------------------------------------------------------------------
class SearchBookForm(forms.Form):
    data = forms.CharField(max_length=255)
    page = forms.IntegerField(validators=[MinValueValidator(1)])


# ----------------------------------------------------------------------------------------------------------------------
class BookPagingForm(forms.Form):
    page = forms.IntegerField(validators=[MinValueValidator(1)])


# ----------------------------------------------------------------------------------------------------------------------
class SetCurrentPageForm(forms.Form):
    page = forms.IntegerField(validators=[MinValueValidator(1)])
    book = forms.CharField(max_length=500)


# ----------------------------------------------------------------------------------------------------------------------
class AddBookImageForm(forms.Form):
    book = forms.CharField(max_length=255)
    image = forms.FileField()


# ----------------------------------------------------------------------------------------------------------------------
class UploadAvatarForm(forms.Form):

# Path: app/validators.py
# def validate_image(value):
#     """
#     Validates if the image which is uploading is exactly image, because file can be renamed.
#     Raises an error if validation not passed.
# 
#     :param str value: The file object.
#     """
#     if not imghdr.what(value):
#         raise ValidationError('Tried to upload not an image!')
# 
# def validate_pdf(value):
#     """
#     Validates the uploading file if it is a PDF.
#     Raises an error if validation not passed.
# 
#     :param value: The file object.
#     """
#     try:
#         PyPDF2.PdfFileReader(io.BytesIO(value.read()))
#     except PyPDF2.utils.PdfReadError:
#         raise ValidationError('Tried to upload not PDF as a book!')


# Path: app/forms.py
from django import forms
from django.core.exceptions import ValidationError
from django.core.validators import MinValueValidator, MaxValueValidator
from django.core.validators import MinLengthValidator, MaxLengthValidator
from django.core.validators import RegexValidator, EmailValidator
from .validators import validate_image, validate_pdf

    category = forms.IntegerField(required=False)
    criterion = forms.CharField(max_length=30)
    page = forms.IntegerField(validators=[MinValueValidator(1)])


# ----------------------------------------------------------------------------------------------------------------------
class SearchBookForm(forms.Form):
    data = forms.CharField(max_length=255)
    page = forms.IntegerField(validators=[MinValueValidator(1)])


# ----------------------------------------------------------------------------------------------------------------------
class BookPagingForm(forms.Form):
    page = forms.IntegerField(validators=[MinValueValidator(1)])


# ----------------------------------------------------------------------------------------------------------------------
class SetCurrentPageForm(forms.Form):
    page = forms.IntegerField(validators=[MinValueValidator(1)])
    book = forms.CharField(max_length=500)


# ----------------------------------------------------------------------------------------------------------------------
class AddBookImageForm(forms.Form):
    book = forms.CharField(max_length=255)
    image = forms.FileField()


# ----------------------------------------------------------------------------------------------------------------------
class UploadAvatarForm(forms.Form):

    avatar = forms.FileField(validators=[validate_image])