Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add settings configurable with admin interface, http://bugzilla.pcult…

  • Loading branch information...
commit 9457184ad36b8c00b8d48b546acf4271a230fd11 1 parent 6e20299
Dmytro Kostochko Alerion authored
5 apps/videos/admin.py
View
@@ -19,6 +19,11 @@
from django.contrib import admin
from videos.models import Video, SubtitleLanguage, SubtitleVersion, Subtitle
from django.core.urlresolvers import reverse
+from django.utils.translation import ugettext_lazy as _
+from utils.livesettings_values import EmailListValue
+from livesettings import BASE_GROUP, config_register
+
+config_register(EmailListValue(BASE_GROUP, 'alert_emails', description=_(u'Email for alert')))
class VideoAdmin(admin.ModelAdmin):
list_display = ['__unicode__', 'title', 'languages', 'video_thumbnail']
2  deploy/requirements.txt
View
@@ -10,6 +10,8 @@ django-extensions==0.4.1
-e hg+http://bitbucket.org/ubernostrum/django-registration/@d36a38202ee3d09d342b000f4ff634296f90df49#egg=django_registration-tip
-e hg+https://bitbucket.org/jespern/django-piston/@c4b2d21db51a#egg=django-piston-0.2.2
-e git://github.com/aduston/Django-Socialauth.git@709d344226471b658250f01c714a0dd9559a88e5#egg=django_socialauth-0.1.5-py2.6-dev
+-e hg+https://bitbucket.org/bkroeze/django-livesettings/@32a38a60367a#egg=django-livesettings
+-e hg+https://bitbucket.org/bkroeze/django-keyedcache/@4be18235b372#egg=django-keyedcache
ipython==0.10
oauth==1.0.1
oauth2==1.2.0
1  settings.py
View
@@ -303,6 +303,7 @@ def rel(*x):
'search',
'api',
'targetter',
+ 'livesettings',
'mirosubs' #dirty hack to fix http://code.djangoproject.com/ticket/5494
)
3  templates/admin/base_site.html
View
@@ -9,6 +9,7 @@ <h1 id="site-name">{% trans 'Universal Subtitles' %}</h1>
{% block nav-global %}
<div style="margin: 5px 0 5px 10px">
- <a href='/'>{% trans 'View site' %}</a>
+ <a href='/'>{% trans 'View site' %}</a> /
+ <a href='{% url satchmo_site_settings %}'>{% trans 'Edit settings' %}</a>
</div>
{% endblock %}
117 templates/livesettings/site_settings.html
View
@@ -0,0 +1,117 @@
+{% extends "admin/base_site.html" %}
+{% load i18n adminmedia admin_modify config_tags %}
+
+{% block stylesheet %}{% admin_media_prefix %}css/forms.css{% endblock %}
+{% block extrahead %}{{ block.super }}
+<script type="text/javascript" src="{% url admin:jsi18n %}"></script>
+<script type="text/javascript" src="{% admin_media_prefix %}js/core.js"></script>
+{% if DJANGO_PRE_12 %}
+<script type="text/javascript" src="{% admin_media_prefix %}js/admin/CollapsedFieldsets.js"></script>
+<script type="text/javascript">
+var uncollapse = function () {
+ CollapsedFieldsets.uncollapse_all();
+ return false;
+}
+</script>
+{% else %}
+<script type="text/javascript" src="{% admin_media_prefix %}js/jquery.min.js"></script>
+<script type="text/javascript" src="{% admin_media_prefix %}js/jquery.init.js"></script>
+<script type="text/javascript" src="{% admin_media_prefix %}js/collapse.js"></script>
+<script type="text/javascript">
+var $ = django.jQuery,
+uncollapse = function() {
+ $("fieldset.collapse a.collapse-toggle").each(function() {
+ var elt = $(this);
+ if (elt.text() == gettext('Show')) {
+ elt.click();
+ }
+ });
+ $('fieldset').removeClass('collapsed');
+ return false
+};
+</script>
+{% endif %}
+{% endblock %}
+{% block extrastyle %}
+{{ block.super }}
+<link rel="stylesheet" type="text/css" href="{% admin_media_prefix %}css/base.css" />
+<style type="text/css">
+ul.fieldref { margin: 0; padding: 0; font-size: 9px; }
+ul.fieldref li { float: left; margin: 0 10px 0 0; list-style: none; }
+fieldset.collapsed h2 { display: block !important; }
+fieldset.collapsed h2 a { display: inline !important; }
+div.fieldcontainer { float: left; margin-right: 0; }
+</style>
+{% endblock %}
+{% block coltype %}colMS{% endblock %}
+{% block bodyclass %}dashboard{% endblock %}
+{% block userlinks %}<a href="/admin/doc/">{% trans 'Documentation' %}</a> / <a href="/admin/password_change/">{% trans 'Change password' %}</a> / <a href="/admin/logout/">{% trans 'Log out' %}</a>{% endblock %}
+{% block breadcrumbs %}{% if not is_popup %}
+<div class="breadcrumbs">
+ <a href="/admin/">{% trans "Home" %}</a> &rsaquo;
+ {% trans "Edit Site Settings" %}
+</div>
+{% endif %}{% endblock %}
+{% block content %}
+<span style="clear: both;"></span>
+<div id="content-main">
+{% if not use_db %}
+ <p>{% trans "Livesettings are disabled for this site." %}</p>
+ <p>{% trans "All configuration options must be edited in the site settings.py file" %}</p>
+ </div>
+ {% admin_site_views 'satchmo_site_settings' %}
+{% else %}
+ {% if form.errors %}
+ <p class="errornote">
+ {% blocktrans count form.errors|length as counter %}Please correct the error below.{% plural %}Please correct the errors below.{% endblocktrans %}
+ </p>
+ {% endif %}
+ {% if form.fields %}
+ <form method="post">{% csrf_token %}
+ {% for field in form %}
+ {% if field.is_hidden %}
+ <tr style="display: none;"><td>{{ field }}</td></tr>
+ {% else %}
+ {% ifchanged field.field.group %}{% with field.field.group as group %}
+ {% if not forloop.first %}
+ </table>
+ </fieldset>
+ {% endif %}
+ <fieldset class="module collapse">
+ <h2 id="{{ group.key }}">{{ group.name }}</h2>
+ <table summary="{% blocktrans with group.name as name %}Group settings: {{ name }}{% endblocktrans %}" style="width: 100%">
+ {% endwith %}{% endifchanged %}
+ {% if field.errors %}
+ <tr class="error">
+ <td colspan="2">{{ field.errors }}</td>
+ </tr>
+ {% endif %}
+ <tr{% if field.errors %} class="error"{% endif %}>
+ <td style="width: 50%;">
+ {{ field.label_tag }}
+ {% if field.help_text %}
+ <p class="help">{{ field.help_text|break_at:40|safe }}</p>
+ {% endif %}
+ {% if field.field.default_text %}
+ <p class="help">{{ field.field.default_text|break_at:40}}</p>
+ {% endif %}
+ </td>
+ <td>{{ field }}</td>
+ </tr>
+ {% endif %}
+ {% endfor %}
+ </table>
+ </fieldset>
+ </div>
+ {% admin_site_views 'satchmo_site_settings' %}
+ <br class="clear:both;" />
+ <input type="submit" value="{% trans 'Update Settings' %}" />
+ <p><a onclick="javascript:return uncollapse();" href="#">{% trans 'Uncollapse all' %}</a></p>
+ <p><a href="{% url settings_export %}">Export</a></p>
+ </form>
+ {% else %}
+ <p>{% trans "You don't have permission to edit values." %}</p>
+ {% endif %}
+{% endif %}
+</div>
+{% endblock %}
1  urls.py
View
@@ -47,6 +47,7 @@
'django.contrib.auth.views.password_reset_confirm'),
(r'^reset/done/$', 'django.contrib.auth.views.password_reset_complete'),
(r'socialauth/', include('socialauth.urls')),
+ (r'^admin/settings/', include('livesettings.urls')),
(r'^admin/', include(admin.site.urls)),
(r'^embed(\d*).js$', 'widget.views.embed'),
(r'^widget_demo/$', 'widget.views.widget_demo'),
37 utils/livesettings_values.py
View
@@ -0,0 +1,37 @@
+from livesettings.values import LongStringValue, NOTSET
+from utils.forms import EmailListField
+from django.forms.widgets import Textarea
+
+class EmailListValue(LongStringValue):
+
+ class field(EmailListField):
+ def __init__(self, *args, **kwargs):
+ kwargs['required'] = False
+ kwargs['widget'] = Textarea()
+ EmailListField.__init__(self, *args, **kwargs)
+
+ def to_python(self, value):
+ if value == NOTSET:
+ value = []
+
+ if isinstance(value, (list, tuple)):
+ return value
+
+ return value.split(',')
+
+ def get_db_prep_save(self, value):
+ if value == NOTSET:
+ value = []
+
+ return ','.join(value)
+
+ def to_editor(self, value):
+ if value == NOTSET:
+ value = []
+
+ if isinstance(value, (list, tuple)):
+ return ','.join(value)
+
+ return value
+
+
Please sign in to comment.
Something went wrong with that request. Please try again.