Skip to content

Commit

Permalink
Merge pull request #119 from EsupPortail/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
ptitloup authored Feb 14, 2019
2 parents 30f9c4d + b0fd07e commit 3ef16db
Show file tree
Hide file tree
Showing 26 changed files with 343 additions and 71 deletions.
10 changes: 10 additions & 0 deletions pod/authentication/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@
('registered-reader', _('registered-reader'))
)
)
ESTABLISHMENTS = getattr(
settings, "ESTABLISHMENTS",
(
('Etab_1', 'Etab_1'),
('Etab_2', 'Etab_2'),
)
)
SECRET_KEY = getattr(settings, 'SECRET_KEY', '')
FILES_DIR = getattr(
settings, 'FILES_DIR', 'files')
Expand All @@ -59,6 +66,9 @@ class Owner(models.Model):
userpicture = models.ForeignKey(CustomImageModel,
blank=True, null=True,
verbose_name=_('Picture'))
establishment = models.CharField(
_('Establishment'), max_length=10, blank=True, choices=ESTABLISHMENTS,
default=ESTABLISHMENTS[0][0])

def __str__(self):
return "%s %s (%s)" % (self.user.first_name, self.user.last_name,
Expand Down
6 changes: 6 additions & 0 deletions pod/authentication/populatedCASbackend.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ def populate_user_from_entry(user, owner, entry):
and entry[USER_LDAP_MAPPING_ATTRIBUTES['primaryAffiliation']]
) else AFFILIATION[0][0]
)
owner.establishment = (
entry[USER_LDAP_MAPPING_ATTRIBUTES['establishment']].value if (
USER_LDAP_MAPPING_ATTRIBUTES.get('establishment')
and entry[USER_LDAP_MAPPING_ATTRIBUTES['establishment']]
) else ""
)
owner.save()
affiliations = (
entry[USER_LDAP_MAPPING_ATTRIBUTES['affiliations']].values if (
Expand Down
3 changes: 2 additions & 1 deletion pod/live/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ class BuildingAdmin(admin.ModelAdmin):


class BroadcasterAdmin(admin.ModelAdmin):
list_display = ('name', 'url', 'status', 'is_restricted')
list_display = ('name', 'slug', 'url', 'status', 'is_restricted')
readonly_fields = ["slug"]


admin.site.register(Building, BuildingAdmin)
Expand Down
11 changes: 11 additions & 0 deletions pod/live/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from django.conf import settings
from django.utils.translation import ugettext_lazy as _
from ckeditor.fields import RichTextField
from django.template.defaultfilters import slugify

if getattr(settings, 'USE_PODFILE', False):
from pod.podfile.models import CustomImageModel
Expand Down Expand Up @@ -41,6 +42,12 @@ class Meta:

class Broadcaster(models.Model):
name = models.CharField(_('name'), max_length=200, unique=True)
slug = models.SlugField(
_('Slug'), unique=True, max_length=200,
help_text=_(
u'Used to access this instance, the "slug" is a short label '
+ 'containing only letters, numbers, underscore or dash top.'),
editable=False, default="") # default empty, fill it in save
building = models.ForeignKey('Building', verbose_name=_('Building'))
description = RichTextField(
_('description'), config_name='complete', blank=True)
Expand Down Expand Up @@ -73,6 +80,10 @@ def get_poster_url(self):
DEFAULT_THUMBNAIL])
return thumbnail_url

def save(self, *args, **kwargs):
self.slug = slugify(self.name)
super(Broadcaster, self).save(*args, **kwargs)

class Meta:
verbose_name = _("Broadcaster")
verbose_name_plural = _("Broadcasters")
Expand Down
5 changes: 4 additions & 1 deletion pod/live/rest_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ class BroadcasterSerializer(serializers.HyperlinkedModelSerializer):

class Meta:
model = Broadcaster
fields = ('id', 'url', 'name',
fields = ('id', 'url', 'name', 'slug',
'building', 'description', 'poster',
'url', 'status')
lookup_field = 'slug'


#############################################################################
# ViewSets define the view behavior.
Expand All @@ -32,3 +34,4 @@ class BuildingViewSet(viewsets.ModelViewSet):
class BroadcasterViewSet(viewsets.ModelViewSet):
queryset = Broadcaster.objects.all().order_by('building', 'name')
serializer_class = BroadcasterSerializer
lookup_field = 'slug'
13 changes: 13 additions & 0 deletions pod/live/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from .models import Building, Broadcaster
from django.conf import settings
from django.shortcuts import redirect
# from django.http import HttpResponse --> not use


def lives(request): # affichage des directs
Expand All @@ -26,3 +27,15 @@ def video_live(request, id): # affichage des directs
return render(request, "live/live.html", {
'broadcaster': broadcaster
})


""" use rest api to change status
def change_status(request, slug):
broadcaster = get_object_or_404(Broadcaster, slug=slug)
if request.GET.get("online") == "1":
broadcaster.status = 1
else:
broadcaster.status = 0
broadcaster.save()
return HttpResponse("ok")
"""
2 changes: 1 addition & 1 deletion pod/main/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class CustomFlatPageAdmin(TranslationAdmin):
'fields': (
'enable_comments',
'registration_required',
# 'sites',
'template_name',
),
}),
)
Expand Down
3 changes: 3 additions & 0 deletions pod/main/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
'POST_FOOTER_TEMPLATE': '',
}
)
OEMBED = getattr(
django_settings, 'OEMBED', False)


def context_settings(request):
Expand All @@ -68,6 +70,7 @@ def context_settings(request):
raise ImproperlyConfigured(m)
new_settings['VERSION'] = VERSION
new_settings["THIRD_PARTY_APPS"] = django_settings.THIRD_PARTY_APPS
new_settings['OEMBED'] = OEMBED
return new_settings


Expand Down
15 changes: 15 additions & 0 deletions pod/main/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,18 @@ $('#btnpartageprive').click(function() {
});

/** Restrict access **/
/** restrict access to group */
$("#id_is_restricted").change(function () {
restrict_access_to_groups();
})
var restrict_access_to_groups = function () {
if ($('#id_is_restricted').prop("checked")) {
$("#id_restrict_access_to_groups").parents(".restricted_access").show();
} else {
$("#id_restrict_access_to_groups option:selected").prop("selected", false);
$("#id_restrict_access_to_groups").parents(".restricted_access").hide();
}
}
$('#id_is_draft').change(function(){
restricted_access();
});
Expand All @@ -402,8 +414,11 @@ var restricted_access = function() {
$('.restricted_access').addClass('show');
$('.restricted_access').removeClass('hide');
}
restrict_access_to_groups();
}
restricted_access();
//restrict_access_to_groups();

/** end restrict access **/
/*** VALID FORM ***/
(function() {
Expand Down
23 changes: 18 additions & 5 deletions pod/recorder/forms.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,38 @@
from django import forms
from django.conf import settings
from django.utils.translation import ugettext_lazy as _

from .models import Recording
from pod.main.forms import add_placeholder_and_asterisk

DEFAULT_RECORDER_PATH = getattr(
settings, 'DEFAULT_RECORDER_PATH',
"/data/ftp-pod/ftp/"
)


class RecordingForm(forms.ModelForm):

def __init__(self, request, *args, **kwargs):
super(RecordingForm, self).__init__(*args, **kwargs)

if not request.user.is_superuser:
del self.fields['user']
del self.fields['source_file']

self.fields = add_placeholder_and_asterisk(self.fields)

if self.initial.get("type"):
self.fields['type'].widget = forms.HiddenInput()
if self.initial.get("title") and self.initial.get("title") != "":
self.fields['title'].widget = forms.HiddenInput()
if self.initial.get("source_file"):

self.fields['source_file'] = forms.FilePathField(
path=DEFAULT_RECORDER_PATH,
recursive=True,
label=_("source_file")
)
self.fields['source_file'].widget.attrs['class'] = 'form-control'

if not request.user.is_superuser:
del self.fields['user']
# del self.fields['source_file']
self.fields['source_file'].widget = forms.HiddenInput()

class Meta:
Expand Down
22 changes: 15 additions & 7 deletions pod/recorder/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,26 @@
@csrf_protect
@staff_member_required(redirect_field_name='referrer')
def add_recording(request):
mediapath = request.GET.get('mediapath')
mediapath = request.GET.get('mediapath') if (
request.GET.get('mediapath')) else ""
course_title = request.GET.get(
'course_title') if request.GET.get('course_title') else ""
course_type = request.GET.get('type')

initial = {
'title': course_title,
'type': course_type}

if not mediapath and not request.user.is_superuser:
messages.add_message(
request, messages.ERROR, _('Mediapath should be indicated.'))
raise PermissionDenied

form = RecordingForm(request, initial={
'source_file': os.path.join(DEFAULT_RECORDER_PATH, mediapath),
'title': course_title,
'type': course_type})
if mediapath != "":
initial['source_file'] = "%s" % os.path.join(
DEFAULT_RECORDER_PATH, mediapath)

form = RecordingForm(request, initial=initial)

if request.method == 'POST': # If the form has been submitted...
# A form bound to the POST data
Expand All @@ -45,11 +51,13 @@ def add_recording(request):
med.user = form.cleaned_data['user']
else:
med.user = request.user
"""
if (request.POST.get('mediapath')
and request.POST.get('mediapath') != ""):
med.mediapath = form.cleaned_data['mediapath']
med.source_file = form.cleaned_data['mediapath']
else:
med.mediapath = mediapath
med.source_file = mediapath
"""
med.save()
message = _(
'Your publication is saved.'
Expand Down
2 changes: 1 addition & 1 deletion pod/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
##
# Version of the project
#
VERSION = '2.0.4'
VERSION = '2.1.0'

##
# Installed applications list
Expand Down
11 changes: 10 additions & 1 deletion pod/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from pod.video.views import theme_edit
from pod.video.views import video_notes
from pod.video.views import video_count
from pod.video.views import video_oembed
from pod.video.feeds import RssSiteVideosFeed, RssSiteAudiosFeed
from pod.main.views import contact_us, download_file
from pod.main.rest_router import urlpatterns as rest_urlpatterns
Expand All @@ -36,6 +37,8 @@

USE_CAS = getattr(
settings, 'USE_CAS', False)
OEMBED = getattr(
settings, 'OEMBED', False)

urlpatterns = [
url(r'^admin/', admin.site.urls),
Expand Down Expand Up @@ -67,7 +70,7 @@
url(r'^video_edit/(?P<slug>[\-\d\w]+)/$', video_edit, name='video_edit'),
url(r'^video_delete/(?P<slug>[\-\d\w]+)/$',
video_delete, name='video_delete'),
url(r'^video_notes/(?P<id>[\d]+)/$',
url(r'^video_notes/(?P<slug>[\-\d\w]+)/$',
video_notes, name='video_notes'),
url(r'^video_count/(?P<id>[\d]+)/$',
video_count, name='video_count'),
Expand Down Expand Up @@ -119,6 +122,12 @@
# CAS
if USE_CAS:
urlpatterns += [url(r'^sso-cas/', include('django_cas.urls')), ]
##
# OEMBED feature patterns
#
if OEMBED:
urlpatterns += [url(r'^oembed/', video_oembed, name='video_oembed'), ]

# APPS -> to change !
urlpatterns += [url(r'^', include('pod.completion.urls')), ]
urlpatterns += [url(r'^', include('pod.chapter.urls')), ]
Expand Down
16 changes: 14 additions & 2 deletions pod/video/admin.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@

from django.conf import settings
from django.contrib import admin
from django.contrib.auth.models import User
from django.core.urlresolvers import reverse
from django.utils.html import format_html
from django.utils.translation import ugettext_lazy as _

from modeltranslation.admin import TranslationAdmin

from .models import Video
Expand Down Expand Up @@ -37,6 +36,9 @@

# Ordering user by username !
User._meta.ordering = ["username"]
# SET USE_ESTABLISHMENT_FIELD
USE_ESTABLISHMENT_FIELD = getattr(
settings, 'USE_ESTABLISHMENT_FIELD', False)


def url_to_edit_object(obj):
Expand Down Expand Up @@ -93,6 +95,16 @@ class VideoAdmin(admin.ModelAdmin):
ChapterInline
]

def get_owner_establishment(self, obj):
owner = obj.owner
return owner.owner.establishment
get_owner_establishment.short_description = _('Establishment')
# Ajout de l'attribut 'establishment'
if USE_ESTABLISHMENT_FIELD:
list_filter = list_filter + ("owner__owner__establishment",)
list_display = list_display + ("get_owner_establishment",)
search_fields.append("owner__owner__establishment",)

def get_owner_by_name(self, obj):
owner = obj.owner
url = url_to_edit_object(owner)
Expand Down
3 changes: 2 additions & 1 deletion pod/video/encode.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@
# + "-deinterlace -threads %(nb_threads)s -g %(key_frames_interval)s "
# + "-keyint_min %(key_frames_interval)s ")

FFMPEG_MISC_PARAMS = getattr(settings, 'MISC_PARAMS', " -hide_banner -y ")
FFMPEG_MISC_PARAMS = getattr(
settings, 'FFMPEG_MISC_PARAMS', " -hide_banner -y ")

AUDIO_BITRATE = getattr(settings, 'AUDIO_BITRATE', "192k")

Expand Down
10 changes: 7 additions & 3 deletions pod/video/feeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,13 @@
}
)

TITLE_ETB = getattr(TEMPLATE_VISIBLE_SETTINGS, 'TITLE_ETB', 'University')
TITLE_SITE = getattr(TEMPLATE_VISIBLE_SETTINGS, 'TITLE_SITE', 'Pod')
LOGO_SITE = getattr(TEMPLATE_VISIBLE_SETTINGS, 'LOGO_SITE', 'img/logoPod.svg')
TITLE_ETB = TEMPLATE_VISIBLE_SETTINGS['TITLE_ETB'] if (
TEMPLATE_VISIBLE_SETTINGS.get('TITLE_ETB')) else 'University name'
TITLE_SITE = TEMPLATE_VISIBLE_SETTINGS['TITLE_SITE'] if (
TEMPLATE_VISIBLE_SETTINGS.get('TITLE_SITE')) else 'Pod'
LOGO_SITE = TEMPLATE_VISIBLE_SETTINGS['LOGO_SITE'] if (
TEMPLATE_VISIBLE_SETTINGS.get('LOGO_SITE')) else 'img/logoPod.svg'

CONTACT_US_EMAIL = getattr(
settings,
'CONTACT_US_EMAIL',
Expand Down
Loading

0 comments on commit 3ef16db

Please sign in to comment.