Skip to content

Commit

Permalink
Merge branch 'main' of github.com:BesLogic/releaf-canopeum into fix-api
Browse files Browse the repository at this point in the history
  • Loading branch information
Theo Auffeuvre committed Mar 23, 2024
2 parents f031cca + 3f42ea4 commit 00e0059
Show file tree
Hide file tree
Showing 33 changed files with 1,485 additions and 1,008 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
3 changes: 3 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"davidanson.vscode-markdownlint",
"dbaeumer.vscode-eslint",
"dprint.dprint",
"dotenv.dotenv-vscode",
"eamodio.gitlens",
"github.vscode-github-actions",
"meganrogge.template-string-converter",
Expand All @@ -29,6 +30,8 @@
"coenraads.bracket-pair-colorizer",
"coenraads.bracket-pair-colorizer-2",
"shardulm94.trailing-spaces",
// Use the official plugin instead
"mikestead.dotenv",
// Lots of conflicts
"esbenp.prettier-vscode",
"rvest.vs-code-prettier-eslint",
Expand Down
42 changes: 21 additions & 21 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python Debugger: runserver",
"type": "debugpy",
"request": "launch",
"program": "canopeum_backend/manage.py",
"args": ["runserver"],
"console": "integratedTerminal"
},
{
"name": "Python Debugger: Current File",
"type": "debugpy",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
}
]
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python Debugger: runserver",
"type": "debugpy",
"request": "launch",
"program": "canopeum_backend/manage.py",
"args": ["runserver"],
"console": "integratedTerminal"
},
{
"name": "Python Debugger: Current File",
"type": "debugpy",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
}
]
}
48 changes: 39 additions & 9 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
72
]
},
"[markdown]": {
"files.trimTrailingWhitespace": false
},
"files.trimTrailingWhitespace": true,
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true,
Expand Down Expand Up @@ -52,7 +49,18 @@
* CSS-specific settings
*/
// TODO: Configure stylelint or dprint-prettier so I can recommend it
"[css][scss][postcss][less]": {
// NOTE: due to a bug in VSCode, we have to specify these individually to ensure it overrides user settings
// Please upvote: https://github.com/microsoft/vscode/issues/168411
"[css]": {
"editor.defaultFormatter": "vscode.css-language-features"
},
"[scss]": {
"editor.defaultFormatter": "vscode.css-language-features"
},
"[postcss]": {
"editor.defaultFormatter": "vscode.css-language-features"
},
"[less]": {
"editor.defaultFormatter": "vscode.css-language-features"
},
"less.format.spaceAroundSelectorSeparator": true,
Expand All @@ -62,9 +70,34 @@
* JavasScript-specific settings
*/
// Set the default formatter to help avoid Prettier
"[json][jsonc][javascript][javascriptreact][typescript][typescriptreact][markdown][dockerfile]": {
// NOTE: due to a bug in VSCode, we have to specify these individually to ensure it overrides user settings
// Please upvote: https://github.com/microsoft/vscode/issues/168411
"[json]": {
"editor.defaultFormatter": "dprint.dprint"
},
"[jsonc]": {
"editor.defaultFormatter": "dprint.dprint"
},
"[javascript]": {
"editor.defaultFormatter": "dprint.dprint"
},
"[javascriptreact]": {
"editor.defaultFormatter": "dprint.dprint"
},
"[typescript]": {
"editor.defaultFormatter": "dprint.dprint"
},
"[typescriptreact]": {
"editor.defaultFormatter": "dprint.dprint"
},
"[markdown]": {
"files.trimTrailingWhitespace": false,
"editor.defaultFormatter": "dprint.dprint"
},
"[dockerfile]": {
"editor.defaultFormatter": "dprint.dprint"
},
"dprint.path": "canopeum_frontend/node_modules/dprint/dprint.exe",
"typescript.tsdk": "canopeum_frontend/node_modules/typescript/lib",
"typescript.enablePromptUseWorkspaceTsdk": true,
"js/ts.implicitProjectConfig.checkJs": true,
Expand Down Expand Up @@ -156,8 +189,5 @@
"evenBetterToml.formatter.reorderArrays": true,
"evenBetterToml.formatter.trailingNewline": true,
// We like keeping TOML keys in a certain non-alphabetical order that feels more natural
"evenBetterToml.formatter.reorderKeys": false,
"[typescriptreact]": {
"editor.defaultFormatter": "vscode.typescript-language-features"
}
"evenBetterToml.formatter.reorderKeys": false
}
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 @@ -189,10 +188,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
siteId = request.GET.get("siteId", "")
if siteId != "":
Expand Down
9 changes: 1 addition & 8 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 @@ -95,12 +94,6 @@ max-args = 7
# At least same as max-complexity
max-branches = 15

# https://github.com/microsoft/pyright/blob/main/docs/configuration.md#sample-pyprojecttoml-file
[tool.pyright]
pythonVersion = "3.12"
exclude = [".venv/"]
typeCheckingMode = "standard"

# https://mypy.readthedocs.io/en/stable/config_file.html
[tool.mypy]
show_column_numbers = true
Expand Down
2 changes: 1 addition & 1 deletion canopeum_frontend/.eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module.exports = {
'beslogic/dprint',
],
ignorePatterns: [
'.eslintrc.cjs',
// Auto-generated
'src/services/api.ts',
],
Expand All @@ -23,6 +24,5 @@ module.exports = {
'no-autofix/no-relative-import-paths/no-relative-import-paths': 'off',
// Using Bootraps directly without a React wrapper will cause us to have to add classes to React Components
'react/forbid-component-props': 'off',
"react/display-name": [false, { "ignoreTranspilerName": false, "checkContextObjects": false }]
},
}
4 changes: 4 additions & 0 deletions canopeum_frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
rel="stylesheet"
href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,[email protected],100..700,0..1,-50..200"
/>
<link
href='https://unpkg.com/[email protected]/dist/maplibre-gl.css'
rel='stylesheet'
/>
</head>

<body>
Expand Down
Loading

0 comments on commit 00e0059

Please sign in to comment.