Beispiel #1
0
from __future__ import unicode_literals

import json

from django.core import urlresolvers
from django.utils.html import format_html_join
from django.contrib import admin
from django.views.generic.base import TemplateResponse

from configure import models
from configure.forms import ConfigStore, TweetConfigOption, RegistrationConfigOption, SiteConfigOption

from HUtils.admin_utils import display_field

config_store = ConfigStore()

config_store.register(TweetConfigOption, name='tweet', label='动弹设置')
config_store.register(RegistrationConfigOption, name='registration', label='注册设置')
config_store.register(SiteConfigOption, name='site', label='网站基本设置')


@admin.register(models.Config)
class ConfigModelAdmin(admin.ModelAdmin):
    list_display = ('label',)

    def has_add_permission(self, request):
        return False

    def has_delete_permission(self, request, obj=None):
        return False
Beispiel #2
0
 def test_register_2(self):
     cs = ConfigStore()
     cs.register(AConfigOption)
     self.assertTrue('A' in cs.store)
     self.assertEqual(AConfigOption, cs._store['A'].option_class)
     self.assertEqual('A', cs.store['A'].label)
Beispiel #3
0
 def test_register_3(self):
     cs = ConfigStore()
     cs.register(AConfigOption)
     with self.assertRaises(InvalidConfiguredException):
         cs.register(AConfigOption)
Beispiel #4
0
 def test_register_1(self):
     cs = ConfigStore()
     cs.register(AConfigOption, name='AConfig', label='Test')
     self.assertTrue('AConfig' in cs.store)
     self.assertEqual(AConfigOption, cs._store['AConfig'].option_class)
     self.assertEqual('Test', cs.store['AConfig'].label)