Re: GeoDjango: Completely Overwhelmed

2008-04-15 Thread Nathaniel Whiteinge

I'm really new to GeoDjango myself, and I agree that jumping right in
is a bit of a shock. Hopefully someone more knowledgeable will also
pipe-up, but I think I can start you off in the right direction.

On Apr 14, 9:43 pm, Alex Ezell <[EMAIL PROTECTED]> wrote:
> The system would then show them trips which have start, end, or both
> points in common with the locations they have entered in the search.
> "In common" being defined as within a radius of say 100 miles or so.

If I understand your question correctly, you're only interested in the
start and end points and not the points along that line between the
two. So define a regular model with a ``PointField`` [1] to hold the
lat/long for a location and make sure to use a ``GeoManager`` [2] for
that model. I've been using GeoPy [3] to obtain lat/long from
addresses and zipcodes. If you need to do complex lookups that you
would normally use a ``Q`` object for, make sure to use a ``GeoQ``
object [4] instead.

Once you've done that and have a few items in your database you can
query proximity pretty easily [5]. You can search for other points in
the database that are within a certain radius using a regular queryset
filter like
``yourmodel.objects.filter(point__distance_lte=(STARTINGPOINT,
D(mi=100))``. If you want to return the distance between your starting
point and a bunch of objects use the ``distance()`` manager method
[6]. Also, I've found the built-in Distance measure functions [7]
really helpful for doing conversions.

.. [1] http://code.djangoproject.com/wiki/GeoDjangoModelAPI#FieldTypes
.. [2] http://code.djangoproject.com/wiki/GeoDjangoModelAPI#GeoManager
.. [3] http://exogen.case.edu/projects/geopy/
.. [4] from django.contrib.gis.db.models import GeoQ
.. [5] http://code.djangoproject.com/wiki/GeoDjangoDatabaseAPI#DistanceLookups
.. [6] http://code.djangoproject.com/wiki/GeoDjangoDatabaseAPI#distance
.. [7] http://code.djangoproject.com/wiki/GeoDjangoExtras#Measure

So I just mentioned three completely different parts of GeoDjango all
named "distance", hopefully I didn't confuse you even more!  :-P

Good luck.
- whiteinge
--~--~-~--~~~---~--~~
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: Per user settings and records in the admin views

2008-04-15 Thread Dmitry Rubinstein
That's great news! Thank you, Eric! I will be waiting for the merge then.

On Tue, Apr 15, 2008 at 9:51 AM, Eric Abrahamsen <[EMAIL PROTECTED]> wrote:

>
> There's a branch of Django called NewForms Admin (
> http://code.djangoproject.com/wiki/NewformsAdminBranch
> ) which will make it much easier to do what you're trying to do. From
> murmurings on this list it seems that branch will be merged into trunk
> before too long (in fact, there's a distinct whiff of 1.0 on the air
> these days), so it's not worth writing your own patches. Either switch
> to the nf-admin branch now, if you're in a hurry, or wait until the
> branch is merged.
>
> Yrs,
> Eric
>
>
> On Apr 15, 2008, at 2:41 PM, dimrub wrote:
>
> >
> > (I will continue talking to myself here for a while)
> >
> > So, I've located the key passage in the django book:
> >
> > == quote ==
> > Another implication is that the permission system, while powerful, has
> > no support for limiting access on a per-object basis as of this
> > writing. If you trust someone to edit his or her own stories, you
> > trust that user not to edit anyone else's stories without permission.
> > == end quote ==
> >
> > To the best of my understanding, the book tells me "Indeed, there is
> > no way to do what you want to do, and there is a reason for it".
> > However, it is an absolute must for my application, and I wouldn't
> > want to give up on Django and its admin interface because of a small
> > issue like this. Hence, a question: suppose I provide a patch that
> > solves this problem (for example, a new field in the models class that
> > is called, say, filter_by_user, and whose value is the name of the
> > field which is a foreign key into the User table, and a corresponding
> > code in the admin views that filters by this field). Is this patch
> > likely to be excepted into the django's main version tree? If not, I
> > will not bother (the solution above works, even if it's a kludge).
> >
> > >
>
>
> >
>


-- 
Vale,
Dmitry Rubinstein

--~--~-~--~~~---~--~~
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: Application Concepts

2008-04-15 Thread andy baxter

James Bennett wrote:
> On Fri, Apr 11, 2008 at 1:09 PM, andy baxter
> <[EMAIL PROTECTED]> wrote:
>   
>>  What /should/ be inside the project folder?
>> 
>
> I often get severely flamed for saying this, but:
>
> I very rarely have a "project folder". All it is is a place to stick a
> settings file and a root URLConf module, both of which are just plain
> old Python files which can live anywhere you can import from. So most
> of the time I don't bother creating a folder just to do that; I only
> do so when I have groups of configuration files that I want to
> organize.
>   
Is there any strong reason why you /shouldn't/ do it the way in the 
tutorial - e.g. security? Or is this just your preference?

--~--~-~--~~~---~--~~
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: Application Concepts

2008-04-15 Thread Malcolm Tredinnick


On Tue, 2008-04-15 at 08:23 +0100, andy baxter wrote:
> James Bennett wrote:
> > On Fri, Apr 11, 2008 at 1:09 PM, andy baxter
> > <[EMAIL PROTECTED]> wrote:
> >   
> >>  What /should/ be inside the project folder?
> >> 
> >
> > I often get severely flamed for saying this, but:
> >
> > I very rarely have a "project folder". All it is is a place to stick a
> > settings file and a root URLConf module, both of which are just plain
> > old Python files which can live anywhere you can import from. So most
> > of the time I don't bother creating a folder just to do that; I only
> > do so when I have groups of configuration files that I want to
> > organize.
> >   
> Is there any strong reason why you /shouldn't/ do it the way in the 
> tutorial - e.g. security? Or is this just your preference?

No there isn't any reason like that and it is often a matter of
preference. The preference is whether your applications are likely to be
useful in other situations or not.

If you implement your applications as things that don't rely on being
inside a particular project directory, it will be much easier to reuse
them elsewhere.

Are all applications reusable? Probably not. I know I've built a few
projects where the applications were all pretty domain-specific. Now I
might be able to reuse those apps in a similar domain, but I'm not
seeing the immediate reuse right now. Still, it's worth designing them
to be able to operate outside of their original project directory so
that if something does come up, I can reuse them. It doesn't take much
effort up front and it does make things unintentionally easier down the
track. If you don't do this, no harm will come to you. It'll just be a
little harder to lift something from projectA and use it in projectB,
since you'll have a whole bunch of "projectA" directories mentioned in
import statements and the like.

I've rambled further on this topic in the past. See [1] and [2] if
you're interested.

[1]
http://www.pointy-stick.com/blog/2007/11/09/django-tip-developing-without-projects/
[2]
http://www.pointy-stick.com/blog/2007/11/14/django-tips-source-code-filenames/

Regards,
Malcolm



-- 
A clear conscience is usually the sign of a bad memory. 
http://www.pointy-stick.com/blog/


--~--~-~--~~~---~--~~
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: How to extend django.views.generic.date_based to return more "context variables"?

2008-04-15 Thread fizban

On 15 Apr, 00:05, fizban <[EMAIL PROTECTED]> wrote:
>
> I have finally solved my problem re-writing "myview":
>
> def myview(request, **kwargs):
>
>         extra_context = {
>                 'year': kwargs['year'],
>                 'month': kwargs['month'],
>                 'day': kwargs['day']
>         }
>
>         kwargs['extra_context'] = extra_context
>
>         return date_based.object_detail(
>                 request, **kwargs
>         )

Just in case anyone will land on this thread by searching on google or
something:

A better approach is the following (in views.py) since it is reusable
and it won't mess with other extra_context stuff you may pass in your
urlconf pattern.

def _entry_kwargs_helper(extra_context_list, kwarg_dict):
for item in extra_context_list:
kwarg_dict['extra_context'][item] = kwarg_dict[item]

return kwarg_dict


def entry_detail(request, **kwargs):
"""
Simple wrapper for object_detail from django.views.generic.date_based

Adds 'year', 'month' and  'day' to the context so that they can be
used directly
instead of obtaining them with object.|
date:"".
"""

extra_context_list = ('year', 'month', 'day')
kwarg_dict = _entry_kwargs_helper(extra_context_list, kwargs)

return date_based.object_detail(request, **kwarg_dict)

If anyone has a better (more elegant, clean, whatever) approach to
this I'd be glad to learn it :)
--~--~-~--~~~---~--~~
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: Django.cgi on Linux Hosting

2008-04-15 Thread Aldo

Thanks for your help on this Karen,

Its apache returning the 404. So as i suspected the rewrite rules are
not working for some reason. Yes admin is in the urls.
Sure the rewrite rules - rewrites www.musicischarity.com to
www.musicischarity.com/home so it really should be working off the
bat.

Initially i got in touch with my hosting provider to confirm the
rewrite rules were working - which they confirmed. Ive just sent an
email again.



On Apr 14, 3:21 pm, "Karen Tracey" <[EMAIL PROTECTED]> wrote:
> On Mon, Apr 14, 2008 at 3:41 AM, Aldo <[EMAIL PROTECTED]> wrote:
> > Yes, so thats fair enough - it just means that maybe MAYBE the dj
> > script is being called - but when i access it viawww.gfdfdf.com/admin/
> > it gives me a 404
>
> (You've switched 
> fromhttp://www.musicischarity.comtowww.gfdfdf.com
> ?)
>
> So the next step is to figure out if the 404 is coming from Apache or
> Django.  Do you have the admin urls configured for your Django app?  If not,
> then it's expected you'd get a 404 trying to access that url -- I just used
> it as an example of one that might work since I have no idea what your own
> application urls are.
>
> Some ways to determine if the 404 is coming from Apache or Django:
> 1 - appearance -- does it look like the standard Apache "not found" or your
> own 404.html template?
> 2 - turn on DEBUG=True in your settings file and you will see the Django
> debug "page not found" page that includes all the urlpatterns and how the
> one it was handed didn't match any of them, if you are getting to Django
> 3 - the Apache error log will have "File not found" errors listed for
> something ending in "admin" if it is Apache returning the 404, but not if it
> is Django.
> 4 - How long does it take for the 404 to be returned?  Quick means it's
> probably coming from Apache, slow means probably your script is running and
> it's your app/Django that is ultimately returning the 404.  (This config is
> a VERY slow way of running Django, and I'm not sure you will find
> performance acceptable even if/when you get it to work.)
>
> If it is Apache returning the 404 then somehow your rewrite rules are not
> kicking in.  What you list below rewrites everything ending in a slash (you
> did include the trailing slash on the attempt to access admin?) except for
> those that start with cgi-bin or media, plus it rewrites an empty url to a
> Django url of 'home/' (so you'd need a urlpattern for 'home/' in your Django
> config).
>
> If it is Django returning the 404 than the urlpattern configuration is not
> handling the incoming urls as you expect, and you need to fix them.
>
> Karen
>
> > On Apr 11, 4:28 pm, "Karen Tracey" <[EMAIL PROTECTED]> wrote:
> > > On Fri, Apr 11, 2008 at 9:28 AM, Aldo <[EMAIL PROTECTED]> wrote:
>
> > > > Fair point.
>
> > > > My problem is - Initially i created my index.html in the root(DOCUMENT
> > > > ROOT).
> > > > Now I have downloaded Django as described - put it in my root.
> > > > I have created my .htaccess files as
> > > > RewriteEngine on
> > > > RewriteRule ^cgi-bin/ - [L]
> > > > RewriteRule ^media/ - [L]
> > > > RewriteRule ^(.*)(/)$ cgi-bin/dj/$1/
> > > > RewriteRule ^$ cgi-bin/dj/home/
> > > > Ive created the cgi-bin/dj file and gave permissions.
> > > > However when i try to access that file(http://www.musicischarity.com/
> > > > cgi-bin/dj ) it gives me an
> > > > error -  Error 500: Internal Server Error
>
> > > You are not supposed to access the script directly like this.  Rather
> > you
> > > are supposed to use your application's normal urls (e.g.
> >http://www.muicscharity.com/admin/for, say, the Django admin app), and the
> > > RewriteRules convert that to an invocation of your dj script.
>
> > > > (Usually I would have content-type in it - but its not in the
> > > > examples. tried it and still no good.)
> > > > The dj file was edited to contain my own details. paths etc. maybe i
> > > > have them wrong.
> > > > sys.path.append("/hsphere/local/home/musicisc/Django-0.96")
> > > > sys.path.append("/hsphere/local/home/musicisc")
> > > > and
> > > > # Change this to the directory above your site code.
> > > > sys.path.append("/hsphere/local/home/musicisc/Django-0.96/")
> > > > os.chdir("/hsphere/local/home/musicisc/Django-0.96/")
> > > > # Change mysite to the name of your site package
> > > > os.environ['DJANGO_SETTINGS_MODULE'] = 'musicischarity.settings'
> > > > run_with_cgi(django.core.handlers.wsgi.WSGIHandler())
>
> > > > I am not sure anyone will be able to help - but my alternative is to
> > > > give up - ive been working on this for hours.
>
> > > CGI is not at all a recommended way to run Django (see the discussion
> > inhttp://code.djangoproject.com/ticket/2407) but it seems it can be made
> > to
> > > work after a fashion if it's your only option.
>
> > > Karen
>
> > > > On Apr 11, 1:23 pm, "Karen Tracey" <[EMAIL PROTECTED]> wrote:
> > > > > On Fri, Apr 11, 2008 at 6:48 AM, Ald

Re: Two sites, one django project

2008-04-15 Thread David Reynolds


On 10 Apr 2008, at 1:48 pm, Polat Tuzla wrote:
> CSS swapping via settings file seems like good idea. Thanks for that..
> But when it comes storing messages in the database: I don't think it's
> feasible.
> By messages I mean almost all of the strings throughout the source;
> page titles, headers in templates, error messges that are added to
> user message set in views, even "verbose name"s of models.
>
> I think I'll have to use a custom template loader as mentioned above,
> but still in this case, I'll have to duplicate the templates between
> the two sites.
> Thank you all, for the suggestions.


I've done a similar thing for a site in which there are 3 sites  
running from the same database.  Basically using the Sites framework  
and then any model you need has a field of:

site = models.ManyToManyField(Site)

That way you can choose which site(s) each item of content will  
appear on.

We then have one overall settings.py file which defines the common  
settings and then a settings file per site that defines the unique  
parts of each site:

from settings import *

SITE_ID = 1

TEMPLATE_DIRS = (
 os.path.join(PROJECT_DIR, 'templates/site1'),
)

EMAIL_SUBJECT_PREFIX = '[site1] '

Then when you run the development server for each site or deploy the  
site you would pass the specific settings file rather than the common  
one.

I hope that makes some sort of sense.

-- 
David Reynolds
[EMAIL PROTECTED]



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



magic

2008-04-15 Thread playyer6

Can you imitate?
http://www.magicalskills.inihu.com/
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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
-~--~~~~--~~--~--~---



Req. Designation - Jr. Software Engineer(QA)

2008-04-15 Thread ......ADMISSION IN TOP 10 IIT's and ENGINNERING COLLEGE.......

Req. Designation - Jr. Software Engineer(QA)

Company - Allindia Technologies Limited.

Criteria - Any Degree

SALARY - 2.5 to 3.5 lakhs PA.

How to apply -:

1] Click the below link and first complete your profile with your
school and college.
http://www.batchmates.com/MGMhome.asp?refid=1970195&reflink=22635

2] After completing your all details,check your email and confirm your
registration.

3] Finally,go to careers and apply for the above mentioned post(After
completing your profile,you must check your email and confirm your
registration before applying for the given job).
Visit and join
http://www.batchmates.com/MGMhome.asp?refid=1970195&reflink=22635

Pls Note:-
After registering with your school/college,please check your email
immediately.
Check the confirmation key or confirmation link.
Then only apply for the job,otherwise your application will be
rejected.


--~--~-~--~~~---~--~~
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: Troubles with localization

2008-04-15 Thread Boris Ozegovic

On 4/15/08, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote:

>  Also you said you "translated Django". Since Django already has a
>  Croation translation in trunk, does that work properly?

The problem was in PYTHONPATH :-/  Django root wasn't in PYTHONPATH.

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



1 django Project / 2 designs

2008-04-15 Thread martyn

Hi,

I can't solve my problem, I have a site that can contain 2 designs
(summer / winter).
Ideally, My urls are :

http://domain.com/winter/
http://domain.com/summer/

But when I go to
http://domain.com/

I want a default saison (that could be stored in my settings file).
It's not only a different design but it's also a different content
sometimes.

Is this can be done with middleware ? session ?
I don't really know this aspect of django.

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: Slow template

2008-04-15 Thread Sebastian

That seems to be the issue! The rendered static page takes 4.5 seconds
to load! Does anyone know if nested lists render faster than tables?
Or any other tricks to make the actual html rendering go faster?
Something that really annoys me is that the page is is not scrollable
until the last element on the page is rendered. Is that a browser
specific issue or can this be mitigated in some way?  Sorry in advance
for deterring from a Django based discussion.

Thanks for your help
Sebastian

On Apr 15, 12:49 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> It sounds like what's lagging is the rendering - try saving the
> rendered page as html, how long does Firefox/Firefox with Fasterfox
> take to display that? You might also want to try with Fasterfox
> disabled, some of its tweaks might be detrimental if you're querying a
> server on the same machine.
> Good luck!
>
> On Apr 14, 10:28 am, Sebastian <[EMAIL PROTECTED]> wrote:
>
> > Hi all,
>
> > Ive been using Django for a while now, and there has been one page in
> > my application that has been running very slowly no matter what I do.
> > Im using Django 0.96.1.
>
> > The page in question renders approximately 8 tables, each with about
> > 50 rows.
> > This does not seem like the kind of page that should take 5-7 seconds
> > to load
> > (timing from fasterfox).
>
> > The view in question uses three raw-sql queries so I am sure there are
> > no hidden
> > db performance caveats as they have all been profiled and run in the
> > millisecond range. I have inserted a few timing lines which yielded
> > the following:
>
> > The following shows the time elapsed between entering the view's
> > authentication
> > decorator all the way to just before my template rendering code:
>
> > start auth decorator function: 2008-04-14 14:59:18.973822
> > just before template render  : 2008-04-14 14:59:19.869873
>
> > So thats about 1 second.
>
> > The next section relates to the template rendering:
>
> > source, origin = loader.find_template_source('test.html')
> > time taken was: 0:00:00.004000
>
> > template = loader.get_template_from_string(source, origin,
> > 'test.html')
> > time taken was: 0:00:00.004001
>
> > template.render(context)
> > time taken was: 0:00:00.248014
>
> > Thats only a total of at most 2 seconds! I have no idea where the
> > other 4-5 seconds could be coming from. The above samples were taken
> > using the Django runtime server to dispatch my
> > media files, so I can understand that it is a little slower. However,
> > in our
> > production environment (where we us apache (with mod_python) to handle
> > media files)
> > the end result is only slightly better.
>
> > Can anyone think of other areas that might be taking up time?
>
> > Regards,
> > Sebastian
--~--~-~--~~~---~--~~
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: Images and Stylesheets

2008-04-15 Thread Reisswolf

I have followed Doug Van Horn's detailed explanation very closely.  I
have also read the Django documentation page on this particular
topic.  But for some reason, I still cannot get the thing to work.

Here is my situation:  In my /Programming/Python/Django
directory I have created a project called TestProject, and in
TestProject I have an app called TestApp.

Also in TestProject I have Media/JavaScript/MyJSFile.js.  In urls.py I
have the following line:

(r'^media/(?P.*)$', 'django.views.static.serve',
{'document_root': 'Programming/Python/Django/TestProject/
Media'}),

I have also specified '/Programming/Python/Django/
TestProject/Media' as my MEDIA_ROOT and '/media/' as MEDIA_URL in
settings.py.  I have read the documentation very carefully, and I
believe I am doing everything correctly.

I have  in the  tag of my template.  Everything
else in the template gets rendered, but the JavaScript part does not.
In fact, I get an error saying "TestFunc() not defined."  (TestFunc()
is a simple hello-world function defined in MyJSFile.js.)

I am really at my wit's end.  If someone here notices my error, I
would be very grateful to him for pointing it out to me.

*

In case it might be important, I should mention that I am using Fedora
8, and I installed Django through yum:  yum install Django.

*

Thanks in advance for your help,

--~--~-~--~~~---~--~~
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: Images and Stylesheets

2008-04-15 Thread Duke


change the URL config as

from django.conf.urls.defaults import *
import os
ROOT_PATH = os.path.dirname(__file__)

urlpatterns = patterns('',
# Example:
 (r'^hellodojo/', 'hello.views.hellodojo'),
 (r'^site_media/(?P.*)$', 'django.views.static.serve',
{'document_root': ROOT_PATH + '/site_media/'}),

the site_media is the floder contain the image and CSS file
site_media should be in the floder that hold the project.
i had this problem three days a go now i have solved by config the URL

Thanks
Duke
--~--~-~--~~~---~--~~
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: Looping....

2008-04-15 Thread Kenneth Gonsalves


On 15-Apr-08, at 4:06 PM, Duke wrote:

> How to use Loop counter iteration (ie) looping 10 time in Django
> Template language (html)

use 'for'

-- 

regards
kg
http://lawgon.livejournal.com
http://nrcfosshelpline.in/code/




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



Looping....

2008-04-15 Thread Duke

How to use Loop counter iteration (ie) looping 10 time in Django
Template language (html)

bye
Sathish



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



User form input as variable for form action?

2008-04-15 Thread Alex

Hi there, Does anyone know if it's possible to take data input into a
form by a user and use this data as a variable within the same form to
populate a form action? My form is as follows:



  
Date: {{ form.date }}
{% if form.date.errors %}*** {{ form.name.errors|join:", " }}{%
endif %}

The date of the batch to save article
profile to (-MM-DD)



DOI: 10.1038/
{{ form.doi }}
{% if form.doi.errors %}*** {{ form.name.errors|join:", " }}{%
endif %}





Perhaps this is not the right way to go about this though? If anyone
has a solution it would be much appreciated.

Thanks
Alex
--~--~-~--~~~---~--~~
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: Looping....

2008-04-15 Thread Duke

Can u give some example  since for iteration over a array or a
dictionary

Thanks
Duke

--~--~-~--~~~---~--~~
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: Looping....

2008-04-15 Thread Kenneth Gonsalves


On 15-Apr-08, at 4:23 PM, Duke wrote:

> Can u give some example  since for iteration over a array or a
> dictionary

http://www.djangoproject.com/documentation/templates/#for

-- 

regards
kg
http://lawgon.livejournal.com
http://nrcfosshelpline.in/code/




--~--~-~--~~~---~--~~
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: session data or ???

2008-04-15 Thread Horst Gutmann

Sorry if I misunderstood your problem, why don't you simply store the
last_login somewhere in a userprofile? Since -- judging from the name
-- it should only be altered when the user really logs in, I don't see
the relation with a session there :-/

-- Horst

On Tue, Apr 15, 2008 at 2:05 PM, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> hi all
>
>  please , i would like to ask for a little help. I have few functions
>  stored in my views.py under class Test. When i visit my homepage the
>  urls.py is calling method homepage from views.py as i mentioned before.
>  Here it dig some data as current server time and user agent from
>  webbrowser. Now i need to pass these two details to any other function
>  when the function is called.  I read all docs about session, cache and
>  others, but still did not found an answer.
>  I also tried to store these details to session with
>
>  s = SessionStore(session_key='2b2289a188b44ad18c35e113ac6ceead')
>  s['last_login'] = datetime.datetime.now()
>  s.save()
>
>  and later call it. It saved it but with different session_key.
>  So back to the first problem. Please how can i pass some data from one
>  method to all methods.
>
>  thank you very much for helping me
>  pavel
>
>  >
>

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



session data or ???

2008-04-15 Thread [EMAIL PROTECTED]

hi all

please , i would like to ask for a little help. I have few functions 
stored in my views.py under class Test. When i visit my homepage the 
urls.py is calling method homepage from views.py as i mentioned before. 
Here it dig some data as current server time and user agent from 
webbrowser. Now i need to pass these two details to any other function 
when the function is called.  I read all docs about session, cache and 
others, but still did not found an answer.
I also tried to store these details to session with

s = SessionStore(session_key='2b2289a188b44ad18c35e113ac6ceead')
s['last_login'] = datetime.datetime.now()
s.save()

and later call it. It saved it but with different session_key.
So back to the first problem. Please how can i pass some data from one 
method to all methods.

thank you very much for helping me
pavel

--~--~-~--~~~---~--~~
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: session data or ???

2008-04-15 Thread [EMAIL PROTECTED]

hi Horst

the last_login is an example from documentation. My problems are, that 
when i save something to the session(as current date, or user agent) 
with some key, and then look to database from terminal, the key is 
different.

The second problem is, that i cannot find a way how to pass some data 
from one function to all other functions.

thank you
pavel

Horst Gutmann wrote:
> Sorry if I misunderstood your problem, why don't you simply store the
> last_login somewhere in a userprofile? Since -- judging from the name
> -- it should only be altered when the user really logs in, I don't see
> the relation with a session there :-/
>
> -- Horst
>
> On Tue, Apr 15, 2008 at 2:05 PM, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>   
>> hi all
>>
>>  please , i would like to ask for a little help. I have few functions
>>  stored in my views.py under class Test. When i visit my homepage the
>>  urls.py is calling method homepage from views.py as i mentioned before.
>>  Here it dig some data as current server time and user agent from
>>  webbrowser. Now i need to pass these two details to any other function
>>  when the function is called.  I read all docs about session, cache and
>>  others, but still did not found an answer.
>>  I also tried to store these details to session with
>>
>>  s = SessionStore(session_key='2b2289a188b44ad18c35e113ac6ceead')
>>  s['last_login'] = datetime.datetime.now()
>>  s.save()
>>
>>  and later call it. It saved it but with different session_key.
>>  So back to the first problem. Please how can i pass some data from one
>>  method to all methods.
>>
>>  thank you very much for helping me
>>  pavel
>>
>>  >
>>
>> 
>
> >
>   


--~--~-~--~~~---~--~~
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: Images and Stylesheets

2008-04-15 Thread Reisswolf

Hi,

Sorry to bother everyone again, but the suggestion above is not
working either.

Actually, I fail to see why the ROOT_PATH suggestion would work when
hard-coding the path document_root is not working.  But that could
just as well be due to my ignorance.

I have tried the ROOT_PATH suggestion.  I have tried everything else I
could think of.  If anyone has any more suggestions, I would be very
grateful.

--~--~-~--~~~---~--~~
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: session data or ???

2008-04-15 Thread wkn


I think the current documentation and implementation of the
SessionStore is not correct. I had some problems with it yesterday as
well. I eventually solved it differently and without a session.

However if you just want to access a session from across different
views you can just use the 'request.session' dictionary. No need for
using the SessionStore.

But like Horst said try to figure out if you really need to use a
session in the first place.

Wim




On Apr 15, 2:05 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> hi all
>
> please , i would like to ask for a little help. I have few functions
> stored in my views.py under class Test. When i visit my homepage the
> urls.py is calling method homepage from views.py as i mentioned before.
> Here it dig some data as current server time and user agent from
> webbrowser. Now i need to pass these two details to any other function
> when the function is called.  I read all docs about session, cache and
> others, but still did not found an answer.
> I also tried to store these details to session with
>
> s = SessionStore(session_key='2b2289a188b44ad18c35e113ac6ceead')
> s['last_login'] = datetime.datetime.now()
> s.save()
>
> and later call it. It saved it but with different session_key.
> So back to the first problem. Please how can i pass some data from one
> method to all methods.
>
> thank you very much for helping me
> pavel
--~--~-~--~~~---~--~~
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: session data or ???

2008-04-15 Thread Horst Gutmann

Why do you want to manipulate just a specific session that might not
even be an existing sesion anymore? And for what reason do you want to
give other views the same data as the last view that's been used? To
me this sounds just like using a normal session (as provided by
request.session) ...

Could you perhaps tell a few more details about what you want to
achieve and for what reason? :-)

-- Horst

On Tue, Apr 15, 2008 at 2:19 PM, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> hi Horst
>
>  the last_login is an example from documentation. My problems are, that
>  when i save something to the session(as current date, or user agent)
>  with some key, and then look to database from terminal, the key is
>  different.
>
>  The second problem is, that i cannot find a way how to pass some data
>  from one function to all other functions.
>
>  thank you
>  pavel
>
>
>
>  Horst Gutmann wrote:
>  > Sorry if I misunderstood your problem, why don't you simply store the
>  > last_login somewhere in a userprofile? Since -- judging from the name
>  > -- it should only be altered when the user really logs in, I don't see
>  > the relation with a session there :-/
>  >
>  > -- Horst
>  >
>  > On Tue, Apr 15, 2008 at 2:05 PM, [EMAIL PROTECTED] <[EMAIL PROTECTED]> 
> wrote:
>  >
>  >> hi all
>  >>
>  >>  please , i would like to ask for a little help. I have few functions
>  >>  stored in my views.py under class Test. When i visit my homepage the
>  >>  urls.py is calling method homepage from views.py as i mentioned before.
>  >>  Here it dig some data as current server time and user agent from
>  >>  webbrowser. Now i need to pass these two details to any other function
>  >>  when the function is called.  I read all docs about session, cache and
>  >>  others, but still did not found an answer.
>  >>  I also tried to store these details to session with
>  >>
>  >>  s = SessionStore(session_key='2b2289a188b44ad18c35e113ac6ceead')
>  >>  s['last_login'] = datetime.datetime.now()
>  >>  s.save()
>  >>
>  >>  and later call it. It saved it but with different session_key.
>  >>  So back to the first problem. Please how can i pass some data from one
>  >>  method to all methods.
>  >>
>  >>  thank you very much for helping me
>  >>  pavel
>  >>
>  >>  >
>  >>
>  >>
>  >
>  > >
>  >
>
>
>  >
>

--~--~-~--~~~---~--~~
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: GeoDjango: Completely Overwhelmed

2008-04-15 Thread Alex Ezell

On Tue, Apr 15, 2008 at 2:03 AM, Nathaniel Whiteinge
<[EMAIL PROTECTED]> wrote:
>
>  I'm really new to GeoDjango myself, and I agree that jumping right in
>  is a bit of a shock. Hopefully someone more knowledgeable will also
>  pipe-up, but I think I can start you off in the right direction.
>
>
>  On Apr 14, 9:43 pm, Alex Ezell <[EMAIL PROTECTED]> wrote:
>  > The system would then show them trips which have start, end, or both
>  > points in common with the locations they have entered in the search.
>  > "In common" being defined as within a radius of say 100 miles or so.
>
>  If I understand your question correctly, you're only interested in the
>  start and end points and not the points along that line between the
>  two.

Exactly.

>  So define a regular model with a ``PointField`` [1] to hold the
>  lat/long for a location and make sure to use a ``GeoManager`` [2] for
>  that model.

This is precisely the kind of pointer I was looking for. I've read the
documentation about a PointField, but wasn't sure what the application
was or how it works with the rest. Here's a silly question: I can
mixin these GeoDjango field types with the base field types from
Django, right? So, my model could have DateTimeField, PointField,
CharField etc.?

>  I've been using GeoPy [3] to obtain lat/long from
>  addresses and zipcodes.

Yep, already using GeoPy for geocoding.

>  If you need to do complex lookups that you
>  would normally use a ``Q`` object for, make sure to use a ``GeoQ``
>  object [4] instead.

This is in the docs, I'm sure, but is that GeoQ subclassed from the
"normal" Q object so that it has all the properties of Q combined with
GeoQ?

>  Once you've done that and have a few items in your database you can
>  query proximity pretty easily [5]. You can search for other points in
>  the database that are within a certain radius using a regular queryset
>  filter like
>  ``yourmodel.objects.filter(point__distance_lte=(STARTINGPOINT,
>  D(mi=100))``. If you want to return the distance between your starting
>  point and a bunch of objects use the ``distance()`` manager method
>  [6]. Also, I've found the built-in Distance measure functions [7]
>  really helpful for doing conversions.

This looks like it will be really great. Just to run these filters
instead of the horribly nasty SQL I have right now. It will also make
it easy to add other columns from my

>  So I just mentioned three completely different parts of GeoDjango all
>  named "distance", hopefully I didn't confuse you even more!  :-P

Thanks so much for your response. This is great info for anyone
starting out. I certainly appreciate the specific pointers into the
docs as well. It really helps to have a subset of this stuff to start
to get familiar with.

Thanks again,
Alex

--~--~-~--~~~---~--~~
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: problem installing GeoDjango (ERROR: Testing closing Polygon objects)

2008-04-15 Thread Justin Bronn

Tyler,

> Any thoughts on what is causing the test to fail?

This is because of a bug I reported in the GDAL library (versions
1.4.1 and below):

http://trac.osgeo.org/gdal/ticket/1673

Fortunately, the bug is isolated to a single feature that is not used
by the GeoDjango internals: the `close_rings()` function of Polygon
OGR geometries.  Thus, you should be able to use the rest of GeoDjango
without any problems -- or you may upgrade your version of GDAL if you
want to see all tests pass.

Best Regards,
-Justin
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



sortable table

2008-04-15 Thread Gboro54

Hi everyone...

I was wondering if there is a way to make a table sortable by clicking
in the column top...(i.e) if I have a table with the tops being:
names | place| things, I would like the user to click anywhere in the
box of the title of each column and have it sort the data by that
column...If its clicked again it will reverse the sort. I would also
like to do mulicolumn sorting if possible


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



Error 500 in admin panel

2008-04-15 Thread Mathieu Goeminne

Hi all,

I'm a newbie in Django, and I'have to populate some data using the admin
panel.

While I'm saving a entity, or sometime while I want to see it, Django
raises a 500 error. The default admin entities don't rise any error,
only my entity do it.

I have changed my user permissions (getting all the permissions) but the
errors are not removed.

Any idea?

Thanks for help.

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



filter a form to find if there are any required fields

2008-04-15 Thread per9000

Hi,

I have added a * to required fields. (Some of my forms do not have any
required fields.) I want to do this:


  {% if form|has_req_field %}
  * = Required Field
  {% endif %}

  {# put form here #}



And my filter looks like this:

def has_req_field(value, arg=None):

for field in value.fields:
if field.field.required:
return True

return False

I get the impression that my template truns the form into a string and
then passes the string into my filter function ('str' object has no
attribute 'field').

Is there any way to get the form intact out of the template and into
python?

Or is there a better way to find out if there is at least one required
field of my form.

Thanks!

/Per
--~--~-~--~~~---~--~~
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: Error 500 in admin panel

2008-04-15 Thread Jarek Zgoda

Mathieu Goeminne napisał(a):

> I'm a newbie in Django, and I'have to populate some data using the admin
> panel.
> 
> While I'm saving a entity, or sometime while I want to see it, Django
> raises a 500 error. The default admin entities don't rise any error,
> only my entity do it.
> 
> I have changed my user permissions (getting all the permissions) but the
> errors are not removed.
> 
> Any idea?

You have some error in your code.

-- 
Jarek Zgoda
Skype: jzgoda | GTalk: [EMAIL PROTECTED] | voice: +48228430101

"We read Knuth so you don't have to." (Tim Peters)

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



Adding new language for i18n

2008-04-15 Thread meledictas

Hi

I try to add translation for Thai language. I did following,

1. My environment is Window so I use Window version of xgettext, see
http://gnuwin32.sourceforge.net/packages/gettext.htm
2. Under my application path, I created directory conf/locale.
3. Executed make-messages.py -l th.
4. I can see conf\locale\th\LC_MESSAGES\django.po.
5. I successfully executed make-messages.py -a.
6. Comoiled, compile-messages.py
7. Set LANGUAGE_CODE to "th".
8. Tested by adding trans tag in template (using message I've added
in .po file).
9. Try to force session and cookie language.
10  Nothing is translated.

Note, I tested 'th' for check_for_language(from
django.utils.translation import ), it returns False.

This is code use to override language settings.

lang_code = 'th'
if hasattr(request, 'session'):
request.session['django_language'] = lang_code
else:
response.set_cookie(settings.LANGUAGE_COOKIE_NAME,
lang_code)

Did I do something wrong?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: session data or ???

2008-04-15 Thread [EMAIL PROTECTED]

ok i will try to explain.

when i or whoever visit homepage, the method from views.py generates 
some data, for example
info about operating system or whatever, just some value stored in 
variable or dict, let's call it
info = {'system': 'unix'}

later when user is browsing the site, he/she visits some other part of 
site when some other method is called. And i need to access this variable.
So does it mean that in every method where i need to work with this 
variable i have to save it to sessions in first method and use 
request.session in method where i need to work with this variable, or is 
there some better way how to pass this variable?
Please feel free to show me some code examples.
thank you
pavel

Horst Gutmann wrote:
> Why do you want to manipulate just a specific session that might not
> even be an existing sesion anymore? And for what reason do you want to
> give other views the same data as the last view that's been used? To
> me this sounds just like using a normal session (as provided by
> request.session) ...
>
> Could you perhaps tell a few more details about what you want to
> achieve and for what reason? :-)
>
> -- Horst
>
> On Tue, Apr 15, 2008 at 2:19 PM, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>   
>> hi Horst
>>
>>  the last_login is an example from documentation. My problems are, that
>>  when i save something to the session(as current date, or user agent)
>>  with some key, and then look to database from terminal, the key is
>>  different.
>>
>>  The second problem is, that i cannot find a way how to pass some data
>>  from one function to all other functions.
>>
>>  thank you
>>  pavel
>>
>>
>>
>>  Horst Gutmann wrote:
>>  > Sorry if I misunderstood your problem, why don't you simply store the
>>  > last_login somewhere in a userprofile? Since -- judging from the name
>>  > -- it should only be altered when the user really logs in, I don't see
>>  > the relation with a session there :-/
>>  >
>>  > -- Horst
>>  >
>>  > On Tue, Apr 15, 2008 at 2:05 PM, [EMAIL PROTECTED] <[EMAIL PROTECTED]> 
>> wrote:
>>  >
>>  >> hi all
>>  >>
>>  >>  please , i would like to ask for a little help. I have few functions
>>  >>  stored in my views.py under class Test. When i visit my homepage the
>>  >>  urls.py is calling method homepage from views.py as i mentioned before.
>>  >>  Here it dig some data as current server time and user agent from
>>  >>  webbrowser. Now i need to pass these two details to any other function
>>  >>  when the function is called.  I read all docs about session, cache and
>>  >>  others, but still did not found an answer.
>>  >>  I also tried to store these details to session with
>>  >>
>>  >>  s = SessionStore(session_key='2b2289a188b44ad18c35e113ac6ceead')
>>  >>  s['last_login'] = datetime.datetime.now()
>>  >>  s.save()
>>  >>
>>  >>  and later call it. It saved it but with different session_key.
>>  >>  So back to the first problem. Please how can i pass some data from one
>>  >>  method to all methods.
>>  >>
>>  >>  thank you very much for helping me
>>  >>  pavel
>>  >>
>>  >>  >
>>  >>
>>  >>
>>  >
>>  > >
>>  >
>>
>>
>>  >
>>
>> 
>
> >
>   


--~--~-~--~~~---~--~~
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: GeoDjango: Completely Overwhelmed

2008-04-15 Thread Justin Bronn

> This is precisely the kind of pointer I was looking for. I've read the
> documentation about a PointField, but wasn't sure what the application
> was or how it works with the rest. Here's a silly question: I can
> mixin theseGeoDjangofield types with the base field types from
> Django, right? So, my model could have DateTimeField, PointField,
> CharField etc.?
>

Most definitely.  GeoDjango would honestly suck if you couldn't use
Django's other fields in the same model.

> This is in the docs, I'm sure, but is that GeoQ subclassed from the
> "normal" Q object so that it has all the properties of Q combined with
> GeoQ?
>

Yes, `GeoQ` is subclassed from `Q` -- basically it is overridden to
use `GeoQuerySet` instead of `QuerySet` so that the OR'ing and AND'ing
of conditionals will work with geometry fields.   When queryset-
refactor is merged to trunk, `GeoQ` will no longer be required (but
will still be around for backward-compatibility).

> Thanks so much for your response. This is great info for anyone
> starting out. I certainly appreciate the specific pointers into the
> docs as well. It really helps to have a subset of this stuff to start
> to get familiar with.
>

Yes, I agree -- kudos to Nathaniel for providing a robust and
informative response to your original inquiry.

Best Regards,
-Justin
--~--~-~--~~~---~--~~
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: sortable table

2008-04-15 Thread Steingrim Dovland

On Tue, Apr 15, 2008 at 2:56 PM, Gboro54 <[EMAIL PROTECTED]> wrote:
>  I was wondering if there is a way to make a table sortable by clicking
>  in the column top..

It's quite easy to achieve this with jQuery[1] and the tablesorter
plugin[2] -- no Django involved, just javascript.

[1]: http://jquery.com/
[2]: http://tablesorter.com/docs/

-- 
Steingrim Dovland. Oslo, Norway.
This behaviour is by design.

--~--~-~--~~~---~--~~
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: sortable table

2008-04-15 Thread Gboro54

can i write the javascript right into a text file and put it into my
folder where I am storeing templetes? If so do I still make it into an
html file or not?

On Apr 15, 9:10 am, "Steingrim Dovland" <[EMAIL PROTECTED]>
wrote:
> On Tue, Apr 15, 2008 at 2:56 PM, Gboro54 <[EMAIL PROTECTED]> wrote:
> >  I was wondering if there is a way to make a table sortable by clicking
> >  in the column top..
>
> It's quite easy to achieve this with jQuery[1] and the tablesorter
> plugin[2] -- no Django involved, just javascript.
>
> [1]:http://jquery.com/
> [2]:http://tablesorter.com/docs/
>
> --
> Steingrim Dovland. Oslo, Norway.
> This behaviour is by design.
--~--~-~--~~~---~--~~
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: session data or ???

2008-04-15 Thread Horst Gutmann

Well, depending on how you handle this "variable" you have multiple options:

1. Store it into the session using request.session['info'] = info and
retrieve it later from the session when you want to use this data.
2. If you also want to keep this "choice" permanently associated with
the user, I'd store it in the user's profile

IMO these are the only options you have and they are not really bad
ones. Naturally you could also simply pass that choice using GET
parameters, but again: This depends on how you want to use this value.

-- Horst

On Tue, Apr 15, 2008 at 3:09 PM, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> ok i will try to explain.
>
>  when i or whoever visit homepage, the method from views.py generates
>  some data, for example
>  info about operating system or whatever, just some value stored in
>  variable or dict, let's call it
>  info = {'system': 'unix'}
>
>  later when user is browsing the site, he/she visits some other part of
>  site when some other method is called. And i need to access this variable.
>  So does it mean that in every method where i need to work with this
>  variable i have to save it to sessions in first method and use
>  request.session in method where i need to work with this variable, or is
>  there some better way how to pass this variable?
>  Please feel free to show me some code examples.
>
>
> thank you
>  pavel
>
>  Horst Gutmann wrote:
>  > Why do you want to manipulate just a specific session that might not
>  > even be an existing sesion anymore? And for what reason do you want to
>  > give other views the same data as the last view that's been used? To
>  > me this sounds just like using a normal session (as provided by
>  > request.session) ...
>  >
>  > Could you perhaps tell a few more details about what you want to
>  > achieve and for what reason? :-)
>  >
>  > -- Horst
>  >
>  > On Tue, Apr 15, 2008 at 2:19 PM, [EMAIL PROTECTED] <[EMAIL PROTECTED]> 
> wrote:
>  >
>  >> hi Horst
>  >>
>  >>  the last_login is an example from documentation. My problems are, that
>  >>  when i save something to the session(as current date, or user agent)
>  >>  with some key, and then look to database from terminal, the key is
>  >>  different.
>  >>
>  >>  The second problem is, that i cannot find a way how to pass some data
>  >>  from one function to all other functions.
>  >>
>  >>  thank you
>  >>  pavel
>  >>
>  >>
>  >>
>  >>  Horst Gutmann wrote:
>  >>  > Sorry if I misunderstood your problem, why don't you simply store the
>  >>  > last_login somewhere in a userprofile? Since -- judging from the name
>  >>  > -- it should only be altered when the user really logs in, I don't see
>  >>  > the relation with a session there :-/
>  >>  >
>  >>  > -- Horst
>  >>  >
>  >>  > On Tue, Apr 15, 2008 at 2:05 PM, [EMAIL PROTECTED] <[EMAIL PROTECTED]> 
> wrote:
>  >>  >
>  >>  >> hi all
>  >>  >>
>  >>  >>  please , i would like to ask for a little help. I have few functions
>  >>  >>  stored in my views.py under class Test. When i visit my homepage the
>  >>  >>  urls.py is calling method homepage from views.py as i mentioned 
> before.
>  >>  >>  Here it dig some data as current server time and user agent from
>  >>  >>  webbrowser. Now i need to pass these two details to any other 
> function
>  >>  >>  when the function is called.  I read all docs about session, cache 
> and
>  >>  >>  others, but still did not found an answer.
>  >>  >>  I also tried to store these details to session with
>  >>  >>
>  >>  >>  s = SessionStore(session_key='2b2289a188b44ad18c35e113ac6ceead')
>  >>  >>  s['last_login'] = datetime.datetime.now()
>  >>  >>  s.save()
>  >>  >>
>  >>  >>  and later call it. It saved it but with different session_key.
>  >>  >>  So back to the first problem. Please how can i pass some data from 
> one
>  >>  >>  method to all methods.
>  >>  >>
>  >>  >>  thank you very much for helping me
>  >>  >>  pavel
>  >>  >>
>  >>  >>  >
>  >>  >>
>  >>  >>
>  >>  >
>  >>  > >
>  >>  >
>  >>
>  >>
>  >>  >
>  >>
>  >>
>  >
>  > >
>  >
>
>
>  >
>

--~--~-~--~~~---~--~~
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: Have you used OrderingField?

2008-04-15 Thread Karen Tracey
On Tue, Apr 15, 2008 at 12:50 AM, Julien <[EMAIL PROTECTED]> wrote:

>
> Hi,
>
> I've stumbled on OrderingField in django.db.models.fields.
>
> That looks very interesting to me but I could not find any example of
> use, either in Django itself or on the web.
>
> Do you know what it is, and how to use it?
>

No, but from looking around in the SVN history you can find that the code
was added on the magic-removal branch in a changeset (1780) with the
comment:

steps towards ordering in edit-inline and spreadsheetish editing in
changelists using ManipulatorCollections

ManipulatorCollection never made it to trunk, it was removed from the
magic-removal branch in changeset 2103 with the comment:

Restored manipulators to code from trunk, removing the unfinished stuff

So, whatever OrderingField was supposed to be used for, it doesn't seem to
have ever been finished.  The code looks to be dead.

Why does it look interesting to you?  Perhaps there is an actually
implemented mechanism to do whatever you thought OrderingField might do, if
you explain what you thought it might be useful for.

Karen





>
> Thanks a lot!
>
> Julien
>
>
> PS: Here's its code:
>
> class OrderingField(IntegerField):
>empty_strings_allowed=False
>def __init__(self, with_respect_to, **kwargs):
>self.wrt = with_respect_to
>kwargs['null'] = True
>IntegerField.__init__(self, **kwargs )
>
>def get_manipulator_fields(self, opts, manipulator, change,
> name_prefix='', rel=False, follow=True):
>return [oldforms.HiddenField(name_prefix + self.name)]
> >
>

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



Multiple-Field PK support

2008-04-15 Thread Vortexmind

Will Django support this feature in the future?
--~--~-~--~~~---~--~~
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: Problem with abstract base class in QS-RF

2008-04-15 Thread Michael
> If that's all it is, then the fix should be pretty easy: for abstract
> base classes, the intermediate table name should be based on the name of
> the child model, not the abstract model. I can't drop everything right
> this minute to look at this, but I'm a little surprised that isn't
> happening already and it should be easy enough to fix when I get some
> time this evening.
>

I have been looking at this for a while now and I am really stumped as to
how to pull out the child model name from inside the field. I really hope
this will be an easy fix, but I am about to give up. Should I file a ticket
anyway, despite the fact that I know you know about it?

>
> However that still leaves a problem in any case where m2m fields refer
> to the same model (or where somebody wants to specify the related name)
> in the abstract base class and that's probably going to be a case of
> hard cheese. Abstract base classes are an aid, not a crutch.
> Fortunately, we can detect that problem and raise a sensible error (I
> was thinking about that over lunch and it doesn't seem too hard).
>

I have been thinking about this since I realized my convolution earlier.
Couldn't related name be achieved by creating another abstract base class
and extending it? This would allow for traversal based on the new abstract
class name. Related names are more often than not used to avoid naming
conflicts in the related class, anything else is just semantics. Creating an
extra base class would solve the naming conflicts.


>
> Regards,
> Malcolm
>
> --
> I don't have a solution, but I admire your problem.
> http://www.pointy-stick.com/blog/
>
>
> >
>

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



QuerySet behavior using extra()

2008-04-15 Thread Aaron

I have a model (Sale) that has latitude and longitude fields. I'm
trying to take one Sale object and find others within a certain radius
(using the great circle formula). When I do this using the extra()
QuerySet modifier, it returns a queryset with all the Sale objects in
the database. But when I manually execute the raw SQL query that's
being run (according to connection.queries), it returns the result
that I'm expecting.

I'm using version 0.97-pre-SVN-7121 with MySQL.

Am I doing something wrong?

>From my shell session:

>>> from data.models import Sale
>>> from django.db import connection
>>>
>>> this_sale = Sale.objects.order_by('?')[0]
>>> distance_query = "acos( SIN( PI( ) * %s /180 ) * SIN( PI( ) * 
>>> `data_sale`.`latitude` /180 ) + COS( PI( ) * %s /180 ) * COS( PI( ) * 
>>> `data_sale`.`latitude` /180 ) * COS( PI( ) * `data_sale`.`longitude` /180 - 
>>> PI( ) * %s /180 ) ) * 3963.191" % (this_sale.latitude, this_sale.latitude, 
>>> this_sale.longitude)
>>>
>>> nearby_sales = Sale.objects.extra(where=['%s < %s'], 
>>> params=[distance_query, .5])
>>> nearby_sales.count()
52448L
>>>
>>> query = connection.queries[-1]['sql']
>>> query
u'SELECT COUNT(*) FROM `data_sale` WHERE acos( SIN( PI( ) * 37.41915 /
180 ) * SIN( PI( ) * `data_sale`.`latitude` /180 ) + COS( PI( ) *
37.41915 /180 ) * COS( PI( ) * `data_sale`.`latitude` /180 ) *
COS( PI( ) * `data_sale`.`longitude` /180 - PI( ) * -76.514234 /
180 ) ) * 3963.191 < 0.5'
>>> cursor = connection.cursor()
>>> cursor.execute(query)
1L
>>> cursor.fetchone()[0]
34L
--~--~-~--~~~---~--~~
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: Normalized dates

2008-04-15 Thread gmacgregor


On Apr 15, 9:38 am, Mark Reynolds <[EMAIL PROTECTED]> wrote:
> I'm looking at this type of issue also.  From what I have been reading -
> it is normally advised to always keep dates in UTC, and just convert
> when needed.  I have two functions that I use to convert to the desired
> TZ just before sending to the template.

Yeah, everything that I've read essentially says that storing dates in
local time is the devil's spawn. Thanks for the two functions, Mark.
They'll come in handy.

Greg
--~--~-~--~~~---~--~~
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: Images and Stylesheets

2008-04-15 Thread Karen Tracey
On Tue, Apr 15, 2008 at 6:34 AM, Reisswolf <[EMAIL PROTECTED]> wrote:

>
> I have followed Doug Van Horn's detailed explanation very closely.  I
> have also read the Django documentation page on this particular
> topic.  But for some reason, I still cannot get the thing to work.
>
> Here is my situation:  In my /Programming/Python/Django
> directory I have created a project called TestProject, and in
> TestProject I have an app called TestApp.
>
> Also in TestProject I have Media/JavaScript/MyJSFile.js.  In urls.py I
> have the following line:
>
> (r'^media/(?P.*)$', 'django.views.static.serve',
> {'document_root': 'Programming/Python/Django/TestProject/
> Media'}),
>
> I have also specified '/Programming/Python/Django/
> TestProject/Media' as my MEDIA_ROOT and '/media/' as MEDIA_URL in
> settings.py.  I have read the documentation very carefully, and I
> believe I am doing everything correctly.
>
> I have  in the  tag of my template.  Everything
> else in the template gets rendered, but the JavaScript part does not.
> In fact, I get an error saying "TestFunc() not defined."  (TestFunc()
> is a simple hello-world function defined in MyJSFile.js.)
>
> I am really at my wit's end.  If someone here notices my error, I
> would be very grateful to him for pointing it out to me.
>
> *
>
> In case it might be important, I should mention that I am using Fedora
> 8, and I installed Django through yum:  yum install Django.
>
> *
>
> Thanks in advance for your help,
>
> >
>

--~--~-~--~~~---~--~~
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: Dynamic queryset to ModelChoiceField

2008-04-15 Thread Alex Koshelev

Or `Topic.objects.none()`

On Apr 15, 8:46 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> Sure, just give the modelchoicefield Topic.objects.all() to start
> with, as this will never actually get used.
>
> On Apr 14, 11:14 pm, shabda <[EMAIL PROTECTED]> wrote:
>
> > I have a form where I want to do something like,
>
> > class SetDefaultForm(forms.Form):
> > topics = forms.ModelChoiceField()
>
> > def __init__(self, user):
> > super(SetDefaultForm, self).__init__()
> > self.fields['topics'].queryset = Topic.objects.filter(user)
>
> > This does not work, of course, as ModelChoiceField has queryset as
> > required argument.
>
> > So I have to do something like,
>
> > class SetDefaultForm(forms.Form):
> > topics = forms.ChoiceField()
>
> > def __init__(self, user):
> > super(SetDefaultForm, self).__init__()
> > self.fields['topics'].choices= [topic for topic in
> > Topic.objects.filter(user)]
>
> > Is there a better way?
--~--~-~--~~~---~--~~
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: Missing help_text for ManyToManyFields with filter_interface

2008-04-15 Thread Rodrigo Culagovski

Thanks, I tried it and it didn't work (the filter_interface stopped
showing).
I removed the filter_interface from now, as the help_text is
mandatory. Will wait for a solution in trunk, I guess.

Thanks,

Rodrigo

On Apr 14, 5:50 pm, "Karen Tracey" <[EMAIL PROTECTED]> wrote:
> On Mon, Apr 14, 2008 at 4:07 PM, Rodrigo Culagovski <[EMAIL PROTECTED]>
> wrote:
>
> > The help_text for my ManyToManyFields dissapears when I use
> > "filter_interface=models.HORIZONTAL" (or "=models.VERTICAL").
> > I figure that it's the JavaScript in the filter_interface, as the
> > help_text is there before the JavaScript modifies the field. Using
> > trunk.
>
> I doubt this will be fixed on trunk, but there's an open ticket for it
> against newforms-admin:
>
> http://code.djangoproject.com/ticket/6183
>
> It's got a patch you could try out if you'd like a fix before the ticket
> gets resolved (+ newforms-admin merged to trunk).  Not sure if the patch
> will need modification to work on trunk.
>
> Karen
--~--~-~--~~~---~--~~
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: Normalized dates

2008-04-15 Thread Mark Reynolds

I'm looking at this type of issue also.  From what I have been reading - 
it is normally advised to always keep dates in UTC, and just convert 
when needed.  I have two functions that I use to convert to the desired 
TZ just before sending to the template. 

def _convert_timezone(utctime, newzone):
newtime = utctime.replace( tzinfo=tz.tzutc() ).astimezone(newzone)
return newtime

def _convert_to_utc(oldtime, oldzone):
newtime = oldtime.replace(tzinfo=oldzone).astimezone( tz.tzutc() 
).replace(tzinfo=None)
return newtime

MySQL seems to have issues with datetimes that have tzinfo, so I always 
store without it.  I.e., I assume all datetimes are UTC, but without a 
tzinfo, until I convert it at the last moment for rendering a template.


-Mark


gmacgregor wrote:
> Some of my project app's models have a DateTimeField where the value
> is UTC while others have EDT/EST values. This is because I populate
> some models (ie. a blog entry) via django-admin while other data is
> populated via my flickr/del.icio.us accounts (via django-syncr  code.google.com/p/django-syncr/>).
>
> When displaying timestamps, I want all values to be EDT/EST-- the
> timezone in which I live. Is there an easy way to handle this
> conversion on the template level? Or should I start thinking about
> overriding the save() method to either make all DateTimeField values
> EDT/EST/UTC? Is there a simple solution out there that I just haven't
> yet considered? Thanks for the help...
> >
>
>   


--~--~-~--~~~---~--~~
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: Error 500 in admin panel

2008-04-15 Thread Karen Tracey
On Tue, Apr 15, 2008 at 8:52 AM, Mathieu Goeminne <[EMAIL PROTECTED]>
wrote:

>
> Hi all,
>
> I'm a newbie in Django, and I'have to populate some data using the admin
> panel.
>
> While I'm saving a entity, or sometime while I want to see it, Django
> raises a 500 error. The default admin entities don't rise any error,
> only my entity do it.
>
> I have changed my user permissions (getting all the permissions) but the
> errors are not removed.
>
> Any idea?
>
> Thanks for help.
>

Set DEBUG=True in your settings file and instead of getting the bare 500
error page you'll get detailed information on where the error is occurring.

Karen

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



primary key type in customized save() method

2008-04-15 Thread aabele

I have a customized save() method in model. If the record ir new
(without ID) - then self.id type is unicode, otherwise self.id is
integer. So when I try to do a  many-to-many relationship search - in
first case it doesn't work, in second - works like a charm.

def save(self):
super(message, self).save()
for single_group in self.group.all():
print '%r' % single_group.id

Is this some kind of bug in django?

Thanx in advance!
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Search Frameworks

2008-04-15 Thread brydon

I'm curious what people are currently using for search frameworks on
django based projects. I've done a fair bit of research here and
elsewhere and I still haven't landed on a clear decision. What are
people successfully using with django to get robust search
capabilities a la lucene etc? Are pylucene, xapian working?

thanks,
brydon
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



QS-RF: maximum recursion depth exceeded in cmp

2008-04-15 Thread sector119

I begin testing qs-rf branch and get this exception, why?
May be because Office model is tree - has parent =
models.ForeignKey('self') field?

Exception Type: RuntimeError
Exception Value:maximum recursion depth exceeded in cmp
Exception Location: /home/sector119/devel/django_src/django/db/models/
sql/query.py in join, line 734
Python Executable:  /usr/bin/python2.5


Template error

In template /home/sector119/devel/eps_src/eps/templates/base.html,
error at line 23
Caught an exception while rendering: maximum recursion depth exceeded
in cmp

23  {{ user.office.location.get_type_display }}.
{{ user.office.location.name }}, {{ user.office.name }}, {% firstof
user.get_full_name user.username %} | {% block userlinks %}{% trans 'Help' %} | {% trans 'Sign out' %}{%
endblock %}
--~--~-~--~~~---~--~~
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: Multiple-Field PK support

2008-04-15 Thread Karen Tracey
On Tue, Apr 15, 2008 at 9:45 AM, Vortexmind <[EMAIL PROTECTED]> wrote:

>
> Will Django support this feature in the future?
>

Maybe.  See: http://code.djangoproject.com/wiki/MultipleColumnPrimaryKeys

Karen

--~--~-~--~~~---~--~~
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: sortable table

2008-04-15 Thread Steingrim Dovland

On Tue, Apr 15, 2008 at 3:16 PM, Gboro54 <[EMAIL PROTECTED]>
>  can i write the javascript right into a text file and put it into my
>  folder where I am storeing templetes? If so do I still make it into an
>  html file or not?

If you decide that you want to use jQuery I suggest you start by
reading one of the jQuery tutorials :) Start here
http://docs.jquery.com/Tutorials


-- 
Steingrim Dovland. Oslo, Norway.
This behaviour is by design.

--~--~-~--~~~---~--~~
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: filter a form to find if there are any required fields

2008-04-15 Thread Karen Tracey
On Tue, Apr 15, 2008 at 9:02 AM, per9000 <[EMAIL PROTECTED]> wrote:

>
> Hi,
>
> I have added a * to required fields. (Some of my forms do not have any
> required fields.) I want to do this:
>
> 
>  {% if form|has_req_field %}
>  * = Required Field
>  {% endif %}
>
>  {# put form here #}
>
> 
>
> And my filter looks like this:
>
> def has_req_field(value, arg=None):
>
>for field in value.fields:
>if field.field.required:
>return True
>
>return False
>
> I get the impression that my template truns the form into a string and
> then passes the string into my filter function ('str' object has no
> attribute 'field').
>
> Is there any way to get the form intact out of the template and into
> python?
>
> Or is there a better way to find out if there is at least one required
> field of my form.
>
> Thanks!
>

I don't know that filters are intended to be used in if blocks like that.
It would seem more natural to have a has_req_field method in your form and
write:

{% if form.has_req_field %}

(Yes, then each form you want to do this with has to have this method, but
there are Python ways to enable that without actually having to duplicate
the code in each form.)

Karen

--~--~-~--~~~---~--~~
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: Search Frameworks

2008-04-15 Thread Jarek Zgoda

brydon napisał(a):
> I'm curious what people are currently using for search frameworks on
> django based projects. I've done a fair bit of research here and
> elsewhere and I still haven't landed on a clear decision. What are
> people successfully using with django to get robust search
> capabilities a la lucene etc? Are pylucene, xapian working?

At first, we used home-built search and indexing machinery based upon
PyLucene + Twisted, but eventually we switched to Solr after we started
getting into massive troubles because of leaking references to Java
objects in PyLucene/GCJ. Unfortunately, the memory footprint of
PyLucene/JCC was unacceptable for us and we had to go with Java.

-- 
Jarek Zgoda
Skype: jzgoda | GTalk: [EMAIL PROTECTED] | voice: +48228430101

"We read Knuth so you don't have to." (Tim Peters)

--~--~-~--~~~---~--~~
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: Multiple-Field PK support

2008-04-15 Thread Vortexmind

Thank you. I missed that wiki article!

> Maybe.  See:http://code.djangoproject.com/wiki/MultipleColumnPrimaryKeys
>
> Karen
--~--~-~--~~~---~--~~
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: Search Frameworks

2008-04-15 Thread brydon

As well, are you guys using SolPython?
http://wiki.apache.org/solr/SolPython

brydon





On Apr 15, 10:23 am, Jarek Zgoda <[EMAIL PROTECTED]> wrote:
> brydon napisał(a):
>
> > I'm curious what people are currently using for search frameworks on
> > django based projects. I've done a fair bit of research here and
> > elsewhere and I still haven't landed on a clear decision. What are
> > people successfully using with django to get robust search
> > capabilities a la lucene etc? Are pylucene, xapian working?
>
> At first, we used home-built search and indexing machinery based upon
> PyLucene + Twisted, but eventually we switched to Solr after we started
> getting into massive troubles because of leaking references to Java
> objects in PyLucene/GCJ. Unfortunately, the memory footprint of
> PyLucene/JCC was unacceptable for us and we had to go with Java.
>
> --
> Jarek Zgoda
> Skype: jzgoda | GTalk: [EMAIL PROTECTED] | voice: +48228430101
>
> "We read Knuth so you don't have to." (Tim Peters)
--~--~-~--~~~---~--~~
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: Images and Stylesheets

2008-04-15 Thread Duke


This is  strange its work for me

U config the URL as i suggested and referce the image as below in the
tab

This should definitly work it even work for javascript.
Thank
Duke

--~--~-~--~~~---~--~~
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: Looping....

2008-04-15 Thread Duke

They are looping over a list
I am looking for

for (i = 0; i < 10; i++) {
 printf("Hello,  World!);
}
link for looping statement

Thank
Duke
--~--~-~--~~~---~--~~
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: Search Frameworks

2008-04-15 Thread brydon

I'm assuming this means you're having good success with solr and
django? You don't happen to know of any related documentation, links,
blog posts you could pass along?

thanks,
brydon




On Apr 15, 10:23 am, Jarek Zgoda <[EMAIL PROTECTED]> wrote:
> brydon napisał(a):
>
> > I'm curious what people are currently using for search frameworks on
> > django based projects. I've done a fair bit of research here and
> > elsewhere and I still haven't landed on a clear decision. What are
> > people successfully using with django to get robust search
> > capabilities a la lucene etc? Are pylucene, xapian working?
>
> At first, we used home-built search and indexing machinery based upon
> PyLucene + Twisted, but eventually we switched to Solr after we started
> getting into massive troubles because of leaking references to Java
> objects in PyLucene/GCJ. Unfortunately, the memory footprint of
> PyLucene/JCC was unacceptable for us and we had to go with Java.
>
> --
> Jarek Zgoda
> Skype: jzgoda | GTalk: [EMAIL PROTECTED] | voice: +48228430101
>
> "We read Knuth so you don't have to." (Tim Peters)
--~--~-~--~~~---~--~~
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: QS-RF: maximum recursion depth exceeded in cmp

2008-04-15 Thread Michael
Could you post your models code somewhere for us to take a look at? Also
could you separate each variable in you template to a different line so we
know what exactly was causing the error?

I think I have an idea of what is going on here, but I want to try to
reproduce it with as few lines as possible.

On Tue, Apr 15, 2008 at 10:16 AM, sector119 <[EMAIL PROTECTED]> wrote:

>
> I begin testing qs-rf branch and get this exception, why?
> May be because Office model is tree - has parent =
> models.ForeignKey('self') field?
>
> Exception Type: RuntimeError
> Exception Value:maximum recursion depth exceeded in cmp
> Exception Location: /home/sector119/devel/django_src/django/db/models/
> sql/query.py in join, line 734
> Python Executable:  /usr/bin/python2.5
>
>
> Template error
>
> In template /home/sector119/devel/eps_src/eps/templates/base.html,
> error at line 23
> Caught an exception while rendering: maximum recursion depth exceeded
> in cmp
>
> 23  {{ user.office.location.get_type_display }}.
> {{ user.office.location.name }}, {{ user.office.name }}, {% firstof
> user.get_full_name user.username %} | {% block userlinks %} href="">{% trans 'Help' %} | {% trans 'Sign out' %}{%
> endblock %}
> >
>

--~--~-~--~~~---~--~~
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: Search Frameworks

2008-04-15 Thread Jarek Zgoda

brydon napisał(a):
> As well, are you guys using SolPython?
> http://wiki.apache.org/solr/SolPython

No, we use PySolr - http://code.google.com/p/pysolr/. It (nearly)
matches our previous search machinery interface.

There's not much about this, just look at the docs in module header to
get overview how it works. Anyway, schema definition and solr
configuration requires most of work, not the interfacing with Solr,
which talks HTTP.

-- 
Jarek Zgoda
Skype: jzgoda | GTalk: [EMAIL PROTECTED] | voice: +48228430101

"We read Knuth so you don't have to." (Tim Peters)

--~--~-~--~~~---~--~~
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: QS-RF: maximum recursion depth exceeded in cmp

2008-04-15 Thread sector119

Template error

In template /home/sector119/devel/eps_src/eps/templates/base.html,
error at line 23
Caught an exception while rendering: maximum recursion depth exceeded
in cmp

23  {{ user.office.location.get_type_display }}.
24  {{ user.office.location.name }},
25  {{ user.office.name }},

--

class Location(models.Model):
id = models.IntegerField(_('Id'), primary_key=True)
parent = models.ForeignKey('self', verbose_name=_('Location parent
id:'), null=True, blank=True,  related_name='child_set')
name = models.CharField(_('Location'), help_text=_('Office or
person location.'), max_length=32)
type = models.PositiveSmallIntegerField(_('Location type'),
choices=LOCATION_TYPE_CHOICES)

def __unicode__(self):
return self.name

class Import:
pass

class Meta:
verbose_name = _('Location')
verbose_name_plural = _('Locations')
ordering = ['parent', 'id']

class Admin:
pass


--

class OrganizationOffice(models.Model):
parent = models.ForeignKey('self', verbose_name=_('Parent
office:'), null=True, blank=True)
location = models.ForeignKey(Location,
verbose_name=_('Location:'))
name = models.CharField(_('Office'), max_length=50)
bank = models.CharField(_('Bank'), max_length=50, null=True,
blank=True)
account = fields.PositiveBigIntegerField(_('Account'), null=True,
blank=True)
bic = models.PositiveIntegerField(_('BIC'), help_text=_('Bank
identifier code.'), null=True, blank=True)
code = models.PositiveIntegerField(_('Code'),
help_text=_('Enterprise code.'), null=True, blank=True)
in_testmode = models.BooleanField(_('Office is in test mode'),
default=False)
day_is_open = models.BooleanField(_('Transaction day is open'),
default=False)

def __unicode__(self):
return self.name

class Import:
pass

class Meta:
verbose_name = _('Office')
verbose_name_plural = _('Offices')
ordering = ['location', 'parent', 'id']

class Admin:
search_fields = ('^id', '^location__name', 'name')

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



QS-RF: something strange happens with model inharitance

2008-04-15 Thread sector119

I have already created models A and B and tables with trunk, now I
installed qs-rf branch and make C model inharit from already created
A, B models, but when I run manage.py sqlall my_app_with_C_model I do
not see any columns from C model :(

But everything works fine if I create all models from scratch..

Any thoughts?
--~--~-~--~~~---~--~~
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: Adding new language for i18n

2008-04-15 Thread Ramiro Morales

On Tue, Apr 15, 2008 at 10:04 AM,  <[EMAIL PROTECTED]> wrote:
>
>  Hi
>
>  I try to add translation for Thai language. I did following,
>
>  1. My environment is Window so I use Window version of xgettext, see
>  http://gnuwin32.sourceforge.net/packages/gettext.htm
>  2. Under my application path, I created directory conf/locale.
>  3. Executed make-messages.py -l th.
>  4. I can see conf\locale\th\LC_MESSAGES\django.po.

For aplications this should be locale\th\LC_MESSAGES
(no intermediate conf\). See:

  http://www.djangoproject.com/documentation/i18n/#message-files

>  5. I successfully executed make-messages.py -a.
>  6. Comoiled, compile-messages.py
>  7. Set LANGUAGE_CODE to "th".
>  8. Tested by adding trans tag in template (using message I've added
>  in .po file).
>  9. Try to force session and cookie language.
>  10  Nothing is translated.
>

Perhaps you missed this part from the documentation:

http://www.djangoproject.com/documentation/i18n/#how-django-discovers-language-preference

"
The LocaleMiddleware can only select languages for which there is a
Django-provided base translation. If you want to provide translations
for your application that aren't already in the set of translations in
Django's source tree, you'll want to provide at least basic
translations for that language.
[...]
A good starting point is to copy the English .po file and to translate
at least the technical messages — maybe the validator messages, too.
"

This is relevant because Django itself hasn' t yet been translated to Thai.

I would recommend you to read:

http://www.djangoproject.com/documentation/i18n/

to avoid these gotchas, The two problems you' ve found seem to be
related to not following what's documented there.

Good luck,

-- 
 Ramiro Morales

--~--~-~--~~~---~--~~
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: Search Frameworks

2008-04-15 Thread Thomas Guettler

brydon schrieb:
> I'm curious what people are currently using for search frameworks on
> django based projects. I've done a fair bit of research here and
> elsewhere and I still haven't landed on a clear decision. What are
> people successfully using with django to get robust search
> capabilities a la lucene etc? Are pylucene, xapian working?
>
>
>   
Since my projects are based on postgres, I have choosen tsearch2 for 
full text search. Big
advantage: It is part of the transaction system.

It took me some time to find out, that the methods to_tsvector and 
to_tsquery can be
replaced by own methods. You just need to return a properly formated 
string and cast
it to tsvector. [1]

I am happy with the speed. It is much faster than the old solution (htdig).

Tsearch2 covers indexing of unicode data only. If you want to index 
HTML, office formats, ... you
need a way to convert them to unicode.

HTH,
  Thomas Güttler

[1]: 
http://www.postgresql.org/docs/current/interactive/datatype-textsearch.html

-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


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



Reverse relations, select_related, and the Queryset Refactor Branch

2008-04-15 Thread robotika

I was initially excited at the idea of specifying a list related
fields with a select_related call, but have since discovered it
doesn't seem to work on reverse relations. I don't know why I was
expecting it to work (stupid optimism!), but it was a little
disappointing. What I was curious about, and I guess this question is
mostly for Malcolm, is how difficult would it be to allow
select_related to follow reverse relations if the fields/models were
specified? If it isn't too difficult, would this be something that
could end up in Django at some point?

To explain what I'm trying to do, I'd like to return unrelated objects
via a shared Model (by using their coordinates) using a single query.
I do have a feeling I probably haven't really thought it through
properly, but at the moment at least, it seems to make sense to
attempt to do it this way.

Here are my models.

# The model that holds Longitude/Latitude coordinates
class GeoPoint(models.Model):
""" A GeoDjango model that only holds Geographic Coordinates """
coords = models.PointField(srid=4326)

# The model for a City
class City(models.Model):
name = models.CharField(max_length=99)
point  = models.OneToOneField(GeoPoint, related_name='place')

class Landmark(models.Model):
""" Tourism related landmarks """
name = models.CharField(max_length=99)
point  = models.OneToOneField(GeoPoint, related_name='landmark')

class Photo(models.Model):
""" User uploaded photos """
name = models.CharField(max_length=99)
point  = models.OneToOneField(GeoPoint, related_name='photo')

class Cafe(models.Model):
name = models.CharField(max_length=99)
point  = models.OneToOneField(GeoPoint, related_name='cafe')

class Event(models.Model):
name = models.CharField(max_length=99)
point  = models.OneToOneField(GeoPoint, related_name='event')


With this structure, if we were to visit Los Angeles, we could do the
following to return a queryset of things to see or do when in LA.

# Only display 20 objects
limit = 20

# Get the city of Los Angeles
city = City.objects.get(slug='los-angeles')

# Get the Coordinates of Los Angeles via the
point = city.geopoint.coords

# Find things in Los Angeles to display on a map. This won't work :(
stuff_to_see = GeoPoint.objects.select_related('landmark', 'photo',
'cafe', 'event')

# Sort the found objects by their distance from Los Angeles
stuff_to_see = stuff_to_see.distance(point).order_by('distance')
[:limit]

Now the above won't work as selected_related won't return any objects
as the specified fields don't exist in the GeoPoint model. I guess my
question at this point, as mentioned above, would having
select_related follow reverse relations in this way be too difficult
to implement into the qs-rf branch. I guess my hope is it's simple,
but yeah, things are usually never that simple :)

If it is too difficult/painful to do, then it's probably better I
start thinking of another way to implement this without resorting to
individual queries for each model. Anyone have any suggestions at
other ways to accomplish something similar? Hopefully some of my
example made sense :)

Thanks :)
John



--~--~-~--~~~---~--~~
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: Adding new language for i18n

2008-04-15 Thread meledictas

I did wrong about po file path. I'm trying to copy a working language
and edit po file and re-compile.

For now, still cannot see the sign.

Thank for your comment, anyway.



On Apr 15, 9:35 pm, "Ramiro Morales" <[EMAIL PROTECTED]> wrote:
> On Tue, Apr 15, 2008 at 10:04 AM,  <[EMAIL PROTECTED]> wrote:
>
> >  Hi
>
> >  I try to add translation for Thai language. I did following,
>
> >  1. My environment is Window so I use Window version of xgettext, see
> >  http://gnuwin32.sourceforge.net/packages/gettext.htm
> >  2. Under my application path, I created directory conf/locale.
> >  3. Executed make-messages.py -l th.
> >  4. I can see conf\locale\th\LC_MESSAGES\django.po.
>
> For aplications this should be locale\th\LC_MESSAGES
> (no intermediate conf\). See:
>
>  http://www.djangoproject.com/documentation/i18n/#message-files
>
> >  5. I successfully executed make-messages.py -a.
> >  6. Comoiled, compile-messages.py
> >  7. Set LANGUAGE_CODE to "th".
> >  8. Tested by adding trans tag in template (using message I've added
> >  in .po file).
> >  9. Try to force session and cookie language.
> >  10  Nothing is translated.
>
> Perhaps you missed this part from the documentation:
>
> http://www.djangoproject.com/documentation/i18n/#how-django-discovers...
>
> "
> The LocaleMiddleware can only select languages for which there is a
> Django-provided base translation. If you want to provide translations
> for your application that aren't already in the set of translations in
> Django's source tree, you'll want to provide at least basic
> translations for that language.
> [...]
> A good starting point is to copy the English .po file and to translate
> at least the technical messages -- maybe the validator messages, too.
> "
>
> This is relevant because Django itself hasn' t yet been translated to Thai.
>
> I would recommend you to read:
>
> http://www.djangoproject.com/documentation/i18n/
>
> to avoid these gotchas, The two problems you' ve found seem to be
> related to not following what's documented there.
>
> Good luck,
>
> --
>  Ramiro Morales
--~--~-~--~~~---~--~~
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: Looping....

2008-04-15 Thread Darryl Ross

Duke wrote:

They are looping over a list
I am looking for

for (i = 0; i < 10; i++) {
 printf("Hello,  World!);
}
link for looping statement



I am not aware of any tag that will allow you to do that, out of the 
box. You have two options, the first is to create a custom template tag 
that do what you want[1]. This shouldn't really be terribly difficult to do.


The second option would be to just pass in a variable into the context 
with a list containing the number of items of the number of times you 
want to loop. Using generic views, this could be done in your urls.py like:


...
 ('^$', 'direct_to_template',
{ 'template_name': 'homepage.html',
  'extra_context': {'looper': range(10) }})
...

Then you can use the standard {% for %} tag:

{% for i in looper %}
  {{i}}
{% endfor %}


[1] 
http://www.djangoproject.com/documentation/templates_python/#extending-the-template-system




signature.asc
Description: OpenPGP digital signature


One app installed several times

2008-04-15 Thread Thomas Guettler

Hi,

I just got an application installed several times in one project.
It was important for me, that each instance of the application
has it on tables.

Here is who I did it. Feedback welcome!

myapp: Exists one time, but never gets used in settings.INSTALLED_APPS

I created two new modules on the PYTHONPATH with symlinks myapp_inst1 
myapp_inst2. Both
directories point to myapp.

in settings INSTALLED_APPS = [ .., 'myapp_inst1', 'myapp_inst2']

I changed all absolute imports in the application to relative imports:
old: from myapp.utils import abc
new: from .utils import abc

in myapp/__init__.py:
import os
application=os.path.basename(os.path.dirname(os.path.abspath(__file__)))

in myapp/models:py:
assert application.startswith('myapp_'), 'Wrong Import. application=%s 
should be myapp_instN.' % (
application)

Now syncdb creates the tables like this: myapp_inst1_mymodel

# urls.py need to prefix the viewnames with application:
myapp/urls.py:
urlpatterns = patterns('',
(r'^$', '%s.views.index' % application),
...

One place left: Templatetag 'url' needs to use relative imports, too.
I modified django: if the view name starts with a dot, the view name gets
the application as prefix. The variable 'application' must be contained 
in the context.

Index: django/template/defaulttags.py
===
--- django/template/defaulttags.py  (Revision 7425)
+++ django/template/defaulttags.py  (Arbeitskopie)
@@ -359,12 +365,16 @@
 args = [arg.resolve(context) for arg in self.args]
 kwargs = dict([(smart_str(k,'ascii'), v.resolve(context))
for k, v in self.kwargs.items()])
+if self.view_name.startswith('.'):
+view = '%s%s' % (context['application'], self.view_name)
+else:
+view = self.view_name
 try:
-return reverse(self.view_name, args=args, kwargs=kwargs)
+return reverse(view, args=args, kwargs=kwargs)
 except NoReverseMatch:
 try:
 project_name = settings.SETTINGS_MODULE.split('.')[0]
-return reverse(project_name + '.' + self.view_name,
+return reverse(project_name + '.' + view,
args=args, kwargs=kwargs)
 except NoReverseMatch:
 return ''

Any thoughts how to do this better?

 Thomas

-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de


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



Custom SQL Escaping apostrophe

2008-04-15 Thread AJ

My custom sql works great unless there is an ' in the query, then of
course it fails.  The question is how do I escape the apostrophe?  For
example the query is "pete's". I first tried:

query = query.replace("'", "\'")

If you printed the query out it does say "pete\'s", but as soon as it
gets substituted into the query the backslash character somehow
dissapears.  The relevant code:

from django.db import connection

cursor = connection.cursor()
query = "pete's"

sql = """
SELECT MAX(`table`.`id`)
FROM `table`
WHERE `table`.`name` LIKE '%(kw)s'
GROUP BY `table`.`original_id`;"""

sql = sql % {'kw' : '%%' + query + '%%'}
cursor.execute(sql)

Again this works fine if the query has no apostrophe, but if there is
one it will fail which makes sense.  So if I can't use query =
query.replace("'", "\'"), is there a builtin function that will escape
apostrophes?  I was under the impression that the db module handled
escaping for you.

Thanks in advance.

Aaron
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Template path error

2008-04-15 Thread Gaurav Sharma
Hi All,

I am very new to Django and facing lot of initial problems. I have created a
template folder at C:/python25/django/templates
and I have updated the settings.py file with "forward slashes" in path. When
I hit the url, it gives me the following error.

c:\python25\django\templates\current_datetime.html (File does not exist)

I am totally clueless as I have this file at this path but it is still
giving the error.

I hope somebody would have the solution as I might be doing some silly
mistake.Thanks in advace

Cheers
Gaurav

--~--~-~--~~~---~--~~
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: Looping....

2008-04-15 Thread Kenneth Gonsalves


On 15-Apr-08, at 9:04 PM, Darryl Ross wrote:

> Duke wrote:
>> They are looping over a list
>> I am looking for
>> for (i = 0; i < 10; i++) {
>>  printf("Hello,  World!);
>> }
>> link for looping statement
>
>
> I am not aware of any tag that will allow you to do that, out of  
> the box. You have two options, the first is to create a custom  
> template tag that do what you want[1]. This shouldn't really be  
> terribly difficult to do.
>
> The second option would be to just pass in a variable into the  
> context with a list containing the number of items of the number of  
> times you want to loop. Using generic views, this could be done in  
> your urls.py like:
>
> ...
>  ('^$', 'direct_to_template',
> { 'template_name': 'homepage.html',
>   'extra_context': {'looper': range(10) }})
> ...
>
> Then you can use the standard {% for %} tag:
>
> {% for i in looper %}
>   {{i}}
> {% endfor %}
>
>
> [1] http://www.djangoproject.com/documentation/templates_python/ 
> #extending-the-template-system
>

where is the use case for this? I cannot conceive of any situation  
where one would want to loop over an arbitrary number.

-- 

regards
kg
http://lawgon.livejournal.com
http://nrcfosshelpline.in/code/




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



Images

2008-04-15 Thread [EMAIL PROTECTED]

I have searched high and low to make it possible for me to display an
image via Django in an html template and it fail bombs so hard.  Can
someone please point me in some direction that can shed some light on
this, a fellow classmate of mine decided to just hard code it but that
is a bad idea if you have oh say more then 1 image or user.  I have
PIL installed.

Thanks for any help.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Pre-processing and preparing data in a separate thread or process?

2008-04-15 Thread Daryl Spitzer

I have a view that takes approximately 5 minutes (plus or minus 4 or
so) to put together data (culled from other sources, such as our SCM
and a web service that wraps our bug database) to be passed on to a
template. Some form of caching may (mostly) solve this problem, but
I'm worried about two things:

1) The unlucky user who is the first to go to this page after the
cached data has expired will have a long wait.

2) What happens when other users go to other pages, or this page,
while the view is gathering data?

I don't have any experience deploying Django projects (yet) nor do I
have any with Apache.  But from what I've read so far, I'm under the
impression that Apache can be configured to run multiple processes,
each with its own invocation of Django...right?  (These processes
will, of course, be unaware of each other unless I take steps to
synchronize them.)

I think the proper solution is to have a separate process periodically
put together the data that my view does now, and serialize (pickle) it
or put it in the database. Then my view will just read and display the
most-recently generated data.

Do you agree?  Do you have any advice?  Should I run this separate
process from within Django (somehow), or as a cronjob?

--
Daryl Spitzer

--~--~-~--~~~---~--~~
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: sortable table

2008-04-15 Thread Gboro54

Thanks for the help...I will do so...

On Apr 15, 10:28 am, "Steingrim Dovland" <[EMAIL PROTECTED]>
wrote:
> On Tue, Apr 15, 2008 at 3:16 PM, Gboro54 <[EMAIL PROTECTED]>
>
> >  can i write the javascript right into a text file and put it into my
> >  folder where I am storeing templetes? If so do I still make it into an
> >  html file or not?
>
> If you decide that you want to use jQuery I suggest you start by
> reading one of the jQuery tutorials :) Start 
> herehttp://docs.jquery.com/Tutorials
>
> --
> Steingrim Dovland. Oslo, Norway.
> This behaviour is by design.
--~--~-~--~~~---~--~~
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: Search Frameworks

2008-04-15 Thread andy baxter

brydon wrote:
> I'm curious what people are currently using for search frameworks on
> django based projects. I've done a fair bit of research here and
> elsewhere and I still haven't landed on a clear decision. What are
> people successfully using with django to get robust search
> capabilities a la lucene etc? Are pylucene, xapian working?
>
>   
I've written a fairly decent search function for my app just using Q 
objects and the icontains test (I'm thinking of updating it to use the 
new iregexp test, so as to search only whole words). I guess this 
wouldn't be so good if you're building a big site, but it works pretty 
well on mine. It takes a space separated string of keywords (which can 
include quoted phrases), and returns the items where each of the 
keywords is in at least one of the given fields.

The code I've written so far is pasted below. It isn't very tidy at the 
moment, but does work, and people are welcome to copy and adapt it if 
they like. I'm thinking at some point to generalise what I've written 
into a custom filter class which takes a list of fields and a string as 
an argument, and then post the code on the wiki, if people think that's 
worth doing?

import re
from django import newforms as forms
from django.http import Http404, HttpResponseRedirect
from django.shortcuts import render_to_response
from library.horace.models import Item, ItemInstance, Tag
from django.db.models import Q

class SimpleSearchForm(forms.Form):
string = forms.CharField(label='Text to search for',max_length=100)
fields = forms.ChoiceField([(1,'Author, Title or 
Description'),(2,'Title or Description'),(3,'Title'),(4,'Author')], 
label='Where to search')
type = forms.ChoiceField([(1,'Any 
item'),(2,'Books'),(3,'Magazines'),(4,'Films'),(5,'Music')], label='What 
kind of item to search')

def simple_search(request):
"""Displays a simple search form and processes it.
Each word or phrase (marked by double quotes) has to be in at least 
one of the fields indicated"""
if request.method == 'POST':
form = SimpleSearchForm(request.POST)
if form.is_valid():
item_list=Item.objects.all()
string=request.POST.get('string','')
fields=request.POST.get('fields',1)
type=request.POST.get('type',1)
# first split the input string into seperate words or phrases.
# I.e. the string '"mandrake linux" compiler c' becomes:
#('mandrake linux','compiler','c')
# begin by taking out the double-quoted phrases.
reqt=re.compile(r'["\'](.*?)["\']')
phrases=reqt.findall(string)
#print "phrases: %s" % phrases
string=reqt.sub('',string) # remove the phrases
#print "string: %s" % string
rewd=re.compile(r'(\w+)( |$)')
resp=re.compile(r' ') # TODO - work out why there's an extra 
space at the end of words in the first place.
for pair in rewd.finditer(string):
wd=resp.sub('',pair.group())
#print "wd: -%s-" % wd
phrases.append(wd)
#print "phrases: %s" % phrases
# now phrases contains a list of terms to search for.
# next thing is to find which items contain all of the terms 
in at least one of the given fields.
# for each term, make a Q object which selects if it is in 
at least one of the given fields...
qand=None # TODO -find out if there is a null Q object you 
can start with without having to check if it's None later.
for phrase in phrases:
qor=None # a 'Q object' which can be combined with other 
Q objects to represent a complex query. see django documentation.
if (fields=='1') or (fields=='2') or (fields=='3'):
qor=Q(title__icontains=phrase)
if fields=='1' or fields=='4':
if qor==None:
qor=Q(creator__icontains=phrase)
else:
qor=qor | Q(creator__icontains=phrase)
if fields=='1' or fields=='2':
qor=qor | Q(description__icontains=phrase)
# now qor must contain something, so 'and' it with the 
rest if there are any yet
if qand != None:
qand=qand & qor
else:
qand=qor
if qand != None:
item_list=item_list.filter(qand)
# now process the 'type' field.
mapping={'2': 1, '3': 2, '4': 3, '5': 4}
if type in mapping.keys():
item_list=item_list.filter(item_type=mapping[type])
#print "item_list: %s" % item_list
#print "item_list._filters %s" % item_list._filters
length=item_list.count()
return render_to_response('simple-search.html',{'item_list': 
item_list,
#'search_string': "containing '%s'" 

Re: Custom SQL Escaping apostrophe

2008-04-15 Thread Jonathan Ballet

AJ wrote:
[...]
> sql = """
> SELECT MAX(`table`.`id`)
> FROM `table`
> WHERE `table`.`name` LIKE '%(kw)s'
> GROUP BY `table`.`original_id`;"""
> 
> sql = sql % {'kw' : '%%' + query + '%%'}
> cursor.execute(sql)
[...]

This is the wrong way to do this, and your problem explains why.

Take a look at [1] ; you were right, the db module handles those things for you.
Typically, you use "%s" in your query where you want to put an external value, 
you give a list of 
values to the "execute" method and the database's backend will correctly handle 
the value's 
quotation for you.

In addition to protect you from SQL injections, it will give you more 
portability between different 
databases (since they don't handle quotations the same way).

  - Jonathan

[1] : http://www.djangoproject.com/documentation/model-api/#executing-custom-sql

--~--~-~--~~~---~--~~
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: Template path error

2008-04-15 Thread AJ

Do you have your TEMPLATE_DIRS setting as a tuple or list?  If it's a
tuple and it has only one element you need a trailing comma like so:
TEMPLATE_DIRS = (
  'C:/python25/django/templates',
)

On Apr 15, 12:00 pm, "Gaurav Sharma" <[EMAIL PROTECTED]> wrote:
> Hi All,
>
> I am very new to Django and facing lot of initial problems. I have created a
> template folder at C:/python25/django/templates
> and I have updated the settings.py file with "forward slashes" in path. When
> I hit the url, it gives me the following error.
>
> c:\python25\django\templates\current_datetime.html (File does not exist)
>
> I am totally clueless as I have this file at this path but it is still
> giving the error.
>
> I hope somebody would have the solution as I might be doing some silly
> mistake.Thanks in advace
>
> Cheers
> Gaurav
--~--~-~--~~~---~--~~
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: Pre-processing and preparing data in a separate thread or process?

2008-04-15 Thread Christopher Allan Webber

We developed something that did something similar here.  The import
process spawned a daemon which imported the data.  However, in our
system only one import could be done at a time (that was actually part
of the spec, not bad programming!), so spawning one daemon per import
wasn't such a bad idea.

If you need to, you could build a persistent daemon that occasionally
checked for new data to import (say, once every 30 seconds) and would
spawn a separate thread for each bit of data to be imported.

Of course, you'll have to develop a good workflow so that either your
user is notified on that page when the import is completed (possibly
through some ajax-y interface either by polling or using a Comet
system) or, the easy way out, just provide a page that provides a
status, where your user can refresh as they like.  All depends on your
situation.

Hope that helps,
Christopher Allan Webber

"Daryl Spitzer" <[EMAIL PROTECTED]> writes:

> I have a view that takes approximately 5 minutes (plus or minus 4 or
> so) to put together data (culled from other sources, such as our SCM
> and a web service that wraps our bug database) to be passed on to a
> template. Some form of caching may (mostly) solve this problem, but
> I'm worried about two things:
>
> 1) The unlucky user who is the first to go to this page after the
> cached data has expired will have a long wait.
>
> 2) What happens when other users go to other pages, or this page,
> while the view is gathering data?
>
> I don't have any experience deploying Django projects (yet) nor do I
> have any with Apache.  But from what I've read so far, I'm under the
> impression that Apache can be configured to run multiple processes,
> each with its own invocation of Django...right?  (These processes
> will, of course, be unaware of each other unless I take steps to
> synchronize them.)
>
> I think the proper solution is to have a separate process periodically
> put together the data that my view does now, and serialize (pickle) it
> or put it in the database. Then my view will just read and display the
> most-recently generated data.
>
> Do you agree?  Do you have any advice?  Should I run this separate
> process from within Django (somehow), or as a cronjob?
>
> --
> Daryl Spitzer
>
> 

--~--~-~--~~~---~--~~
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: Pre-processing and preparing data in a separate thread or process?

2008-04-15 Thread Daryl Spitzer

>  If you need to, you could build a persistent daemon that occasionally
>  checked for new data to import (say, once every 30 seconds) and would
>  spawn a separate thread for each bit of data to be imported.

I think this is what I'll do.  I can't quickly check whether there is
new data to import, so I think I'll have the daemon pickle the data
into a temporary file (and when done, replace the existing file).  My
view can then unpickle from that file.  (I'll probably have it run
every 10 minutes or so, unless it gets a signal to start ASAP.)

The daemon has to read from the Django project's database; is it
possible (and safe) to have it use Django's ORM to do so?

> ...or, the easy way out, just provide a page that provides a status,
> where your user can refresh as they like.

I'll have the daemon include a datetime value in the pickled data
which can be displayed in the page, and add a refresh button that will
trigger the signal I describe above.

Thanks Christopher.

--
Daryl


On Tue, Apr 15, 2008 at 10:17 AM, Christopher Allan Webber
<[EMAIL PROTECTED]> wrote:
>
>  We developed something that did something similar here.  The import
>  process spawned a daemon which imported the data.  However, in our
>  system only one import could be done at a time (that was actually part
>  of the spec, not bad programming!), so spawning one daemon per import
>  wasn't such a bad idea.
>
>  If you need to, you could build a persistent daemon that occasionally
>  checked for new data to import (say, once every 30 seconds) and would
>  spawn a separate thread for each bit of data to be imported.
>
>  Of course, you'll have to develop a good workflow so that either your
>  user is notified on that page when the import is completed (possibly
>  through some ajax-y interface either by polling or using a Comet
>  system) or, the easy way out, just provide a page that provides a
>  status, where your user can refresh as they like.  All depends on your
>  situation.
>
>  Hope that helps,
>  Christopher Allan Webber
>
>
>
>  "Daryl Spitzer" <[EMAIL PROTECTED]> writes:
>
>  > I have a view that takes approximately 5 minutes (plus or minus 4 or
>  > so) to put together data (culled from other sources, such as our SCM
>  > and a web service that wraps our bug database) to be passed on to a
>  > template. Some form of caching may (mostly) solve this problem, but
>  > I'm worried about two things:
>  >
>  > 1) The unlucky user who is the first to go to this page after the
>  > cached data has expired will have a long wait.
>  >
>  > 2) What happens when other users go to other pages, or this page,
>  > while the view is gathering data?
>  >
>  > I don't have any experience deploying Django projects (yet) nor do I
>  > have any with Apache.  But from what I've read so far, I'm under the
>  > impression that Apache can be configured to run multiple processes,
>  > each with its own invocation of Django...right?  (These processes
>  > will, of course, be unaware of each other unless I take steps to
>  > synchronize them.)
>  >
>  > I think the proper solution is to have a separate process periodically
>  > put together the data that my view does now, and serialize (pickle) it
>  > or put it in the database. Then my view will just read and display the
>  > most-recently generated data.
>  >
>  > Do you agree?  Do you have any advice?  Should I run this separate
>  > process from within Django (somehow), or as a cronjob?
>  >
>  > --
>  > Daryl Spitzer
>  >
>  >
>
>  >
>

--~--~-~--~~~---~--~~
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: QS-RF: something strange happens with model inharitance

2008-04-15 Thread Michael
manage.py syncdb doesn't create new columns into tables. If you already have
the tables installed and you wish to add another column you are going to
have to do this with SQL directly. There are a few projects out there that
intend to fix this; search this forum a bit and you can probably find links.


This is expected behavior and would act the same throughout all the
branches, trunk and releases.

Hope that helps,

Michael


On Tue, Apr 15, 2008 at 10:52 AM, sector119 <[EMAIL PROTECTED]> wrote:

>
> I have already created models A and B and tables with trunk, now I
> installed qs-rf branch and make C model inharit from already created
> A, B models, but when I run manage.py sqlall my_app_with_C_model I do
> not see any columns from C model :(
>
> But everything works fine if I create all models from scratch..
>
> Any thoughts?
> >
>

--~--~-~--~~~---~--~~
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: Images

2008-04-15 Thread Rajesh Dhawan

On Apr 15, 12:06 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> I have searched high and low to make it possible for me to display an
> image via Django in an html template and it fail bombs so hard.

Can you put that in developer-friendly terms? :)

- What error do you get? Is here an error trace you can share?
- What's your template code excerpt that's supposed to create the HMTL
img tag?

-Rajesh D

--~--~-~--~~~---~--~~
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: One app installed several times

2008-04-15 Thread Rajesh Dhawan

Hi Thomas,

> I just got an application installed several times in one project.
> It was important for me, that each instance of the application
> has it on tables.
>
> Here is who I did it. Feedback welcome!
>

>
> Any thoughts how to do this better?

You mention above that it was important to you to have multiple
instances of the app models in your DB. Can you explain the reason
behind this so people can see if there's a way to do this better?

-Rajesh D
--~--~-~--~~~---~--~~
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: primary key type in customized save() method

2008-04-15 Thread Rajesh Dhawan

On Apr 15, 10:04 am, aabele <[EMAIL PROTECTED]> wrote:
> I have a customized save() method in model. If the record ir new
> (without ID) - then self.id type is unicode, otherwise self.id is
> integer. So when I try to do a  many-to-many relationship search - in
> first case it doesn't work, in second - works like a charm.
>
> def save(self):
> super(message, self).save()
> for single_group in self.group.all():
> print '%r' % single_group.id
>
> Is this some kind of bug in django?

What is your custom save() above doing other than printing out the
many to many objects' ids?

You say that the m2m search doesn't work. Do you want to explain how
you have implemented this search that's not working (the queryset you
use, for example)?


--~--~-~--~~~---~--~~
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: QuerySet behavior using extra()

2008-04-15 Thread Karen Tracey
On Tue, Apr 15, 2008 at 9:48 AM, Aaron <[EMAIL PROTECTED]> wrote:

>
> I have a model (Sale) that has latitude and longitude fields. I'm
> trying to take one Sale object and find others within a certain radius
> (using the great circle formula). When I do this using the extra()
> QuerySet modifier, it returns a queryset with all the Sale objects in
> the database. But when I manually execute the raw SQL query that's
> being run (according to connection.queries), it returns the result
> that I'm expecting.
>
> I'm using version 0.97-pre-SVN-7121 with MySQL.
>

What version of MySQL and which Django mysql backend?  Trying to recreate
with MySQL 5.0.45 the count() on the query set  below raises a warning.
With the current mysql backend that gets turned into an exception thrown, so
I get no result.  When I tried backing up to using the mysql_old backend,
the warning doesn't (apparently) get turned into an exception (though I
still see it printed on the console), and the count returns the (incorrect)
result of all the rows in the table.  So I think you must be using the old
mysql backend?  But I don't understand why you do not see the warning I do.

My results are indicated below...


> Am I doing something wrong?
>
> From my shell session:
>
> >>> from data.models import Sale
> >>> from django.db import connection
> >>>
> >>> this_sale = Sale.objects.order_by('?')[0]
> >>> distance_query = "acos( SIN( PI( ) * %s /180 ) * SIN( PI( ) *
> `data_sale`.`latitude` /180 ) + COS( PI( ) * %s /180 ) * COS( PI( ) *
> `data_sale`.`latitude` /180 ) * COS( PI( ) * `data_sale`.`longitude` /180 -
> PI( ) * %s /180 ) ) * 3963.191" % (this_sale.latitude, this_sale.latitude,
> this_sale.longitude)
> >>>
> >>> nearby_sales = Sale.objects.extra(where=['%s < %s'],
> params=[distance_query, .5])
> >>> nearby_sales.count()


Here I get:

/homedir/django/trunk/django/db/backends/mysql_old/base.py:48: Warning:
Truncated incorrect DOUBLE value: 'acos( SIN( PI( ) * 99.0 /180 ) * SIN( PI(
) * `data_sale`.`latitude` /180 ) + COS( PI( ) * 99.0 /180 ) * COS( PI( ) *
`data_sale'
  return self.cursor.execute(sql, params)
3L

(For the data, I mocked up, there are 3 rows in the table but the correct
answer should be 1.)

Note the quote before acos( in the warning.  I believe the problem is that
strings you specify in params for the extra are automatically quoted, which
you do not want to be done to your distance_query parameter.  To avoid
having the distance_query parameter quoted do something like this:

>>> where='%s < %%s' % distance_query
>>> nearby_sales = Sale.objects.extra(where=[where], params=[.5])
>>> nearby_sales.count()
1L


>
> 52448L
> >>>
> >>> query = connection.queries[-1]['sql']
> >>> query
> u'SELECT COUNT(*) FROM `data_sale` WHERE acos( SIN( PI( ) * 37.41915 /
> 180 ) * SIN( PI( ) * `data_sale`.`latitude` /180 ) + COS( PI( ) *
> 37.41915 /180 ) * COS( PI( ) * `data_sale`.`latitude` /180 ) *
> COS( PI( ) * `data_sale`.`longitude` /180 - PI( ) * -76.514234 /
> 180 ) ) * 3963.191 < 0.5'
> >>> cursor = connection.cursor()
> >>> cursor.execute(query)
> 1L
> >>> cursor.fetchone()[0]
> 34L


connection.queries doesn't exactly mimic the backend quoting behavior,
apparently.

Karen

--~--~-~--~~~---~--~~
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: Images

2008-04-15 Thread Michael Wieher

in views:
get the username
set a variable named media-root to be an absolute url, not relative
(where static media lives, not django-processed stuff)
send username to a function that returns a list of image-paths
relative to the media-root
concatenate the media-root variable to this list of paths
pass the list of paths to the template
have the template load the images using these absolute urls

you will also have to configure apache's httpd.conf file such that it
recognizes this media-url
google "static media django" and you'll find the right page for this

On Tue, Apr 15, 2008 at 12:39 PM, Rajesh Dhawan <[EMAIL PROTECTED]> wrote:
>
>  On Apr 15, 12:06 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
>  > I have searched high and low to make it possible for me to display an
>  > image via Django in an html template and it fail bombs so hard.
>
>  Can you put that in developer-friendly terms? :)
>
>  - What error do you get? Is here an error trace you can share?
>  - What's your template code excerpt that's supposed to create the HMTL
>  img tag?
>
>  -Rajesh D
>
>  >
>

--~--~-~--~~~---~--~~
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: Custom SQL Escaping apostrophe

2008-04-15 Thread AJ

I read the related article, but i'm still having trouble with a few
items.  The first is that it seems like I have to  pass the string
into execute and can't store it in a variable.

I tried this:

kw = 'test'

sql = """
SELECT MAX(`table`.`id`)
FROM `table`
WHERE `table`.`name` LIKE %s
GROUP BY `table`.`original_id`;"""

cursor.execute(sql, [kw])

and I get the error "Not all arguments converted during string
formatting"

I'd rather do it that way so that I can read the query better.  This
works however:

cursor.execute("SELECT MAX(`table`.`id`) FROM `table` WHERE
`table`.`name` LIKE %s GROUP BY `table`.`original_id`;", [kw])

The 2nd issue comes from not knowing how to do a query with like this:

`some`.`field` like '%est%';

I try this:

cursor.execute("SELECT MAX(`table`.`id`) FROM `table` WHERE
`table`.`name` LIKE '%%%s%%' GROUP BY `table`.`original_id`;", [kw])

And I get a sql error, it looks like there are quotes going on the
inside of the %'s:

You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near '%'test'% GROUP BY...

On Apr 15, 12:02 pm, Jonathan Ballet <[EMAIL PROTECTED]> wrote:
> AJ wrote:
>
> [...]> sql = """
> > SELECT MAX(`table`.`id`)
> > FROM `table`
> > WHERE `table`.`name` LIKE '%(kw)s'
> > GROUP BY `table`.`original_id`;"""
>
> > sql = sql % {'kw' : '%%' + query + '%%'}
> > cursor.execute(sql)
>
> [...]
>
> This is the wrong way to do this, and your problem explains why.
>
> Take a look at [1] ; you were right, the db module handles those things for 
> you.
> Typically, you use "%s" in your query where you want to put an external 
> value, you give a list of
> values to the "execute" method and the database's backend will correctly 
> handle the value's
> quotation for you.
>
> In addition to protect you from SQL injections, it will give you more 
> portability between different
> databases (since they don't handle quotations the same way).
>
>   - Jonathan
>
> [1] :http://www.djangoproject.com/documentation/model-api/#executing-custo...
--~--~-~--~~~---~--~~
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: QS-RF: maximum recursion depth exceeded in cmp

2008-04-15 Thread Michael
What I am trying to do is reproduce your problem. So I laid out two simple
classes:

CHOICES = (
(1,'Choice 1'),
(2, 'Choice 2')
)

class FirstClass(models.Model):
parent = models.ForeignKey('self', blank=True, null=True)
choicelist = models.PositiveSmallIntegerField(choices=CHOICES)

class SecondClass(models.Model):
parent = models.ForeignKey('self', blank=True, null=True)
choice = models.ForeignKey(FirstClass)

in which I am trying to get to the problem. In the shell I am able to see
what is going on:

>>> a = FirstClass(choicelist=1)
>>> a.save()
>>> b = SecondClass(choice=a)
>>> b.save()
>>> b.choice.get_choicelist_display()
u'Choice 1'

This test does exactly what it is supposed to do.

I still am missing what is causing this error. It is most likely happening
in a loop of some sort, which is somewhere else in your template. Is there a
loop in you template? Go into the shell and try to extract the data from the
user object like above. My bet is that that api works exactly like you
expect it to. There is something else. Is there anymore traceback? Try to
reproduce in the shell, that will help us pinpoint exactly where the error
is coming from.

One more thing: What are you doing with class Import? That doesn't make any
sense like that to me.

Also, I realize that the fact that you are using the QS-RF branch is
important for us to know what base code you are working from, but this is
the second post you have posted that doesn't really have anything specific
to that branch. You will get more people to help you out if you leave that
out of the subject and mention it inside the body of the message where it
becomes apparent that the problem is not QS-RF specific.




On Tue, Apr 15, 2008 at 10:59 AM, sector119 <[EMAIL PROTECTED]> wrote:

>
> Template error
>
> In template /home/sector119/devel/eps_src/eps/templates/base.html,
> error at line 23
> Caught an exception while rendering: maximum recursion depth exceeded
> in cmp
>
> 23  {{ user.office.location.get_type_display }}.
> 24  {{ user.office.location.name }},
> 25  {{ user.office.name }},
>
> --
>
> class Location(models.Model):
>id = models.IntegerField(_('Id'), primary_key=True)
>parent = models.ForeignKey('self', verbose_name=_('Location parent
> id:'), null=True, blank=True,  related_name='child_set')
>name = models.CharField(_('Location'), help_text=_('Office or
> person location.'), max_length=32)
>type = models.PositiveSmallIntegerField(_('Location type'),
> choices=LOCATION_TYPE_CHOICES)
>
>def __unicode__(self):
>return self.name
>
>class Import:
>pass
>
>class Meta:
>verbose_name = _('Location')
>verbose_name_plural = _('Locations')
>ordering = ['parent', 'id']
>
>class Admin:
>pass
>
>
> --
>
> class OrganizationOffice(models.Model):
>parent = models.ForeignKey('self', verbose_name=_('Parent
> office:'), null=True, blank=True)
>location = models.ForeignKey(Location,
> verbose_name=_('Location:'))
>name = models.CharField(_('Office'), max_length=50)
>bank = models.CharField(_('Bank'), max_length=50, null=True,
> blank=True)
>account = fields.PositiveBigIntegerField(_('Account'), null=True,
> blank=True)
>bic = models.PositiveIntegerField(_('BIC'), help_text=_('Bank
> identifier code.'), null=True, blank=True)
>code = models.PositiveIntegerField(_('Code'),
> help_text=_('Enterprise code.'), null=True, blank=True)
>in_testmode = models.BooleanField(_('Office is in test mode'),
> default=False)
>day_is_open = models.BooleanField(_('Transaction day is open'),
> default=False)
>
>def __unicode__(self):
>return self.name
>
>class Import:
>pass
>
>class Meta:
>verbose_name = _('Office')
>verbose_name_plural = _('Offices')
>ordering = ['location', 'parent', 'id']
>
>class Admin:
>search_fields = ('^id', '^location__name', 'name')
>
> >
>

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



sqlite and django tutorials setup

2008-04-15 Thread sebey

ok so I have latest verson of sqlite and django 96.0 and i'm reading
the tutorial how do I set up sqlite for the tut?
--~--~-~--~~~---~--~~
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: Pre-processing and preparing data in a separate thread or process?

2008-04-15 Thread Brian Rosner

> Of course, you'll have to develop a good workflow so that either your
> user is notified on that page when the import is completed (possibly
> through some ajax-y interface either by polling or using a Comet
> system) or, the easy way out, just provide a page that provides a
> status, where your user can refresh as they like.  All depends on your
> situation.

I did something similar to this as well. My notification was just an 
e-mail to the user with the information that they needed to know 
whether the import was successful or not and what field failed 
validation. Of course it can be improved, but it was the simplest thing 
to do to make it work :)



--~--~-~--~~~---~--~~
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: working example of django.contrib.localflavor ?

2008-04-15 Thread e

Is this worthy of submitting a ticket to fix the documentation for?

On Apr 14, 2:10 pm, "Karen Tracey" <[EMAIL PROTECTED]> wrote:
> On Mon, Apr 14, 2008 at 11:58 AM, e <[EMAIL PROTECTED]> wrote:
>
> > I have a form set up and all working, its basically straight out of
> > the Form Processing chapter of the django book:
>
> > class ContactForm(forms.Form):
> >    email = forms.EmailField(required=True)
> >    message = forms.CharField()
> >    phone_number = forms.CharField()
>
> > def contact(request):
> >    form = ContactForm()
> >    return render_to_response('contact.html', {'form': form})
>
> > Now this works just fine, but I want to use
> > django.contrib.localflavor.us.forms.USPhoneNumberFIeld instead of the
> > CharField for the phone_number.  When I replace it with this line:
> > phone_number = us.forms.USPhoneNumberField(max_length=100)
>
> > I get this error:
>
> > ViewDoesNotExist: Tried contact in module mysite.contact.views. Error
> > was: 'module' object has no attribute 'forms'
>
> > What am I doing wrong?
>
> I'm assuming you have:
>
> from django.contrib.localflavor import us
>
> somewhere before you try to define phone_number as us.forms.USPhone...
>
> Instead try:
>
> from django.contrib.localflavor.us.forms import USPhoneNumberField
> phone_number = USPhoneNumberField()
>
> This works for me.  I don't know why the documentation 
> (http://www.djangoproject.com/documentation/localflavor/) shows an example
> using the first kind of import, since it does not appear that things are set
> up for that to work.
>
> Karen
--~--~-~--~~~---~--~~
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: Looping....

2008-04-15 Thread Michael
I feel like something like this already exists somewhere, but you can simply
write a filter that turns a number into a range:

so in your templates you would have:

{% for i in 10|range %}
...
{%endfor%}

and your template filter would simply be:

from django.template.defaultfilters import stringfilter

@stringfilter
def range(value): return range(int(value))




On Tue, Apr 15, 2008 at 12:07 PM, Kenneth Gonsalves <[EMAIL PROTECTED]>
wrote:

>
>
> On 15-Apr-08, at 9:04 PM, Darryl Ross wrote:
>
> > Duke wrote:
> >> They are looping over a list
> >> I am looking for
> >> for (i = 0; i < 10; i++) {
> >>  printf("Hello,  World!);
> >> }
> >> link for looping statement
> >
> >
> > I am not aware of any tag that will allow you to do that, out of
> > the box. You have two options, the first is to create a custom
> > template tag that do what you want[1]. This shouldn't really be
> > terribly difficult to do.
> >
> > The second option would be to just pass in a variable into the
> > context with a list containing the number of items of the number of
> > times you want to loop. Using generic views, this could be done in
> > your urls.py like:
> >
> > ...
> >  ('^$', 'direct_to_template',
> > { 'template_name': 'homepage.html',
> >   'extra_context': {'looper': range(10) }})
> > ...
> >
> > Then you can use the standard {% for %} tag:
> >
> > {% for i in looper %}
> >   {{i}}
> > {% endfor %}
> >
> >
> > [1] http://www.djangoproject.com/documentation/templates_python/
> > #extending-the-template-system
> >
>
> where is the use case for this? I cannot conceive of any situation
> where one would want to loop over an arbitrary number.
>
> --
>
> regards
> kg
> http://lawgon.livejournal.com
> http://nrcfosshelpline.in/code/
>
>
>
>
> >
>

--~--~-~--~~~---~--~~
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: working example of django.contrib.localflavor ?

2008-04-15 Thread Karen Tracey
On Tue, Apr 15, 2008 at 2:19 PM, e <[EMAIL PROTECTED]> wrote:

> Is this worthy of submitting a ticket to fix the documentation for?


I'd say so.  Near as I can tell if you cut & paste the example from the
documentation it doesn't work.  That seems wrong, and worth fixing.

Karen


>
> On Apr 14, 2:10 pm, "Karen Tracey" <[EMAIL PROTECTED]> wrote:
> > On Mon, Apr 14, 2008 at 11:58 AM, e <[EMAIL PROTECTED]> wrote:
> >
> > > I have a form set up and all working, its basically straight out of
> > > the Form Processing chapter of the django book:
> >
> > > class ContactForm(forms.Form):
> > >email = forms.EmailField(required=True)
> > >message = forms.CharField()
> > >phone_number = forms.CharField()
> >
> > > def contact(request):
> > >form = ContactForm()
> > >return render_to_response('contact.html', {'form': form})
> >
> > > Now this works just fine, but I want to use
> > > django.contrib.localflavor.us.forms.USPhoneNumberFIeld instead of the
> > > CharField for the phone_number.  When I replace it with this line:
> > > phone_number = us.forms.USPhoneNumberField(max_length=100)
> >
> > > I get this error:
> >
> > > ViewDoesNotExist: Tried contact in module mysite.contact.views. Error
> > > was: 'module' object has no attribute 'forms'
> >
> > > What am I doing wrong?
> >
> > I'm assuming you have:
> >
> > from django.contrib.localflavor import us
> >
> > somewhere before you try to define phone_number as us.forms.USPhone...
> >
> > Instead try:
> >
> > from django.contrib.localflavor.us.forms import USPhoneNumberField
> > phone_number = USPhoneNumberField()
> >
> > This works for me.  I don't know why the documentation (
> http://www.djangoproject.com/documentation/localflavor/) shows an example
> > using the first kind of import, since it does not appear that things are
> set
> > up for that to work.
> >
> > Karen
> >
>

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



model_to_dict including foreign key's fields

2008-04-15 Thread Panos Laganakos

I am using 0.96.1, but I wanted to prepopulate a form from a model. So
I grabbed
`model_to_dict` from trunk. It works (I just had to replace `pk` with
`id`),
but, I need to be able to get data from a foreign key field.

The model is a profile, which has a ForeignKey to `User`. Is it
possible to make
`model_to_dict`, grab the `User` fields too?
--~--~-~--~~~---~--~~
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: Pre-processing and preparing data in a separate thread or process?

2008-04-15 Thread Christopher Allan Webber

"Daryl Spitzer" <[EMAIL PROTECTED]> writes:

>>  If you need to, you could build a persistent daemon that occasionally
>>  checked for new data to import (say, once every 30 seconds) and would
>>  spawn a separate thread for each bit of data to be imported.
>
> I think this is what I'll do.  I can't quickly check whether there is
> new data to import, so I think I'll have the daemon pickle the data
> into a temporary file (and when done, replace the existing file).  My
> view can then unpickle from that file.  (I'll probably have it run
> every 10 minutes or so, unless it gets a signal to start ASAP.)
>
> The daemon has to read from the Django project's database; is it
> possible (and safe) to have it use Django's ORM to do so?

We haven't had any problems yet.  I think you should be fine.

>> ...or, the easy way out, just provide a page that provides a status,
>> where your user can refresh as they like.
>
> I'll have the daemon include a datetime value in the pickled data
> which can be displayed in the page, and add a refresh button that will
> trigger the signal I describe above.
>
> Thanks Christopher.
>
> --
> Daryl
>
>
> On Tue, Apr 15, 2008 at 10:17 AM, Christopher Allan Webber
> <[EMAIL PROTECTED]> wrote:
>>
>>  We developed something that did something similar here.  The import
>>  process spawned a daemon which imported the data.  However, in our
>>  system only one import could be done at a time (that was actually part
>>  of the spec, not bad programming!), so spawning one daemon per import
>>  wasn't such a bad idea.
>>
>>  If you need to, you could build a persistent daemon that occasionally
>>  checked for new data to import (say, once every 30 seconds) and would
>>  spawn a separate thread for each bit of data to be imported.
>>
>>  Of course, you'll have to develop a good workflow so that either your
>>  user is notified on that page when the import is completed (possibly
>>  through some ajax-y interface either by polling or using a Comet
>>  system) or, the easy way out, just provide a page that provides a
>>  status, where your user can refresh as they like.  All depends on your
>>  situation.
>>
>>  Hope that helps,
>>  Christopher Allan Webber
>>
>>
>>
>>  "Daryl Spitzer" <[EMAIL PROTECTED]> writes:
>>
>>  > I have a view that takes approximately 5 minutes (plus or minus 4 or
>>  > so) to put together data (culled from other sources, such as our SCM
>>  > and a web service that wraps our bug database) to be passed on to a
>>  > template. Some form of caching may (mostly) solve this problem, but
>>  > I'm worried about two things:
>>  >
>>  > 1) The unlucky user who is the first to go to this page after the
>>  > cached data has expired will have a long wait.
>>  >
>>  > 2) What happens when other users go to other pages, or this page,
>>  > while the view is gathering data?
>>  >
>>  > I don't have any experience deploying Django projects (yet) nor do I
>>  > have any with Apache.  But from what I've read so far, I'm under the
>>  > impression that Apache can be configured to run multiple processes,
>>  > each with its own invocation of Django...right?  (These processes
>>  > will, of course, be unaware of each other unless I take steps to
>>  > synchronize them.)
>>  >
>>  > I think the proper solution is to have a separate process periodically
>>  > put together the data that my view does now, and serialize (pickle) it
>>  > or put it in the database. Then my view will just read and display the
>>  > most-recently generated data.
>>  >
>>  > Do you agree?  Do you have any advice?  Should I run this separate
>>  > process from within Django (somehow), or as a cronjob?
>>  >
>>  > --
>>  > Daryl Spitzer
>>  >
>>  >
>>
>>  >
>>
>
> 

--~--~-~--~~~---~--~~
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: Custom SQL Escaping apostrophe

2008-04-15 Thread AJ

Ok, so I got this to work.  I couldn't find anything online about
using the like statement in queries with the python db api's, so here
is what I did, in case anyone else runs into this.

#this would actually come from a POST request
kw = "test"

sql = """
SELECT MAX(`table`.`id`)
FROM `table`
WHERE `table`.`name` LIKE %s
GROUP BY `table`.`original_id`;"""

kw = "%" + kw + "%"
cursor.execute(sql, (kw,))

So the db module handles the quotes as Jonathan stated, so no need for
those.  For some reason you need to add the % to the keyword then pass
it as a tuple to the 2nd paramater of the execute function.  Using %
in the actual query does not work, even if you escape it with a double
%%.

Not sure if this is the best way but it seems to work as expected now.

On Apr 15, 2:03 pm, AJ <[EMAIL PROTECTED]> wrote:
> I read the related article, but i'm still having trouble with a few
> items.  The first is that it seems like I have to  pass the string
> into execute and can't store it in a variable.
>
> I tried this:
>
> kw = 'test'
>
> sql = """
> SELECT MAX(`table`.`id`)
> FROM `table`
> WHERE `table`.`name` LIKE %s
> GROUP BY `table`.`original_id`;"""
>
> cursor.execute(sql, [kw])
>
> and I get the error "Not all arguments converted during string
> formatting"
>
> I'd rather do it that way so that I can read the query better.  This
> works however:
>
> cursor.execute("SELECT MAX(`table`.`id`) FROM `table` WHERE
> `table`.`name` LIKE %s GROUP BY `table`.`original_id`;", [kw])
>
> The 2nd issue comes from not knowing how to do a query with like this:
>
> `some`.`field` like '%est%';
>
> I try this:
>
> cursor.execute("SELECT MAX(`table`.`id`) FROM `table` WHERE
> `table`.`name` LIKE '%%%s%%' GROUP BY `table`.`original_id`;", [kw])
>
> And I get a sql error, it looks like there are quotes going on the
> inside of the %'s:
>
> You have an error in your SQL syntax; check the manual that
> corresponds to your MySQL server version for the right syntax to use
> near '%'test'% GROUP BY...
>
> On Apr 15, 12:02 pm, Jonathan Ballet <[EMAIL PROTECTED]> wrote:
>
> > AJ wrote:
>
> > [...]> sql = """
> > > SELECT MAX(`table`.`id`)
> > > FROM `table`
> > > WHERE `table`.`name` LIKE '%(kw)s'
> > > GROUP BY `table`.`original_id`;"""
>
> > > sql = sql % {'kw' : '%%' + query + '%%'}
> > > cursor.execute(sql)
>
> > [...]
>
> > This is the wrong way to do this, and your problem explains why.
>
> > Take a look at [1] ; you were right, the db module handles those things for 
> > you.
> > Typically, you use "%s" in your query where you want to put an external 
> > value, you give a list of
> > values to the "execute" method and the database's backend will correctly 
> > handle the value's
> > quotation for you.
>
> > In addition to protect you from SQL injections, it will give you more 
> > portability between different
> > databases (since they don't handle quotations the same way).
>
> >   - Jonathan
>
> > [1] 
> > :http://www.djangoproject.com/documentation/model-api/#executing-custo...
--~--~-~--~~~---~--~~
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: QuerySet behavior using extra()

2008-04-15 Thread Aaron

That worked. Thanks.

For the record, I'm using MySQL 4.1.21 and MySQLdb 1.2.2-final. Not
sure why I wasn't getting the error.

On Apr 15, 1:53 pm, "Karen Tracey" <[EMAIL PROTECTED]> wrote:
> On Tue, Apr 15, 2008 at 9:48 AM, Aaron <[EMAIL PROTECTED]> wrote:
>
> > I have a model (Sale) that has latitude and longitude fields. I'm
> > trying to take one Sale object and find others within a certain radius
> > (using the great circle formula). When I do this using the extra()
> > QuerySet modifier, it returns a queryset with all the Sale objects in
> > the database. But when I manually execute the raw SQL query that's
> > being run (according to connection.queries), it returns the result
> > that I'm expecting.
>
> > I'm using version 0.97-pre-SVN-7121 with MySQL.
>
> What version of MySQL and which Django mysql backend?  Trying to recreate
> with MySQL 5.0.45 the count() on the query set  below raises a warning.
> With the current mysql backend that gets turned into an exception thrown, so
> I get no result.  When I tried backing up to using the mysql_old backend,
> the warning doesn't (apparently) get turned into an exception (though I
> still see it printed on the console), and the count returns the (incorrect)
> result of all the rows in the table.  So I think you must be using the old
> mysql backend?  But I don't understand why you do not see the warning I do.
>
> My results are indicated below...
>
>
>
> > Am I doing something wrong?
>
> > From my shell session:
>
> > >>> from data.models import Sale
> > >>> from django.db import connection
>
> > >>> this_sale = Sale.objects.order_by('?')[0]
> > >>> distance_query = "acos( SIN( PI( ) * %s /180 ) * SIN( PI( ) *
> > `data_sale`.`latitude` /180 ) + COS( PI( ) * %s /180 ) * COS( PI( ) *
> > `data_sale`.`latitude` /180 ) * COS( PI( ) * `data_sale`.`longitude` /180 -
> > PI( ) * %s /180 ) ) * 3963.191" % (this_sale.latitude, this_sale.latitude,
> > this_sale.longitude)
>
> > >>> nearby_sales = Sale.objects.extra(where=['%s < %s'],
> > params=[distance_query, .5])
> > >>> nearby_sales.count()
>
> Here I get:
>
> /homedir/django/trunk/django/db/backends/mysql_old/base.py:48: Warning:
> Truncated incorrect DOUBLE value: 'acos( SIN( PI( ) * 99.0 /180 ) * SIN( PI(
> ) * `data_sale`.`latitude` /180 ) + COS( PI( ) * 99.0 /180 ) * COS( PI( ) *
> `data_sale'
>   return self.cursor.execute(sql, params)
> 3L
>
> (For the data, I mocked up, there are 3 rows in the table but the correct
> answer should be 1.)
>
> Note the quote before acos( in the warning.  I believe the problem is that
> strings you specify in params for the extra are automatically quoted, which
> you do not want to be done to your distance_query parameter.  To avoid
> having the distance_query parameter quoted do something like this:
>
> >>> where='%s < %%s' % distance_query
> >>> nearby_sales = Sale.objects.extra(where=[where], params=[.5])
> >>> nearby_sales.count()
>
> 1L
>
>
>
> > 52448L
>
> > >>> query = connection.queries[-1]['sql']
> > >>> query
> > u'SELECT COUNT(*) FROM `data_sale` WHERE acos( SIN( PI( ) * 37.41915 /
> > 180 ) * SIN( PI( ) * `data_sale`.`latitude` /180 ) + COS( PI( ) *
> > 37.41915 /180 ) * COS( PI( ) * `data_sale`.`latitude` /180 ) *
> > COS( PI( ) * `data_sale`.`longitude` /180 - PI( ) * -76.514234 /
> > 180 ) ) * 3963.191 < 0.5'
> > >>> cursor = connection.cursor()
> > >>> cursor.execute(query)
> > 1L
> > >>> cursor.fetchone()[0]
> > 34L
>
> connection.queries doesn't exactly mimic the backend quoting behavior,
> apparently.
>
> Karen
--~--~-~--~~~---~--~~
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: Dynamically limiting choices in admin.

2008-04-15 Thread Justin Bronn

Rodrigo,

I've found this to be a common use-case among many projects of mine.
The admin becomes completely unusable if you have hundreds of
thousands of possibilities for ForeignKey and/or ManyToMany
relations.  I've created a `ModelAdmin` (newforms-admin) subclass
called `LimitedRelatedAdmin` that does what I think you're looking to
accomplish.  It does require a small patch (2 changes) to newforms-
admin in order to accommodate the AJAX goodness -- email me for a link
to my private mercurial if you wish to examine the code.

-Justin
--~--~-~--~~~---~--~~
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: Custom SQL Escaping apostrophe

2008-04-15 Thread Jonathan Ballet

[ I saw you next email, but I answer to this one, because errors are here ]

Le Tue, 15 Apr 2008 11:03:03 -0700 (PDT), AJ <[EMAIL PROTECTED]> a écrit :

> kw = 'test'
> 
> sql = """
> SELECT MAX(`table`.`id`)
> FROM `table`
> WHERE `table`.`name` LIKE %s
> GROUP BY `table`.`original_id`;"""
> 
> cursor.execute(sql, [kw])
> 
> and I get the error "Not all arguments converted during string
> formatting"

This _should_ work, since "execute" expect an iterable as its second argument 
(I guess).
Maybe you can show us the traceback ?

Be aware that you cannot use variables interpolation in the declaration of the 
SQL variable.
I mean, you cannot do this :

sql = "SELECT MAX(id) FROM %s WHERE name LIKE %s" % 'table'

since Python expects to find two values, and it raises the kind of error you 
told us.
However, you can do something like this :

sql = "SELECT MAX(id) FROM %s WHERE name LIKE %%s" % 'table'

(notice the double "%").

[...]

> cursor.execute("SELECT MAX(`table`.`id`) FROM `table` WHERE
> `table`.`name` LIKE '%%%s%%' GROUP BY `table`.`original_id`;", [kw])
> 
> And I get a sql error, it looks like there are quotes going on the
> inside of the %'s:
> 
> You have an error in your SQL syntax; check the manual that
> corresponds to your MySQL server version for the right syntax to use
> near '%'test'% GROUP BY...

You already find the correct answer, but let's explain what's happening there.
You _must_ not quote your variables into your SQL query : this is the database 
backend's job, and
by passing to "cursor.execute" an iterable as its second argument, you tell it 
to handle
automatically the quotation of values.

In your previous example, you already put quotation marks around the "%%%s%%". 
However, the backend
doesn't know about it, so it automatically add quotations marks around "%s".
So, the following instruction :

cursor.execute("SELECT MAX(id) FROM table WHERE name LIKE '%%%s%%'", 
['myvalue'])

is translated into the following SQL query :

SELECT MAX(id) FROM table WHERE name LIKE '%%'myvalue'%%'

... and obviously, it doesn't work.

So, let do the quotation's job to the database backend.
And so, if you want to add wildcards character into your value, you must add it 
to your value, not
in the SQL query (but you already proposed a solution in your last email ;) ).

I hope it clarifies some obscur points ...

 - Jonathan


signature.asc
Description: PGP signature


Re: Images

2008-04-15 Thread [EMAIL PROTECTED]

The error I get is the white box with the red X which means it can't
find the image.

On Apr 15, 1:39 pm, Rajesh Dhawan <[EMAIL PROTECTED]> wrote:
> On Apr 15, 12:06 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
>
> > I have searched high and low to make it possible for me to display an
> > image via Django in an html template and it fail bombs so hard.
>
> Can you put that in developer-friendly terms? :)
>
> - What error do you get? Is here an error trace you can share?
> - What's your template code excerpt that's supposed to create the HMTL
> img tag?
>
> -Rajesh D
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



  1   2   >