From 9ff3e63082efc9c4c4bb595522f89c286ab06fe1 Mon Sep 17 00:00:00 2001 From: alazo Date: Mon, 16 Jul 2018 19:11:20 +0200 Subject: [PATCH 1/4] group module 7 and 8 --- templates/cms/index.html | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/templates/cms/index.html b/templates/cms/index.html index 87e6232..3eb8784 100644 --- a/templates/cms/index.html +++ b/templates/cms/index.html @@ -64,22 +64,14 @@   - {{ P04.url }} + {{ P04.url }}         - {{ M07.url_code }} + {{ M07.url_code }} + {{ M08.url_code }} {{ M09.url_code }} - -   -   -   -   - {{ M08.url_code }}  - From cf3cf1748b4c253b2a98cde9c2c127791ce4e7ac Mon Sep 17 00:00:00 2001 From: alazo Date: Mon, 16 Jul 2018 20:57:37 +0200 Subject: [PATCH 2/4] Add DocProf model --- cms/models.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/cms/models.py b/cms/models.py index a9f2bff..2ef963e 100644 --- a/cms/models.py +++ b/cms/models.py @@ -178,3 +178,17 @@ class UploadDoc(models.Model): def __str__(self): return self.titre + +class DocumentProf(models.Model): + doc = models.FileField(upload_to='docprof') + module = models.ForeignKey(Module, blank=False, on_delete=models.PROTECT) + title = models.CharField('titre', max_length=100, blank=False) + published = models.BooleanField(default=False) + + class Meta: + verbose_name = 'DocProf' + + def __str__(self): + return "{0} : {1}".format(self.module.code, self.title) + + From faef1e2caa351475494dd934188543b6dcf4de8a Mon Sep 17 00:00:00 2001 From: alazo Date: Sun, 29 Jul 2018 11:38:02 +0200 Subject: [PATCH 3/4] Intranet app --- cms/admin.py | 3 +- cms/models.py | 15 -------- cms/views.py | 1 - common/settings.py | 2 + common/urls.py | 13 +++++-- intranet/migrations/0001_Add_Intranet_app.py | 31 ++++++++++++++++ intranet/urls.py | 10 +++++ intranet/views.py | 39 ++++++++++++++++++++ templates/cms/base_site.html | 8 ++-- templates/cms/index.html | 2 +- templates/cms/module_detail.html | 5 ++- templates/intranet/list.html | 23 ++++++++++++ 12 files changed, 125 insertions(+), 27 deletions(-) create mode 100644 intranet/migrations/0001_Add_Intranet_app.py create mode 100644 intranet/urls.py create mode 100644 intranet/views.py create mode 100644 templates/intranet/list.html diff --git a/cms/admin.py b/cms/admin.py index 6d0329f..d22bc9f 100644 --- a/cms/admin.py +++ b/cms/admin.py @@ -85,8 +85,7 @@ class ConceptAdmin(admin.ModelAdmin): class UploadAdmin(admin.ModelAdmin): form = UploadAdminForm - - + admin.site.register(Enseignant) admin.site.register(Domaine, DomaineAdmin) admin.site.register(Competence, CompetenceAdmin) diff --git a/cms/models.py b/cms/models.py index 2ef963e..f441a56 100644 --- a/cms/models.py +++ b/cms/models.py @@ -6,7 +6,6 @@ Created on 17 nov. 2012 from django.db import models from django.utils.html import format_html - from tinymce import models as tinymce_models @@ -178,17 +177,3 @@ class UploadDoc(models.Model): def __str__(self): return self.titre - -class DocumentProf(models.Model): - doc = models.FileField(upload_to='docprof') - module = models.ForeignKey(Module, blank=False, on_delete=models.PROTECT) - title = models.CharField('titre', max_length=100, blank=False) - published = models.BooleanField(default=False) - - class Meta: - verbose_name = 'DocProf' - - def __str__(self): - return "{0} : {1}".format(self.module.code, self.title) - - diff --git a/cms/views.py b/cms/views.py index d4a26c4..58244f9 100644 --- a/cms/views.py +++ b/cms/views.py @@ -6,7 +6,6 @@ Created on 4 déc. 2012 import os import tempfile - from django.db.models import Sum from django.http import HttpResponse from django.views.generic import ListView, TemplateView, DetailView diff --git a/common/settings.py b/common/settings.py index 6a672b0..c3ebee4 100644 --- a/common/settings.py +++ b/common/settings.py @@ -24,6 +24,7 @@ INSTALLED_APPS = [ 'django.contrib.staticfiles', 'tinymce', 'cms', + 'intranet', ] @@ -123,5 +124,6 @@ TINYMCE_COMPRESSOR = True PDF_FOOTER_TEXT = 'Ecole Santé-social Pierre-Coullery | Prévoyance 82 - 2300 La Chaux-de-Fonds | 032 886 33 00 | cifom-epc@rpn.ch' +LOGIN_REDIRECT_URL = '/intranet/list/' from .local_settings import * diff --git a/common/urls.py b/common/urls.py index f92c020..4501ad6 100644 --- a/common/urls.py +++ b/common/urls.py @@ -2,15 +2,19 @@ """ import os -from django.urls import path, include -from django.contrib import admin + from django.conf import settings +from django.contrib import admin +from django.contrib.auth.views import LoginView, logout +from django.urls import path, include from django.views.static import serve from cms import views urlpatterns = [ path('', views.HomeView.as_view(), name='home'), + path('login/', LoginView.as_view(), name='login'), + path('logout/', logout, {'next_page': '/'}, name='logout'), path('plan_pdf/', views.print_plan_formation, name='plan-pdf'), path('admin/', admin.site.urls), path('domaine//', views.DomaineDetailView.as_view(), name='domaine-detail'), @@ -28,8 +32,11 @@ urlpatterns = [ path('upload/', views.UploadDocListView.as_view(), name='uploaddoc-list'), path('concept//', views.ConceptDetailView.as_view(), name='concept-detail'), path('tinymce/', include('tinymce.urls'), name='tinymce-js'), - + path('intranet/', include('intranet.urls'), name='intranet'), # Serve docs by Django to allow LoginRequiredMiddleware to apply + path('media/intranet/', serve, + {'document_root': os.path.join(settings.MEDIA_ROOT, 'intranet'), 'show_indexes': False} + ), path('media/doc/', serve, {'document_root': os.path.join(settings.MEDIA_ROOT, 'doc'), 'show_indexes': False} ), diff --git a/intranet/migrations/0001_Add_Intranet_app.py b/intranet/migrations/0001_Add_Intranet_app.py new file mode 100644 index 0000000..50dde2a --- /dev/null +++ b/intranet/migrations/0001_Add_Intranet_app.py @@ -0,0 +1,31 @@ +# Generated by Django 2.0.6 on 2018-07-28 11:31 + +from django.db import migrations, models +import django.db.models.deletion +import intranet.models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ('cms', '0009_drop_unneeded_defaults'), + ] + + operations = [ + migrations.CreateModel( + name='IntranetDoc', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('doc', models.FileField(unique=True, upload_to='intranet')), + ('published', models.BooleanField(default=True)), + ('authorization', models.SmallIntegerField(choices=[(3, 'admin'), (0, 'aucun'), (1, 'étudiant'), (2, 'prof')], default=0, verbose_name='autorisation')), + ('module', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='cms.Module')), + ], + options={ + 'verbose_name': 'Intranet', + 'verbose_name_plural': 'Intranet', + }, + ), + ] diff --git a/intranet/urls.py b/intranet/urls.py new file mode 100644 index 0000000..2ef3e78 --- /dev/null +++ b/intranet/urls.py @@ -0,0 +1,10 @@ +"""eds URL Configuration + +""" +from django.urls import path +from intranet import views + + +urlpatterns = [ + path('list/', views.IntranetListView.as_view(), name='intranet-list'), +] diff --git a/intranet/views.py b/intranet/views.py new file mode 100644 index 0000000..d50b341 --- /dev/null +++ b/intranet/views.py @@ -0,0 +1,39 @@ +from django.conf import settings +from django.views.generic import ListView +from cms.models import Module +from intranet.models import IntranetDoc +from django.contrib.auth.mixins import LoginRequiredMixin + + +class IntranetListView(LoginRequiredMixin, ListView): + + model = IntranetDoc + template_name = 'intranet/list.html' + login_url = '/login/' + redirect_field_name = 'redirecto_to' + + def get_queryset(self): + modules = Module.objects.all().order_by('code') + groups = self.request.user.groups.values_list('name',flat=True) + + if self.request.user.is_superuser: + return IntranetDoc.objects.filter(authorization__in=[1,2,3], + published=True) + if 'prof' in groups: + return IntranetDoc.objects.filter(authorization__in=[1,2], + published=True) + if 'Student_1_year' in groups or 'Student_2_year' in groups or 'Student_3_year' in groups: + modules_selected = [] + student_access = {'Student_1_year': [m for m in modules if m.sem1 > 0 or m.sem2 > 0], + 'Student_2_year': [m for m in modules if m.sem3 > 0 or m.sem4 > 0], + 'Student_3_year': [m for m in modules if m.sem5 > 0 or m.sem6 > 0] + } + + + for group in groups: + for mod in student_access[group]: #settings.STUDENT_ACCESS[group]: + modules_selected.append(mod.code) + return IntranetDoc.objects.filter(module__code__in=modules_selected, + authorization=1, + published=True) + return None diff --git a/templates/cms/base_site.html b/templates/cms/base_site.html index 8b4ab2e..2c3529c 100644 --- a/templates/cms/base_site.html +++ b/templates/cms/base_site.html @@ -9,9 +9,9 @@
{% if user.is_authenticated %} {% block welcome-msg %}Bienvenue {% firstof user.username %}.{% endblock %} - Site public  Admin + Déconnexion  {% else %} - Admin + Login {% endif %}
{% endblock %} @@ -29,8 +29,8 @@
  • Concept pédagogique  
  • Concept de formation  
  • Téléchargements  
  • - {% if has_permission %} -
  • Calendrier  
  • + {% if user.is_superuser %} +
  • Administration
  • {% endif %} diff --git a/templates/cms/index.html b/templates/cms/index.html index 3eb8784..e5b657f 100644 --- a/templates/cms/index.html +++ b/templates/cms/index.html @@ -54,7 +54,7 @@ - {{ D2.url }} + {{ D2.url }} {{ P03.url }} {{ M05.url_code }}   diff --git a/templates/cms/module_detail.html b/templates/cms/module_detail.html index 33304f1..32ee98f 100644 --- a/templates/cms/module_detail.html +++ b/templates/cms/module_detail.html @@ -85,7 +85,10 @@ {{ object.processus.domaine.responsable.descr|safe }} -

    Imprimer en PDF

    +

    + Imprimer en PDF +     Documents de cours (login requis) +

    {% endblock %} diff --git a/templates/intranet/list.html b/templates/intranet/list.html new file mode 100644 index 0000000..4aded2f --- /dev/null +++ b/templates/intranet/list.html @@ -0,0 +1,23 @@ +{% extends "../cms/base_site.html" %} +{% load i18n static %} + +{% block content %} + +
    +

    Documents de cours

    + {% regroup object_list by module as module_list %} + +
    +{% endblock %} From 9454d8de468a316ee9c689af79b924e3cb7159e9 Mon Sep 17 00:00:00 2001 From: alazo Date: Sun, 29 Jul 2018 11:40:40 +0200 Subject: [PATCH 4/4] Intranet app --- .gitignore | 2 +- .idea/eds.iml | 12 + .idea/misc.xml | 7 + .idea/modules.xml | 8 + .idea/vcs.xml | 6 + .idea/workspace.xml | 644 ++++++++++++++++++++++++++++++ intranet/__init__.py | 0 intranet/admin.py | 32 ++ intranet/apps.py | 5 + intranet/migrations/__init__.py | 0 intranet/models.py | 36 ++ intranet/tests.py | 3 + templates/registration/login.html | 66 +++ 13 files changed, 820 insertions(+), 1 deletion(-) create mode 100644 .idea/eds.iml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml create mode 100644 intranet/__init__.py create mode 100644 intranet/admin.py create mode 100644 intranet/apps.py create mode 100644 intranet/migrations/__init__.py create mode 100644 intranet/models.py create mode 100644 intranet/tests.py create mode 100644 templates/registration/login.html diff --git a/.gitignore b/.gitignore index 9a7f560..e5ee446 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,4 @@ db.eds db.* *.sql scripts/* - +.idea/* diff --git a/.idea/eds.iml b/.idea/eds.iml new file mode 100644 index 0000000..4682891 --- /dev/null +++ b/.idea/eds.iml @@ -0,0 +1,12 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..6538501 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..ca01fa5 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..298819b --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,644 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {% url 'admin_password_reset' as password_reset_url %} + {% if password_reset_url %} + + {% endif %} +
    + +
    + + + +{% endblock %}