Skip to content

Commit

Permalink
Minor enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
TreyWW committed Apr 22, 2024
1 parent 1c9a533 commit d70e5c1
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 7 deletions.
4 changes: 4 additions & 0 deletions backend/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ class EmailSendStatusAdmin(admin.ModelAdmin):
readonly_fields = ["aws_message_id"]


class InvoiceURLAdmin(admin.ModelAdmin):
readonly_fields = ["expires"]


admin.site.register(QuotaLimit, QuotaLimitAdmin)
admin.site.register(QuotaUsage, QuotaUsageAdmin)
admin.site.register(QuotaOverrides, QuotaOverridesAdmin)
Expand Down
51 changes: 51 additions & 0 deletions backend/utils/dataclasses.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from typing import TypeVar


T = TypeVar("T")


def extract_to_dataclass(request, class_type: [T], request_types: list[str], *args, **kwargs) -> [T]:
"""
Turn kwargs from Key:Value and get request.POST.get(value) and set class.key = request.POST.get(value)
Usage:
from pydantic.dataclasses import dataclass
from typing import Optional
@dataclass
class MyView:
name: str
age: int
different: bool
non_required: Optional[str]
def myview(request):
try:
data = extract_to_dataclass(request, MyView, ["post"], "name", "age", diff_bool="different")
except pydantic.ValidationError:
pass
"""
data = {}
if "get" in request_types:
if args:
data |= {key: request.GET.get(key) for key in args}

if kwargs:
data |= {key: request.GET.get(value) for key, value in kwargs.items()}

if "post" in request_types:
if args:
data |= {key: request.POST.get(key) for key in args}

if kwargs:
data |= {key: request.POST.get(value) for key, value in kwargs.items()}

if "headers" in request_types:
if args:
data |= {key: request.headers.get(key) for key in args}

if kwargs:
data |= {key: request.headers.get(value) for key, value in kwargs.items()}
return class_type(**data)
21 changes: 21 additions & 0 deletions docs/debugging/python/poetry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Already installed

The error where `poetry install` says "Skipped for the following reason: Already installed" but `pip freeze` shows that these
clearly aren't installed, you may need to configure your poetry environment to use the local ./venv/ instead of a global one.

First, make sure you aren't in a venv (`deactivate`). If there isn't a /venv/ folder inside of the project, you'll need to
create one with `python -m venv ./venv/`. Now activate it. `./venv/Scripts/activate`.

After you have a venv and it's activated you can run these poetry config commands:

```shell
pip install poetry

poetry config virtualenvs.in-project true

poetry config virtualenvs.path ./venv/

poetry install
```

And this time they should all be correctly installed!
13 changes: 6 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[tool.poetry]
name = "MyFinances"
package-mode = false
version = "0.3.0"
description = "github.com/TreyWW/MyFinances"
authors = ["TreyWW"]
Expand All @@ -20,12 +19,6 @@ django-mathfilters = "^1.0.0"
sample-helper-aws-appconfig = "^2.1.0"
redis = { extras = ["hiredis"], version = "^5.0.1" }

djangorestframework = "^3.14.0"
django-tz-detect = "^0.5.0"
typos = "^1.20.3"
pre-commit = "^3.7.0"
pulumi-aws = "^6.29.0"

[tool.poetry.group.mypy.dependencies]
mypy = "1.7.1"
djangorestframework-stubs = { extras = ["compatible-mypy"], version = "^3.14.5" }
Expand All @@ -37,6 +30,12 @@ boto3-stubs = { extras = [
"stepfunctions",
], version = "^1.34.76" }

djangorestframework = "^3.14.0"
django-tz-detect = "^0.5.0"
typos = "^1.20.3"
pre-commit = "^3.7.0"
pulumi-aws = "^6.29.0"

[tool.poetry.group.django.dependencies]
Django = "^5.0.2"
gunicorn = "22.0.0"
Expand Down

0 comments on commit d70e5c1

Please sign in to comment.