From 9e422edfb26a694e5e629e43412537f9b53be1be Mon Sep 17 00:00:00 2001
From: Ernesto Rico Schmidt <ernesto@helsinki.at>
Date: Tue, 11 Jan 2022 18:14:44 -0400
Subject: [PATCH] Remove buttons and colors from models, admin, serializers and
 fixtures

---
 fixtures/program/category.json                |  40 +----
 fixtures/program/musicfocus.json              |  50 ++-----
 fixtures/program/topic.json                   |  25 +---
 fixtures/program/type.json                    |  28 +---
 program/admin.py                              |  17 +--
 program/forms.py                              |  68 ---------
 program/migrations/0004_auto_20220111_1806.py |  64 ++++++++
 program/migrations/0005_auto_20220111_2251.py |  21 +++
 program/models.py                             | 139 ------------------
 program/serializers.py                        |   3 -
 10 files changed, 120 insertions(+), 335 deletions(-)
 delete mode 100644 program/forms.py
 create mode 100644 program/migrations/0004_auto_20220111_1806.py
 create mode 100644 program/migrations/0005_auto_20220111_2251.py

diff --git a/fixtures/program/category.json b/fixtures/program/category.json
index f0c3aa28..45b7facc 100644
--- a/fixtures/program/category.json
+++ b/fixtures/program/category.json
@@ -8,10 +8,7 @@
       "slug": "interkulturell",
       "is_active": true,
       "color": "",
-      "description": "",
-      "button": "",
-      "button_hover": "",
-      "big_button": ""
+      "description": ""
     }
   },
   {
@@ -23,10 +20,7 @@
       "slug": "lokalbezug",
       "is_active": true,
       "color": "",
-      "description": "",
-      "button": "",
-      "button_hover": "",
-      "big_button": ""
+      "description": ""
     }
   },
   {
@@ -38,10 +32,7 @@
       "slug": "minderheiten",
       "is_active": true,
       "color": "",
-      "description": "",
-      "button": "",
-      "button_hover": "",
-      "big_button": ""
+      "description": ""
     }
   },
   {
@@ -53,10 +44,7 @@
       "slug": "wiederholung",
       "is_active": true,
       "color": "",
-      "description": "",
-      "button": "",
-      "button_hover": "",
-      "big_button": ""
+      "description": ""
     }
   },
   {
@@ -68,10 +56,7 @@
       "slug": "mehr-fremdsprachig",
       "is_active": true,
       "color": "",
-      "description": "",
-      "button": "",
-      "button_hover": "",
-      "big_button": ""
+      "description": ""
     }
   },
   {
@@ -83,10 +68,7 @@
       "slug": "frauenschwerpunkt",
       "is_active": true,
       "color": "",
-      "description": "",
-      "button": "",
-      "button_hover": "",
-      "big_button": ""
+      "description": ""
     }
   },
   {
@@ -98,10 +80,7 @@
       "slug": "osterreichische-musik",
       "is_active": true,
       "color": "",
-      "description": "",
-      "button": "",
-      "button_hover": "",
-      "big_button": ""
+      "description": ""
     }
   },
   {
@@ -113,10 +92,7 @@
       "slug": "sendungsubernahme",
       "is_active": true,
       "color": "",
-      "description": "",
-      "button": "",
-      "button_hover": "",
-      "big_button": ""
+      "description": ""
     }
   }
 ]
diff --git a/fixtures/program/musicfocus.json b/fixtures/program/musicfocus.json
index d301e403..b2ef22a6 100644
--- a/fixtures/program/musicfocus.json
+++ b/fixtures/program/musicfocus.json
@@ -6,10 +6,7 @@
       "focus": "Jazz",
       "abbrev": "J",
       "slug": "jazz",
-      "is_active": true,
-      "button": "",
-      "button_hover": "",
-      "big_button": ""
+      "is_active": true
     }
   },
   {
@@ -19,10 +16,7 @@
       "focus": "Volksmusik/Folk",
       "abbrev": "V",
       "slug": "volksmusik-folk",
-      "is_active": true,
-      "button": "",
-      "button_hover": "",
-      "big_button": ""
+      "is_active": true
     }
   },
   {
@@ -32,10 +26,7 @@
       "focus": "Experimentelle Musik",
       "abbrev": "Ex",
       "slug": "expermentelle-musik",
-      "is_active": true,
-      "button": "",
-      "button_hover": "",
-      "big_button": ""
+      "is_active": true
     }
   },
   {
@@ -45,10 +36,7 @@
       "focus": "Rock/Indie",
       "abbrev": "R",
       "slug": "rock-indie",
-      "is_active": true,
-      "button": "",
-      "button_hover": "",
-      "big_button": ""
+      "is_active": true
     }
   },
   {
@@ -58,10 +46,7 @@
       "focus": "Metal/Hardrock",
       "abbrev": "M",
       "slug": "metal-hardrock",
-      "is_active": true,
-      "button": "",
-      "button_hover": "",
-      "big_button": ""
+      "is_active": true
     }
   },
   {
@@ -71,10 +56,7 @@
       "focus": "Electronic",
       "abbrev": "E",
       "slug": "electronic",
-      "is_active": true,
-      "button": "",
-      "button_hover": "",
-      "big_button": ""
+      "is_active": true
     }
   },
   {
@@ -84,10 +66,7 @@
       "focus": "Klassik",
       "abbrev": "K",
       "slug": "klassik",
-      "is_active": true,
-      "button": "",
-      "button_hover": "",
-      "big_button": ""
+      "is_active": true
     }
   },
   {
@@ -97,10 +76,7 @@
       "focus": "Oldies",
       "abbrev": "O",
       "slug": "oldies",
-      "is_active": true,
-      "button": "",
-      "button_hover": "",
-      "big_button": ""
+      "is_active": true
     }
   },
   {
@@ -110,10 +86,7 @@
       "focus": "Reggae/Ska",
       "abbrev": "Re",
       "slug": "reggae-ska",
-      "is_active": true,
-      "button": "",
-      "button_hover": "",
-      "big_button": ""
+      "is_active": true
     }
   },
   {
@@ -123,10 +96,7 @@
       "focus": "Hiphop",
       "abbrev": "H",
       "slug": "hiphop",
-      "is_active": true,
-      "button": "",
-      "button_hover": "",
-      "big_button": ""
+      "is_active": true
     }
   }
 ]
diff --git a/fixtures/program/topic.json b/fixtures/program/topic.json
index 93ce5e19..5969364f 100644
--- a/fixtures/program/topic.json
+++ b/fixtures/program/topic.json
@@ -6,10 +6,7 @@
       "topic": "Politik/Gesellschaft",
       "abbrev": "P",
       "slug": "politik-gesellschaft",
-      "is_active": true,
-      "button": "",
-      "button_hover": "",
-      "big_button": ""
+      "is_active": true
     }
   },
   {
@@ -19,10 +16,7 @@
       "topic": "Natur/Klima/Tiere",
       "abbrev": "N",
       "slug": "natur-klima-tiere",
-      "is_active": true,
-      "button": "",
-      "button_hover": "",
-      "big_button": ""
+      "is_active": true
     }
   },
   {
@@ -32,10 +26,7 @@
       "topic": "Kultur/Kunst",
       "abbrev": "K",
       "slug": "kultur-kunst",
-      "is_active": true,
-      "button": "",
-      "button_hover": "",
-      "big_button": ""
+      "is_active": true
     }
   },
   {
@@ -45,10 +36,7 @@
       "topic": "Soziales",
       "abbrev": "S",
       "slug": "soziales",
-      "is_active": true,
-      "button": "",
-      "button_hover": "",
-      "big_button": ""
+      "is_active": true
     }
   },
   {
@@ -58,10 +46,7 @@
       "topic": "Wissenschaft/Philosophie",
       "abbrev": "W",
       "slug": "wissenschaft-philosophie",
-      "is_active": true,
-      "button": "",
-      "button_hover": "",
-      "big_button": ""
+      "is_active": true
     }
   }
 ]
diff --git a/fixtures/program/type.json b/fixtures/program/type.json
index e7492c21..8b8c1dc7 100644
--- a/fixtures/program/type.json
+++ b/fixtures/program/type.json
@@ -5,9 +5,7 @@
     "fields": {
       "type": "Talk",
       "slug": "talk",
-      "is_active": true,
-      "color": "#ffffff",
-      "text_color": "#000000"
+      "is_active": true
     }
   },
   {
@@ -16,9 +14,7 @@
     "fields": {
       "type": "Musiksendung",
       "slug": "musiksendung",
-      "is_active": true,
-      "color": "#ffffff",
-      "text_color": "#000000"
+      "is_active": true
     }
   },
   {
@@ -27,9 +23,7 @@
     "fields": {
       "type": "Unmoderiertes Musikprogramm",
       "slug": "unmoderiertes-musikprogramm",
-      "is_active": true,
-      "color": "#ffffff",
-      "text_color": "#000000"
+      "is_active": true
     }
   },
   {
@@ -38,9 +32,7 @@
     "fields": {
       "type": "Feature/Magazin",
       "slug": "feature-magazin",
-      "is_active": true,
-      "color": "#ffffff",
-      "text_color": "#000000"
+      "is_active": true
     }
   },
   {
@@ -49,9 +41,7 @@
     "fields": {
       "type": "Experimentell",
       "slug": "experimentell",
-      "is_active": true,
-      "color": "#ffffff",
-      "text_color": "#000000"
+      "is_active": true
     }
   },
   {
@@ -60,9 +50,7 @@
     "fields": {
       "type": "Hörspiel/Literatur",
       "slug": "horspiel-literatur",
-      "is_active": true,
-      "color": "#ffffff",
-      "text_color": "#000000"
+      "is_active": true
     }
   },
   {
@@ -71,9 +59,7 @@
     "fields": {
       "type": "Vortrag/Diskussion",
       "slug": "vortrag-diskussion",
-      "is_active": true,
-      "color": "#ffffff",
-      "text_color": "#000000"
+      "is_active": true
     }
   }
 ]
diff --git a/program/admin.py b/program/admin.py
index bbbc6fd0..01d4c493 100644
--- a/program/admin.py
+++ b/program/admin.py
@@ -18,17 +18,11 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 
-from datetime import date, datetime, timedelta
-
-from django.conf import settings
 from django.contrib import admin
-from django.core.exceptions import ObjectDoesNotExist
-from django.shortcuts import render
 from django.utils import timezone
 from django.utils.translation import ugettext_lazy as _
 
-from .forms import MusicFocusForm
-from .models import Language, Type, MusicFocus, Category, Topic, FundingCategory, Host, Note, RRule, Schedule, Show, TimeSlot
+from .models import Language, Type, MusicFocus, Category, Topic, FundingCategory, Host
 
 
 class ActivityFilter(admin.SimpleListFilter):
@@ -73,20 +67,19 @@ class ActiveHostsFilter(ActivityFilter):
 
 
 class TypeAdmin(admin.ModelAdmin):
-    list_display = ('type', 'admin_color', 'is_active')
+    list_display = ('type', 'is_active')
     list_filter = ('is_active',)
     prepopulated_fields = {'slug': ('type',)}
 
 
 class MusicFocusAdmin(admin.ModelAdmin):
-    form = MusicFocusForm
-    list_display = ('focus', 'abbrev', 'admin_buttons', 'is_active')
+    list_display = ('focus', 'abbrev', 'is_active')
     list_filter = ('is_active',)
     prepopulated_fields = {'slug': ('focus',)}
 
 
 class CategoryAdmin(admin.ModelAdmin):
-    list_display = ('category', 'abbrev', 'admin_buttons', 'is_active')
+    list_display = ('category', 'abbrev', 'is_active')
     list_filter = ('is_active',)
     prepopulated_fields = {'slug': ('category',)}
 
@@ -97,7 +90,7 @@ class LanguageAdmin(admin.ModelAdmin):
 
 
 class TopicAdmin(admin.ModelAdmin):
-    list_display = ('topic', 'abbrev', 'admin_buttons', 'is_active')
+    list_display = ('topic', 'abbrev', 'is_active')
     list_filter = ('is_active',)
     prepopulated_fields = {'slug': ('topic',)}
 
diff --git a/program/forms.py b/program/forms.py
deleted file mode 100644
index aa3a907d..00000000
--- a/program/forms.py
+++ /dev/null
@@ -1,68 +0,0 @@
-#
-# steering, Programme/schedule management for AURA
-#
-# Copyright (C) 2011-2017, 2020, Ernesto Rico Schmidt
-# Copyright (C) 2017-2019, Ingo Leindecker
-#
-# This program is free software: you can redistribute it and/or modify it under
-# the terms of the GNU Affero General Public License as published by the Free
-# Software Foundation, either version 3 of the License, or (at your option) any
-# later version.
-#
-# This program is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-# FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
-# details.
-#
-# You should have received a copy of the GNU Affero General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-#
-
-from django.core.files.images import get_image_dimensions
-from django.forms import ModelForm, ValidationError
-
-from program.models import MusicFocus, Category, Topic
-
-
-class FormWithButton(ModelForm):
-    def clean_button(self):
-        button = self.cleaned_data.get('button')
-        if button:
-            width, height = get_image_dimensions(button)
-            if width != 11 or height != 11:
-                raise ValidationError("width or height is not 11, (11x11)")
-        return button
-
-    def clean_button_hover(self):
-        button_hover = self.cleaned_data.get('button_hover')
-        if button_hover:
-            width, height = get_image_dimensions(button_hover)
-            if width != 11 or height != 11:
-                raise ValidationError("width or height is not 11, (11x11)")
-        return button_hover
-
-    def clean_big_button(self):
-        big_button = self.cleaned_data.get('big_button')
-        if big_button:
-            width, height = get_image_dimensions(big_button)
-            if width != 17 or height != 17:
-                raise ValidationError("width or height is not 17, (17x17)")
-        return big_button
-
-
-class MusicFocusForm(FormWithButton):
-    class Meta:
-        model = MusicFocus
-        fields = '__all__'
-
-
-class CategoryForm(FormWithButton):
-    class Meta:
-        model = Category
-        fields = '__all__'
-
-
-class TopicForm(FormWithButton):
-    class Meta:
-        model = Topic
-        fields = '__all__'
diff --git a/program/migrations/0004_auto_20220111_1806.py b/program/migrations/0004_auto_20220111_1806.py
new file mode 100644
index 00000000..2a7706ec
--- /dev/null
+++ b/program/migrations/0004_auto_20220111_1806.py
@@ -0,0 +1,64 @@
+# Generated by Django 2.2.25 on 2022-01-11 17:06
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('program', '0003_auto_20210713_0420'),
+    ]
+
+    operations = [
+        migrations.RemoveField(
+            model_name='category',
+            name='big_button',
+        ),
+        migrations.RemoveField(
+            model_name='category',
+            name='button',
+        ),
+        migrations.RemoveField(
+            model_name='category',
+            name='button_hover',
+        ),
+        migrations.RemoveField(
+            model_name='musicfocus',
+            name='big_button',
+        ),
+        migrations.RemoveField(
+            model_name='musicfocus',
+            name='button',
+        ),
+        migrations.RemoveField(
+            model_name='musicfocus',
+            name='button_hover',
+        ),
+        migrations.RemoveField(
+            model_name='topic',
+            name='big_button',
+        ),
+        migrations.RemoveField(
+            model_name='topic',
+            name='button',
+        ),
+        migrations.RemoveField(
+            model_name='topic',
+            name='button_hover',
+        ),
+        migrations.AlterField(
+            model_name='note',
+            name='slug',
+            field=models.SlugField(help_text='A simple to read URL for your show.', max_length=32, unique=True, verbose_name='Slug'),
+        ),
+        migrations.AlterField(
+            model_name='schedule',
+            name='default_playlist_id',
+            field=models.IntegerField(blank=True, null=True, verbose_name='Default Playlist ID'),
+        ),
+        migrations.AlterField(
+            model_name='show',
+            name='default_playlist_id',
+            field=models.IntegerField(blank=True, help_text='If a timeslot of your show is empty, this playlist will be aired as a backup.', null=True, verbose_name='Default Playlist ID'),
+        ),
+    ]
diff --git a/program/migrations/0005_auto_20220111_2251.py b/program/migrations/0005_auto_20220111_2251.py
new file mode 100644
index 00000000..7e8f0576
--- /dev/null
+++ b/program/migrations/0005_auto_20220111_2251.py
@@ -0,0 +1,21 @@
+# Generated by Django 2.2.25 on 2022-01-11 21:51
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('program', '0004_auto_20220111_1806'),
+    ]
+
+    operations = [
+        migrations.RemoveField(
+            model_name='type',
+            name='color',
+        ),
+        migrations.RemoveField(
+            model_name='type',
+            name='text_color',
+        ),
+    ]
diff --git a/program/models.py b/program/models.py
index 23d4381d..8c874061 100644
--- a/program/models.py
+++ b/program/models.py
@@ -43,21 +43,12 @@ class Type(models.Model):
     type = models.CharField(_("Type"), max_length=32)
     slug = models.SlugField(_("Slug"), max_length=32, unique=True)
     is_active = models.BooleanField(_("Is active?"), default=True)
-    color = models.CharField(_("Color"), max_length=7, default='#ffffff')
-    text_color = models.CharField(_("Text color"), max_length=7, default='#000000')
 
     class Meta:
         ordering = ('type',)
         verbose_name = _("Type")
         verbose_name_plural = _("Types")
 
-    def admin_color(self):
-        return '<span style="background-color: %s; color: %s; padding: 0.2em">%s/%s</span>' % (
-            self.color, self.text_color, self.color, self.text_color)
-
-    admin_color.short_description = _("Color")
-    admin_color.allow_tags = True
-
     def __str__(self):
         return '%s' % self.type
 
@@ -67,57 +58,13 @@ class Category(models.Model):
     abbrev = models.CharField(_("Abbreviation"), max_length=4, unique=True)
     slug = models.SlugField(_("Slug"), max_length=32, unique=True)
     is_active = models.BooleanField(_("Is active?"), default=True)
-    color = models.TextField(_("Color"), max_length=7, blank=True)
     description = models.TextField(_("Description"), blank=True)
-    button = models.ImageField(_("Button image"), blank=True, null=True, upload_to='buttons')
-    button_hover = models.ImageField(_("Button image (hover)"), blank=True, null=True, upload_to='buttons')
-    big_button = models.ImageField(_("Big button image"), blank=True, null=True, upload_to='buttons')
 
     class Meta:
         ordering = ('category',)
         verbose_name = _("Category")
         verbose_name_plural = _("Categories")
 
-    def admin_buttons(self):
-        buttons = []
-        if self.button:
-            buttons.append('<img src="%s" />' % self.button.url)
-        else:
-            buttons.append('x')
-
-        if self.button_hover:
-            buttons.append('<img src="%s" />' % self.button_hover.url)
-        else:
-            buttons.append('x')
-
-        if self.big_button:
-            buttons.append('<img src="%s" />' % self.big_button.url)
-        else:
-            buttons.append('x')
-
-        return ' '.join(buttons)
-
-    admin_buttons.short_description = _("Buttons")
-    admin_buttons.allow_tags = True
-
-    def button_url(self):
-        if self.button:
-            return self.button.url
-        else:
-            return '/site_media/buttons/default-11.png'
-
-    def button_hover_url(self):
-        if self.button_hover:
-            return self.button_hover.url
-        else:
-            return '/site_media/buttons/default-11.png'
-
-    def big_button_url(self):
-        if self.big_button:
-            return self.big_button.url
-        else:
-            return '/site_media/buttons/default-17.png'
-
     def __str__(self):
         return '%s' % self.category
 
@@ -127,55 +74,12 @@ class Topic(models.Model):
     abbrev = models.CharField(_("Abbreviation"), max_length=4, unique=True)
     slug = models.SlugField(_("Slug"), max_length=32, unique=True)
     is_active = models.BooleanField(_("Is active?"), default=True)
-    button = models.ImageField(_("Button image"), blank=True, null=True, upload_to='buttons')
-    button_hover = models.ImageField(_("Button image (hover)"), blank=True, null=True, upload_to='buttons')
-    big_button = models.ImageField(_("Big button image"), blank=True, null=True, upload_to='buttons')
 
     class Meta:
         ordering = ('topic',)
         verbose_name = _("Topic")
         verbose_name_plural = _("Topics")
 
-    def admin_buttons(self):
-        buttons = []
-        if self.button:
-            buttons.append('<img src="%s" />' % self.button.url)
-        else:
-            buttons.append('x')
-
-        if self.button_hover:
-            buttons.append('<img src="%s" />' % self.button_hover.url)
-        else:
-            buttons.append('x')
-
-        if self.big_button:
-            buttons.append('<img src="%s" />' % self.big_button.url)
-        else:
-            buttons.append('x')
-
-        return ' '.join(buttons)
-
-    admin_buttons.short_description = _("Buttons")
-    admin_buttons.allow_tags = True
-
-    def button_url(self):
-        if self.button:
-            return self.button.url
-        else:
-            return '/site_media/buttons/default-11.png'
-
-    def button_hover_url(self):
-        if self.button_hover:
-            return self.button_hover.url
-        else:
-            return '/site_media/buttons/default-11.png'
-
-    def big_button_url(self):
-        if self.big_button:
-            return self.big_button.url
-        else:
-            return '/site_media/buttons/default-17.png'
-
     def __str__(self):
         return '%s' % self.topic
 
@@ -185,55 +89,12 @@ class MusicFocus(models.Model):
     abbrev = models.CharField(_("Abbreviation"), max_length=4, unique=True)
     slug = models.SlugField(_("Slug"), max_length=32, unique=True)
     is_active = models.BooleanField(_("Is active?"), default=True)
-    button = models.ImageField(_("Button image"), blank=True, null=True, upload_to='buttons')
-    button_hover = models.ImageField(_("Button image (hover)"), blank=True, null=True, upload_to='buttons')
-    big_button = models.ImageField(_("Big button image"), blank=True, null=True, upload_to='buttons')
 
     class Meta:
         ordering = ('focus',)
         verbose_name = _("Music focus")
         verbose_name_plural = _("Music focus")
 
-    def admin_buttons(self):
-        buttons = []
-        if self.button:
-            buttons.append('<img src="%s" />' % self.button.url)
-        else:
-            buttons.append('x')
-
-        if self.button_hover:
-            buttons.append('<img src="%s" />' % self.button_hover.url)
-        else:
-            buttons.append('x')
-
-        if self.big_button:
-            buttons.append('<img src="%s" />' % self.big_button.url)
-        else:
-            buttons.append('x')
-
-        return ' '.join(buttons)
-
-    admin_buttons.short_description = _("Buttons")
-    admin_buttons.allow_tags = True
-
-    def button_url(self):
-        if self.button:
-            return self.button.url
-        else:
-            return '/site_media/buttons/default-11.png'
-
-    def button_hover_url(self):
-        if self.button_hover:
-            return self.button_hover.url
-        else:
-            return '/site_media/buttons/default-11.png'
-
-    def big_button_url(self):
-        if self.big_button:
-            return self.big_button.url
-        else:
-            return '/site_media/buttons/default-17.png'
-
     def __str__(self):
         return '%s' % self.focus
 
diff --git a/program/serializers.py b/program/serializers.py
index cff27afb..bbd59e11 100644
--- a/program/serializers.py
+++ b/program/serializers.py
@@ -100,7 +100,6 @@ class CategorySerializer(serializers.ModelSerializer):
         instance.category = validated_data.get('category', instance.category)
         instance.abbrev = validated_data.get('abbrev', instance.abbrev)
         instance.slug = validated_data.get('slug', instance.slug)
-        instance.color = validated_data.get('color', instance.color)
         instance.description = validated_data.get('description', instance.description)
         instance.is_active = validated_data.get('is_active', instance.is_active)
 
@@ -213,8 +212,6 @@ class TypeSerializer(serializers.ModelSerializer):
         """
         instance.type = validated_data.get('type', instance.type)
         instance.slug = validated_data.get('slug', instance.slug)
-        instance.color = validated_data.get('color', instance.color)
-        instance.text_color = validated_data.get('text_color', instance.text_color)
         instance.is_active = validated_data.get('is_active', instance.is_active)
 
         instance.save()
-- 
GitLab