Skip to content

Commit

Permalink
Updated to use core/ templates, attempted to fix migrations (broke th…
Browse files Browse the repository at this point in the history
…em more though)

Signed-off-by: Trey <73353716+TreyWW@users.noreply.github.com>
  • Loading branch information
TreyWW committed Jan 1, 2025
1 parent e16ebcd commit 28637e7
Show file tree
Hide file tree
Showing 116 changed files with 1,438 additions and 2,399 deletions.
6 changes: 2 additions & 4 deletions backend/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@
InvoiceProduct,
Receipt,
ReceiptDownloadToken,
FinanceDefaultValues,
)

from backend.clients.models import Client, DefaultValues

# from django.contrib.auth.models imp/ort User
# admin.register(Invoice)
admin.site.register(
[
Client,
Invoice,
InvoiceURL,
InvoiceItem,
Expand All @@ -26,7 +24,7 @@
ReceiptDownloadToken,
InvoiceReminder,
InvoiceRecurringProfile,
DefaultValues,
FinanceDefaultValues,
]
)

Expand Down
2 changes: 1 addition & 1 deletion backend/api/emails/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from django.shortcuts import render, redirect
from django_ratelimit.core import is_ratelimited

from backend.decorators import web_require_scopes
from core.decorators import web_require_scopes
from backend.models import EmailSendStatus
from core.types.htmx import HtmxHttpRequest

Expand Down
16 changes: 8 additions & 8 deletions backend/api/emails/send.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
from django.views.decorators.http import require_POST
from mypy_boto3_sesv2.type_defs import BulkEmailEntryResultTypeDef

from backend.decorators import feature_flag_check, web_require_scopes
from backend.decorators import htmx_only
from core.decorators import feature_flag_check, web_require_scopes
from core.decorators import htmx_only
from backend.models import Client
from backend.models import EmailSendStatus

Expand Down Expand Up @@ -82,7 +82,7 @@ def _send_bulk_email_view(request: WebRequest) -> HttpResponse:

if validated_bulk:
messages.error(request, validated_bulk)
return render(request, "base/toast.html")
return render(request, "core/base/toast.html")

message += email_footer()
message_single_line_html = message.replace("\r\n", "<br>").replace("\n", "<br>")
Expand Down Expand Up @@ -124,7 +124,7 @@ def _send_bulk_email_view(request: WebRequest) -> HttpResponse:
}
)
messages.success(request, f"Successfully emailed {len(email_list)} people.")
return render(request, "base/toast.html")
return render(request, "core/base/toast.html")

EMAIL_SENT = send_templated_bulk_email(
email_list=email_list,
Expand All @@ -138,7 +138,7 @@ def _send_bulk_email_view(request: WebRequest) -> HttpResponse:

if EMAIL_SENT.failed:
messages.error(request, EMAIL_SENT.error)
return render(request, "base/toast.html")
return render(request, "core/base/toast.html")

# todo - fix

Expand Down Expand Up @@ -188,7 +188,7 @@ def _send_bulk_email_view(request: WebRequest) -> HttpResponse:
# except QuotaLimit.DoesNotExist:
# ...

return render(request, "base/toast.html")
return render(request, "core/base/toast.html")


def _send_single_email_view(request: WebRequest) -> HttpResponse:
Expand All @@ -205,7 +205,7 @@ def _send_single_email_view(request: WebRequest) -> HttpResponse:

if validated_single:
messages.error(request, validated_single)
return render(request, "base/toast.html")
return render(request, "core/base/toast.html")

message += email_footer()
message_single_line_html = message.replace("\r\n", "<br>").replace("\n", "<br>")
Expand Down Expand Up @@ -249,7 +249,7 @@ def _send_single_email_view(request: WebRequest) -> HttpResponse:

# QuotaUsage.create_str(request.user, "emails-single-count", status_object.id)

return render(request, "base/toast.html")
return render(request, "core/base/toast.html")


def validate_bulk_inputs(*, request, emails, clients, message, subject) -> str | None:
Expand Down
10 changes: 5 additions & 5 deletions backend/api/emails/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from django_ratelimit.core import is_ratelimited
from mypy_boto3_sesv2.type_defs import GetMessageInsightsResponseTypeDef, InsightsEventTypeDef

from backend.decorators import htmx_only, feature_flag_check, web_require_scopes
from core.decorators import htmx_only, feature_flag_check, web_require_scopes
from backend.models import EmailSendStatus
from core.types.htmx import HtmxHttpRequest
from settings.helpers import EMAIL_CLIENT
Expand All @@ -26,13 +26,13 @@ def get_status_view(request: HtmxHttpRequest, status_id: str) -> HttpResponse:
EMAIL_STATUS = EmailSendStatus.objects.get(user=request.user, id=status_id)
except EmailSendStatus.DoesNotExist:
messages.error(request, "Status not found")
return render(request, "base/toast.html")
return render(request, "core/base/toast.html")

message_insight = get_message_insights(message_id=EMAIL_STATUS.aws_message_id) # type: ignore[arg-type]

if isinstance(message_insight, str):
messages.error(request, message_insight)
return render(request, "base/toast.html", {"autohide": False})
return render(request, "core/base/toast.html", {"autohide": False})

important_info = get_important_info_from_response(message_insight)

Expand All @@ -41,7 +41,7 @@ def get_status_view(request: HtmxHttpRequest, status_id: str) -> HttpResponse:
EMAIL_STATUS.save()

messages.success(request, f"Status updated to {important_info['status']}")
return render(request, "base/toast.html", {"autohide": False})
return render(request, "core/base/toast.html", {"autohide": False})


@require_POST
Expand All @@ -52,7 +52,7 @@ def refresh_all_statuses_view(request: HtmxHttpRequest) -> HttpResponse:
request, group="email-refresh_all_statuses", key="user", rate="1/m", increment=True
):
messages.error(request, "Woah, slow down! Refreshing the statuses takes a while, give us a break!")
return render(request, "base/toast.html")
return render(request, "core/base/toast.html")
if request.user.logged_in_as_team:
ALL_STATUSES = EmailSendStatus.objects.filter(organization=request.user.logged_in_as_team)
else:
Expand Down
2 changes: 1 addition & 1 deletion backend/api/public/endpoints/invoices/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from rest_framework.decorators import api_view
from rest_framework.response import Response

from backend.clients.models import Client
from backend.models import Client
from core.api.public.decorators import require_scopes
from core.api.public.helpers.response import APIResponse
from backend.api.public.serializers.invoices import InvoiceSerializer
Expand Down
10 changes: 5 additions & 5 deletions backend/api/settings/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from django.shortcuts import render
from django.views.decorators.http import require_http_methods

from backend.clients.models import Client
from backend.models import Client
from backend.finance.service.clients.validate import validate_client
from backend.finance.service.defaults.get import get_account_defaults
from backend.finance.service.defaults.update import change_client_defaults
Expand Down Expand Up @@ -62,10 +62,10 @@ def change_client_defaults_endpoint(request: WebRequest, client_id: int | None =

if response.failed:
messages.error(request, response.error)
return render(request, "base/toast.html")
return render(request, "core/base/toast.html")

messages.success(request, "Successfully updated client defaults")
return render(request, "base/toast.html")
return render(request, "core/base/toast.html")


@require_http_methods(["DELETE"])
Expand All @@ -85,11 +85,11 @@ def remove_client_default_logo_endpoint(request: WebRequest, client_id: int | No

if not defaults.default_invoice_logo:
messages.error(request, "No default logo to remove")
return render(request, "base/toast.html")
return render(request, "core/base/toast.html")

defaults.default_invoice_logo.delete()

messages.success(request, "Successfully updated client defaults")
resp = render(request, "base/toast.html")
resp = render(request, "core/base/toast.html")
resp["HX-Refresh"] = "true"
return resp
8 changes: 4 additions & 4 deletions backend/api/settings/email_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.views.decorators.http import require_POST

from backend.finance.service.defaults.get import get_account_defaults
from backend.decorators import web_require_scopes
from core.decorators import web_require_scopes
from core.types.requests import WebRequest


Expand All @@ -15,11 +15,11 @@ def save_email_template(request: WebRequest, template: str):

if template not in ["invoice_created", "invoice_overdue", "invoice_cancelled"]:
messages.error(request, f"Invalid template: {template}")
return render(request, "base/toast.html")
return render(request, "core/base/toast.html")

if content is None:
messages.error(request, f"Missing content for template: {template}")
return render(request, "base/toast.html")
return render(request, "core/base/toast.html")

acc_defaults = get_account_defaults(request.actor)

Expand All @@ -29,4 +29,4 @@ def save_email_template(request: WebRequest, template: str):

messages.success(request, f"Email template '{template}' saved successfully")

return render(request, "base/toast.html")
return render(request, "core/base/toast.html")
22 changes: 0 additions & 22 deletions backend/auth_backends.py

This file was deleted.

4 changes: 2 additions & 2 deletions backend/clients/api/delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.shortcuts import render
from django.views.decorators.http import require_http_methods

from backend.decorators import web_require_scopes
from core.decorators import web_require_scopes
from backend.finance.service.clients.delete import delete_client, DeleteClientServiceResponse
from core.types.requests import WebRequest

Expand All @@ -16,4 +16,4 @@ def client_delete(request: WebRequest, id: int):
messages.error(request, response.error)
else:
messages.success(request, f"Successfully deleted client #{id}")
return render(request, "base/toast.html")
return render(request, "core/base/toast.html")
4 changes: 2 additions & 2 deletions backend/clients/api/fetch.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from django.shortcuts import render, redirect
from django.views.decorators.http import require_http_methods

from backend.decorators import web_require_scopes
from backend.clients.models import Client
from core.decorators import web_require_scopes
from backend.models import Client
from backend.finance.service.clients.get import fetch_clients, FetchClientServiceResponse
from core.types.htmx import HtmxHttpRequest
from core.types.requests import WebRequest
Expand Down
8 changes: 4 additions & 4 deletions backend/clients/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.dispatch import receiver
from django.db.models.signals import post_save

from backend.clients.models import Client, DefaultValues
from backend.models import Client, FinanceDefaultValues

logger = logging.getLogger(__name__)

Expand All @@ -16,11 +16,11 @@ def create_client_defaults(sender: Type[Client], instance: Client, created, **kw
logger.info(f"Creating client defaults for client #{instance.id}")

if instance.user:
account_defaults, _ = DefaultValues.objects.get_or_create(user=instance.owner, client=None)
account_defaults, _ = FinanceDefaultValues.objects.get_or_create(user=instance.owner, client=None)
else:
account_defaults, _ = DefaultValues.objects.get_or_create(organization=instance.owner, client=None)
account_defaults, _ = FinanceDefaultValues.objects.get_or_create(organization=instance.owner, client=None)

defaults = DefaultValues.objects.create(client=instance, owner=instance.owner) # type: ignore[misc]
defaults = FinanceDefaultValues.objects.create(client=instance, owner=instance.owner) # type: ignore[misc]

defaults.invoice_date_value = account_defaults.invoice_date_value
defaults.invoice_date_type = account_defaults.invoice_date_type
Expand Down
Loading

0 comments on commit 28637e7

Please sign in to comment.