Skip to content
Snippets Groups Projects
Commit 0c2a864c authored by Ernesto Rico Schmidt's avatar Ernesto Rico Schmidt Committed by GitHub
Browse files

Merge pull request #3 from radio-helsinki-graz/recognize_activity

Recognize activity
parents 6990ff7f 8531fd17
No related branches found
No related tags found
No related merge requests found
...@@ -7,6 +7,47 @@ from forms import MusicFocusForm ...@@ -7,6 +7,47 @@ from forms import MusicFocusForm
from datetime import date, datetime, timedelta from datetime import date, datetime, timedelta
class ActivityFilter(admin.SimpleListFilter):
title = _("Activity")
def lookups(self, request, model_admin):
return (
('yes', _("active")),
('no', _("inactive"))
)
def queryset(self, request, queryset):
if self.parameter_name == 'has_timeslots': # active/inactive ProgramSlots
if self.value() == 'yes':
return queryset.filter(until__gt=datetime.now()).distinct()
if self.value() == 'no':
return queryset.filter(until__lt=datetime.now()).distinct()
if self.parameter_name == 'has_programslots_timeslots': # active/inactive Shows
if self.value() == 'yes':
return queryset.filter(programslots__until__gt=datetime.now()).distinct()
if self.value() == 'no':
return queryset.filter(programslots__until__lt=datetime.now()).distinct()
if self.parameter_name == 'has_shows_programslots_timeslots': # active/inactive Hosts
if self.value() == 'yes':
return queryset.filter(shows__programslots__until__gt=datetime.now()).distinct()
if self.value() == 'no':
return queryset.filter(shows__programslots__until__lt=datetime.now()).distinct()
class ActiveProgramSlotsFilter(ActivityFilter):
parameter_name = 'has_timeslots'
class ActiveShowsFilter(ActivityFilter):
parameter_name = 'has_programslots_timeslots'
class ActiveHostsFilter(ActivityFilter):
parameter_name = 'has_shows_programslots_timeslots'
class BroadcastFormatAdmin(admin.ModelAdmin): class BroadcastFormatAdmin(admin.ModelAdmin):
list_display = ('format', 'admin_color', 'enabled') list_display = ('format', 'admin_color', 'enabled')
prepopulated_fields = {'slug': ('format',)} prepopulated_fields = {'slug': ('format',)}
...@@ -29,8 +70,8 @@ class ShowTopicAdmin(admin.ModelAdmin): ...@@ -29,8 +70,8 @@ class ShowTopicAdmin(admin.ModelAdmin):
class HostAdmin(admin.ModelAdmin): class HostAdmin(admin.ModelAdmin):
list_display = ('name', 'is_active') list_display = ('name',)
list_filter = ('is_active', 'is_always_visible') list_filter = (ActiveHostsFilter, 'is_always_visible',)
class NoteAdmin(admin.ModelAdmin): class NoteAdmin(admin.ModelAdmin):
...@@ -73,7 +114,7 @@ class ProgramSlotAdmin(admin.ModelAdmin): ...@@ -73,7 +114,7 @@ class ProgramSlotAdmin(admin.ModelAdmin):
inlines = (TimeSlotInline,) inlines = (TimeSlotInline,)
fields = (('rrule', 'byweekday'), ('dstart', 'tstart', 'tend'), 'until', 'is_repetition', 'automation_id') fields = (('rrule', 'byweekday'), ('dstart', 'tstart', 'tend'), 'until', 'is_repetition', 'automation_id')
list_display = ('get_show_name', 'byweekday', 'rrule', 'tstart', 'tend', 'until') list_display = ('get_show_name', 'byweekday', 'rrule', 'tstart', 'tend', 'until')
list_filter = ('is_active', 'byweekday', 'rrule', 'is_repetition') list_filter = (ActiveProgramSlotsFilter, 'byweekday', 'rrule', 'is_repetition')
ordering = ('byweekday', 'dstart') ordering = ('byweekday', 'dstart')
save_on_top = True save_on_top = True
search_fields = ('show__name',) search_fields = ('show__name',)
...@@ -85,7 +126,7 @@ class ProgramSlotAdmin(admin.ModelAdmin): ...@@ -85,7 +126,7 @@ class ProgramSlotAdmin(admin.ModelAdmin):
if renewed == 1: if renewed == 1:
message = _("1 program slot was renewed until %s") % until message = _("1 program slot was renewed until %s") % until
else: else:
message = _("%s program slots were renewed until %s") % until message = _("%s program slots were renewed until %s") % (renewed, until)
self.message_user(request, message) self.message_user(request, message)
renew.short_description = _("Renew selected program slots") renew.short_description = _("Renew selected program slots")
...@@ -103,8 +144,8 @@ class ProgramSlotInline(admin.TabularInline): ...@@ -103,8 +144,8 @@ class ProgramSlotInline(admin.TabularInline):
class ShowAdmin(admin.ModelAdmin): class ShowAdmin(admin.ModelAdmin):
filter_horizontal = ('hosts', 'owners', 'musicfocus', 'showinformation', 'showtopic') filter_horizontal = ('hosts', 'owners', 'musicfocus', 'showinformation', 'showtopic')
inlines = (ProgramSlotInline,) inlines = (ProgramSlotInline,)
list_display = ('name', 'short_description', 'is_active') list_display = ('name', 'short_description')
list_filter = ('is_active', 'broadcastformat', 'showinformation', 'showtopic', 'musicfocus') list_filter = (ActiveShowsFilter, 'broadcastformat', 'showinformation', 'showtopic', 'musicfocus')
ordering = ('slug',) ordering = ('slug',)
prepopulated_fields = {'slug': ('name',)} prepopulated_fields = {'slug': ('name',)}
search_fields = ('name', 'short_description', 'description') search_fields = ('name', 'short_description', 'description')
......
from django.core.management.base import NoArgsCommand
from program.models import Host
class Command(NoArgsCommand):
help = 'update host by setting is_active'
def handle_noargs(self, **options):
activated = 0
deactivated = 0
for host in Host.objects.all():
active_shows = 0
for show in host.shows.all():
if show.is_active:
active_shows += 1
else:
active_shows -= 1
host.is_active = active_shows > 0
host.save()
if host.is_active:
activated += 1
else:
deactivated += 1
print "%s hosts activated, %s hosts de-activated " % (activated, deactivated)
from django.core.management.base import NoArgsCommand
from program.models import ProgramSlot
from datetime import datetime
class Command(NoArgsCommand):
help = 'update programslots by setting is_active'
def handle_noargs(self, **options):
deactivated = ProgramSlot.objects.filter(until__lt=datetime.now()).update(is_active=False)
activated = ProgramSlot.objects.filter(until__gt=datetime.now()).update(is_active=True)
print "%s program slots activated, %s program slots de-activated" % (activated, deactivated)
from django.core.management.base import NoArgsCommand
from program.models import Show
from datetime import datetime
class Command(NoArgsCommand):
help = 'update shows by setting is_active'
def handle_noargs(self, **options):
deactivated = Show.objects.exclude(id=1).filter(programslots__until__lt=datetime.now()).update(is_active=False)
activated = Show.objects.exclude(id=1).filter(programslots__until__gt=datetime.now()).distinct().update(is_active=True)
print "%s shows activated, %s shows de-activated" % (activated, deactivated)
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('program', '0008_show_remove_automation_id'),
]
operations = [
migrations.RemoveField(
model_name='host',
name='is_active',
),
]
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('program', '0009_host_remove_is_active'),
]
operations = [
migrations.RemoveField(
model_name='show',
name='is_active',
),
]
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('program', '0010_show_remove_is_active'),
]
operations = [
migrations.RemoveField(
model_name='programslot',
name='is_active',
),
]
...@@ -211,7 +211,6 @@ class MusicFocus(models.Model): ...@@ -211,7 +211,6 @@ class MusicFocus(models.Model):
class Host(models.Model): class Host(models.Model):
name = models.CharField(_("Name"), max_length=128) name = models.CharField(_("Name"), max_length=128)
is_always_visible = models.BooleanField(_("Is always visible"), default=False) is_always_visible = models.BooleanField(_("Is always visible"), default=False)
is_active = models.BooleanField(_("Is active"), default=True, editable=False)
email = models.EmailField(_("E-Mail"), blank=True) email = models.EmailField(_("E-Mail"), blank=True)
website = models.URLField(_("Website"), blank=True) website = models.URLField(_("Website"), blank=True)
...@@ -243,7 +242,6 @@ class Show(models.Model): ...@@ -243,7 +242,6 @@ class Show(models.Model):
description = tinymce_models.HTMLField(_("Description"), blank=True, null=True) description = tinymce_models.HTMLField(_("Description"), blank=True, null=True)
email = models.EmailField(_("E-Mail"), blank=True, null=True) email = models.EmailField(_("E-Mail"), blank=True, null=True)
website = models.URLField(_("Website"), blank=True, null=True) website = models.URLField(_("Website"), blank=True, null=True)
is_active = models.BooleanField(_("Is active"), default=True, editable=False)
created = models.DateTimeField(auto_now_add=True, editable=False) created = models.DateTimeField(auto_now_add=True, editable=False)
last_updated = models.DateTimeField(auto_now=True, editable=False) last_updated = models.DateTimeField(auto_now=True, editable=False)
...@@ -306,7 +304,6 @@ class ProgramSlot(models.Model): ...@@ -306,7 +304,6 @@ class ProgramSlot(models.Model):
tstart = models.TimeField(_("Start time")) tstart = models.TimeField(_("Start time"))
tend = models.TimeField(_("End time")) tend = models.TimeField(_("End time"))
until = models.DateField(_("Last date")) until = models.DateField(_("Last date"))
is_active = models.BooleanField(_("Is active"), default=True, editable=False)
is_repetition = models.BooleanField(_("Is repetition"), default=False) is_repetition = models.BooleanField(_("Is repetition"), default=False)
automation_id = models.IntegerField(_("Automation ID"), blank=True, null=True, choices=get_automation_id_choices()) automation_id = models.IntegerField(_("Automation ID"), blank=True, null=True, choices=get_automation_id_choices())
created = models.DateTimeField(auto_now_add=True, editable=False) created = models.DateTimeField(auto_now_add=True, editable=False)
...@@ -351,9 +348,6 @@ class ProgramSlot(models.Model): ...@@ -351,9 +348,6 @@ class ProgramSlot(models.Model):
else: else:
old = False old = False
self.is_active = self.until > date.today()
self.show.is_active = self.until > date.today()
super(ProgramSlot, self).save(*args, **kwargs) super(ProgramSlot, self).save(*args, **kwargs)
if self.rrule.freq == 0: if self.rrule.freq == 0:
......
...@@ -10,12 +10,7 @@ ...@@ -10,12 +10,7 @@
<div id="shows"> <div id="shows">
<div id="shows-title">Sendungen</div> <div id="shows-title">Sendungen</div>
{% for show in host.shows.all %} {% for show in host.shows.all %}
{% if show.is_active %} <div class="show {{ show.broadcastformat.slug }}">{{ show }}</div>
<div class="show {{ show.broadcastformat.slug }}"><a
href="{% url "show-detail" show.slug %}">{{ show }}</a></div>
{% else %}
<div class="show {{ show.broadcastformat.slug }}">{{ show }}</div>
{% endif %}
{% endfor %} {% endfor %}
</div> </div>
......
...@@ -14,9 +14,7 @@ ...@@ -14,9 +14,7 @@
{% if show.id != 1 %} {% if show.id != 1 %}
<p id="programslots"> <p id="programslots">
{% for slot in show.programslots.all %} {% for slot in show.programslots.all %}
{% if slot.is_active %} <span class="programslot">{{ slot }}</span><br/>
<span class="programslot">{{ slot }}</span><br/>
{% endif %}
{% endfor %} {% endfor %}
</p> </p>
{% endif %} {% endif %}
......
...@@ -41,9 +41,7 @@ ...@@ -41,9 +41,7 @@
<h3 class="show-title"><a href="{% url "show-detail" show.slug %}">{{ show.name }}</a></h3> <h3 class="show-title"><a href="{% url "show-detail" show.slug %}">{{ show.name }}</a></h3>
<ul class="show-programslots"> <ul class="show-programslots">
{% for programslot in show.programslots.all %} {% for programslot in show.programslots.all %}
{% if programslot.is_active %} <li class="show-programslot">{{ programslot }}</li>
<li class="show-programslot">{{ programslot }}</li>
{% endif %}
{% endfor %} {% endfor %}
</ul> </ul>
<p class="show-description">{{ show.short_description }}</p> <p class="show-description">{{ show.short_description }}</p>
......
...@@ -15,19 +15,19 @@ from program.utils import tofirstdayinisoweek ...@@ -15,19 +15,19 @@ from program.utils import tofirstdayinisoweek
class HostListView(ListView): class HostListView(ListView):
context_object_name = 'host_list' context_object_name = 'host_list'
queryset = Host.objects.filter(Q(is_active=True) | Q(is_always_visible=True)).distinct() queryset = Host.objects.filter(is_always_visible=True).distinct()
template_name = 'host_list.html' template_name = 'host_list.html'
class HostDetailView(DetailView): class HostDetailView(DetailView):
context_object_name = 'host' context_object_name = 'host'
queryset = Host.objects.filter(Q(is_active=True) | Q(is_always_visible=True)).distinct() queryset = Host.objects.filter(is_always_visible=True).distinct()
template_name = 'host_detail.html' template_name = 'host_detail.html'
class ShowListView(ListView): class ShowListView(ListView):
context_object_name = 'show_list' context_object_name = 'show_list'
queryset = Show.objects.filter(is_active=True).exclude(id=1).distinct() queryset = Show.objects.exclude(id=1).distinct()
template_name = 'show_list.html' template_name = 'show_list.html'
def get_queryset(self): def get_queryset(self):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment