Skip to content

Commit

Permalink
Done requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Aryamanz29 committed Apr 8, 2021
1 parent b4b90c6 commit cb0621c
Show file tree
Hide file tree
Showing 43 changed files with 81 additions and 226 deletions.
11 changes: 9 additions & 2 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
#W503 Line break occurred before a binary operator
#F841 Local variable name is assigned to but never used


[flake8]
ignore = F401,F405,W503,F841,F403,E402,F821,W291,E266,F811
max-line-length = 160
ignore = F841,W503

# IGNORES F405 AND F403 FOR BELOW FILES
per-file-ignores = ./app/database/db_add_mock.py: F405,F403 ,./app/api/resources/users.py : F405,F403,./app/api/resources/organizations.py : F405,F403
max-line-length = 180
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,21 @@ To run black:
```
black .
```
### Linting with Flake8
We use [flake8](https://flake8.pycqa.org/en/latest/) to lint the source code of this repository.

To install _Flake8_ run below command:
```
pip install flake8==3.8.4
```
Then run shell script using:

```
./flake8-check
```




## Project Documentation

Expand Down
6 changes: 2 additions & 4 deletions app/api/bit_extension.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from flask_restx import Api
from app.api.resources.users import users_ns as user_namespace
from app.api.resources.organizations import organizations_ns as organization_namespace

api = Api(
title="Bridge In Tech API",
Expand All @@ -14,10 +16,6 @@
api.namespaces.clear()

# Adding namespaces
from app.api.resources.users import users_ns as user_namespace

api.add_namespace(user_namespace, path="/")

from app.api.resources.organizations import organizations_ns as organization_namespace

api.add_namespace(organization_namespace, path="/")
4 changes: 1 addition & 3 deletions app/api/dao/organization.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import logging
import ast
from http import HTTPStatus
from flask import json
from sqlalchemy import func
from app.database.models.bit_schema.organization import OrganizationModel
from app.database.models.bit_schema.user_extension import UserExtensionModel
Expand All @@ -12,7 +11,6 @@
from app.utils.bit_constants import MAX_ORGANIZATIONS_PER_PAGE
from app.utils.decorator_utils import http_response_namedtuple_converter
from app.utils.date_converter import (
convert_human_date_to_timestamp,
convert_timestamp_to_human_date,
)

Expand Down Expand Up @@ -195,7 +193,7 @@ def list_organizations(name, page, per_page, token):
if not organizations_list:
return messages.NO_ORGANIZATION_FOUND, HTTPStatus.NOT_FOUND
return organizations_list, HTTPStatus.OK
except ValueError:
except ValueError as e:
return e, HTTPStatus.BAD_REQUEST


Expand Down
3 changes: 1 addition & 2 deletions app/api/dao/personal_background.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import ast
from http import HTTPStatus
from flask import json
from app.database.models.bit_schema.personal_background import PersonalBackgroundModel
from app import messages
from app.api.request_api_utils import AUTH_COOKIE
from app.utils.bitschema_utils import *
from app.utils.bitschema_utils import Gender, Age, Ethnicity, SexualOrientation, Religion ,PhysicalAbility, MentalAbility ,SocioEconomic ,HighestEducation , YearsOfExperience, Gender, Age # noqa


class PersonalBackgroundDAO:
Expand Down
6 changes: 1 addition & 5 deletions app/api/dao/program.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import ast
import datetime
import logging
from http import HTTPStatus
import pytz
from app.database.models.bit_schema.organization import OrganizationModel
from app.database.models.bit_schema.program import ProgramModel
from app.database.models.bit_schema.user_extension import UserExtensionModel
from app import messages
from app.api.request_api_utils import AUTH_COOKIE, get_request, http_response_checker
from app.utils.bitschema_utils import *
from app.utils.bit_constants import MAX_PROGRAMS_PER_PAGE
from app.utils.bitschema_utils import Timezone, ContactType, ProgramStatus, Zone
from app.utils.date_converter import (
convert_human_date_to_timestamp,
convert_timestamp_to_human_date,
Expand Down
1 change: 0 additions & 1 deletion app/api/dao/user_extension.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import ast
from http import HTTPStatus
from flask import json
from app.database.models.bit_schema.user_extension import UserExtensionModel
from app import messages
from app.api.request_api_utils import AUTH_COOKIE
Expand Down
1 change: 0 additions & 1 deletion app/api/request_api_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import logging
from http import HTTPStatus, cookies
from datetime import datetime
from flask import json
import requests
from app import messages
Expand Down
11 changes: 3 additions & 8 deletions app/api/resources/organizations.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
import ast
from http import HTTPStatus, cookies
from http import HTTPStatus
from flask import request
from flask_restx import Resource, marshal, Namespace
from flask_restx import Resource, Namespace
from app import messages
from app.api.request_api_utils import (
post_request,
get_request,
put_request,
http_response_checker,
AUTH_COOKIE,
validate_token,
)
from app.api.resources.common import auth_header_parser
from app.api.dao.organization import OrganizationDAO
from app.api.dao.program import ProgramDAO
from app.utils.validation_utils import expected_fields_validator
from app.api.models.organization import *
from app.api.models.organization import * # noqa
from app.api.validations.organization import (
validate_update_organization,
validate_update_program,
)
from app.utils.bit_constants import (
DEFAULT_PAGE,
DEFAULT_ORGANIZATIONS_PER_PAGE,
DEFAULT_PROGRAMS_PER_PAGE,
)


Expand Down
7 changes: 2 additions & 5 deletions app/api/resources/users.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import ast
import json
from http import HTTPStatus, cookies
from datetime import datetime, timedelta
from http import HTTPStatus
from flask import request
from flask_restx import Resource, marshal, Namespace
from flask_restx import Resource, Namespace
from app import messages
from app.api.request_api_utils import (
post_request,
Expand All @@ -19,7 +17,6 @@
from app.api.dao.user_extension import UserExtensionDAO
from app.api.dao.personal_background import PersonalBackgroundDAO
from app.utils.validation_utils import expected_fields_validator
from app.database.models.bit_schema.user_extension import UserExtensionModel
from app.utils.ms_constants import DEFAULT_PAGE, DEFAULT_USERS_PER_PAGE

users_ns = Namespace("Users", description="Operations related to users")
Expand Down
2 changes: 1 addition & 1 deletion app/api/validations/organization.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from app import messages
from app.utils.bitschema_utils import OrganizationStatus, Timezone, Zone, ProgramStatus
from app.utils.bitschema_utils import OrganizationStatus, Timezone, ProgramStatus
from app.utils.validation_utils import is_email_valid, is_phone_valid


Expand Down
24 changes: 12 additions & 12 deletions app/api/validations/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
validate_length,
get_stripped_string,
)
from app.utils.bitschema_utils import *
from app.utils.bitschema_utils import * # noqa

# Field character limit

Expand Down Expand Up @@ -256,7 +256,7 @@ def validate_update_additional_info_request(data):
mobile = data.get("mobile", None)

try:
timezone = Timezone(timezone_value).name
timezone = Timezone(timezone_value).name # noqa
except ValueError:
return messages.TIMEZONE_INPUT_IS_INVALID
if phone:
Expand All @@ -270,15 +270,15 @@ def validate_update_additional_info_request(data):
def validate_update_personal_background_info_request(data):
approved = []
try:
approved.append(Gender(data["gender"]).name)
approved.append(Age(data["age"]).name)
approved.append(Ethnicity(data["ethnicity"]).name)
approved.append(SexualOrientation(data["sexual_orientation"]).name)
approved.append(Religion(data["religion"]).name)
approved.append(PhysicalAbility(data["physical_ability"]).name)
approved.append(MentalAbility(data["mental_ability"]).name)
approved.append(SocioEconomic(data["socio_economic"]).name)
approved.append(HighestEducation(data["highest_education"]).name)
approved.append(YearsOfExperience(data["years_of_experience"]).name)
approved.append(Gender(data["gender"]).name) # noqa
approved.append(Age(data["age"]).name) # noqa
approved.append(Ethnicity(data["ethnicity"]).name) # noqa
approved.append(SexualOrientation(data["sexual_orientation"]).name) # noqa
approved.append(Religion(data["religion"]).name) # noqa
approved.append(PhysicalAbility(data["physical_ability"]).name) # noqa
approved.append(MentalAbility(data["mental_ability"]).name) # noqa
approved.append(SocioEconomic(data["socio_economic"]).name) # noqa
approved.append(HighestEducation(data["highest_education"]).name) # noqa
approved.append(YearsOfExperience(data["years_of_experience"]).name) # noqa
except ValueError:
return messages.PERSONAL_BACKGROUND_IS_INVALID
1 change: 0 additions & 1 deletion app/database/db_add_mock.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from datetime import datetime, timezone
from app.database.sqlalchemy_extension import db
from app.utils.bitschema_utils import *
from app.utils.enum_utils import *
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
from datetime import date

from app.database.models.ms_schema.mentorship_relation import MentorshipRelationModel
from app.database.sqlalchemy_extension import db


Expand Down
3 changes: 1 addition & 2 deletions app/database/models/bit_schema/organization.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import time
from sqlalchemy import null
from app.database.sqlalchemy_extension import db
from app.utils.bitschema_utils import OrganizationStatus, Timezone
from app.database.models.bit_schema.program import ProgramModel
Expand Down Expand Up @@ -45,7 +44,7 @@ class OrganizationModel(db.Model):

def __init__(self, rep_id, name, email, address, website, timezone):
"""Initialises OrganizationModel class."""
## required fields
# required fields

self.rep_id = rep_id
self.name = name
Expand Down
5 changes: 2 additions & 3 deletions app/database/models/bit_schema/personal_background.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from sqlalchemy import null
from sqlalchemy.dialects.postgresql import JSONB
from app.database.sqlalchemy_extension import db
from app.utils.bitschema_utils import *
from app.utils.bitschema_utils import Gender, Age, Ethnicity, SexualOrientation, Religion, PhysicalAbility, MentalAbility, HighestEducation, YearsOfExperience, SocioEconomic


class PersonalBackgroundModel(db.Model):
Expand Down Expand Up @@ -64,7 +63,7 @@ def __init__(
years_of_experience,
):
"""Initialises PersonalBackgroundModel class."""
## required fields
# required fields
self.user_id = user_id
self.gender = gender
self.age = age
Expand Down
3 changes: 1 addition & 2 deletions app/database/models/bit_schema/program.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import time
from sqlalchemy import null
from sqlalchemy import BigInteger, ARRAY
from sqlalchemy.dialects.postgresql import JSONB
from app.database.sqlalchemy_extension import db
Expand Down Expand Up @@ -68,7 +67,7 @@ class ProgramModel(db.Model):
)

"""Initialises ProgramModel class."""
## required fields
# required fields
def __init__(self, program_name, organization_id, start_date, end_date):
self.program_name = program_name
self.organization = organization_id
Expand Down
3 changes: 1 addition & 2 deletions app/database/models/bit_schema/user_extension.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from sqlalchemy import null
from sqlalchemy.dialects.postgresql import JSONB
from app.database.sqlalchemy_extension import db
from app.utils.bitschema_utils import Timezone
Expand Down Expand Up @@ -30,7 +29,7 @@ class UserExtensionModel(db.Model):
timezone = db.Column(db.Enum(Timezone))

"""Initialises UserExtensionModel class."""
## required fields
# required fields
def __init__(self, user_id, timezone):
self.user_id = user_id
self.timezone = timezone
Expand Down
4 changes: 0 additions & 4 deletions app/database/models/ms_schema/mentorship_relation.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
from datetime import date

from app.database.models.ms_schema.tasks_list import TasksListModel

# from app.database.models.bitschema import MentorshipRelationExtensionModel
from app.database.sqlalchemy_extension import db
from app.utils.enum_utils import MentorshipRelationState

Expand Down
5 changes: 1 addition & 4 deletions app/database/models/ms_schema/user.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import time
from typing import Optional
from sqlalchemy import null
from sqlalchemy.types import JSON
from werkzeug.security import generate_password_hash, check_password_hash
from app.database.sqlalchemy_extension import db
from app.database.models.bit_schema.personal_background import PersonalBackgroundModel
Expand Down Expand Up @@ -84,7 +81,7 @@ class UserModel(db.Model):

def __init__(self, name, username, password, email, terms_and_conditions_checked):
"""Initialises userModel class with name, username, password, email, and terms_and_conditions_checked. """
## required fields
# required fields

self.name = name
self.username = username
Expand Down
1 change: 0 additions & 1 deletion app/database/sqlalchemy_extension.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy import MetaData

Expand Down
1 change: 0 additions & 1 deletion app/utils/date_converter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import datetime
import pytz
import dateutil.parser


def convert_timestamp_to_human_date(unix_time, timezone):
Expand Down
6 changes: 3 additions & 3 deletions app/utils/validation_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
against predetermined patterns as well as to ensure the string input is within the accepted length.
For the "name" field to be valid, it may contain one or more character from:
- letter "a" to "z" and/or "A" to "Z",
- letter "a" to "z" and/or "A" to "Z",
- any of the whitespace characters, and/or
- special character "-".
Expand All @@ -28,7 +28,7 @@
- special character "-".
For the "phone" or "mobile" field to be valid, it must have the following format:
- must contain numbers from "0" to "9"
- must contain numbers from "0" to "9"
- may contain one or more character from special character "-"
- may contain one or more character from whitespace " "
"""
Expand Down Expand Up @@ -127,7 +127,7 @@ def get_length_validation_error_message(field_name, min_length, max_length):
- error message if minimum length is determined.
"""
if min_length is None:
return f"The {field_name} field has to be no more than {max_limit} characters."
return f"The {field_name} field has to be no more than {max_length} characters."

return f"The {field_name} field has to be at least {min_length} characters and no more than {max_length} characters."

Expand Down
21 changes: 2 additions & 19 deletions run.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os
from flask import Flask, jsonify
from flask_migrate import Migrate, MigrateCommand
from flask import Flask
from flask_migrate import Migrate
from flask_cors import CORS
from config import get_env_config

Expand All @@ -19,22 +18,6 @@ def create_app(config_filename: str) -> Flask:

db.init_app(app)

from app.database.models.ms_schema.user import UserModel
from app.database.models.ms_schema.mentorship_relation import (
MentorshipRelationModel,
)
from app.database.models.ms_schema.tasks_list import TasksListModel
from app.database.models.ms_schema.task_comment import TaskCommentModel
from app.database.models.bit_schema.organization import OrganizationModel
from app.database.models.bit_schema.program import ProgramModel
from app.database.models.bit_schema.user_extension import UserExtensionModel
from app.database.models.bit_schema.personal_background import (
PersonalBackgroundModel,
)
from app.database.models.bit_schema.mentorship_relation_extension import (
MentorshipRelationExtensionModel,
)

migrate = Migrate(app, db)

cors.init_app(app, resources={r"*": {"origins": "http://localhost:3000"}})
Expand Down
Loading

0 comments on commit cb0621c

Please sign in to comment.