Skip to content

Commit

Permalink
Version bump 2.0.0a7
Browse files Browse the repository at this point in the history
  • Loading branch information
jpic committed Dec 17, 2013
1 parent 49daf08 commit 1b6b4b9
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 57 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG
@@ -1,3 +1,22 @@
2.0.0a7:

- Removed a layer of complexity by trading autocomplete_js_attributes and
widget_js_attributes for attrs (for input/autocomplete object) and widget_attrs
(for widget container/widget js object).
- Fixed naming conventions issues:
- #124: css class .choiceDetail should be .choice-detail, same for
.choiceUpdate
- #97: rename .div css class to .block,
- Fixed #84: data-autocomplete-placeholder is gone in favor of the
placeholder attribute.
- Fixed #82: data-* is not parsed anymore by yourlabs.Widget, data-widget-*
is parsed for options instead.
- Fixed #81: js Autocomplete object now parses data-autocomplete-* for
options,
- Fixed #80: js maxValues is now maximumValues.
- Fixed #27: refactored selenium tests to be able to test any example app.
- Bugfix: get_autocomplete_from_arg returned wrong autocomplete in two cases

2.0.0a6:

- Simplified widget template selection.
Expand Down
41 changes: 41 additions & 0 deletions autocomplete_light/widgets.py
Expand Up @@ -30,8 +30,47 @@ class WidgetBase(object):
"""
Base widget for autocompletes.
.. py:attribute:: attrs
HTML ``<input />`` attributes, such as class, placeholder, etc ... Note
that any ``data-autocomplete-*`` attribute will be parsed as an option
for ``yourlabs.Autocomplete`` js object. For example::
attrs={
'placeholder': 'foo',
'data-autocomplete-minimum-characters': 0
'class': 'bar',
}
Will render like::
<input placeholder="foo" data-autocomplete-minimum-characters="0" class="autocomplete bar" />
Which will set by the way ``yourlabs.Autocomplete.minimumCharacters``
option - the naming conversion is handled by jQuery.
.. py:attribute:: widget_attrs
HTML widget container attributes. Note that any ``data-widget-*``
attribute will be parsed as an option for ``yourlabs.Widget`` js
object. For example::
widget_attrs={
'data-widget-maximum-values': 6,
'class': 'country-autocomplete',
}
Will render like::
<span id="country-wrapper" data-widget-maximum-values="6" class="country-autocomplete autcomplete-light-widget">
Which will set by the way ``yourlabs.Widget.maximumValues`` - note that
the naming conversion is handled by jQuery.
.. py:attribute:: widget_js_attributes
**DEPRECATED** in favor of :py:attr::`widget_attrs`.
A dict of options that will override the default widget options. For
example::
Expand All @@ -58,6 +97,8 @@ class WidgetBase(object):
.. py:attribute:: autocomplete_js_attributes
**DEPRECATED** in favor of :py:attr::`attrs`.
A dict of options like for :py:attr:`widget_js_attributes`. However,
note that HTML attributes will be prefixed by ``data-autocomplete-``
instead of just ``data-``. This allows the jQuery plugins to make the
Expand Down
2 changes: 1 addition & 1 deletion docs/source/conf.py
Expand Up @@ -76,7 +76,7 @@
# The short X.Y version.
version = '2.0'
# The full version, including alpha/beta/rc tags.
release = '2.0.0a6'
release = '2.0.0a7'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
25 changes: 13 additions & 12 deletions docs/source/cookbook.rst
Expand Up @@ -28,10 +28,10 @@ Various cooking recipes ``your_app/autocomplete_light_registry.py``:
# It is possible to override javascript options from Python.
autocomplete_light.register(OtherModel,
autocomplete_js_attributes={
# This will actually data-minimum-characters which
attrs={
# This will actually data-autocomplete-minimum-characters which
# will set widget.autocomplete.minimumCharacters.
'minimum_characters': 0,
'data-autocomplete-minimum-characters': 0,
'placeholder': 'Other model name ?',
}
)
Expand All @@ -40,19 +40,20 @@ Various cooking recipes ``your_app/autocomplete_light_registry.py``:
class YourModelAutocomplete(autocomplete_light.AutocompleteModelTemplate):
template_name = 'your_app/your_special_choice_template.html'
autocomplete_js_attributes = {
'minimum_characters': 4,
input_attrs = {
'data-mininum-minimum-characters': 4,
'placeholder': 'choose your model',
}
widget_js_attributes = {
widget_attrs = {
# That will set data-max-values which will set widget.maxValues
'max_values': 6,
'data-widget-maximum-values': 6,
}
def choices_for_request(self):
""" Return choices for a particular request """
return super(YourModelAutocomplete, self).choices_for_request(
).exclude(extra=self.request.GET['extra'])
self.choices = self.choices.exclude(extra=self.request.GET['extra'])
return super(YourModelAutocomplete, self).choices_for_request()
# Just pass the class to register and it'll subclass it to be thread safe.
autocomplete_light.register(YourModel, YourModelAutocomplete)
Expand Down Expand Up @@ -89,9 +90,9 @@ Various cooking recipes for ``your_app/forms.py``:
cities = forms.ModelMultipleChoiceField(City.objects.all(),
widget=autocomplete_light.MultipleChoiceWidget('CityAutocomplete',
# Those attributes have priority over the Autocomplete ones.
autocomplete_js_attributes={'minimum_characters': 0,
'placeholder': 'Choose 3 cities ...'},
widget_js_attributes={'max_values': 3}))
attrs={'data-autocomplete-minimum-characters': 0,
'placeholder': 'Choose 3 cities ...'},
widget_attrs={'data-widget-maximum-values': 3}))
tags = autocomplete_light.TextWidget('TagAutocomplete')
Expand Down
83 changes: 44 additions & 39 deletions docs/source/script.rst
Expand Up @@ -112,60 +112,65 @@ autocomplete.
Overriding a JS option in Python
````````````````````````````````

Javascript widget options can be set in Python via the ``widget_js_attributes``
keyword argument. And javascript autocomplete options can be set in Python via
the ``autocomplete_js_attributes``.
Javascript widget and autocomplete objects options can be overidden via HTML
data attributes:

Those can be set either on an Autocomplete class, either using the
``register()`` shortcut, either via the Widget constructor.
- ``yourlabs.Autocomplete`` will use any ``data-autocomplete-*`` attribute **on
the input tag**,
- ``yourlabs.Widget`` will use any ``data-widget-*`` attribute **on the widget
container**.

Per Autocomplete class
>>>>>>>>>>>>>>>>>>>>>>
Those can be set in Python either with ``register()``, as Autocomplete class
attributes or as widget attributes. See next examples for details.

Per registered Autocomplete
>>>>>>>>>>>>>>>>>>>>>>>>>>>

These options can be set with the ``register()`` shortcut:

.. code-block:: python
class AutocompleteYourModel(autocomplete_light.AutocompleteModelTemplate):
template_name = 'your_app/your_special_choice_template.html'
autocomplete_js_attributes = {
# This will actually data-autocomplete-minimum-characters which
# will set widget.autocomplete.minimumCharacters.
'minimum_characters': 4,
}
autocomplete_light.register(Person,
input_attrs={
'placeholder': 'foo',
'data-autocomplete-minimum-characters': 0
},
widget_attrs={'data-widget-maximum-values': 4}
)
widget_js_attributes = {
# That will set data-max-values which will set widget.maxValues
'max_values': 6,
}
Per Autocomplete class
>>>>>>>>>>>>>>>>>>>>>>

Per registered Autocomplete
>>>>>>>>>>>>>>>>>>>>>>>>>>>
Or equivalently on a Python Autocomplete class:

.. code-block:: python
autocomplete_light.register(City,
# Those have priority over the class attributes
autocomplete_js_attributes={
'minimum_characters': 0,
'placeholder': 'City name ?',
}
widget_js_attributes = {
'max_values': 6,
}
)
class YourAutocomplete(autocomplete_light.AutocompleteModelBase):
model = Person
input_attrs={
'placeholder': 'foo',
'data-autocomplete-minimum-characters': 0
},
widget_attrs={'data-widget-maximum-values': 4}
Per widget
>>>>>>>>>>

Or via the Python widget class:

.. code-block:: python
class SomeForm(forms.Form):
cities = forms.ModelMultipleChoiceField(City.objects.all(),
widget=autocomplete_light.MultipleChoiceWidget('CityAutocomplete',
# Those attributes have priority over the Autocomplete ones.
autocomplete_js_attributes={'minimum_characters': 0,
'placeholder': 'Choose 3 cities ...'},
widget_js_attributes={'max_values': 3}))
autocomplete_light.ChoiceWidget('FooAutocomplete',
attrs={
'placeholder': 'foo',
'data-autocomplete-minimum-characters': 0
},
widget_attrs={'data-widget-maximum-values': 4}
)
**NOTE** the difference of the option name here. It is ``attrs`` to match
django and not ``input_attrs``. Note that ``Autocomplete.input_attrs`` might be
renamed to ``Autocomplete.attrs`` before v2 hits RC.

Override autocomplete JS options in JS
``````````````````````````````````````
Expand Down Expand Up @@ -269,7 +274,7 @@ way.
.. code-block:: python
autocomplete_light.register(City,
widget_js_attributes={'bootstrap': 'your-custom-bootstrap'})
widget_attrs={'data-widget-bootstrap': 'your-custom-bootstrap'})
.. note::

Expand Down
16 changes: 12 additions & 4 deletions docs/source/tutorial.rst
Expand Up @@ -20,9 +20,18 @@ Register an Autocomplete for your model in
autocomplete_light.register(Person,
# Just like in ModelAdmin.search_fields
search_fields=['^first_name', 'last_name'],
# This will actually html attribute data-placeholder which will set
# javascript attribute widget.autocomplete.placeholder.
autocomplete_js_attributes={'placeholder': 'Other model name ?',},
attrs={
# This will set the input placeholder attribute:
'placeholder': 'Other model name ?',
# This will set the yourlabs.Autocomplete.minimumCharacters
# options, the naming conversion is handled by jQuery
'data-widget-minimum-characters': 1,
},
# This will set the data-widget-maximum-values attribute on the
# widget container element, and will be set to
# yourlabs.Widget.maximumValues (jQuery handles the naming
# conversion).
widget_attrs={'data-widget-maximum-values', 4},
)
:py:meth:`AutocompleteView.get()
Expand Down Expand Up @@ -63,7 +72,6 @@ the above code would be:
class PersonAutocomplete(autocomplete_light.AutocompleteModelBase):
search_fields = ['^first_name', 'last_name']
autocomplete_js_attributes={'placeholder': 'Other model name ?',}
model = Person
autocomplete_light.register(PersonAutocomplete)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -59,7 +59,7 @@ def run(self):

setup(
name='django-autocomplete-light',
version='2.0.0a6',
version='2.0.0a7',
description='Fresh autocompletes for Django',
author='James Pic',
author_email='jamespic@gmail.com',
Expand Down

0 comments on commit 1b6b4b9

Please sign in to comment.