Commit 9b0c9d46 by Daniel Hahler

flake8 fixes

parent 0591e1fa
...@@ -10,9 +10,11 @@ from taggit.utils import parse_tags, edit_string_for_tags ...@@ -10,9 +10,11 @@ from taggit.utils import parse_tags, edit_string_for_tags
class TagWidget(forms.TextInput): class TagWidget(forms.TextInput):
def render(self, name, value, attrs=None): def render(self, name, value, attrs=None):
if value is not None and not isinstance(value, six.string_types): if value is not None and not isinstance(value, six.string_types):
value = edit_string_for_tags([o.tag for o in value.select_related("tag")]) value = edit_string_for_tags([
o.tag for o in value.select_related("tag")])
return super(TagWidget, self).render(name, value, attrs) return super(TagWidget, self).render(name, value, attrs)
class TagField(forms.CharField): class TagField(forms.CharField):
widget = TagWidget widget = TagWidget
...@@ -21,4 +23,5 @@ class TagField(forms.CharField): ...@@ -21,4 +23,5 @@ class TagField(forms.CharField):
try: try:
return parse_tags(value) return parse_tags(value)
except ValueError: except ValueError:
raise forms.ValidationError(_("Please provide a comma-separated list of tags.")) raise forms.ValidationError(
_("Please provide a comma-separated list of tags."))
...@@ -102,7 +102,7 @@ class _TaggableManager(models.Manager): ...@@ -102,7 +102,7 @@ class _TaggableManager(models.Manager):
else 'content_object') else 'content_object')
fk = self.through._meta.get_field(fieldname) fk = self.through._meta.get_field(fieldname)
query = { query = {
'%s__%s__in' % (self.through.tag_relname(), fk.name) : '%s__%s__in' % (self.through.tag_relname(), fk.name):
set(obj._get_pk_val() for obj in instances) set(obj._get_pk_val() for obj in instances)
} }
join_table = self.through._meta.db_table join_table = self.through._meta.db_table
...@@ -110,8 +110,8 @@ class _TaggableManager(models.Manager): ...@@ -110,8 +110,8 @@ class _TaggableManager(models.Manager):
connection = connections[db] connection = connections[db]
qn = connection.ops.quote_name qn = connection.ops.quote_name
qs = self.get_queryset().using(db)._next_is_sticky().filter(**query).extra( qs = self.get_queryset().using(db)._next_is_sticky().filter(**query).extra(
select = { select={
'_prefetch_related_val' : '%s.%s' % (qn(join_table), qn(source_col)) '_prefetch_related_val': '%s.%s' % (qn(join_table), qn(source_col))
} }
) )
return (qs, return (qs,
...@@ -220,10 +220,12 @@ class _TaggableManager(models.Manager): ...@@ -220,10 +220,12 @@ class _TaggableManager(models.Manager):
class TaggableManager(RelatedField, Field): class TaggableManager(RelatedField, Field):
_related_name_counter = 0 _related_name_counter = 0
def __init__(self, verbose_name=_("Tags"), help_text=_("A comma-separated list of tags."), def __init__(self, verbose_name=_("Tags"),
help_text=_("A comma-separated list of tags."),
through=None, blank=False, related_name=None, to=None, through=None, blank=False, related_name=None, to=None,
manager=_TaggableManager): manager=_TaggableManager):
Field.__init__(self, verbose_name=verbose_name, help_text=help_text, blank=blank, null=True, serialize=False) Field.__init__(self, verbose_name=verbose_name, help_text=help_text,
blank=blank, null=True, serialize=False)
self.through = through or TaggedItem self.through = through or TaggedItem
self.rel = TaggableRel(self, related_name, self.through, to=to) self.rel = TaggableRel(self, related_name, self.through, to=to)
self.swappable = False self.swappable = False
...@@ -238,7 +240,7 @@ class TaggableManager(RelatedField, Field): ...@@ -238,7 +240,7 @@ class TaggableManager(RelatedField, Field):
through=self.through, through=self.through,
model=model, model=model,
instance=instance, instance=instance,
prefetch_cache_name = self.name prefetch_cache_name=self.name
) )
return manager return manager
...@@ -287,7 +289,6 @@ class TaggableManager(RelatedField, Field): ...@@ -287,7 +289,6 @@ class TaggableManager(RelatedField, Field):
else: else:
self.post_through_setup(cls) self.post_through_setup(cls)
def __lt__(self, other): def __lt__(self, other):
""" """
Required contribute_to_class as Django uses bisect Required contribute_to_class as Django uses bisect
...@@ -364,7 +365,7 @@ class TaggableManager(RelatedField, Field): ...@@ -364,7 +365,7 @@ class TaggableManager(RelatedField, Field):
def extra_filters(self, pieces, pos, negate): def extra_filters(self, pieces, pos, negate):
if negate or not self.use_gfk: if negate or not self.use_gfk:
return [] return []
prefix = "__".join(["tagged_items"] + pieces[:pos-2]) prefix = "__".join(["tagged_items"] + pieces[:pos - 2])
get = ContentType.objects.get_for_model get = ContentType.objects.get_for_model
cts = [get(obj) for obj in _get_subclasses(self.model)] cts = [get(obj) for obj in _get_subclasses(self.model)]
if len(cts) == 1: if len(cts) == 1:
...@@ -378,13 +379,18 @@ class TaggableManager(RelatedField, Field): ...@@ -378,13 +379,18 @@ class TaggableManager(RelatedField, Field):
else: else:
alias_to_join = lhs_alias alias_to_join = lhs_alias
extra_col = self.through._meta.get_field_by_name('content_type')[0].column extra_col = self.through._meta.get_field_by_name('content_type')[0].column
content_type_ids = [ContentType.objects.get_for_model(subclass).pk for subclass in _get_subclasses(self.model)] content_type_ids = [ContentType.objects.get_for_model(subclass).pk for
subclass in _get_subclasses(self.model)]
if len(content_type_ids) == 1: if len(content_type_ids) == 1:
content_type_id = content_type_ids[0] content_type_id = content_type_ids[0]
extra_where = " AND %s.%s = %%s" % (qn(alias_to_join), qn(extra_col)) extra_where = " AND %s.%s = %%s" % (qn(alias_to_join),
qn(extra_col))
params = [content_type_id] params = [content_type_id]
else: else:
extra_where = " AND %s.%s IN (%s)" % (qn(alias_to_join), qn(extra_col), ','.join(['%s']*len(content_type_ids))) extra_where = " AND %s.%s IN (%s)" % (qn(alias_to_join),
qn(extra_col),
','.join(['%s'] *
len(content_type_ids)))
params = content_type_ids params = content_type_ids
return extra_where, params return extra_where, params
......
...@@ -59,7 +59,7 @@ class TagBase(models.Model): ...@@ -59,7 +59,7 @@ class TagBase(models.Model):
except IntegrityError: except IntegrityError:
pass pass
# Now try to find existing slugs with similar names # Now try to find existing slugs with similar names
slugs = set(Tag.objects.filter(slug__startswith=self.slug)\ slugs = set(Tag.objects.filter(slug__startswith=self.slug)
.values_list('slug', flat=True)) .values_list('slug', flat=True))
i = 1 i = 1
while True: while True:
...@@ -145,7 +145,7 @@ class GenericTaggedItemBase(ItemBase): ...@@ -145,7 +145,7 @@ class GenericTaggedItemBase(ItemBase):
content_object = GenericForeignKey() content_object = GenericForeignKey()
class Meta: class Meta:
abstract=True abstract = True
@classmethod @classmethod
def lookup_kwargs(cls, instance): def lookup_kwargs(cls, instance):
......
...@@ -18,4 +18,3 @@ def tagged_object_list(request, slug, queryset, **kwargs): ...@@ -18,4 +18,3 @@ def tagged_object_list(request, slug, queryset, **kwargs):
kwargs["extra_context"] = {} kwargs["extra_context"] = {}
kwargs["extra_context"]["tag"] = tag kwargs["extra_context"]["tag"] = tag
return ListView.as_view(request, qs, **kwargs) return ListView.as_view(request, qs, **kwargs)
...@@ -6,7 +6,7 @@ from .models import Food, DirectFood, CustomPKFood, OfficialFood ...@@ -6,7 +6,7 @@ from .models import Food, DirectFood, CustomPKFood, OfficialFood
fields = None fields = None
if VERSION >= (1,6): if VERSION >= (1, 6):
fields = '__all__' fields = '__all__'
......
...@@ -150,7 +150,7 @@ class TaggableManagerTestCase(BaseTaggingTestCase): ...@@ -150,7 +150,7 @@ class TaggableManagerTestCase(BaseTaggingTestCase):
# make sure we don't double create. # make sure we don't double create.
# + 12 on Django 1.6 for save points. # + 12 on Django 1.6 for save points.
queries = 22 queries = 22
if django.VERSION < (1,6): if django.VERSION < (1, 6):
queries -= 12 queries -= 12
self.assertNumQueries(queries, apple.tags.add, "red", "delicious", "green") self.assertNumQueries(queries, apple.tags.add, "red", "delicious", "green")
...@@ -160,7 +160,7 @@ class TaggableManagerTestCase(BaseTaggingTestCase): ...@@ -160,7 +160,7 @@ class TaggableManagerTestCase(BaseTaggingTestCase):
# make sure we dont't double create. # make sure we dont't double create.
# + 4 on Django 1.6 for save points. # + 4 on Django 1.6 for save points.
queries = 9 queries = 9
if django.VERSION < (1,6): if django.VERSION < (1, 6):
queries -= 4 queries -= 4
self.assertNumQueries(queries, pear.tags.add, "green", "delicious") self.assertNumQueries(queries, pear.tags.add, "green", "delicious")
...@@ -254,7 +254,7 @@ class TaggableManagerTestCase(BaseTaggingTestCase): ...@@ -254,7 +254,7 @@ class TaggableManagerTestCase(BaseTaggingTestCase):
pear = self.food_model.objects.create(name="pear") pear = self.food_model.objects.create(name="pear")
pear.tags.add("green", "delicious") pear.tags.add("green", "delicious")
guava = self.food_model.objects.create(name="guava") self.food_model.objects.create(name="guava")
pks = self.food_model.objects.exclude(tags__name__in=["red"]) pks = self.food_model.objects.exclude(tags__name__in=["red"])
model_name = self.food_model.__name__ model_name = self.food_model.__name__
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment