Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
266998b
commit
yashgoyal0110 Apr 5, 2025
13c49e4
make changes to config
yashgoyal0110 Apr 6, 2025
d70fc22
Merge branch 'main' into feat/adding-type-annotations
arkid15r Apr 6, 2025
5f26d16
Merge branch 'main' into feat/adding-type-annotations
yashgoyal0110 Apr 7, 2025
25c451e
Merge branch 'OWASP:main' into feat/adding-type-annotations
yashgoyal0110 Apr 9, 2025
d5c105c
fixed exceptions
yashgoyal0110 Apr 9, 2025
c8b2494
fixed exceptions
yashgoyal0110 Apr 9, 2025
b02455d
Merge branch 'main' into feat/adding-type-annotations
yashgoyal0110 Apr 11, 2025
56c6d37
conflicts resolved
yashgoyal0110 Apr 11, 2025
7ce76d0
Merge branch 'main' into feat/adding-type-annotations
yashgoyal0110 Apr 12, 2025
684b650
Address more warnings
arkid15r Apr 11, 2025
8147382
Update code
arkid15r Apr 12, 2025
05b4748
Update MultiSearch.tsx
arkid15r Apr 12, 2025
e5adaad
Update home page e2e tests
arkid15r Apr 12, 2025
f87a392
Update code
arkid15r Apr 13, 2025
51968b3
Merge branch 'main' into feat/adding-type-annotations
yashgoyal0110 Apr 14, 2025
f3b5079
Merge branch 'main' into feat/adding-type-annotations
yashgoyal0110 Apr 16, 2025
8300c3e
Merge branch 'main' into feat/adding-type-annotations
yashgoyal0110 Apr 17, 2025
1bcd7f1
Merge branch 'main' into pr/yashgoyal0110/1290
arkid15r Apr 21, 2025
1406f32
Merge branch 'main' into feat/adding-type-annotations
yashgoyal0110 Apr 22, 2025
38b6a00
conflicts resolved
yashgoyal0110 Apr 22, 2025
7a75ad8
Merge branch 'main' into feat/adding-type-annotations
yashgoyal0110 Apr 23, 2025
0c41d30
Merge branch 'main' into feat/adding-type-annotations
yashgoyal0110 Apr 25, 2025
401487c
Merge branch 'main' into feat/adding-type-annotations
yashgoyal0110 Apr 27, 2025
91f257f
conflicts resolved
yashgoyal0110 Apr 27, 2025
a18eaa3
Merge branch 'main' into feat/adding-type-annotations
yashgoyal0110 Apr 28, 2025
2eb6f6b
Merge branch 'main' into feat/adding-type-annotations
yashgoyal0110 Apr 29, 2025
bf5f204
Merge branch 'main' into feat/adding-type-annotations
yashgoyal0110 Apr 30, 2025
300dca0
Merge branch 'main' into feat/adding-type-annotations
yashgoyal0110 May 2, 2025
e840d3b
Merge branch 'main' into feat/adding-type-annotations
yashgoyal0110 May 2, 2025
7f4573d
commit
yashgoyal0110 May 2, 2025
7affed8
Merge branch 'main' into feat/adding-type-annotations
yashgoyal0110 May 2, 2025
724cb20
Merge branch 'main' into pr/yashgoyal0110/1290
arkid15r May 3, 2025
b1579ef
Update code
arkid15r May 3, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ repos:
- --sequence=4
exclude: (.github|pnpm-lock.yaml)

- repo: https://github.com/pre-commit/mirrors-mypy
Comment thread
yashgoyal0110 marked this conversation as resolved.
Outdated
rev: v1.15.0
hooks:
- id: mypy
args:
- --exclude
- backend/tests
- --explicit-package-bases
- --config-file
- backend/pyproject.toml

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
Expand Down
3 changes: 2 additions & 1 deletion backend/apps/common/geocoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
import time

from geopy.geocoders import Nominatim
from geopy.location import Location

from apps.common.utils import get_nest_user_agent


def get_location_coordinates(query, delay=2):
def get_location_coordinates(query: str, delay: int = 2) -> Location:
"""Get location geo coordinates.

Args:
Expand Down
24 changes: 13 additions & 11 deletions backend/apps/common/index.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Algolia index common classes and helpers."""

from __future__ import annotations

import logging
from functools import lru_cache
from pathlib import Path
Expand All @@ -13,7 +15,7 @@

from apps.common.constants import NL

logger = logging.getLogger(__name__)
logger: logging.Logger = logging.getLogger(__name__)

EXCLUDED_LOCAL_INDEX_NAMES = (
"projects_contributors_count_asc",
Expand All @@ -36,19 +38,19 @@ class IndexRegistry:

_instance = None

def __init__(self):
def __init__(self) -> None:
"""Initialize index registry."""
self.excluded_local_index_names = set()
self.load_excluded_local_index_names()

@classmethod
def get_instance(cls):
def get_instance(cls) -> IndexRegistry:
"""Get or create a singleton instance of IndexRegistry."""
if cls._instance is None:
cls._instance = IndexRegistry()
return cls._instance

def is_indexable(self, name: str):
def is_indexable(self, name: str) -> bool:
"""Check if an index is enabled for indexing.

Args:
Expand All @@ -60,7 +62,7 @@ def is_indexable(self, name: str):
"""
return name.lower() not in self.excluded_local_index_names if IS_LOCAL_BUILD else True

def load_excluded_local_index_names(self):
def load_excluded_local_index_names(self) -> IndexRegistry:
"""Load excluded local index names from settings.

Returns
Expand All @@ -81,7 +83,7 @@ def load_excluded_local_index_names(self):
return self


def is_indexable(index_name: str):
def is_indexable(index_name: str) -> bool:
"""Determine if an index should be created based on configuration.

Args:
Expand Down Expand Up @@ -120,7 +122,7 @@ class IndexBase(AlgoliaIndex):
"""Base index class."""

@staticmethod
def get_client(ip_address=None):
def get_client(ip_address=None) -> SearchClientSync:
"""Return an instance of the search client.

Args:
Expand All @@ -140,7 +142,7 @@ def get_client(ip_address=None):
return SearchClientSync(config=config)

@staticmethod
def configure_replicas(index_name: str, replicas: dict):
def configure_replicas(index_name: str, replicas: dict) -> None:
"""Configure replicas for an index.

Args:
Expand Down Expand Up @@ -168,7 +170,7 @@ def configure_replicas(index_name: str, replicas: dict):
client.set_settings(replica_name, {"ranking": replica_ranking})

@staticmethod
def _parse_synonyms_file(file_path):
def _parse_synonyms_file(file_path) -> list | None:
"""Parse a synonyms file and return its content.

Args:
Expand Down Expand Up @@ -214,7 +216,7 @@ def _parse_synonyms_file(file_path):
return synonyms

@staticmethod
def reindex_synonyms(app_name, index_name):
def reindex_synonyms(app_name: str, index_name: str) -> int | None:
"""Reindex synonyms for a specific index.

Args:
Expand Down Expand Up @@ -246,7 +248,7 @@ def reindex_synonyms(app_name, index_name):

@staticmethod
@lru_cache(maxsize=1024)
def get_total_count(index_name, search_filters=None):
def get_total_count(index_name: str, search_filters=None) -> int | None:
"""Get the total count of records in an index.

Args:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class Command(BaseCommand):
help = "Update OWASP Nest index replicas."

def handle(self, *_args, **_options):
def handle(self, *_args, **_options) -> None:
"""Update replicas for Algolia indices.

Args:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class Command(BaseCommand):
help = "Update OWASP Nest index synonyms."

def handle(self, *_args, **_options):
def handle(self, *_args, **_options) -> None:
"""Update synonyms for Algolia indices.

Args:
Expand Down
24 changes: 12 additions & 12 deletions backend/apps/common/management/commands/generate_sitemap.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Command(BaseCommand):
],
}

def add_arguments(self, parser):
def add_arguments(self, parser) -> None:
"""Add command-line arguments to the parser.

Args:
Expand All @@ -41,7 +41,7 @@ def add_arguments(self, parser):
help="Directory where sitemap files will be saved",
)

def handle(self, *args, **options):
def handle(self, *args, **options) -> None:
"""Generate sitemaps for the OWASP Nest application.

Args:
Expand Down Expand Up @@ -70,7 +70,7 @@ def handle(self, *args, **options):

self.stdout.write(self.style.SUCCESS(f"Successfully generated sitemaps in {output_dir}"))

def generate_project_sitemap(self, output_dir):
def generate_project_sitemap(self, output_dir: Path) -> None:
"""Generate a sitemap for projects.

Args:
Expand All @@ -91,7 +91,7 @@ def generate_project_sitemap(self, output_dir):
content = self.generate_sitemap_content(routes)
self.save_sitemap(content, output_dir / "sitemap-project.xml")

def generate_chapter_sitemap(self, output_dir):
def generate_chapter_sitemap(self, output_dir: Path) -> None:
"""Generate a sitemap for chapters.

Args:
Expand All @@ -112,7 +112,7 @@ def generate_chapter_sitemap(self, output_dir):
content = self.generate_sitemap_content(routes)
self.save_sitemap(content, output_dir / "sitemap-chapters.xml")

def generate_committee_sitemap(self, output_dir):
def generate_committee_sitemap(self, output_dir: Path) -> None:
"""Generate a sitemap for committees.

Args:
Expand All @@ -136,7 +136,7 @@ def generate_committee_sitemap(self, output_dir):
content = self.generate_sitemap_content(routes)
self.save_sitemap(content, output_dir / "sitemap-committees.xml")

def generate_user_sitemap(self, output_dir):
def generate_user_sitemap(self, output_dir: Path) -> None:
"""Generate a sitemap for users.

Args:
Expand Down Expand Up @@ -185,7 +185,7 @@ def generate_sitemap_content(self, routes):

return self.create_sitemap(urls)

def generate_index_sitemap(self, sitemap_files):
def generate_index_sitemap(self, sitemap_files: list) -> str:
"""Generate the sitemap index file.

Args:
Expand All @@ -204,7 +204,7 @@ def generate_index_sitemap(self, sitemap_files):

return self.create_sitemap_index(sitemaps)

def create_url_entry(self, url_data):
def create_url_entry(self, url_data: dict) -> str:
"""Create a URL entry for the sitemap.

Args:
Expand All @@ -223,7 +223,7 @@ def create_url_entry(self, url_data):
" </url>"
).format(**url_data)

def create_sitemap_index_entry(self, sitemap_data):
def create_sitemap_index_entry(self, sitemap_data: dict) -> str:
"""Create a sitemap index entry.

Args:
Expand All @@ -237,7 +237,7 @@ def create_sitemap_index_entry(self, sitemap_data):
" <sitemap>\n <loc>{loc}</loc>\n <lastmod>{lastmod}</lastmod>\n </sitemap>"
).format(**sitemap_data)

def create_sitemap(self, urls):
def create_sitemap(self, urls: list) -> str:
"""Create the complete sitemap XML.

Args:
Expand All @@ -254,7 +254,7 @@ def create_sitemap(self, urls):
"</urlset>"
)

def create_sitemap_index(self, sitemaps):
def create_sitemap_index(self, sitemaps: list) -> str:
"""Create the complete sitemap index XML.

Args:
Expand All @@ -272,7 +272,7 @@ def create_sitemap_index(self, sitemaps):
)

@staticmethod
def save_sitemap(content, filepath):
def save_sitemap(content: str, filepath: Path) -> None:
"""Save the sitemap content to a file.

Args:
Expand Down
2 changes: 1 addition & 1 deletion backend/apps/common/management/commands/load_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class Command(BaseCommand):
help = "Load OWASP Nest data."

def handle(self, *_args, **_options):
def handle(self, *_args, **_options) -> None:
"""Load data into the OWASP Nest application.

Args:
Expand Down
2 changes: 1 addition & 1 deletion backend/apps/common/management/commands/purge_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class Command(BaseCommand):
help = "Purge OWASP Nest data."

def handle(self, *_args, **options):
def handle(self, *_args, **options) -> None:
"""Purge data from specified OWASP Nest applications.

Args:
Expand Down
2 changes: 1 addition & 1 deletion backend/apps/common/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Meta:
abstract = True

@staticmethod
def bulk_save(model, objects, fields=None):
def bulk_save(model, objects, fields=None) -> None:
"""Bulk save objects.

Args:
Expand Down
17 changes: 11 additions & 6 deletions backend/apps/common/open_ai.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
"""Open AI API module."""

from __future__ import annotations

import logging

import openai
from django.conf import settings

logger = logging.getLogger(__name__)
logger: logging.Logger = logging.getLogger(__name__)


class OpenAi:
"""Open AI communication class."""

def __init__(self, model="gpt-4o-mini", max_tokens=1000, temperature=0.7):
def __init__(
self, model: str = "gpt-4o-mini", max_tokens: int = 1000, temperature: float = 0.7
) -> None:
"""OpenAi constructor.

Args:
Expand All @@ -29,7 +33,7 @@ def __init__(self, model="gpt-4o-mini", max_tokens=1000, temperature=0.7):
self.model = model
self.temperature = temperature

def set_input(self, content):
def set_input(self, content: str) -> OpenAi:
"""Set system role content.

Args:
Expand All @@ -43,7 +47,7 @@ def set_input(self, content):

return self

def set_max_tokens(self, max_tokens):
def set_max_tokens(self, max_tokens: int) -> OpenAi:
"""Set max tokens.

Args:
Expand All @@ -57,7 +61,7 @@ def set_max_tokens(self, max_tokens):

return self

def set_prompt(self, content):
def set_prompt(self, content: str) -> OpenAi:
"""Set system role content.

Args:
Expand All @@ -71,7 +75,7 @@ def set_prompt(self, content):

return self

def complete(self):
def complete(self) -> str | None:
"""Get API response.

Returns
Expand All @@ -98,3 +102,4 @@ def complete(self):
logger.exception("A connection error occurred during OpenAI API request.")
except Exception:
logger.exception("An error occurred during OpenAI API request.")
return None
Loading