Parcourir la source

Add of django app

Jérôme BUISINE il y a 4 ans
Parent
commit
a1aefe8097

+ 3 - 0
.vscode/settings.json

@@ -0,0 +1,3 @@
+{
+    "python.pythonPath": "/home/jbuisine/.pyenv/versions/django-web/bin/python"
+}

+ 12 - 0
README.md

@@ -4,6 +4,12 @@
 
 Project for generating users links in order to launch SIN3D application quickly during experiment.
 
+## Requirements
+
+```
+pip install -r requirements.txt
+```
+
 ## How to use ?
 
 
@@ -25,6 +31,12 @@ link1;link2;...;linkN
 link2;link3;...;linkN
 ```
 
+## Launch WebApp
+
+```
+python manage.py runserver
+```
+
 ## Licence
 
 [The MIT license](LICENSE)

+ 2 - 2
config.py

@@ -10,5 +10,5 @@ experiment_list = [
 
 default_host = 'https://diran.univ-littoral.fr'
 
-links_data_folder = 'data'
-expe_data_folder  = 'expe'
+links_data_folder = 'media/data'
+expe_data_folder  = 'media/expe'

+ 0 - 0
launcher/__init__.py


+ 128 - 0
launcher/settings.py

@@ -0,0 +1,128 @@
+"""
+Django settings for launcher project.
+
+Generated by 'django-admin startproject' using Django 2.2.4.
+
+For more information on this file, see
+https://docs.djangoproject.com/en/2.2/topics/settings/
+
+For the full list of settings and their values, see
+https://docs.djangoproject.com/en/2.2/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/2.2/howto/deployment/checklist/
+
+# SECURITY WARNING: keep the secret key used in production secret!
+SECRET_KEY = 'a(wm02y7+q^voeqj9i8w&9*ryvtn0gg3bo$-k=()oz!8+5_okg'
+
+# SECURITY WARNING: don't run with debug turned on in production!
+DEBUG = True
+
+ALLOWED_HOSTS = []
+
+
+# Application definition
+
+INSTALLED_APPS = [
+    'django.contrib.admin',
+    'django.contrib.auth',
+    'django.contrib.contenttypes',
+    'django.contrib.sessions',
+    'django.contrib.messages',
+    'django.contrib.staticfiles',
+    'links'
+]
+
+MIDDLEWARE = [
+    'django.middleware.security.SecurityMiddleware',
+    'django.contrib.sessions.middleware.SessionMiddleware',
+    'django.middleware.common.CommonMiddleware',
+    'django.middleware.csrf.CsrfViewMiddleware',
+    'django.contrib.auth.middleware.AuthenticationMiddleware',
+    'django.contrib.messages.middleware.MessageMiddleware',
+    'django.middleware.clickjacking.XFrameOptionsMiddleware',
+]
+
+ROOT_URLCONF = 'launcher.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 = 'launcher.wsgi.application'
+
+
+# Database
+# https://docs.djangoproject.com/en/2.2/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/2.2/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/2.2/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/2.2/howto/static-files/
+
+STATIC_URL = '/static/'
+
+STATICFILES_DIRS = (
+    os.path.join(BASE_DIR, 'static'),
+)
+
+MEDIA_ROOT = "media/"
+MEDIA_URL = "media/"

+ 22 - 0
launcher/urls.py

@@ -0,0 +1,22 @@
+"""launcher URL Configuration
+
+The `urlpatterns` list routes URLs to views. For more information please see:
+    https://docs.djangoproject.com/en/2.2/topics/http/urls/
+Examples:
+Function views
+    1. Add an import:  from my_app import views
+    2. Add a URL to urlpatterns:  path('', views.home, name='home')
+Class-based views
+    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, include
+
+urlpatterns = [
+    path('admin/', admin.site.urls),
+    path('', include('links.urls', namespace='links')),
+]

+ 16 - 0
launcher/wsgi.py

@@ -0,0 +1,16 @@
+"""
+WSGI config for launcher 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/2.2/howto/deployment/wsgi/
+"""
+
+import os
+
+from django.core.wsgi import get_wsgi_application
+
+os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'launcher.settings')
+
+application = get_wsgi_application()

+ 0 - 0
links/__init__.py


+ 3 - 0
links/admin.py

@@ -0,0 +1,3 @@
+from django.contrib import admin
+
+# Register your models here.

+ 5 - 0
links/apps.py

@@ -0,0 +1,5 @@
+from django.apps import AppConfig
+
+
+class LinksConfig(AppConfig):
+    name = 'links'

+ 0 - 0
links/migrations/__init__.py


+ 3 - 0
links/models.py

@@ -0,0 +1,3 @@
+from django.db import models
+
+# Create your models here.

+ 35 - 0
links/templates/base.html

@@ -0,0 +1,35 @@
+<!DOCTYPE html>
+<html lang="fr">
+<head>
+    <meta charset="UTF-8"/>
+    <title>
+        {% block title %}
+
+        {% endblock %}
+    </title>
+
+    {% load staticfiles %}
+    
+    {% block stylesheets %}
+        <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
+        <link rel="stylesheet" type="text/css" href="{% static "css/links.css" %}">
+        <script src="https://kit.fontawesome.com/ee9d97bd14.js" crossorigin="anonymous"></script>
+    {% endblock %}
+</head>
+<body>
+
+    <div class="container">
+        {% block content %}
+            
+        {% endblock %}
+    </div>
+
+    <!-- Global scripts used -->
+    <script type="text/javascript"> 
+    </script>
+
+    <!-- Custom Javascript file for experiments template is placed here -->
+    {% block javascripts %}
+        
+    {% endblock %}
+</body>

+ 16 - 0
links/templates/links/files.html

@@ -0,0 +1,16 @@
+{% extends 'base.html' %}
+
+{% load staticfiles %}
+
+{% block title %}
+    List of files
+{% endblock %}
+
+{% block content %}
+
+    We will display list of files here
+
+    {% block javascripts %}
+ 
+    {% endblock %}
+{% endblock %}

+ 3 - 0
links/tests.py

@@ -0,0 +1,3 @@
+from django.test import TestCase
+
+# Create your tests here.

+ 15 - 0
links/urls.py

@@ -0,0 +1,15 @@
+from django.contrib import admin
+from django.urls import path
+from django.conf import settings
+from django.conf.urls.static import static
+
+from . import views
+
+app_name = 'expe'
+
+urlpatterns = [
+    path('', views.list_files, name='list_files'),
+]
+
+if settings.DEBUG is True:
+    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

+ 26 - 0
links/views.py

@@ -0,0 +1,26 @@
+# django imports
+from django.shortcuts import render
+from django.http import HttpResponse
+from django.conf import settings
+from django.contrib.auth.decorators import login_required
+from django.http import Http404
+
+# main imports
+import os
+
+
+def list_files(request):
+
+    # get param 
+    # TODO : implement view which list all expe links file
+
+    data = {
+
+    }
+
+    return render(request, 'links/files.html', data)
+
+
+
+
+

+ 21 - 0
manage.py

@@ -0,0 +1,21 @@
+#!/usr/bin/env python
+"""Django's command-line utility for administrative tasks."""
+import os
+import sys
+
+
+def main():
+    os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'launcher.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)
+
+
+if __name__ == '__main__':
+    main()

+ 3 - 0
requirements.txt

@@ -0,0 +1,3 @@
+Django
+numpy
+requests

+ 3 - 0
static/css/links.css

@@ -0,0 +1,3 @@
+body {
+    background-color: lightgrey;
+}