feat: várias melhorias e evoluções no projeto
This commit is contained in:
11
config/api.py
Normal file
11
config/api.py
Normal file
@ -0,0 +1,11 @@
|
||||
from ninja import NinjaAPI
|
||||
from diarios.views import router as diarios_router
|
||||
|
||||
|
||||
api = NinjaAPI(
|
||||
title="API de Diários Oficiais",
|
||||
version="1.0.0",
|
||||
description="API para busca em diários oficiais",
|
||||
)
|
||||
|
||||
api.add_router("/diarios/", diarios_router)
|
||||
@ -7,11 +7,11 @@ from pathlib import Path
|
||||
import environ
|
||||
|
||||
BASE_DIR = Path(__file__).resolve(strict=True).parent.parent.parent
|
||||
# diários_oficiais_alems/
|
||||
APPS_DIR = BASE_DIR / "diários_oficiais_alems"
|
||||
# diarios_oficiais_alems/
|
||||
APPS_DIR = BASE_DIR / "diarios_oficiais_alems"
|
||||
env = environ.Env()
|
||||
|
||||
READ_DOT_ENV_FILE = env.bool("DJANGO_READ_DOT_ENV_FILE", default=False)
|
||||
READ_DOT_ENV_FILE = env.bool("DJANGO_READ_DOT_ENV_FILE", default=True)
|
||||
if READ_DOT_ENV_FILE:
|
||||
# OS environment variables take precedence over variables from .env
|
||||
env.read_env(str(BASE_DIR / ".env"))
|
||||
@ -47,7 +47,7 @@ LOCALE_PATHS = [str(BASE_DIR / "locale")]
|
||||
# ------------------------------------------------------------------------------
|
||||
# https://docs.djangoproject.com/en/dev/ref/settings/#databases
|
||||
DATABASES = {"default": env.db("DATABASE_URL")}
|
||||
DATABASES["default"]["ATOMIC_REQUESTS"] = True
|
||||
DATABASES["default"]["ATOMIC_REQUESTS"] = False
|
||||
# https://docs.djangoproject.com/en/stable/ref/settings/#std:setting-DEFAULT_AUTO_FIELD
|
||||
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
|
||||
|
||||
@ -81,10 +81,10 @@ THIRD_PARTY_APPS = [
|
||||
]
|
||||
|
||||
LOCAL_APPS = [
|
||||
"diários_oficiais_alems.users",
|
||||
"diarios_oficiais_alems.users",
|
||||
"diarios",
|
||||
"django_elasticsearch_dsl",
|
||||
"rest_framework",
|
||||
"corsheaders",
|
||||
]
|
||||
# https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps
|
||||
INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS
|
||||
@ -92,7 +92,7 @@ INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS
|
||||
# MIGRATIONS
|
||||
# ------------------------------------------------------------------------------
|
||||
# https://docs.djangoproject.com/en/dev/ref/settings/#migration-modules
|
||||
MIGRATION_MODULES = {"sites": "diários_oficiais_alems.contrib.sites.migrations"}
|
||||
MIGRATION_MODULES = {"sites": "diarios_oficiais_alems.contrib.sites.migrations"}
|
||||
|
||||
# AUTHENTICATION
|
||||
# ------------------------------------------------------------------------------
|
||||
@ -138,6 +138,8 @@ MIDDLEWARE = [
|
||||
"django.middleware.locale.LocaleMiddleware",
|
||||
"django.middleware.common.CommonMiddleware",
|
||||
"django.middleware.csrf.CsrfViewMiddleware",
|
||||
"corsheaders.middleware.CorsMiddleware",
|
||||
"django.middleware.common.CommonMiddleware",
|
||||
"django.contrib.auth.middleware.AuthenticationMiddleware",
|
||||
"django.contrib.messages.middleware.MessageMiddleware",
|
||||
"django.middleware.clickjacking.XFrameOptionsMiddleware",
|
||||
@ -187,7 +189,7 @@ TEMPLATES = [
|
||||
"django.template.context_processors.static",
|
||||
"django.template.context_processors.tz",
|
||||
"django.contrib.messages.context_processors.messages",
|
||||
"diários_oficiais_alems.users.context_processors.allauth_settings",
|
||||
"diarios_oficiais_alems.users.context_processors.allauth_settings",
|
||||
],
|
||||
},
|
||||
},
|
||||
@ -273,14 +275,14 @@ ACCOUNT_EMAIL_REQUIRED = True
|
||||
# https://docs.allauth.org/en/latest/account/configuration.html
|
||||
ACCOUNT_EMAIL_VERIFICATION = "mandatory"
|
||||
# https://docs.allauth.org/en/latest/account/configuration.html
|
||||
ACCOUNT_ADAPTER = "diários_oficiais_alems.users.adapters.AccountAdapter"
|
||||
ACCOUNT_ADAPTER = "diarios_oficiais_alems.users.adapters.AccountAdapter"
|
||||
# https://docs.allauth.org/en/latest/account/forms.html
|
||||
ACCOUNT_FORMS = {"signup": "diários_oficiais_alems.users.forms.UserSignupForm"}
|
||||
ACCOUNT_FORMS = {"signup": "diarios_oficiais_alems.users.forms.UserSignupForm"}
|
||||
# https://docs.allauth.org/en/latest/socialaccount/configuration.html
|
||||
SOCIALACCOUNT_ADAPTER = "diários_oficiais_alems.users.adapters.SocialAccountAdapter"
|
||||
SOCIALACCOUNT_ADAPTER = "diarios_oficiais_alems.users.adapters.SocialAccountAdapter"
|
||||
# https://docs.allauth.org/en/latest/socialaccount/configuration.html
|
||||
SOCIALACCOUNT_FORMS = {
|
||||
"signup": "diários_oficiais_alems.users.forms.UserSocialSignupForm"
|
||||
"signup": "diarios_oficiais_alems.users.forms.UserSocialSignupForm"
|
||||
}
|
||||
# django-compressor
|
||||
# ------------------------------------------------------------------------------
|
||||
@ -290,40 +292,67 @@ STATICFILES_FINDERS += ["compressor.finders.CompressorFinder"]
|
||||
|
||||
# Elastic Search
|
||||
# ------------------------------------------------------------------------------
|
||||
ELASTICSEARCH_USER = env.str("ELASTICSEARCH_USER")
|
||||
ELASTICSEARCH_PASSWORD = env.str("ELASTICSEARCH_PASSWORD")
|
||||
|
||||
ELASTICSEARCH_DSL = {
|
||||
"default": {"hosts": "http://elasticsearch:9200"}, # same as above
|
||||
"default": {
|
||||
"hosts": "http://elasticsearch:9200",
|
||||
"timeout": 60,
|
||||
"http_auth": (
|
||||
ELASTICSEARCH_USER,
|
||||
ELASTICSEARCH_PASSWORD,
|
||||
),
|
||||
},
|
||||
}
|
||||
ELASTICSEARCH_HOSTS = "http://elasticsearch:9200"
|
||||
|
||||
ELASTICSEARCH_INDEX_SETTINGS = {
|
||||
'number_of_shards': 1,
|
||||
'number_of_replicas': 0,
|
||||
'analysis': {
|
||||
'filter': {
|
||||
'portuguese_stop': {
|
||||
'type': 'stop',
|
||||
'stopwords': '_portuguese_'
|
||||
# Define o número de shards (partições) para o índice.
|
||||
"number_of_shards": 1,
|
||||
# Define o número de réplicas de cada shard.
|
||||
"number_of_replicas": 0,
|
||||
# Configurações de análise do Elasticsearch para processamento do texto
|
||||
"analysis": {
|
||||
# Definição de filtros de análise
|
||||
"filter": {
|
||||
# Filtro de remoção de stopwords (palavras comuns que não agregam significado)
|
||||
"portuguese_stop": {"type": "stop", "stopwords": "_portuguese_"},
|
||||
# Filtro de stemming para reduzir palavras à sua raiz (ex: "correndo" -> "correr")
|
||||
"portuguese_stemmer": {"type": "stemmer", "language": "portuguese"},
|
||||
# Filtro de sinônimos, carregando um arquivo externo com a lista de sinônimos
|
||||
"synonym_filter": {
|
||||
"type": "synonym",
|
||||
"synonyms_path": "analysis/sinonimos.txt", # Caminho para o arquivo de sinônimos
|
||||
},
|
||||
'portuguese_stemmer': {
|
||||
'type': 'stemmer',
|
||||
'language': 'portuguese'
|
||||
},
|
||||
'synonym_filter': {
|
||||
'type': 'synonym',
|
||||
'synonyms_path': 'analysis/sinonimos.txt',
|
||||
},
|
||||
# Definição de analisadores (combinações de tokenizer e filtros)
|
||||
"analyzer": {
|
||||
# Criando um analisador chamado "pt_analyzer" para português
|
||||
"pt_analyzer": {
|
||||
# Define o tokenizer como "standard", que quebra o texto em palavras básicas
|
||||
"tokenizer": "standard",
|
||||
# Lista de filtros a serem aplicados ao texto após a tokenização
|
||||
"filter": [
|
||||
# Converte todas as palavras para minúsculas
|
||||
"lowercase",
|
||||
# Aplica o filtro de remoção de stopwords em português
|
||||
"portuguese_stop",
|
||||
# Aplica o filtro de stemming para reduzir palavras à sua raiz
|
||||
"portuguese_stemmer",
|
||||
# Aplica o filtro de sinônimos, substituindo palavras por seus sinônimos conforme o arquivo
|
||||
"synonym_filter",
|
||||
],
|
||||
}
|
||||
},
|
||||
'analyzer': {
|
||||
'pt_analyzer': {
|
||||
'tokenizer': 'standard',
|
||||
'filter': [
|
||||
'lowercase',
|
||||
'portuguese_stop',
|
||||
'portuguese_stemmer',
|
||||
'synonym_filter'
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
CORS_ALLOWED_ORIGINS = [
|
||||
"http://109.199.98.226:8006",
|
||||
"http://109.199.98.226:8005",
|
||||
"http://localhost:8006",
|
||||
"http://localhost:8005",
|
||||
"http://127.0.0.1:8006",
|
||||
"http://127.0.0.1:8005",
|
||||
]
|
||||
|
||||
@ -6,21 +6,25 @@ from django.urls import include
|
||||
from django.urls import path
|
||||
from django.views import defaults as default_views
|
||||
from django.views.generic import TemplateView
|
||||
from .api import api
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
path("", TemplateView.as_view(template_name="pages/home.html"), name="home"),
|
||||
path('', include('diarios.urls')),
|
||||
path(
|
||||
"about/",
|
||||
TemplateView.as_view(template_name="pages/about.html"),
|
||||
name="about",
|
||||
),
|
||||
path("api/v1/", api.urls),
|
||||
# Django Admin, use {% url 'admin:index' %}
|
||||
path(settings.ADMIN_URL, admin.site.urls),
|
||||
# User management
|
||||
path("users/", include("diários_oficiais_alems.users.urls", namespace="users")),
|
||||
path("accounts/", include("allauth.urls")),
|
||||
path("users/", include("diarios_oficiais_alems.users.urls", namespace="users")),
|
||||
# path("accounts/", include("allauth.urls")),
|
||||
# Your stuff: custom urls includes go here
|
||||
path("diarios/", include("diarios.urls")),
|
||||
path("", include("diarios.urls")),
|
||||
# Media files
|
||||
*static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT),
|
||||
]
|
||||
|
||||
@ -22,9 +22,9 @@ from pathlib import Path
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
|
||||
# This allows easy placement of apps within the interior
|
||||
# diários_oficiais_alems directory.
|
||||
# diarios_oficiais_alems directory.
|
||||
BASE_DIR = Path(__file__).resolve(strict=True).parent.parent
|
||||
sys.path.append(str(BASE_DIR / "diários_oficiais_alems"))
|
||||
sys.path.append(str(BASE_DIR / "diarios_oficiais_alems"))
|
||||
# We defer to a DJANGO_SETTINGS_MODULE already in the environment. This breaks
|
||||
# if running multiple sites in the same mod_wsgi process. To fix this, use
|
||||
# mod_wsgi daemon mode with each site in its own daemon process, or use
|
||||
|
||||
Reference in New Issue
Block a user