This repository has been archived by the owner on Feb 1, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add fallback to manually defined class
- Loading branch information
Krzysiek Szularz
committed
May 17, 2013
1 parent
0b813d9
commit a18812c
Showing
9 changed files
with
80 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
include LICENSE.txt | ||
recursive-include aldryn_style/templates * | ||
recursive-include aldryn_style/static * | ||
recursive-include aldryn_style/locale * | ||
recursive-include aldryn_style/migrations * | ||
recursive-exclude * *.pyc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
# -*- coding: utf-8 -*- | ||
__version__ = '0.0.1' | ||
__version__ = '0.0.5' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# -*- coding: utf-8 -*- | ||
from django import forms | ||
from django.conf import settings | ||
from django.utils.safestring import mark_safe | ||
from django.utils.translation import ugettext_lazy as _ | ||
|
||
|
||
from aldryn_style.models import StylePlugin | ||
|
||
|
||
class ClassNameWidget(forms.MultiWidget): | ||
|
||
def __init__(self): | ||
self.options = getattr(settings, 'STYLE_CLASS_NAMES', []) | ||
choices = [(x, x) for x in self.options] | ||
choices.append(('', _('Enter manually'))) | ||
widgets = [forms.Select(choices=choices), forms.TextInput()] | ||
super(ClassNameWidget, self).__init__(widgets) | ||
|
||
class Media: | ||
js = ['aldryn_style/js/class_name_widget.js'] | ||
|
||
def decompress(self, value): | ||
select_visible = value in self.options | ||
return (value, '') if select_visible else ('', value) | ||
|
||
def value_from_datadict(self, *args, **kwargs): | ||
value = super(ClassNameWidget, self).value_from_datadict(*args, **kwargs) | ||
(select_value, text_input_value) = value | ||
return select_value or text_input_value | ||
|
||
def format_output(self, rendered_widgets): | ||
return mark_safe(' '.join(rendered_widgets)) | ||
|
||
|
||
class StyleForm(forms.ModelForm): | ||
|
||
def __init__(self, *args, **kwargs): | ||
super(StyleForm, self).__init__(*args, **kwargs) | ||
self.fields['class_name'].widget = ClassNameWidget() | ||
|
||
class Meta: | ||
model = StylePlugin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,16 @@ | ||
# -*- coding: utf-8 -*- | ||
from django.core.validators import RegexValidator | ||
from django.db import models | ||
from django.conf import settings | ||
from django.utils.translation import ugettext_lazy as _ | ||
|
||
from cms.models.pluginmodel import CMSPlugin | ||
|
||
|
||
def get_class_choices(): | ||
return [(x, x) for x in getattr(settings, 'STYLE_CLASS_NAMES', [''])] | ||
from aldryn_style.utils import CLASS_NAME_FORMAT | ||
|
||
|
||
class StylePlugin(CMSPlugin): | ||
|
||
class_name = models.CharField(_('Class name'), choices=get_class_choices(), max_length=50) | ||
class_name = models.CharField(_('Class name'), max_length=50, validators=[RegexValidator(CLASS_NAME_FORMAT)]) | ||
|
||
def __unicode__(self): | ||
return self.class_name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
(function($) { | ||
function init() { | ||
var class_name_field = $(this); | ||
var select = class_name_field.find('select'); | ||
var text_input = class_name_field.find('input'); | ||
|
||
select.change(function() { | ||
if (select.val()) { | ||
text_input.hide(); | ||
} else { | ||
text_input.show(); | ||
} | ||
}); | ||
|
||
select.change(); | ||
} | ||
|
||
$(document).ready(function() { | ||
$('.field-class_name').each(init); | ||
}); | ||
}(django.jQuery)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# -*- coding: utf-8 -*- | ||
import re | ||
|
||
|
||
CLASS_NAME_FORMAT = re.compile(r'^\w[\w_-]*$') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters