Skip to content

Commit

Permalink
Fix python issues + Add extensions install in VSCode (#58)
Browse files Browse the repository at this point in the history
* Fix python issues + Add extensions install in VSCode

* set working-directory for pyright-action
  • Loading branch information
Samuel-Therrien-Beslogic authored Mar 23, 2024
1 parent bd70c6b commit 3097557
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 20 deletions.
1 change: 1 addition & 0 deletions .github/workflows/canopeum_backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,4 @@ jobs:
- uses: jakebailey/pyright-action@v2
with:
python-version: "3.12"
working-directory: canopeum_backend
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,15 @@ For backend
cd releaf-canopeum
```

3. Set up a Python 3.12 virtual environment
3. Install recommended Editor Extensions (for VSCode):\
When you first open the project in VSCode, you'll get a notification like this.\
![Recommended Popup](/docs/Recommended_Popup.png)

If you've already dismissed this notification, you can search for `@recommended` in your Extensions tab.
Install everything under "**WORKSPACE RECOMMENDATIONS**", you can ignore "other recommendations":\
![Recommended Extensions](/docs/Recommended_Extensions.png)

4. Set up a Python 3.12 virtual environment

```shell
cd canopeum_backend
Expand Down Expand Up @@ -64,7 +72,7 @@ For backend
`CTRL+Shift+P` (Open Command Palette) > `Python: Select Interpreter`
![VSCode_select_venv](/docs/VSCode_select_venv.png)

4. Set up Django backend and Database: (Skip this section for Frontend only)
5. Set up Django backend and Database: (Skip this section for Frontend only)

```shell
docker compose up
Expand All @@ -74,7 +82,7 @@ For backend
python manage.py runserver
```

5. Set up React frontend:
6. Set up React frontend:

```shell
cd canopeum_frontend
Expand Down
14 changes: 7 additions & 7 deletions canopeum_backend/canopeum_backend/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class SiteTypeSerializer(serializers.ModelSerializer):

class Meta:
model = Sitetype
fields = ["id", "en", "fr"]
fields = ("id", "en", "fr")

def get_en(self, obj):
return InternationalizationSerializer(obj.name).data.get("en", None)
Expand All @@ -74,7 +74,7 @@ class TreeTypeSerializer(serializers.ModelSerializer):

class Meta:
model = Treetype
fields = ["en", "fr"]
fields = ("en", "fr")

def get_en(self, obj):
return InternationalizationSerializer(obj.name).data.get("en", None)
Expand Down Expand Up @@ -149,7 +149,7 @@ class BatchfertilizerSerializer(serializers.ModelSerializer):

class Meta:
model = Batchfertilizer
fields = ["id", "en", "fr"]
fields = ("id", "en", "fr")

def get_en(self, obj):
return InternationalizationSerializer(obj.fertilizer_type).data.get("en", None)
Expand All @@ -164,7 +164,7 @@ class BatchMulchLayerSerializer(serializers.ModelSerializer):

class Meta:
model = Mulchlayertype
fields = ["id", "en", "fr"]
fields = ("id", "en", "fr")

def get_en(self, obj):
return InternationalizationSerializer(obj.mulch_layer_type).data.get("en", None)
Expand All @@ -179,7 +179,7 @@ class BatchSupportedSpeciesSerializer(serializers.ModelSerializer):

class Meta:
model = BatchSupportedSpecies
fields = ["en", "fr"]
fields = ("en", "fr")

def get_en(self, obj):
return InternationalizationSerializer(obj.tree_type).data.get("en", None)
Expand All @@ -194,7 +194,7 @@ class BatchSeedSerializer(serializers.ModelSerializer):

class Meta:
model = BatchSeed
fields = ["quantity", "en", "fr"]
fields = ("quantity", "en", "fr")

def get_en(self, obj):
return InternationalizationSerializer(obj.tree_type).data.get("en", None)
Expand All @@ -209,7 +209,7 @@ class BatchSpeciesSerializer(serializers.ModelSerializer):

class Meta:
model = BatchSpecies
fields = ["quantity", "en", "fr"]
fields = ("quantity", "en", "fr")

def get_en(self, obj):
return InternationalizationSerializer(obj.tree_type).data.get("en", None)
Expand Down
12 changes: 4 additions & 8 deletions canopeum_backend/canopeum_backend/views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from typing import ClassVar

from django.contrib.auth import authenticate
from django.contrib.auth.models import User
from drf_spectacular.utils import extend_schema
from rest_framework import status
Expand Down Expand Up @@ -28,7 +27,7 @@


class LoginAPIView(APIView):
permission_classes: ClassVar[list[type[AllowAny]]] = [AllowAny]
permission_classes = (AllowAny,)

@extend_schema(request=AuthUserSerializer, responses=UserSerializer, operation_id="authentication_login")
def post(self, request):
Expand All @@ -43,7 +42,7 @@ def post(self, request):


class RegisterAPIView(APIView):
permission_classes: ClassVar[list[type[AllowAny]]] = [AllowAny]
permission_classes = (AllowAny,)

@extend_schema(request=UserSerializer, responses=AuthUserSerializer, operation_id="authentication_register")
def post(self, request):
Expand Down Expand Up @@ -183,10 +182,7 @@ def get(self, request):
class PostListAPIView(APIView):
@extend_schema(responses=PostSerializer(many=True), operation_id="post_all")
def get(self, request):
try:
comment_count = Comment.objects.get(post=request.data.get("id")).count()
except Comment.DoesNotExist:
comment_count = 0
comment_count = Comment.objects.filter(post=request.data.get("id")).count()
has_liked = 0
posts = Post.objects.all()
serializer = PostSerializer(posts, many=True, context={"comment_count": comment_count, "has_liked": has_liked})
Expand Down
5 changes: 3 additions & 2 deletions canopeum_backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,9 @@ ignore = [
### https://github.com/astral-sh/ruff/issues/1256 & https://github.com/astral-sh/ruff/issues/1774):
"DJ001", # Avoid using `null=True` on string-based fields
"DJ008", # Model does not define `__str__` method: https://docs.astral.sh/ruff/rules/django-model-without-dunder-str/
"N803", # Different naming convention between js/json and python. A better/configured middleware could take care of that
]

[tool.ruff.format]

# https://docs.astral.sh/ruff/settings/#flake8-implicit-str-concat
[tool.ruff.lint.flake8-implicit-str-concat]
allow-multiline = false
Expand All @@ -100,6 +99,8 @@ max-branches = 15
pythonVersion = "3.12"
exclude = [".venv/"]
typeCheckingMode = "standard"
# django-specific mypy plugin does a better job getting serializers data type of dict vs list
reportAttributeAccessIssue = "none"

# https://mypy.readthedocs.io/en/stable/config_file.html
[tool.mypy]
Expand Down
Binary file added docs/Recommended_Extensions.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/Recommended_Popup.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 3097557

Please sign in to comment.