Skip to content

Commit

Permalink
Renaming project and files
Browse files Browse the repository at this point in the history
Renamed README.txt in README.markdown
Added more informations to README
  • Loading branch information
nemesisdesign committed Feb 9, 2012
1 parent f8c9a57 commit b75b259
Show file tree
Hide file tree
Showing 40 changed files with 89 additions and 70 deletions.
69 changes: 69 additions & 0 deletions README.markdown
@@ -0,0 +1,69 @@
# django-tagging-autocomplete-tag-it

Fork of *[django-tagging-autocomplete](http://code.google.com/p/django-tagging-autocomplete/)* that works with a modified version (another fork) jQuery UI Tag-it.

**This is not stable**. If you would like to use this widget please share your ideas (and code) on how to improve it.

## Demo:

To see the jQuery UI widget in action its demos: [http://aehlke.github.com/tag-it/](http://aehlke.github.com/tag-it/)
The forked repository for the javascript is: [https://github.com/nemesisdesign/tag-it](https://github.com/nemesisdesign/tag-it)

## Features:
* Tag editing
* Autocompletition
* Customizable minimum amount of letters before the autocompletition starts
* Customizable maximum tags number
* Costomizable max length of each tag
* Aims to be flexible

## Available settings:

TAGGING_AUTOCOMPLETE_MIN_LENGTH defaults to 1
TAGGING_AUTOCOMPLETE_REMOVE_CONFIRMATION defaults to True
TAGGING_AUTOCOMPLETE_ANIMATE defaults to True
TAGGING_AUTOCOMPLETE_MAX_TAGS defaults to 20 - this general setting can be overriden in each field if needed
TAGGING_AUTOCOMPLETE_JS_BASE_URL defaults to 'STATIC_URL/js/jquery-tag-it/'
TAGGING_AUTOCOMPLETE_JQUERY_UI_FILE defaults to 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.12/jquery-ui.min.js'
TAGGING_AUTOCOMPLETE_CSS is a list of CSS files and defaults to ['TAGGING_AUTOCOMPLETE_JS_BASE_URL/css/ui-autocomplete-tag-it.css']

## Usage

I wrote these instructions quickly, don't trust this completely.

###Usage in models:

# models.py
from django.db import models
from tagging_autocomplete_tagit.models import TagAutocompleteTagItField

class SomeModel(models.Model):
# max_tags defaults to TAGGING_AUTOCOMPLETE_MAX_TAGS
# If max_tags is specified it will override the value specified in TAGGING_AUTOCOMPLETE_MAX_TAGS
tags = TagAutocompleteTagItField(max_tags=False)

###Using the form widget:

Alternatively you can use the TagAutocomplete form widget while creating your form. For example:

# forms.py
from django import forms
from tagging.forms import TagField
from tagging_autocomplete_tagit.widgets import TagAutocompleteTagIt

class SomeForm(forms.Form):
# max_tags defaults to TAGGING_AUTOCOMPLETE_MAX_TAGS
# If max_tags is specified it will override the value specified in TAGGING_AUTOCOMPLETE_MAX_TAGS
tags = TagField(widget=TagAutocompleteTagIt(max_tags=5))

##Instalation

1. You need to have django-tagging already installed
2. Download django-tagging-autocomplete-tag-it and use setup.py to install it on your system:
python setup.py install
(NOT SURE THIS WORKS NOW)
4. Copy "jquery-tag-it" folder of this repository to the 'js' folder specified in your project's STATIC_URL setting. If you want to put it somewhere else add TAGGING_AUTOCOMPLETE_JS_BASE_URL to your project settings.
5. Add "tagging_autocomplete_tagit" to installed apps in your project's settings.
6. Add the following line to your project's urls.py file:

(r'^tagging_autocomplete_tagit/', include('tagging_autocomplete_tagit.urls')),
50 changes: 0 additions & 50 deletions README.txt

This file was deleted.

5 changes: 0 additions & 5 deletions tagging_autocomplete/urls.py

This file was deleted.

File renamed without changes.
@@ -1,25 +1,25 @@
from django.db import models
from tagging.fields import TagField
from tagging_autocomplete.widgets import TagAutocomplete
from tagging_autocomplete_tagit.widgets import TagAutocompleteTagIt
from django.contrib.admin.widgets import AdminTextInputWidget

# The following code is based on models.py file from django-tinymce by Joost Cassee

class TagAutocompleteField(TagField):
class TagAutocompleteTagItField(TagField):
"""
TagField with autocomplete widget
TagField with jQuery UI Tag-it widget
"""

def __init__(self, max_tags=False, *args, **kwargs):
self.max_tags = max_tags
super(TagAutocompleteField, self).__init__(*args, **kwargs)
super(TagAutocompleteTagItField, self).__init__(*args, **kwargs)

def formfield(self, **kwargs):
defaults = {'widget': TagAutocomplete(max_tags=self.max_tags)}
defaults = {'widget': TagAutocompleteTagIt(max_tags=self.max_tags)}
defaults.update(kwargs)

# As an ugly hack, we override the admin widget
if defaults['widget'] == AdminTextInputWidget:
defaults['widget'] = TagAutocomplete(max_tags=self.max_tags)
defaults['widget'] = TagAutocompleteTagIt(max_tags=self.max_tags)

return super(TagAutocompleteField, self).formfield(**defaults)
return super(TagAutocompleteTagItField, self).formfield(**defaults)
5 changes: 5 additions & 0 deletions tagging_autocomplete_tagit/urls.py
@@ -0,0 +1,5 @@
from django.conf.urls.defaults import *

urlpatterns = patterns('tagging_autocomplete_tagit.views',
url(r'^list$', 'list_tags', name='tagging_autocomplete_tagit-list'),
)
File renamed without changes.
Expand Up @@ -4,11 +4,11 @@
from django.utils.safestring import mark_safe


class TagAutocomplete(TextInput):
class TagAutocompleteTagIt(TextInput):

def __init__(self, max_tags, *args, **kwargs):
self.max_tags = max_tags if max_tags else getattr(settings, 'TAGGING_AUTOCOMPLETE_MAX_TAGS', 20)
super(TagAutocomplete, self).__init__(*args, **kwargs)
super(TagAutocompleteTagIt, self).__init__(*args, **kwargs)

def render(self, name, value, attrs=None):
""" Render HTML code """
Expand All @@ -20,8 +20,8 @@ def render(self, name, value, attrs=None):
remove_confirmation = 'true' if getattr(settings, 'TAGGING_AUTOCOMPLETE_REMOVE_CONFIRMATION', True) else 'false'
animate = 'true' if getattr(settings, 'TAGGING_AUTOCOMPLETE_ANIMATE', True) else 'false'

list_view = reverse('tagging_autocomplete-list')
html = super(TagAutocomplete, self).render(name, value, attrs)
list_view = reverse('tagging_autocomplete_tagit-list')
html = super(TagAutocompleteTagIt, self).render(name, value, attrs)
# Subclass this field in case you need to add some custom behaviour like custom callbacks
js = u"""<script type="text/javascript">init_jQueryTagit({
objectId: '%s',
Expand All @@ -44,7 +44,7 @@ def render(self, name, value, attrs=None):

class Media:
# JS Base url defaults to STATIC_URL/jquery-autocomplete/
js_base_url = getattr(settings, 'TAGGING_AUTOCOMPLETE_JS_BASE_URL', '%s/jquery-autocomplete' % settings.STATIC_URL)
js_base_url = getattr(settings, 'TAGGING_AUTOCOMPLETE_JS_BASE_URL', '%sjs/jquery-tag-it/' % settings.STATIC_URL)
# jQuery ui is loaded from google's CDN by default
jqueryui_default = 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.12/jquery-ui.min.js'
jqueryui_file = getattr(settings, 'TAGGING_AUTOCOMPLETE_JQUERY_UI_FILE', jqueryui_default)
Expand All @@ -55,13 +55,13 @@ class Media:

# load js
js = (
'%stagging_autocomplete.js' % js_base_url,
'%stagging_autocomplete_tagit.js' % js_base_url,
jqueryui_file,
'%stag-it.min.js' % js_base_url,
'%sjquery.tag-it.min.js' % js_base_url,
)

# custom css can also be overriden in settings
css_list = getattr(settings, 'TAGGING_AUTOCOMPLETE_CSS', ['%scss/django-tagging-autocomplete.css' % js_base_url])
css_list = getattr(settings, 'TAGGING_AUTOCOMPLETE_CSS', ['%scss/ui-autocomplete-tag-it.css' % js_base_url])
# check is a list, if is a string convert it to a list
if type(css_list) != list and type(css_list) == str:
css_list = [css_list]
Expand Down

0 comments on commit b75b259

Please sign in to comment.