Fixed theme switching bug
parent
4ef14c248a
commit
b25cf463eb
|
|
@ -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,9 +102,6 @@ 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()
|
||||
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Reference in New Issue