Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Videos on television narrowcasting #727

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions amelie/api/narrowcasting.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from amelie.api.activitystream_utils import add_images_property, add_thumbnails_property
from amelie.api.decorators import authentication_optional
from amelie.api.utils import parse_datetime_parameter
from amelie.companies.models import TelevisionBanner
from amelie.companies.models import TelevisionBanner, TelevisionVideo
from amelie.news.models import NewsItem
from amelie.narrowcasting.models import TelevisionPromotion
from amelie.room_duty.models import RoomDuty
Expand All @@ -20,13 +20,23 @@
def get_narrowcasting_banners(request):
result = []
banners = TelevisionBanner.objects.filter(start_date__lte=timezone.now(), end_date__gte=timezone.now(), active=True)
videos = TelevisionVideo.objects.filter(start_date__lte=timezone.now(), end_date__gte=timezone.now(), active=True)

for banner in banners:
result.append({
"name": banner.name,
"image": "%s%s" % (settings.MEDIA_URL, str(banner.picture)),
"type": "image",
"id": banner.id
})

for video in videos:
result.append({
"name": video.name,
"videoId": video.video_id,
"type": video.video_type,
"id": video.id
})

return result

Expand Down Expand Up @@ -54,13 +64,13 @@ def get_television_promotions(request):
result = []
promotions = TelevisionPromotion.objects.filter(start__lte=timezone.now(), end__gte=timezone.now())

for promotion in promotions:
for promotion in promotions:
res_dict = {
"image": "%s%s" % (settings.MEDIA_URL, str(promotion.attachment))
}

if promotion.activity:
res_dict["title"] = promotion.activity.description
res_dict["title"] = promotion.activity.summary
if promotion.activity.enrollment:
res_dict["signup"] = promotion.activity.enrollment
res_dict["signupStart"] = promotion.activity.enrollment_begin.isoformat()
Expand Down
6 changes: 5 additions & 1 deletion amelie/companies/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.contrib import admin

from amelie.companies.models import Company, TelevisionBanner, WebsiteBanner
from amelie.companies.models import Company, TelevisionBanner, WebsiteBanner, TelevisionVideo


class CompanyAdmin(admin.ModelAdmin):
Expand All @@ -14,8 +14,12 @@ class WebsiteBannerAdmin(admin.ModelAdmin):

class TelevisionBannerAdmin(admin.ModelAdmin):
list_display = ['name', 'start_date', 'end_date', 'active']

class TelevisionVideoAdmin(admin.ModelAdmin):
list_display = ['name', 'start_date', 'end_date', 'active']


admin.site.register(Company, CompanyAdmin)
admin.site.register(WebsiteBanner, WebsiteBannerAdmin)
admin.site.register(TelevisionBanner, TelevisionBannerAdmin)
admin.site.register(TelevisionVideo, TelevisionVideoAdmin)
29 changes: 29 additions & 0 deletions amelie/companies/migrations/0006_televisionvideo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Generated by Django 3.2.16 on 2023-02-06 21:05

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('companies', '0005_add_default_career_label'),
]

operations = [
migrations.CreateModel(
name='TelevisionVideo',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100)),
('start_date', models.DateField()),
('end_date', models.DateField()),
('active', models.BooleanField(default=True)),
('video_id', models.CharField(max_length=12)),
],
options={
'verbose_name': 'Television Promotion Video',
'verbose_name_plural': 'Television Promotion Videos',
'ordering': ['-start_date'],
},
),
]
18 changes: 18 additions & 0 deletions amelie/companies/migrations/0007_televisionvideo_video_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.16 on 2023-02-06 22:02

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('companies', '0006_televisionvideo'),
]

operations = [
migrations.AddField(
model_name='televisionvideo',
name='video_type',
field=models.CharField(choices=[('youtube', 'YouTube'), ('streamingia', 'StreamingIA')], default='streamingia', max_length=11),
),
]
27 changes: 27 additions & 0 deletions amelie/companies/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from amelie.companies.managers import CompanyManager
from amelie.calendar.managers import EventManager
from amelie.calendar.models import Event
from amelie.activities.models import ActivityLabel
from amelie.tools.discord import send_discord

class Company(models.Model):
Expand Down Expand Up @@ -175,9 +176,31 @@ class Meta:
ordering = ['-end_date']
verbose_name = _('Television banner')
verbose_name_plural = _('Television banners')


class TelevisionVideo(models.Model):
class VideoTypes(models.TextChoices):
YOUTUBE = 'youtube', 'YouTube'
STREAMINGIA = 'streamingia', 'StreamingIA'

name = models.CharField(max_length=100)
start_date = models.DateField()
end_date = models.DateField()
active = models.BooleanField(default=True)
video_id = models.CharField(max_length=12)
video_type = models.CharField(
max_length=11,
choices=VideoTypes.choices,
default=VideoTypes.STREAMINGIA)

class Meta:
ordering = ['-start_date']
verbose_name = _('Television Promotion Video')
verbose_name_plural = _('Television Promotion Videos')


class CompanyEvent(Event):

objects = EventManager()
company = models.ForeignKey('Company', blank=True, null=True, on_delete=models.SET_NULL)
company_text = models.CharField(max_length=100, blank=True)
Expand All @@ -186,6 +209,10 @@ class CompanyEvent(Event):
visible_from = models.DateTimeField()
visible_till = models.DateTimeField()

@property
def activity_label(self):
return ActivityLabel.objects.filter(name_en="Career").first()

@property
def activity_type(self):
return "external"
Expand Down
4 changes: 1 addition & 3 deletions amelie/narrowcasting/static/css/narrowcasting.css
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@ body {
}

.footer {
height: 137px;
padding: 15px 793px 15px 30px;
padding: 7.5px 793px 7.5px 20px;
box-shadow: -25px 25px 215px 25px #222222;
}

Expand All @@ -143,7 +142,6 @@ body {

.news-header {
font-size:24px;
margin-bottom:5px;
}

.news-header span {
Expand Down
29 changes: 19 additions & 10 deletions amelie/narrowcasting/static/js/promotion_widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ function PromotionWidget() {

this.television_promotions = [];
this.current_promotion = null;
this.current_idx = 0;
this.ticks = 0;
this.duration = 0;
}
Expand Down Expand Up @@ -36,12 +37,15 @@ PromotionWidget.prototype.tick = function () {

PromotionWidget.prototype.change_photo = function () {
if (this.television_promotions.length > 0){
var res = this.television_promotions.indexOf(this.current_promotion);

if (res >= 0) {
this.current_promotion = this.television_promotions[(res + 1) % (this.television_promotions.length)];
if (this.current_idx >= 0) {
var idx = (this.current_idx + 1) % this.television_promotions.length;

this.current_promotion = this.television_promotions[idx];
this.current_idx = idx;
} else if (this.television_promotions.length > 0) {
this.current_promotion = this.television_promotions[0];
this.current_idx = 0;
}

var photo_url = this.current_promotion.image;
Expand All @@ -54,12 +58,16 @@ PromotionWidget.prototype.change_photo = function () {
}).load(function(){
$(".photo-wrapper #photo").remove();
$(".photo-wrapper").append($(this));
if(self.current_promotion.title != undefined){
$("#photo-activity").html(self.current_promotion.title);
} else {
// This is a hack, hiding and showing does not yet work correctly
$("#photo-activity").html("Promotion");
}

// if(self.current_promotion.title != undefined){
// $("#photo-activity").html(self.current_promotion.title);
// } else {
// // This is a hack, hiding and showing does not yet work correctly
// $("#photo-activity").html("Promotion");
// }

$("#photo-activity").hide();

if($(this).height() > $(this).width()){
$("#photo").addClass("portrait");
}
Expand All @@ -71,4 +79,5 @@ PromotionWidget.prototype.change_photo = function () {
}
};

PromotionWidget.prototype.get_duration = function () { return this.duration; };
// PromotionWidget.prototype.get_duration = function () { return this.duration; };
PromotionWidget.prototype.get_duration = function () { return 5; };
Loading