Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ compile-requirements: ## Re-compile *.in requirements to *.txt
sed '/^[dD]jango==/d' requirements/test.txt > requirements/test.tmp
mv requirements/test.tmp requirements/test.txt

format:
black ${SRC_FILES}

upgrade: ## update the requirements/*.txt files with the latest packages satisfying requirements/*.in
$(MAKE) compile-requirements COMPILE_OPTS="--upgrade"

Expand All @@ -69,7 +72,7 @@ test-all: clean test test-quality test-pii selfcheck ## run all tests
test: ## run unit tests
pytest

test-quality: test-lint test-codestyle test-isort test-mypy ## run static coverage tests
test-quality: test-lint test-codestyle test-mypy test-format ## run static coverage tests

test-lint: ## run pylint
pylint ${SRC_FILES}
Expand All @@ -84,6 +87,9 @@ test-isort: ## run isort checks
test-mypy: ## run type tests
mypy ${SRC_FILES_PROD}

test-format: ## Run code formatting tests
Comment thread
Faraz32123 marked this conversation as resolved.
black --check ${SRC_FILES}

test-pii: export DJANGO_SETTINGS_MODULE=test_settings
test-pii: ## # check for PII annotations on all Django models
code_annotations django_find_annotations --config_file .pii_annotations.yml --lint --report --coverage
Expand Down
2 changes: 1 addition & 1 deletion forum/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
Openedx forum app.
"""

__version__ = '0.1.0'
__version__ = "0.1.0"
8 changes: 6 additions & 2 deletions forum/models/contents.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ def __init__(
"""
super().__init__(collection_name, client)

def get(self, _id: str) -> Optional[Dict[str, Any]]: # pylint: disable=arguments-differ
def get(
self, _id: str
) -> Optional[Dict[str, Any]]: # pylint: disable=arguments-differ
"""
Retrieves a contents document from the database based on the provided _id.
Args:
Expand Down Expand Up @@ -85,7 +87,9 @@ def insert( # pylint: disable=arguments-differ
result = self._collection.insert_one(content_data)
return str(result.inserted_id)

def update(self, _id: str, **kwargs: Any) -> int: # pylint: disable=arguments-differ
def update(
self, _id: str, **kwargs: Any
) -> int: # pylint: disable=arguments-differ
"""
Updates a contents document in the database based on the provided _id.

Expand Down
4 changes: 3 additions & 1 deletion forum/models/model_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ def flag_as_abuse(
return Contents().get(entity["_id"])


def un_flag_as_abuse(user: Dict[str, Any], entity: Dict[str, Any]) -> Union[Dict[str, Any], None]:
def un_flag_as_abuse(
user: Dict[str, Any], entity: Dict[str, Any]
) -> Union[Dict[str, Any], None]:
"""
Unflag an entity as abuse.

Expand Down
1 change: 1 addition & 0 deletions forum/serializers/comment.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Serializer for the comment data.
"""

from typing import Any, Dict

from rest_framework import serializers
Expand Down
1 change: 1 addition & 0 deletions forum/serializers/thread.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Serializer for the thread data.
"""

from typing import Any, Dict

from rest_framework import serializers
Expand Down
13 changes: 8 additions & 5 deletions forum/views/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
from rest_framework.views import APIView

from forum.models import Contents, Users
from forum.models.model_utils import flag_as_abuse, un_flag_all_as_abuse, un_flag_as_abuse
from forum.models.model_utils import (
flag_as_abuse,
un_flag_all_as_abuse,
un_flag_as_abuse,
)
from forum.serializers.contents import ContentSerializer


Expand Down Expand Up @@ -38,7 +42,7 @@ def put(self, request: Request, comment_id: str, action: str) -> Response:
if not (user and content):
return Response(
{"error": "User / Comment doesn't exist"},
status=status.HTTP_400_BAD_REQUEST
status=status.HTTP_400_BAD_REQUEST,
)
if action == "flag":
comment = flag_as_abuse(user, content)
Expand All @@ -49,8 +53,7 @@ def put(self, request: Request, comment_id: str, action: str) -> Response:
comment = un_flag_as_abuse(user, content)
else:
return Response(
{"error": "Invalid action"},
status=status.HTTP_400_BAD_REQUEST
{"error": "Invalid action"}, status=status.HTTP_400_BAD_REQUEST
)
serializer = ContentSerializer(comment)
return Response(serializer.data, status=status.HTTP_200_OK)
Expand Down Expand Up @@ -83,7 +86,7 @@ def put(self, request: Request, thread_id: str, action: str) -> Response:
if not (user and content):
return Response(
{"error": "User / Comment doesn't exist"},
status=status.HTTP_400_BAD_REQUEST
status=status.HTTP_400_BAD_REQUEST,
)
if action == "flag":
thread = flag_as_abuse(user, content)
Expand Down
4 changes: 2 additions & 2 deletions manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

PWD = os.path.abspath(os.path.dirname(__file__))

if __name__ == '__main__':
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'test_settings')
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "test_settings")
sys.path.append(PWD)
try:
from django.core.management import execute_from_command_line
Expand Down
4 changes: 1 addition & 3 deletions requirements/base.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# This file is autogenerated by pip-compile with Python 3.10
# This file is autogenerated by pip-compile with Python 3.11
# by the following command:
#
# make upgrade
Expand Down Expand Up @@ -29,7 +29,5 @@ requests==2.32.3
# via -r requirements/base.in
sqlparse==0.5.1
# via django
typing-extensions==4.12.2
# via asgiref
urllib3==2.2.2
# via requests
2 changes: 2 additions & 0 deletions requirements/ci.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
-c constraints.txt

-r quality.txt # Core and quality check dependencies

black # code formatter
30 changes: 11 additions & 19 deletions requirements/ci.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# This file is autogenerated by pip-compile with Python 3.10
# This file is autogenerated by pip-compile with Python 3.11
# by the following command:
#
# make upgrade
Expand All @@ -14,6 +14,8 @@ astroid==3.2.4
# -r requirements/quality.txt
# pylint
# pylint-celery
black==24.8.0
# via -r requirements/ci.in
cachetools==5.4.0
# via
# -r requirements/quality.txt
Expand All @@ -33,6 +35,7 @@ charset-normalizer==3.3.2
click==8.1.7
# via
# -r requirements/quality.txt
# black
# click-log
# code-annotations
# edx-lint
Expand Down Expand Up @@ -85,10 +88,6 @@ dnspython==2.6.1
# pymongo
edx-lint==5.3.7
# via -r requirements/quality.txt
exceptiongroup==1.2.2
# via
# -r requirements/quality.txt
# pytest
filelock==3.15.4
# via
# -r requirements/quality.txt
Expand Down Expand Up @@ -125,23 +124,28 @@ mypy==1.11.1
mypy-extensions==1.0.0
# via
# -r requirements/quality.txt
# black
# mypy
openedx-atlas==0.6.1
# via -r requirements/quality.txt
packaging==24.1
# via
# -r requirements/quality.txt
# black
# mongomock
# pyproject-api
# pytest
# tox
pathspec==0.12.1
# via black
pbr==6.0.0
# via
# -r requirements/quality.txt
# stevedore
platformdirs==4.2.2
# via
# -r requirements/quality.txt
# black
# pylint
# tox
# virtualenv
Expand Down Expand Up @@ -225,21 +229,11 @@ text-unidecode==1.3
# via
# -r requirements/quality.txt
# python-slugify
tomli==2.0.1
# via
# -r requirements/quality.txt
# coverage
# django-stubs
# mypy
# pylint
# pyproject-api
# pytest
# tox
tomlkit==0.13.0
tomlkit==0.13.2
# via
# -r requirements/quality.txt
# pylint
tox==4.17.1
tox==4.18.0
# via -r requirements/quality.txt
types-pyyaml==6.0.12.20240808
# via
Expand All @@ -253,8 +247,6 @@ types-requests==2.32.0.20240712
typing-extensions==4.12.2
# via
# -r requirements/quality.txt
# asgiref
# astroid
# django-stubs
# django-stubs-ext
# djangorestframework-stubs
Expand Down
37 changes: 13 additions & 24 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# This file is autogenerated by pip-compile with Python 3.10
# This file is autogenerated by pip-compile with Python 3.11
# by the following command:
#
# make upgrade
Expand All @@ -16,6 +16,8 @@ astroid==3.2.4
# -r requirements/quality.txt
# pylint
# pylint-celery
black==24.8.0
# via -r requirements/ci.txt
build==1.2.1
# via
# -r requirements/pip-tools.txt
Expand Down Expand Up @@ -46,6 +48,7 @@ click==8.1.7
# -r requirements/ci.txt
# -r requirements/pip-tools.txt
# -r requirements/quality.txt
# black
# click-log
# code-annotations
# edx-lint
Expand Down Expand Up @@ -120,11 +123,6 @@ edx-lint==5.3.7
# via
# -r requirements/ci.txt
# -r requirements/quality.txt
exceptiongroup==1.2.2
# via
# -r requirements/ci.txt
# -r requirements/quality.txt
# pytest
filelock==3.15.4
# via
# -r requirements/ci.txt
Expand Down Expand Up @@ -176,6 +174,7 @@ mypy-extensions==1.0.0
# via
# -r requirements/ci.txt
# -r requirements/quality.txt
# black
# mypy
openedx-atlas==0.6.1
# via
Expand All @@ -186,13 +185,18 @@ packaging==24.1
# -r requirements/ci.txt
# -r requirements/pip-tools.txt
# -r requirements/quality.txt
# black
# build
# mongomock
# pyproject-api
# pytest
# tox
path==16.16.0
# via edx-i18n-tools
pathspec==0.12.1
# via
# -r requirements/ci.txt
# black
pbr==6.0.0
# via
# -r requirements/ci.txt
Expand All @@ -204,6 +208,7 @@ platformdirs==4.2.2
# via
# -r requirements/ci.txt
# -r requirements/quality.txt
# black
# pylint
# tox
# virtualenv
Expand Down Expand Up @@ -324,26 +329,12 @@ text-unidecode==1.3
# -r requirements/ci.txt
# -r requirements/quality.txt
# python-slugify
tomli==2.0.1
# via
# -r requirements/ci.txt
# -r requirements/pip-tools.txt
# -r requirements/quality.txt
# build
# coverage
# django-stubs
# mypy
# pip-tools
# pylint
# pyproject-api
# pytest
# tox
tomlkit==0.13.0
tomlkit==0.13.2
# via
# -r requirements/ci.txt
# -r requirements/quality.txt
# pylint
tox==4.17.1
tox==4.18.0
# via
# -r requirements/ci.txt
# -r requirements/quality.txt
Expand All @@ -362,8 +353,6 @@ typing-extensions==4.12.2
# via
# -r requirements/ci.txt
# -r requirements/quality.txt
# asgiref
# astroid
# django-stubs
# django-stubs-ext
# djangorestframework-stubs
Expand Down
Loading