Skip to content

Commit

Permalink
Merge pull request #39 from marcanpilami/mag/defaultproject
Browse files Browse the repository at this point in the history
Added more FK to models
  • Loading branch information
marcanpilami committed Oct 2, 2022
2 parents e5d4812 + 76f5a98 commit d3e65d1
Show file tree
Hide file tree
Showing 75 changed files with 760 additions and 536 deletions.
12 changes: 11 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
doc
doc
.env/
.venv/
env/
venv/
.github/
doc/
tmp/
MAGE/local_settings.py
*.pyc
**/Dockerfile*
5 changes: 4 additions & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
[FORMAT]
max-line-length=240
max-line-length=240

[MESSAGES CONTROL]
disable=missing-class-docstring,missing-function-docstring
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"**/templates/**/*": "django-txt",
"**/requirements{/**,*}.{txt,in}": "pip-requirements"
},
"snooty.sourceFolder": "${workspaceFolder}/doc",
"restructuredtext.confPath": "${workspaceFolder}/doc",
"esbonio.sphinx.confDir": "${workspaceFolder}\\doc",
"restructuredtext.linter.rstcheck.executablePath": "rstcheck",
}
17 changes: 9 additions & 8 deletions MAGE/force_login_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,28 @@ class ForceLoginMiddleware(object):
"""
Middleware component that forces authentication on all views.
It actually wraps the login_required decorator around the views.
To use, add the class to MIDDLEWARE_CLASSES and optionally define
To use, add the class to MIDDLEWARE and optionally define
FORCE_LOGIN_EXCEPTIONS containing the named URLs that are to be
exempted from forces authentication in your settings.py.
For example:
------
FORCE_LOGIN_EXCEPTIONS = ('login', 'script_login')
------
"""
def __init__(self):
self.exceptions = ('login',)
def __init__(self, next_chain):
self.exceptions = ('login', 'logout', )
self.next = next_chain
if hasattr(settings, 'FORCE_LOGIN_EXCEPTIONS'):
self.exceptions = settings.FORCE_LOGIN_EXCEPTIONS

def process_view(self, request, view_func, view_args, view_kwargs):
def __call__(self, request):
# No need to process URLs if user already logged in
if request.user.is_authenticated:
return None
return self.next(request)

# An exception match should immediately return None
if request.resolver_match.url_name in self.exceptions:
return None
if not request.resolver_match or request.resolver_match.url_name in self.exceptions:
return self.next(request)

# Otherwise return the view wrapped inside the standard decorator
return login_required(view_func)(request, *view_args, **view_kwargs)
return login_required(self.next)(request)
28 changes: 28 additions & 0 deletions MAGE/local_settings.docker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# coding: utf-8
import os

BASE_DIR = os.path.dirname(os.path.dirname(__file__))
MEDIA_ROOT = os.path.join(BASE_DIR, 'deployment/media')
STATIC_ROOT = os.path.join(BASE_DIR, 'deployment/static')

USE_X_FORWARDED_HOST = True
USE_X_FORWARDED_PORT = True
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

MIDDLEWARE = [
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'whitenoise.middleware.WhiteNoiseMiddleware',
'ref.middleware.DisableCSRF',
'MAGE.project_middleware.ProjectFromProjectIdMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'MAGE.force_login_middleware.ForceLoginMiddleware',
]

STATICFILES_STORAGE = "whitenoise.storage.CompressedManifestStaticFilesStorage"

TIME_ZONE = 'Europe/Paris'
LANGUAGE_CODE = 'fr-fr'

DEFAULT_PROJECT_ID=os.getenv('MAGE_DEFAULT_PROJECT', None)
2 changes: 1 addition & 1 deletion MAGE/local_settings.sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
#}

# Uncomment to force authentication on all pages (default is public read access)
# LOCAL_MIDDLEWARE_CLASSES = ['MAGE.force_login_middleware.ForceLoginMiddleware',]
# LOCAL_MIDDLEWARE = ['MAGE.force_login_middleware.ForceLoginMiddleware',]

# If True, detailed exception will be displayed on errors. Performance and security impact.
DEBUG = False
Expand Down
14 changes: 12 additions & 2 deletions MAGE/project_middleware.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from django.core.cache import cache

from ref.models import Project

"""A very simple middleware which adds a 'project' argument to the view call and template context if the argument 'project_id' was given. Factorizes stupid code, including global cache."""
class ProjectFromProjectIdMiddleware:
"""A very simple middleware which adds a 'project' argument to the view call and template context if the argument 'project_id' was given. Factorizes stupid code, including global cache."""
def __init__(self, get_response):
self.get_response = get_response

Expand All @@ -10,7 +12,15 @@ def __call__(self, request):

def process_view(self, request, view_func, view_args, view_kwargs):
if not 'project' in view_kwargs and 'project_id' in view_kwargs and view_kwargs['project_id']:
request.project = Project.objects.get(pk = view_kwargs['project_id'])
id = view_kwargs['project_id']
request.project = cache.get(f'project_{id}')

if not request.project:
try:
request.project = Project.objects.get(pk = id)
except (Project.DoesNotExist,ValueError):
request.project = Project.objects.get(name = id)
cache.set(f'project_{id}', request.project, 3600)

if 'project_id' in view_kwargs:
del view_kwargs['project_id']
Expand Down
14 changes: 6 additions & 8 deletions MAGE/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def getenv(environment_variable, default=''):

BASE_DIR = os.path.dirname(os.path.dirname(__file__))

DEBUG = getenv('DEBUG', False)
DEBUG = getenv('DJANGO_DEBUG', False)
TEMPLATE_DEBUG = DEBUG

ADMINS = ()
Expand All @@ -21,7 +21,7 @@ def getenv(environment_variable, default=''):
DATABASES = {
'default': {
'ENGINE': getenv('DATABASE_ENGINE', 'django.db.backends.sqlite3'), # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
'NAME': getenv('DATABASE_NAME', os.path.join(BASE_DIR, r'tmp\db.sqlite')), # Or path to database file if using sqlite3.
'NAME': getenv('DATABASE_NAME', os.path.join(BASE_DIR, 'tmp/db.sqlite')), # Or path to database file if using sqlite3.
# The following settings are not used with sqlite3:
'USER': getenv('DATABASE_USER', ''),
'PASSWORD': getenv('DATABASE_PASSWORD', ''),
Expand All @@ -36,9 +36,9 @@ def getenv(environment_variable, default=''):

# Hosts/domain names that are valid for this site; required if DEBUG is False
# See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts
ALLOWED_HOSTS = [getenv('ALLOWED_HOSTS', '*')]
ALLOWED_HOSTS = getenv('DJANGO_ALLOWED_HOSTS', '*').split(',')

INTERNAL_IPS = [ getenv('INTERNAL_IPS', '127.0.0.1'), ]
INTERNAL_IPS = [ getenv('DJANGO_INTERNAL_IPS', '127.0.0.1'), ]

# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
Expand Down Expand Up @@ -90,7 +90,7 @@ def getenv(environment_variable, default=''):
)

# Make this unique, and don't share it with anybody. (overloaded in local settings)
SECRET_KEY = getenv('SECRET_KEY', 'your_own_here')
SECRET_KEY = getenv('DJANGO_SECRET_KEY', 'your_own_here')

LOCAL_MIDDLEWARE = []
MIDDLEWARE = [
Expand All @@ -104,8 +104,6 @@ def getenv(environment_variable, default=''):
# Uncomment the next line for simple clickjacking protection:
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
MIDDLEWARE_CLASSES = []
LOCAL_MIDDLEWARE_CLASSES = []

ROOT_URLCONF = 'MAGE.urls'

Expand Down Expand Up @@ -187,6 +185,7 @@ def getenv(environment_variable, default=''):
}
}

DEFAULT_PROJECT_ID = None
LOCAL_APPS = []
try:
from MAGE.local_settings import *
Expand All @@ -211,4 +210,3 @@ def getenv(environment_variable, default=''):

INSTALLED_APPS += LOCAL_APPS
MIDDLEWARE += LOCAL_MIDDLEWARE
MIDDLEWARE_CLASSES += LOCAL_MIDDLEWARE_CLASSES
2 changes: 1 addition & 1 deletion MAGE/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# coding: utf-8
'''
@license: Apache License, Version 2.0
@copyright: 2007-2013 Marc-Antoine Gouillart
@copyright: 2007-2022 Marc-Antoine Gouillart
@author: Marc-Antoine Gouillart
'''

Expand Down
2 changes: 1 addition & 1 deletion NOTICE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Oxymores MAGE
Copyright 2007-2014 Marc-Antoine Gouillart
Copyright 2007-2022 Marc-Antoine Gouillart

This software uses the web framework (and much else) Django, which is open
source software under a BSD license. The original software is available from
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ Ce framework couvre donc les aspects suivants :
* Transverse
* Gestion simple des habilitations, avec de base seulement trois rôles clairs (toute cette gestion pouvant être finement adaptée à tous les besoins si nécessaire)
* L'authentification peut être déléguée à un serveur LDAP

Un début de documentation est disponible [ici](https://mage.readthedocs.io/)
4 changes: 2 additions & 2 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

## Project data
project = 'MAGE'
copyright = '2008-2014, Marc-Antoine Gouillart'
release = '6.1'
copyright = '2008-2022, Marc-Antoine Gouillart'
release = '6.2'
language = 'en'

## HTML options
Expand Down
10 changes: 10 additions & 0 deletions doc/diagrams.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Development help: model diagrams
#######################################

These two diagrams are developer helpers.

.. image:: ./media/scm.png
:alt: a view centered on the main SCM classes

.. image:: ./media/full.png
:alt: Full schema of all models
11 changes: 7 additions & 4 deletions doc/html.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
if (! (Test-Path .\html ))
if (! (Test-Path $PSScriptRoot/html ))
{
mkdir .\html
mkdir $PSScriptRoot/html
}
C:\Python27\Scripts\sphinx-build.exe -a -b html . html
Read-Host # allows to read errors
& sphinx-build.exe -a -b html $PSScriptRoot $PSScriptRoot/html

# For updating the class diagrams with django_extensions enabled
# python .\manage.py graph_models --pydot -g -o ./doc/media/full.png scm ref
# python .\manage.py graph_models --pydot -g -o ./doc/media/scm.png --include-models InstallableSet,InstallableItem,LogicalComponentVersion,InstallationMethod,Installation,ComponentInstanceConfiguration,LogicalComponentVersion,Application,Project,ComponentInstance,Environment,LogicalComponent,ComponentImplementationClass scm ref
3 changes: 1 addition & 2 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,4 @@ Contents
mql
conventions
security


diagrams
Binary file added doc/media/full.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/media/scm.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 3 additions & 4 deletions doc/starting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ actually) between the CIC and the LC is very important.
.. py:attribute:: ComponentImplementationClass.name
.. py:attribute:: ComponentImplementationClass.description
The description object that will be used to actually instantiate the CIC. See above.

.. py:attribute:: ComponentImplementationClass.implements
Expand All @@ -134,9 +136,6 @@ actually) between the CIC and the LC is very important.
An optional :py:class:`SLA` object

.. py:attribute:: ComponentImplementationClass.description
The description object that will be used to actually instantiate the CIC. See above.

Environments
***********************
Expand Down Expand Up @@ -227,7 +226,7 @@ The component instance is described by the :py:attr:`ComponentImplementationClas

.. py:attribute:: instantiates
The :py:class:`ComponentImplementationClass` implemented.
The :py:class:`ComponentImplementationClass` implemented. It is optional - not all component instances need to be version tracked.

.. py:attribute:: deleted
Expand Down

0 comments on commit d3e65d1

Please sign in to comment.