Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 29 additions & 12 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
ROOT_DIR = Path(__file__).resolve(strict=True).parent.parent.parent
# core/
APPS_DIR = ROOT_DIR / "core"
LLAMA_MODEL_DIR = ROOT_DIR / "ia/download"

env = environ.Env()
READ_DOT_ENV_FILE = env.bool("DJANGO_READ_DOT_ENV_FILE", default=False)
Expand All @@ -40,7 +41,7 @@
"core.home",
"wagtail.contrib.forms",
"wagtail.contrib.redirects",
'wagtail.contrib.settings',
"wagtail.contrib.settings",
"wagtail_modeladmin",
"wagtail.embeds",
"wagtail.sites",
Expand All @@ -63,7 +64,7 @@
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"django_celery_results"
"django_celery_results",
]

THIRD_PARTY_APPS = [
Expand All @@ -77,6 +78,7 @@
"core",
"core_settings",
"xml_manager",
"ia",
]

INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS + WAGTAIL
Expand All @@ -85,7 +87,7 @@
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
'django.middleware.locale.LocaleMiddleware',
"django.middleware.locale.LocaleMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
Expand All @@ -106,7 +108,7 @@
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
'wagtail.contrib.settings.context_processors.settings',
"wagtail.contrib.settings.context_processors.settings",
],
},
},
Expand Down Expand Up @@ -145,13 +147,13 @@
LANGUAGE_CODE = "en"

LANGUAGES = [
('pt-br', 'Português (Brasil)'),
('es', 'Español'),
('en', 'English'),
("pt-br", "Português (Brasil)"),
("es", "Español"),
("en", "English"),
]

LOCALE_PATHS = [
os.path.join(BASE_DIR, 'locale'),
os.path.join(BASE_DIR, "locale"),
]

TIME_ZONE = "UTC"
Expand Down Expand Up @@ -239,10 +241,22 @@
# This can be omitted to allow all files, but note that this may present a security risk
# if untrusted users are allowed to upload files -
# see https://docs.wagtail.org/en/stable/advanced_topics/deploying.html#user-uploaded-files
WAGTAILDOCS_EXTENSIONS = ['csv', 'docx', 'json', 'key', 'odt', 'pdf', 'pptx', 'rtf', 'txt', 'xlsx', 'zip']
WAGTAILDOCS_EXTENSIONS = [
"csv",
"docx",
"json",
"key",
"odt",
"pdf",
"pptx",
"rtf",
"txt",
"xlsx",
"zip",
]

# https://docs.djangoproject.com/en/dev/ref/settings/#auth-user-model
AUTH_USER_MODEL = 'users.CustomUser'
AUTH_USER_MODEL = "users.CustomUser"

# Celery
# ------------------------------------------------------------------------------
Expand All @@ -269,13 +283,15 @@
CELERY_BEAT_SCHEDULER = "django_celery_beat.schedulers:DatabaseScheduler"
# http://docs.celeryproject.org/en/latest/userguide/configuration.html
DJANGO_CELERY_BEAT_TZ_AWARE = False
#CELERY PROMETHEUS DASHBOARD
# CELERY PROMETHEUS DASHBOARD
# https://docs.celeryq.dev/en/stable/userguide/configuration.html#worker-send-task-events
CELERY_WORKER_SEND_TASK_EVENTS = True
# https://docs.celeryq.dev/en/stable/userguide/configuration.html#std-setting-task_send_sent_event
CELERY_SEND_TASK_SENT_EVENT = True
CELERYD_SEND_EVENTS = True
CE_BUCKETS=1,2.5,5,10,30,60,300,600,900,1800
CE_BUCKETS = 1, 2.5, 5, 10, 30, 60, 300, 600, 900, 1800

LLAMA_ENABLED = env.bool("LLAMA_ENABLED", default=True)

# Celery Results
# ------------------------------------------------------------------------------
Expand All @@ -285,3 +301,4 @@
CELERY_RESULT_EXTENDED = True

DATA_UPLOAD_MAX_NUMBER_FIELDS = 10000
SILENCED_SYSTEM_CHECKS = ["treebeard.E001"]
1 change: 1 addition & 0 deletions config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

urlpatterns = [
path("django-admin/", admin.site.urls),
path("admin/ia/", include("ia.urls")),
path("admin/", include(wagtailadmin_urls)),
path("documents/", include(wagtaildocs_urls)),
path("i18n/", include("django.conf.urls.i18n")),
Expand Down
7 changes: 0 additions & 7 deletions core/wagtail_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,6 @@ def ensure_image_title(sender, instance, **kwargs):
pre_save.connect(ensure_image_title, sender=get_image_model())


@hooks.register("construct_main_menu")
def keep_only_sps_validation_menu(request, menu_items):
menu_items[:] = [
item for item in menu_items if item.name == "sps_package_validation"
]


@hooks.register("construct_help_menu")
def replace_help_menu_items(request, help_menu_items):
help_menu_items[:] = [
Expand Down
1 change: 1 addition & 0 deletions ia/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

8 changes: 8 additions & 0 deletions ia/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.apps import AppConfig
from django.utils.translation import gettext_lazy as _


class IAConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "ia"
verbose_name = _("IA Model")
33 changes: 33 additions & 0 deletions ia/db_router.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
class IADatabaseRouter:
app_label = "ia"
db_alias = "ia_db"

def _ia_db_configured(self):
from django.conf import settings

return self.db_alias in settings.DATABASES

def db_for_read(self, model, **hints):
if model._meta.app_label == self.app_label and self._ia_db_configured():
return self.db_alias
return None

def db_for_write(self, model, **hints):
if model._meta.app_label == self.app_label and self._ia_db_configured():
return self.db_alias
return None

def allow_relation(self, obj1, obj2, **hints):
if (
obj1._meta.app_label == self.app_label
or obj2._meta.app_label == self.app_label
):
return True
return None

def allow_migrate(self, db, app_label, model_name=None, **hints):
if app_label != self.app_label:
return None
if self._ia_db_configured():
return db == self.db_alias
return db == "default"
10 changes: 10 additions & 0 deletions ia/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class LlamaDisabledError(Exception):
pass


class LlamaModelNotFoundError(FileNotFoundError):
pass


class LlamaNotInstalledError(ImportError):
pass
15 changes: 15 additions & 0 deletions ia/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from wagtail.admin.forms import WagtailAdminModelForm


class IAAdminModelForm(WagtailAdminModelForm):
def save_all(self, user):
model_with_creator = super().save(commit=False)

if self.instance.pk is not None:
model_with_creator.updated_by = user
else:
model_with_creator.creator = user

self.save()

return model_with_creator
Loading