liberation / django-elasticsearch

Simple wrapper around elasticsearch-py to index/search a django Model.
MIT License
211 stars 73 forks source link

NameError: name 'basestring' is not defined #57

Open ignacionf opened 8 years ago

ignacionf commented 8 years ago

i has this error in a clean code:

14:25 $ git diff
diff --git a/requeriments.txt b/requeriments.txt
index 47d501b..5f36098 100644
--- a/requeriments.txt
+++ b/requeriments.txt
@@ -29,3 +29,5 @@ django-ajax-selects==1.4.1
 Babel==2.3.4
 django-compressor==2.1
 django-libsass==0.7
+elasticsearch==2.3.0
+git+https://github.com/liberation/django_elasticsearch.git
diff --git a/uniresto/products/models.py b/uniresto/products/models.py
index c78781d..4928754 100644
--- a/uniresto/products/models.py
+++ b/uniresto/products/models.py
@@ -9,6 +9,8 @@ from imagekit.processors import ResizeToFill
 from image_cropping import ImageRatioField
 from enum import Enum
 from django.utils.text import slugify
+from django_elasticsearch.models import EsIndexable
+

 COMBO_PRODUCT_TYPES = (
@@ -166,7 +168,7 @@ class Category(models.Model):
         verbose_name_plural = 'Categorias de productos (Pasta, carnes, etc).'

-class ProductTemplates(models.Model):
+class ProductTemplates(EsIndexable, models.Model):
     """
     Almacena plantillas de productos por categorias. Se utiliza para agilizar el registro de todos los productos
     de marca comercial o no ya definidos.
14:36 $ 

in settings:

ELASTICSEARCH_URL='http://localhost:9200'
ELASTICSEARCH_AUTO_INDEX=True
ELASTICSEARCH_DEFAULT_INDEX='uniresto'

Tracktrace:

NameError                                 Traceback (most recent call last)
<ipython-input-3-be67e0bf0776> in <module>()
----> 1 ProductTemplates(name="caca", category=o, celiac=False, delivery=True, consumed_in_store=True, max_choices=1).save()

/home/ignacio/uniresto/lib/python3.5/site-packages/django_elasticsearch/models.py in save(self, *args, **kwargs)
     52     def save(self, *args, **kwargs):
     53         self._raise_no_db_operation()
---> 54         super(EsIndexable, self).save(*args, **kwargs)
     55 
     56     def delete(self, *args, **kwargs):

/home/ignacio/uniresto/lib/python3.5/site-packages/django/db/models/base.py in save(self, force_insert, force_update, using, update_fields)
    708 
    709         self.save_base(using=using, force_insert=force_insert,
--> 710                        force_update=force_update, update_fields=update_fields)
    711     save.alters_data = True
    712 

/home/ignacio/uniresto/lib/python3.5/site-packages/django/db/models/base.py in save_base(self, raw, force_insert, force_update, using, update_fields)
    745         if not meta.auto_created:
    746             signals.post_save.send(sender=origin, instance=self, created=(not updated),
--> 747                                    update_fields=update_fields, raw=raw, using=using)
    748 
    749     save_base.alters_data = True

/home/ignacio/uniresto/lib/python3.5/site-packages/django/dispatch/dispatcher.py in send(self, sender, **named)
    199 
    200         for receiver in self._live_receivers(sender):
--> 201             response = receiver(signal=self, sender=sender, **named)
    202             responses.append((receiver, response))
    203         return responses

/home/ignacio/uniresto/lib/python3.5/site-packages/django_elasticsearch/models.py in es_save_callback(sender, instance, **kwargs)
     70     if not issubclass(sender, EsIndexable):
     71         return
---> 72     instance.es.do_index()
     73 
     74 

/home/ignacio/uniresto/lib/python3.5/site-packages/django_elasticsearch/managers.py in wrapper(*args, **kwargs)
     44         if args[0].instance is None:
     45             raise AttributeError("This method requires an instance of the model.")
---> 46         return f(*args, **kwargs)
     47     return wrapper
     48 

/home/ignacio/uniresto/lib/python3.5/site-packages/django_elasticsearch/managers.py in do_index(self)
    122     @needs_instance
    123     def do_index(self):
--> 124         body = self.serialize()
    125         es_client.index(index=self.index,
    126                         doc_type=self.doc_type,

/home/ignacio/uniresto/lib/python3.5/site-packages/django_elasticsearch/managers.py in wrapper(*args, **kwargs)
     44         if args[0].instance is None:
     45             raise AttributeError("This method requires an instance of the model.")
---> 46         return f(*args, **kwargs)
     47     return wrapper
     48 

/home/ignacio/uniresto/lib/python3.5/site-packages/django_elasticsearch/managers.py in serialize(self)
    101         Note: by default, will use all the model's fields.
    102         """
--> 103         serializer = self.get_serializer()
    104         return serializer.serialize(self.instance)
    105 

/home/ignacio/uniresto/lib/python3.5/site-packages/django_elasticsearch/managers.py in get_serializer(self, **kwargs)
     88     def get_serializer(self, **kwargs):
     89         serializer = self.model.Elasticsearch.serializer_class
---> 90         if isinstance(serializer, basestring):
     91             module, kls = self.model.Elasticsearch.serializer_class.rsplit(".", 1)
     92             mod = importlib.import_module(module)

NameError: name 'basestring' is not defined
lauxley commented 8 years ago

Yep the code is still not python3 ready :(

ignacionf commented 8 years ago

ouch....

ok, i can help with this, but i need time.

ignacionf commented 8 years ago

http://stackoverflow.com/questions/11301138/how-to-check-if-variable-is-string-with-python-2-and-3-compatibility

ignacionf commented 8 years ago

╰། ◉ ◯ ◉ །╯

https://github.com/liberation/django-elasticsearch/blob/master/django_elasticsearch/managers.py#L3-L12

ahopkins commented 8 years ago

Is anyone working on upgrading this to work with Python3?

ignacionf commented 8 years ago

My fork is for py3. Can you test?

El 23 sept. 2016 2:37 a. m., "Adam Hopkins" notifications@github.com escribió:

Is anyone working on upgrading this to work with Python3?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/liberation/django-elasticsearch/issues/57#issuecomment-249114355, or mute the thread https://github.com/notifications/unsubscribe-auth/AAGLRAl4G0jAf0LRTSDMvQfwlqmuvplwks5qs3OxgaJpZM4JsQ4g .

ahopkins commented 8 years ago

Awesome. Yeah, I'll take a look next week and see if I can help out.

On Fri, Sep 23, 2016, 15:31 Ignacio Feijoo notifications@github.com wrote:

My fork is for py3. Can you test?

El 23 sept. 2016 2:37 a. m., "Adam Hopkins" notifications@github.com escribió:

Is anyone working on upgrading this to work with Python3?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub < https://github.com/liberation/django-elasticsearch/issues/57#issuecomment-249114355 , or mute the thread < https://github.com/notifications/unsubscribe-auth/AAGLRAl4G0jAf0LRTSDMvQfwlqmuvplwks5qs3OxgaJpZM4JsQ4g

.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/liberation/django-elasticsearch/issues/57#issuecomment-249179557, or mute the thread https://github.com/notifications/unsubscribe-auth/AAKJfXvDTXXM3TwJnazgtck9XKN7ADfgks5qs8awgaJpZM4JsQ4g .