Skip to content

Commit

Permalink
Lowercase and strip tags before saving
Browse files Browse the repository at this point in the history
  • Loading branch information
stianpr committed Jul 11, 2012
1 parent d4f5684 commit f7aeb86
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.pyc
4 changes: 4 additions & 0 deletions taggit_autocomplete_jqueryui/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ def formfield(self, form_class=TagField, **kwargs):
formfield(form_class, **kwargs))
field.widget = TagAutocomplete()
return field

def save_form_data(self, instance, value):
value = map(lambda v: v.strip().lower(), value)
getattr(instance, self.name).set(*value)
15 changes: 11 additions & 4 deletions taggit_autocomplete_jqueryui/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ class TagAutocomplete(Input):

class Media:
css = {
'all': ('%s/css/jquery-ui-1.8.20.custom.css' % MEDIA_URL, )
'all': (
'%s/css/jquery-ui-1.8.20.custom.css' % MEDIA_URL,
'%s/css/autocomplete.css' % MEDIA_URL,
)
}
js = (
'%s/js/jquery-ui-1.8.20.custom.min.js' % MEDIA_URL,
Expand All @@ -34,19 +37,23 @@ def render(self, name, value, attrs=None):

html = u'<ul class="tags">'
for tag in tags:
html += (u'<li data-tag="%(name)s">%(name)s</li>' %
{'name': tag.name})
html += (u'''
<li data-tag="%(name)s">
<span class="name">%(name)s</span>
<a class="remove" href="#">X</a>
</li>''' % {'name': tag.name})
html += '</ul>'
html += super(TagAutocomplete, self).render(name, value, attrs)
html += u'<input type="text" id="%s_autocomplete"/>' % attrs['id']

js = u'''
<script type="text/javascript">
django.jQuery(document).ready(function($) {
Taggit.init('#%s_autocomplete');
$("#%s_autocomplete").autocomplete({
source: "%s",
select: Taggit.autocomplete
});
});
</script>''' % (attrs['id'], json_view)
</script>''' % (attrs['id'], attrs['id'], json_view)
return mark_safe("\n".join([html, js]))

0 comments on commit f7aeb86

Please sign in to comment.