TELEFORMA_EXAM_MAX_SESSIONS = 99
TELEFORMA_EXAM_SCRIPT_MAX_SIZE = 31457280
TELEFORMA_EXAM_SCRIPT_SERVICE_URL = '/webviewer/teleforma.html'
+TELEFORMA_PRIVATE_DOCUMENTS_MODE = True
EMAIL_HOST = 'angus.parisson.com'
DEFAULT_FROM_EMAIL = 'crfpa@pre-barreau.com'
readers = models.ManyToManyField(User, related_name="document", verbose_name=_('readers'),
blank=True)
+ class Meta(MetaCore):
+ db_table = app_label + '_' + 'document'
+ ordering = ['-date_added']
+ indexes = [
+ models.Index(fields=['course', 'is_published', '-date_added' ]),
+ ]
+
def is_image(self):
is_url_image = False
if self.url:
self.set_mime_type()
super(Document, self).save(**kwargs)
+ def private_file(self, user):
+ private_document = DocumentPrivate.objects.get_or_create(document=self, user=user)
+ return private_document.file
+
+
+class DocumentPrivate(MediaBase):
+
+ document = models.ForeignKey('Document', related_name='private_documents', verbose_name=_('document'),
+ null=True, blank=True, on_delete=models.CASCADE)
+ user = models.ForeignKey(User, related_name="private_documents", verbose_name=_('user'),
+ null=True, blank=True, on_delete=models.CASCADE)
+ file = models.FileField(_('file'), upload_to='private_documents/%Y/%m/%d', db_column="filename",
+ max_length=1024, blank=True)
class Meta(MetaCore):
- db_table = app_label + '_' + 'document'
+ db_table = app_label + '_' + 'document_private'
ordering = ['-date_added']
- indexes = [
- models.Index(fields=['course', 'is_published', '-date_added' ]),
- ]
+
+ def save(self, **kwargs):
+ if "pdf" in self.document.mimetype:
+ from pypdf import PdfReader, PdfWriter
+ writer = PdfWriter(clone_from=self.document.file.path)
+ writer.add_metadata({"/Downloader": self.user.username})
+ name = self.document.file.name
+ today = datetime.date.today()
+ root = settings.MEDIA_ROOT + "private_documents/%s/%s/%s/" % (today.year, today.month, today.day)
+ os.path.makedirs(root)
+ path = root + user.username + " - " + name
+ with open(path, "wb") as f:
+ writer.write(f)
+ self.file = path
+ super(DocumentPrivate, self).save(**kwargs)
class DocumentSimple(MediaBase):
# -*- coding: utf-8 -*-
-# Copyright (c) 2011-2018 Parisson SARL
-# Copyright (c) 2011-2018 Guillaume Pellerin
+# Copyright (c) 2011-2024 Parisson SARL
+# Copyright (c) 2011-2024 Guillaume Pellerin
# This software is a computer program whose purpose is to backup, analyse,
# transcode and stream any audio content with its metadata over a web frontend.
# knowledge of the CeCILL license and that you accept its terms.
#
# Authors: Guillaume Pellerin <yomguy@parisson.com>
+
import datetime
import os
import requests
courses = get_courses(request.user)
document = Document.objects.get(pk=pk)
if get_access(document, courses):
- return serve_media(document.file.path, streaming=False)
+ if settings.TELEFORMA_PRIVATE_DOCUMENTS_MODE:
+ path = document.private_file.path
+ else:
+ path = document.file.path
+ return serve_media(path, streaming=False)
else:
return redirect('teleforma-home')
courses = get_courses(request.user)
document = Document.objects.get(pk=pk)
if get_access(document, courses):
- return serve_media(document.file.path, streaming=True)
+ if settings.TELEFORMA_PRIVATE_DOCUMENTS_MODE:
+ path = document.private_file.path
+ else:
+ path = document.file.path
+ return serve_media(path, streaming=True)
else:
return redirect('teleforma-home')
settings, "TELECASTER_LIVE_STREAMING_PROTOCOL", 'http')
server_type = stream['server_type']
stream_type = stream['stream_type']
+
if server_type == 'icecast':
port = getattr(
settings, "TELECASTER_LIVE_ICECAST_STREAMING_PORT", '8000')
settings, "TELECASTER_LIVE_STREAM_M_STREAMING_PORT", '8080')
path = getattr(
settings, "TELECASTER_LIVE_STREAM_M_STREAMING_PATH", '/')
- #site = Site.objects.all()[0]
server, c = StreamingServer.objects.get_or_create(
protocol=protocol,
host=host,