google-code-export / django-filebrowser

Automatically exported from code.google.com/p/django-filebrowser
Other
0 stars 0 forks source link

Patch for /trunk/filebrowser/fields.py #344

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
解决无法进行查询的错误,如:
q = q.exclude({ 'Image__exact' : '' })

Original issue reported on code.google.com by Kidw...@gmail.com on 2 Jun 2011 at 8:37

Attachments:

GoogleCodeExporter commented 9 years ago
this patch doesn´t work for me ... did you tested it?

Original comment by sehmaschine on 2 Jun 2011 at 8:48

GoogleCodeExporter commented 9 years ago
Sorry, my English is not good.
I hope you can understand.
I have a QuerySets object is 'q', i execute q = q.exclude({ 'Image__exact' : '' 
}) Not work,i Changed can execute,i don't know why。

Original comment by Kidw...@gmail.com on 2 Jun 2011 at 8:56

GoogleCodeExporter commented 9 years ago
I can´t follow your usecase ... can you try this one and tell me if it works:

def get_db_prep_value(self, value, connection, prepared=False):
    if not value:
        return None
    return value.url_save

Original comment by sehmaschine on 2 Jun 2011 at 8:59

GoogleCodeExporter commented 9 years ago
See the following error message:

TemplateSyntaxError at /

Caught AttributeError while rendering: 'str' object has no attribute 'url_save'

Request Method:     GET
Request URL:    http://127.0.0.1:8000/
Django Version:     1.4 pre-alpha SVN-16313
Exception Type:     TemplateSyntaxError
Exception Value:    

Caught AttributeError while rendering: 'str' object has no attribute 'url_save'

Exception Location:     E:\Program 
Files\Python26\lib\site-packages\filebrowser\fields.py in get_db_prep_value, 
line 101
Python Executable:  E:\Program Files\Python26\python.exe
Python Version:     2.6.5

...

E:\Program Files\Python26\lib\site-packages\filebrowser\fields.py in 
get_db_prep_value

            if not value or isinstance(value, FileObject):

                return value

            return FileObject(url_to_path(value))

        def get_db_prep_value(self, value, connection, prepared=False):

            if value is None:

                return None

            return value.url_save

    ...

        def formfield(self, **kwargs):

            attrs = {}

            attrs["directory"] = self.directory

            attrs["extensions"] = self.extensions

            attrs["format"] = self.format

▼ Local vars
Variable    Value
connection  

<django.db.backends.mysql.base.DatabaseWrapper object at 0x01721090>

self    

<filebrowser.fields.FileBrowseField: Image>

value   

''

prepared    

True

Original comment by Kidw...@gmail.com on 2 Jun 2011 at 9:04

GoogleCodeExporter commented 9 years ago
yes ... but you didn´t include my changes. what if you change 
get_db_prep_value as mentioned in comment3?

Original comment by sehmaschine on 2 Jun 2011 at 9:07

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
I has changed, but the result is under my expecation, I want to check all image 
uploading records.

Original comment by Kidw...@gmail.com on 2 Jun 2011 at 9:24

GoogleCodeExporter commented 9 years ago
my usecase:

>>> obj_list = BlogEntry.objects.all()
>>> obj_list
[<BlogEntry: testentry without image>, <BlogEntry: Testentry>]

>>> obj_list = BlogEntry.objects.exclude(image__exact="")
>>> obj_list
[<BlogEntry: testentry without image>]

>>> obj_list = BlogEntry.objects.filter(image__isnull=False)
>>> obj_list
[<BlogEntry: Testentry>]

Original comment by sehmaschine on 2 Jun 2011 at 9:24

GoogleCodeExporter commented 9 years ago
I has changed, but the result is under my expecation, I want to check all image 
uploading records. Now Did not return any records.

Original comment by Kidw...@gmail.com on 2 Jun 2011 at 9:25

GoogleCodeExporter commented 9 years ago
i test again!

Original comment by Kidw...@gmail.com on 2 Jun 2011 at 9:26

GoogleCodeExporter commented 9 years ago
my query is a method! exclude parameter is the dynamic transfer, like this :

def getListQuery(excludes)
    q = Article.objects.all()
    q = q.exclude(**excludes)
    return q

call :

list = getListQuery({ 'Image__exact' : '' })

how can i do????

Original comment by Kidw...@gmail.com on 2 Jun 2011 at 9:37

GoogleCodeExporter commented 9 years ago
I´m sorry, but that problem is not related to the filebrowser, is it?

Original comment by sehmaschine on 2 Jun 2011 at 9:46

GoogleCodeExporter commented 9 years ago
The previous version can execute, after updated, can't execute. 

Original comment by Kidw...@gmail.com on 2 Jun 2011 at 9:56

GoogleCodeExporter commented 9 years ago
so, you say that this doesn´t work? can you reply and replace the "???" with 
what you get ... if the list is too long, just tell me if you get what´s 
expected.

>>> obj_list = Article.objects.all()
>>> obj_list
???

>>> obj_list = Article.objects.exclude(image__exact="")
>>> obj_list
???

>>> obj_list = Article.objects.filter(image__isnull=False)
>>> obj_list
???

Original comment by sehmaschine on 2 Jun 2011 at 10:07

GoogleCodeExporter commented 9 years ago
sorry, I do not know how to express, my English is not good.
I changed it to:

def get_db_prep_value(self, value, connection, prepared=False):
        if value is None:
            return None
        if isinstance(value, basestring):
            return unicode(value)
        return value.url_save

Original comment by Kidw...@gmail.com on 2 Jun 2011 at 10:19

GoogleCodeExporter commented 9 years ago
why don´t you answer my question?

Original comment by sehmaschine on 2 Jun 2011 at 10:26

GoogleCodeExporter commented 9 years ago
Because my english is not good, i don't know how to expression.

Original comment by Kidw...@gmail.com on 2 Jun 2011 at 10:27

GoogleCodeExporter commented 9 years ago
are you on skype?

Original comment by sehmaschine on 2 Jun 2011 at 10:28

GoogleCodeExporter commented 9 years ago
Maybe i pass a string not object

Original comment by Kidw...@gmail.com on 2 Jun 2011 at 10:29

GoogleCodeExporter commented 9 years ago
get_db_prep_value should look like this (see r696):

def get_db_prep_value(self, value, connection, prepared=False):
    if not value:
        return value
    return value.url_save

Original comment by sehmaschine on 2 Jun 2011 at 10:34

GoogleCodeExporter commented 9 years ago
i don't konw how to explained,my value is a string not a FileObject

Original comment by Kidw...@gmail.com on 2 Jun 2011 at 10:40

GoogleCodeExporter commented 9 years ago
are you saying that you´re using a FileBrowseField and getting back a string 
(instead of a FileObject)?

Original comment by sehmaschine on 2 Jun 2011 at 10:43

GoogleCodeExporter commented 9 years ago
Hi there, I have got same error:

AttributeError at /admin/lookwish/retailer/1/
'unicode' object has no attribute 'url_save'
Request Method: POST
Request URL:    http://lookwish.ru:8000/admin/lookwish/retailer/1/
Django Version: 1.3
Exception Type: AttributeError
Exception Value:    
'unicode' object has no attribute 'url_save'
Exception 
Location:   /home/zakhar/workspace/lookwish/.env/src/django-filebrowser/filebrowse
r/fields.py in get_db_prep_value, line 101
Python Executable:  /home/zakhar/workspace/lookwish/.env/bin/python
Python Version: 2.7.1

Original comment by zakhar.zibarov on 6 Jul 2011 at 9:12

GoogleCodeExporter commented 9 years ago
Temporary I resolved problem by change get_db_prep_value to:

def get_db_prep_value(self, value, connection, prepared=False):
    if value is None:
        return None
    if isinstance(value, FileObject):
        return value.url_save
    return unicode(value)

Original comment by zakhar.zibarov on 6 Jul 2011 at 9:16

GoogleCodeExporter commented 9 years ago
Ops, the problem was resolved at trunk.

Original comment by zakhar.zibarov on 6 Jul 2011 at 9:37

GoogleCodeExporter commented 9 years ago
Congratulations

Original comment by Kidw...@gmail.com on 6 Jul 2011 at 9:42