generated from ita-social-projects/DevTemplate
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #614 from ita-social-projects/SeparateBackend
Separate backend
- Loading branch information
Showing
116 changed files
with
138 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
0
manage.py → BackEnd/manage.py
100755 → 100644
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file.
68 changes: 34 additions & 34 deletions
68
validation/validate_edrpou.py → BackEnd/validation/validate_edrpou.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,34 @@ | ||
from django.core.exceptions import ValidationError | ||
|
||
|
||
def validate_edrpou(edrpou: str): | ||
if len(edrpou) != 8 or not edrpou.isdecimal(): | ||
raise ValidationError("EDRPOU must be exactly 8 digits long.") | ||
value_for_validation = [int(i) for i in edrpou] | ||
# Determine weight coefficients for calculating the checksum key, based on the value of the EDRPOU. | ||
weight_coeff_base = ( | ||
[7, 1, 2, 3, 4, 5, 6] | ||
if 30000000 < int(edrpou) < 60000000 | ||
else [1, 2, 3, 4, 5, 6, 7] | ||
) | ||
|
||
# Calculate the checksum key using the first 7 digits of EDRPOU code and weight coefficients. | ||
# If the key greater than 10, 'extra' is added to each weight to adjust the key calculation. | ||
def calculate_key(extra=0): | ||
return ( | ||
sum( | ||
(weight_coeff_base[i] + extra) * value_for_validation[i] | ||
for i in range(7) | ||
) | ||
% 11 | ||
) | ||
|
||
key = calculate_key() | ||
if key > 10: | ||
key = calculate_key(2) | ||
if key < 10 and key == value_for_validation[-1]: | ||
return True | ||
else: | ||
raise ValidationError( | ||
"EDRPOU is not correct, checksum key is not valid." | ||
) | ||
from django.core.exceptions import ValidationError | ||
|
||
|
||
def validate_edrpou(edrpou: str): | ||
if len(edrpou) != 8 or not edrpou.isdecimal(): | ||
raise ValidationError("EDRPOU must be exactly 8 digits long.") | ||
value_for_validation = [int(i) for i in edrpou] | ||
# Determine weight coefficients for calculating the checksum key, based on the value of the EDRPOU. | ||
weight_coeff_base = ( | ||
[7, 1, 2, 3, 4, 5, 6] | ||
if 30000000 < int(edrpou) < 60000000 | ||
else [1, 2, 3, 4, 5, 6, 7] | ||
) | ||
|
||
# Calculate the checksum key using the first 7 digits of EDRPOU code and weight coefficients. | ||
# If the key greater than 10, 'extra' is added to each weight to adjust the key calculation. | ||
def calculate_key(extra=0): | ||
return ( | ||
sum( | ||
(weight_coeff_base[i] + extra) * value_for_validation[i] | ||
for i in range(7) | ||
) | ||
% 11 | ||
) | ||
|
||
key = calculate_key() | ||
if key > 10: | ||
key = calculate_key(2) | ||
if key < 10 and key == value_for_validation[-1]: | ||
return True | ||
else: | ||
raise ValidationError( | ||
"EDRPOU is not correct, checksum key is not valid." | ||
) |
24 changes: 12 additions & 12 deletions
24
validation/validate_foundation_year.py → ...nd/validation/validate_foundation_year.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
import datetime | ||
from django.core.exceptions import ValidationError | ||
|
||
|
||
def validate_foundation_year_range(foundation_year_value: int) -> None: | ||
if not ( | ||
foundation_year_value | ||
in range(1800, (datetime.datetime.now().year + 1)) | ||
): | ||
raise ValidationError( | ||
"Foundation year must be exactly in range 1800-current year." | ||
) | ||
import datetime | ||
from django.core.exceptions import ValidationError | ||
|
||
|
||
def validate_foundation_year_range(foundation_year_value: int) -> None: | ||
if not ( | ||
foundation_year_value | ||
in range(1800, (datetime.datetime.now().year + 1)) | ||
): | ||
raise ValidationError( | ||
"Foundation year must be exactly in range 1800-current year." | ||
) |
58 changes: 29 additions & 29 deletions
58
validation/validate_image.py → BackEnd/validation/validate_image.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,29 @@ | ||
from django.core.exceptions import ValidationError | ||
from PIL import Image | ||
|
||
Image.MAX_IMAGE_PIXELS = None | ||
|
||
MAX_ALLOWED_BANNER_IMAGE_SIZE = 5 * 1024 * 1024 | ||
MAX_ALLOWED_LOGO_IMAGE_SIZE = 1 * 1024 * 1024 | ||
|
||
|
||
def validate_image_format(image: Image): | ||
valid_formats = ["PNG", "JPEG"] | ||
img = Image.open(image) | ||
format_ = img.format | ||
if format_ not in valid_formats: | ||
raise ValidationError( | ||
"Unsupported image format. Only PNG and JPEG are allowed." | ||
) | ||
|
||
|
||
def validate_image_size(image_file): | ||
max_size = image_file.size | ||
if max_size > MAX_ALLOWED_BANNER_IMAGE_SIZE: | ||
raise ValidationError("Image size exceeds the maximum allowed (5MB).") | ||
|
||
|
||
def validate_logo_size(image_file): | ||
max_size = image_file.size | ||
if max_size > MAX_ALLOWED_LOGO_IMAGE_SIZE: | ||
raise ValidationError("Image size exceeds the maximum allowed (1MB).") | ||
from django.core.exceptions import ValidationError | ||
from PIL import Image | ||
|
||
Image.MAX_IMAGE_PIXELS = None | ||
|
||
MAX_ALLOWED_BANNER_IMAGE_SIZE = 5 * 1024 * 1024 | ||
MAX_ALLOWED_LOGO_IMAGE_SIZE = 1 * 1024 * 1024 | ||
|
||
|
||
def validate_image_format(image: Image): | ||
valid_formats = ["PNG", "JPEG"] | ||
img = Image.open(image) | ||
format_ = img.format | ||
if format_ not in valid_formats: | ||
raise ValidationError( | ||
"Unsupported image format. Only PNG and JPEG are allowed." | ||
) | ||
|
||
|
||
def validate_image_size(image_file): | ||
max_size = image_file.size | ||
if max_size > MAX_ALLOWED_BANNER_IMAGE_SIZE: | ||
raise ValidationError("Image size exceeds the maximum allowed (5MB).") | ||
|
||
|
||
def validate_logo_size(image_file): | ||
max_size = image_file.size | ||
if max_size > MAX_ALLOWED_LOGO_IMAGE_SIZE: | ||
raise ValidationError("Image size exceeds the maximum allowed (1MB).") |
38 changes: 19 additions & 19 deletions
38
validation/validate_password.py → BackEnd/validation/validate_password.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
from django.core.exceptions import ValidationError | ||
|
||
|
||
def validate_password_long(password_value: str): | ||
if len(password_value) < 8: | ||
raise ValidationError("Password must be at least 8 characters long.") | ||
if len(password_value) > 128: | ||
raise ValidationError("The password must not exceed 128 characters.") | ||
|
||
|
||
def validate_password_include_symbols(password_value: str): | ||
if ( | ||
not any(char.isupper() for char in password_value) | ||
or not any(char.islower() for char in password_value) | ||
or not any(char.isdigit() for char in password_value) | ||
): | ||
raise ValidationError( | ||
"Password must include at least one uppercase letter (A-Z), one lowercase letter (a-z) and one digit (0-9)." | ||
) | ||
from django.core.exceptions import ValidationError | ||
|
||
|
||
def validate_password_long(password_value: str): | ||
if len(password_value) < 8: | ||
raise ValidationError("Password must be at least 8 characters long.") | ||
if len(password_value) > 128: | ||
raise ValidationError("The password must not exceed 128 characters.") | ||
|
||
|
||
def validate_password_include_symbols(password_value: str): | ||
if ( | ||
not any(char.isupper() for char in password_value) | ||
or not any(char.islower() for char in password_value) | ||
or not any(char.isdigit() for char in password_value) | ||
): | ||
raise ValidationError( | ||
"Password must include at least one uppercase letter (A-Z), one lowercase letter (a-z) and one digit (0-9)." | ||
) |
26 changes: 13 additions & 13 deletions
26
validation/validate_phone_number.py → BackEnd/validation/validate_phone_number.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
from django.core.exceptions import ValidationError | ||
|
||
|
||
def validate_phone_number_len(phone_number_value: str): | ||
if len(phone_number_value) != 12: | ||
raise ValidationError( | ||
"Phone number must be exactly 12 characters long." | ||
) | ||
|
||
|
||
def validate_phone_number_is_digit(phone_number_value: str): | ||
if not phone_number_value.isdigit(): | ||
raise ValidationError("Phone number must contain only numbers.") | ||
from django.core.exceptions import ValidationError | ||
|
||
|
||
def validate_phone_number_len(phone_number_value: str): | ||
if len(phone_number_value) != 12: | ||
raise ValidationError( | ||
"Phone number must be exactly 12 characters long." | ||
) | ||
|
||
|
||
def validate_phone_number_is_digit(phone_number_value: str): | ||
if not phone_number_value.isdigit(): | ||
raise ValidationError("Phone number must contain only numbers.") |
42 changes: 21 additions & 21 deletions
42
validation/validate_rnokpp.py → BackEnd/validation/validate_rnokpp.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,21 @@ | ||
from django.core.exceptions import ValidationError | ||
|
||
|
||
def validate_rnokpp(rnokpp: str): | ||
if len(rnokpp) != 10 or not rnokpp.isdecimal(): | ||
raise ValidationError("RNOKPP must be exactly 10 digits long.") | ||
value_for_validation = [int(i) for i in rnokpp] | ||
# Weight coefficients for calculating the checksum key | ||
weight_coeff_base = [-1, 5, 7, 9, 4, 6, 10, 5, 7] | ||
# Calculate the checksum key using the first 9 digits of RNOKPP code and weight coefficients. | ||
key = ( | ||
sum(weight_coeff_base[i] * value_for_validation[i] for i in range(9)) | ||
% 11 | ||
) % 10 | ||
# Validate the RNOKPP by comparing the calculated checksum key with its last digit. | ||
if key == value_for_validation[-1]: | ||
return True | ||
else: | ||
raise ValidationError( | ||
"RNOKPP is not correct, checksum key is not valid." | ||
) | ||
from django.core.exceptions import ValidationError | ||
|
||
|
||
def validate_rnokpp(rnokpp: str): | ||
if len(rnokpp) != 10 or not rnokpp.isdecimal(): | ||
raise ValidationError("RNOKPP must be exactly 10 digits long.") | ||
value_for_validation = [int(i) for i in rnokpp] | ||
# Weight coefficients for calculating the checksum key | ||
weight_coeff_base = [-1, 5, 7, 9, 4, 6, 10, 5, 7] | ||
# Calculate the checksum key using the first 9 digits of RNOKPP code and weight coefficients. | ||
key = ( | ||
sum(weight_coeff_base[i] * value_for_validation[i] for i in range(9)) | ||
% 11 | ||
) % 10 | ||
# Validate the RNOKPP by comparing the calculated checksum key with its last digit. | ||
if key == value_for_validation[-1]: | ||
return True | ||
else: | ||
raise ValidationError( | ||
"RNOKPP is not correct, checksum key is not valid." | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters