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 import admin
from django.contrib.auth.admin import UserAdmin 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. # Register your models here.
admin.site.register(DocumentComment) admin.site.register(DocumentComment)
......
...@@ -14,15 +14,15 @@ class PostCourseCommentForm(forms.ModelForm): ...@@ -14,15 +14,15 @@ class PostCourseCommentForm(forms.ModelForm):
class PostDocumentForm(forms.ModelForm): class PostDocumentForm(forms.ModelForm):
class Meta: class Meta:
model = Document model = Document
fields=['name','course','file','description','type','documentDate','correction'] fields = ['name', 'course', 'file', 'description', 'type', 'documentDate', 'correction']
class PostCourseForm(forms.ModelForm): class PostCourseForm(forms.ModelForm):
class Meta: class Meta:
model = Course model = Course
fields=['name','type',"year",'description'] fields = ['name', 'type', "year", 'description']
class PostTeacherForm(forms.ModelForm): class PostTeacherForm(forms.ModelForm):
class Meta: class Meta:
model = Teacher 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 from django.http import HttpResponseRedirect
import requests
import time
import datetime
from .models import User
from django.core import serializers
class CGUMiddleware: class CGUMiddleware:
def __init__(self, get_response): def __init__(self, get_response):
self.get_response = get_response self.get_response = get_response
def __call__(self, request): 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 # Middleware default allowed pages
return self.get_response(request) return self.get_response(request)
if request.user.is_anonymous: if request.user.is_anonymous:
...@@ -20,8 +14,7 @@ class CGUMiddleware: ...@@ -20,8 +14,7 @@ class CGUMiddleware:
if request.user.hasAcceptedCGU: if request.user.hasAcceptedCGU:
# Let people go if they accepted CGU # Let people go if they accepted CGU
return self.get_response(request) return self.get_response(request)
else: return HttpResponseRedirect('/legal')
return HttpResponseRedirect('/legal')
class MessagesMiddleware: class MessagesMiddleware:
def __init__(self, get_response): def __init__(self, get_response):
...@@ -29,4 +22,4 @@ class MessagesMiddleware: ...@@ -29,4 +22,4 @@ class MessagesMiddleware:
def __call__(self, request): def __call__(self, request):
request.messages = [] request.messages = []
return self.get_response(request) return self.get_response(request)
\ No newline at end of file
...@@ -7,19 +7,19 @@ class Course(models.Model): ...@@ -7,19 +7,19 @@ class Course(models.Model):
year = models.CharField( year = models.CharField(
max_length=2, max_length=2,
choices=( choices=(
('1A','1A'), ('1A', '1A'),
('2A','2A'), ('2A', '2A'),
('3A','3A'), ('3A', '3A'),
), ),
null=True, null=True,
) )
description = models.CharField(max_length=10000,null=True,blank=True) description = models.CharField(max_length=10000, null=True, blank=True)
teachers = models.ManyToManyField('Teacher',blank=True) teachers = models.ManyToManyField('Teacher', blank=True)
type = models.CharField( type = models.CharField(
max_length=50, max_length=50,
choices=( choices=(
('Tronc commun','Tronc commun'), ('Tronc commun', 'Tronc commun'),
('Electif','Electif'), ('Electif', 'Electif'),
), ),
null=True, null=True,
) )
...@@ -31,21 +31,22 @@ class Course(models.Model): ...@@ -31,21 +31,22 @@ class Course(models.Model):
class Document(models.Model): class Document(models.Model):
name = models.CharField(max_length=200) name = models.CharField(max_length=200)
documentDate = models.DateField() 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) isAccepted = models.BooleanField(default=False)
user = models.ForeignKey('User', 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) course = models.ForeignKey('Course', on_delete=models.SET_NULL, null=True, blank=True)
file = models.FileField(upload_to='') file = models.FileField(upload_to='')
correction = models.FileField(upload_to='corrections/', blank=True, null=True) correction = models.FileField(upload_to='corrections/', blank=True, null=True)
type = models.CharField( type = models.CharField(
max_length=50, max_length=50,
choices=( choices=(
('Annale','Annale'), ('Annale', 'Annale'),
('Fiche','Fiche'), ('Fiche', 'Fiche'),
('Poly de cours','Poly de cours'), ('Poly de cours', 'Poly de cours'),
('Notes de cours', 'Notes de cours'), ('Notes de cours', 'Notes de cours'),
), ),
null=True) null=True
)
def __str__(self): def __str__(self):
return self.name return self.name
...@@ -55,8 +56,8 @@ class DocumentComment(models.Model): ...@@ -55,8 +56,8 @@ class DocumentComment(models.Model):
content = models.CharField(max_length=10000) content = models.CharField(max_length=10000)
commentDate = models.DateTimeField() commentDate = models.DateTimeField()
isModerated = models.BooleanField(default=False) isModerated = models.BooleanField(default=False)
user = models.ForeignKey('User',on_delete=models.CASCADE,null=True,blank=True) user = models.ForeignKey('User', on_delete=models.CASCADE, null=True, blank=True)
document = models.ForeignKey('Document',on_delete=models.CASCADE) document = models.ForeignKey('Document', on_delete=models.CASCADE)
def __str__(self): def __str__(self):
return str(self.commentDate) return str(self.commentDate)
...@@ -66,21 +67,21 @@ class CourseComment(models.Model): ...@@ -66,21 +67,21 @@ class CourseComment(models.Model):
content = models.CharField(max_length=10000) content = models.CharField(max_length=10000)
commentDate = models.DateTimeField() commentDate = models.DateTimeField()
isModerated = models.BooleanField(default=False) isModerated = models.BooleanField(default=False)
user = models.ForeignKey('User',on_delete=models.CASCADE,null=True,blank=True) user = models.ForeignKey('User', on_delete=models.CASCADE, null=True, blank=True)
course = models.ForeignKey('Course',on_delete=models.CASCADE) course = models.ForeignKey('Course', on_delete=models.CASCADE)
def __str__(self): def __str__(self):
return str(self.commentDate) return str(self.commentDate)
class Teacher(models.Model): 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) lastName = models.CharField(max_length=50)
email = models.EmailField(max_length=100,null=True,blank=True) email = models.EmailField(max_length=100, null=True, blank=True)
department = models.CharField(max_length=50,null=True,blank=True) department = models.CharField(max_length=50, null=True, blank=True)
office = models.CharField(max_length=50,null=True,blank=True) office = models.CharField(max_length=50, null=True, blank=True)
isAccepted = models.BooleanField(default=False) isAccepted = models.BooleanField(default=False)
def __str__(self): def __str__(self):
return self.lastName return self.lastName
...@@ -115,16 +116,16 @@ User._meta.get_field('last_login').verbose_name = "Dernière connexion" ...@@ -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" User._meta.get_field('date_joined').verbose_name = "Première connexion"
class CourseLike(models.Model): class CourseLike(models.Model):
user = models.ForeignKey('User',on_delete=models.CASCADE) user = models.ForeignKey('User', on_delete=models.CASCADE)
course = models.ForeignKey('Course',on_delete=models.CASCADE) course = models.ForeignKey('Course', on_delete=models.CASCADE)
def __str__(self): def __str__(self):
return str(self.user) + " aime " + str(self.course) return str(self.user) + " aime " + str(self.course)
class DocumentLike(models.Model): class DocumentLike(models.Model):
user = models.ForeignKey('User',on_delete=models.CASCADE) user = models.ForeignKey('User', on_delete=models.CASCADE)
document = models.ForeignKey('Document',on_delete=models.CASCADE) document = models.ForeignKey('Document', on_delete=models.CASCADE)
def __str__(self): def __str__(self):
return str(self.user) + " aime " + str(self.document) return str(self.user) + " aime " + str(self.document)
\ No newline at end of file
from core.models import User
import requests import requests
from core.models import User
def find_or_create_user(access_token, access_token_payload): def find_or_create_user(access_token, access_token_payload):
...@@ -25,4 +25,3 @@ 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.is_superuser = True
user.save() user.save()
return user return user
...@@ -38,14 +38,16 @@ ...@@ -38,14 +38,16 @@
<i class="ui database icon"></i> <i class="ui database icon"></i>
Tes données Tes données
</h2> </h2>
<div class="ui relaxed divided list"> <table class="ui very basic collapsing celled table">
<tbody>
{% for field, value in data %} {% for field, value in data %}
<div class="item content"> <tr>
<p class="header">{{ field }}</p> <td><p class="header">{{ field }}</p></td>
<p class="description">{{ value }}</p> <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>
</div> </tr>
{% endfor %} {% endfor %}
</div> </tbody>
</table>
<div class="ui center aligned container"> <div class="ui center aligned container">
<button onclick="$('.ui.modal').modal('show')" class="ui red button">Supprimer mon compte</button> <button onclick="$('.ui.modal').modal('show')" class="ui red button">Supprimer mon compte</button>
</div> </div>
......
...@@ -10,6 +10,9 @@ ...@@ -10,6 +10,9 @@
<span id="stars">{{ course.like_list|length }}</span> <span id="stars">{{ course.like_list|length }}</span>
</div> </div>
</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> </div>
<div class="content"> <div class="content">
...@@ -26,11 +29,6 @@ ...@@ -26,11 +29,6 @@
<p class="ui red label">{{course.year}}</p> <p class="ui red label">{{course.year}}</p>
<p class="ui {% if course.type == 'Electif' %}grey{% else %}teal{% endif %} label">{{ course.type }}</p> <p class="ui {% if course.type == 'Electif' %}grey{% else %}teal{% endif %} label">{{ course.type }}</p>
</div> </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>
</div> </div>
......
...@@ -10,6 +10,9 @@ ...@@ -10,6 +10,9 @@
<span id="stars">{{ document.like_list|length }}</span> <span id="stars">{{ document.like_list|length }}</span>
</div> </div>
</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> </div>
{% if document.course.pk != Null %}<div class="meta"><a href="{% url 'core:get_course' document.course.pk %}">{{document.course}}</a></div>{% endif %} {% if document.course.pk != Null %}<div class="meta"><a href="{% url 'core:get_course' document.course.pk %}">{{document.course}}</a></div>{% endif %}
</div> </div>
...@@ -20,12 +23,9 @@ ...@@ -20,12 +23,9 @@
<p class="ui {% if document.type == 'Annale' %}red{% else %}blue{% endif %} label">{{ document.type }}</p> <p class="ui {% if document.type == 'Annale' %}red{% else %}blue{% endif %} label">{{ document.type }}</p>
<p class="ui green label">{{document.documentDate.year}}</p> <p class="ui green label">{{document.documentDate.year}}</p>
</div> </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> <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 %} {% 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> </div>
</div> </div>
......
...@@ -49,7 +49,7 @@ ...@@ -49,7 +49,7 @@
</a> </a>
<div class="right menu"> <div class="right menu">
<div class="item"> <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' %}"> <a class="ui red label" href="{% url 'core:moderation' %}">
<i class="ui bell icon"></i> <i class="ui bell icon"></i>
{{ to_moderate_number }} {{ to_moderate_number }}
......
from django.test import TestCase # from django.test import TestCase
# Create your tests here. # Create your tests here.
from django.urls import path, re_path from django.urls import path
from . import views from . import views
...@@ -40,4 +40,4 @@ urlpatterns = [ ...@@ -40,4 +40,4 @@ urlpatterns = [
# Like # Like
path("like/<type>/<int:id>", views.like, name="like"), path("like/<type>/<int:id>", views.like, name="like"),
path("dislike/<type>/<int:id>", views.dislike, name="dislike"), path("dislike/<type>/<int:id>", views.dislike, name="dislike"),
] ]
\ No newline at end of file
...@@ -2,4 +2,4 @@ from core.models import Teacher, Course, Document, CourseComment, DocumentCommen ...@@ -2,4 +2,4 @@ from core.models import Teacher, Course, Document, CourseComment, DocumentCommen
def count_to_moderate(): def count_to_moderate():
to_moderate_number = len(Course.objects.filter(isAccepted=False)) + len(Document.objects.filter(isAccepted=False)) + len(Teacher.objects.filter(isAccepted=False)) + len(CourseComment.objects.filter(isModerated=False)) + len(DocumentComment.objects.filter(isModerated=False)) to_moderate_number = len(Course.objects.filter(isAccepted=False)) + len(Document.objects.filter(isAccepted=False)) + len(Teacher.objects.filter(isAccepted=False)) + len(CourseComment.objects.filter(isModerated=False)) + len(DocumentComment.objects.filter(isModerated=False))
return to_moderate_number return to_moderate_number
\ No newline at end of file
This diff is collapsed.
...@@ -77,8 +77,9 @@ TEMPLATES = [ ...@@ -77,8 +77,9 @@ TEMPLATES = [
TEMPLATE_DIRS = (os.path.join(BASE_DIR, 'templates'),) TEMPLATE_DIRS = (os.path.join(BASE_DIR, 'templates'),)
TEMPLATE_LOADERS = ( TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader', 'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',) 'django.template.loaders.app_directories.Loader',
)
WSGI_APPLICATION = 'nofistv2.wsgi.application' WSGI_APPLICATION = 'nofistv2.wsgi.application'
...@@ -148,7 +149,7 @@ SITE_ID = 1 ...@@ -148,7 +149,7 @@ SITE_ID = 1
# OAUTH # OAUTH
LOGIN_URL = reverse_lazy('oauth_vr:login') LOGIN_URL = reverse_lazy('oauth_vr:login')
LOGIN_REDIRECT_URL = reverse_lazy('core:home') 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_ID = client_id
OAUTH_CLIENT_SECRET = client_secret OAUTH_CLIENT_SECRET = client_secret
...@@ -165,4 +166,4 @@ if environment == "production": ...@@ -165,4 +166,4 @@ if environment == "production":
SECURE_CONTENT_TYPE_NOSNIFF = True SECURE_CONTENT_TYPE_NOSNIFF = True
SECURE_BROWSER_XSS_FILTER = True SECURE_BROWSER_XSS_FILTER = True
elif environment == "development": elif environment == "development":
DEBUG = True DEBUG = True
\ No newline at end of file
...@@ -7,11 +7,12 @@ For more information on this file, see ...@@ -7,11 +7,12 @@ For more information on this file, see
https://docs.djangoproject.com/en/2.0/howto/deployment/wsgi/ 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') sys.path.append('/var/www/nofistv2')
from django.core.wsgi import get_wsgi_application
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "nofistv2.settings") 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