Re: WEB SERVICE IN DJANGO USING SOAP

2010-11-26 Thread Sam Lai
No, you need that line. It is the first *character* of the file that
you need to remove. It is an *invisible* character. Try opening and
closing it in notepad; it might remove it. Otherwise, can you get your
WSDL generator to not output the BOM?

Or, you could use python to read and rewrite that file without the BOM.

On 27 November 2010 18:13, sami nathan  wrote:
> encoding="UTF-8"?> should i remove this from wsdl file...? and more
> over i am trying to use my system as  server i am refering dive into
> python chapter 12 introspecting wsdl and searching google i cant find
> weather its an client side code or server side code but i am in need
> of server side code do u find any refrence for me to study server side
> code using SOAP or REST sorry if i had asked anything wrong i am
> newbee
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: WEB SERVICE IN DJANGO USING SOAP

2010-11-26 Thread sami nathan
encoding="UTF-8"?> should i remove this from wsdl file...? and more
over i am trying to use my system as  server i am refering dive into
python chapter 12 introspecting wsdl and searching google i cant find
weather its an client side code or server side code but i am in need
of server side code do u find any refrence for me to study server side
code using SOAP or REST sorry if i had asked anything wrong i am
newbee

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: WEB SERVICE IN DJANGO USING SOAP

2010-11-26 Thread Sam Lai
How was the WSDL generated? Was it done on a Windows machine? If so,
it writes a Byte Order Mark at the start of Unicode documents by
default. *nix and Python however doesn't expect BOMs, so it chokes.

You need to remove the BOM from your WSDL file.

On 27 November 2010 17:46, sami nathan  wrote:
> Thanks for notification I am trying to develop web service using
> django with soap interface i checked my code in python to open wsdl
> file but its showing error i am sure that wsdl file dosent have any
> errors this is my code>>> from SOAPpy import WSDL
>>> server=WSDL.Proxy('D/soap/FlyppSms.wsdl')
> Traceback (most recent call last):
>  File "", line 1, in 
>  File "D:\Python25\Lib\site-packages\SOAPpy\WSDL.py", line 67, in __init__
>    self.wsdl = reader.loadFromString(str(wsdlsource))
>  File "D:\Python25\Lib\site-packages\SOAPpy\wstools\WSDLTools.py", line 47, in
> loadFromString
>    return self.loadFromStream(StringIO(data))
>  File "D:\Python25\Lib\site-packages\SOAPpy\wstools\WSDLTools.py", line 28, in
> loadFromStream
>    document = DOM.loadDocument(stream)
>  File "D:\Python25\Lib\site-packages\SOAPpy\wstools\Utility.py", line 602, in 
> l
> oadDocument
>    return xml.dom.minidom.parse(data)
>  File "D:\Python25\Lib\site-packages\_xmlplus\dom\minidom.py", line 1915, in 
> pa
> rse
>    return expatbuilder.parse(file)
>  File "D:\Python25\Lib\site-packages\_xmlplus\dom\expatbuilder.py", line 930, 
> i
> n parse
>    result = builder.parseFile(file)
>  File "D:\Python25\Lib\site-packages\_xmlplus\dom\expatbuilder.py", line 207, 
> i
> n parseFile
>    parser.Parse(buffer, 0)
> xml.parsers.expat.ExpatError: not well-formed (invalid token): line 1, column 
> 1
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Caching middleware causes default page caching

2010-11-26 Thread Ashish Gupta
yes, I mistakenly thought I need middleware to cache db objects. I guess
following is enough for my needs,

CACHE_BACKEND = 'locmem://'

from django.core.cache import cache
 and cache.set('add_key', 'Initial value')
>>> cache.add('add_key', 'New value')
>>> cache.get('add_key')

thanks

On Fri, Nov 26, 2010 at 9:02 PM, Christophe Pettus  wrote:

>
> On Nov 26, 2010, at 8:30 PM, ydjango wrote:
>
> > I have added following to cache some common DB data and it seems it
> > has started caching whole pages by default. Some pages appeared to be
> > retrieved from cache without even hitting the view.
>
> Unless I'm missing something, that's exactly what it is supposed to be
> doing.  The cache middleware caches your entire site, all the time, by
> default.  If all you want to do is use the cache framework to store some
> database objects, you don't need the cache middleware.
>
>
> http://docs.djangoproject.com/en/1.2/topics/cache/#the-per-site-cache
>
> --
> -- Christophe Pettus
>   x...@thebuild.com
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



WEB SERVICE IN DJANGO USING SOAP

2010-11-26 Thread sami nathan
Thanks for notification I am trying to develop web service using
django with soap interface i checked my code in python to open wsdl
file but its showing error i am sure that wsdl file dosent have any
errors this is my code>>> from SOAPpy import WSDL
>> server=WSDL.Proxy('D/soap/FlyppSms.wsdl')
Traceback (most recent call last):
  File "", line 1, in 
  File "D:\Python25\Lib\site-packages\SOAPpy\WSDL.py", line 67, in __init__
self.wsdl = reader.loadFromString(str(wsdlsource))
  File "D:\Python25\Lib\site-packages\SOAPpy\wstools\WSDLTools.py", line 47, in
loadFromString
return self.loadFromStream(StringIO(data))
  File "D:\Python25\Lib\site-packages\SOAPpy\wstools\WSDLTools.py", line 28, in
loadFromStream
document = DOM.loadDocument(stream)
  File "D:\Python25\Lib\site-packages\SOAPpy\wstools\Utility.py", line 602, in l
oadDocument
return xml.dom.minidom.parse(data)
  File "D:\Python25\Lib\site-packages\_xmlplus\dom\minidom.py", line 1915, in pa
rse
return expatbuilder.parse(file)
  File "D:\Python25\Lib\site-packages\_xmlplus\dom\expatbuilder.py", line 930, i
n parse
result = builder.parseFile(file)
  File "D:\Python25\Lib\site-packages\_xmlplus\dom\expatbuilder.py", line 207, i
n parseFile
parser.Parse(buffer, 0)
xml.parsers.expat.ExpatError: not well-formed (invalid token): line 1, column 1

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Caching middleware causes default page caching

2010-11-26 Thread Christophe Pettus

On Nov 26, 2010, at 8:30 PM, ydjango wrote:

> I have added following to cache some common DB data and it seems it
> has started caching whole pages by default. Some pages appeared to be
> retrieved from cache without even hitting the view.

Unless I'm missing something, that's exactly what it is supposed to be doing.  
The cache middleware caches your entire site, all the time, by default.  If all 
you want to do is use the cache framework to store some database objects, you 
don't need the cache middleware.

http://docs.djangoproject.com/en/1.2/topics/cache/#the-per-site-cache

--
-- Christophe Pettus
   x...@thebuild.com

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Caching middleware causes default page caching

2010-11-26 Thread ydjango
I have added following to cache some common DB data and it seems it
has started caching whole pages by default. Some pages appeared to be
retrieved from cache without even hitting the view.

I am using
CACHE_BACKEND = 'locmem://'

following middleware  in following order

'django.middleware.cache.UpdateCacheMiddleware',
   'django.middleware.common.CommonMiddleware',
   'django.contrib.sessions.middleware.SessionMiddleware',
   'django.contrib.auth.middleware.AuthenticationMiddleware',
   'django.middleware.doc.XViewMiddleware',
   'django.middleware.cache.FetchFromCacheMiddleware',

and in my views,

from django.core.cache import cache
 and cache.set('add_key', 'Initial value')
>>> cache.add('add_key', 'New value')
>>> cache.get('add_key')
'Initial value'

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: remember me in login

2010-11-26 Thread creecode
Hello robos85,

On Nov 26, 4:07 pm, robos85  wrote:

> Is there any easy way to do remember me trigger during login?

For remember me functionality you can try my remember me app at
.

> I know that there is SESSION_COOKIE_AGE but it's set site-wide. Is
> there any possibility to set expiration at browser close or x time?

You can accomplish the first with remember me and by not checking the
remember me checkbox.  The second is also possible but my app doesn't
do that.  You could probably adapt the code in remember me to do x
time or at least it might point you in the right direction.

Others have dealt with this issue I'm sure a Google search would
product some results.

Toodle-loo...
creecode

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: newbie: concept question

2010-11-26 Thread Łukasz Rekucki
On 26 November 2010 21:09, Charlietuna  wrote:
> Hi all,
>
> I looked for FAQ, but I couldn't find any. Here's my question. I've
> been working through the tutorials. I've taken a community college
> class on Python. So, I have some background there.
> I've gotten Django installed and working. So far, I've used sqlite3.
>
> Here's the question:  If you have an MySql database that is already
> establised with data, etc,
> how do you get Django to set up the abstraction of the db, so that you
> can access the data.
>
> I've worked with the tutorials where you use Django to create the
> database. You use syncdb command to setup the "abstraction" of the
> data. How do you do it the other direction?

If you have an existing schema in your database, you can use
django-admin.py inspectdb[1] to create models from it. It's not
guaranteed to be 100% correct, so you may need to tweak the generated
models. If you have a database table that you want to access, but
don't won't Django to manage it's schema, you can use
"managed=False"[2] on the model. Hope that helps :)

[1]: http://docs.djangoproject.com/en/dev/ref/django-admin/#inspectdb
[2]: http://docs.djangoproject.com/en/dev/ref/models/options/#managed

-- 
Łukasz Rekucki

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: remember me in login

2010-11-26 Thread Addy Yeow
i use this http://djangosnippets.org/snippets/1881/

On Sat, Nov 27, 2010 at 8:07 AM, robos85  wrote:

> Is there any easy way to do remember me trigger during login?
> I know that there is SESSION_COOKIE_AGE but it's set site-wide. Is
> there any possibility to set expiration at browser close or x time?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



newbie: concept question

2010-11-26 Thread Charlietuna
Hi all,

I looked for FAQ, but I couldn't find any. Here's my question. I've
been working through the tutorials. I've taken a community college
class on Python. So, I have some background there.
I've gotten Django installed and working. So far, I've used sqlite3.

Here's the question:  If you have an MySql database that is already
establised with data, etc,
how do you get Django to set up the abstraction of the db, so that you
can access the data.

I've worked with the tutorials where you use Django to create the
database. You use syncdb command to setup the "abstraction" of the
data. How do you do it the other direction?

Thanks for all your help.

Steve

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



remember me in login

2010-11-26 Thread robos85
Is there any easy way to do remember me trigger during login?
I know that there is SESSION_COOKIE_AGE but it's set site-wide. Is
there any possibility to set expiration at browser close or x time?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Askani

2010-11-26 Thread Wim Feijen
Nice! It definitely saves typing. Sounds like a right thing for
newbies, because when I was a newbie, I always had to look up which
fieldname to use and oh the typos.

Wim

On Nov 20, 3:28 pm, Alvaro Mouriño  wrote:
> Hi.
>
> I'd like to introduce to you this idea I've been working on for the
> last month, a django models generator:http://askani.net/
>
> Field options definition it's repetitive. Writing meta options leads
> to inconsistent use due to the variety available. "Inspired" by the
> repetitiveness of coding django models and the required memory load of
> defining meta options I decided to create a graphical interface that
> would guide the user in the creation of models.
>
> Askani.net is the result of scratching those itches. It represents
> models, fields, attributes and meta options in a UML-and-MER-ish way
> (but doesn't follow it strictly). It displays all the possible
> information for a model so the user only has to fill in the blanks the
> desired options, not remember all of them.
>
> The python code that outputs it's far from perfect, I know, this is
> just a barely-usable system to prove the concept, a prototype.
>
> The reason for this email is to request comments, suggestions and
> critics on the idea and specially on the usability. Clone the source,
> read the README file and play with it. Have fun =)
>
> Regards,
>
> --
> Alvaro Mouriñohttp://askani.net/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Reusing actions "Save and continue editing" and "Save"

2010-11-26 Thread Wim Feijen
Hi Lom,

I would recommend the following:
1. Add all three buttons to your template
2. In your view, handle the form saving and then determine which
button has been pressed.
3. Accordingly, redirect to the same url (for example, redirect("/
address/14") for viewing, redirect("/address/14/edit") for continue
editing, or redirect("address/add") to add another).

For the redirect function, see:
http://docs.djangoproject.com/en/dev/topics/http/shortcuts/

Hope this helps.

Best regards,

Wim


On Nov 23, 3:46 pm, lom276  wrote:
> Hi all.
>
> I want to ask you if there is a best way to implement the actions
> "Save and add another", "Save and continue editing" and "Save" for my
> own forms. Is it possible to reuse the functionality from the Admin-
> Interface or do I have to invent the wheel again and implement it
> without reusing any existing code?
>
> Thank you.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Building Privacy Options Like Facebook with Django

2010-11-26 Thread Wim Feijen
Hi Corey,

I would recommend using a UserProfile for this, which is bound to a
user (so make sure an authenticated user can access only his profile
by using request.user.get_profile() in your views.

See: http://docs.djangoproject.com/en/dev/topics/auth/

Good luck!

Best regards,

Wim

On Nov 25, 5:49 am, Corey  wrote:
> I was trying to build a website that would be a good idea to have
> privacy options to hide certain data such as Facebook does with
> personal info. I am a somewhat newbie to Django and website building
> in general. So Im trying to wrap my head around how to work on this. I
> have indeed tried to look on Google to find something regarding this
> but have had no luck. Any pointers or tutorial links regarding this
> would be greatly appreciated. Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Central Login with Redirecting users based on Groups

2010-11-26 Thread Wim Feijen
In addition, you can use permissions to deny access for users to
certain views by using the permission_required decorator, see:

http://docs.djangoproject.com/en/dev/topics/auth/

Wim

On Nov 25, 4:46 pm, Knut Ivar Nesheim  wrote:
> Hi Stefan,
>
> If you roll your own login view, this can be done by simply
> redirecting to the correct url after authentication. You would have to
> come up with the correct url by looking at the groups. Consider
> something like this:
>
> def login_view(request):
>     # login and authenticate..
>     user = User object
>
>     url = get_redirect_url(user)
>     return HttpResponseRedirect(url)
>
> def get_redirect_url(user):
>     if user.groups.filter(name = 'Manager'):
>         return '/managers'/
>    elif user.groups.filter(name = 'Users'):
>         return '/users/'
>
>    return '/'
>
> This could be further improved by using some Django helpers, like
> 'redirect' and 'reverse'.
>
> If you have many groups, you could improve this by having a dict
> mapping group name to url. Consider something like this in your
> settings
>
> LOGIN_URL_MAP = {
>     'Managers': '/managers'/,
>     'Users': '/users':
>
> }
>
> Then 'get_redirect_url' could look something like this:
>
> def get_redirect_url(user):
>     url = '/'
>     for group in user.groups.all():
>         url = settings.LOGIN_URL_MAP[group.name]
>
>     return url
>
> Regards
> Knut
>
> On Thu, Nov 25, 2010 at 10:24 AM, stefanvonfintel
>
>
>
>
>
>
>
>  wrote:
> > Hi all.
>
> > I am new to Django and have just recently started using it for a new
> > project at our company.
> > I have a bit of problem at the moment. What I would ideally like is to
> > have one central login for users and then redirect them based on the
> > groups that
> > they belong to once they have been authenticated successfully ie. for
> > managers they get redirected towww.example.com/manager/and for
> > normal
> > users they get redirected towww.example.com/users/.
>
> > I have searched google and the forums for a while and can not get an
> > answer to this question.
> > So I have given up on that idea that's why at the moment I have got
> > two different login forms one on /users/ and one on /managers/. But
> > they are both using the login() and authenticate() functions that are
> > built in to django. This is a problem since if you login to /users/
> > then you have access to /managers/ without logging in there. Or is the
> > some other way that I am completely missing?
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: extends a template that is stored in an app template directory

2010-11-26 Thread Wim Feijen
Hi Owidjaya,

Common usage is to refer to your_app_name/template_name.html , so you
can put for example

{% extends "datagrid/template1.html" %}

in your client template.

So it is recommended to store your templates in a directory
your_app_name/templates/your_app_name/template_name.html

For more info, see http://docs.djangoproject.com/en/1.2/topics/templates/

Hope this helps.

Best regards, Wim


On Nov 26, 7:48 pm, owidjaya  wrote:
> How do i extends a template that is stored within an application
> template directory from another application?
> I have two apps
> one is datagrid and the other one is client
> I want to use datagrid to display list of clients
> but instead of using the datagrid template that comes from the app, i
> want to extend that template to modify the datagrid for client display

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Models not being updated when accessed by multiple processes

2010-11-26 Thread Iqbal Abdullah
After a bit more of searching I've finally figured out what I wanted
is "atomic updates".

Using the F() expression seems to be the best solution without much
code overhaul:
http://stackoverflow.com/questions/280075/atomic-operations-in-django
http://efreedom.com/Question/1-1598932/Atomic-Increment-Counter-Django

Thanks JeeyoungKim for pointing to the right direction.

On 11月23日, 午後5:52, Iqbal Abdullah  wrote:
> Since we only run the application on a single server we're using file
> based locking; fail_to_get_lock() and release_lock() tries to create a
> file in the tmp directory with the user's unique identification data,
> and release_lock() deletes it.
>
> What I don't understand is, even if the save() method is not thread
> safe, am I correct to assume that everytime I call something like
> object = MyModel.object.get(id=1) I will get the latest data for
> object?
>
> On 11月20日, 午後2:18, JeeyoungKim  wrote:
>
> > I'm wondering, how are fail_to_get_lock and release_lock implemented?
> > It would be some kind of multiprocess lock, which seems overly
> > complicated..
>
> > using save() in this case is cumbersome, because save() isnot
> > threadsafe... you'll have to try to maintain your own lock.
>
> > If you only want to implement increments and decrements, you can use
> > F() object and update() methods to update the database.
>
> > I have an example, here
>
> >http://pastebin.com/qp4ExWC2
>
> > On Nov 19, 4:30 pm, Iqbal Abdullah  wrote:
>
> > > Hi Steve,
>
> > > Ops, yes, I forgot to include the object.save() in the pseudo code
> > > above. Yes, we're actually saving it:
>
> > > 1 object = MyModel.object.get(id=1)
> > > 2 print object.value    # starting value is 5
> > > 3 while object.fail_to_get_lock():
> > > 4    sleep(5)
> > > 5 object = MyModel.object.get(id=1)  # Re-get the object so we can
> > > have the latest state
> > > 6 object.value = object.value - 1
> > > 7 object.save()
> > > 8 print object.value    # returns 4
> > > 9 object.release_lock()
>
> > > On 11月20日, 午前7:39, Steve Holden  wrote:
>
> > > > On 11/19/2010 5:35 PM, Iqbal Abdullah wrote:
>
> > > > > Hi,
>
> > > > > This might be a gotcha on themodelsside, but I would like
> > > > > clarification and guidance on how to write the code better concerning
> > > > >multipleprocess accessing the same data viamodels.
>
> > > > > I have a backend script that runs the following code inmultiple
> > > > >processes:
>
> > > > > 1 object = MyModel.object.get(id=1)
> > > > > 2 print object.value    # starting value is 5
> > > > > 3 while object.fail_to_get_lock():
> > > > > 4    sleep(5)
> > > > > 5 object = MyModel.object.get(id=1)  # Re-get the object so we can
> > > > > have the latest state
> > > > > 6 object.value = object.value - 1
> > > > > 7 print object.value    # returns 4
> > > > > 8 object.release_lock()
>
> > > > > If the above code fails to get the lock because another process is
> > > > > running the code, it goes to sleep until the other process finishes.
> > > > > The other process will also be decrementing object.value, so if we
> > > > > have 2processesrunning the above script at the same time, I would
> > > > > expect the later process to return line 7 as 3 andnot4.
>
> > > > Shouldn't some saving occur for that to be true?
>
> > > > regards
> > > >  Steve
> > > > --
> > > > DjangoCon US 2010 September 7-9http://djangocon.us/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: how to do Query profiling of views called from AJAX calls?

2010-11-26 Thread Matteius
Have you tried using Firebug Firefox Add-on?

On Nov 25, 3:46 pm, ydjango  wrote:
> Django debug and django debug tool bar are not capturing the django
> ORM calls made from the views which are called via AJAX calls in the
> page . Is there any way to profile these sqls and times ?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Caught UnicodeDecodeError when using {% get_available_languages as langs %}

2010-11-26 Thread Federico Capoano
Thanks Tom.



On Nov 26, 9:15 pm, Tom Evans  wrote:
> On Fri, Nov 26, 2010 at 7:46 PM, Federico Capoano
>
>
>
>
>
>
>
>
>
>  wrote:
> > Hi all,
>
> > this is my settings.py
>
> > _ = lambda s: s
>
> > LANGUAGES = (
> >  ('en', _('English')),
> >  ('es', _('Español')),
> >  ('it', _('Italiano')),
> > )
>
> > When I use {% get_available_languages as langs %}
>
> > I get this error:
>
> > TemplateSyntaxError at /
> > Caught UnicodeDecodeError while rendering: 'ascii' codec can't decode
> > byte 0xc3 in position 4: ordinal not in range(128)
>
> > Am I doing something wrong?
>
> Mark the strings correctly as unicode, eg _(u'Español'). I'm assuming
> your file encoding on settings.py is UTF-8.
>
> HTH
>
> Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Caught UnicodeDecodeError when using {% get_available_languages as langs %}

2010-11-26 Thread Tom Evans
On Fri, Nov 26, 2010 at 7:46 PM, Federico Capoano
 wrote:
> Hi all,
>
> this is my settings.py
>
> _ = lambda s: s
>
> LANGUAGES = (
>  ('en', _('English')),
>  ('es', _('Español')),
>  ('it', _('Italiano')),
> )
>
> When I use {% get_available_languages as langs %}
>
> I get this error:
>
> TemplateSyntaxError at /
> Caught UnicodeDecodeError while rendering: 'ascii' codec can't decode
> byte 0xc3 in position 4: ordinal not in range(128)
>
> Am I doing something wrong?
>

Mark the strings correctly as unicode, eg _(u'Español'). I'm assuming
your file encoding on settings.py is UTF-8.

HTH

Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Caught UnicodeDecodeError when using {% get_available_languages as langs %}

2010-11-26 Thread Federico Capoano
1.3 alpha 1 SVN-14688


On Nov 26, 8:46 pm, Federico Capoano  wrote:
> Hi all,
>
> this is my settings.py
>
> _ = lambda s: s
>
> LANGUAGES = (
>   ('en', _('English')),
>   ('es', _('Español')),
>   ('it', _('Italiano')),
> )
>
> When I use {% get_available_languages as langs %}
>
> I get this error:
>
> TemplateSyntaxError at /
> Caught UnicodeDecodeError while rendering: 'ascii' codec can't decode
> byte 0xc3 in position 4: ordinal not in range(128)
>
> Am I doing something wrong?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Caught UnicodeDecodeError when using {% get_available_languages as langs %}

2010-11-26 Thread Federico Capoano
Hi all,

this is my settings.py

_ = lambda s: s

LANGUAGES = (
  ('en', _('English')),
  ('es', _('Español')),
  ('it', _('Italiano')),
)

When I use {% get_available_languages as langs %}

I get this error:

TemplateSyntaxError at /
Caught UnicodeDecodeError while rendering: 'ascii' codec can't decode
byte 0xc3 in position 4: ordinal not in range(128)

Am I doing something wrong?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: PIL issue opening an image file

2010-11-26 Thread Sithembewena Lloyd Dube
@Steve, very well. I concede. It's just that it was not the first time I
thought he could be more respectful in his approach. He has acknowledged and
apologised for this type of behaviour previously. My concern is that those
types of unhelpful responses could lead to newcomers feeling that this place
is of no use other than to humiliate them. Also, I am certainly not one to
be dressed down, no matter how stupid I might have been. Make me understand
my mistake, but do not get onto a high horse about it. Then, we will
co-exist just fine.

Regards,
Lloyd

On Fri, Nov 26, 2010 at 9:07 PM, Steve Holden  wrote:

> On 11/26/2010 9:58 AM, Sithembewena Lloyd Dube wrote:
> > Thanks for breaking this down, Tom. I'll play around with it and see if
> > I'm grasping this.
>
> For the record, while it might have seemed to you that Bruno was being
> "snooty", in fact he was probably (I have no direct evidence) simply
> crediting you with more knowledge than you actually had.
>
> Misunderstandings can be frustrating, and we all give in to the
> frustration sometimes.
>
> regards
>  Steve
> --
> DjangoCon US 2011 Portland, OR: September 6-8 http://djangocon.us/
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


-- 
Regards,
Sithembewena Lloyd Dube
http://www.lloyddube.com

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: PIL issue opening an image file

2010-11-26 Thread Steve Holden
On 11/26/2010 9:58 AM, Sithembewena Lloyd Dube wrote:
> Thanks for breaking this down, Tom. I'll play around with it and see if
> I'm grasping this.

For the record, while it might have seemed to you that Bruno was being
"snooty", in fact he was probably (I have no direct evidence) simply
crediting you with more knowledge than you actually had.

Misunderstandings can be frustrating, and we all give in to the
frustration sometimes.

regards
 Steve
-- 
DjangoCon US 2011 Portland, OR: September 6-8 http://djangocon.us/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: PIL issue opening an image file

2010-11-26 Thread Sithembewena Lloyd Dube
Kate, that was...

On Fri, Nov 26, 2010 at 9:07 PM, Sithembewena Lloyd Dube
wrote:

> So, I am making headway. Thanks to the gentlemen who nudged me onto the
> right path.
>
> Quick word to Bruno Desthuilliers: while I appreciate that you have greater
> experience and might find others' endeavours ridiculous, you could be more
> helpful and respectful in your tone. Do you see a difference between your
> response and that of Tom Evans, for example? There is a civilised way to
> disagree.
>
> This was not the first time that you and I have had something of a spat
> regarding your demeanour on this mailing list. The last time, you attacked a
> total novice to Django with the same air of wanton condescension -and worse,
> you condescended to Kaste (an experienced Django user) who was trying to
> come to the aid of said newbie.
>
> This is a place where people  'fraternise', and mostly the goal of it all
> is to enlighten those that need to be enlightened. There is *absolutely* no
> reason to be uncouth about it. You were also once devoid of comprehension,
> and you gradually attained it, in no small part thanks to others' patience
> and advice.
>
> Regards,
> Lloyd
>
>
>
>
> On Fri, Nov 26, 2010 at 5:58 PM, Sithembewena Lloyd Dube <
> zebr...@gmail.com> wrote:
>
>> Thanks for breaking this down, Tom. I'll play around with it and see if
>> I'm grasping this.
>>
>> Regards,
>> Lloyd
>>
>>
>> On Fri, Nov 26, 2010 at 5:55 PM, Tom Evans wrote:
>>
>>> On Fri, Nov 26, 2010 at 3:44 PM, Sithembewena Lloyd Dube
>>>  wrote:
>>> > Thanks Daniel, makes sense. I gather that what Bruno meant to say on
>>> his
>>> > soapbox was that the file is in the HTTP request object and can/ should
>>> not
>>> > be accessible from the hard disk?
>>> >
>>> > I was familiar with that, as the file upload dialogue does the job of
>>> > reading the file off the disk and into memory.
>>> >
>>> > So I see where I went wrong :) I was trying to read the file off the
>>> disk.
>>> > I'll see if I can manipulate the file in a view, where I have access to
>>> the
>>> > request object.
>>> >
>>> > Is that the gist of the problem?
>>> >
>>> > Thanks Daniel!
>>> >
>>>
>>> Not really.
>>>
>>> 1) User chooses file from disk
>>> 2) Browser reads file from disk, and generates POST request
>>> 3) Django receives POST request, and generates temporary file to store
>>> received POST data
>>> 4) Django model form processes request, and moves temporary file into
>>> the location specified by upload_to attribute on model field
>>> 5) You save the model instance, which puts us into the save() method,
>>> where you want to create a thumbnail of the file
>>>
>>> At this point, the full size image is on disk, in
>>> os.path.join(settings.MEDIA_ROOT, instance.file_field.path). You want
>>> to read that image in, create a django.core.files.File (or subclass)
>>> instance for the thumbnailed image, and assign it to the thumbnail
>>> field on the model.
>>>
>>> Cheers
>>>
>>> Tom
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Django users" group.
>>> To post to this group, send email to django-us...@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> django-users+unsubscr...@googlegroups.com
>>> .
>>> For more options, visit this group at
>>> http://groups.google.com/group/django-users?hl=en.
>>>
>>>
>>
>>
>> --
>> Regards,
>> Sithembewena Lloyd Dube
>> http://www.lloyddube.com
>>
>
>
>
> --
> Regards,
> Sithembewena Lloyd Dube
> http://www.lloyddube.com
>



-- 
Regards,
Sithembewena Lloyd Dube
http://www.lloyddube.com

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: PIL issue opening an image file

2010-11-26 Thread Sithembewena Lloyd Dube
So, I am making headway. Thanks to the gentlemen who nudged me onto the
right path.

Quick word to Bruno Desthuilliers: while I appreciate that you have greater
experience and might find others' endeavours ridiculous, you could be more
helpful and respectful in your tone. Do you see a difference between your
response and that of Tom Evans, for example? There is a civilised way to
disagree.

This was not the first time that you and I have had something of a spat
regarding your demeanour on this mailing list. The last time, you attacked a
total novice to Django with the same air of wanton condescension -and worse,
you condescended to Kaste (an experienced Django user) who was trying to
come to the aid of said newbie.

This is a place where people  'fraternise', and mostly the goal of it all is
to enlighten those that need to be enlightened. There is *absolutely* no
reason to be uncouth about it. You were also once devoid of comprehension,
and you gradually attained it, in no small part thanks to others' patience
and advice.

Regards,
Lloyd



On Fri, Nov 26, 2010 at 5:58 PM, Sithembewena Lloyd Dube
wrote:

> Thanks for breaking this down, Tom. I'll play around with it and see if I'm
> grasping this.
>
> Regards,
> Lloyd
>
>
> On Fri, Nov 26, 2010 at 5:55 PM, Tom Evans wrote:
>
>> On Fri, Nov 26, 2010 at 3:44 PM, Sithembewena Lloyd Dube
>>  wrote:
>> > Thanks Daniel, makes sense. I gather that what Bruno meant to say on his
>> > soapbox was that the file is in the HTTP request object and can/ should
>> not
>> > be accessible from the hard disk?
>> >
>> > I was familiar with that, as the file upload dialogue does the job of
>> > reading the file off the disk and into memory.
>> >
>> > So I see where I went wrong :) I was trying to read the file off the
>> disk.
>> > I'll see if I can manipulate the file in a view, where I have access to
>> the
>> > request object.
>> >
>> > Is that the gist of the problem?
>> >
>> > Thanks Daniel!
>> >
>>
>> Not really.
>>
>> 1) User chooses file from disk
>> 2) Browser reads file from disk, and generates POST request
>> 3) Django receives POST request, and generates temporary file to store
>> received POST data
>> 4) Django model form processes request, and moves temporary file into
>> the location specified by upload_to attribute on model field
>> 5) You save the model instance, which puts us into the save() method,
>> where you want to create a thumbnail of the file
>>
>> At this point, the full size image is on disk, in
>> os.path.join(settings.MEDIA_ROOT, instance.file_field.path). You want
>> to read that image in, create a django.core.files.File (or subclass)
>> instance for the thumbnailed image, and assign it to the thumbnail
>> field on the model.
>>
>> Cheers
>>
>> Tom
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-us...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>>
>
>
> --
> Regards,
> Sithembewena Lloyd Dube
> http://www.lloyddube.com
>



-- 
Regards,
Sithembewena Lloyd Dube
http://www.lloyddube.com

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Accessing multiple databases from a single django app?

2010-11-26 Thread Tom Evans
On Fri, Nov 26, 2010 at 5:28 PM, Roy Smith  wrote:
> I want my application to be able to access two different mysql
> databases (with different credentials, running on two different
> servers).  One is a large data collection which I'll be accessing read-
> only.  The other is read-write, and will be the one which manages the
> site (account creation, user preferences, etc).  Is there a way to do
> this?
>

http://docs.djangoproject.com/en/1.2/topics/db/multi-db/ ?

HTH

Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



extends a template that is stored in an app template directory

2010-11-26 Thread owidjaya
How do i extends a template that is stored within an application
template directory from another application?
I have two apps
one is datagrid and the other one is client
I want to use datagrid to display list of clients
but instead of using the datagrid template that comes from the app, i
want to extend that template to modify the datagrid for client display

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Accessing multiple databases from a single django app?

2010-11-26 Thread Roy Smith
I want my application to be able to access two different mysql
databases (with different credentials, running on two different
servers).  One is a large data collection which I'll be accessing read-
only.  The other is read-write, and will be the one which manages the
site (account creation, user preferences, etc).  Is there a way to do
this?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Dynamic db_table change

2010-11-26 Thread Tom Evans
On Fri, Nov 26, 2010 at 4:33 PM, Sebastien Ramage
 wrote:
>
>
>> First off, this is a stupid database design. Do you really create new
>> tables in your DB each time you add a user? Mental.
>
> yes you're right and what I said was just a example ;)
> In the real app, there's no per user table but per company
> the database is used by many different companies and each company have
> a code (100,200,...) and this code is used in tablename.
> And I can't change this design because this is the design use by Baan
> ERP (call ERP LN now)
>
>
>> You can make this work though. You can execute code in your models.py
>> to dynamically generate all your models, as described on the wiki page
>> you already mentioned.
>
> hum, I've not see this part,
> if I understand, you suggest that I have to generate all models
> dynamically at models.py import ?
>
> Seb
>

Yep, I thought this may be some sort of multi tenant application.
There is some work being planned for multi tenancy for 1.4 (iirc, see
the thread on django-developers).

Generating all the models at import time is doable - see the example
on the wiki page where the author generates arbitrary models that are
described in the database - but you would still have to find a way to
make your views generic, or choose model types according to tenant.

Cheers

Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Dynamic db_table change

2010-11-26 Thread Sebastien Ramage


> First off, this is a stupid database design. Do you really create new
> tables in your DB each time you add a user? Mental.

yes you're right and what I said was just a example ;)
In the real app, there's no per user table but per company
the database is used by many different companies and each company have
a code (100,200,...) and this code is used in tablename.
And I can't change this design because this is the design use by Baan
ERP (call ERP LN now)


> You can make this work though. You can execute code in your models.py
> to dynamically generate all your models, as described on the wiki page
> you already mentioned.

hum, I've not see this part,
if I understand, you suggest that I have to generate all models
dynamically at models.py import ?

Seb

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Dynamic db_table change

2010-11-26 Thread Daniel Roseman
On Nov 26, 2:34 pm, Seb  wrote:
> Hi all !
>
> I want to use Django on an existing database where every user have his
> own table.

> Any idea ?

Yes: don't do this. Really, really, don't do this.

There's absolutely no reason for each user to have their own table. It
breaks not only Django's ORM, but also the whole relational model.
--
DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: PIL issue opening an image file

2010-11-26 Thread Sithembewena Lloyd Dube
Thanks for breaking this down, Tom. I'll play around with it and see if I'm
grasping this.

Regards,
Lloyd

On Fri, Nov 26, 2010 at 5:55 PM, Tom Evans  wrote:

> On Fri, Nov 26, 2010 at 3:44 PM, Sithembewena Lloyd Dube
>  wrote:
> > Thanks Daniel, makes sense. I gather that what Bruno meant to say on his
> > soapbox was that the file is in the HTTP request object and can/ should
> not
> > be accessible from the hard disk?
> >
> > I was familiar with that, as the file upload dialogue does the job of
> > reading the file off the disk and into memory.
> >
> > So I see where I went wrong :) I was trying to read the file off the
> disk.
> > I'll see if I can manipulate the file in a view, where I have access to
> the
> > request object.
> >
> > Is that the gist of the problem?
> >
> > Thanks Daniel!
> >
>
> Not really.
>
> 1) User chooses file from disk
> 2) Browser reads file from disk, and generates POST request
> 3) Django receives POST request, and generates temporary file to store
> received POST data
> 4) Django model form processes request, and moves temporary file into
> the location specified by upload_to attribute on model field
> 5) You save the model instance, which puts us into the save() method,
> where you want to create a thumbnail of the file
>
> At this point, the full size image is on disk, in
> os.path.join(settings.MEDIA_ROOT, instance.file_field.path). You want
> to read that image in, create a django.core.files.File (or subclass)
> instance for the thumbnailed image, and assign it to the thumbnail
> field on the model.
>
> Cheers
>
> Tom
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


-- 
Regards,
Sithembewena Lloyd Dube
http://www.lloyddube.com

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: PIL issue opening an image file

2010-11-26 Thread Tom Evans
On Fri, Nov 26, 2010 at 3:44 PM, Sithembewena Lloyd Dube
 wrote:
> Thanks Daniel, makes sense. I gather that what Bruno meant to say on his
> soapbox was that the file is in the HTTP request object and can/ should not
> be accessible from the hard disk?
>
> I was familiar with that, as the file upload dialogue does the job of
> reading the file off the disk and into memory.
>
> So I see where I went wrong :) I was trying to read the file off the disk.
> I'll see if I can manipulate the file in a view, where I have access to the
> request object.
>
> Is that the gist of the problem?
>
> Thanks Daniel!
>

Not really.

1) User chooses file from disk
2) Browser reads file from disk, and generates POST request
3) Django receives POST request, and generates temporary file to store
received POST data
4) Django model form processes request, and moves temporary file into
the location specified by upload_to attribute on model field
5) You save the model instance, which puts us into the save() method,
where you want to create a thumbnail of the file

At this point, the full size image is on disk, in
os.path.join(settings.MEDIA_ROOT, instance.file_field.path). You want
to read that image in, create a django.core.files.File (or subclass)
instance for the thumbnailed image, and assign it to the thumbnail
field on the model.

Cheers

Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Key 'buscar' not found in "

2010-11-26 Thread bvcelari
Thanks for the answers,
@Nick, but the issue is if add the hidden value buscar, I must add all
the parameters used in the search form (quite long), I'm looking for a
lazy way doing it.
@Rodrigo, same issue, if there is no search parameters, I can't apply
my filters to the model, so I will not be able to retrieve the "page
2" related items, isn't it?

Thank you very much for yours answers.

Regards
Bvcelari

On Nov 26, 1:17 pm, "Rodrigo \"OreiA\" Chacon" 
wrote:
> The most secure way to retrieve a parameter is to use the get method
> of the QueryDict.
>
> So, instead of:
> request.GET['buscar']
> do:
> request.GET.get('buscar', 'default_value')
>
> Or check if the key exists in the QueryDict instance before trying to
> retrieve it, with:
> if 'buscar' in request.GET:
>    buscar = request.GET['buscar']
>
> ;-)
>
> -- Rodrigo Chacon
>
> On Nov 25, 12:42 pm, Nick Arnett  wrote:
>
> > On Thu, Nov 25, 2010 at 6:35 AM, bvcelari  wrote:
> > > Hy,
> > > I'm trying to deploy my first django app, and I'm trying to use
> > > pagination , I 'm using Django 1.2
> > > I'm using a simple view with form, and with the request show the
> > > results paginated. when I try to go to next page
> > > the message appears:
> > > "Key 'buscar' not found in "
> > > buscar is a hidden value used for check if the request comes from the
> > > search form.
> > > I think this message comes from the "request" URL is not properly
> > > generated in fact my link targets to
> > > "http://localhost:8000/search/?page=2";
> > > instead of something like this:
> > > "http://localhost:8000/search/?option_value1=7&option_value2=3&page=2";
> > > There is any way to maintain the searchred url and indicate wich is
> > > the next page?
>
> > You need to pass that variable to the template, then add it to the page it
> > as a hidden input.
>
> > For example:
>
> > 
>
> > Nick
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: PIL issue opening an image file

2010-11-26 Thread Sithembewena Lloyd Dube
Thanks Daniel, makes sense. I gather that what Bruno meant to say on his
soapbox was that the file is in the HTTP request object and can/ should not
be accessible from the hard disk?

I was familiar with that, as the file upload dialogue does the job of
reading the file off the disk and into memory.

So I see where I went wrong :) I was trying to read the file off the disk.
I'll see if I can manipulate the file in a view, where I have access to the
request object.

Is that the gist of the problem?

Thanks Daniel!

On Fri, Nov 26, 2010 at 5:29 PM, Daniel Roseman wrote:

> On Nov 26, 3:16 pm, Sithembewena Lloyd Dube  wrote:
> > Bruno, the file being uploaded has nothing to do with the deployment
> server.
> > When you edit your Google profile to change your avatar, does the file
> > upload dialogue browse a Google server?
>
> No. But that has nothing whatever to do with the problem you are
> experiencing.
>
> At the point you are calling the save() method, the file has *already*
> been uploaded. There is absolutely *no way* for Python code running on
> the server to access files on your machine. (Can you imagine the
> security implications if that were possible?)
> --
> DR.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


-- 
Regards,
Sithembewena Lloyd Dube
http://www.lloyddube.com

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Dynamic db_table change

2010-11-26 Thread Tom Evans
On Fri, Nov 26, 2010 at 2:34 PM, Seb  wrote:
> Hi all !
>
> I want to use Django on an existing database where every user have his
> own table.
> I want to be able to define one "generic" model for every user and
> choose db_table at runtime
> there is "table_a" and "table_b" which is a sub-table of "table_a"
>
> Database looks like this :
> For user "100" I have:
> table_a_100
> table_b_100
>
> and for user "200" :
> table_a_200
> table_b_200
>
> I've create model like this :
>
> class A(models.Model):
>    class Meta:
>        db_table = 'table_a'
>        managed = False
>    f1 = models.CharField(max_length=12)
>
>
> class B(models.Model):
>    class Meta:
>        db_table = 'table_b'
>        managed = False
>    f1 = models.CharField(max_length=12)
>    a = models.ForeignKey(A)
>
>
> And now the big challenge how can I change db_table at runtime ?
> according to http://code.djangoproject.com/wiki/DynamicModels I have
> created a factory function that change the db_table from "table_a" to
> "table_a_[user]"
> example usage :
> A_100 = factory(A,'100') #change table_a to table_a_100
> it works but I can't use the foreign key
> a=A_100.objects.get(pk=1)
> a.b_set.all() # <== I need B pointed to table_b_100
>
>
> Any idea ?
>
> seb
>

First off, this is a stupid database design. Do you really create new
tables in your DB each time you add a user? Mental.

The factory function you describe does not change the db_table at
runtime, it defines new django models. So when you do this:

> A_100 = factory(A,'100') #change table_a to table_a_100

you are defining a new model class, A_100, which explains why:

> it works but I can't use the foreign key
> a=A_100.objects.get(pk=1)
> a.b_set.all() # <== I need B pointed to table_b_100

Your factory method changes Meta options for the class it defines, it
doesn't change the class members at all, so A_100 will always point at
B, not some class B_100, which hasn't been declared at all. For this
to happen, you must be declaring a B_100 class, which has a foreign
key to A_100, rather than declaring a B class which has a foreign key
to A, and then using A as a basis for creating a new model.

You can make this work though. You can execute code in your models.py
to dynamically generate all your models, as described on the wiki page
you already mentioned.

Cheers

Tom

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: PIL issue opening an image file

2010-11-26 Thread Daniel Roseman
On Nov 26, 3:16 pm, Sithembewena Lloyd Dube  wrote:
> Bruno, the file being uploaded has nothing to do with the deployment server.
> When you edit your Google profile to change your avatar, does the file
> upload dialogue browse a Google server?

No. But that has nothing whatever to do with the problem you are
experiencing.

At the point you are calling the save() method, the file has *already*
been uploaded. There is absolutely *no way* for Python code running on
the server to access files on your machine. (Can you imagine the
security implications if that were possible?)
--
DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: PIL issue opening an image file

2010-11-26 Thread Sithembewena Lloyd Dube
Bruno, the file being uploaded has nothing to do with the deployment server.
When you edit your Google profile to change your avatar, does the file
upload dialogue browse a Google server?

On Fri, Nov 26, 2010 at 4:50 PM, bruno desthuilliers <
bruno.desthuilli...@gmail.com> wrote:

>
>
> On 26 nov, 15:03, Sithembewena Lloyd Dube  wrote:
> > I found the issue: it is the path to the image. When I change the problem
> > line to
> >
> > image = Image.open(os.path.realpath('C:\Users\Lloyd\Desktop\Lloyd.png'))
> >
> > it works,
>
> Well, kinda... accidentally...
>
> > but I cannot hard code the path and I cannot predict where the
> > user will try to upload a file from.
>
> That's not exactly the problem, but the mere fact you think you could
> solve your problem that way says a lot about your misunderstanding of
> the HTTP protocol.
>
>
> > Isn't there a way to dynamically get
> > the path from the file upload dialogue where the user browses to it and
> > selects it?
>
> What would you do with this information ? Do you really think the
> server on which your application will be deployed will have any access
> to the client's filesystem ???
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


-- 
Regards,
Sithembewena Lloyd Dube
http://www.lloyddube.com

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: PIL issue opening an image file

2010-11-26 Thread Sithembewena Lloyd Dube
Thanks for nothing.

On Fri, Nov 26, 2010 at 4:52 PM, bruno desthuilliers <
bruno.desthuilli...@gmail.com> wrote:

> On 26 nov, 15:33, Sithembewena Lloyd Dube  wrote:
> > Thanks Daniel,
> >
> > Using photo.path causes it to try to find the image in my MEDIA_ROOT,
> which
> > is not what I need.
>
> Yes it is.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


-- 
Regards,
Sithembewena Lloyd Dube
http://www.lloyddube.com

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: PIL issue opening an image file

2010-11-26 Thread Sithembewena Lloyd Dube
Well, Bruno, if I knew exactly how to solve this I wouldn't be sitting here
taking your snooty remarks, would I? I am asking because I do not know how
to go about it.

On Fri, Nov 26, 2010 at 4:50 PM, bruno desthuilliers <
bruno.desthuilli...@gmail.com> wrote:

>
>
> On 26 nov, 15:03, Sithembewena Lloyd Dube  wrote:
> > I found the issue: it is the path to the image. When I change the problem
> > line to
> >
> > image = Image.open(os.path.realpath('C:\Users\Lloyd\Desktop\Lloyd.png'))
> >
> > it works,
>
> Well, kinda... accidentally...
>
> > but I cannot hard code the path and I cannot predict where the
> > user will try to upload a file from.
>
> That's not exactly the problem, but the mere fact you think you could
> solve your problem that way says a lot about your misunderstanding of
> the HTTP protocol.
>
>
> > Isn't there a way to dynamically get
> > the path from the file upload dialogue where the user browses to it and
> > selects it?
>
> What would you do with this information ? Do you really think the
> server on which your application will be deployed will have any access
> to the client's filesystem ???
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


-- 
Regards,
Sithembewena Lloyd Dube
http://www.lloyddube.com

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Dynamic db_table change

2010-11-26 Thread Seb
Hi all !

I want to use Django on an existing database where every user have his
own table.
I want to be able to define one "generic" model for every user and
choose db_table at runtime
there is "table_a" and "table_b" which is a sub-table of "table_a"

Database looks like this :
For user "100" I have:
table_a_100
table_b_100

and for user "200" :
table_a_200
table_b_200

I've create model like this :

class A(models.Model):
class Meta:
db_table = 'table_a'
managed = False
f1 = models.CharField(max_length=12)


class B(models.Model):
class Meta:
db_table = 'table_b'
managed = False
f1 = models.CharField(max_length=12)
a = models.ForeignKey(A)


And now the big challenge how can I change db_table at runtime ?
according to http://code.djangoproject.com/wiki/DynamicModels I have
created a factory function that change the db_table from "table_a" to
"table_a_[user]"
example usage :
A_100 = factory(A,'100') #change table_a to table_a_100
it works but I can't use the foreign key
a=A_100.objects.get(pk=1)
a.b_set.all() # <== I need B pointed to table_b_100


Any idea ?

seb




-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Key 'buscar' not found in "

2010-11-26 Thread Rodrigo "OreiA" Chacon
The most secure way to retrieve a parameter is to use the get method
of the QueryDict.

So, instead of:
request.GET['buscar']
do:
request.GET.get('buscar', 'default_value')

Or check if the key exists in the QueryDict instance before trying to
retrieve it, with:
if 'buscar' in request.GET:
   buscar = request.GET['buscar']

;-)

-- Rodrigo Chacon


On Nov 25, 12:42 pm, Nick Arnett  wrote:
> On Thu, Nov 25, 2010 at 6:35 AM, bvcelari  wrote:
> > Hy,
> > I'm trying to deploy my first django app, and I'm trying to use
> > pagination , I 'm using Django 1.2
> > I'm using a simple view with form, and with the request show the
> > results paginated. when I try to go to next page
> > the message appears:
> > "Key 'buscar' not found in "
> > buscar is a hidden value used for check if the request comes from the
> > search form.
> > I think this message comes from the "request" URL is not properly
> > generated in fact my link targets to
> > "http://localhost:8000/search/?page=2";
> > instead of something like this:
> > "http://localhost:8000/search/?option_value1=7&option_value2=3&page=2";
> > There is any way to maintain the searchred url and indicate wich is
> > the next page?
>
> You need to pass that variable to the template, then add it to the page it
> as a hidden input.
>
> For example:
>
> 
>
> Nick

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



ModelForm + MultiValueField = form.save() problem

2010-11-26 Thread Dr.Bleedjent
Hi!
I have a modelForm for some model. Example Article:

class Article(models.Model)
  title = models.CharField(max_length=255)
  price = models.IntegerField()
  currency = models.IntegerField()

class ArticleForm(forms.ModelForm)
  price = MyPriceFied(choices = CURRENCY_CHOICES)

  class Meta:
model = Article
fields = ['title', 'price']

And i have a MyPriceField(forms.MiltiValueField) and
SinteticWidget(forms.MultiWidget)

class MyPriceField(forms.MultiValueField):
'''
Field witch contains with two widgets input and select.
Select's choices set in "choices" param.
'''
def __init__(self, choices = (), *args, **kwargs):
fields = (
forms.CharField(),
forms.ChoiceField(choices = choices),
)
widget_list = (
forms.TextInput(),
forms.Select(choices = choices),
)
self.widget = SinteticWidget(widgets = widget_list)
super(MyPriceField, self).__init__(fields, choices, *args,
**kwargs)

This work fine. In template for field price rendered two controls
input type text and select.
But i have problem with submiting form. I have no idea how can i
create instance of Article class by form.save().
Becouse in form i have one field but in model i have two.

Can somebody help me? Can some one advise algorithm that can be used
to implement this?
Maybe it's not really)))
Thanks

Sorry for my english)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: PIL issue opening an image file

2010-11-26 Thread bruno desthuilliers
On 26 nov, 15:33, Sithembewena Lloyd Dube  wrote:
> Thanks Daniel,
>
> Using photo.path causes it to try to find the image in my MEDIA_ROOT, which
> is not what I need.

Yes it is.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: PIL issue opening an image file

2010-11-26 Thread bruno desthuilliers


On 26 nov, 15:03, Sithembewena Lloyd Dube  wrote:
> I found the issue: it is the path to the image. When I change the problem
> line to
>
> image = Image.open(os.path.realpath('C:\Users\Lloyd\Desktop\Lloyd.png'))
>
> it works,

Well, kinda... accidentally...

> but I cannot hard code the path and I cannot predict where the
> user will try to upload a file from.

That's not exactly the problem, but the mere fact you think you could
solve your problem that way says a lot about your misunderstanding of
the HTTP protocol.


> Isn't there a way to dynamically get
> the path from the file upload dialogue where the user browses to it and
> selects it?

What would you do with this information ? Do you really think the
server on which your application will be deployed will have any access
to the client's filesystem ???

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: PIL issue opening an image file

2010-11-26 Thread Sithembewena Lloyd Dube
If I was handling the photo in a view, I'm sure I could get the path
information out of request.FILES['filename'] - but I am trying to upload it
in a model.

Regards,
Lloyd

On Fri, Nov 26, 2010 at 4:33 PM, Sithembewena Lloyd Dube
wrote:

> Thanks Daniel,
>
> Using photo.path causes it to try to find the image in my MEDIA_ROOT, which
> is not what I need. I need a way to get the path from the image upload
> dialogue as encircled in the attached image.
>
> The image is currently on my desktop and not in my media root and I need to
> get the desktop path.
>
> Thanks!
>
> Lloyd
>
>
> On Fri, Nov 26, 2010 at 4:14 PM, Daniel Roseman wrote:
>
>> On Nov 26, 2:03 pm, Sithembewena Lloyd Dube  wrote:
>> > I found the issue: it is the path to the image. When I change the
>> problem
>> > line to
>> >
>> > image = Image.open(os.path.realpath('C:\Users\Lloyd\Desktop\Lloyd.png'))
>> >
>> > it works, but I cannot hard code the path and I cannot predict where the
>> > user will try to upload a file from. Isn't there a way to dynamically
>> get
>> > the path from the file upload dialogue where the user browses to it and
>> > selects it?
>> >
>> > Thanks...
>>
>> Why were you using photo.name as the path in the first place?
>> photo.path stores the full path to the image, as noted in the
>> documentation:
>> http://docs.djangoproject.com/en/1.2/ref/files/file/
>> --
>> DR.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-us...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>>
>
>
> --
> Regards,
> Sithembewena Lloyd Dube
> http://www.lloyddube.com
>



-- 
Regards,
Sithembewena Lloyd Dube
http://www.lloyddube.com

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: PIL issue opening an image file

2010-11-26 Thread Sithembewena Lloyd Dube
Thanks Daniel,

Using photo.path causes it to try to find the image in my MEDIA_ROOT, which
is not what I need. I need a way to get the path from the image upload
dialogue as encircled in the attached image.

The image is currently on my desktop and not in my media root and I need to
get the desktop path.

Thanks!

Lloyd

On Fri, Nov 26, 2010 at 4:14 PM, Daniel Roseman wrote:

> On Nov 26, 2:03 pm, Sithembewena Lloyd Dube  wrote:
> > I found the issue: it is the path to the image. When I change the problem
> > line to
> >
> > image = Image.open(os.path.realpath('C:\Users\Lloyd\Desktop\Lloyd.png'))
> >
> > it works, but I cannot hard code the path and I cannot predict where the
> > user will try to upload a file from. Isn't there a way to dynamically get
> > the path from the file upload dialogue where the user browses to it and
> > selects it?
> >
> > Thanks...
>
> Why were you using photo.name as the path in the first place?
> photo.path stores the full path to the image, as noted in the
> documentation:
> http://docs.djangoproject.com/en/1.2/ref/files/file/
> --
> DR.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


-- 
Regards,
Sithembewena Lloyd Dube
http://www.lloyddube.com

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

<>

Re: PIL issue opening an image file

2010-11-26 Thread Daniel Roseman
On Nov 26, 2:03 pm, Sithembewena Lloyd Dube  wrote:
> I found the issue: it is the path to the image. When I change the problem
> line to
>
> image = Image.open(os.path.realpath('C:\Users\Lloyd\Desktop\Lloyd.png'))
>
> it works, but I cannot hard code the path and I cannot predict where the
> user will try to upload a file from. Isn't there a way to dynamically get
> the path from the file upload dialogue where the user browses to it and
> selects it?
>
> Thanks...

Why were you using photo.name as the path in the first place?
photo.path stores the full path to the image, as noted in the
documentation:
http://docs.djangoproject.com/en/1.2/ref/files/file/
--
DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: PIL issue opening an image file

2010-11-26 Thread Sithembewena Lloyd Dube
I found the issue: it is the path to the image. When I change the problem
line to

image = Image.open(os.path.realpath('C:\Users\Lloyd\Desktop\Lloyd.png'))

it works, but I cannot hard code the path and I cannot predict where the
user will try to upload a file from. Isn't there a way to dynamically get
the path from the file upload dialogue where the user browses to it and
selects it?

Thanks...

On Fri, Nov 26, 2010 at 3:49 PM, Sithembewena Lloyd Dube
wrote:

> Hi all,
>
> I have a Photo model which should take an image, generate a thumbnail and
> save both the original and the thumbnail images. I registered the model in
> the admin site, but when I select an image to upload and click 'Save', I get
> an error as follows:
>
> Request Method: POST
> Request URL: http://127.0.0.1:8000/admin/browse/photo/add/
> Django Version: 1.2.3
> Exception Type: IOError
> Exception Value:
>
> [Errno 2] No such file or directory: u'Lloyd.png'
>
> Exception Location: C:\Python26\lib\site-packages\PIL\Image.py in open,
> line 1952
> Python Executable: C:\Python26\python.exe
> Python Version: 2.6.5
>
> The model looks like this (the line where the error occurs is highlighted):
>
> class Photo(models.Model):
>  """
>  An avatar for a site member
>  """
>  title =   models.CharField(max_length=50)
>  photo =   models.ImageField(upload_to='photos/')
>  thumbnail =
> models.ImageField(upload_to='thumbnails/', editable=False)
>
>  def save(self):
>   from PIL import Image
>   from cStringIO import StringIO
>   from django.core.files.uploadedfile import SimpleUploadedFile
>
>   # Set our max thumbnail size in a tuple (max width, max height)
>   THUMBNAIL_SIZE = (65, 65)
>
>   # Open original photo which we want to thumbnail using PIL's
> Image
>   # object
>   image = Image.open(self.photo.name)
>
>   # Convert to RGB if necessary
>   # Thanks to Limodou on DjangoSnippets.org
>   # http://www.djangosnippets.org/snippets/20/
>   if image.mode not in ('L', 'RGB'):
>image = image.convert('RGB')
>
>   # We use our PIL Image object to create the thumbnail, which
> already
>   # has a thumbnail() convenience method that contrains
> proportions.
>   # Additionally, we use Image.ANTIALIAS to make the image look
> better.
>   # Without antialiasing the image pattern artifacts may result.
>   image.thumbnail(THUMBNAIL_SIZE, Image.ANTIALIAS)
>
>   # Save the thumbnail
>   temp_handle = StringIO()
>   image.save(temp_handle, 'png')
>   temp_handle.seek(0)
>
>   # Save to the thumbnail field
>   suf = SimpleUploadedFile(os.path.split(self.photo.name)[-1],
>temp_handle.read(), content_type='image/png')
>   self.thunbnail.save(suf.name+'.png', suf, save=False)
>
>   # Save this photo instance
>   super(Photo, self).save()
>
>   class Admin:
>pass
>
>   def __str__(self):
>return self.title
>
> What could the issue be? Any ideas welcome.
>
> Thanks.
> --
> Regards,
> Sithembewena Lloyd Dube
> http://www.lloyddube.com
>



-- 
Regards,
Sithembewena Lloyd Dube
http://www.lloyddube.com

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



PIL issue opening an image file

2010-11-26 Thread Sithembewena Lloyd Dube
Hi all,

I have a Photo model which should take an image, generate a thumbnail and
save both the original and the thumbnail images. I registered the model in
the admin site, but when I select an image to upload and click 'Save', I get
an error as follows:

Request Method: POST
Request URL: http://127.0.0.1:8000/admin/browse/photo/add/
Django Version: 1.2.3
Exception Type: IOError
Exception Value:

[Errno 2] No such file or directory: u'Lloyd.png'

Exception Location: C:\Python26\lib\site-packages\PIL\Image.py in open,
line 1952
Python Executable: C:\Python26\python.exe
Python Version: 2.6.5

The model looks like this (the line where the error occurs is highlighted):

class Photo(models.Model):
 """
 An avatar for a site member
 """
 title =   models.CharField(max_length=50)
 photo =   models.ImageField(upload_to='photos/')
 thumbnail =
models.ImageField(upload_to='thumbnails/', editable=False)

 def save(self):
  from PIL import Image
  from cStringIO import StringIO
  from django.core.files.uploadedfile import SimpleUploadedFile

  # Set our max thumbnail size in a tuple (max width, max height)
  THUMBNAIL_SIZE = (65, 65)

  # Open original photo which we want to thumbnail using PIL's Image
  # object
  image = Image.open(self.photo.name)

  # Convert to RGB if necessary
  # Thanks to Limodou on DjangoSnippets.org
  # http://www.djangosnippets.org/snippets/20/
  if image.mode not in ('L', 'RGB'):
   image = image.convert('RGB')

  # We use our PIL Image object to create the thumbnail, which
already
  # has a thumbnail() convenience method that contrains proportions.
  # Additionally, we use Image.ANTIALIAS to make the image look
better.
  # Without antialiasing the image pattern artifacts may result.
  image.thumbnail(THUMBNAIL_SIZE, Image.ANTIALIAS)

  # Save the thumbnail
  temp_handle = StringIO()
  image.save(temp_handle, 'png')
  temp_handle.seek(0)

  # Save to the thumbnail field
  suf = SimpleUploadedFile(os.path.split(self.photo.name)[-1],
   temp_handle.read(), content_type='image/png')
  self.thunbnail.save(suf.name+'.png', suf, save=False)

  # Save this photo instance
  super(Photo, self).save()

  class Admin:
   pass

  def __str__(self):
   return self.title

What could the issue be? Any ideas welcome.

Thanks.
-- 
Regards,
Sithembewena Lloyd Dube
http://www.lloyddube.com

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: tree data structure

2010-11-26 Thread bruno desthuilliers
On 25 nov, 16:07, pa_ree  wrote:
> the idea is basically that there are people in an organization who are
> working in various projects under different roles.
> so i want to represent the project hierarchy in the form of an
> inverted tree structure.

You're talking about (what you thing is) the solution, but not about
your real use case. What are you actually going to DO with these
infos ?

Still, I'll give you a couple hints:

First point: your hierarchy involves roles, not peoples.

If this hierarchy is known and fixed and the same for each and every
project, you could as well hardcode it in your role models. If it's
not totally fixed but rather stable and still the same for each and
every project, you could define the hierarchical relationships between
roles in your settings using a simple dict.

If you need more flexiblity, you'll have to use models for your roles,
and yes this time you'll have to represent the roles hierarchy in your
models. There are basically three ways to model trees in a RDBMS : the
adjacency list, the materialized path, and the modified preorder tree
traversal (aka MPTT). They're all have their pros and cons, and are
all well documented on the net - modelling trees in a RDBMS is not
exactly a new problem.

Second point: there's a django pluggable app named treebeard that
offer a unified API for these three possible implementation - but I
strongly suggest you first do your homework and read about these three
patterns before you go any further, else you'll have a hard time
making informed decisions about what solution is the more appropriate
for your project's use cases.


> i also want it to be dynamic that is when a
> new project is assigned to a person say who is wrking at the
> managerial level to be upgraded to the next higher level.
> one person can work in various projects with different roles and one
> project has various persons involved.

Looks like a trinary relationship (person,role,project).

> i wud be realy grateful if u cud come out wid the solution as to how
> do i implememnt this.

A bit OT, but do yourself (and everyone here) a favour and quit that
childish "l33t" speak. No one is going to take you seriously here if
you don't speak as a grown up person. And now, I'm not going to do
your own work.

HTH

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: confirm user by ref_has and email

2010-11-26 Thread bruno desthuilliers


On 25 nov, 15:11, robos85  wrote:
> Yes it looks that:
> from django.db import models
> from django.contrib.auth.models import User
>
> class UserProfile(models.Model):
>     user = models.ForeignKey(User, unique=True)
>     register_hash = models.CharField(max_length=32)
>
> And now I want to do something like this:
>     check = User.objects.all()
>
>     for x in check:
>         print x.userprofile.register_hash
>
> And I get :
> 'User' object has no attribute 'userprofile'
>
At least we're getting somewhere... Why didn't you start with this
above problem FWIW - would have saved everyone's time ;)

Is your UserProfile a "registration profile" (ie
http://bitbucket.org/ubernostrum/django-registration/) or is it a real
"user profile" (ie 
http://docs.djangoproject.com/en/dev/topics/auth/#storing-additional-information-about-users)
- or both, or None ?

In the second case, if you declare your UserProfile model in the
settings as speficied in the docs, you should be able to retrieve a
User's profile using the .get_profile() method.

In any case, since you 1/ used a ForeignKey - not a OneToOne field -
and 2/ didn't specified "userprofile" as the related name for the
relationship, the RelatedManager is accessible as "userprofile_set".
Also and FWIW, since it's many-to-one relationship, this
RelatedManager will work as documented for a standard ForeignKey.

Now given your first post, I think that what you really want here is,
given a email address (stored in the User model) and a reg_hash
(stored in the UserProfile model) check you do have the corresponding
records. The solution here is obviously not to do a whole scan of any
of the underlying tables (which would work but at a prohibitive cost),
but a direct joined query instead (as documented here :
http://docs.djangoproject.com/en/1.2/topics/db/queries/#lookups-that-span-relationships),
ie:

try:
profile = UserProfile.objects.get(register_hash=reg_hash,
user__email=email)
except UserProfile.DoesNotExist:
# handle the case here
else:
# if you need to get at the user:
user = profile.user


HTH

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Removing title from each admin page

2010-11-26 Thread Marcos Moyano
Sure there is. You have to override the template:
django/contrib/admin/templates/admin/base.html
Create an admin folder within your templates folder, copy that template over
that admin folder and remove the "{{ title }}" statement.

Hope it helps.
Marcos

On Fri, Nov 26, 2010 at 7:37 AM, Luca Casagrande
wrote:

> Hello folks,
> is there any way to remove the title over each admin element, like
> "Site administration" or "Select..to change".
>
> Thanks
> Luca
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


-- 
Some people, when confronted with a problem, think “I know, I'll use regular
expressions.” Now they have two problems.

Jamie Zawinski, in comp.emacs.xemacs

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Removing title from each admin page

2010-11-26 Thread Luca Casagrande
Hello folks,
is there any way to remove the title over each admin element, like
"Site administration" or "Select..to change".

Thanks
Luca

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Django feeds sometimes generate AttributeError: 'LatestStripsByStripConfig' object has no attribute '__name __'

2010-11-26 Thread Łukasz Rekucki
On 26 November 2010 10:35, marty3d  wrote:
> I have disabled cache and still getting the error. That
> leaves...what? :/
>
> I could really appreciate some help debugging this.

On a closer look, this looks like:
http://code.djangoproject.com/ticket/13842 ; But then, you must have
changed something in your code/settings (like migrating from Django
1.1 syndication views or adding XView).


-- 
Łukasz Rekucki

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Django feeds sometimes generate AttributeError: 'LatestStripsByStripConfig' object has no attribute '__name __'

2010-11-26 Thread marty3d
I have disabled cache and still getting the error. That
leaves...what? :/

I could really appreciate some help debugging this.

Thank you,
/Martin

On Nov 25, 10:06 pm, marty3d  wrote:
> It's 1.2.3. I have two ideas, either it could be the cache (started
> using filesystem cache a week ago) or I'm using a stupid query for
> returning the queryset (aka database performance issue).
>
> Have anyone heard of caching messing with the feeds system?
>
> /Martin
>
> On Nov 25, 3:42 pm, £ukasz Rekucki  wrote:
>
> > Well, something must have changed if you didn't had the problem
> > before. What version of Django are you running ?
>
> > On 25 November 2010 15:38, marty3d  wrote:
>
> > > Hi!
>
> > > My site have started to behave a little weird.
>
> > > Lately, I get two or three errors per day, saying:
> > > Traceback (most recent call last):
>
> > >  File "/home/mistalaba/.virtualenvs/production/lib/python2.5/site-
> > > packages/django/core/handlers/base.py", line 95, in get_response
> > >   response = middleware_method(request, callback, callback_args,
> > > callback_kwargs)
>
> > >  File "/home/mistalaba/.virtualenvs/production/lib/python2.5/site-
> > > packages/django/middleware/doc.py", line 18, in process_view
> > >   response['X-View'] = "%s.%s" % (view_func.__module__,
> > > view_func.__name__)
>
> > > AttributeError: 'LatestStripsByStripConfig' object has no attribute
> > > '__name__'
>
> > > I don't know why this is appearing all of a sudden, I haven't changed
> > > the code, but I don't know where to start debugging this.
>
> > > Here is my feeds.py, rather straightforward:
> > > from django.contrib.syndication.views import Feed
> > > from django.shortcuts import get_object_or_404
>
> > > from strip.models import StripConfig, Strip
>
> > > class LatestStripsByStripConfig(Feed):
> > >    #__name__ = 'LatestStripsByStripConfig'
> > >    description_template = 'feeds/latest_description.html'
>
> > >    def get_object(self, request, stripconfig):
> > >        return get_object_or_404(StripConfig, slug=stripconfig)
>
> > >    def title(self, obj):
> > >        return "Scandinavian Comics RSS feed for %s" % obj.strip_name
>
> > >    def link(self, obj):
> > >        return "%s?utm_source=feed&utm_medium=%s" %
> > > (obj.get_absolute_url(), obj.strip_name)
>
> > >    def description(self, obj):
> > >        return "The latest %s comic strips. See more at
> > >http://www.scandinavian-comics.com/strips/"; % obj.strip_name
>
> > >    def items(self, obj):
> > >        return
> > > Strip.objects.filter(strip_config__slug=obj.slug).order_by('-date')[:
> > > 10]
>
> > >    def item_link(self, item):
> > >        return "%s?utm_source=feed&utm_medium=%s&utm_campaign=%s" %
> > > (item.get_absolute_url(), item.strip_config, item)
>
> > > Does anyone have some wise suggestions? I would really appreciate it!
> > > Thank you!
>
> > > --
> > > You received this message because you are subscribed to the Google Groups 
> > > "Django users" group.
> > > To post to this group, send email to django-us...@googlegroups.com.
> > > To unsubscribe from this group, send email to 
> > > django-users+unsubscr...@googlegroups.com.
> > > For more options, visit this group 
> > > athttp://groups.google.com/group/django-users?hl=en.
>
> > --
> > £ukasz Rekucki
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Custom Login using model form

2010-11-26 Thread Daniel Roseman
On Nov 26, 8:00 am, PRANAV HEGDE  wrote:
> Hi Daniel,
>
> Yeah I had a thought like that. I thought I could leave the validation
> to the model.
> Turns out model form comes handy only if your modifying or updating
> something in the database, as you said.
> Simple form can also enforce constraints but I just have to write
> another form with same constraints as the model.
>
> Thanks for the suggestion.
>
> Warm Regards,
> Pranav.

The thing to realise is that when it comes to login forms, the
'validation' is performed by the authentication backend, not the form
itself.
--
DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Custom Login using model form

2010-11-26 Thread PRANAV HEGDE


On Nov 26, 1:57 am, Daniel Roseman  wrote:
> On Nov 25, 7:53 am, PRANAV HEGDE  wrote:
>
>
>
>
>
>
>
>
>
> > Hi guys,
>
> > I'm trying to create a login form using a model form,
>
> > user model:
> > class users(models.Model):
> >     username = models.CharField(max_length=20, primary_key=True)
> >     password = models.CharField(max_length=50)
> >     usertype = models.CharField(max_length=20)
> >     class Meta:
> >         db_table = u'users'
>
> > login form:
> > class loginlorm(forms.ModelForm):
> >     class Meta:
> >         model = users
> >         fields = ('username','password','usertype')
> >         widgets = {
> >                     'username':TextInput(),
> >                     'password':PasswordInput(),
> >                     'usertype':Select(choices=(("t1","type1"),
> > ("t2","type2"))),
> >                    }
>
> > The form comes up as i wanted it to, but when i login it gives a
> > validation error saying "user with this name already exists".
> > I think its "form.is_valid()" checking "primary key" constraint,
> > thinking i'm trying to write into the table. :(
> > I cant remove the "primary key" constraint on "username" is there a
> > way around this problem..
>
> Why do you want a modelform though? The usual reason is to allow you
> to add users or edit existing ones - since you don't supply an
> existing user when instantiating the form, Django assumes you want to
> create a new one, hence the error. But what are you gaining by using
> the modelform here? It seems to me, nothing at all. Instead of
> subclassing modelform, setting the model, and defining the widgets,
> you might as well just use a normal form and define the fields
> directly.
> --
> DR.


Hi Daniel,

Yeah I had a thought like that. I thought I could leave the validation
to the model.
Turns out model form comes handy only if your modifying or updating
something in the database, as you said.
Simple form can also enforce constraints but I just have to write
another form with same constraints as the model.

Thanks for the suggestion.

Warm Regards,
Pranav.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.