Skip to content

Commit

Permalink
Merge branch 'TreyWW:main' into fix/email-as-auth-bug
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Makela authored Jun 10, 2024
2 parents d88d168 + cbbf492 commit aab5e3f
Show file tree
Hide file tree
Showing 45 changed files with 911 additions and 136 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run_black_linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v4.1.6
- uses: psf/black@stable
18 changes: 6 additions & 12 deletions .github/workflows/run_djlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,18 @@ on:

jobs:
lint:
strategy:
fail-fast: true
matrix:
os: [ "ubuntu-latest" ]
python-version: [ "3.10", "3.11", "3.12" ]
django-version: [ "4", "5" ]
runs-on: ${{ matrix.os }}
runs-on: ubuntu-latest
steps:
#----------------------------------------------
# check-out repo and set-up python
#----------------------------------------------
- name: Check out repository
uses: actions/checkout@v4
- name: Set up python ${{ matrix.python-version }}
uses: actions/checkout@v4.1.6
- name: Set up python
id: setup-python
uses: actions/setup-python@v5
uses: actions/setup-python@v5.1.0
with:
python-version: ${{ matrix.python-version }}
python-version: "3.12"
#----------------------------------------------
# ----- install & configure poetry -----
#----------------------------------------------
Expand All @@ -42,7 +36,7 @@ jobs:
#----------------------------------------------
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v3
uses: actions/cache@v4.0.2
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
Expand Down
47 changes: 47 additions & 0 deletions .github/workflows/run_mypy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Mypy
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
mypy:
name: mypy
runs-on: ubuntu-latest
env:
SECRET_KEY: "some!random!secret!key!use!online!generator!to!get"
URL: "127.0.0.1"
PROXY_IP: "localhost"
BRANCH: "debug"
DEBUG: "true"
DATABASE_TYPE: "sqlite3"
SITE_URL: "http://myfinances.example.com"
SITE_NAME: "myfinances"
steps:
- name: Clone repo
uses: actions/[email protected]
- name: Set up python
uses: actions/[email protected]
with:
python-version: "3.12"
- name: Install and configure Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/[email protected]
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root
- name: Run mypy checks
run: |
source .venv/bin/activate
mypy .
4 changes: 1 addition & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@ jobs:
django-version: ["4", "5"]
steps:
- name: Clone repo
uses: actions/[email protected].4
uses: actions/[email protected].6
- name: Set up python
uses: actions/[email protected]
with:
python-version: ${{ matrix.python-version }}
- name: Install and configure Poetry
uses: snok/install-poetry@v1
with:
version: 1.8.0
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
Expand Down Expand Up @@ -79,4 +78,3 @@ jobs:
source .venv/bin/activate
python3 manage.py collectstatic --no-input
python3 manage.py test --parallel
56 changes: 43 additions & 13 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,65 @@ repos:
entry: black --check --diff
hooks:
- id: black
name: Black Formatter
files: .
language: python
types: [ python ]
- repo: local
hooks:
- id: pre-commit-django-migrations
name: Check django migrations
entry: python manage.py makemigrations --dry-run --check --no-input
language: system
types: [ python ]
files: ./backend/models.py
pass_filenames: false
- repo: local
hooks:
- id: pre-commit-djlint
name: Djlint (html files)
entry: djlint . --profile django --check
entry: djlint ./frontend/templates/ --profile django --reformat
language: system
types: [ python ]
files: ./frontend/templates/
types: [ html ]
pass_filenames: false
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: trailing-whitespace
types: [ text ]
language: python
- id: end-of-file-fixer
- id: debug-statements
- id: name-tests-test
- repo: https://github.com/asottile/setup-cfg-fmt
rev: v2.5.0
hooks:
- id: setup-cfg-fmt
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.2
hooks:
- id: pyupgrade
args: [ --py39-plus ]
types: [ python ]
language: python
- id: detect-aws-credentials
- id: detect-private-key
exclude: "docs/getting-started/settings/AWS/static.md"
- id: check-added-large-files
- id: check-ast
types: [ python3 ]
language: python
files: ".*\\.py$" # may not be needed due to type of python3
- id: check-json
types: [ json ]
files: ".*\\.json$"
exclude: "backend/management/commands/contributors.json"
# - id: debug-statements # (unknown use)
# - id: name-tests-test # (blocking)
# - repo: https://github.com/asottile/setup-cfg-fmt
# rev: v2.5.0
# hooks:
# - id: setup-cfg-fmt
# - repo: https://github.com/asottile/pyupgrade
# rev: v3.15.2
# hooks:
# - id: pyupgrade # (blocking)
# args: [ --py39-plus ]
# - repo: https://github.com/pre-commit/mirrors-mypy
# rev: v1.7.0
# hooks:
# - id: mypy # (blocking)
# args:
# - --explicit-package-bases
# - --no-incremental
# additional_dependencies: ['mypy >=1.7.0, <1.8.0']
38 changes: 34 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ To contribute code:
3. Create a new branch for your changes.
4. Make your changes, following the coding style guidelines.
5. Test your changes thoroughly
- `python manage.py test`
- run the app (`python manage.py runserver`)
- `python3 manage.py test`
- run the app (`python3 manage.py runserver`)
- view any changed pages in browser (`http://127.0.0.1:8000`) and make sure the changes work as expected
6. Submit a pull request to the main repository's `main` branch.

Expand All @@ -112,6 +112,12 @@ pip install black
black ./
```

For static type checking we are using [mypy](https://mypy-lang.org/). Code tests will be run before PRs can be merged, they will fail if types in you code will be incorrect. You can run check with this command:

```
mypy .
```

### Version Control

We use Git. Make sure your commits are clear, concise, and well-documented. Follow conventional commit message style.
Expand Down Expand Up @@ -448,6 +454,30 @@ Thank you for your contributions!
<br />
<a href="https://github.com/TreyWW/MyFinances/pulls?q=is%3Apr+author%3Aglizondo" title="Bug Fixes">🐞</a>
</td>
</td><td>
<td align="center">
<a href="https://github.com/marvinl803" title="marvinl803">
<img title="Full Stack" src="https://github.com/marvinl803.png" width="100px;" alt="" />
<br />
<sub>
<b>Marvin Lopez</b>
</sub>
</a>
<br />
<a href="https://github.com/TreyWW/MyFinances/pulls?q=is%3Apr+author%3Amarvinl803" title="Backend">🖥</a><a href="https://github.com/TreyWW/MyFinances/pulls?q=is%3Apr+author%3Amarvinl803" title="Frontend">🎨</a>
</td>
</td><td>
<td align="center">
<a href="https://github.com/artkolpakov" title="artkolpakov">
<img title="Bug Fixes" src="https://github.com/artkolpakov.png" width="100px;" alt="" />
<br />
<sub>
<b>Artem Kolpakov</b>
</sub>
</a>
<br />
<a href="https://github.com/TreyWW/MyFinances/pulls?q=is%3Apr+author%3Aartkolpakov" title="Bug Fixes">🐞</a>
</td>
</td></tr></table>
<!-- CONTRIBUTORS TABLE END -->

Expand All @@ -456,8 +486,8 @@ manually edit with the details below.

### How to edit the contributors table?

- Updated any info using `python manage.py contriubtors`
- Run `python manage.py contributors sync`
- Updated any info using `python3 manage.py contriubtors`
- Run `python3 manage.py contributors sync`
- Make a PR to request these changes in
- Done :)

Expand Down
5 changes: 3 additions & 2 deletions assets/scripts/htmx.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ function htmx_resend(event) {
}

// https://htmx.org/docs/#config
htmx.config.globalViewTransitions = true
htmx.config.useTemplateFragments = true // for swapping of table items
htmx.config.globalViewTransitions = true;
htmx.config.useTemplateFragments = true; // for swapping of table items
htmx.config.scrollIntoViewOnBoost = false; // to stop hx-boost scrolling down automatically


window.addEventListener("DOMContentLoaded", (event) => {
Expand Down
20 changes: 15 additions & 5 deletions backend/api/base/notifications.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django.contrib import messages
from django.http import HttpResponse
from django.shortcuts import render

Expand All @@ -7,25 +8,34 @@

def get_notification_html(request: HtmxHttpRequest):
user_notifications = Notification.objects.filter(user=request.user).order_by("-date")
above_5 = False
count = user_notifications.count()

if user_notifications.count() > 5:
if count > 5:
user_notifications = user_notifications[:5]
above_5 = True

return render(
request,
"base/topbar/_notification_dropdown_items.html",
{"notifications": user_notifications, "notifications_above_max": above_5},
{"notifications": user_notifications, "notif_count": count},
)


def get_notification_count_html(request: HtmxHttpRequest):
user_notifications = Notification.objects.filter(user=request.user).count()
return HttpResponse(f"{user_notifications}")


def delete_notification(request: HtmxHttpRequest, id: int):
notif = Notification.objects.filter(id=id, user=request.user).first()

if notif is None or notif.user != request.user:
if request.htmx:
messages.error(request, "Notification not found")
return render(request, "base/toasts.html")
return HttpResponse(status=404, content="Notification not found")

notif.delete()

return HttpResponse(status=200)
response = HttpResponse(status=200)
response["HX-Trigger"] = "refresh_notification_count"
return response
1 change: 1 addition & 0 deletions backend/api/base/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
notifications.get_notification_html,
name="notifications get",
),
path("notifications/get_count", notifications.get_notification_count_html, name="notifications get count"),
path(
"notifications/delete/<int:id>",
notifications.delete_notification,
Expand Down
6 changes: 3 additions & 3 deletions backend/api/invoices/create/services/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
@require_http_methods(["POST"])
def add_service(request: HtmxHttpRequest):
context: dict = {}
existing_service = request.POST.get("existing_service", "")
existing_service = request.POST.get("existing_service", 0)

try:
existing_service_obj = InvoiceProduct.objects.get(user=request.user, id=existing_service)
Expand All @@ -23,10 +23,10 @@ def add_service(request: HtmxHttpRequest):
list_of_current_rows = [row for row in zip(list_hours, list_service_name, list_service_description, list_price_per_hour)]

if not existing_service:
hours = int(request.POST.get("post_hours", ""))
hours = int(request.POST.get("post_hours", "0"))
service_name = request.POST.get("post_service_name")
service_description = request.POST.get("post_service_description")
price_per_hour = int(request.POST.get("post_rate", ""))
price_per_hour = int(request.POST.get("post_rate", "0"))

if not hours:
return JsonResponse(
Expand Down
6 changes: 4 additions & 2 deletions backend/api/invoices/delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ def delete_invoice(request: HtmxHttpRequest):
try:
invoice = Invoice.objects.get(id=delete_items.get("invoice", ""))
except Invoice.DoesNotExist:
return JsonResponse({"message": "Invoice not found"}, status=404)
messages.error(request, "Invoice Not Found")
return render(request, "base/toasts.html")

if not invoice.has_access(request.user):
return JsonResponse({"message": "You do not have permission to delete this invoice"}, status=404)
messages.error(request, "You do not have permission to delete this invoice")
return render(request, "base/toasts.html")

QuotaLimit.delete_quota_usage("invoices-count", request.user, invoice.id, invoice.date_created)

Expand Down
8 changes: 7 additions & 1 deletion backend/api/receipts/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ def fetch_all_receipts(request: HtmxHttpRequest):
results = results.filter(user=request.user)

if search_text:
results = results.filter(Q(name__icontains=search_text) | Q(date__icontains=search_text)).order_by("-date")
results = results.filter(
Q(name__icontains=search_text)
| Q(date__icontains=search_text)
| Q(merchant_store__icontains=search_text)
| Q(purchase_category__icontains=search_text)
| Q(id__icontains=search_text)
).order_by("-date")
elif selected_filters:
context.update({"selected_filters": [selected_filters]})
results = results.filter(total_price__gte=selected_filters).order_by("-date")
Expand Down
2 changes: 1 addition & 1 deletion backend/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def generate_breadcrumbs(*breadcrumb_list: str) -> list[dict[Any, Any] | None]:
"""
return [all_items.get(breadcrumb) for breadcrumb in breadcrumb_list]

current_url_name: str | Any = request.resolver_match.url_name # type: ignore[union-attr]
current_url_name: str | Any = request.resolver_match.view_name # type: ignore[union-attr]

all_items: dict[str, dict] = {
"dashboard": get_item("Dashboard", "dashboard", "house"),
Expand Down
Loading

0 comments on commit aab5e3f

Please sign in to comment.