Maps with Django

2020-12-08 Thread Paolo Melchiorre
Hi all,

I've just published:
"Maps with Django (part 1): GeoDjango, SpatiaLite and Leaflet"

A quickstart guide to create a web #map 🗺️ with #Django 🦄 using its 
module #GeoDjango 🌍, the #SQLite 🪶 database with its spatial extension 
#SpatiaLite 🌐 and #Leaflet 🍃

https://www.paulox.net/2020/12/08/maps-with-django-part-1-geodjango-spatialite-and-leaflet/

See you,
Paolo

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2c19e395-167c-40af-9561-a51cd6d4f547n%40googlegroups.com.


Re: django 2.0 tutorial :: exception:: application labels are not unique.

2018-05-16 Thread Paolo Chilosi
just a note on your note: I created a few more new project/app using 
PyCharm create facility and I found the app registered in the 
INSTALLED_APPS settings. I do not know if it is Django or PyCharm that 
introduce this setting. In the first case the Django tutorial documentation 
should be amended. In any case from now I follow the protocol of inspecting 
the INSTALLED_APPS settings after the creation of a new project/app. 

On Tuesday, May 15, 2018 at 12:27:15 PM UTC-4, James Farris wrote:
>
> Just to note: Django doesn’t change the settings.py file, it only 
> references it so it knows what configurations to load. 
>
> On Tue, May 15, 2018 at 7:27 AM Paolo Chilosi  > wrote:
>
>> thanks for pointing out about the typo. However this was not the cause of 
>> the exception. Look to my previous answer.
>>
>>
>> On Tuesday, May 15, 2018 at 9:44:57 AM UTC-4, Sidyvan Fernandes de 
>> Andrade wrote:
>>
>>> python manage.py makemigrations polls 
>>>
>>> 2018-05-15 8:51 GMT-03:00 Paolo Chilosi :
>>>
>> As new to Django I am learning following the tutorial carefully. When I 
>>>> reached the point of making the migration for the polls app I executed 
>>>> (from the PyCharm terminal) the command:
>>>>
>>>> (venv) C:\Users\Paolo\PycharmProjects\mysite>python manage.py 
>>>> makemigration polls
>>>>
>>>> and then I obtained the following exception messages 
>>>>
>>>> Traceback (most recent call last):
>>>>   File "manage.py", line 15, in 
>>>> execute_from_command_line(sys.argv)
>>>>   File 
>>>> "C:\Users\Paolo\PycharmProjects\mysite\venv\lib\site-packages\django\core\management\__ini
>>>> t__.py", line 371, in execute_from_command_line
>>>> utility.execute()
>>>>   File 
>>>> "C:\Users\Paolo\PycharmProjects\mysite\venv\lib\site-packages\django\core\management\__ini
>>>> t__.py", line 347, in execute
>>>> django.setup()
>>>>   File 
>>>> "C:\Users\Paolo\PycharmProjects\mysite\venv\lib\site-packages\django\__init__.py",
>>>>  
>>>> line 24
>>>> , in setup
>>>> apps.populate(settings.INSTALLED_APPS)
>>>>   File 
>>>> "C:\Users\Paolo\PycharmProjects\mysite\venv\lib\site-packages\django\apps\registry.py",
>>>>  
>>>> line 93, in populate
>>>> "duplicates: %s" % app_config.label)
>>>> django.core.exceptions.ImproperlyConfigured: Application labels aren't 
>>>> unique, duplicates: polls
>>>> (venv) C:\Users\Paolo\PycharmProjects\mysite>
>>>>
>>>> I reviewed carefully the code and restarted the tutorial several times 
>>>> , all the times having the same problem.
>>>>
>>>> ANY SUGGESTION?? thanks
>>>>
>>>> -- 
>>>> You received this message because you are subscribed to the Google 
>>>> Groups "Django users" group.
>>>>
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>>> an email to django-users...@googlegroups.com.
>>>> To post to this group, send email to django...@googlegroups.com.
>>>
>>>
>>>> Visit this group at https://groups.google.com/group/django-users.
>>>> To view this discussion on the web visit 
>>>> https://groups.google.com/d/msgid/django-users/653a7dd7-b330-4062-86b2-3fa06598008a%40googlegroups.com
>>>>  
>>>> <https://groups.google.com/d/msgid/django-users/653a7dd7-b330-4062-86b2-3fa06598008a%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>> .
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/fffe2c47-a057-4dbb-9f8c-718b3abb8939%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/fffe2c47-a057-4dbb-9f8c-718b3abb8939%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/024e9646-9424-44cc-adfb-cc5397c3146e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Standard approach

2018-05-16 Thread Paolo Chilosi
It will be helpful to have a group/blog for Django beginner so we could 
share problems and solution, maybe this group is geared for more advance 
users.

On Tuesday, May 15, 2018 at 7:53:58 PM UTC-4, Mike Dewhirst wrote:
>
> This list gets a lot of new people joining. They come from all cultures 
> and degrees of general competence. And list members have always made 
> them welcome and try to help as much as possible. 
>
> I would say to beginners - without thinking too hard - that the best 
> place to begin is the excellent Django documentation.  Read "Getting 
> started" https://docs.djangoproject.com/en/1.11/intro/ followed by "What 
> to read next" https://docs.djangoproject.com/en/1.11/intro/whatsnext/ 
>
> However, there are many non-native-english speakers who find reading any 
> documentation just one extra hurdle instead of an open gate. When I see 
> such a request for help in getting started I admire the courage displayed. 
>
> Maybe we need more than a standardised docs approach. Perhaps a wiki 
> would help to display stable advice for different groups of beginners. 
> There have been some particularly illuminating threads in this list 
> revealing the merits of different beginner approaches. The Django blog 
> might be a permanent location for such threads. Maybe there already is a 
> spot for accumulated beginner wisdom? 
>
> There are lots of other resources and recent beginners are probably the 
> most competent to advise. 
>
> I really don't know because I don't have much of a problem reading docs. 
> And it is a while since I was a beginner. 
>
> Just thinking about this, the tutorial project might be valuable as a 
> real project frozen at a seriously simple level so that beginners can 
> browse the source and read the docstrings and comments. A  comment in 
> code might also carry a link to the documentation. Beginners who have 
> trouble with documentation should still be able to figure out the actual 
> code. 
>
> Mike 
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/71b7fec5-f0b9-439d-ab00-352430b5e767%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: django 2.0 tutorial :: exception:: application labels are not unique.

2018-05-15 Thread Paolo Chilosi
thanks for pointing out about the typo. However this was not the cause of 
the exception. Look to my previous answer.

On Tuesday, May 15, 2018 at 9:44:57 AM UTC-4, Sidyvan Fernandes de Andrade 
wrote:
>
> python manage.py makemigrations polls 
>
> 2018-05-15 8:51 GMT-03:00 Paolo Chilosi 
> >:
>
>> As new to Django I am learning following the tutorial carefully. When I 
>> reached the point of making the migration for the polls app I executed 
>> (from the PyCharm terminal) the command:
>>
>> (venv) C:\Users\Paolo\PycharmProjects\mysite>python manage.py 
>> makemigration polls
>>
>> and then I obtained the following exception messages 
>>
>> Traceback (most recent call last):
>>   File "manage.py", line 15, in 
>> execute_from_command_line(sys.argv)
>>   File 
>> "C:\Users\Paolo\PycharmProjects\mysite\venv\lib\site-packages\django\core\management\__ini
>> t__.py", line 371, in execute_from_command_line
>> utility.execute()
>>   File 
>> "C:\Users\Paolo\PycharmProjects\mysite\venv\lib\site-packages\django\core\management\__ini
>> t__.py", line 347, in execute
>> django.setup()
>>   File 
>> "C:\Users\Paolo\PycharmProjects\mysite\venv\lib\site-packages\django\__init__.py",
>>  
>> line 24
>> , in setup
>> apps.populate(settings.INSTALLED_APPS)
>>   File 
>> "C:\Users\Paolo\PycharmProjects\mysite\venv\lib\site-packages\django\apps\registry.py",
>>  
>> line 93, in populate
>> "duplicates: %s" % app_config.label)
>> django.core.exceptions.ImproperlyConfigured: Application labels aren't 
>> unique, duplicates: polls
>> (venv) C:\Users\Paolo\PycharmProjects\mysite>
>>
>> I reviewed carefully the code and restarted the tutorial several times , 
>> all the times having the same problem.
>>
>> ANY SUGGESTION?? thanks
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com 
>> .
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/653a7dd7-b330-4062-86b2-3fa06598008a%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/django-users/653a7dd7-b330-4062-86b2-3fa06598008a%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/fffe2c47-a057-4dbb-9f8c-718b3abb8939%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: django 2.0 tutorial :: exception:: application labels are not unique.

2018-05-15 Thread Paolo Chilosi
Mattew,
thank for the prompt answer. 
In effects, for some reason the app was preset 2 times in the 
INSTALLED_APPS list, also if I am sure I added it only once at the 
beginning of the list. Maybe django added it again at the end of the list. 
I will watch this behavior and let the list know.
Problem solved



On Tuesday, May 15, 2018 at 9:43:39 AM UTC-4, Matthew Pava wrote:

> Though I’ve never seen that error, I’m guessing that maybe you added 
> ‘polls’ to your INSTALLED_APPS setting more than once.  Simply remove the 
> extra references to it.
>
>  
>
> *From:* django...@googlegroups.com  [mailto:
> django...@googlegroups.com ] *On Behalf Of *Paolo Chilosi
> *Sent:* Tuesday, May 15, 2018 6:52 AM
> *To:* Django users
> *Subject:* django 2.0 tutorial :: exception:: application labels are not 
> unique.
>
>  
>
> As new to Django I am learning following the tutorial carefully. When I 
> reached the point of making the migration for the polls app I executed 
> (from the PyCharm terminal) the command:
>
>  
>
> (venv) C:\Users\Paolo\PycharmProjects\mysite>python manage.py 
> makemigration polls
>
>  
>
> and then I obtained the following exception messages 
>
>  
>
> Traceback (most recent call last):
>   File "manage.py", line 15, in 
> execute_from_command_line(sys.argv)
>   File 
> "C:\Users\Paolo\PycharmProjects\mysite\venv\lib\site-packages\django\core\management\__ini
> t__.py", line 371, in execute_from_command_line
> utility.execute()
>   File 
> "C:\Users\Paolo\PycharmProjects\mysite\venv\lib\site-packages\django\core\management\__ini
> t__.py", line 347, in execute
> django.setup()
>   File 
> "C:\Users\Paolo\PycharmProjects\mysite\venv\lib\site-packages\django\__init__.py",
>  
> line 24
> , in setup
> apps.populate(settings.INSTALLED_APPS)
>   File 
> "C:\Users\Paolo\PycharmProjects\mysite\venv\lib\site-packages\django\apps\registry.py",
>  
> line 93, in populate
> "duplicates: %s" % app_config.label)
> django.core.exceptions.ImproperlyConfigured: Application labels aren't 
> unique, duplicates: polls
>
> (venv) C:\Users\Paolo\PycharmProjects\mysite>
>
>  
>
> I reviewed carefully the code and restarted the tutorial several times , 
> all the times having the same problem.
>
>  
>
> ANY SUGGESTION?? thanks
>
>  
>
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users...@googlegroups.com .
> To post to this group, send email to djang...@googlegroups.com 
> .
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/653a7dd7-b330-4062-86b2-3fa06598008a%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/django-users/653a7dd7-b330-4062-86b2-3fa06598008a%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d0685aa9-f404-4fca-b97f-b72c97045f9a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


django 2.0 tutorial :: exception:: application labels are not unique.

2018-05-15 Thread Paolo Chilosi
As new to Django I am learning following the tutorial carefully. When I 
reached the point of making the migration for the polls app I executed 
(from the PyCharm terminal) the command:

(venv) C:\Users\Paolo\PycharmProjects\mysite>python manage.py makemigration 
polls

and then I obtained the following exception messages 

Traceback (most recent call last):
  File "manage.py", line 15, in 
execute_from_command_line(sys.argv)
  File 
"C:\Users\Paolo\PycharmProjects\mysite\venv\lib\site-packages\django\core\management\__ini
t__.py", line 371, in execute_from_command_line
utility.execute()
  File 
"C:\Users\Paolo\PycharmProjects\mysite\venv\lib\site-packages\django\core\management\__ini
t__.py", line 347, in execute
django.setup()
  File 
"C:\Users\Paolo\PycharmProjects\mysite\venv\lib\site-packages\django\__init__.py",
 
line 24
, in setup
apps.populate(settings.INSTALLED_APPS)
  File 
"C:\Users\Paolo\PycharmProjects\mysite\venv\lib\site-packages\django\apps\registry.py",
 
line 93, in populate
"duplicates: %s" % app_config.label)
django.core.exceptions.ImproperlyConfigured: Application labels aren't 
unique, duplicates: polls
(venv) C:\Users\Paolo\PycharmProjects\mysite>

I reviewed carefully the code and restarted the tutorial several times , 
all the times having the same problem.

ANY SUGGESTION?? thanks

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/653a7dd7-b330-4062-86b2-3fa06598008a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


DjangoCon Europe 2017

2017-05-06 Thread Paolo Melchiorre
Hi everyone,
DjangoCon Europe 2017 is over a month, to remember it, I collected one 
twitter moment for each day:
https://twitter.com/i/moments/849039187319943168
https://twitter.com/i/moments/849401309333794816
https://twitter.com/i/moments/849752697578430464
https://twitter.com/i/moments/851110007190016002

I created also a group on flickr to share photo from everyone:
https://twitter.com/pauloxnet/status/853352614255366146

I hope you would appreciate it,
Paolo

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/ba24f8a8-4d09-4225-9f24-edc78e6dd639%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Advanced Annotate

2015-09-16 Thread Paolo C.
Hi Carsten,

my problem is slightly different, in your example you wanted to annotate 
for example the max_book price, I need to annotate not only the price but 
also which is the book that has that max value.


Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2d99ea2e-7927-437a-91f2-cc354986f5c7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Advanced Annotate

2015-09-14 Thread Paolo C.


I've posted this 
 
issue on Stackoverflow

Given this model:

from django.db import models


class Post(models.Model):
text = models.CharField(max_length=255)


class Comment(models.Model):
text = models.CharField(max_length=255)
needs_attention = models.BooleanField(default=False)
created_at = models.DateTimeField(auto_now_add=True)
post = models.ForeignKey(Post)

I can annotate the list of posts with:

Post.objects.annotate(last_comment_date=Max('comment__created_at'))

to know the last_comment_date, how to annotate to set a value for 
last_comment_needs_attention?

How can obtain details from the last comment when listing ll posts?

Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/767682ba-7b96-464e-b2b2-b0ff82fbd320%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Avoid Django s3-urls stripping

2014-03-31 Thread Paolo Bertasi


Hi Aaron,
this is the url:

http://this-is-the-irish-aeneas-bucket.s3.amazonaws.com/XXXASCIINAMEXXX/5/2014-03-10_08%3A37%3A39.274998-d3421964017734f96198c74d853eb2e7?Signature=2hR%2Fy0iXqimJ5e1umXX2xY1FqjU%3D&Expires=1396003040&AWSAccessKeyId=XX

I replaced some byte with X for security reason.
Today, in order to debug, i ve trie:

c = {}

url = aws.get_s3_content(key).replace('/','')
c['s3url'] = url.encode('utf-8')

context = RequestContext(request, c)

return HttpResponse(template.render(context))


and the url is stripped... incredible!


Il giorno venerdì 28 marzo 2014 15:20:13 UTC+1, Aaron Cannon ha scritto:
>
> I'd like to try to reproduce this locally.  If you can send me the URL 
> (feel free to mangle the signature parameter for security), that will 
> help.  Alternatively, you might cut the URL into pieces, to see if 
> it's some specific characters that it's choking on, and then just send 
> me that bit. 
>
> Otherwise, if you'd like to create a small example project that 
> demonstrates this issue, and upload it to github, that would work as 
> well. 
>
> Aaron 
>
> On 3/28/14, Paolo Bertasi > wrote: 
> > 
> > Hi and thanks for your help. 
> > 
> > I tried 
> > * to print url in the console : OK 
> > * to print HttpResponse(url) in the console: OK 
> > * to return the url witout a template in the browser : wrong 
> > 
> > So i am really confused 
> > I am almost sure that: 
> > 1) it is not a s3 problem 
> > 2) it is not a HttpResponse problem 
> > 3) it is not a templating problem 
> > 
> > It seems that django strip the url when i get the url via browser... 
> > 
> > 
> > 
> > Il giorno giovedì 27 marzo 2014 19:34:10 UTC+1, Aaron Cannon ha scritto: 
> >> 
> >> Is the url a bytestring?  A quick check of the code for HttpResponse 
> >> shows that that class is expecting a byte string.  Perhaps the URL 
> >> contains unicode characters that aren't being escaped properly? 
> >> 
> >> Aaron 
> >> 
> >> On 3/27/14, Aaron Cannon > 
> >> wrote: 
> >> > Other things I'd probably try to debug this issue would be: 
> >> > 
> >> > * Hard coding the string into the call to HttpResponse, 
> >> > * printing the variable that contains the URL to the console. 
> >> > 
> >> > If the URL was still bad after trying the first item, and the second 
> >> > item printed the expected result, then you could completely take S3 
> >> > out of the picture.  From there, I would start narrowing it down, to 
> >> > see if it was a specific character that was causing the problem. 
> >> > 
> >> > Narrowing things down a bit more might make it easier for folks to 
> >> > help you figure out your issue. 
> >> > 
> >> > Luck. 
> >> > 
> >> > Aaron 
> >> > 
> >> > On 3/27/14, Paolo Bertasi > wrote: 
> >> >> Hi Aaron, 
> >> >> the html is "wrong" as well. 
> >> >> 
> >> >> Moreover i tried {% autoescape off %} but with no luck :( 
> >> >> 
> >> >> 
> >> >> 
> >> >> 
> >> >> Il giorno giovedì 27 marzo 2014 17:24:45 UTC+1, Aaron Cannon ha 
> >> scritto: 
> >> >>> 
> >> >>> Try clicking view source in your browser when you view it.  Perhaps 
> >> >>> the URL needs to be HTML escaped? 
> >> >>> 
> >> >>> Just a guess. 
> >> >>> 
> >> >>> Aaron 
> >> >>> 
> >> >>> On 3/21/14, Paolo Bertasi > 
> wrote: 
> >> >>> > Hello, 
> >> >>> > I'm trying to setup a mini django app to allow users to download 
> >> files 
> >> >>> from 
> >> >>> > 
> >> >>> > s3. I wrote a simple python function (using boto of course) to 
> fetch 
> >> >>> > 
> >> >>> > the 
> >> >>> > 
> >> >>> > correct url but when i handle the url with django the url is 
> >> stripped. 
> >> >>> > I wrote down the exact behaviour 
> >> >>> > here< 
> >> >>> 
> >> 
> http://stackoverflow.com/questions/22531195/avoid-django-s3-urls-stripping> 
>
> >> 
> >> 
> >> >>> 
> >

Re: Avoid Django s3-urls stripping

2014-03-28 Thread Paolo Bertasi

Hi and thanks for your help.

I tried 
* to print url in the console : OK
* to print HttpResponse(url) in the console: OK
* to return the url witout a template in the browser : wrong 

So i am really confused
I am almost sure that:
1) it is not a s3 problem
2) it is not a HttpResponse problem
3) it is not a templating problem

It seems that django strip the url when i get the url via browser... 



Il giorno giovedì 27 marzo 2014 19:34:10 UTC+1, Aaron Cannon ha scritto:
>
> Is the url a bytestring?  A quick check of the code for HttpResponse 
> shows that that class is expecting a byte string.  Perhaps the URL 
> contains unicode characters that aren't being escaped properly? 
>
> Aaron 
>
> On 3/27/14, Aaron Cannon > 
> wrote: 
> > Other things I'd probably try to debug this issue would be: 
> > 
> > * Hard coding the string into the call to HttpResponse, 
> > * printing the variable that contains the URL to the console. 
> > 
> > If the URL was still bad after trying the first item, and the second 
> > item printed the expected result, then you could completely take S3 
> > out of the picture.  From there, I would start narrowing it down, to 
> > see if it was a specific character that was causing the problem. 
> > 
> > Narrowing things down a bit more might make it easier for folks to 
> > help you figure out your issue. 
> > 
> > Luck. 
> > 
> > Aaron 
> > 
> > On 3/27/14, Paolo Bertasi > wrote: 
> >> Hi Aaron, 
> >> the html is "wrong" as well. 
> >> 
> >> Moreover i tried {% autoescape off %} but with no luck :( 
> >> 
> >> 
> >> 
> >> 
> >> Il giorno giovedì 27 marzo 2014 17:24:45 UTC+1, Aaron Cannon ha 
> scritto: 
> >>> 
> >>> Try clicking view source in your browser when you view it.  Perhaps 
> >>> the URL needs to be HTML escaped? 
> >>> 
> >>> Just a guess. 
> >>> 
> >>> Aaron 
> >>> 
> >>> On 3/21/14, Paolo Bertasi > wrote: 
> >>> > Hello, 
> >>> > I'm trying to setup a mini django app to allow users to download 
> files 
> >>> from 
> >>> > 
> >>> > s3. I wrote a simple python function (using boto of course) to fetch 
> >>> > the 
> >>> > 
> >>> > correct url but when i handle the url with django the url is 
> stripped. 
> >>> > I wrote down the exact behaviour 
> >>> > here< 
> >>> 
> http://stackoverflow.com/questions/22531195/avoid-django-s3-urls-stripping> 
>
> >>> 
> >>> 
> >>> > . 
> >>> > 
> >>> > Please help :) 
> >>> > 
> >>> > -- 
> >>> > You received this message because you are subscribed to the Google 
> >>> Groups 
> >>> > "Django users" group. 
> >>> > To unsubscribe from this group and stop receiving emails from it, 
> send 
> >>> an 
> >>> > email to django-users...@googlegroups.com . 
> >>> > To post to this group, send email to 
> >>> > django...@googlegroups.com. 
> >>> 
> >>> > Visit this group at http://groups.google.com/group/django-users. 
> >>> > To view this discussion on the web visit 
> >>> > 
> >>> 
> https://groups.google.com/d/msgid/django-users/e3dba710-5189-4800-b455-09868dcf578b%40googlegroups.com.
>  
>
> >>> 
> >>> 
> >>> > For more options, visit https://groups.google.com/d/optout. 
> >>> > 
> >>> 
> >> 
> >> -- 
> >> You received this message because you are subscribed to the Google 
> Groups 
> >> "Django users" group. 
> >> To unsubscribe from this group and stop receiving emails from it, send 
> an 
> >> email to django-users...@googlegroups.com . 
> >> To post to this group, send email to 
> >> django...@googlegroups.com. 
>
> >> Visit this group at http://groups.google.com/group/django-users. 
> >> To view this discussion on the web visit 
> >> 
> https://groups.google.com/d/msgid/django-users/1172243d-6d55-41b4-9cf4-a6bbc6379225%40googlegroups.com.
>  
>
> >> For more options, visit https://groups.google.com/d/optout. 
> >> 
> > 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d8f379e1-4485-43ea-9a0a-7982ff1d0e35%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Avoid Django s3-urls stripping

2014-03-27 Thread Paolo Bertasi
Hi Aaron,
the html is "wrong" as well.

Moreover i tried {% autoescape off %} but with no luck :(




Il giorno giovedì 27 marzo 2014 17:24:45 UTC+1, Aaron Cannon ha scritto:
>
> Try clicking view source in your browser when you view it.  Perhaps 
> the URL needs to be HTML escaped? 
>
> Just a guess. 
>
> Aaron 
>
> On 3/21/14, Paolo Bertasi > wrote: 
> > Hello, 
> > I'm trying to setup a mini django app to allow users to download files 
> from 
> > 
> > s3. I wrote a simple python function (using boto of course) to fetch the 
> > correct url but when i handle the url with django the url is stripped. 
> > I wrote down the exact behaviour 
> > here<
> http://stackoverflow.com/questions/22531195/avoid-django-s3-urls-stripping> 
>
> > . 
> > 
> > Please help :) 
> > 
> > -- 
> > You received this message because you are subscribed to the Google 
> Groups 
> > "Django users" group. 
> > To unsubscribe from this group and stop receiving emails from it, send 
> an 
> > email to django-users...@googlegroups.com . 
> > To post to this group, send email to 
> > django...@googlegroups.com. 
>
> > Visit this group at http://groups.google.com/group/django-users. 
> > To view this discussion on the web visit 
> > 
> https://groups.google.com/d/msgid/django-users/e3dba710-5189-4800-b455-09868dcf578b%40googlegroups.com.
>  
>
> > For more options, visit https://groups.google.com/d/optout. 
> > 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1172243d-6d55-41b4-9cf4-a6bbc6379225%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Avoid Django s3-urls stripping

2014-03-21 Thread Paolo Bertasi
Hello,
I'm trying to setup a mini django app to allow users to download files from 
s3. I wrote a simple python function (using boto of course) to fetch the 
correct url but when i handle the url with django the url is stripped.
I wrote down the exact behaviour 
here
.

Please help :)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/e3dba710-5189-4800-b455-09868dcf578b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Managing existing UI

2013-11-01 Thread Paolo Giannoccaro
Hi All,
which are the best practices while developing a full Django app (version 
1.5, Phyton 3) starting from an existing html UI ? The template approach is 
still valid ? In this case which is the impact over existing html UI ?
Many thanks

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8ffa3b52-705f-42d5-92ee-93f785523fe5%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Testing: Fixtures vs Factories vs ???

2012-02-17 Thread Paolo
Hi folks,

I've been coding away on my latest Django project, and have recently 
started to think about how best to test the functionality I have so far.

Creating fixtures for my tests seems like a good idea initially, but from 
experience I find fixtures become harder and harder to maintain as the 
project ages and expands.

The literature appears to recommend fixtures as the way forward, but I also 
see there are projects such as 'factory boy' (inspired by the Rails world) 
offering an alternative (or complimentary?) method.  

Are there any recommendations/comments/examples from the Django community 
on what the best way to go is with regards to data for testing? 

Cheers,

Paul

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/QGmQpB5A5moJ.
To post to this group, send email to django-users@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.



OneToOneField causes NotFound exception?

2011-10-24 Thread Paolo
Hi,

It looks like if I'm using a OneToOne field (with blank=True etc set) and 
happen to try and access this field when it's Null (or None) then I get a 
NotFound exception?  

My expectation was it would return None of nothing was set, not raise an 
exception?

I could of course catch this exception each time, but I need to keep 
remembering which fields I've set as OneToOne and which are plan old 
ForeignKey!

Thanks,

Paul

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/wf7ZOZlnAc4J.
To post to this group, send email to django-users@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 ORM - Am I trying to do the impossible?

2011-10-21 Thread Paolo
Hi Jirka,

Thanks for the response, but if I understand your post then the issue is 
still the need to iterate over every Team (as opposed to every assignment) 
in order to construct a collection of Teams in a certain Status... if that 
makes sense.

I think the crux of the issue is a limitation of Django's ORM to retrieve 
anything except the fields you are grouping by/working with with the 
"annotate" and "values" methods.  E.g. I'm grouping by the assignment_id in 
assignment_update and getting the max_date from each of the groups, but 
Django is unable to give me the assignment_update_id of the max_date record 
it finds (in this case it just returns all records...).

Cheers,

Paul

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/5O4kTbR9V-0J.
To post to this group, send email to django-users@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 ORM - Am I trying to do the impossible?

2011-10-21 Thread Paolo
Thanks guys, I think you're essentially saying the same thing in different 
ways - 'denormalise' the data so I can make use of the Assignment model for 
querying without looking at the Update models.

This clears things up for me, cheers!


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/sDgwsGkI9d8J.
To post to this group, send email to django-users@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 ORM - Am I trying to do the impossible?

2011-10-21 Thread Paolo
An additional requirement for assignments is to keep status history, so we 
can see "assignment 1 was active mon-wed, standby thu-fri then active again" 
etc.

As for the query, yes that was my initial idea but I thought it was going to 
be inefficient for times when I wanted to query for all assignments in a 
current status.  So essentially we have:

'Load all assignments into Django. Loop through each one doing a "select top 
record from assignment_update where assignment_id = this assignment", add it 
to a list of matched_assignments then pass back to the caller to display"

Where what I'm trying to ask the database for is:

"Group all assignment updates by assignment and select the one with the 
latest date and status X, giving me the assignment id from this record back 
so I can load it into a list of filtered assignments without looking at each 
one in turn".

Does that make sense? Mountain out of molehill you think? Interesting 
anyway, right? ;)

Cheers,

Paul

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/EW_igFGqE1sJ.
To post to this group, send email to django-users@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.



Django ORM - Am I trying to do the impossible?

2011-10-20 Thread Paolo
Hi all,

I'm developing a Django app that has a slightly complex model, as follows:

Teams have Assignments, which in turn have Assignment Updates.  The status 
of the Assignment (and therefore the Team) is based on the latest Assignment 
Update, which has a status of ACTIVE, STANDBY etc.

My issue is I've found it impossible so far to retrieve the current Status 
for a group of Teams/Assignments without resorting to loading everything 
into the app and processing, or (as I've actually done to get around the 
impending speed issues) have fields which act as 'pointers' to the latest 
Status Report for each Assignment.

The problem comes when I try and pull the assignment update id of the 
record.  It seems that when I use the "annotate" method, I can only get the 
value I'm grouping by (assignment_id) and the max value - if I try and pull 
out the assignment_update_id (e.g. the thing I'm interested in), the ORM 
just pulls back all records?

Broken code is something like the following:

Assignment.objects.filter(id__in=AssignmentUpdate.objects.filter(id__in=AssignmentUpdate.objects.filter(actual_report_time__isnull=False).values('assignment_id').annotate(actual_report_time=Max('actual_report_time')).values_list('id',
 
flat=True), status=ASSIGNMENT_STANDBY).values_list('assignment_id', 
flat=True)) 

Any pointers would be appreciated - I'm not too excited about storing the 
latest_assignment_update_id in my Assignment model!!

Thanks,

Paul

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/W_DHsyrhNjQJ.
To post to this group, send email to django-users@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: DatabaseError: ORA-03127: no new operations allowed until the active operation ends

2011-03-22 Thread Paolo Corti
On 22 Mar, 11:41, Paolo Corti  wrote:
> Hi
> I had to migrate a GeoDjango project based on a Postgres/PostGIS
> backend to a Oracle/Oracle Spatial backend.
>
> I could sync the database without problems and now I can successfully
> read and create new data from the shell, but as soon as I try to
> access my Django web application I am getting in this error:
>
> Traceback (most recent call last):
>   File "/home/pcorti/virtualenv/forest_env/lib/python2.6/site-packages/
> django/core/servers/basehttp.py", line 283, in run
>     self.result = application(self.environ, self.start_response)
>   File "/home/pcorti/virtualenv/forest_env/lib/python2.6/site-packages/
> django/contrib/staticfiles/handlers.py", line 68, in __call__
>     return self.application(environ, start_response)
>   File "/home/pcorti/virtualenv/forest_env/lib/python2.6/site-packages/
> django/core/handlers/wsgi.py", line 275, in __call__
>     signals.request_finished.send(sender=self.__class__)
>   File "/home/pcorti/virtualenv/forest_env/lib/python2.6/site-packages/
> django/dispatch/dispatcher.py", line 172, in send
>     response = receiver(signal=self, sender=sender, **named)
>   File "/home/pcorti/virtualenv/forest_env/lib/python2.6/site-packages/
> django/db/__init__.py", line 85, in close_connection
>     conn.close()
>   File "/home/pcorti/virtualenv/forest_env/lib/python2.6/site-packages/
> django/db/backends/__init__.py", line 244, in close
>     self.connection.close()
>
> DatabaseError: ORA-03127: no new operations allowed until the active
> operation end
>
> I am having the same behavior both with Django 1.2.5 and 1.3 RC
> any ideas?
> thanks

I have solved this by downgrading the cx_Oracle library from 5.1 to
5.0.1
I am using Oracle 11.2
Now works well both on Django 1.2.5 and 1.3 RC with Python 2.6
best regards
P

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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.



DatabaseError: ORA-03127: no new operations allowed until the active operation ends

2011-03-22 Thread Paolo Corti
Hi
I had to migrate a GeoDjango project based on a Postgres/PostGIS
backend to a Oracle/Oracle Spatial backend.

I could sync the database without problems and now I can successfully
read and create new data from the shell, but as soon as I try to
access my Django web application I am getting in this error:

Traceback (most recent call last):
  File "/home/pcorti/virtualenv/forest_env/lib/python2.6/site-packages/
django/core/servers/basehttp.py", line 283, in run
self.result = application(self.environ, self.start_response)
  File "/home/pcorti/virtualenv/forest_env/lib/python2.6/site-packages/
django/contrib/staticfiles/handlers.py", line 68, in __call__
return self.application(environ, start_response)
  File "/home/pcorti/virtualenv/forest_env/lib/python2.6/site-packages/
django/core/handlers/wsgi.py", line 275, in __call__
signals.request_finished.send(sender=self.__class__)
  File "/home/pcorti/virtualenv/forest_env/lib/python2.6/site-packages/
django/dispatch/dispatcher.py", line 172, in send
response = receiver(signal=self, sender=sender, **named)
  File "/home/pcorti/virtualenv/forest_env/lib/python2.6/site-packages/
django/db/__init__.py", line 85, in close_connection
conn.close()
  File "/home/pcorti/virtualenv/forest_env/lib/python2.6/site-packages/
django/db/backends/__init__.py", line 244, in close
self.connection.close()

DatabaseError: ORA-03127: no new operations allowed until the active
operation end

I am having the same behavior both with Django 1.2.5 and 1.3 RC
any ideas?
thanks

--
Paolo Corti
Geospatial software developer
web: http://www.paolocorti.net
twitter: @paolo_corti

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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.



Pre-filled user info in Django Comments?

2010-12-09 Thread Paolo
Hi,

The site I'm building uses the standard user management framework and
the standard comments framework.

What I'd like to see happen is the comments form rendered with the
user's name and email address pre-filled if they are already signed in
(or have the fields hidden entirely!).

Easy enough?

Cheers,

Paul

-- 
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.



Custom manager on abstract model

2009-09-01 Thread Paolo Ferretti

Hi,

I've got a problem with a custom manager on an abstract model. I've
something like this:

class CommonModelManager(models.Manager):
def get_query_set(self):
return super(CommonModelManager, self).get_query_set().filter
(time_deleted__isnull=True).filter
(registration_site=Site.objects.get_current())

class CommonModel(models.Model):
author = models.ForeignKey(User)
[other fields...]
registration_site = models.ForeignKey(Site, blank=True, null=True,
editable=False)

objects= CommonModelManager()

class Meta:
abstract = True

class Image(CommonModel):
image = ImageWithThumbnailsField([...])
title = models.CharField(_('title'), max_length=65, blank=True)
caption = models.TextField(_('caption'), blank=True,
max_length=512)
albums = models.ManyToManyField('Album', verbose_name=_('album'),
blank=True)

So, I have Image with a ForeignKey to User related to current Site. I
want to retrieve all images in current site from a user (a user can be
on multiple sites), using:

user.image_set.all()

but I can't, because I can't filter results in this type of manager
subclass ( 
http://docs.djangoproject.com/en/dev/topics/db/managers/#writing-correct-managers-for-use-in-automatic-manager-instances
).
An ugly solution may be:

Image.objects.filter(author=user)

But I think that that the most elegant solution is the one with
image_set and, if possible, I would like to use the elegant solution!

Any ideas to solve this problem?

Thanks, Paolo
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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: Update an object with a dictionary

2009-06-10 Thread Paolo Corti


>
> .save() is only for persisting the object to disk, not for modifying
> objects. To update any Python object from a dictionary is as easy as:
>
> for k,v in d.items(): setattr(myobject, k, v)

this is also what i came to.
But curious to try the Daniel's approach, will let you know
best regards
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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
-~--~~~~--~~--~--~---



Update an object with a dictionary

2009-06-10 Thread Paolo Corti

Hi
is it possible to update an object with a dictionary?

I tried something like this:
myobject.save(force_update=True, **my_dict)

getting an error, though:
TypeError at ...
save() got an unexpected keyword argument 'myfieldname'

I wouldn't like to iterate the dictionary, neither to delete and
create the object again using the dictionary, is there a best
approach?

thanks
Paolo

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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 can i access UserProfile from User in the views?

2009-03-18 Thread Paolo Corti

On Mar 17, 7:24 pm, Andy Mckay  wrote:

> If you use request context then you will get the user available:
>
> http://docs.djangoproject.com/en/dev/ref/templates/api/?from=olddocs#...

I could correctly access context, in fact i had the error also from
the shell.

The problem i had ("Caught an exception while rendering: Cannot
resolve keyword 'user' into field") was because in my model i had:

utente = models.ForeignKey(User, unique=True, blank=True, null=True)

i renamed my attribute to user, and so it is working:

user = models.ForeignKey(User, unique=True, blank=True, null=True)

so looks like in the doc should be written that the foreign key MUST
be called user.

thanks anyway
Paolo




--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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 can i access UserProfile from User in the views?

2009-03-17 Thread Paolo Corti

Hello Andy

>
> Do you mean in the template?

yes, sorry...

>
> I don't use Django templating but have you tried:
>
> user.get_profile.home_address
>

if i use this in the template i get this error: Caught an exception
while rendering: Cannot resolve keyword 'user' into field

thanks anyway

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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
-~--~~~~--~~--~--~---



How can i access UserProfile from User in the views?

2009-03-17 Thread Paolo Corti

Hi
I know is easy to access to the UserProfile, like here:

from django.contrib.auth.models import User
u = User.objects.get(pk=1) # Get the first user in the system
user_address = u.get_profile().home_address

but is there a way to access to UserProfile in the view?
supposing the UserProfile model is called myprofile, this will not do
the trick:

{{ user.myprofile.home_address }}

any advice? 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-users@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: link to ForeignKey in Admin's change list page

2008-11-18 Thread Paolo Corti

Daniel,
thanks a lot, it works perfectly

Paolo

On Nov 17, 8:19 pm, Daniel Roseman <[EMAIL PROTECTED]>
wrote:
> On Nov 17, 4:42 pm, Paolo Corti <[EMAIL PROTECTED]> wrote:
>
>
>
> > Hi
> > maybe this is trivial, but i can't find a way to get it (and from what
> > i can see it seems not possible):
>
> > my model:
>
> > class Project(models.Model):
> >         name = models.CharField('name', max_length=255)
> >         
> >         #relationship
> >         projectowner = models.ForeignKey(Person)
>
> > in admin.py:
>
> > class ProjectAdmin(admin.ModelAdmin):
> >         model = Project
> >         list_display = ['name', ..., 'projectowner']
> >         list_display_links = ['name']
> >         list_filter = ['name', 'projectowner']
>
> > list_display_links will put a link at the 'name' field to the
> > Project's page, like this 
> > one:http://localhost:8000/admin/projects/project/1/
>
> > is there a way to the the same result for the foreign key?
>
> > I would like that at the 'projectowner' field there would be a link
> > like this one:http://localhost:8000/admin/projects/person/2/
>
> > thanks!
>
> Your best bet would be to define a method on the Project model that
> returns a snippet of HTML with the link and text. You need to set
> allow_tags=True.
>
> def projectowner_link(self):
>     return u'%s' %
> (self.projectowner.id, self.projectowner.name)
> projectowner_link.allow_tags = True
>
> list_display = ['name', ..., 'projectowner_link']
> --
> 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-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



link to ForeignKey in Admin's change list page

2008-11-17 Thread Paolo Corti

Hi
maybe this is trivial, but i can't find a way to get it (and from what
i can see it seems not possible):

my model:

class Project(models.Model):
name = models.CharField('name', max_length=255)

#relationship
projectowner = models.ForeignKey(Person)

in admin.py:

class ProjectAdmin(admin.ModelAdmin):
model = Project
list_display = ['name', ..., 'projectowner']
list_display_links = ['name']
list_filter = ['name', 'projectowner']

list_display_links will put a link at the 'name' field to the
Project's page, like this one:
http://localhost:8000/admin/projects/project/1/

is there a way to the the same result for the foreign key?

I would like that at the 'projectowner' field there would be a link
like this one:
http://localhost:8000/admin/projects/person/2/

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-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



verbose_name_plural not working in the admin?

2008-09-09 Thread Paolo Corti

Hi

here is a sample class:

class TipoMisura(models.Model):
nome = models.CharField('nome', max_length=255, null=True)

class Meta:
verbose_name = "Tipo di Misura"
verbose_name_plural = "Tipo di Misure"

In the admin interface, the link to the change page is displayed as
"Tipo di Misuras".
Is it a bug or am i missing something?

thanks in advance
Paolo

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



Re: Unicode decode errors with Admin and Postgres

2008-09-09 Thread Paolo Corti



On 1 Set, 18:48, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote:
> On Mon, 2008-09-01 at 08:37 -0700, PaoloCortiwrote:
> > Hi all
>
> > I am a beginner using Django from the trunk and Postgres 8.2
>
> > I have this issue with utf8, you can replicate it this way (it is
> > something similiar to this with MySql i guess:
> >http://groups.google.com/group/django-users/browse_frm/thread/d7dd214...)
>
> > 1) create a postgres db like this:
>
> > CREATE DATABASE test2
> >   WITH ENCODING='UTF8'
> >        OWNER=test;
>
> > 2) create a django project
>
> > django-admin.py startproject testutf
>
> > 3) configure the settings.py file for the database access and enable
> > the admin application
>
> > 4) create a test application
>
> > python manage.py startapp apptestutf
>
> > 5) create this simple model
>
> > from django.db import models
>
> > class Person(models.Model):
> >    name = models.CharField('name', max_length=100)
>
> >    def __str__(self):
> >            return '%s' % self.name
>
> So as soon as you see UnicodeDecodeError, you should immediately think
> "where am I passing a unicode object to something that can only handle
> bytestrings." The __str__ method is certainly one of those cases.
>
> Best to follow the Django documentation here and write a __unicode__
> method for your model (not a __str__ method). Refer to the first two
> sections here (or the /unicode documentation) for 
> details:http://www.djangoproject.com/documentation/model-api/#str
>
> And, yes, those sections are arguably backwards, since it explains
> __str__ and then effectively says "don't bother doing that" in a
> confusing fashion. That will be fixed at some point.
>
> Regards,
> Malcolm

Thanks Malcolm
it makes sense and is working now

Paolo

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



Unicode decode errors with Admin and Postgres

2008-09-01 Thread Paolo Corti

Hi all

I am a beginner using Django from the trunk and Postgres 8.2

I have this issue with utf8, you can replicate it this way (it is
something similiar to this with MySql i guess:
http://groups.google.com/group/django-users/browse_frm/thread/d7dd21493ab5f1fa/a0bd99e381d9de2a?tvc=1&q=encoding+admin#a0bd99e381d9de2a)

1) create a postgres db like this:

CREATE DATABASE test2
  WITH ENCODING='UTF8'
   OWNER=test;

2) create a django project

django-admin.py startproject testutf

3) configure the settings.py file for the database access and enable
the admin application

4) create a test application

python manage.py startapp apptestutf

5) create this simple model

from django.db import models

class Person(models.Model):
name = models.CharField('name', max_length=100)

def __str__(self):
return '%s' % self.name

6) sync db

 python manage.py syncdb

7) run the shell and add this object

 python manage.py shell

>>> from testutf.apptestutf.models import Person
>>> Person.objects.create(name=u'Paol\xe8')


8) start the server

 python manage.py runserver

If I access the object I just created from the admin interface:

http://localhost:8000/admin/apptestutf/person/6/

I get this error:

TemplateSyntaxError at /admin/apptestutf/person/6/

Caught an exception while rendering: 'ascii' codec can't encode
character u'\xe8' in position 4: ordinal not in range(128)

Any ideas? Thanks in advance

Paolo Corti

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



Unicode decode errors with Admin and Postgres

2008-09-01 Thread Paolo Corti

hello Django users
I am a beginner using Django from the trunk and Postgres 8.2

I have this issue with utf8, you can replicate it this way (it is
something similiar to this with MySql i guess:
http://groups.google.com/group/django-users/browse_frm/thread/d7dd21493ab5f1fa/a0bd99e381d9de2a?tvc=1&q=encoding+admin#a0bd99e381d9de2a)

1) create a postgres db like this:

CREATE DATABASE test2
  WITH ENCODING='UTF8'
   OWNER=test;

2) create a django project

django-admin.py startproject testutf

3) configure the settings.py file for the database access and enable
the admin application

4) create a test application

python manage.py startapp apptestutf

5) create this simple model

from django.db import models

class Person(models.Model):
name = models.CharField('name', max_length=100)

def __str__(self):
return '%s' % self.name

6) sync db

 python manage.py syncdb

7) run the shell and add this object

 python manage.py shell

>>> from testutf.apptestutf.models import Person
>>> Person.objects.create(name=u'Paol\xe8')


8) start the server

 python manage.py runserver

If I access the object I just created from the admin interface:

http://localhost:8000/admin/apptestutf/person/6/

I get this error:

TemplateSyntaxError at /admin/apptestutf/person/6/

Caught an exception while rendering: 'ascii' codec can't encode
character u'\xe8' in position 4: ordinal not in range(128)

Any ideas? Thanks in advance

Paolo Corti

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



Re: memcache not used?

2008-07-01 Thread Paolo Ambrosio

Hi,

just a quick note... the port (112211) wrong only on your email, or in
the settings file too?

> CACHE_BACKEND = 'memcached://127.0.0.1:112211/'

Paolo

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



Re: possible urls issue

2008-06-30 Thread Paolo Ambrosio

On Mon, Jun 30, 2008 at 5:36 PM, Bobby Roberts <[EMAIL PROTECTED]> wrote:

> ok assuming i use a HttpResponseRedirect, how would I pull the session
> variables into the template?

HttpResponseRedirect does not use a template. The response is a 302
code to the browser, not an html page, to tell the browser to issue
another request for the page you are redirecting to.

Let's say that you return HttpResponseRedirect('/step2/ '). The
browser receives the redirection request and calls the new url
http://mysite.com/step2/. That is ANOTHER request that is handled by
the view you chose for '^step2/' in your urls.py

Paolo

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



Re: Trying to get ifequal to evaluate to True

2008-06-30 Thread Paolo Ambrosio

On Mon, Jun 30, 2008 at 5:14 PM, Ayaz Ahmed Khan
<[EMAIL PROTECTED]> wrote:
>
> On Jun 30, 8:05 pm, "Paolo Ambrosio" <[EMAIL PROTECTED]>
> wrote:
>> On Mon, Jun 30, 2008 at 4:52 PM, Ayaz Ahmed Khan
>>
>> <[EMAIL PROTECTED]> wrote:
>> > [...]  The variable "next"
>> > does have that particular value (I verified both by printing it out
>> > and by making sure {% if next %} evaluates to True).  However, the
>> > "ifequal" expression just doesn't work.
>>
>> Are you passing it through the context while invoking the template?
>
> I, myself, am not passing that particular value.  I am calling the
> built-in login view provided by Django -- which is ``from
> django.contrib.auth.views import login''.  That view passes the "next"
> as part of the context while rendering the login template.

I just built a test application and it works for me, if I understood
what is your problem.

I created a view protected by the @login_required decorator, mapped to
two different urls:

1) /accounts/test1/
2) /accounts/test2/

The login_required redirects to /accounts/login/?next=... that calls
the same view you are using.

And this is my template ("registration/login.html"):

{{ next }} - {% ifequal next "/accounts/test1/" %}true{% endifequal %}

If I go to http://localhost:8000/accounts/test1/, I am redirected to
http://localhost:8000/accounts/login/?next=/accounts/test1/ that
shows:

/accounts/test1/ - true

otherwise if I go to http://localhost:8000/accounts/test2/ I see:

/accounts/test2/ -

Maybe yours is just a typo.

Paolo

P.S.
I am using the trunk

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



Re: Trying to get ifequal to evaluate to True

2008-06-30 Thread Paolo Ambrosio

On Mon, Jun 30, 2008 at 4:52 PM, Ayaz Ahmed Khan
<[EMAIL PROTECTED]> wrote:

> [...]  The variable "next"
> does have that particular value (I verified both by printing it out
> and by making sure {% if next %} evaluates to True).  However, the
> "ifequal" expression just doesn't work.

Are you passing it through the context while invoking the template?

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



Re: possible urls issue

2008-06-30 Thread Paolo Ambrosio

On Mon, Jun 30, 2008 at 4:50 PM, Bobby Roberts <[EMAIL PROTECTED]> wrote:

> when form1 is_valid, the view saves form1 to session variables then
> redirects to step2 as follows:
>
> return render_to_response("step2.html",'form': form},
> context_instance=RequestContext(request))
>
>
> The main issue i'm having is that i need this to redirect to
> mysite.com/step2/ but it's staying at mysite.com/step1/ which results
> in the view for step2 not being executed.

I am not sure I understood your problem correctly, but if you want to
redirect the request to another url you have to use
HttpResponseRedirect, since render_to_response simply uses the
step2.html template to render the page (so no http redirect). AFAIK it
should be also explained in the Django tutorial.

Hope it helps.

Paolo

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



File Upload with newforms

2008-03-10 Thread Paolo Ferretti

I've got a problem with file upload in django. I found some generic
documentation like this:

http://www.djangoproject.com/documentation/model-api/#filefield
http://www.djangoproject.com/documentation/faq/#how-do-i-use-image-an...

Reading that pages, I suppose that the file uploading copy into my
MEDIA_ROOT happens automatically when I save my record.
The problem is that the file name is saved into my database table, but
the file isn't saved into the MEDIA_ROOT directory in the filesystem.
Where am I wrong? Here is the code (I use django SVN version under
Windows XP):

# models.py

class Auto(models.Model):
[...others field...]
foto = models.ImageField(upload_to="images/auto/", blank=True,
null=True)

# forms.py

class AddImageForm(forms.Form):
immagine = forms.ImageField(label='Immagine:', required=True)

# views.py

def addphotoauto(request, id):
if request.method == 'GET':
form = AddImageForm()
return render_to_response('auto/aggiungi_foto.html', {'form':
form})
if request.method == 'POST':
form = AddImageForm(request.POST, request.FILES)
if form.is_valid():
try:
a = Auto.objects.get(id__exact = id)
a.foto = form.cleaned_data.get('immagine')
a.save()
# TODO: save file
return HttpResponseRedirect('/')
except Exception, e:
# exception handling
else:
return render_to_response('auto/aggiungi_foto.html',
{'form': form})
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Use properties for filtering results

2007-04-11 Thread Paolo Dina

In my model there is model method I'd like to use for filtering.
Is it possible? I have put it in form of property, but when I use it
with field lookup syntax I get an error.

This is a minimal sample model that should explain what I mean:

class Category(models.Model):
name = models.CharField(maxlength=16)

class Content(models.Model):
title = models.CharField(maxlength=32)
category = models.ForeignKey(Category)
pub_date = models.DateTimeField()
priv = BooleanField(default=True)

def _visible(self):
return (self.priv == False and self.pub_date < datetime.now())
visible = property(_visible)

>>> c = Content.objects.get(pk=1)
>>> c.visible
False
>>> Category.objects.filter(visible=False)
Traceback (most recent call last):
...
TypeError: Cannot resolve keyword 'visible' into field

Filtering in this way would come handy in a custom template tag, where
I'd like to ask things in this way:
Category.objects.get_categories(user), where get_categories is a
Category's custom manager method that returns different results
depending on user's authentication status.

def get_categories(self, user=None):
c_qs = Category.objects.all()

if hasattr(user, 'is_staff') and user.is_staff:
res = [(c, c.content_set.count()) for c in c_qs]
else:
res = [(c, c.content_set.filter(visible=True).count()) for c
in c_qs]
return res

Any suggestion?

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-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Upload to custom directory

2006-09-12 Thread paolo

Hi, search the list for ImageField or FileField and you will find some
useful answer to your question, together with other side effects about
these fields that is good to know. Other people have had your same
problem (and actually me too), and some of them offered their solution.
Example:
http://groups.google.com/group/django-users/browse_frm/thread/93c024f1523f5323

Hope this help, regards.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Italian Documentation

2006-09-10 Thread paolo

> 2. In the page you mentioned I saw that tutorial part 1 italian is
> already finished by you
>  so mine would be a "surplus". From now on I will check the page
> before any translation start.

Hmm rather than a "surplus" it is just another translation of the same
document (and that was one of that things we want avoid, in respect of
DRY!).
My translations are kept on the Django wiki, so if you think you can
improve their quality make changes and add yourself as a "contributor"
at the top of the document, if you want. Obviously the two translations
could coexist also :-)

> 3. The reason why I decided to translate the official tutorial is just
> to help myself into learning Django. I don't pretend to be so good in
> translation so a supervision would be necessary. (And also I don't
> know well the Rest formatting). But I definitely offer my help in
> translate docs.

This is my idea: if you need a "review", once you finish a translation,
make it public (for example via Django I18N mailinglist - let's join it
if you are not) and some of us italian users probably will give you a
feedback.

About reStructuredText I can suggest to download docutils, install it
and see by yourself if your reST formatting is ok.
A final note: if you are interested in Italian translations of docutils
documentation look here: http://docit.bice.dyndns.org/ReST/

> 4 I wold go ahead and do tutorial part 2,3,4 are you aready there?

Go go!

> P.S: I'm from Rome and you?
>From Mantua.

P.S.
Consider to add you name/email to
http://code.djangoproject.com/wiki/Localization


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Italian Documentation

2006-09-08 Thread paolo

> A trivial question: Is it better to wait 1.0 for me to learn django?

In my opinion, NO. Why wait for 1.0? If you are learning Django you
have two choices: use an official release or stay with the trunk.

I'm using the trunk since I'm using Django, and I never had problems.
However I must say that each time I do an svn up I always feel the fear
that something breaks. But it is just a personal problem, I repeat that
I never had any kind of unpleasant situation. If you choose for the
trunk be sure to read
http://code.djangoproject.com/wiki/BackwardsIncompatibleChanges .

Anyway, now I would choose stable releases. It is supposed, for the
most of the times, that someone that is learning Django isn't
interested in the bleeding edges features, and maybe it's better to
have them in the next official release, in all their reliability.

Do you want a diff from the current Django release and 1.0? Look here:
http://www.djangoproject.com/documentation/api_stability/

Paolo

P.S.
Please, next time could you please create a dedicated thread when ask
different questions? 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-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Italian Documentation

2006-09-08 Thread paolo

Hi, I'm sorry to see your post so late.
This page on the wiki should answer all your questions:
http://code.djangoproject.com/wiki/TranslateDocumentation

Differently, ask!

I can assure that translate live documentation (docs in the trunk I
mean) and keep it up to date is a real pain, I did so but it
definitively it is not the best approach if you haven't a lot of time
at your disposal. You could rather consider to stick on official
releases.

As documentation for a particular Django release is frozen once the
version has been released officially, unless some security update
forces a change to some document, I suggest you to keep translated the
last stable release (0.95, at the moment) and go for it. (more details
here: http://www.djangoproject.com/documentation/documentation/ )

I think that update translations from a release to the next release
should be reasonably smooth and easy.

Paolo


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: mod_python Segmentation fault importing django.utils.feedgenerator.py - with fix

2006-02-16 Thread paolo

Hi, I had problems running Django with mod_python, so I had the
possibility to investigate and obtain some detailed info, which I'd
like to share here.

I'd like to suggest "Expat Causing Apache Crash", which explains
problems caused due to mismatches in the version of the "expat" library
embedded into Python and that linked into Apache, how to verifying if
expat is the problem and finally a resolution.
(http://www.dscpl.com.au/articles/modpython-006.html)

Another reading is mod_python FAQ Entry - mod_python and MySQLDb won't
work together
(http://www.modpython.org/FAQ/faqw.py?req=show&file=faq02.013.htp)

Then, a good way to obtain useful information that can be used to ask
for help is - first of all - check if mod_python works alone, without
involve Django. The procedure is detailed here:
http://www.dscpl.com.au/articles/modpython-001.html.

Again, it's useful to locate which is the problematic module (if it's
true that an imported module causes the crash) that make the
segmentation fault happen. For this I'd like to cite textually the
answer I had on mod_python mailing list (here is the whole thread, in
case anyone would care to read it,
http://www.modpython.org/pipermail/mod_python/2005-December/019647.html):


"Next step then would be to import into the handler of your test code,
the module which you specify needs to be imported in order to make
use of Django. If done in the test handler function, accessing the
test URL will cause it to be imported and if it does crash at that
point
you have confirmed that it is the actual import of the Django stuff
that
is the problem. If that is confirmed, then look internally at Django
and
see what module it imports, and instead of importing the Django top
level module, import what it imports. Gradually reduce the set of
imports
until it stops crashing so as to find the specific module that causes
the
problem. Drop down further into modules and look at their imports as
necessary.

This sort of process of elimination is the only way you are going to
be able to narrow it down. Unless you can determine precisely which
module is the issue, we aren't really going to be able to help."

This is all I gathered around.

HTH, regards


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users
-~--~~~~--~~--~--~---



Re: Help running Django with mod_python

2005-12-02 Thread Paolo

2005/12/2, frank h. <[EMAIL PROTECTED]>:
>
> hej paolo,
> I am on OS X as well, and I had problems with Apache and mod_python.

Hi frank, I'm not running OS X! I looked at django's documentation and
at http://cavedoni.com/2005/django-osx, as you suggested, but even
trying a bunch of different "variations", I've not yet achieved a
working setup. In the meanwhile I'm asking to mod_python's people.

Thanks for help


Re: Help running Django with mod_python

2005-12-02 Thread Paolo

2005/12/1, Bryan Murdock <[EMAIL PROTECTED]>:

> Do you have mod_php running too?  See this:
>
> http://www.modpython.org/pipermail/mod_python/2004-January/014886.html

No mod_php installed! I already checked that (and this faq gives an
explanation about mod_php and mod_python incompatibilities in some
circumstances, http://www.modpython.org/FAQ/faqw.py?req=show&file=faq02.013.htp)

>
> Bryan

Thanks


Re: Help running Django with mod_python

2005-12-02 Thread Paolo

2005/12/1, Afternoon <[EMAIL PROTECTED]>:
> Have you tried adding PythonDebug On to your httpd.conf? Also, I'm
> using SetHandler python-program, no idea if that makes any difference
> though.

Yes, PythonDebug is On, and to increase verbosity LogLevel is set to
value debug.

For mod_python 3.1, it is preferred to use mod_python, as
python-program is the old name (that is still supported). With
mod_python 2.7 instead it is mandatory to use python-program.


Re: Help running Django with mod_python

2005-12-01 Thread Paolo

2005/12/1, Afternoon <[EMAIL PROTECTED]>:
>
> What platform are you building on? Where is your Python? I had to
> define PYTHONHOME = /usr/ in envopts for Apache because I'm running
> OS X and my Python is stock but my Apache comes from the Fink project.
>
> Is there any way that Apache might not be able to find Python such as
> this?

Well, my experiments take place on linux slackware, kernel 2.4.26.
Running a simple mod_python test handler, like the one to test if
mod_python installation has completed succesfully
(http://www.modpython.org/live/current/doc-html/inst-testing.html),
happens without problems. This make me think that
apache/mod_python/python installation is fine and that the problem is
in httpd.conf or in my project.

So I'll post them. This is the relevant part of httpd.conf:

DocumentRoot /home/paolo/projects/django

SetHandler mod_python
PythonHandler django.core.handlers.modpython
PythonPath ['/home/paolo/projects/django']+sys.path
SetEnv DJANGO_SETTINGS_MODULE cardano.settings



and this is urlpatterns:
urlpatterns = patterns('',
(r'^admin/', include('django.contrib.admin.urls.admin')),
)

Project cardano lives in /home/paolo/projects/django

Thanks


Re: Help running Django with mod_python

2005-12-01 Thread Paolo

2005/12/1, Afternoon <[EMAIL PROTECTED]>:
>
>
> On 1 Dec 2005, at 14:29, Paolo wrote:
>
> > [Thu Dec 01 11:07:13 2005] [notice] child pid 15299 exit signal
> > Segmentation fault (11)
>
> Ah, I spent a frustrating few hours wrestling with this error (or one
> like it) last night. Are you using mod_python 3? After building
> mod_python have you fully restarted Apache or just gracefully
> restarted it?

Hi Afternoon, not only I have restarted Apache after building
mod_python (3.1.4), I also have updated it from version 2.0.54 to
2.0.55, but nothing has changed.


Help running Django with mod_python

2005-12-01 Thread Paolo

I'm trying to setup Django with Apache and mod_python.

I have followed the procedure described in the document "how to use
Django with mod_python", but I can't obtain a working basic (single
Django installation on the same Apache) environment, because Apache
unexpectedly crashes at each request.

It happens that a blank page (no response) is returned to the browser
when a request is made.

These strings appear in error_log:
[Thu Dec 01 11:03:47 2005] [notice] mod_python: Creating 32 session
mutexes based on 150 max processes and 0 max threads.
[Thu Dec 01 11:03:47 2005] [notice] Apache/2.0.55 (Unix)
mod_python/3.1.4 Python/2.3.5 configured -- resuming normal operations
[Thu Dec 01 11:07:12 2005] [notice] mod_python: (Re)importing module
'django.core.handlers.modpython'
[Thu Dec 01 11:07:13 2005] [notice] child pid 15299 exit signal
Segmentation fault (11)

Looking around for some pointer I have discovered that some
incompatibilities might generate this problem. It is the case (but
there are others) of embedded Python's version of expat and Apache's
linked version of expat that differ. However in my setup they are the
same.

As I have spent a lot of time on this without results, and the cause
of this bad behavior maybe is something simple for an experienced
user, I'd really love some help.

Thanks in advance!


Re: Standalone template language

2005-11-24 Thread paolo

The first import in django/core/template/__init__.py wants to obtain
DEFAULT_CHARSET and TEMPLATE_DEBUG from the settings file. Being
DJANGO_SETTINGS_MODULE not set, an EnvironmentError exception is
raised. If you handle this exception with try/except, defining yourself
default values for DEFAULT_CHARSET and TEMPLATE_DEBUG, you have found a
(rude) way to change the intended behaviour.

Of course, as already said, this is not an acceptable solution,
because: 1) in this way the default charset and template debug settings
are hardcoded; 2) still worst, you can't extend the template language
with your tags and filters, as their definitions live in a package at
the same level as models, views, etc., and so it is coupled to an
application.

Perhaps, a valid solution would require changes at a deeper level!

Thanks for your attention.



Re: Standalone template language

2005-11-24 Thread Paolo

2005/11/24, Cheng Zhang <[EMAIL PROTECTED]>:
>
> It's possible, based on my limited knowledge of Django. I think such
> usage is more like using a Python library.
> In your case, you need to set the environment variable
> DJANGO_SETTINGS_MODULE as shown in tutorial 1, e.g. export
> DJANGO_SETTINGS_MODULE=myproject.settings

Hi Cheng Zhang, perhaps my request wasn't clear enough. I'd like to
use Django's template language in an application made in plain Python.
Django doesn't appear at all in this scenario, so setting
DJANGO_SETTINGS_MODULE has not much sense, because I'm not working
with a Django project.

Today I've been able to use the template language on its own with a
simple "trick". My solution works well enough for my modest needings
(though it is far from being an acceptable solution), but probably it
will present side effects in some situation and *for sure* will limit
the flexibility of Django's template system (i.e., it is not possible
to define custom filters/tags)

I hope some Django's developer or hacker will hear my voice and give
some help ;-)

Thanks for your attention.


Standalone template language

2005-11-24 Thread paolo

I wonder if it's possible to use Django's template engine outside of
Django.

I tried to import Template from django.core.template but Python
interpreter complains about undefined DJANGO_SETTINGS_MODULE.

Thanks



Re: Help using POST to pass values

2005-10-25 Thread paolo

It works now! Sorry but I didn't find that page.

Thanks a lot, Sune.



Help using POST to pass values

2005-10-25 Thread paolo

Hi, since today I've used the admin interface as a frontend for my
applications' data, but now I'm trying to do a simple query interface
by my own. I need some help figuring how to pass values through
requests.

Actually the frontend consists of two pages: page A contains a form
where the user may tune some parameters used for specialized data
extraction, and page B that presents these data.

The form in page A specifies "POST" as method and 'page B' as action,
so I'd expect that the request object is passed from page A to page B
and finally, request.POST contains a dictionary of keys/values. If I
have correctly interpreted the docs, this should happen because when
the user submits the form, there is an URLconf that intercepts calls to
page B (triggered by form submission) and call the view for page B.
This view receives the request as a parameter, optionally does some
computation and then rolls the context that will be passed to the
template (with the request object inside).

However this doesn't happen. Looking at the request I can see a
DjangoRequest object with POST: {} and 'REQUEST_METHOD': 'GET', while
I'm expecting to see the dictionary with my keys/values in POST and
'REQUEST_METHOD': 'POST'.

Using GET as method instead works fine. Passing values using session
works fine. Change the action from page B to page A itself (keeping
POST as method) also work. If it could be an option to use GET, it
seems a non-sense to move the machinery of sessions for such a simple
task.

Would you please help me to clarify how things work and what I have
missed?

If you may find it useful, there is a simplified version of Python
scripts involved at http://pastebin.com/405021

Thanks



About _post_save

2005-10-06 Thread paolo

Hi!
I'm trying to use _post_save hook. How to distinguish if an object has
been saved for the first time or if has been updated, and so make
_post_save behave differently in the two situations?

TIA,
paolo



Re: Duplicate objects

2005-09-22 Thread paolo

[EMAIL PROTECTED] ha scritto:

> Hi
>
> I'm bing a bit slow I think. All i want to do is get an object and
> create a new entry that is a duplicate of it.
>

The parameter save_as should do what your need. Model reference
document offers more details.



Re: error: (10053, 'Software caused connection abort')

2005-09-10 Thread paolo

Eugene Lazutkin wrote:
[cut[
> error: (10053, 'Software caused connection abort')

"This error can occur when the local network system aborts a
connection, such as when Winsock closes an established connection after
data retransmission fails (receiver never acknowledges data sent on a
datastream socket).", Django is not the source of the problem.
(http://www.sockets.com/err_lst1.htm#WSAECONNABORTED)

There are a lot of people asking for help on the net about this(google
for it), and actually it seems that a "standard" remedy doesn't exist.

HTH



Need help in structuring db for my app

2005-09-07 Thread paolo

Hi, finally I'm able to provide a precise description of what I'd like
to realize with Django.
Considering that I'm moving my first steps in the relational world and
considering the complexity of the project, I would be glad to receive
some help to figure how to structure the database.

I know that this kind of request can be considered semi-OT. If you
think so, please, provide a better place to ask if you can (forum,
mailing list, whatever).

I need to realize a tool to create configurations, collection of
components. When customers ask for some configuration I can generate it
using the awesome Django and keep them stored in a database for future
consultations/statistics. Once they are in, I can do a lot of
delightful things, like generate pdf for printing and more (but it's
too early for these dreams ;-)

Not yet said but implicit, each configuration is associated to a
particular customer.
Components are organized in categories, and actually it doesn't matter
to handle hierarchical categories. It is however important that
components are kept in separated categories mostly for (future)
presentation purposes: in this way I can choose components from many
specific lists instead than from a long list containing the whole mixed
components.

Some further details:
* in a configuration multiple components belonging to the same
categories may appear
* all the components have a set of common attributes: a name, a
description and a price. Other components extend this behaviour adding
some specific properties (example, hard disks have a size, monitor have
a resolution and a max frequency so on)
* it is required that each configuration is *stored*, I mean: when I
change the price of some product already present in some configuration,
I don't want that the price inside the configuration is changed.


I'd really really appreciate at least some comments :-) (but please,
possibly not about my mental disorders!)

Thanks for reading,
paolo



Different fieldsets for the same fields in admin?

2005-08-26 Thread paolo

Hi, I'd like to know if it is possible to have different fieldsets for
the same fields, subdivided by some criterion.
For example, the screen for adding a recipe referring to the following
model results in 5 "generic" (not grouped by any particular criterion)
fields. I'd like that for each category a list of available ingredients
is presented, subdivided in different fieldsets.
I don't know if it can be done in this way, but probably using the
fields option for meta.Admin() might help to clarify what I need.
Something like like this:

admin = meta.Admin(
  fields = (
  ('category1', {
  'classes': 'collapse',
  'fields': ('name', 'short_desc', 'long_desc')
  }),
  ('category2', {
  'classes': 'collapse',
  'fields' : ('name', 'short_desc', 'long_desc')
  }),
  ('category_n', {
  'classes': 'collapse',
  'fields' : ('name', 'short_desc', 'long_desc')
  }),
  ),
)

This is the model:

# Stripped off the details
class Recipe(meta.Model):
name = meta.CharField('Name', maxlength=128)
class META:
admin = meta.Admin()

class Ing_category(meta.Model):
name = meta.CharField('Name', maxlength=128)
class META:
admin = meta.Admin()

class Ingredient(meta.Model):
name = meta.CharField('Name', maxlength=128)
short_desc = meta.TextField('Short desc')
long_desc = meta.TextField('Long desc')
category = meta.ForeignKey(Ing_category, core=True)
class META:
admin = meta.Admin()

class Intermediary(meta.Model):
ing = meta.ForeignKey(Ingredient)
quantity = meta.IntegerField("Quantity")
recipe = meta.ForeignKey(Recipe, edit_inline=True, num_in_admin=5)
class META:
verbose_name = "Ingredient list"


Thanks for your patience...
paolo



Re: Show auxiliary data in admin interface for a model

2005-08-26 Thread paolo

I realized that it was enough to have a string containing both the
component name and the price. In this way in the admin page for adding
a new configuration (that shows the components list too, due to
edit_inline=True) will be shown a combobox with, as said, the string
'comp name -- price' obtained via __repr__.

Initially instead I though that a tuple could keep the two values
separated, so that they could be used in different contexts. For
example, and it was my initial question, to have in the admin a listbox
'Component' filled with the name, and a dummy-display-box 'Price'
filled with the price.

Sorry for the confusion, I'm new to Django and I'm still trying to
figure how the things work together.



Show auxiliary data in admin interface for a model

2005-08-26 Thread paolo

Using the following model it is possible to add an arbitrary number of
components (with a quantity) to configurations.

class Configuration(meta.Model):
pass  fields definition.
class META:
pass  meta definition

class Component(meta.Model):
code = meta.CharField('Code', maxlength=64, unique=True)
full_desc = meta.TextField('Description', blank=True)
price = meta.FloatField('Price', max_digits=6, decimal_places=2)

class META:
admin = meta.Admin()

def __repr__(self):
return self.code

class Intermediary(meta.Model):
component = meta.ForeignKey(Component, blank=True, core=True)
quantity = meta.PositiveIntegerField('Quantity', blank=True)
estimate = meta.ForeignKey(Configuration, edit_inline=True)

I'd like that once a user select or change a component from the
component's listbox, its price appears somewhere. I'd like to avoid the
javascript solution, as probably it wouldn't be trivial and I don't
know javascript well.. So I thought to change __repr__ to return a
tuple containing self.code and self.price, but some problems arise.

Can you suggest some alternatives?

Thanks,
paolo



Re: Help me checking this model.. (tb included)

2005-08-22 Thread paolo

Hi Brant, thanks for your comment. Effectively the model was wrong and
your fix has been very useful.

This is the working version:

from django.core import meta
class Ingredient(meta.Model):
fields = (
meta.CharField('name', 'Name', maxlength=128),
meta.TextField('description', 'Description', blank=True),
)

admin = meta.Admin()

def __repr__(self):
return self.name

class Recipe(meta.Model):
fields = (
meta.CharField('name', 'Name', maxlength= 128, unique=True),
meta.TextField('description', 'Description')
)

admin = meta.Admin()

def __repr__(self):
return self.name

class Intermediary(meta.Model):
fields = (
meta.ForeignKey(Ingredient, blank=True, core=True),
meta.PositiveIntegerField('quantity', 'Quantity', blank=True),
meta.ForeignKey(Recipe, edit_inline=True)
)

I also have changed the order of classes definition. In the previous
model it was Ingredient, Intermediary, Recipe: adding inside
Intermediary a reference to Recipes, it gave: NameError: name 'Recipe'
is not defined

So the model now defines classes in this order: Ingredient, Recipes,
Intermediary and all works fine.

My question is.. if order matters, is there the possibility, expecially
in complex models, to reach a "deadlock" condition?

Thanks,
paolo



Help me checking this model.. (tb included)

2005-08-20 Thread paolo

This is my solution to add to a recipe an arbitrary number of
ingredients, each of them with a quantity specified.

from django.core import meta
class Ingredient(meta.Model):
fields = (
meta.CharField('name', 'Name', maxlength=128),
meta.TextField('description', 'Description', blank=True),
)

admin = meta.Admin()

def __repr__(self):
return self.name

class Intermediary(meta.Model):
fields = (
meta.ForeignKey(Ingredient),
meta.PositiveIntegerField('quantity', 'Quantity', blank=True)
)

class Recipe(meta.Model):
fields = (
meta.CharField('name', 'Name', maxlength= 128, unique=True),
meta.TextField('description', 'Description'),
meta.ForeignKey(Intermediary, to_field='id', edit_inline=True)
)

admin = meta.Admin()

def __repr__(self):
return self.name


Adding new ingredients works fine.. while when trying to add a new
recipe it gives:

There's been an error:

Traceback (most recent call last):

  File
"/usr/local/lib/python2.3/site-packages/django/core/handlers/base.py",
line 64, in get_response
response = callback(request, **param_dict)

  File
"/usr/local/lib/python2.3/site-packages/django/views/admin/main.py",
line 810, in add_stage
elif not f.blank and ((isinstance(f.rel, meta.ManyToOne) and not
f.rel.raw_id_admin) or f.choices) and len(manipulator[f.name].choices)
== 2:

  File
"/usr/local/lib/python2.3/site-packages/django/core/formfields.py",
line 26, in __getitem__
    raise KeyError, "Field %s not found" % field_name

KeyError: 'Field intermediary_id not found'


What's wrong with my implementation?

Thanks,
paolo



Re: Set arguments in model dinamically

2005-08-18 Thread paolo

Adrian Holovaty ha scritto:

> On 8/17/05, paolo <[EMAIL PROTECTED]> wrote:
[cut]
>
> For customization like this, you can write some custom JavaScript that
> alters your form in that way. Then just add the path to your
> JavaScript file to the "admin.js" list in your model.
[cut]

Hi Adrian, perhaps I've not been so accurate in my explanation, sorry.
My request was slightly different.., for "dinamically" I meant to have
the possibility to set some value (automatically) depending on some
other value. For me it would be enough something like:

class Customer(meta.Model):
fields = (
meta.BooleanField('blocked', 'Blocked', default=False),
meta.CharField('title', 'Title', maxlength=128,
editable=self.blocked)
)

This is however not possible, and validator gives:

Unhandled exception in thread started by 
Traceback (most recent call last):
  File
"/usr/local/lib/python2.3/site-packages/django/core/management.py",
line 556, in inner_run
validate()
  File
"/usr/local/lib/python2.3/site-packages/django/core/management.py",
line 497, in validate
import django.models
  File
"/usr/local/lib/python2.3/site-packages/django/models/__init__.py",
line 13, in ?
modules = meta.get_installed_model_modules(__all__)
  File
"/usr/local/lib/python2.3/site-packages/django/core/meta/__init__.py",
line 103, in get_installed_model_modules
mod = __import__('django.models.%s' % submodule, '', '', [''])
  File
"/home/paolo/projects/django/cardano/apps/estimator/models/estimator.py",
line 74, in ?
class Customer(meta.Model):
  File
"/home/paolo/projects/django/cardano/apps/estimator/models/estimator.py",
line 79, in Customer
fields = (
NameError: name 'self' is not defined

Any pointer?

Thanks again.



Set arguments in model dinamically

2005-08-17 Thread paolo

The model I'm using for 'customers' has a BooleanField called
'blocked'. I'd like that when blocked is True other fields won't be
shown, or eventually won't be editable.

How to obtain this?

Thanks



Split model's classes in more modules

2005-08-17 Thread paolo

I thought it was a valid option to fragment models' classes in more
python modules, and import them inside
project/apps/application/models/application.py
However when i try django-admin.py sql application I get a traceback
(http://django.pastebin.com/339033)

Do you know what I'm doing wrong?

Thanks