Fixed theme switching bug

pull/17/merge
Fabio Caccamo 2017-05-22 18:56:22 +02:00
parent 4ef14c248a
commit b25cf463eb
2 changed files with 22 additions and 5 deletions

View File

@ -21,6 +21,9 @@ class Theme(models.Model):
@staticmethod
def post_save_handler(instance, created, **kwargs):
theme = instance
if theme.active:
Theme.objects.exclude( pk = theme.pk ).update( active = False )
Theme.get_active_theme()
@staticmethod
@ -99,11 +102,8 @@ class Theme(models.Model):
def set_active(self):
Theme.objects.exclude( pk = self.pk ).update( active = False )
if not self.active:
self.active = True
self.save()
self.active = True
self.save()
def set_default_logo(self):

View File

@ -5,6 +5,7 @@ from django.test import TestCase
from django.template import Context, Template
import os
import random
import shutil
from admin_interface.models import Theme
@ -93,6 +94,22 @@ class AdminInterfaceTestCase(TestCase):
self.assertEqual( Theme.get_active_theme().pk, theme_3.pk )
self.__test_active_theme()
def test_last_theme_activated_on_multiple_themes_activated(self):
Theme.objects.all().delete()
theme_1 = Theme.objects.create( name = 'Custom 1', active = True )
theme_2 = Theme.objects.create( name = 'Custom 2', active = True )
theme_3 = Theme.objects.create( name = 'Custom 3', active = True )
theme_4 = Theme.objects.create( name = 'Custom 4', active = True )
theme_5 = Theme.objects.create( name = 'Custom 5', active = True )
themes = [ theme_1, theme_2, theme_3, theme_4, theme_5 ]
for i in range(5):
random.shuffle(themes)
for theme in themes:
theme.set_active()
self.assertEqual( Theme.get_active_theme().pk, theme.pk )
self.__test_active_theme()
def test_templatetags(self):
Theme.objects.all().delete()