Browse Source

Preparando para Django 4

revisaoSidenav
Sesostris Vieira 3 years ago
parent
commit
16e2061513
  1. 1
      .gitignore
  2. 5
      CONTRIBUTORS.txt
  3. 2183
      locale/en/LC_MESSAGES/django.po
  4. 20
      manage.py
  5. 16
      sigi/asgi.py
  6. 7
      sigi/settings/__init__.py
  7. 212
      sigi/settings/base.py
  8. 31
      sigi/settings/dev.py
  9. 45
      sigi/settings/development.py
  10. 22
      sigi/settings/test.py
  11. 59
      sigi/urls.py
  12. 6
      sigi/wsgi.py

1
.gitignore

@ -48,3 +48,4 @@ db.*
.vagrant .vagrant
sigi/settings/prod.py sigi/settings/prod.py
sigi/settings/production.py

5
CONTRIBUTORS.txt

@ -1,4 +1 @@
Sesostris Viera / @SesostrisVieira See https://github.com/interlegis/sigi/graphs/contributors
Breno Teixeira / @Breno_tx
Marcio Mazza / @marciomazza
Gilson Filho / @gilsonfilho

2183
locale/en/LC_MESSAGES/django.po

File diff suppressed because it is too large

20
manage.py

@ -1,10 +1,22 @@
#!/usr/bin/env python #!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os import os
import sys import sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "sigi.settings")
from django.core.management import execute_from_command_line
def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'sigi.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv) execute_from_command_line(sys.argv)
if __name__ == '__main__':
main()

16
sigi/asgi.py

@ -0,0 +1,16 @@
"""
ASGI config for sigi project.
It exposes the ASGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/4.0/howto/deployment/asgi/
"""
import os
from django.core.asgi import get_asgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'sigi.settings')
application = get_asgi_application()

7
sigi/settings/__init__.py

@ -1,13 +1,12 @@
try: try:
from prod import * from sigi.settings.production import *
except ImportError: except ImportError:
from django.core.exceptions import ImproperlyConfigured from django.core.exceptions import ImproperlyConfigured
msg = """ msg = """
###################################################################### ######################################################################
Arquivo prod.py (django settings) nao encontrado. Arquivo production.py (django settings) nao encontrado.
Se vc esta num ambiente de desenvolvimento pode cria-lo com Se vc esta num ambiente de desenvolvimento pode cria-lo com
ln -s dev.py prod.py ln -s development.py production.py
###################################################################### ######################################################################
""" """
raise ImproperlyConfigured(msg) raise ImproperlyConfigured(msg)

212
sigi/settings/base.py

@ -1,199 +1,81 @@
# -*- coding: utf-8 -*-
""" """
Django settings for sigi project. Django base settings for sigi project.
Generated by 'django-admin startproject' using Django 4.0.1.
For more information on this file, see For more information on this file, see
https://docs.djangoproject.com/en/dev/topics/settings/ https://docs.djangoproject.com/en/4.0/topics/settings/
For the full list of settings and their values, see For the full list of settings and their values, see
https://docs.djangoproject.com/en/dev/ref/settings/ https://docs.djangoproject.com/en/4.0/ref/settings/
""" """
# Build paths inside the project like this: os.path.join(BASE_DIR, ...) from pathlib import Path
import os
from os.path import dirname
import django.conf.global_settings as DEFAULT_SETTINGS
BASE_DIR = dirname(dirname(dirname(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/dev/howto/deployment/checklist/
ALLOWED_HOSTS = []
ADMINS = (
# ('Your Name', 'your_email@example.com'),
)
MANAGERS = ADMINS
SITE_ID = 1 # Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
TEMPLATE_CONTEXT_PROCESSORS = DEFAULT_SETTINGS.TEMPLATE_CONTEXT_PROCESSORS + (
'django.core.context_processors.request',
)
# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = ('django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
)
# Application definition # Application definition
INSTALLED_APPS = (
'bootstrap3',
'django_admin_bootstrapped',
INSTALLED_APPS = [
'django.contrib.admin', 'django.contrib.admin',
'django.contrib.auth', 'django.contrib.auth',
'django.contrib.contenttypes', 'django.contrib.contenttypes',
'django.contrib.sessions', 'django.contrib.sessions',
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.staticfiles', 'django.contrib.staticfiles',
]
# Local apps MIDDLEWARE = [
'sigi.apps.home', 'django.middleware.security.SecurityMiddleware',
'sigi.apps.contatos',
'sigi.apps.servidores',
'sigi.apps.parlamentares',
'sigi.apps.casas',
'sigi.apps.convenios',
'sigi.apps.inventario',
'sigi.apps.servicos',
'sigi.apps.metas',
'sigi.apps.ocorrencias',
'sigi.apps.financeiro',
'sigi.apps.diagnosticos',
'sigi.apps.eventos',
'sigi.apps.whois',
# Third-party apps
'localflavor',
'reporting',
'django_extensions',
'easy_thumbnails',
'image_cropping',
'rest_framework',
'tinymce',
)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware', 'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware', 'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware', 'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware',
) ]
ROOT_URLCONF = 'sigi.urls' ROOT_URLCONF = 'sigi.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'sigi.wsgi.application' WSGI_APPLICATION = 'sigi.wsgi.application'
# Internationalization # Internationalization
# https://docs.djangoproject.com/en/dev/topics/i18n/ # https://docs.djangoproject.com/en/4.0/topics/i18n/
LANGUAGE_CODE = 'pt-br'
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True USE_I18N = True
USE_L10N = True
USE_THOUSAND_SEPARATOR = True
TIME_ZONE = "America/Sao_Paulo"
gettext_noop = lambda s: s # for gettext discovery USE_TZ = True
LANGUAGES = (
('en', gettext_noop('English')),
('pt-br', gettext_noop('Brazilian Portuguese')),
)
# Static files (CSS, JavaScript, Images) # Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/dev/howto/static-files/ # https://docs.djangoproject.com/en/4.0/howto/static-files/
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/' STATIC_URL = 'static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'sigiStatic'), # Default primary key field type
) # https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field
SERVER_EMAIL = 'sigi@interlegis.leg.br' DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
DEFAULT_FROM_EMAIL = 'spdt@interlegis.leg.br'
EMAIL_SUBJECT_PREFIX = u'[SIGI]'
TEMPLATE_DIRS = (
os.path.join(BASE_DIR, 'templates'),
)
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'
SESSION_EXPIRE_AT_BROWSER_CLOSE = True
LOGIN_REDIRECT_URL = '/'
LOGIN_URL = '/login/'
# Using pytest directly (without a test runner)
TEST_RUNNER = None
from easy_thumbnails.conf import Settings as thumbnail_settings
THUMBNAIL_PROCESSORS = (
'image_cropping.thumbnail_processors.crop_corners',
) + thumbnail_settings.THUMBNAIL_PROCESSORS
THUMBNAIL_ALIASES = {
'': {
'small': {'size': (300, 225), 'crop': True, },
'thumb': {'size': (160, 120), 'crop': True, },
'portrait': {'size': (73,100), 'crop': True},
'icon': {'size': (36,50), 'crop': True},
},
}
IMAGE_CROPPING_SIZE_WARNING = True
IMAGE_CROPPING_THUMB_SIZE = (800, 600)
LOGGING = {
'version': 1,
'disable_existing_loggers': False,
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
}
},
'handlers': {
'mail_admins': {
'level': 'ERROR',
'class': 'django.utils.log.AdminEmailHandler',
'include_html': True,
'filters': ['require_debug_false'],
},
'file': {
'level': 'DEBUG',
'class': 'logging.FileHandler',
'filename': '/var/log/sigi/application.log',
},
},
'loggers': {
'django.request': {
'handlers': ['mail_admins', 'file'],
'level': 'ERROR',
'propagate': True,
},
},
}
OSTICKET_URL = 'https://suporte.interlegis.leg.br/scp/tickets.php?a=search&query=%s'
REST_FRAMEWORK = {
# Use Django's standard `django.contrib.auth` permissions,
# or allow read-only access for unauthenticated users.
'DEFAULT_PERMISSION_CLASSES': [
'rest_framework.permissions.AllowAny',
]
}
# Lista de endereços IP que podem acessar a API de whois
WHOIS_WHITELIST = [
'127.0.0.1',
]
# TinyMCE configuration
TINYMCE_SPELLCHECKER = True
TINYMCE_COMPRESSOR = True
TINYMCE_DEFAULT_CONFIG = {
'theme': "advanced",
"height": 500,
}

31
sigi/settings/dev.py

@ -1,31 +0,0 @@
from base import *
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '0$ip1fb5xtq%a=)-k_4r^(#jn0t^@+*^kihkxkozg-mip7+w3+'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'sigi',
'USER': 'sigi',
'PASSWORD': 'sigi',
'HOST': 'localhost',
},
}
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
TEMPLATE_DEBUG = DEBUG
DEBUG_TOOLBAR_CONFIG = {
'SHOW_TEMPLATE_CONTEXT': True,
}
INSTALLED_APPS += (
'debug_toolbar',
)
CACHES = {
'default': {
'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
}
}

45
sigi/settings/development.py

@ -0,0 +1,45 @@
from sigi.settings.base import *
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-z%cw$-jyh13g2an=8r5ltkyub75bfc$34o(k#%jncdcdgr2$3#'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Database
# https://docs.djangoproject.com/en/4.0/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'sigi',
'USER': 'sigi',
'PASSWORD': '123456',
'HOST': 'database',
}
}
# Password validation
# https://docs.djangoproject.com/en/4.0/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]

22
sigi/settings/test.py

@ -1,22 +0,0 @@
from base import *
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '0$ip1fb5xtq%a=)-k_4r^(#jn0t^@+*^kihkxkozg-mip7+w3+'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'sigi', # will be actually used as "test_sigi" by pytest-django
'USER': 'sigi',
'PASSWORD': 'sigi',
'HOST': 'localhost',
'PORT': '5432',
}
}
# Validate arguments in django-dynamic-fixture
# http://django-dynamic-fixture.readthedocs.org/en/latest/more.html?highlight=ddf_validate_args#validate-arguments-new-in-1-5-0
DDF_VALIDATE_ARGS = True
DDF_DEBUG_MODE = True
DDF_DEFAULT_DATA_FIXTURE = 'sigi.testutils.SigiDataFixture'

59
sigi/urls.py

@ -1,42 +1,21 @@
#-*- coding:utf-8 -*- """sigi URL Configuration
from django.conf import settings
from django.conf.urls import patterns, include, url
from django.conf.urls.static import static
from django.contrib import admin
from django.views.generic.base import TemplateView
admin.site.index_template = 'index.html'
admin.autodiscover()
urlpatterns = patterns(
'',
url(r'^parlamentares/', include('sigi.apps.parlamentares.urls')),
url(r'^casas/', include('sigi.apps.casas.urls')),
url(r'^convenios/', include('sigi.apps.convenios.urls')),
url(r'^diagnosticos/', include('sigi.apps.diagnosticos.urls')),
url(r'^servicos/', include('sigi.apps.servicos.urls')),
url(r'^dashboard/', include('sigi.apps.metas.urls')),
url(r'^ocorrencias/', include('sigi.apps.ocorrencias.urls')),
url(r'^eventos/', include('sigi.apps.eventos.urls')),
url(r'^whois/', include('sigi.apps.whois.urls')),
url(r'^tinymce/', include('tinymce.urls')),
url(r'^', include('sigi.apps.home.urls')),
url(r'^', include(admin.site.urls)),
# to enable language selection The `urlpatterns` list routes URLs to views. For more information please see:
# Suspended https://docs.djangoproject.com/en/4.0/topics/http/urls/
#url(r'^i18n/', include('django.conf.urls.i18n')), Examples:
Function views
) + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT) 1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
if settings.DEBUG: Class-based views
urlpatterns = patterns( 1. Add an import: from other_app.views import Home
'', 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
url(r'^404/$', TemplateView.as_view(template_name='404.html')), urlpatterns = [
url(r'^500/$', TemplateView.as_view(template_name='500.html')), path('admin/', admin.site.urls),
url(r'^503/$', TemplateView.as_view(template_name='503.html')), ]
url(r'^media/(?P<path>.*)$', 'django.views.static.serve', {
'document_root': settings.MEDIA_ROOT, }),
) + urlpatterns

6
sigi/wsgi.py

@ -4,11 +4,13 @@ WSGI config for sigi project.
It exposes the WSGI callable as a module-level variable named ``application``. It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see For more information on this file, see
https://docs.djangoproject.com/en/dev/howto/deployment/wsgi/ https://docs.djangoproject.com/en/4.0/howto/deployment/wsgi/
""" """
import os import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "sigi.settings")
from django.core.wsgi import get_wsgi_application from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'sigi.settings')
application = get_wsgi_application() application = get_wsgi_application()

Loading…
Cancel
Save