Delete old settings app, move translations to new settings app
This commit is contained in:
@@ -1,7 +0,0 @@
|
||||
from __future__ import absolute_import
|
||||
|
||||
from project_setup.api import register_setup
|
||||
|
||||
from .links import check_settings
|
||||
|
||||
register_setup(check_settings)
|
||||
@@ -1,55 +0,0 @@
|
||||
from __future__ import absolute_import
|
||||
|
||||
from django.conf import settings as django_settings
|
||||
from django.utils.importlib import import_module
|
||||
|
||||
settings = {}
|
||||
settings_list = []
|
||||
namespaces = {}
|
||||
namespace_list = []
|
||||
|
||||
|
||||
def is_superuser(context):
|
||||
return context['request'].user.is_staff or context['request'].user.is_superuser
|
||||
|
||||
|
||||
class SettingNamespace(object):
|
||||
def __init__(self, name, label, module, sprite=None):
|
||||
self.name = name
|
||||
self.label = label
|
||||
self.module = module
|
||||
self.sprite = sprite
|
||||
namespace_list.append(self)
|
||||
namespaces[self.name] = self
|
||||
|
||||
def __unicode__(self):
|
||||
return unicode(self.label)
|
||||
|
||||
def settings(self):
|
||||
return [setting for setting in settings_list if setting.namespace == self]
|
||||
|
||||
|
||||
class Setting(object):
|
||||
def __init__(self, namespace, name, global_name, default, description=u'', hidden=False, exists=False):
|
||||
self.namespace = namespace
|
||||
self.name = name
|
||||
self.global_name = global_name
|
||||
self.default = default
|
||||
self.description = description
|
||||
self.hidden = hidden
|
||||
self.exists = exists
|
||||
|
||||
# Get the global value
|
||||
value = getattr(django_settings, global_name, default)
|
||||
|
||||
# Create the local entity
|
||||
try:
|
||||
self.module = namespace.module
|
||||
setattr(self.module, name, value)
|
||||
except AttributeError:
|
||||
self.module = import_module(namespace.module)
|
||||
setattr(self.module, name, value)
|
||||
|
||||
settings_list.append(self)
|
||||
settings.setdefault(self.namespace.name, [])
|
||||
settings[self.namespace.name].append(self)
|
||||
@@ -1,9 +0,0 @@
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from navigation.api import Link
|
||||
|
||||
|
||||
def is_superuser(context):
|
||||
return context['request'].user.is_staff or context['request'].user.is_superuser
|
||||
|
||||
check_settings = Link(text=_(u'settings'), view='setting_list', sprite='cog', icon='cog.png', condition=is_superuser, children_view_regex=[r'^setting_'])
|
||||
@@ -1,3 +0,0 @@
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 2.1 KiB |
@@ -1,6 +0,0 @@
|
||||
from django.conf.urls.defaults import patterns, url
|
||||
|
||||
urlpatterns = patterns('smart_settings.views',
|
||||
url(r'^list/(?P<namespace_name>\w+)/$', 'setting_list', (), 'setting_list'),
|
||||
url(r'^list/$', 'setting_list', (), 'setting_list'),
|
||||
)
|
||||
@@ -1,55 +0,0 @@
|
||||
from __future__ import absolute_import
|
||||
|
||||
from django.shortcuts import render_to_response
|
||||
from django.template import RequestContext
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.utils.safestring import mark_safe
|
||||
|
||||
from common.utils import return_type, encapsulate
|
||||
from common.widgets import exists_with_famfam
|
||||
from navigation.api import Link
|
||||
|
||||
from .api import settings_list, namespace_list, settings, namespaces
|
||||
from .links import is_superuser
|
||||
|
||||
|
||||
def setting_list(request, namespace_name=None, object_list=None, title=None, extra_context=None):
|
||||
#TODO: check user is super user
|
||||
namespace_links = []
|
||||
for namespace in namespace_list:
|
||||
namespace_links.append(
|
||||
Link(text=namespace.label, view='setting_list', args=[u'"%s"' % namespace.name], sprite=getattr(namespace, 'sprite') or 'cog', condition=is_superuser, children_view_regex=[r'^setting_'])
|
||||
)
|
||||
|
||||
if namespace_name:
|
||||
object_list = [setting for setting in settings[namespace_name] if setting.hidden == False]
|
||||
title = _(u'settings for the module: %s') % namespaces[namespace_name]
|
||||
|
||||
context = {
|
||||
'title': title if title else _(u'settings'),
|
||||
'object_list': object_list if not (object_list is None) else [setting for setting in settings_list if setting.hidden == False],
|
||||
'hide_link': True,
|
||||
'hide_object': True,
|
||||
'extra_columns': [
|
||||
{'name': _(u'name'), 'attribute': encapsulate(lambda x: mark_safe(u'<span style="font-weight: bold;">%s</span><br />%s' % (x.global_name, x.description)))},
|
||||
{'name': _(u'default'), 'attribute': encapsulate(lambda x: return_type(x.default))},
|
||||
{'name': _(u'value'), 'attribute': encapsulate(lambda x: mark_safe(u'<div class="nowrap">%s %s</div>' % (
|
||||
return_type(getattr(x.module, x.name)),
|
||||
exists_with_famfam(getattr(x.module, x.name)) if x.exists else ''
|
||||
)))
|
||||
},
|
||||
],
|
||||
'temporary_navigation_links': {
|
||||
'form_header': {
|
||||
'setting_list': {
|
||||
'links': namespace_links
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if extra_context:
|
||||
context.update(extra_context)
|
||||
|
||||
return render_to_response('generic_list.html', context,
|
||||
context_instance=RequestContext(request))
|
||||
Reference in New Issue
Block a user