Commit 38c28ce6 authored by Sylvain Coulange's avatar Sylvain Coulange
Browse files

new player (comptes users, bdd distante, createSerie)

parent 2e862399
from django.contrib import admin
from .models import Serie
# Register your models here.
admin.site.register(Serie)
\ No newline at end of file
# Generated by Django 3.0.5 on 2020-11-05 10:21
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name='Serie',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('dateCreation', models.DateTimeField(auto_now_add=True)),
('dateModification', models.DateTimeField(auto_now=True)),
('nom', models.CharField(max_length=100, null=True)),
('description', models.TextField(max_length=300)),
('auteur', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL)),
],
),
]
from django.db import models
from djongo import models
from django.contrib.auth.models import User
class Serie(models.Model):
dateCreation = models.DateTimeField(auto_now_add=True, auto_now=False)
dateModification = models.DateTimeField(auto_now_add=False, auto_now=True)
nom = models.CharField(max_length=100)
description = models.TextField(max_length=300)
auteur = models.ForeignKey(User, on_delete=models.PROTECT)
mots = models.CharField(max_length=10000)
def __str__(self):
return self.nom
# class Mot(models.Model):
# motGenerique = models.CharField(max_length=100) # "chat"
# phono = models.CharField(max_length=1000) # ["phon_s_maj","phon_a"]
# audio = models.CharField(max_length=500) # "s0_chat.mp3"
# image = models.CharField(max_length=500) # "s0_chat.jpg"
# phonographies = models.CharField(max_length=3000) # liste d'objets Phonographie() (une ortho, un alignement phonographique)
\ No newline at end of file
from django.shortcuts import render, HttpResponseRedirect
from django.http import JsonResponse
import subprocess
import json
import os
import tempfile
from .models import Serie
from django.forms.models import model_to_dict
import subprocess, json, os, tempfile
### Chargement de la base de données
dbFile = '../db/db_phonographe.json'
......@@ -109,26 +108,34 @@ def save2db(request):
def openPlayerHome(request):
updateTimeStr = updateTime()
allseries = json.dumps(dbActivities)
return render(request, 'playerHome.html', {'updateTime': updateTimeStr, 'allseries':allseries})
#allseries = json.dumps(dbActivities)
series = Serie.objects.all()
seriesJson = {}
for serie in Serie.objects.all():
seriesJson[serie.id] = model_to_dict(serie)
seriesJson = json.dumps(seriesJson)
return render(request, 'playerHome.html', {'updateTime': updateTimeStr, 'series': series, 'seriesJson': seriesJson})
def openPlayerPhono(request, serieId):
updateTimeStr = updateTime()
serieContent = json.dumps(dbActivities[serieId])
#serieContent = json.dumps(dbActivities[serieId])
serieContent = json.dumps(model_to_dict(Serie.objects.filter(id=serieId).first()))
print(serieContent)
print("Demande ouverture série",serieId)
return render(request, 'playerPhono.html', {'updateTime': updateTimeStr, 'serieContent':serieContent})
def getActivity(request):
colis = json.loads(request.body)
serieIdreq = colis[serieId-request]
print(serieIdreq)
serieContent = dbActivities[serieIdreq]
return JsonResponse(serieContent)
# def getActivity(request):
# colis = json.loads(request.body)
# serieIdreq = colis[serieId-request]
# print(serieIdreq)
# serieContent = dbActivities[serieIdreq]
# return JsonResponse(serieContent)
def openSwitchStress(request):
updateTimeStr = updateTime()
return render(request, 'playerSwitchStress.html', {'updateTime': updateTimeStr})
# def openSwitchStress(request):
# updateTimeStr = updateTime()
# return render(request, 'playerSwitchStress.html', {'updateTime': updateTimeStr})
def getActivitySwitchStress(request):
activity = dbActivitiesSwitchStress["serie0"]
return JsonResponse(activity)
\ No newline at end of file
# def getActivitySwitchStress(request):
# activity = dbActivitiesSwitchStress["serie0"]
# return JsonResponse(activity)
\ No newline at end of file
......@@ -39,6 +39,8 @@ CSRF_TRUSTED_ORIGINS = [
# Application definition
INSTALLED_APPS = [
'users.apps.UsersConfig',
'crispy_forms',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
......@@ -84,14 +86,25 @@ WSGI_APPLICATION = 'clavierPhono.wsgi.application'
# Database
# https://docs.djangoproject.com/en/2.1/ref/settings/#databases
# DATABASES = {
# 'default': {
# 'ENGINE': 'django.db.backends.sqlite3',
# 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
# }
# }
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
'ENGINE': 'djongo',
'CLIENT': {
"name": "alem-app_db",
"host": "mongodb+srv://alemadmin:9bO8Uzf3zMswb1gL@cluster0.6nopd.mongodb.net/alem-app_db?retryWrites=true&w=majority",
"username": "alemadmin",
"password": "9bO8Uzf3zMswb1gL",
"authMechanism": "SCRAM-SHA-1",
},
}
}
# Password validation
# https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators
......@@ -133,4 +146,9 @@ STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static')
]
STATIC_ROOT = os.path.join(BASE_DIR, 'assets')
\ No newline at end of file
STATIC_ROOT = os.path.join(BASE_DIR, 'assets')
CRISPY_TEMPLATE_PACK = 'bootstrap4'
LOGIN_REDIRECT_URL = 'home'
LOGIN_URL = 'login'
\ No newline at end of file
......@@ -15,21 +15,31 @@ Including another URLconf
"""
from django.contrib import admin
from django.urls import path
from clavier.views import newPage, save2db, loadPage, getPageContent, openPlayerPhono, getActivity, openSwitchStress, getActivitySwitchStress, openPlayerHome
from django.contrib.auth import views as auth_views
from clavier import views as clavier_views
from users import views as user_views
from django.views.decorators.csrf import csrf_exempt
urlpatterns = [
path('admin/', admin.site.urls),
path('', newPage),
path('fr/', newPage),
path('en/', newPage),
path('id-<str:pageId>/', loadPage),
path('id-<str:pageId>/page', getPageContent),
path('<str:pageLang>/id-<str:pageId>/', loadPage),
path('export/', csrf_exempt(save2db)),
path('player/', openPlayerHome),
path('player/<str:serieId>', openPlayerPhono),
path('getActivity/', csrf_exempt(getActivity)),
path('switchstress/', openSwitchStress),
path('getActivitySwitchStress/', csrf_exempt(getActivitySwitchStress))
path('register/', user_views.register, name='register'),
path('login/', auth_views.LoginView.as_view(template_name="users/login.html"), name='login'),
path('logout/', auth_views.LogoutView.as_view(template_name="users/logout.html"), name='logout'),
path('profile/', user_views.profile, name='profile'),
path('', clavier_views.newPage),
path('fr/', clavier_views.newPage),
path('en/', clavier_views.newPage),
path('id-<str:pageId>/', clavier_views.loadPage),
path('id-<str:pageId>/page', clavier_views.getPageContent),
path('<str:pageLang>/id-<str:pageId>/', clavier_views.loadPage),
path('export/', csrf_exempt(clavier_views.save2db)),
path('player/', clavier_views.openPlayerHome, name='home'),
path('player/<str:serieId>', clavier_views.openPlayerPhono),
path('player/createSerie/', user_views.createSerie),
# path('getActivity/', csrf_exempt(clavier_views.getActivity)),
# path('switchstress/', clavier_views.openSwitchStress),
# path('getActivitySwitchStress/', csrf_exempt(clavier_views.getActivitySwitchStress))
]
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment