Skip to content

Commit

Permalink
Updated core to 0.0.4 and fixed settings
Browse files Browse the repository at this point in the history
Signed-off-by: Trey <[email protected]>
  • Loading branch information
TreyWW committed Dec 30, 2024
1 parent 000cd9b commit ed91e32
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 66 deletions.
45 changes: 24 additions & 21 deletions backend/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,30 @@
path("clients/", include("backend.clients.api.urls", namespace="clients")),
path("", include("backend.finance.api.urls", namespace="finance")),
path(
"settings/",
include(
(
[
path("client_defaults/<int:client_id>/", handle_client_defaults_endpoints, name="client_defaults"),
path("client_defaults/", handle_client_defaults_endpoints, name="client_defaults without client"),
path(
"client_defaults/remove_default_logo/",
remove_client_default_logo_endpoint,
name="client_defaults remove logo without client",
),
path(
"client_defaults/remove_default_logo/<int:client_id>",
remove_client_default_logo_endpoint,
name="client_defaults remove logo",
),
],
"settings",
),
namespace="settings",
),
"",
include("backend.api.settings.urls", namespace="settings"),
# path(
# "settings/",
# include(
# (
# [
# path("client_defaults/<int:client_id>/", handle_client_defaults_endpoints, name="client_defaults"),
# path("client_defaults/", handle_client_defaults_endpoints, name="client_defaults without client"),
# path(
# "client_defaults/remove_default_logo/",
# remove_client_default_logo_endpoint,
# name="client_defaults remove logo without client",
# ),
# path(
# "client_defaults/remove_default_logo/<int:client_id>",
# remove_client_default_logo_endpoint,
# name="client_defaults remove logo",
# ),
# ],
# "settings",
# ),
# namespace="settings",
# ),
),
path("public/", include("backend.api.public.urls")),
path("emails/", include("backend.api.emails.urls")),
Expand Down
20 changes: 20 additions & 0 deletions backend/core/service/settings/view/email_templates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from core.types.requests import WebRequest

from backend.finance.service.defaults.get import get_account_defaults


def email_templates_context(request: WebRequest, context: dict) -> None:
acc_defaults = get_account_defaults(request.actor)
context.update(
{
"account_defaults": acc_defaults,
"email_templates": {
"recurring_invoices": {
"invoice_created": acc_defaults.email_template_recurring_invoices_invoice_created,
"invoice_overdue": acc_defaults.email_template_recurring_invoices_invoice_overdue,
"invoice_cancelled": acc_defaults.email_template_recurring_invoices_invoice_cancelled,
}
},
}
)
# print(context.get("email_templates"))
36 changes: 18 additions & 18 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ drf-yasg = "^1.21.7"
setuptools = "^70.1.1"
xhtml2pdf = "^0.2.16"
stripe = "^10.8.0"
strelix-core = "^0.0.2"
strelix-core = { version = "0.0.4" }
[tool.poetry.group.mypy.dependencies]
mypy = "1.7.1"
django-stubs = { version = "4.2.7" }
Expand Down
28 changes: 21 additions & 7 deletions settings/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@

import stripe
from core.config import CoreConfig
from django.conf import settings
from django.contrib.messages import constants as messages
from django.contrib.staticfiles.storage import FileSystemStorage # type: ignore
from storages.backends.s3 import S3Storage

from .helpers import get_var

core_config = CoreConfig()

# from backend.utils import appconfig

DEBUG = True if get_var("DEBUG") in ["True", "true", "TRUE", True] else False
Expand Down Expand Up @@ -131,6 +134,8 @@
"social_core.backends.google.GoogleOAuth2",
]

AUTH_USER_MODEL = "core.User"

SECRET_KEY = get_var("SECRET_KEY", default="secret_key")

LOGIN_URL = "/auth/login/"
Expand Down Expand Up @@ -288,8 +293,6 @@
}
}

AUTH_USER_MODEL = "core.User"

LANGUAGE_CODE = "en-us"

TIME_ZONE = "UTC"
Expand Down Expand Up @@ -344,6 +347,7 @@
},
"handlers": {
"console": {
"level": "DEBUG",
"class": "logging.StreamHandler",
"formatter": "simple",
},
Expand All @@ -352,20 +356,26 @@
"django": {
"handlers": ["console"],
"level": "INFO",
"propagate": True,
"propagate": False, # Ensure propagation is False to avoid duplicates
},
"django.db.backends": {
"handlers": ["console"],
"level": get_var("DJANGO_LOG_LEVEL", default="INFO"),
"propagate": False,
"level": "INFO", # Set your desired logging level
"propagate": False, # Prevent propagation for database logs
},
"django.request": {
"handlers": ["console"],
"level": "ERROR",
"propagate": False, # Only log errors for requests
},
},
"root": {
"handlers": ["console"],
"level": get_var("DJANGO_LOG_LEVEL", default="INFO"),
"level": "INFO", # Root logger level
},
}

# Apply the configuration to the Django logging system
logging.config.dictConfig(LOGGING)


Expand Down Expand Up @@ -461,7 +471,11 @@ class CustomPrivateMediaStorage(FileSystemStorage): # type: ignore # This overr

# CORE SETTINGS

EXPIRY_MODELS = CoreConfig().CORE_EXPIRY_MODELS + ["backend.InvoiceURL"]
core_config.EXPIRY_MODELS += ["backend.InvoiceURL"]
core_config.SETTINGS_PAGE_CONTEXT_HANDLERS.update(
{"email_templates": "backend.core.service.settings.view.email_templates.email_templates_context"}
)
# EXPIRY_MODELS = CoreConfig().EXPIRY_MODELS

# SENDGRID_SANDBOX_MODE_IN_DEBUG = True
if "test" in sys.argv[1:]:
Expand Down
54 changes: 35 additions & 19 deletions tailwind.config.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,56 @@
/** @type {import('tailwindcss').Config} */

const {execSync} = require('child_process');
const {spawnSync} = require('child_process');
const path = require('path');
const projectRoot = path.resolve(__dirname, '.');

function getDjangoTemplates(appName) {
try {
// Get the path of the app's templates directory in the pip-installed package
const result = execSync(
`python -c "import importlib.util, os; app_spec = importlib.util.find_spec('${appName}'); print(os.path.join(os.path.dirname(app_spec.origin), 'templates'))"`
).toString().trim();
const getCoreTemplateFiles = () => {
const command = 'python'; // Requires virtualenv to be activated.
const args = ['manage.py', 'list_core_templates']; // Requires cwd to be set.
const options = {cwd: projectRoot};
const result = spawnSync(command, args, options);

return result || '';
} catch (error) {
console.error(`Failed to get templates for ${appName}:`, error);
return '';
if (result.error) {
throw result.error;
}
}

const coreTemplatesPath = getDjangoTemplates('core');
const billingTemplatesPath = getDjangoTemplates('billing');
if (result.status !== 0) {
console.log(result.stdout.toString(), result.stderr.toString());
throw new Error(`Django management command exited with code ${result.status}`);
}

const covert_to_template = (value) => {
new_value = value.trim()

if (!new_value.startsWith("TMPL:")) {
return ""
}

// new_value = value.replace(/\\/g, "/").replace("\\", "/").replace("\r", "") + "/**/*.html"

return new_value.slice(5) + "/**/*.html"
}

console.log('Resolved core templates path:', coreTemplatesPath);
console.log('Resolved billing templates path:', billingTemplatesPath);
const templateFiles = result.stdout.toString()
.split('\n')
.map((path) => covert_to_template(path))
.filter(function (e) {
return e
}); // Remove empty strings, including last empty line.
console.log(templateFiles)
return templateFiles;
}

module.exports = {
mode: 'jit',
content: [
'./frontend/templates/**/*.html',
'./billing/templates/**/*.html',
'./components/**/*.html',
'./frontend/templates/base/base.html',
'./backend/**/views/*.py',
'./backend/views/core/**/*.py',
'./assets/scripts/tableify.js',
coreTemplatesPath ? `${coreTemplatesPath}/**/*.html` : '',
billingTemplatesPath ? `${billingTemplatesPath}/**/*.html` : '',
...getCoreTemplateFiles()
],
safelist: [
'alert',
Expand Down

0 comments on commit ed91e32

Please sign in to comment.