Skip to content

Commit

Permalink
Merge pull request #614 from ita-social-projects/SeparateBackend
Browse files Browse the repository at this point in the history
Separate backend
  • Loading branch information
BelousSofiya authored May 28, 2024
2 parents cd4f65a + e7dbec3 commit 09e4ff4
Show file tree
Hide file tree
Showing 116 changed files with 138 additions and 135 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/tests_be.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,16 @@ jobs:
- uses: actions/setup-python@v3
with:
python-verion: 3.10
- name: install requirements.txt
- name: install ./BackEnd/requirements.txt
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r ./BackEnd/requirements.txt
- name: Create Migrations
run: |
cd BackEnd
python manage.py makemigrations
python manage.py migrate
- name: running tests
run: python manage.py test --settings=forum.test_setting
run: |
cd BackEnd
python manage.py test --settings=forum.test_setting
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ env
__pycache__/
/FrontEnd/node_modules

public/*
!public/media/.gitkeep
!public/static/.gitkeep
BackEnd/public/*
!BackEnd/public/media/.gitkeep
!BackEnd/public/static/.gitkeep
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.
Empty file added BackEnd/utils/__init__.py
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file added BackEnd/validation/__init__.py
Empty file.
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."
)
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."
)
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).")
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)."
)
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.")
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."
)
2 changes: 1 addition & 1 deletion docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: '3.9'

services:
api-dev:
build: .
build: ./BackEnd
container_name: api-dev
restart: on-failure
command: gunicorn --log-level debug forum.wsgi:application --bind 0.0.0.0:8000
Expand Down

0 comments on commit 09e4ff4

Please sign in to comment.