Commit 70cd185c authored by Martin Lehoux's avatar Martin Lehoux

Merge branch 'dev' into 'master'

Dev

See merge request !34
parents cfeefbfa 07d27767
This diff is collapsed.
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from .models import CourseComment,DocumentComment,Course,User,Teacher,Document,CourseLike,DocumentLike
from .models import CourseComment, DocumentComment, Course, User, Teacher, Document, CourseLike, DocumentLike
# Register your models here.
admin.site.register(DocumentComment)
......
......@@ -14,15 +14,15 @@ class PostCourseCommentForm(forms.ModelForm):
class PostDocumentForm(forms.ModelForm):
class Meta:
model = Document
fields=['name','course','file','description','type','documentDate','correction']
fields = ['name', 'course', 'file', 'description', 'type', 'documentDate', 'correction']
class PostCourseForm(forms.ModelForm):
class Meta:
model = Course
fields=['name','type',"year",'description']
fields = ['name', 'type', "year", 'description']
class PostTeacherForm(forms.ModelForm):
class Meta:
model = Teacher
fields = ['firstName','lastName','email','department','office']
fields = ['firstName', 'lastName', 'email', 'department', 'office']
\ No newline at end of file
from django.shortcuts import redirect
from django.http import HttpResponseRedirect
import requests
import time
import datetime
from .models import User
from django.core import serializers
class CGUMiddleware:
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request):
if request.path in ['/legal','/accept_CGU', '/auth/login']:
if request.path in ['/legal', '/accept_CGU', '/auth/login']:
# Middleware default allowed pages
return self.get_response(request)
if request.user.is_anonymous:
......@@ -20,7 +14,6 @@ class CGUMiddleware:
if request.user.hasAcceptedCGU:
# Let people go if they accepted CGU
return self.get_response(request)
else:
return HttpResponseRedirect('/legal')
class MessagesMiddleware:
......
......@@ -7,19 +7,19 @@ class Course(models.Model):
year = models.CharField(
max_length=2,
choices=(
('1A','1A'),
('2A','2A'),
('3A','3A'),
('1A', '1A'),
('2A', '2A'),
('3A', '3A'),
),
null=True,
)
description = models.CharField(max_length=10000,null=True,blank=True)
teachers = models.ManyToManyField('Teacher',blank=True)
description = models.CharField(max_length=10000, null=True, blank=True)
teachers = models.ManyToManyField('Teacher', blank=True)
type = models.CharField(
max_length=50,
choices=(
('Tronc commun','Tronc commun'),
('Electif','Electif'),
('Tronc commun', 'Tronc commun'),
('Electif', 'Electif'),
),
null=True,
)
......@@ -31,21 +31,22 @@ class Course(models.Model):
class Document(models.Model):
name = models.CharField(max_length=200)
documentDate = models.DateField()
description = models.CharField(max_length=10000,null=False,blank=True)
description = models.CharField(max_length=10000, null=False, blank=True)
isAccepted = models.BooleanField(default=False)
user = models.ForeignKey('User', on_delete=models.SET_NULL,null=True,blank=True)
course = models.ForeignKey('Course',on_delete=models.SET_NULL,null=True,blank=True)
user = models.ForeignKey('User', on_delete=models.SET_NULL, null=True, blank=True)
course = models.ForeignKey('Course', on_delete=models.SET_NULL, null=True, blank=True)
file = models.FileField(upload_to='')
correction = models.FileField(upload_to='corrections/', blank=True, null=True)
type = models.CharField(
max_length=50,
choices=(
('Annale','Annale'),
('Fiche','Fiche'),
('Poly de cours','Poly de cours'),
('Annale', 'Annale'),
('Fiche', 'Fiche'),
('Poly de cours', 'Poly de cours'),
('Notes de cours', 'Notes de cours'),
),
null=True)
null=True
)
def __str__(self):
return self.name
......@@ -55,8 +56,8 @@ class DocumentComment(models.Model):
content = models.CharField(max_length=10000)
commentDate = models.DateTimeField()
isModerated = models.BooleanField(default=False)
user = models.ForeignKey('User',on_delete=models.CASCADE,null=True,blank=True)
document = models.ForeignKey('Document',on_delete=models.CASCADE)
user = models.ForeignKey('User', on_delete=models.CASCADE, null=True, blank=True)
document = models.ForeignKey('Document', on_delete=models.CASCADE)
def __str__(self):
return str(self.commentDate)
......@@ -66,19 +67,19 @@ class CourseComment(models.Model):
content = models.CharField(max_length=10000)
commentDate = models.DateTimeField()
isModerated = models.BooleanField(default=False)
user = models.ForeignKey('User',on_delete=models.CASCADE,null=True,blank=True)
course = models.ForeignKey('Course',on_delete=models.CASCADE)
user = models.ForeignKey('User', on_delete=models.CASCADE, null=True, blank=True)
course = models.ForeignKey('Course', on_delete=models.CASCADE)
def __str__(self):
return str(self.commentDate)
class Teacher(models.Model):
firstName = models.CharField(max_length=50,null=True,blank=True)
firstName = models.CharField(max_length=50, null=True, blank=True)
lastName = models.CharField(max_length=50)
email = models.EmailField(max_length=100,null=True,blank=True)
department = models.CharField(max_length=50,null=True,blank=True)
office = models.CharField(max_length=50,null=True,blank=True)
email = models.EmailField(max_length=100, null=True, blank=True)
department = models.CharField(max_length=50, null=True, blank=True)
office = models.CharField(max_length=50, null=True, blank=True)
isAccepted = models.BooleanField(default=False)
def __str__(self):
......@@ -115,16 +116,16 @@ User._meta.get_field('last_login').verbose_name = "Dernière connexion"
User._meta.get_field('date_joined').verbose_name = "Première connexion"
class CourseLike(models.Model):
user = models.ForeignKey('User',on_delete=models.CASCADE)
course = models.ForeignKey('Course',on_delete=models.CASCADE)
user = models.ForeignKey('User', on_delete=models.CASCADE)
course = models.ForeignKey('Course', on_delete=models.CASCADE)
def __str__(self):
return str(self.user) + " aime " + str(self.course)
class DocumentLike(models.Model):
user = models.ForeignKey('User',on_delete=models.CASCADE)
document = models.ForeignKey('Document',on_delete=models.CASCADE)
user = models.ForeignKey('User', on_delete=models.CASCADE)
document = models.ForeignKey('Document', on_delete=models.CASCADE)
def __str__(self):
return str(self.user) + " aime " + str(self.document)
from core.models import User
import requests
from core.models import User
def find_or_create_user(access_token, access_token_payload):
......@@ -25,4 +25,3 @@ def find_or_create_user(access_token, access_token_payload):
user.is_superuser = True
user.save()
return user
......@@ -38,14 +38,16 @@
<i class="ui database icon"></i>
Tes données
</h2>
<div class="ui relaxed divided list">
<table class="ui very basic collapsing celled table">
<tbody>
{% for field, value in data %}
<div class="item content">
<p class="header">{{ field }}</p>
<p class="description">{{ value }}</p>
</div>
<tr>
<td><p class="header">{{ field }}</p></td>
<td><p class="description">{% if value == True %}<i class="ui green check circle icon"></i>{% elif value == False %}<i class="ui red close icon"></i>{% else %}{{ value }}{% endif %}</p></td>
</tr>
{% endfor %}
</div>
</tbody>
</table>
<div class="ui center aligned container">
<button onclick="$('.ui.modal').modal('show')" class="ui red button">Supprimer mon compte</button>
</div>
......
......@@ -10,6 +10,9 @@
<span id="stars">{{ course.like_list|length }}</span>
</div>
</div>
<button id="like" class="ui green right floated icon button"> <i class="thumbs up icon"></i> </button>
<button id="dislike" class="ui red right floated icon button"> <i class="thumbs down icon"></i> </button>
<button id="load" class="ui loading right floated button"> . </button>
</div>
</div>
<div class="content">
......@@ -26,11 +29,6 @@
<p class="ui red label">{{course.year}}</p>
<p class="ui {% if course.type == 'Electif' %}grey{% else %}teal{% endif %} label">{{ course.type }}</p>
</div>
<div class="ui one bottom attached buttons">
<button id="like" class="ui green basic labeled icon fluid button"> <i class="thumbs up icon"></i> J'aime ce cours</button>
<button id="dislike" class="ui red basic labeled icon fluid button"> <i class="thumbs down icon"></i> Je n'aime plus ce cours</button>
<button id="load" class="ui loading fluid button">Loading...</button>
</div>
</div>
</div>
......
......@@ -10,6 +10,9 @@
<span id="stars">{{ document.like_list|length }}</span>
</div>
</div>
<button id="like" class="ui green right floated icon button"> <i class="thumbs up icon"></i></a>
<button id="dislike" class="ui red right floated icon button"> <i class="thumbs down icon"></i></a>
<button id="load" class="ui loading right floated button">.</button>
</div>
{% if document.course.pk != Null %}<div class="meta"><a href="{% url 'core:get_course' document.course.pk %}">{{document.course}}</a></div>{% endif %}
</div>
......@@ -20,12 +23,9 @@
<p class="ui {% if document.type == 'Annale' %}red{% else %}blue{% endif %} label">{{ document.type }}</p>
<p class="ui green label">{{document.documentDate.year}}</p>
</div>
<div class="ui {% if document.type == "Annale" %}three{% else %}two{% endif %} bottom attached buttons">
<div class="ui {% if document.type == "Annale" %}two{% else %}one{% endif %} bottom attached buttons">
<a href="{% url 'core:download_document' document.id %}" class="ui blue basic labeled icon fluid button" target="_new"> <i class="cloud download icon"></i> Sujet</a>
{% if document.type == "Annale" %}<a href="{% url 'core:download_correction' document.id %}" class="ui blue basic labeled icon fluid button" target="_new"> <i class="edit icon"></i> Correction </a>{% endif %}
<button id="like" class="ui green basic icon button"> <i class="thumbs up icon"></i></a>
<button id="dislike" class="ui red basic icon button"> <i class="thumbs down icon"></i></a>
<button id="load" class="ui loading fluid button">Loading...</button>
</div>
</div>
</div>
......
......@@ -49,7 +49,7 @@
</a>
<div class="right menu">
<div class="item">
{% if to_moderate_number != 0 %}
{% if to_moderate_number != 0 and user.is_staff %}
<a class="ui red label" href="{% url 'core:moderation' %}">
<i class="ui bell icon"></i>
{{ to_moderate_number }}
......
from django.test import TestCase
# from django.test import TestCase
# Create your tests here.
from django.urls import path, re_path
from django.urls import path
from . import views
......
import datetime
from django.shortcuts import render, redirect
from .models import Course, Document, User, Teacher, CourseComment, DocumentComment, CourseLike, DocumentLike
from .forms import PostDocumentCommentForm, PostDocumentForm, PostCourseCommentForm, PostCourseForm, PostTeacherForm
import datetime, time
from django.http import HttpResponseRedirect, HttpResponse
import json
from .utils import count_to_moderate
from django.core.exceptions import ObjectDoesNotExist
from django.contrib.auth.decorators import login_required
from django.views.decorators.csrf import csrf_exempt
from django.db.models import Count
from django.contrib.auth import logout
from django.http import HttpResponseRedirect, HttpResponse
from .models import Course, Document, User, Teacher, CourseComment, DocumentComment, CourseLike, DocumentLike
from .forms import PostDocumentCommentForm, PostDocumentForm, PostCourseCommentForm, PostCourseForm, PostTeacherForm
from .utils import count_to_moderate
# Create your views here.
@login_required
......@@ -51,7 +51,7 @@ def home(request):
})
@login_required
def get_document(request,document_id):
def get_document(request, document_id):
# Error is document doesn't exist
try:
document = Document.objects.get(pk=document_id)
......@@ -137,7 +137,7 @@ def post_document_comment(request, document_id):
return get_document(request, document_id)
@login_required
def get_course(request,course_id):
def get_course(request, course_id):
try:
course = Course.objects.get(pk=course_id)
......@@ -266,7 +266,7 @@ def post_document(request):
})
return error(request)
form = PostDocumentForm(request.POST,request.FILES)
form = PostDocumentForm(request.POST, request.FILES)
# Redirect if form not valid
if not form.is_valid():
......@@ -309,7 +309,7 @@ def post_course(request):
return error(request)
# Treat teacher list syntax
if len(request.POST['teacher_list'])>0:
if request.POST['teacher_list']:
teacher_list = [int(x) for x in request.POST['teacher_list'][0].split(',')]
else:
teacher_list = []
......@@ -418,7 +418,7 @@ def moderation(request):
})
@login_required
def accept(request,type,id):
def accept(request, type, id):
# Redirect if user not moderator
if not request.user.is_staff:
request.messages.append({
......@@ -429,7 +429,7 @@ def accept(request,type,id):
return error(request)
# Check object type and set prop to True
if type=='course':
if type == 'course':
try:
course = Course.objects.get(pk=id)
except ObjectDoesNotExist:
......@@ -443,7 +443,7 @@ def accept(request,type,id):
course.isAccepted = True
course.save()
elif type=='document':
elif type == 'document':
try:
document = Document.objects.get(pk=id)
except ObjectDoesNotExist:
......@@ -457,7 +457,7 @@ def accept(request,type,id):
document.isAccepted = True
document.save()
elif type=='document_comment':
elif type == 'document_comment':
try:
comment = DocumentComment.objects.get(pk=id)
except ObjectDoesNotExist:
......@@ -471,7 +471,7 @@ def accept(request,type,id):
comment.isModerated = True
comment.save()
elif type=='course_comment':
elif type == 'course_comment':
try:
comment = CourseComment.objects.get(pk=id)
except ObjectDoesNotExist:
......@@ -485,7 +485,7 @@ def accept(request,type,id):
comment.isModerated = True
comment.save()
elif type=='teacher':
elif type == 'teacher':
try:
teacher = Teacher.objects.get(pk=id)
except ObjectDoesNotExist:
......@@ -510,7 +510,7 @@ def accept(request,type,id):
return moderation(request)
@login_required
def reject(request,type,id):
def reject(request, type, id):
# Check user moderation right
if not request.user.is_staff:
request.messages.append({
......@@ -521,19 +521,19 @@ def reject(request,type,id):
return error(request)
# Check object type and delete it
if type=='course':
if type == 'course':
course = Course.objects.get(pk=id)
course.delete()
elif type=='document':
elif type == 'document':
document = Document.objects.get(pk=id)
document.delete()
elif type=='document_comment':
elif type == 'document_comment':
comment = DocumentComment.objects.get(pk=id)
comment.delete()
elif type=='course_comment':
elif type == 'course_comment':
comment = CourseComment.objects.get(pk=id)
comment.delete()
elif type=='teacher':
elif type == 'teacher':
teacher = Teacher.objects.get(pk=id)
teacher.delete()
else:
......@@ -544,19 +544,18 @@ def reject(request,type,id):
})
return error(request)
return moderation(request)
@login_required
def download_document(request,document_id):
def download_document(request, document_id):
try:
document = Document.objects.get(pk=document_id)
except ObjectDoesNotExist:
return error(request,"Le document que vous souhaitez télécharger n'existe pas")
return error(request, "Le document que vous souhaitez télécharger n'existe pas")
# Redirect if the document is not accepted and the user is not mederator
if not document.isAccepted and not request.user.is_staff:
return error(request,"Vous essayez de télécharger un document non validé, mais vous n'êtes pas modérateur.")
return error(request, "Vous essayez de télécharger un document non validé, mais vous n'êtes pas modérateur.")
response = HttpResponse(content=document.file)
response['Content-Type'] = 'application/pdf'
......@@ -571,11 +570,11 @@ def download_correction(request, document_id):
if not document.correction:
raise ObjectDoesNotExist
except ObjectDoesNotExist:
return error(request,"Le document que vous souhaitez télécharger n'existe pas")
return error(request, "Le document que vous souhaitez télécharger n'existe pas")
# Redirect if the document is not accepted and the user is not mederator
if not document.isAccepted and not request.user.is_staff:
return error(request,"Vous essayez de télécharger un document non validé, mais vous n'êtes pas modérateur.")
return error(request, "Vous essayez de télécharger un document non validé, mais vous n'êtes pas modérateur.")
response = HttpResponse(content=document.correction)
response['Content-Type'] = 'application/pdf'
......@@ -584,12 +583,12 @@ def download_correction(request, document_id):
return response
def error(request,message="Bienvenue sur la page d'affichage d'erreurs !"):
def error(request, message="Bienvenue sur la page d'affichage d'erreurs !"):
# Count to_moderate_number to display on moderation menu tab
to_moderate_number = count_to_moderate()
# This special view is called everytime there is an error to display it into the browser
return render(request,'core/error.html', {
return render(request, 'core/error.html', {
'to_moderate_number': to_moderate_number,
'messages': request.messages,
})
......@@ -623,7 +622,7 @@ def legal(request):
@login_required
def account(request):
# Load fields and value from user
data = [(field.verbose_name, getattr(request.user,field.name)) for field in User._meta.fields if field.verbose_name not in ['password', 'ID', 'Adresse email']]
data = [(field.verbose_name, getattr(request.user, field.name)) for field in User._meta.fields if field.verbose_name not in ['password', 'ID', 'Adresse email']]
# Select statistics
online_comments_number = len(request.user.coursecomment_set.filter(isModerated=True)) + len(request.user.documentcomment_set.filter(isModerated=True))
......@@ -700,7 +699,7 @@ def like(request, type, id):
# Warning when like already exist
try:
DocumentLike.objects.get(user=request.user,document=document)
DocumentLike.objects.get(user=request.user, document=document)
except ObjectDoesNotExist:
# We can continue
DocumentLike.objects.create(user=request.user, document=document)
......@@ -727,7 +726,7 @@ def like(request, type, id):
# Warning when like already exist
try:
CourseLike.objects.get(user=request.user,course=course)
CourseLike.objects.get(user=request.user, course=course)
except ObjectDoesNotExist:
# We can continue
CourseLike.objects.create(user=request.user, course=course)
......@@ -769,7 +768,7 @@ def dislike(request, type, id):
# Warning when like doesn't exist
try:
DocumentLike.objects.get(user=request.user,document=document)
DocumentLike.objects.get(user=request.user, document=document)
except ObjectDoesNotExist:
request.messages.append({
'type': 'warning',
......@@ -797,7 +796,7 @@ def dislike(request, type, id):
# Warning when like doesn't exist
try:
CourseLike.objects.get(user=request.user,course=course)
CourseLike.objects.get(user=request.user, course=course)
except ObjectDoesNotExist:
request.messages.append({
'type': 'warning',
......
......@@ -77,8 +77,9 @@ TEMPLATES = [
TEMPLATE_DIRS = (os.path.join(BASE_DIR, 'templates'),)
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',)
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
)
WSGI_APPLICATION = 'nofistv2.wsgi.application'
......@@ -148,7 +149,7 @@ SITE_ID = 1
# OAUTH
LOGIN_URL = reverse_lazy('oauth_vr:login')
LOGIN_REDIRECT_URL = reverse_lazy('core:home')
LOGOUT_REDIRECT_URL = 'https://auth.viarezo.fr/logout?%s' % urlencode({ 'redirect_logout': domain })
LOGOUT_REDIRECT_URL = 'https://auth.viarezo.fr/logout?%s' % urlencode({'redirect_logout': domain})
OAUTH_CLIENT_ID = client_id
OAUTH_CLIENT_SECRET = client_secret
......
......@@ -7,11 +7,12 @@ For more information on this file, see
https://docs.djangoproject.com/en/2.0/howto/deployment/wsgi/
"""
import os, sys
import os
import sys
from django.core.wsgi import get_wsgi_application
sys.path.append('/var/www/nofistv2')
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "nofistv2.settings")
......
Markdown is supported
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