Skip to content

Commit

Permalink
Merge branch 'release/4.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
wolph committed Sep 8, 2017
2 parents 3f69627 + e52486e commit 877d798
Show file tree
Hide file tree
Showing 81 changed files with 34,215 additions and 1,837 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "tags_input/static/jquery-tagsinput-revisited"]
path = tags_input/static/jquery-tagsinput-revisited
url = https://github.com/underovsky/jquery-tagsinput-revisited
5 changes: 4 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,10 @@ Admin usage
from tags_input import admin as tags_input_admin
class YourAdmin(tags_input_admin.TagsInputAdmin):
pass
#Optionally specify which ManyToMany fields are to be used for tagging
#Or define a get_tag_fields() method
tag_fields = ["some_field"]
admin.site.register(models.YourModel, YourAdmin)
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# documentation root, use os.path.abspath to make it absolute, like shown here.
sys.path.insert(0, os.path.abspath('..'))
os.environ['DJANGO_SETTINGS_MODULE'] = 'example.settings'
from tags_input import metadata
from tags_input import __about__ as metadata

# -- General configuration -----------------------------------------------------

Expand Down
Binary file modified example/database
Binary file not shown.
1 change: 1 addition & 0 deletions example/demo/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class InlineModelAdmin(tags_input_admin.TagsInputAdmin):
list_display = ('id', 'name')
raw_id_fields = ('simple_names',)
search_fields = ('name',)
tag_fields = {'simple_names', }


def _register(model, admin_class):
Expand Down
5 changes: 5 additions & 0 deletions example/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,8 @@ def get_queryset(*args, **kwargs):

TAGS_INPUT_INCLUDE_JQUERY = True

ALLOWED_HOSTS = (
'localhost',
'127.0.0.1',
)

35 changes: 19 additions & 16 deletions example/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ def setUp(self):
assert foo_extra_spam

def test_metadata(self):
from tags_input import metadata
assert metadata
from tags_input import __about__
assert __about__

# Utils Test Cases
@pytest.mark.xfail(raises=TypeError)
Expand Down Expand Up @@ -129,25 +129,23 @@ def test_admin(self):
)
self.assertEqual(response.status_code, 200)

response = self.client.get(admin_change_url % dict(
app='autocompletionexample', model='foo', id=1))
url = admin_change_url % dict(
app='autocompletionexample', model='foo', id=1)
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
response = self.client.post(
'/admin/autocompletionexample/foo/1/',
url,
response.context['adminform'].form.initial,
follow=True,
)
self.assertEqual(response.status_code, 200)

response = self.client.get(admin_change_url % dict(
app='autocompletionexample', model='spam', id=1))
url = admin_change_url % dict(
app='autocompletionexample', model='spam', id=1)
response = self.client.get(url)
data = response.context['adminform'].form.initial.copy()
self.assertEqual(response.status_code, 200)
response = self.client.post(
'/admin/autocompletionexample/spam/1/',
data,
follow=True,
)
response = self.client.post(url, data, follow=True)
self.assertEqual(response.status_code, 200)
data['foo_incomplete'] = 'a,b,c'
response = self.client.post(
Expand All @@ -158,17 +156,22 @@ def test_admin(self):
)
self.assertEqual(response.status_code, 200)

response = self.client.get(admin_change_url % dict(
app='autocompletionexample', model='extraspam', id=1))
url = admin_change_url % dict(
app='autocompletionexample', model='extraspam', id=1)
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
response = self.client.post(
admin_change_url % dict(
app='autocompletionexample', model='extraspam', id=1),
url,
response.context['adminform'].form.initial,
follow=True,
)
self.assertEqual(response.status_code, 200)

url = '/admin/%(app)s/%(model)s/add/' % dict(app='demo',
model='inlinemodel')
response = self.client.get(url)
self.assertEqual(response.status_code, 200)

# Test Forms
def test_form(self):
form = Form(data=dict(
Expand Down
29 changes: 18 additions & 11 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@
import setuptools
from setuptools.command.test import test as TestCommand

from tags_input import metadata

# To prevent importing about and thereby breaking the coverage info we use this
# exec hack
about = {}
with open('tags_input/__about__.py') as fp:
exec(fp.read(), about)


if os.path.isfile('README.rst'):
long_description = open('README.rst').read()
with open('README.rst') as fh:
readme = fh.read()
else:
long_description = ('See http://pypi.python.org/pypi/' +
metadata.__package_name__)
readme = \
'See http://pypi.python.org/pypi/%(__package_name__)s/' % about


class PyTest(TestCommand):
Expand All @@ -26,12 +33,12 @@ def run_tests(self):


setuptools.setup(
name=metadata.__package_name__,
version=metadata.__version__,
author=metadata.__author__,
author_email=metadata.__author_email__,
description=metadata.__description__,
url=metadata.__url__,
name=about['__package_name__'],
version=about['__version__'],
author=about['__author__'],
author_email=about['__email__'],
description=about['__description__'],
url=about['__url__'],
license='BSD',
packages=setuptools.find_packages(exclude=[
'example',
Expand All @@ -46,7 +53,7 @@ def run_tests(self):
'static/css/base/images/*.png',
],
},
long_description=long_description,
long_description=readme,
cmdclass={'test': PyTest},
classifiers=['License :: OSI Approved :: BSD License'],
install_requires=[
Expand Down
11 changes: 11 additions & 0 deletions tags_input/__about__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
__package_name__ = 'django-tags-input'
__version__ = '4.0.0'
__author__ = 'Rick van Hattem'
__email__ = 'wolph@wol.ph'
__description__ = ' '.join('''
Django jQuery Tags Input is a Django field and widget wrapper that adds an easy
to use interface for `ManyToManyField` and `ForeignKey` fields in the forms of
autocompleting tags with optionally live creation of new linked
items
'''.strip().split())
__url__ = 'https://github.com/WoLpH/django-tags-input'
30 changes: 24 additions & 6 deletions tags_input/admin.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,54 @@
from django.contrib import admin

from . import fields
from . import widgets

from django.contrib import admin


class TagsInputMixin(object):
def get_tag_fields(self):
'''Get a list fo fields on this model that could be potentially tagged.
By default reads self.tag_fields if it exists of returns None for
default behavious.
'''

return getattr(self, 'tag_fields', None)

def formfield_for_manytomany(self, db_field, request=None, **kwargs):
'''
Get a form Field for a ManyToManyField.
'''
# If it uses an intermediary model that isn't auto created, don't show
# a field in admin.

if not db_field.rel.through._meta.auto_created:
return None

# If there is a list of taggable fields, and this filed isn't one of
# them, then fall back to parent method.
tag_fields = self.get_tag_fields()

if tag_fields and db_field.name not in tag_fields:
print('in fields', tag_fields, db_field.name)
return super(TagsInputMixin, self).formfield_for_manytomany(
db_field, request, **kwargs)
else:
print('nin fields', tag_fields, db_field.name)

queryset = db_field.rel.to._default_manager.get_queryset()

kwargs['queryset'] = queryset
kwargs['widget'] = widgets.AdminTagsInputWidget(
verbose_name=db_field.verbose_name,
is_stacked=db_field.name in self.filter_vertical,
attrs=kwargs.get('attrs'),
choices=kwargs.get('choices', ()),
)
choices=kwargs.get('choices', ()), )
kwargs['required'] = not db_field.blank
kwargs['help_text'] = getattr(db_field, 'help_text', None)
kwargs['verbose_name'] = getattr(db_field, 'verbose_name', None)

# Ugly hack to stop the Django admin from adding the + icon

if db_field.name not in self.raw_id_fields:
self.raw_id_fields = list(self.raw_id_fields)
self.raw_id_fields.append(db_field.name)
Expand All @@ -46,5 +66,3 @@ class TagsInputTabularInline(TagsInputMixin, admin.TabularInline):

class TagsInputStackedInline(TagsInputMixin, admin.StackedInline):
pass


10 changes: 0 additions & 10 deletions tags_input/metadata.py

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
15 changes: 0 additions & 15 deletions tags_input/static/css/base/jquery.ui.accordion.css

This file was deleted.

11 changes: 0 additions & 11 deletions tags_input/static/css/base/jquery.ui.all.css

This file was deleted.

13 changes: 0 additions & 13 deletions tags_input/static/css/base/jquery.ui.autocomplete.css

This file was deleted.

24 changes: 0 additions & 24 deletions tags_input/static/css/base/jquery.ui.base.css

This file was deleted.

39 changes: 0 additions & 39 deletions tags_input/static/css/base/jquery.ui.button.css

This file was deleted.

Loading

0 comments on commit 877d798

Please sign in to comment.