first commit

Change-Id: I8a65ee5527dd16d81e87c8ac5d4bdb471e5e759d
Signed-off-by: lombardof <flombardo@cnit.it>
diff --git a/sf_t3d/__init__.py b/sf_t3d/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/sf_t3d/__init__.py
diff --git a/sf_t3d/context_processor.py b/sf_t3d/context_processor.py
new file mode 100644
index 0000000..d554515
--- /dev/null
+++ b/sf_t3d/context_processor.py
@@ -0,0 +1,10 @@
+from django.conf import settings  # import the settings file
+
+
+def conf_constants(request):
+    # return the value you want as a dictionnary. you may add multiple values in there.
+    return {
+        'SITE_NAME': settings.SITE_NAME,
+        'SHORT_SITE_NAME': settings.SHORT_SITE_NAME,
+        'VERSION': settings.VERSION,
+    }
\ No newline at end of file
diff --git a/sf_t3d/settings.py b/sf_t3d/settings.py
new file mode 100644
index 0000000..1020acd
--- /dev/null
+++ b/sf_t3d/settings.py
@@ -0,0 +1,168 @@
+"""
+Django settings for sf_t3d project.
+
+Generated by 'django-admin startproject' using Django 1.9.
+
+For more information on this file, see
+https://docs.djangoproject.com/en/1.9/topics/settings/
+
+For the full list of settings and their values, see
+https://docs.djangoproject.com/en/1.9/ref/settings/
+"""
+
+import os
+
+# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
+BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
+
+
+# Quick-start development settings - unsuitable for production
+# See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/
+
+# SECURITY WARNING: keep the secret key used in production secret!
+SECRET_KEY = 'o5+o2jv(3-dqr(&ia#-@79cgr%xi*s+6xjws^8cxp211ge#buf'
+
+# SECURITY WARNING: don't run with debug turned on in production!
+DEBUG = True
+
+ALLOWED_HOSTS = []
+
+AUTH_USER_MODEL = "sf_user.CustomUser"
+
+SITE_NAME = "OSM Light Weight"
+SHORT_SITE_NAME = "OSM-LW-UI"
+
+LOGIN_URL = '/auth/'
+LOGOUT_URL = '/auth/'
+
+VERSION = "0.0.1"
+
+
+# Application definition
+INSTALLED_APPS = [
+    'django.contrib.admin',
+    'django.contrib.auth',
+    'django.contrib.contenttypes',
+    'django.contrib.messages',
+    'django.contrib.staticfiles',
+    'sf_user',
+    'projecthandler',
+    'vimhandler',
+    'instancehandler'
+]
+
+MIDDLEWARE_CLASSES = [
+    'django.middleware.security.SecurityMiddleware',
+    'django.contrib.sessions.middleware.SessionMiddleware',
+    'django.middleware.common.CommonMiddleware',
+    'django.middleware.csrf.CsrfViewMiddleware',
+    'django.contrib.auth.middleware.AuthenticationMiddleware',
+    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
+    'django.contrib.messages.middleware.MessageMiddleware',
+    'django.middleware.clickjacking.XFrameOptionsMiddleware',
+
+]
+
+SESSION_ENGINE='sf_user.sessions'
+SESSION_COOKIE_AGE = 3500 #25 min
+SESSION_EXPIRE_AT_BROWSER_CLOSE = True
+SESSION_SAVE_EVERY_REQUEST = True
+
+ROOT_URLCONF = 'sf_t3d.urls'
+
+TEMPLATES = [
+    {
+        'BACKEND': 'django.template.backends.django.DjangoTemplates',
+        'DIRS': [
+            os.path.join(BASE_DIR, 'template'),
+            os.path.join(BASE_DIR, 'projecthandler', 'template'),
+            os.path.join(BASE_DIR, 'projecthandler', 'template', 'download'),
+            os.path.join(BASE_DIR, 'projecthandler', 'template', 'project'),
+            os.path.join(BASE_DIR, 'vimhandler', 'template'),
+            os.path.join(BASE_DIR, 'instancehandler', 'template'),
+        ],
+        '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',
+                'sf_t3d.context_processor.conf_constants',
+            ],
+            'libraries':{
+                'get': 'sf_t3d.templatetags.get',
+
+            }
+        },
+    },
+]
+
+WSGI_APPLICATION = 'sf_t3d.wsgi.application'
+
+
+# Database
+# https://docs.djangoproject.com/en/1.9/ref/settings/#databases
+
+DATABASES = {
+    'default': {
+        'ENGINE': 'django.db.backends.sqlite3',
+        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
+    }
+}
+
+
+# Password validation
+# https://docs.djangoproject.com/en/1.9/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',
+    },
+]
+
+
+# Internationalization
+# https://docs.djangoproject.com/en/1.9/topics/i18n/
+
+LANGUAGE_CODE = 'en-us'
+
+TIME_ZONE = 'UTC'
+
+USE_I18N = True
+
+USE_L10N = True
+
+USE_TZ = True
+
+
+# Static files (CSS, JavaScript, Images)
+# https://docs.djangoproject.com/en/1.9/howto/static-files/
+
+STATIC_URL = '/static/'
+
+STATICFILES_FINDERS = (
+    'django.contrib.staticfiles.finders.FileSystemFinder',
+    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
+    'django.contrib.staticfiles.finders.DefaultStorageFinder'
+)
+
+STATICFILES_DIRS = (
+    # Put strings here, like "/home/html/static" or "C:/www/django/static".
+    # Always use forward slashes, even on Windows.
+    # Don't forget to use absolute paths, not relative paths.
+    os.path.join(BASE_DIR, "static"),
+)
+
+LOCALE_PATHS = (
+    os.path.join(BASE_DIR, 'locale'),
+)
\ No newline at end of file
diff --git a/sf_t3d/templatetags/__init__.py b/sf_t3d/templatetags/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/sf_t3d/templatetags/__init__.py
diff --git a/sf_t3d/templatetags/get.py b/sf_t3d/templatetags/get.py
new file mode 100644
index 0000000..80d3695
--- /dev/null
+++ b/sf_t3d/templatetags/get.py
@@ -0,0 +1,37 @@
+#
+#   Copyright 2018 CNIT - Consorzio Nazionale Interuniversitario per le Telecomunicazioni
+#
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an  BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+#
+
+from django import template
+register = template.Library()
+
+'''
+    Custom template filter 
+'''
+@register.filter
+def get(mapping, key):
+    result = mapping.get(key, '')
+    return result
+
+'''
+    Custom template filter 
+'''
+@register.filter
+def get_sub(mapping, args):
+    splitted = args.split(',')
+    sub_dict = mapping.get(splitted[0], '')
+    if isinstance(sub_dict, dict):
+        return sub_dict.get(splitted[1], '')
+    return ''
diff --git a/sf_t3d/urls.py b/sf_t3d/urls.py
new file mode 100644
index 0000000..0784ed1
--- /dev/null
+++ b/sf_t3d/urls.py
@@ -0,0 +1,35 @@
+"""sf_t3d URL Configuration
+
+The `urlpatterns` list routes URLs to views. For more information please see:
+    https://docs.djangoproject.com/en/1.9/topics/http/urls/
+Examples:
+Function views
+    1. Add an import:  from my_app import views
+    2. Add a URL to urlpatterns:  url(r'^$', views.home, name='home')
+Class-based views
+    1. Add an import:  from other_app.views import Home
+    2. Add a URL to urlpatterns:  url(r'^$', Home.as_view(), name='home')
+Including another URLconf
+    1. Add an import:  from blog import urls as blog_urls
+    2. Import the include() function: from django.conf.urls import url, include
+    3. Add a URL to urlpatterns:  url(r'^blog/', include(blog_urls))
+"""
+from django.conf.urls import url, include
+from django.contrib import admin
+from sf_user import views as user_views
+from sf_t3d import views
+
+app_name = 'base'
+urlpatterns = [
+    url(r'^admin/', admin.site.urls),
+    url(r'^auth/$', user_views.login_view, name='auth_user'),
+    url(r'^auth_guest/$', user_views.guest_login, name='auth_user_guest'),
+    url(r'^register', user_views.register_view, name='register_user'),
+    url(r'^projects/', include('projecthandler.urls.project', namespace='projects'), name='projects_base'),
+    url(r'^vims/', include('vimhandler.urls', namespace='vim'), name='vims_base'),
+
+    url(r'^$', views.home, name='home'),
+    url(r'^home', views.home, name='home'),
+    url(r'^forbidden', views.forbidden, name='forbidden'),
+
+]
diff --git a/sf_t3d/views.py b/sf_t3d/views.py
new file mode 100644
index 0000000..91590f0
--- /dev/null
+++ b/sf_t3d/views.py
@@ -0,0 +1,22 @@
+from django.shortcuts import render
+from django.contrib.auth.decorators import login_required
+
+from projecthandler.models import Project
+from sf_user.models import CustomUser
+
+
+@login_required
+def home(request):
+    user = CustomUser.objects.get(id=request.user.id)
+    projects = Project.objects.filter(owner=user).select_subclasses()
+    result = {
+        'projects': len(projects) if projects else 0,
+    }
+    return render(request, 'home.html', result)
+
+
+def forbidden(request):
+    return render(request, 'forbidden.html')
+
+
+
diff --git a/sf_t3d/wsgi.py b/sf_t3d/wsgi.py
new file mode 100644
index 0000000..c52ee6f
--- /dev/null
+++ b/sf_t3d/wsgi.py
@@ -0,0 +1,16 @@
+"""
+WSGI config for sf_t3d project.
+
+It exposes the WSGI callable as a module-level variable named ``application``.
+
+For more information on this file, see
+https://docs.djangoproject.com/en/1.9/howto/deployment/wsgi/
+"""
+
+import os
+
+from django.core.wsgi import get_wsgi_application
+
+os.environ.setdefault("DJANGO_SETTINGS_MODULE", "sf_t3d.settings")
+
+application = get_wsgi_application()