Re: modwsgi on suburl

2009-11-25 Thread Some Guy
my bad :). didn't really get his gist. just switched to wsgi myself.

On Nov 25, 11:00 pm, Graham Dumpleton 
wrote:
> On Nov 26, 5:04 pm, Some Guy  wrote:
>
> > WSGIScriptAlias /test
>
> > should be
>
> >  WSGIScriptAlias /
>
> > not really sure what you mean by suburl...
>
> No it shouldn't. What he was doing with the directive is correct.
>
> Provided they are using 1.0 or later, urls.py should be setup the same
> as if site mounted at root URL. That is, do not put the suburl in
> urls.py.
>
> So, can't see anything wrong with what OP was doing.
>
> Graham
>
>
>
> > On Nov 25, 9:47 pm, Amit Sethi  wrote:
>
> > > Hi , can somebody tell me how i should configure mod_wsgi on a suburl I 
> > > want
> > > to set a django project on
>
> > > domain.com/test/
>
> > > so my urls.py at present looks like :
>
> > > urlpatterns = patterns('',
> > >      (r'^(.*)', 'sttp.views.serve'),)
>
> > > and the wgi scrip alias is WSGIScriptAlias /test
> > > /home/amit/sttp-project/django.wsgi
>
> > > --
> > > A-M-I-T S|S

--

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




Re: Alternative model without Database

2009-11-25 Thread ash
I don't know your problem in detail, but as alternative
I recommend read about twisted framework. If you work
with xmlrpc servers and you need in call remote methods,
then it help you. Simple exmaples:
http://twistedmatrix.com/documents/current/web/howto/xmlrpc.html

--

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




Re: modelformset and pagination?

2009-11-25 Thread Some Guy
well, I've looked into it more, and it seems that the max_num argument
to the modelformset_factory constructor is the best way to go. If it
works i'll post it here for those who might find this thread from
google.

On Nov 25, 8:46 pm, Some Guy  wrote:
> I'm having an issue trying to create pagination with a modelformset.
> so far I have...
>
>    SubFormSet = modelformset_factory(Submission, can_delete=True,
> extra=0, form=PricingForm)
> ...
>    objs = Submission.objects.all()
>    formset = SubFormSet(queryset=objs)  <-overriding the basic
> queryset
>    groups = map(None, objs, formset.forms)  <- I need both the objects
> and the forms, iterating over them together in the view
>    paginator = Paginator(groups, 10) <-- standard paginator
>    this_page = paginator.page(ppage)
> ...then render
>
> so, basically, this works for viewing, but submitting doesn't work
> because the management form values (INITIAL_FORMS, FORM_COUNT, etc)
> are wrong, they still hold the values of the whole queryset. I tried
> feeding the formset constructor the object_list from the paginiator,
> but that fails, complaining about "is_ordered" not being there.So my
> considerations are to...
>
> 1.Change the management form values with js (scary at best)
> 2.Slice the queryset (seems like i'd have to duplicate all the
> pagination in my code)
> 3.Try to overwrite the management_form values directly.
> 4.Set the max_num attribute of the model_formset
> 5.beg for help on the mailing list. :)
>
> Anyone have any guidance as to which might be best option? Anyone ever
> done this?
> TIA

--

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




Re: modwsgi on suburl

2009-11-25 Thread Graham Dumpleton


On Nov 26, 5:04 pm, Some Guy  wrote:
> WSGIScriptAlias /test
>
> should be
>
>  WSGIScriptAlias /
>
> not really sure what you mean by suburl...

No it shouldn't. What he was doing with the directive is correct.

Provided they are using 1.0 or later, urls.py should be setup the same
as if site mounted at root URL. That is, do not put the suburl in
urls.py.

So, can't see anything wrong with what OP was doing.

Graham


> On Nov 25, 9:47 pm, Amit Sethi  wrote:
>
>
>
> > Hi , can somebody tell me how i should configure mod_wsgi on a suburl I want
> > to set a django project on
>
> > domain.com/test/
>
> > so my urls.py at present looks like :
>
> > urlpatterns = patterns('',
> >      (r'^(.*)', 'sttp.views.serve'),)
>
> > and the wgi scrip alias is WSGIScriptAlias /test
> > /home/amit/sttp-project/django.wsgi
>
> > --
> > A-M-I-T S|S

--

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




Re: modwsgi on suburl

2009-11-25 Thread Some Guy
WSGIScriptAlias /test

should be

 WSGIScriptAlias /

not really sure what you mean by suburl...

On Nov 25, 9:47 pm, Amit Sethi  wrote:
> Hi , can somebody tell me how i should configure mod_wsgi on a suburl I want
> to set a django project on
>
> domain.com/test/
>
> so my urls.py at present looks like :
>
> urlpatterns = patterns('',
>      (r'^(.*)', 'sttp.views.serve'),)
>
> and the wgi scrip alias is WSGIScriptAlias /test
> /home/amit/sttp-project/django.wsgi
>
> --
> A-M-I-T S|S

--

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




modwsgi on suburl

2009-11-25 Thread Amit Sethi
Hi , can somebody tell me how i should configure mod_wsgi on a suburl I want
to set a django project on

domain.com/test/

so my urls.py at present looks like :

urlpatterns = patterns('',
 (r'^(.*)', 'sttp.views.serve'),)

and the wgi scrip alias is WSGIScriptAlias /test
/home/amit/sttp-project/django.wsgi


-- 
A-M-I-T S|S

--

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




modelformset and pagination?

2009-11-25 Thread Some Guy
I'm having an issue trying to create pagination with a modelformset.
so far I have...

   SubFormSet = modelformset_factory(Submission, can_delete=True,
extra=0, form=PricingForm)
...
   objs = Submission.objects.all()
   formset = SubFormSet(queryset=objs)  <-overriding the basic
queryset
   groups = map(None, objs, formset.forms)  <- I need both the objects
and the forms, iterating over them together in the view
   paginator = Paginator(groups, 10) <-- standard paginator
   this_page = paginator.page(ppage)
...then render

so, basically, this works for viewing, but submitting doesn't work
because the management form values (INITIAL_FORMS, FORM_COUNT, etc)
are wrong, they still hold the values of the whole queryset. I tried
feeding the formset constructor the object_list from the paginiator,
but that fails, complaining about "is_ordered" not being there.So my
considerations are to...

1.Change the management form values with js (scary at best)
2.Slice the queryset (seems like i'd have to duplicate all the
pagination in my code)
3.Try to overwrite the management_form values directly.
4.Set the max_num attribute of the model_formset
5.beg for help on the mailing list. :)

Anyone have any guidance as to which might be best option? Anyone ever
done this?
TIA

--

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




Re: reversing URLs

2009-11-25 Thread Karen Tracey
On Wed, Nov 25, 2009 at 11:23 AM, Tim Valenta wrote:

>
> I had not realized that models.permalink depends on the `sites`
> application.  I had removed this for the sake of simplifying the admin
> options as much as possible for those who would use it.  But, having
> removed that app a long time ago, I now get a different exception.
>
>'servicetrac.django_site' doesn't exist
>
>
It's not permalink that requires sites, it's the "view on site" function.
There's a ticket open on that:

http://code.djangoproject.com/ticket/8960

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




Forms ForeignKeyField does not populate with initial value

2009-11-25 Thread Todd Blanchard
I have a (simplified) model

class Incident(models.Model):
title = models.CharField(max_length=128)
when_reported = models.DateTimeField(auto_now_add=True)
reporter = models.ForeignKey(User)


Where User is from auth.  When used with a ModelForm, this creates a popup 
button with a list of users.  I want it to default to the currently logged in 
user so in my view I have:

def new_incident(request):
   form = IncidentForm(initial={
'reporter': request.user,
'title': 'New Incident',
'when_reported' : datetime.now(),
})

media = form.media
return render_to_response('incidents/new.html',{'form': form, 'media': 
media},context_instance=RequestContext(request))

However the popup button's selection is never set to the current logged in 
user.  I have rendered the current logged in user's name elsewhere on the page, 
it is set.  But the popup selector isn't getting its selection set right.  Any 
tips?  

-Todd Blanchard

--

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




Re: german umlaute on search querys

2009-11-25 Thread Karen Tracey
On Wed, Nov 25, 2009 at 1:54 AM, Hinnack wrote:

> Hi Karen,
>
> thanks for your reply
>
> it means so far I must do a:
> qs = search[query].encode('iso-8859-1')
>
> before I add the qs to a Q object of a queryset. Only in this case I get
> results.
>
> the full codepart looks like:
>
> decoder = simplejson.JSONDecoder()
> search = decoder.decode(request.POST['search'])
> qs = search['caption'].encode('iso-8859-1')
>
> searchstr = urllib.unquote_plus(qs).strip('=!~')
>
> basic.filter( Q(evid__caption__icontains=searchstr) )
>
>
> I do have no DATABASE_OPTIONS set. Maybe that's it?
>

No, there's nothing you need to set specially to get this to work.

It would be interesting to see the repr of search['caption'] before and
after you do the encode('iso-8859-1').

I suspect search['caption'] is originally a Unicode object that was
(incorrectly) constructed from a utf-8 bytestring assuming iso-8859-1
encoding.  That would explain the results you are getting, since encoding
such an incorrectly constructed object to iso-8859-1 will restore it to a
utf-8 bytestring. Django, when handed a bytestring, assumes it is utf-8
encoded and speaks utf-8 to the database, so all works.  If on the other
hand you pass such an incorrectly built unicode object as a unicode object,
Django will encode it using utf-8, which results in two levels utf-8
encoding having been done, and the result won't match actual utf-8 data in
the database.

But it's also just possible that the problem is the data values in the
database, maybe.  Confirmation of where the problem is would come from
knowing the repr of search['caption'] before and after the encode to
iso-8859-1.  Then we'd be sure whether to look more closely at the way in
which search['caption'] is getting built or the database itself.

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




How to instantiate django.test.Client out of django unittest framework

2009-11-25 Thread Alex Dong
Hi all,

The software we're developing uses sphinx search engine whose index
updating process doesn't play well with django's unittest setup, as a
result we have to move all the tests from django to nosetest.  I found
one of your test talk on djangocon and you mentioned that we could
'instantiate Client out of django unittest framework', I've tried but
kept bumping into the `ImportError: No module named urls` exception.

Here is our test code:

#! /usr/bin/env python

import os
os.environ['DJANGO_SETTINGS_MODULE']='hivemind.settings'

from django.test.utils import setup_test_environment
setup_test_environment()

from django.core.management import call_command
from django.test.client import Client
from nose.tools import with_setup

from hivemind import settings
from hivemind.engine.models import *
from hivemind.indexer.models import update_index, search
from hivemind.utils.debugger import dump_tables


def teardown():
dump_tables()

def setup():
call_command('flush', verbosity=0, interactive=False)
update_index()


@with_setup(setup, teardown)
def test_api():
mine_expertise(0)

# following code is using the api to redo the test_engine
# modification parts.
c = Client()

r = c.post('/api/expertise/6/update/', {'threshold':10, 'filter':
5})
assert 200==r.status_code
r = c.get('/api/expertise/6/')
assert 200==r.status_code

Here is the exception:
==
ERROR: hivemind.tests.test_api
--
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/2.6/lib/
python2.6/site-packages/nose-0.11.0-py2.6.egg/nose/case.py", line 183,
in runTest
self.test(*self.arg)
  File "/Users/alexdong/Projects/hivemind/trunk/hivemind/tests.py",
line 70, in test_api
r = c.post('/api/expertise/6/update/', {'threshold':10, 'filter':
5})
  File "/Library/Frameworks/Python.framework/Versions/2.6/lib/
python2.6/site-packages/django/test/client.py", line 318, in post
response = self.request(**r)
  File "/Library/Frameworks/Python.framework/Versions/2.6/lib/
python2.6/site-packages/django/core/handlers/base.py", line 90, in
get_response
request.path_info)
  File "/Library/Frameworks/Python.framework/Versions/2.6/lib/
python2.6/site-packages/django/core/urlresolvers.py", line 222, in
resolve
sub_match = pattern.resolve(new_path)
  File "/Library/Frameworks/Python.framework/Versions/2.6/lib/
python2.6/site-packages/django/core/urlresolvers.py", line 220, in
resolve
for pattern in self.url_patterns:
  File "/Library/Frameworks/Python.framework/Versions/2.6/lib/
python2.6/site-packages/django/core/urlresolvers.py", line 249, in
_get_url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns",
self.urlconf_module)
  File "/Library/Frameworks/Python.framework/Versions/2.6/lib/
python2.6/site-packages/django/core/urlresolvers.py", line 244, in
_get_urlconf_module
self._urlconf_module = import_module(self.urlconf_name)
  File "/Library/Frameworks/Python.framework/Versions/2.6/lib/
python2.6/site-packages/django/utils/importlib.py", line 35, in
import_module
__import__(name)
ImportError: No module named urls

--

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




import twice when run test

2009-11-25 Thread fallhunter
i have this code in my tests.py:

from models import *

and in the models.py I have a signal handler and register it with

post_save.connect( post_save_note, sender=Note )

and when i run test with ./manage.py test main

I found the signal handler was registered twice and executed twice,
and I found it's because the models was imported twice.

can't i put "from models import *" in the test code? what should i do?

--

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




For DateField, render() gets date object in some cases, but unicode datestring in other

2009-11-25 Thread Margie Roginski
I have a TaskForm that contains a DateField.  If I create my form from
an instance of a Task, I find that when I render the DateField field,
the value argument to render() is an actual datetime.date object.
However, if I create my form from POST data, the value argument to
render() is just a unicode string for the date - ie, whatever the user
typed in.

I want to render my date with a class of "late" if the date is in the
past.   Is it good practice to just have the render() method look at
the value and if it's a unicode string, just turn it into a date
object in order to do the compare?   This seems somehow wrong to me,
so I'm just wondering if I'm missing something.

Thanks,

Margie

--

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




Re: How to tell whether the current module is loaded under `manage.py test`

2009-11-25 Thread Russell Keith-Magee
On Wed, Nov 25, 2009 at 4:10 PM, Alex Dong  wrote:
> Hi all,
>
> During the `manage.py test` process, django will automatically change
> the database from `hivemind` to `test_hivemind`,  For similar reason,
> I'd like to change a file path from `sphinx.conf` to
> `sphinx_test.conf` but unfortunately I couldn't find a proper way to
> do it.
>
> Ideally, if there is a django method called `django.test.is_testing()
> `, then I should be able to change the filename based on the return
> value.  Any hints on how I could do this?

You shouldn't.

Code shouldn't be aware that it is being run in a test. Introducing
'if TESTING' branches into code introduces extra complexity into the
code you are trying to test - complexity that, by definition, is
untestable.

If you need to modify a setting for testing purposes, then do the same
thing that the Django test suite does - in your test setUp() method,
modify the value of the setting, then restore the original value
during tearDown().

Yours,
Russ Magee %-)

--

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




Re: More media collection nightmares

2009-11-25 Thread Tim Valenta
I tend to find that Django's true potential bubbles up when all of the
components work together in an interdependent manner.  Normally that
sounds like a bad idea (too much interdependency could make it hard to
grasp the bigger picture), but for some reason, Django comes together
very nicely as you figure out how all of these components can co-
exist.

I hadn't realized that form media comes out of the queue after widget
media.  That does seem pretty backwards, since it's totally logical to
place form-wide media dependencies on the form itself.  If you're
certain that that's what it's doing, you might consider making a
simple bug report on it, with your reasoning for reporting it as
such.  The developers who go over the tickets are always looking for
solid "real-world" problems that a bug report claims to exist.  If
it's only a preferential thing, it won't get much consideration.  But
if you can prove why changing it makes more sense, you'll have a case
for making an improvement.  Bugs will be the focus of version 1.2's
development once January comes around.

Anyway, I hope things are rolling for you now :)

Tim

On Nov 25, 4:00 pm, Todd Blanchard  wrote:
> Actually, a widget required a js file that required core.js, but did not 
> specify it.  So I added core.js to the form's media list - but apparently it 
> renders the widget media, then the form media - so no good.
>
> Your second suggestion was the best - I now just include the jsi18n and 
> core.js on every page as part of the base template.
>
> So far so good.  Hopefully I won't find any more widgets with surprise 
> dependencies.
>
> -Todd Blanchard
>
> On Nov 25, 2009, at 12:14 PM, Tim Valenta wrote:
>
>
>
> > Is it a widget that has the "core.js"?  I'd suggest putting that on
> > the form instead, if that's the case.  Alternatively, if the page
> > should always have this JS anyway, you could always insert it directly
> > to the template, to avoid any ambiguity for any future eyeballs
> > wondering how it all works.

--

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




Re: More media collection nightmares

2009-11-25 Thread Todd Blanchard
Actually, a widget required a js file that required core.js, but did not 
specify it.  So I added core.js to the form's media list - but apparently it 
renders the widget media, then the form media - so no good.

Your second suggestion was the best - I now just include the jsi18n and core.js 
on every page as part of the base template.

So far so good.  Hopefully I won't find any more widgets with surprise 
dependencies.

-Todd Blanchard

On Nov 25, 2009, at 12:14 PM, Tim Valenta wrote:

> Is it a widget that has the "core.js"?  I'd suggest putting that on
> the form instead, if that's the case.  Alternatively, if the page
> should always have this JS anyway, you could always insert it directly
> to the template, to avoid any ambiguity for any future eyeballs
> wondering how it all works.

--

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




Re: Accessing model instance on pre_save signal

2009-11-25 Thread neridaj
Thanks Tim. That's funny you just posted that because I just got done
doing that and was going to post it as solved.

Cheers,

J

On Nov 25, 1:48 pm, Tim Valenta  wrote:
> I know how messed up this all seems, so I sympathize.  I totally want
> to store items according to a related object's name or id or whatever.
>
> However, I'm using upload_to in a more straightforward manner, and it
> seems to work out alright.  Tell me if you've already tried it this
> way:
>
>     class ScreenShot(models.Model):
>         def _image_location(instance, filename):
>             return ''.join("web_projects/%Y/", instance.project.slug,
> "/", filename)
>         # ...
>         image = models.ImageField(upload_to=_image_location)
>
> The thing you pass to your field's "upload_to" value can be a
> callable, which takes two arguments: the instance of `ScreenShot`
> being altered, and the filename of the original file that was
> uploaded.  You then just return a string of the path to save in,
> including the filename.
>
> It's all described here, which it looks like you've already 
> read:http://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.mod...
>
> Does that not work for you?  I do exactly the same thing for various
> fields on some of my models.  I could see how it might complicate
> things if you were doing it on an inline. I admit that I haven't
> tried that one out, as luck would have it.  If the main model already
> exists, it should work, though.
>
> Just brainstorming to find a simpler solution.  Have you already tried
> it that way?
>
> Tim
>
> On Nov 25, 12:08 pm, neridaj  wrote:
>
> > I'm trying to access the current instance of ScreenShot related to the
> > current instance of WebProject, in order to get the slug field of
> > WebProject to use as a upload directory but I don't think I can
> > because there's no primary key in the db yet. I need to call
> > change_upload_to when the instance of WebProject tries to save because
> > it saves before the instance of ScreenShot i.e., before slug is
> > obtained to append to the upload_to directory. Are you suggesting I
> > should just add the ImageField to the WebProject class? I don't want
> > to have a fixed number of ImageFields for WebProject, if there's a way
> > to do that without using another class that would work. Can I access
> > the save method of ScreenShot from WebProject? Should I just add
> > another slug field to ScreenShot?
>
> > class ScreenShotInline(admin.StackedInline):
> >         model = ScreenShot
> >         extra = 3
>
> > class WebProjectAdmin(admin.ModelAdmin):
> >         prepopulated_fields = {'slug': ('title',)}
> >         inlines = [ScreenShotInline]
>
> > On Nov 25, 9:46 am, Preston Holmes  wrote:
>
> > > I'm a bit confused on a few points here.  The upload_to field
> > > attribute should be atomic to the imagefield - it doesn't rely on
> > > related models.
>
> > > your change_upload_to creates a new screenshot - but doesn't connect
> > > it to the current WebProject instance.  Is that what you are trying to
> > > do?
>
> > > s = ScreenShot(project=instance)
>
> > > Is there a reason your WebProject is not defined when you create a
> > > screenshot in your view?
>
> > > Something about this seems like it is making it more complicated than
> > > it needs to be. but details are lacking t
>
> > > -Preston
>
> > > On Nov 24, 5:52 pm, neridaj  wrote:
>
> > > > Hello,
>
> > > > I'm trying to change the upload_to attribute of an ImageField so that
> > > > it is in the format "web_projects/year/slug/". The problem I am having
> > > > is that the ForeignKey model is getting saved before the related
> > > > ScreenShot model is able to call it's save method to change upload_to.
> > > > I'm trying to use a pre_save signal to reverse the order of saving but
> > > > I'm not sure how to access the current instance of the ScreenShot
> > > > model to call it's save method. Thanks for any suggestions.
>
> > > > class ScreenShot(models.Model):
> > > >         project = models.ForeignKey(WebProject)
> > > >         image = models.ImageField(upload_to="web_projects/%Y/")
> > > >         page_title = models.CharField(max_length=250, 
> > > > help_text="Maximum 250
> > > > characters.")
>
> > > >         def __unicode__(self):
> > > >                 return self.page_title
>
> > > >         def save(self):
> > > >                 
> > > > self.image.upload_to="web_projects/%Y/"+self.project.slug
> > > >                 super(ScreenShot, self).save()
>
> > > > def change_upload_to(sender, **kwargs):
> > > >         s = ScreenShot() # not sure how to access current instance
> > > >         s.save()
>
> > > > pre_save.connect(change_upload_to, sender=WebProject)

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this 

Re: Install django on apache

2009-11-25 Thread Christophe Pettus

On Nov 25, 2009, at 12:39 PM, Nadae Ivar BADIO wrote:
> i'm new in django and i trying to run django on my production server  
> who have debian and apache someone can please help me?

It's Centos, not Debian, but this might help:


http://thebuild.com/blog/2009/10/16/wordpress-to-djangopostgresql-part-1-installing-postgresql/

(It's a set of articles about bringing up Apache+Django+PostgreSQL on  
Centos.)

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

--

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




Install django on apache

2009-11-25 Thread Nadae Ivar BADIO
Hi,
i'm new in django and i trying to run django on my production server who have 
debian and apache someone can please help me?
Thanks

--

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




Re: Accessing model instance on pre_save signal

2009-11-25 Thread Tim Valenta
I know how messed up this all seems, so I sympathize.  I totally want
to store items according to a related object's name or id or whatever.

However, I'm using upload_to in a more straightforward manner, and it
seems to work out alright.  Tell me if you've already tried it this
way:

class ScreenShot(models.Model):
def _image_location(instance, filename):
return ''.join("web_projects/%Y/", instance.project.slug,
"/", filename)
# ...
image = models.ImageField(upload_to=_image_location)

The thing you pass to your field's "upload_to" value can be a
callable, which takes two arguments: the instance of `ScreenShot`
being altered, and the filename of the original file that was
uploaded.  You then just return a string of the path to save in,
including the filename.

It's all described here, which it looks like you've already read:
http://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.FileField.upload_to

Does that not work for you?  I do exactly the same thing for various
fields on some of my models.  I could see how it might complicate
things if you were doing it on an inline. I admit that I haven't
tried that one out, as luck would have it.  If the main model already
exists, it should work, though.

Just brainstorming to find a simpler solution.  Have you already tried
it that way?

Tim

On Nov 25, 12:08 pm, neridaj  wrote:
> I'm trying to access the current instance of ScreenShot related to the
> current instance of WebProject, in order to get the slug field of
> WebProject to use as a upload directory but I don't think I can
> because there's no primary key in the db yet. I need to call
> change_upload_to when the instance of WebProject tries to save because
> it saves before the instance of ScreenShot i.e., before slug is
> obtained to append to the upload_to directory. Are you suggesting I
> should just add the ImageField to the WebProject class? I don't want
> to have a fixed number of ImageFields for WebProject, if there's a way
> to do that without using another class that would work. Can I access
> the save method of ScreenShot from WebProject? Should I just add
> another slug field to ScreenShot?
>
> class ScreenShotInline(admin.StackedInline):
>         model = ScreenShot
>         extra = 3
>
> class WebProjectAdmin(admin.ModelAdmin):
>         prepopulated_fields = {'slug': ('title',)}
>         inlines = [ScreenShotInline]
>
> On Nov 25, 9:46 am, Preston Holmes  wrote:
>
>
>
> > I'm a bit confused on a few points here.  The upload_to field
> > attribute should be atomic to the imagefield - it doesn't rely on
> > related models.
>
> > your change_upload_to creates a new screenshot - but doesn't connect
> > it to the current WebProject instance.  Is that what you are trying to
> > do?
>
> > s = ScreenShot(project=instance)
>
> > Is there a reason your WebProject is not defined when you create a
> > screenshot in your view?
>
> > Something about this seems like it is making it more complicated than
> > it needs to be. but details are lacking t
>
> > -Preston
>
> > On Nov 24, 5:52 pm, neridaj  wrote:
>
> > > Hello,
>
> > > I'm trying to change the upload_to attribute of an ImageField so that
> > > it is in the format "web_projects/year/slug/". The problem I am having
> > > is that the ForeignKey model is getting saved before the related
> > > ScreenShot model is able to call it's save method to change upload_to.
> > > I'm trying to use a pre_save signal to reverse the order of saving but
> > > I'm not sure how to access the current instance of the ScreenShot
> > > model to call it's save method. Thanks for any suggestions.
>
> > > class ScreenShot(models.Model):
> > >         project = models.ForeignKey(WebProject)
> > >         image = models.ImageField(upload_to="web_projects/%Y/")
> > >         page_title = models.CharField(max_length=250, help_text="Maximum 
> > > 250
> > > characters.")
>
> > >         def __unicode__(self):
> > >                 return self.page_title
>
> > >         def save(self):
> > >                 self.image.upload_to="web_projects/%Y/"+self.project.slug
> > >                 super(ScreenShot, self).save()
>
> > > def change_upload_to(sender, **kwargs):
> > >         s = ScreenShot() # not sure how to access current instance
> > >         s.save()
>
> > > pre_save.connect(change_upload_to, sender=WebProject)

--

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




Re: middleware to log request/response objects for testing purposes?

2009-11-25 Thread Tim Valenta
http://code.google.com/p/django-logging/

*shrug*  I haven't used it, but he's got a screen-cast about how the
thing is set up.  He builds it off of built-in Python logging
modules.  It looks like it provides some decorators for suppressing
logging output on methods, etc.  Might be worth the time to figure it
out!  I'm considering it myself, now that I've looked at it!

Tim

On Nov 25, 1:52 pm, Sean Neilan  wrote:
> Dear Django Community,
>
> I am curious if anyone has built some middleware to log all request/
> response objects & possibly view & exception calls. I could do this
> myself easily, but, I would like to not reinvent the wheel.
>
> Thank you for your time.
>
> -Sean Neilan

--

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




middleware to log request/response objects for testing purposes?

2009-11-25 Thread Sean Neilan
Dear Django Community,

I am curious if anyone has built some middleware to log all request/
response objects & possibly view & exception calls. I could do this
myself easily, but, I would like to not reinvent the wheel.

Thank you for your time.

-Sean Neilan

--

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




integrating website and django site

2009-11-25 Thread ydjango
I have a website running on www.mydomain.com. It is not a django site.
It has a registration page which is not a django template/form.

I have django app running on app.mydomain.com

I want the registration page on www.domain.com to use django views and
models on app.mydomain.com to save registration to db, send email etc.

what is the best way to achieve this?

--

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




Re: Is it possible to 'order' the left side of a filter_horizontal?

2009-11-25 Thread Tim Valenta
Well, you've got a couple of options.  One is easiest and most
straightforward, but could impact performance.  The second is a little
bit more work, but would limit the ordering to only taking effect on
that one form.

The first way is to use the Meta option `ordering = ('fieldname',)`,
as described here:
http://docs.djangoproject.com/en/dev/ref/models/options/#ordering

Bare in mind that this will passively affect ALL queries you do to
that model's objects, unless you specifically tell it not to order
during the query.  If you think that you'll *always* want that sort
order to take effect, then this is the preferred method of
accomplishing that.

The second way is to intercept the form's queryset powering the
widget.  If you're not using Form objects with your admin (ie, you're
just specifying 'fields' or 'fieldsets' on your ModelAdmin), then
you'll have to take a quick sidequest:

Create a class somewhere (preferably in your app's directory, in a
"forms.py" file or something obvious) like so:

from django import forms
from models import MyModel
class MyModelForm(forms.ModelForm):
class Meta:
model = MyModel
def __init__(self, *args, **kwargs):
forms.ModelForm.__init__(self, *args, **kwargs)
self.fields['myfieldname'].queryset =
MyModel.objects.order_by('custom_sort_field_name')

And then back in your ModelAdmin, add this attribute to the class:

# ...
from forms import MyModelForm
form = MyModelForm

This will cause the admin to use *your* form instead of the default.
What I've done is created a form which simply hijacks the queryset on
'myfieldname' (the field you're trying to sort), and alters it before
the widget has a chance to render itself.


Both methods are effective, but be sure to consider my initial
statement, about performance impact.  Pick the method that strikes the
balance in your mind between performance and practicality.

Hope that helps!

On Nov 25, 1:06 pm, rc  wrote:
> I have configured a modeladmin which uses the filter_horizontal
> feature. I would like to be able to order left side of this feature by
> name instead of the default (which I believe is by id). Is this
> possible? I see how to use "ordering" in the display for change lists,
> but not sure how to apply that to the 'left' side data of the
> filter_horizontal.

--

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




Re: Translate models

2009-11-25 Thread Jani Tiainen
On 11/25/09, Alessandro Ronchi  wrote:
> I need to make my model translatable into different languages.
> Is there any simple way to handle that in a transparent manner?
> I've fround transmeta project on google, anyone is using that?
>

I'm using django-multilingual which pretty much makes same thing just
a bit different way.

-- 

Jani Tiainen

--

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




Re: Chart tool

2009-11-25 Thread Javier Guerra
On Wed, Nov 25, 2009 at 3:07 PM, S.Selvam  wrote:
> I need to show some data as a chart.
>
> I would like to achieve a high quality rendering.
>
> Is reportlab or matplotlib enough ?

reportlab allows you to generate PDFs, which can be as high quality as
you want; but if you want to display them on a webpage it's far from
the best.

matplotlib is nice, being python.  the biggest drawback is that being
a server-side task, so you have to deal with the processing time
and/or storage/deletion of (old) images.

for in-page charts, you can use flot (http://code.google.com/p/flot/),
or Google Charts (http://code.google.com/apis/chart/).  the first one
is a jQuery plugin, the other is an API that basically lets you
construct an URL for a PNG that's rendered on Google servers.  in both
cases, you simply put (some of) your data on the page and let either
the client (if using flot) or somebody else (if using Google charts)
deal with the heavy tasks.


-- 
Javier

--

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




Re: cannot import name settings - accessing Django environment from external script

2009-11-25 Thread Tim Valenta
Hah.. wow.  I'm glad you figured that out.  I haven't used pth files
in any serious manner before, so I totally wasn't thinking about that.

Best of luck to you!

On Nov 25, 1:08 pm, Stodge  wrote:
> What do you know - it's my .pth file. My Mercurial hook is in /home/
> mike/hooks and I have a path file /usr/lib64/python2.5/site-packages/
> hooks.pth defined, which contains:
>
> /home/mike/hooks
>
> If I comment this line out, I can do ./manage.py shell. If I uncomment
> this line, manage.py doesn't work
>
> Thanks for your help.
>
> On Nov 25, 3:04 pm, Stodge  wrote:
>
>
>
> > I can successfully start python and import the settings file. My
> > settings file only imports os.
>
> > On Nov 25, 3:01 pm, Tim Valenta  wrote:
>
> > > Well, does it have errors?  If you navigate to the directory where
> > > it's kept, can you enter the python shell and do "import settings"?
> > > Given all of the trouble you're having, can you verify that it imports
> > > successfully?  The settings module itself should have no immediate
> > > dependencies, unless you've placed a bunch of extra stuff in it.
>
> > > On Nov 25, 12:53 pm, Stodge  wrote:
>
> > > > It fails even if I delete the hg and .hg directories now. It worked a
> > > > few times before, but no longer. Odd.
>
> > > > > /usr/lib/python2.5/site-packages/django/core/management/base.py(194)run_fro
> > > > >  m_argv()
>
> > > > -> handle_default_options(options)
> > > > (Pdb) print options
> > > > {'pythonpath': None, 'verbosity': '1', 'traceback': None, 'plain':
> > > > None, 'settings': None}
> > > > (Pdb) n> 
> > > > /usr/lib/python2.5/site-packages/django/core/management/base.py(195)run_fro
> > > >  m_argv()
>
> > > > -> self.execute(*args, **options.__dict__)
> > > > (Pdb) print args
> > > > []
> > > > (Pdb) print options.__dict__
> > > > {'pythonpath': None, 'verbosity': '1', 'traceback': None, 'plain':
> > > > None, 'settings': None}
> > > > (Pdb) n
> > > > Error: Could not import settings 'indigo.settings' (Is it on sys.path?
> > > > Does it have syntax errors?): No module named settings
> > > > SystemExit: 1> 
> > > > /usr/lib/python2.5/site-packages/django/core/management/base.py(195)run_fro
> > > >  m_argv()
>
> > > > -> self.execute(*args, **options.__dict__)
>
> > > > ./manage.py shell --settings=/var/www/sites/indigo/settings.py
> > > > Error: Could not import settings '/var/www/sites/indigo/
> > > > settings.py' (Is it on sys.path? Does it have syntax errors?): No
> > > > module named /var/www/sites/indigo/settings.py
>
> > > > On Nov 25, 2:37 pm, Bill Freeman  wrote:
>
> > > > > Interesting.
>
> > > > > I take it that hg and hg/hooks both have __init__.py files?  Otherwise
> > > > > I'm not sure how django sees them.  Unless hg is also an app, listed
> > > > > in installed apps and has a models.py file.  That is, I don't believe 
> > > > > that
> > > > > the name 'hg' has any special meaning to django.
>
> > > > > You might try sticking "import pdb;pdb.set_trace()" in the beginning 
> > > > > of
> > > > > settings.py to see if it is at least trying to be imported.  If the 
> > > > > breakpoint
> > > > > is hit, you could "n" your way through the file to see if something is
> > > > > getting an exception that prevents the import from succeeding, then
> > > > > back up by moving the set_trace() to just before the failing item, 
> > > > > restart,
> > > > > and "s" your way into the failing item to see how it manages to depend
> > > > > on the presence of an "hg" directory.
>
> > > > > On Wed, Nov 25, 2009 at 2:18 PM, Stodge  wrote:
> > > > > > I think I have it. I'm developing a Mercurial hook in 
> > > > > > /var/www/sites/
> > > > > > project/hg/hooks. If I delete this directory it works. If I recreate
> > > > > > the directory and the hook, it fails. Guess Django is getting 
> > > > > > confused
> > > > > > by its existence.
>
> > > > > > On Nov 25, 12:56 pm, Bill Freeman  wrote:
> > > > > >> Does /var/www/sites/project/__init__.py exist?
>
> > > > > >> Are the files and directories readable, and the directories 
> > > > > >> searchable
> > > > > >> (excutable)
> > > > > >> by the user as which the webserver runs?
>
> > > > > >> On Wed, Nov 25, 2009 at 12:21 PM, Stodge  wrote:
> > > > > >> > If I break the code out and write a simple python script that 
> > > > > >> > only
> > > > > >> > contains:
>
> > > > > >> > import sys, os
> > > > > >> > sys.path.append("/var/www/sites")
> > > > > >> > from project import settings
> > > > > >> > from django.core.management import setup_environ
> > > > > >> > setup_environ(settings)
>
> > > > > >> > Even this doesn't work yet as far as I can tell, it should. Any 
> > > > > >> > ideas?
>
> > > > > >> > --
>
> > > > > >> > You received this message because you are subscribed to the 
> > > > > >> > Google Groups "Django users" group.
> > > > > >> > To post to 

Re: More media collection nightmares

2009-11-25 Thread Tim Valenta
It looks to me like the Media class managing the files stores JS files
in a Python list, so order should be remembered.  I can see the issue
though if a *widget* has critical "core" media, which isn't rendered
until after other bits of media already went out the hatch.

Is it a widget that has the "core.js"?  I'd suggest putting that on
the form instead, if that's the case.  Alternatively, if the page
should always have this JS anyway, you could always insert it directly
to the template, to avoid any ambiguity for any future eyeballs
wondering how it all works.

On Nov 25, 12:43 pm, Todd Blanchard  wrote:
> The latest is that the media collection strategy apparently has no concept of 
> order dependence when specifying or loading javascript and in my form it 
> seems to be sticking core.js somewhere in the middle which contains addEvent 
> which is required by something being loaded sooner and thus it results in 
> failure.
>
> Is there some way to specify order dependency in js files using this 
> mechanism? Otherwise I think it is worthless.
>
> -Todd Blanchard

--

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




Chart tool

2009-11-25 Thread S.Selvam
Hi all,

This is my first post here andi  am new to django.

I need to show some data as a chart.

I would like to achieve a high quality rendering.

Is reportlab or matplotlib enough ?

I hope you can direct me on track.

-- 
Yours,
S.Selvam
Sent from Bangalore, KA, India

--

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




Re: cannot import name settings - accessing Django environment from external script

2009-11-25 Thread Stodge
What do you know - it's my .pth file. My Mercurial hook is in /home/
mike/hooks and I have a path file /usr/lib64/python2.5/site-packages/
hooks.pth defined, which contains:

/home/mike/hooks

If I comment this line out, I can do ./manage.py shell. If I uncomment
this line, manage.py doesn't work

Thanks for your help.

On Nov 25, 3:04 pm, Stodge  wrote:
> I can successfully start python and import the settings file. My
> settings file only imports os.
>
> On Nov 25, 3:01 pm, Tim Valenta  wrote:
>
> > Well, does it have errors?  If you navigate to the directory where
> > it's kept, can you enter the python shell and do "import settings"?
> > Given all of the trouble you're having, can you verify that it imports
> > successfully?  The settings module itself should have no immediate
> > dependencies, unless you've placed a bunch of extra stuff in it.
>
> > On Nov 25, 12:53 pm, Stodge  wrote:
>
> > > It fails even if I delete the hg and .hg directories now. It worked a
> > > few times before, but no longer. Odd.
>
> > > > /usr/lib/python2.5/site-packages/django/core/management/base.py(194)run_fro
> > > >  m_argv()
>
> > > -> handle_default_options(options)
> > > (Pdb) print options
> > > {'pythonpath': None, 'verbosity': '1', 'traceback': None, 'plain':
> > > None, 'settings': None}
> > > (Pdb) n> 
> > > /usr/lib/python2.5/site-packages/django/core/management/base.py(195)run_fro
> > >  m_argv()
>
> > > -> self.execute(*args, **options.__dict__)
> > > (Pdb) print args
> > > []
> > > (Pdb) print options.__dict__
> > > {'pythonpath': None, 'verbosity': '1', 'traceback': None, 'plain':
> > > None, 'settings': None}
> > > (Pdb) n
> > > Error: Could not import settings 'indigo.settings' (Is it on sys.path?
> > > Does it have syntax errors?): No module named settings
> > > SystemExit: 1> 
> > > /usr/lib/python2.5/site-packages/django/core/management/base.py(195)run_fro
> > >  m_argv()
>
> > > -> self.execute(*args, **options.__dict__)
>
> > > ./manage.py shell --settings=/var/www/sites/indigo/settings.py
> > > Error: Could not import settings '/var/www/sites/indigo/
> > > settings.py' (Is it on sys.path? Does it have syntax errors?): No
> > > module named /var/www/sites/indigo/settings.py
>
> > > On Nov 25, 2:37 pm, Bill Freeman  wrote:
>
> > > > Interesting.
>
> > > > I take it that hg and hg/hooks both have __init__.py files?  Otherwise
> > > > I'm not sure how django sees them.  Unless hg is also an app, listed
> > > > in installed apps and has a models.py file.  That is, I don't believe 
> > > > that
> > > > the name 'hg' has any special meaning to django.
>
> > > > You might try sticking "import pdb;pdb.set_trace()" in the beginning of
> > > > settings.py to see if it is at least trying to be imported.  If the 
> > > > breakpoint
> > > > is hit, you could "n" your way through the file to see if something is
> > > > getting an exception that prevents the import from succeeding, then
> > > > back up by moving the set_trace() to just before the failing item, 
> > > > restart,
> > > > and "s" your way into the failing item to see how it manages to depend
> > > > on the presence of an "hg" directory.
>
> > > > On Wed, Nov 25, 2009 at 2:18 PM, Stodge  wrote:
> > > > > I think I have it. I'm developing a Mercurial hook in /var/www/sites/
> > > > > project/hg/hooks. If I delete this directory it works. If I recreate
> > > > > the directory and the hook, it fails. Guess Django is getting confused
> > > > > by its existence.
>
> > > > > On Nov 25, 12:56 pm, Bill Freeman  wrote:
> > > > >> Does /var/www/sites/project/__init__.py exist?
>
> > > > >> Are the files and directories readable, and the directories 
> > > > >> searchable
> > > > >> (excutable)
> > > > >> by the user as which the webserver runs?
>
> > > > >> On Wed, Nov 25, 2009 at 12:21 PM, Stodge  wrote:
> > > > >> > If I break the code out and write a simple python script that only
> > > > >> > contains:
>
> > > > >> > import sys, os
> > > > >> > sys.path.append("/var/www/sites")
> > > > >> > from project import settings
> > > > >> > from django.core.management import setup_environ
> > > > >> > setup_environ(settings)
>
> > > > >> > Even this doesn't work yet as far as I can tell, it should. Any 
> > > > >> > ideas?
>
> > > > >> > --
>
> > > > >> > You received this message because you are subscribed to the Google 
> > > > >> > Groups "Django users" group.
> > > > >> > To post to this group, send email to django-us...@googlegroups.com.
> > > > >> > To unsubscribe from this group, send email to 
> > > > >> > django-users+unsubscr...@googlegroups.com.
> > > > >> > For more options, visit this group 
> > > > >> > athttp://groups.google.com/group/django-users?hl=en.
>
> > > > > --
>
> > > > > You received this message because you are subscribed to the Google 
> > > > > Groups "Django users" group.
> > > > > To post to this 

Is it possible to 'order' the left side of a filter_horizontal?

2009-11-25 Thread rc
I have configured a modeladmin which uses the filter_horizontal
feature. I would like to be able to order left side of this feature by
name instead of the default (which I believe is by id). Is this
possible? I see how to use "ordering" in the display for change lists,
but not sure how to apply that to the 'left' side data of the
filter_horizontal.

--

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




Re: cannot import name settings - accessing Django environment from external script

2009-11-25 Thread Stodge
I can successfully start python and import the settings file. My
settings file only imports os.

On Nov 25, 3:01 pm, Tim Valenta  wrote:
> Well, does it have errors?  If you navigate to the directory where
> it's kept, can you enter the python shell and do "import settings"?
> Given all of the trouble you're having, can you verify that it imports
> successfully?  The settings module itself should have no immediate
> dependencies, unless you've placed a bunch of extra stuff in it.
>
> On Nov 25, 12:53 pm, Stodge  wrote:
>
> > It fails even if I delete the hg and .hg directories now. It worked a
> > few times before, but no longer. Odd.
>
> > > /usr/lib/python2.5/site-packages/django/core/management/base.py(194)run_fro
> > >  m_argv()
>
> > -> handle_default_options(options)
> > (Pdb) print options
> > {'pythonpath': None, 'verbosity': '1', 'traceback': None, 'plain':
> > None, 'settings': None}
> > (Pdb) n> 
> > /usr/lib/python2.5/site-packages/django/core/management/base.py(195)run_fro 
> > m_argv()
>
> > -> self.execute(*args, **options.__dict__)
> > (Pdb) print args
> > []
> > (Pdb) print options.__dict__
> > {'pythonpath': None, 'verbosity': '1', 'traceback': None, 'plain':
> > None, 'settings': None}
> > (Pdb) n
> > Error: Could not import settings 'indigo.settings' (Is it on sys.path?
> > Does it have syntax errors?): No module named settings
> > SystemExit: 1> 
> > /usr/lib/python2.5/site-packages/django/core/management/base.py(195)run_fro 
> > m_argv()
>
> > -> self.execute(*args, **options.__dict__)
>
> > ./manage.py shell --settings=/var/www/sites/indigo/settings.py
> > Error: Could not import settings '/var/www/sites/indigo/
> > settings.py' (Is it on sys.path? Does it have syntax errors?): No
> > module named /var/www/sites/indigo/settings.py
>
> > On Nov 25, 2:37 pm, Bill Freeman  wrote:
>
> > > Interesting.
>
> > > I take it that hg and hg/hooks both have __init__.py files?  Otherwise
> > > I'm not sure how django sees them.  Unless hg is also an app, listed
> > > in installed apps and has a models.py file.  That is, I don't believe that
> > > the name 'hg' has any special meaning to django.
>
> > > You might try sticking "import pdb;pdb.set_trace()" in the beginning of
> > > settings.py to see if it is at least trying to be imported.  If the 
> > > breakpoint
> > > is hit, you could "n" your way through the file to see if something is
> > > getting an exception that prevents the import from succeeding, then
> > > back up by moving the set_trace() to just before the failing item, 
> > > restart,
> > > and "s" your way into the failing item to see how it manages to depend
> > > on the presence of an "hg" directory.
>
> > > On Wed, Nov 25, 2009 at 2:18 PM, Stodge  wrote:
> > > > I think I have it. I'm developing a Mercurial hook in /var/www/sites/
> > > > project/hg/hooks. If I delete this directory it works. If I recreate
> > > > the directory and the hook, it fails. Guess Django is getting confused
> > > > by its existence.
>
> > > > On Nov 25, 12:56 pm, Bill Freeman  wrote:
> > > >> Does /var/www/sites/project/__init__.py exist?
>
> > > >> Are the files and directories readable, and the directories searchable
> > > >> (excutable)
> > > >> by the user as which the webserver runs?
>
> > > >> On Wed, Nov 25, 2009 at 12:21 PM, Stodge  wrote:
> > > >> > If I break the code out and write a simple python script that only
> > > >> > contains:
>
> > > >> > import sys, os
> > > >> > sys.path.append("/var/www/sites")
> > > >> > from project import settings
> > > >> > from django.core.management import setup_environ
> > > >> > setup_environ(settings)
>
> > > >> > Even this doesn't work yet as far as I can tell, it should. Any 
> > > >> > ideas?
>
> > > >> > --
>
> > > >> > You received this message because you are subscribed to the Google 
> > > >> > Groups "Django users" group.
> > > >> > To post to this group, send email to django-us...@googlegroups.com.
> > > >> > To unsubscribe from this group, send email to 
> > > >> > django-users+unsubscr...@googlegroups.com.
> > > >> > For more options, visit this group 
> > > >> > athttp://groups.google.com/group/django-users?hl=en.
>
> > > > --
>
> > > > You received this message because you are subscribed to the Google 
> > > > Groups "Django users" group.
> > > > To post to this group, send email to django-us...@googlegroups.com.
> > > > To unsubscribe from this group, send email to 
> > > > django-users+unsubscr...@googlegroups.com.
> > > > For more options, visit this group 
> > > > athttp://groups.google.com/group/django-users?hl=en.
>
>

--

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

Re: cannot import name settings - accessing Django environment from external script

2009-11-25 Thread Tim Valenta
Well, does it have errors?  If you navigate to the directory where
it's kept, can you enter the python shell and do "import settings"?
Given all of the trouble you're having, can you verify that it imports
successfully?  The settings module itself should have no immediate
dependencies, unless you've placed a bunch of extra stuff in it.

On Nov 25, 12:53 pm, Stodge  wrote:
> It fails even if I delete the hg and .hg directories now. It worked a
> few times before, but no longer. Odd.
>
> > /usr/lib/python2.5/site-packages/django/core/management/base.py(194)run_fro 
> > m_argv()
>
> -> handle_default_options(options)
> (Pdb) print options
> {'pythonpath': None, 'verbosity': '1', 'traceback': None, 'plain':
> None, 'settings': None}
> (Pdb) n> 
> /usr/lib/python2.5/site-packages/django/core/management/base.py(195)run_fro 
> m_argv()
>
> -> self.execute(*args, **options.__dict__)
> (Pdb) print args
> []
> (Pdb) print options.__dict__
> {'pythonpath': None, 'verbosity': '1', 'traceback': None, 'plain':
> None, 'settings': None}
> (Pdb) n
> Error: Could not import settings 'indigo.settings' (Is it on sys.path?
> Does it have syntax errors?): No module named settings
> SystemExit: 1> 
> /usr/lib/python2.5/site-packages/django/core/management/base.py(195)run_fro 
> m_argv()
>
> -> self.execute(*args, **options.__dict__)
>
> ./manage.py shell --settings=/var/www/sites/indigo/settings.py
> Error: Could not import settings '/var/www/sites/indigo/
> settings.py' (Is it on sys.path? Does it have syntax errors?): No
> module named /var/www/sites/indigo/settings.py
>
> On Nov 25, 2:37 pm, Bill Freeman  wrote:
>
>
>
> > Interesting.
>
> > I take it that hg and hg/hooks both have __init__.py files?  Otherwise
> > I'm not sure how django sees them.  Unless hg is also an app, listed
> > in installed apps and has a models.py file.  That is, I don't believe that
> > the name 'hg' has any special meaning to django.
>
> > You might try sticking "import pdb;pdb.set_trace()" in the beginning of
> > settings.py to see if it is at least trying to be imported.  If the 
> > breakpoint
> > is hit, you could "n" your way through the file to see if something is
> > getting an exception that prevents the import from succeeding, then
> > back up by moving the set_trace() to just before the failing item, restart,
> > and "s" your way into the failing item to see how it manages to depend
> > on the presence of an "hg" directory.
>
> > On Wed, Nov 25, 2009 at 2:18 PM, Stodge  wrote:
> > > I think I have it. I'm developing a Mercurial hook in /var/www/sites/
> > > project/hg/hooks. If I delete this directory it works. If I recreate
> > > the directory and the hook, it fails. Guess Django is getting confused
> > > by its existence.
>
> > > On Nov 25, 12:56 pm, Bill Freeman  wrote:
> > >> Does /var/www/sites/project/__init__.py exist?
>
> > >> Are the files and directories readable, and the directories searchable
> > >> (excutable)
> > >> by the user as which the webserver runs?
>
> > >> On Wed, Nov 25, 2009 at 12:21 PM, Stodge  wrote:
> > >> > If I break the code out and write a simple python script that only
> > >> > contains:
>
> > >> > import sys, os
> > >> > sys.path.append("/var/www/sites")
> > >> > from project import settings
> > >> > from django.core.management import setup_environ
> > >> > setup_environ(settings)
>
> > >> > Even this doesn't work yet as far as I can tell, it should. Any ideas?
>
> > >> > --
>
> > >> > You received this message because you are subscribed to the Google 
> > >> > Groups "Django users" group.
> > >> > To post to this group, send email to django-us...@googlegroups.com.
> > >> > To unsubscribe from this group, send email to 
> > >> > django-users+unsubscr...@googlegroups.com.
> > >> > For more options, visit this group 
> > >> > athttp://groups.google.com/group/django-users?hl=en.
>
> > > --
>
> > > You received this message because you are subscribed to the Google Groups 
> > > "Django users" group.
> > > To post to this group, send email to django-us...@googlegroups.com.
> > > To unsubscribe from this group, send email to 
> > > django-users+unsubscr...@googlegroups.com.
> > > For more options, visit this group 
> > > athttp://groups.google.com/group/django-users?hl=en.

--

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




Re: cannot import name settings - accessing Django environment from external script

2009-11-25 Thread Stodge
It fails even if I delete the hg and .hg directories now. It worked a
few times before, but no longer. Odd.

> /usr/lib/python2.5/site-packages/django/core/management/base.py(194)run_from_argv()
-> handle_default_options(options)
(Pdb) print options
{'pythonpath': None, 'verbosity': '1', 'traceback': None, 'plain':
None, 'settings': None}
(Pdb) n
> /usr/lib/python2.5/site-packages/django/core/management/base.py(195)run_from_argv()
-> self.execute(*args, **options.__dict__)
(Pdb) print args
[]
(Pdb) print options.__dict__
{'pythonpath': None, 'verbosity': '1', 'traceback': None, 'plain':
None, 'settings': None}
(Pdb) n
Error: Could not import settings 'indigo.settings' (Is it on sys.path?
Does it have syntax errors?): No module named settings
SystemExit: 1
> /usr/lib/python2.5/site-packages/django/core/management/base.py(195)run_from_argv()
-> self.execute(*args, **options.__dict__)



./manage.py shell --settings=/var/www/sites/indigo/settings.py
Error: Could not import settings '/var/www/sites/indigo/
settings.py' (Is it on sys.path? Does it have syntax errors?): No
module named /var/www/sites/indigo/settings.py




On Nov 25, 2:37 pm, Bill Freeman  wrote:
> Interesting.
>
> I take it that hg and hg/hooks both have __init__.py files?  Otherwise
> I'm not sure how django sees them.  Unless hg is also an app, listed
> in installed apps and has a models.py file.  That is, I don't believe that
> the name 'hg' has any special meaning to django.
>
> You might try sticking "import pdb;pdb.set_trace()" in the beginning of
> settings.py to see if it is at least trying to be imported.  If the breakpoint
> is hit, you could "n" your way through the file to see if something is
> getting an exception that prevents the import from succeeding, then
> back up by moving the set_trace() to just before the failing item, restart,
> and "s" your way into the failing item to see how it manages to depend
> on the presence of an "hg" directory.
>
> On Wed, Nov 25, 2009 at 2:18 PM, Stodge  wrote:
> > I think I have it. I'm developing a Mercurial hook in /var/www/sites/
> > project/hg/hooks. If I delete this directory it works. If I recreate
> > the directory and the hook, it fails. Guess Django is getting confused
> > by its existence.
>
> > On Nov 25, 12:56 pm, Bill Freeman  wrote:
> >> Does /var/www/sites/project/__init__.py exist?
>
> >> Are the files and directories readable, and the directories searchable
> >> (excutable)
> >> by the user as which the webserver runs?
>
> >> On Wed, Nov 25, 2009 at 12:21 PM, Stodge  wrote:
> >> > If I break the code out and write a simple python script that only
> >> > contains:
>
> >> > import sys, os
> >> > sys.path.append("/var/www/sites")
> >> > from project import settings
> >> > from django.core.management import setup_environ
> >> > setup_environ(settings)
>
> >> > Even this doesn't work yet as far as I can tell, it should. Any ideas?
>
> >> > --
>
> >> > You received this message because you are subscribed to the Google 
> >> > Groups "Django users" group.
> >> > To post to this group, send email to django-us...@googlegroups.com.
> >> > To unsubscribe from this group, send email to 
> >> > django-users+unsubscr...@googlegroups.com.
> >> > For more options, visit this group 
> >> > athttp://groups.google.com/group/django-users?hl=en.
>
> > --
>
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/django-users?hl=en.
>
>

--

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




More media collection nightmares

2009-11-25 Thread Todd Blanchard
The latest is that the media collection strategy apparently has no concept of 
order dependence when specifying or loading javascript and in my form it seems 
to be sticking core.js somewhere in the middle which contains addEvent which is 
required by something being loaded sooner and thus it results in failure.

Is there some way to specify order dependency in js files using this mechanism? 
Otherwise I think it is worthless.

-Todd Blanchard

--

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




Re: applying a patch

2009-11-25 Thread Tim Valenta
It's meant to be done through an SVN checkout, since that's the format
that the Django development repository is kept.

If you haven't got SVN, I'd start there.  If you're on Windows, the
"nicest" solution is "tortoisesvn", which integrates pretty simply
into the Windows shell for easy right-click controls.  If you've got
some form of Unix, then you'll have to decide if you've already got
the commandline client program.

If you've got SVN under your belt, then you're pretty much already
almost there.  If you're using the command line, you'll have to
navigate to your repository, and then use:

patch -p0 < /path/to/patch.diff

If you're using that Windows "TortoiseSVN", you can right-click the
repository folder, and use the menus to find the "Apply patch"
command.  Just locate it and it should be done.

There are some complications with command line patching where file
renames are involved.  Hopefully your patch is pretty simple.  There's
quite a bit of info in the blog circles about this stuff, so you can
find more specifics by searching online.

Tim

On Nov 25, 12:12 pm, paulh  wrote:
> I am interested in applying patch 7028, but I don't know what to apply
> it to.
> Any help would be appreciated.
>
> Paul Hide

--

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




Re: Sick of defining urls

2009-11-25 Thread Tim Valenta
I usually don't find myself writing too many redundant views, since
the built-in admin site does so much of that automatically.  Then I
just build views specific to the site's public UI.  I still find it
curious that you would find yourself recreating said urls.  I run a
company database through the admin and three urls and three views.
There should only have to be one url pattern defined per model, plus
any extra views for looking at that one model.  I don't mean to
belittle what it is you're doing, but I can't say that I can identify
very well.  How many of your models have exactly the same set of
views?  My tendency is to think that those should be caught through
some keyword captures.

There are, however, generic views (http://docs.djangoproject.com/en/
dev/ref/generic-views/) which might help.  You might look at it and
not think that it is as easy to use as you might like, but they are
quite good for automatically handling dates in URLs, etc.

I can't explain too much about generic views, as I haven't had to use
them much.  I'm totally not an authority on that end.

If they don't really work out, you could always write a url which
captures each of those three things as keyword arguments:

urlpatterns = patterns('',
(r'^(?P[^/]+)/(?P[^/]+)/(?P\d+)/',
'magic_view_handler'),
)

"magic_view_handler" would then be a view that gets called, whose
signature looks something like:

magic_view_handler(request, app, view, id):
view_function = None
try:
view_function = import('%s.%s' % (app, view))
except ImportError:
raise Http404
view_function(request, id)

It'd then be up to your *real* view to check to ensure that the id is
legit.

I forget precise syntax on that import() function.  I don't use it
often.  The idea is to import a dynamic module based on some string
you've got handy.

I think that the reason why this latter suggestion doesn't have a
reason to exist is because you've always got to validate all sorts of
stuff very specific to the model.  By making one generic view, you're
bound to never really allowing yourself any custom processing.  You'd
always be passing your variably-defined model to the same template.
How could the same template render entirely different models to the
page?

Anyway, "sticky" the word for it, at best.  I'm totally curious, so
could I ask that you give an example of your url conf?  If feels like
there might be something missing that could simplify your task.

Tim

On Nov 25, 12:07 pm, Todd Blanchard  wrote:
> It is mostly a waste of time and busy work.
>
> I like the rails strategy of /controller/action/id
>
> I'd like to define a similar one time couple rules in urls.py
>
> Something like /application/view/id where view is the name of the function in 
> the views.py in that application.
>
> Anybody got a little snippet or recipe to do this generically once and for 
> all?
>
> -Todd Blanchard

--

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




Re: cannot import name settings - accessing Django environment from external script

2009-11-25 Thread Bill Freeman
Interesting.

I take it that hg and hg/hooks both have __init__.py files?  Otherwise
I'm not sure how django sees them.  Unless hg is also an app, listed
in installed apps and has a models.py file.  That is, I don't believe that
the name 'hg' has any special meaning to django.

You might try sticking "import pdb;pdb.set_trace()" in the beginning of
settings.py to see if it is at least trying to be imported.  If the breakpoint
is hit, you could "n" your way through the file to see if something is
getting an exception that prevents the import from succeeding, then
back up by moving the set_trace() to just before the failing item, restart,
and "s" your way into the failing item to see how it manages to depend
on the presence of an "hg" directory.

On Wed, Nov 25, 2009 at 2:18 PM, Stodge  wrote:
> I think I have it. I'm developing a Mercurial hook in /var/www/sites/
> project/hg/hooks. If I delete this directory it works. If I recreate
> the directory and the hook, it fails. Guess Django is getting confused
> by its existence.
>
> On Nov 25, 12:56 pm, Bill Freeman  wrote:
>> Does /var/www/sites/project/__init__.py exist?
>>
>> Are the files and directories readable, and the directories searchable
>> (excutable)
>> by the user as which the webserver runs?
>>
>> On Wed, Nov 25, 2009 at 12:21 PM, Stodge  wrote:
>> > If I break the code out and write a simple python script that only
>> > contains:
>>
>> > import sys, os
>> > sys.path.append("/var/www/sites")
>> > from project import settings
>> > from django.core.management import setup_environ
>> > setup_environ(settings)
>>
>> > Even this doesn't work yet as far as I can tell, it should. Any ideas?
>>
>> > --
>>
>> > You received this message because you are subscribed to the Google Groups 
>> > "Django users" group.
>> > To post to this group, send email to django-us...@googlegroups.com.
>> > To unsubscribe from this group, send email to 
>> > django-users+unsubscr...@googlegroups.com.
>> > For more options, visit this group 
>> > athttp://groups.google.com/group/django-users?hl=en.
>>
>>
>
> --
>
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>
>

--

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




Re: cannot import name settings - accessing Django environment from external script

2009-11-25 Thread Stodge
And now it doesn't work again.. what is going on???

On Nov 25, 2:18 pm, Stodge  wrote:
> I think I have it. I'm developing a Mercurial hook in /var/www/sites/
> project/hg/hooks. If I delete this directory it works. If I recreate
> the directory and the hook, it fails. Guess Django is getting confused
> by its existence.
>
> On Nov 25, 12:56 pm, Bill Freeman  wrote:
>
> > Does /var/www/sites/project/__init__.py exist?
>
> > Are the files and directories readable, and the directories searchable
> > (excutable)
> > by the user as which the webserver runs?
>
> > On Wed, Nov 25, 2009 at 12:21 PM, Stodge  wrote:
> > > If I break the code out and write a simple python script that only
> > > contains:
>
> > > import sys, os
> > > sys.path.append("/var/www/sites")
> > > from project import settings
> > > from django.core.management import setup_environ
> > > setup_environ(settings)
>
> > > Even this doesn't work yet as far as I can tell, it should. Any ideas?
>
> > > --
>
> > > You received this message because you are subscribed to the Google Groups 
> > > "Django users" group.
> > > To post to this group, send email to django-us...@googlegroups.com.
> > > To unsubscribe from this group, send email to 
> > > django-users+unsubscr...@googlegroups.com.
> > > For more options, visit this group 
> > > athttp://groups.google.com/group/django-users?hl=en.
>
>

--

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




Re: cannot import name settings - accessing Django environment from external script

2009-11-25 Thread Stodge
I think I have it. I'm developing a Mercurial hook in /var/www/sites/
project/hg/hooks. If I delete this directory it works. If I recreate
the directory and the hook, it fails. Guess Django is getting confused
by its existence.

On Nov 25, 12:56 pm, Bill Freeman  wrote:
> Does /var/www/sites/project/__init__.py exist?
>
> Are the files and directories readable, and the directories searchable
> (excutable)
> by the user as which the webserver runs?
>
> On Wed, Nov 25, 2009 at 12:21 PM, Stodge  wrote:
> > If I break the code out and write a simple python script that only
> > contains:
>
> > import sys, os
> > sys.path.append("/var/www/sites")
> > from project import settings
> > from django.core.management import setup_environ
> > setup_environ(settings)
>
> > Even this doesn't work yet as far as I can tell, it should. Any ideas?
>
> > --
>
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/django-users?hl=en.
>
>

--

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




Re: cannot import name settings - accessing Django environment from external script

2009-11-25 Thread Stodge
Permissions are correct, __init__.py exists. Something is screwing the
filesystem up. I blew away the old environment and re-created it and
it worked. After a short while it broke again. I'm using Mercurial to
manage source control for the environment; maybe that is interfering.

On Nov 25, 12:56 pm, Bill Freeman  wrote:
> Does /var/www/sites/project/__init__.py exist?
>
> Are the files and directories readable, and the directories searchable
> (excutable)
> by the user as which the webserver runs?
>
> On Wed, Nov 25, 2009 at 12:21 PM, Stodge  wrote:
> > If I break the code out and write a simple python script that only
> > contains:
>
> > import sys, os
> > sys.path.append("/var/www/sites")
> > from project import settings
> > from django.core.management import setup_environ
> > setup_environ(settings)
>
> > Even this doesn't work yet as far as I can tell, it should. Any ideas?
>
> > --
>
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/django-users?hl=en.
>
>

--

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




applying a patch

2009-11-25 Thread paulh
I am interested in applying patch 7028, but I don't know what to apply
it to.
Any help would be appreciated.

Paul Hide

--

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




Re: Accessing model instance on pre_save signal

2009-11-25 Thread neridaj
I'm trying to access the current instance of ScreenShot related to the
current instance of WebProject, in order to get the slug field of
WebProject to use as a upload directory but I don't think I can
because there's no primary key in the db yet. I need to call
change_upload_to when the instance of WebProject tries to save because
it saves before the instance of ScreenShot i.e., before slug is
obtained to append to the upload_to directory. Are you suggesting I
should just add the ImageField to the WebProject class? I don't want
to have a fixed number of ImageFields for WebProject, if there's a way
to do that without using another class that would work. Can I access
the save method of ScreenShot from WebProject? Should I just add
another slug field to ScreenShot?

class ScreenShotInline(admin.StackedInline):
model = ScreenShot
extra = 3

class WebProjectAdmin(admin.ModelAdmin):
prepopulated_fields = {'slug': ('title',)}
inlines = [ScreenShotInline]

On Nov 25, 9:46 am, Preston Holmes  wrote:
> I'm a bit confused on a few points here.  The upload_to field
> attribute should be atomic to the imagefield - it doesn't rely on
> related models.
>
> your change_upload_to creates a new screenshot - but doesn't connect
> it to the current WebProject instance.  Is that what you are trying to
> do?
>
> s = ScreenShot(project=instance)
>
> Is there a reason your WebProject is not defined when you create a
> screenshot in your view?
>
> Something about this seems like it is making it more complicated than
> it needs to be. but details are lacking t
>
> -Preston
>
> On Nov 24, 5:52 pm, neridaj  wrote:
>
> > Hello,
>
> > I'm trying to change the upload_to attribute of an ImageField so that
> > it is in the format "web_projects/year/slug/". The problem I am having
> > is that the ForeignKey model is getting saved before the related
> > ScreenShot model is able to call it's save method to change upload_to.
> > I'm trying to use a pre_save signal to reverse the order of saving but
> > I'm not sure how to access the current instance of the ScreenShot
> > model to call it's save method. Thanks for any suggestions.
>
> > class ScreenShot(models.Model):
> >         project = models.ForeignKey(WebProject)
> >         image = models.ImageField(upload_to="web_projects/%Y/")
> >         page_title = models.CharField(max_length=250, help_text="Maximum 250
> > characters.")
>
> >         def __unicode__(self):
> >                 return self.page_title
>
> >         def save(self):
> >                 self.image.upload_to="web_projects/%Y/"+self.project.slug
> >                 super(ScreenShot, self).save()
>
> > def change_upload_to(sender, **kwargs):
> >         s = ScreenShot() # not sure how to access current instance
> >         s.save()
>
> > pre_save.connect(change_upload_to, sender=WebProject)

--

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




Sick of defining urls

2009-11-25 Thread Todd Blanchard
It is mostly a waste of time and busy work.

I like the rails strategy of /controller/action/id

I'd like to define a similar one time couple rules in urls.py

Something like /application/view/id where view is the name of the function in 
the views.py in that application.

Anybody got a little snippet or recipe to do this generically once and for all?

-Todd Blanchard

--

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




Re: Configure multi-field multi-select form in Django Admin

2009-11-25 Thread rc
Tim,

Thanks for the response. That is what I was looking for. I got it
working now, just needed a little hint. Found the User Admin stuff (in
contrib) and was able to follow that.
As far as the "id" columns.I adapted Django to an existing system
so that is why the models don't necessarily match the Django norm.

Reed

On Nov 24, 7:41 pm, Tim Valenta  wrote:
> > The javascript will be found somewhere under django/contrib/admin/media/js.
>
> To be clear, rc, although the javascript is of course available for
> viewing, you should only need to put that attribute
> "filter_horizontal" on your ModelAdmin.  There shouldn't be any need
> for inserting any custom javascript commands anywhere.  That one
> attribute does it all.
>
> And... this might pose a problem, but I don't see any ManyToManyFields
> in your models.  It won't work unless you're using those, instead of
> ForeignKeys.
>
> For the extra mile, you shouldn't need those various "_id =
> models.AutoField(primary_key=True)" parts.  Django does that
> automatically, but names each one just "id", instead of "[modelname]
> _id".  Unless you specifically want them to be named differently than
> "id", you don't have to specify it, which helps it be more readable.
> But it's of course your own project :)  Do it however you wish!
>
> Tim
>
> On Nov 24, 6:01 pm, Karen Tracey  wrote:
>
> > On Tue, Nov 24, 2009 at 12:32 PM, rc  wrote:
> > > As I mentioned, the Django admin has exactly what I want with the user
> > > permission form (auth_user, auth_permissions and
> > > auth_user_user_permission). Does anyone know where that code is
> > > located in the Django environment?
>
> > That's done with javascript, activated by listing the fields in:
>
> >http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contri...
>
> > The javascript will be found somewhere under django/contrib/admin/media/js.
>
> > 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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Content types and interaction with DeferredAttribute models

2009-11-25 Thread Giovannetti, Mark

FYI:

Trying to run unittests.

Using the .only() method on a queryset causes the content types
machinery to find and attempt to use a model with Deferred attributes.

This function (with print and verbosity added):

def update_contenttypes(app, created_models, verbosity=2, **kwargs):
"""
Creates content types for models in the given app, removing any
model
entries that no longer have a matching model class.
"""
verbosity=2
ContentType.objects.clear_cache()
content_types =
list(ContentType.objects.filter(app_label=app.__name__.split('.')[-2]))
app_models = get_models(app)
#print "app, app_models", app, app_models
if not app_models:
return
for klass in app_models:
opts = klass._meta
#print "klass, opts", klass, opts, opts.__dict__
try:
ct = ContentType.objects.get(app_label=opts.app_label,
 model=opts.object_name.lower())
content_types.remove(ct)
except ContentType.DoesNotExist:
ct = ContentType(name=smart_unicode(opts.verbose_name_raw),
app_label=opts.app_label,
model=opts.object_name.lower())
print ct.name, len(ct.name), ct.app_label, ct.model
ct.save()
if verbosity >= 2:
print "Adding content type '%s | %s'" % (ct.app_label,
ct.model)

[...]

while running unittests, gives this output and error.

Adding content type 'contact | webaddress'
postal address 14 contact postaladdress
Adding content type 'contact | postaladdress'
postal address boundary 23 contact postaladdressboundary
Adding content type 'contact | postaladdressboundary'
contact mechanism link 22 contact contactmechanismlink
Adding content type 'contact | contactmechanismlink'

===
Output of:
print ct.name, len(ct.name), ct.app_label, ct.model gives:

contact mechanism type_
deferred_creation_date_time_description_display_is_default_privilege_tok
en_record_deleted_record_enabled 128 contact 
contactmechanismtype_deferred_creation_date_time_description_display_is_
default_privilege_token_record_deleted_record_enabled
===
Traceback (most recent call last):
  File
"C:\1mvgdocs\neodfos_workspace\neodfos\trunk\src\tools\tests\run_tests.p
y", line 245, in 
test_name =
connection.creation.create_test_db(verbosity=db_verbosity,
autoclobber=autoclobber)
  File "C:\Python26\lib\site-packages\django\db\backends\creation.py",
line 336, in create_test_db
call_command('syncdb', verbosity=verbosity, interactive=False)
  File
"C:\Python26\lib\site-packages\django\core\management\__init__.py", line
166, in call_command
return klass.execute(*args, **defaults)
  File "C:\Python26\lib\site-packages\django\core\management\base.py",
line 222, in execute
output = self.handle(*args, **options)
  File "C:\Python26\lib\site-packages\django\core\management\base.py",
line 351, in handle
return self.handle_noargs(**options)
  File
"C:\Python26\lib\site-packages\django\core\management\commands\syncdb.py
", line 99, in handle_noargs
emit_post_sync_signal(created_models, verbosity, interactive)
  File "C:\Python26\lib\site-packages\django\core\management\sql.py",
line 205, in emit_post_sync_signal
interactive=interactive)
  File "C:\Python26\lib\site-packages\django\dispatch\dispatcher.py",
line 166, in send
response = receiver(signal=self, sender=sender, **named)
  File
"C:\Python26\lib\site-packages\django\contrib\contenttypes\management.py
", line 28, in update_contenttypes
ct.save()
  File "C:\Python26\lib\site-packages\django\db\models\base.py", line
410, in save
self.save_base(force_insert=force_insert, force_update=force_update)
  File "C:\Python26\lib\site-packages\django\db\models\base.py", line
495, in save_base
result = manager._insert(values, return_id=update_pk)
  File "C:\Python26\lib\site-packages\django\db\models\manager.py", line
177, in _insert
return insert_query(self.model, values, **kwargs)
  File "C:\Python26\lib\site-packages\django\db\models\query.py", line
1087, in insert_query
return query.execute_sql(return_id)
  File
"C:\Python26\lib\site-packages\django\db\models\sql\subqueries.py", line
320, in execute_sql
cursor = super(InsertQuery, self).execute_sql(None)
  File "C:\Python26\lib\site-packages\django\db\models\sql\query.py",
line 2369, in execute_sql
cursor.execute(sql, params)
  File "C:\Python26\lib\site-packages\django\db\backends\util.py", line
19, in execute
return self.cursor.execute(sql, params)
psycopg2.DataError: value too long for type character varying(100)


The error can be eliminated if the .only() method is not used:

#for subtype in type_entity.objects.all().only('slug'):
for subtype in type_entity.objects.all():


The tests complete without error when changing the above line to not use
.only().

Other output from the various print statements in update_contenttypes 
(note the last model listed):


Re: Django with GXmlHttp

2009-11-25 Thread 504Django
Tim,

Thanks. That's exactly the kind of simple example that I was looking
for of how to bridge the two worlds of Django templates and Ajax. BTW,
me living in a major crucible of brass band music, I'm completely
fascinated by your site and brass band culture in England -- of which
to date I was completely unfamiliar despite living there for six
months.

The example poses an additional dilemma, however, which is probably
the subject of separate post: How to present data in a browser using a
mapping API without exposing valuable or sensitive data to
unscrupulous hackers.

Let's say it's sensitive data that required an enormous investment to
scrape and aggregate.

The project I'm working would require mapping and charting events
without exposing the bulk of data or other attributes in a way that
could be easily filched.

I think the answer might be server-side Javascript -- something
ASP.NET can handle with the Ajax Toolkit, and Ruby on Rails can handle
-- as I understand it -- by allowing injection of Javascript into its
templates. Django seems to have left Javascript out of mind, which I
view as a weakness.

There do appear to be some Django kludges -- using Jaxer for example.

http://filthyweasel.co.uk/post/7/

Then again, maybe I should really be investing my time learning how to
deploy GeoDjango.

I really looking for an expert opinion before I discover that I've
scaled the wrong mountain.

I'd appreciate any additional comments the Django community might
offer. This seems like a discussion others would benefit from as well.


On Nov 25, 7:56 am, Tim Sawyer  wrote:
> Not quite sure what you're looking for, but I've used google maps with
> django, without using GeoDjango.
>
> http://www.brassbandresults.co.uk/map/
>
> The script used in this page is here:
>
> http://www.brassbandresults.co.uk/map/map_script.js
>
> which is generated using this template:
>
>   function initialize() {
>        if (GBrowserIsCompatible()) {
>          var map = new GMap2(document.getElementById("map_canvas"));
> {% if Band %}
>          map.setCenter(new GLatLng({{Band.latitude}},
> {{Band.longitude}}), 12);
> {% else %}
>                 map.setCenter(new GLatLng(53.800651, -1.454), 8);
> {% endif %}
>          map.setUIToDefault();
>                 var mgr = new MarkerManager(map);
>                 var lBandMarkers = [];
> {% for band in Bands %}
> {% if band.latitude %}
> {% if band.longitude %}
>                 lPoint{{band.id}} = new GLatLng({{band.latitude}}, 
> {{band.longitude}});
>                 lMarker{{band.id}} = new GMarker(lPoint{{band.id}}, {title:
> "{{band.name}}"});
>                 GEvent.addListener(lMarker{{band.id}}, "click", function() {
>                         var myHtml = "{{band.name}}{% if 
> band.rehearsal_night_1
> %}Rehearsals {{band.rehearsal_nights}}{%endif%}[ href='/bands/{{band.slug}}/'>ContestResults] [ target='_blank' href='{{band.website}}'>BandWebsite]";
>                         map.openInfoWindowHtml(lPoint{{band.id}}, myHtml);
>                 });
>                 lBandMarkers.push(lMarker{{band.id}});
> {% endif %}            
> {% endif %}
> {% endfor %}
>                 mgr.addMarkers(lBandMarkers, 0);
>                 mgr.refresh();
>        }
>      }
>
> Hope that helps,
>
> Tim.
>
> 504Django wrote:
> > Hmm ... the lack of a suggested solution to my question is
> > discouraging. The lack of common knowledge in the developer community
> > leads me to think that, aside from using the GeoDjango module, Django
> > may not be able to elegantly integrate with Google Maps AJAX API. It
> > that's truly the case, perhaps I should consider looking at a
> > different framework before I invest too much more effort.
>
> > On Nov 23, 10:01 pm, 504Django <504cr...@gmail.com> wrote:
> >> There seems to be a dearth of examples illustrating best practices in
> >> deploying Google Maps with Django.
>
> >> Common recommendations are to use GeoDjango.
>
> >> Of course, it doesn't have to be Google Maps. It could be
> >> OpenSteetMap, Yahoo Maps, or some other mapping API.
>
> >> Not necessarily related, there are also suggestions to use JQuery to
> >> handle AJAX requests.
>
> >> I'm trying to understand how to take the next step -- to make the
> >> required GXmlHttp GET requests calling a Django view that returns
> >> marker points, while not violating the RESTful nature of Django URLs.
>
> >> What would be the recommendation?
>
> >> To help the discussion along with an example, this might be the
> >> implementation of a pure AJAX solution returning XML with a Get
> >> request to a PHP page:
>
> >> var request = GXmlHttp.create();
> >> request.open('GET','query.php?var1=' + val1 + '=' + val1, true);
> >> request.onreadystatechange = function() {
> >>         if (request.readyState == 4) {
> >>                 if (request.status == 200) {
> >>                         var xmlsource = request.responseXML;
> >>                         var markers = 
> >> 

Re: cannot import name settings - accessing Django environment from external script

2009-11-25 Thread Bill Freeman
Does /var/www/sites/project/__init__.py exist?

Are the files and directories readable, and the directories searchable
(excutable)
by the user as which the webserver runs?

On Wed, Nov 25, 2009 at 12:21 PM, Stodge  wrote:
> If I break the code out and write a simple python script that only
> contains:
>
> import sys, os
> sys.path.append("/var/www/sites")
> from project import settings
> from django.core.management import setup_environ
> setup_environ(settings)
>
> Even this doesn't work yet as far as I can tell, it should. Any ideas?
>
> --
>
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>
>

--

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




Re: calendar.js can't find variable gettext

2009-11-25 Thread Todd Blanchard
Did that, filed it.  Ticket #12264

-Todd Blanchard

On Nov 25, 2009, at 8:01 AM, Tim Valenta wrote:

> 
> 
> On Nov 24, 10:32 pm, Todd Blanchard  wrote:
>> Yep, I solved this by ripping and copying some code out of admin/sites.py
>> and adding a url conf for it.
>> 
>> It works now, but this should be included by default through the widget 
>> media dependency system.  Not very slick.  I tried filing a bug and the 
>> submission was rejected as spam.
> 
> I'd just sign up for the account.  It's pretty simple.  Filing bugs is
> how this thing gets better-- I'd urge you not to just let it drop.
> 
> Glad that that worked out for you.  I learned something about it,
> myself.  It had never struck me that it was a view :)
> 
> Tim
> 
>> 
>> -Todd Blanchard
>> 
>> On Nov 24, 2009, at 8:42 PM, Karen Tracey wrote:
>> 
>> 
>> 
>>> On Tue, Nov 24, 2009 at 8:56 PM, Todd Blanchard  wrote:
>>> I'm trying to use the date/time entry widgets from admin and I get this 
>>> javascript error and the controls don't render.
>> 
>>> Where is this supposed to come from?
>> 
>>> In annoyance, I have copied the head section precisely from an admin page 
>>> that work.  Still doesn't work in my page.
>> 
>>> 
>>> 
>>> 
>> 
>>> 
>> 
>>> This is the one gettext would be coming from and I'm guessing the relative 
>>> path here is causing a problem.  (gettext is internationalization support, 
>>> and jsi18n is javascript internationalization support, I'd guess)  jsi18n 
>>> is an admin view:
>> 
>>> http://code.djangoproject.com/browser/django/tags/releases/1.1.1/djan...
>>> http://code.djangoproject.com/browser/django/tags/releases/1.1.1/djan...
>> 
>>> It is not being pulled in via a form media definition but rather looks to 
>>> be hardcoded into the templates that depend on it, for example:
>> 
>>> http://code.djangoproject.com/browser/django/tags/releases/1.1.1/djan...
>> 
>>> It seems using the admin widgets that use the i18n javascript is a bit more 
>>> involved than just importing them and using them.  Maybe there is some 
>>> elegant way you're supposed to pull in this javascript, but I don't know it 
>>> (I don't know much when it comes to javascript).
>> 
>>> 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-us...@googlegroups.com.
>>> To unsubscribe from this group, send email to 
>>> django-users+unsubscr...@googlegroups.com.
>>> For more options, visit this group 
>>> athttp://groups.google.com/group/django-users?hl=en.
> 
> --
> 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 
> 

--

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




Re: cannot import name settings - accessing Django environment from external script

2009-11-25 Thread Stodge
Uh-oh: when did this break?


./manage.py shell
Error: Could not import settings 'indigo.settings' (Is it on sys.path?
Does it have syntax errors?): No module named settings




On Nov 25, 12:21 pm, Stodge  wrote:
> If I break the code out and write a simple python script that only
> contains:
>
> import sys, os
> sys.path.append("/var/www/sites")
> from project import settings
> from django.core.management import setup_environ
> setup_environ(settings)
>
> Even this doesn't work yet as far as I can tell, it should. Any ideas?

--

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




Re: Accessing model instance on pre_save signal

2009-11-25 Thread Preston Holmes
I'm a bit confused on a few points here.  The upload_to field
attribute should be atomic to the imagefield - it doesn't rely on
related models.

your change_upload_to creates a new screenshot - but doesn't connect
it to the current WebProject instance.  Is that what you are trying to
do?

s = ScreenShot(project=instance)

Is there a reason your WebProject is not defined when you create a
screenshot in your view?

Something about this seems like it is making it more complicated than
it needs to be. but details are lacking t

-Preston

On Nov 24, 5:52 pm, neridaj  wrote:
> Hello,
>
> I'm trying to change the upload_to attribute of an ImageField so that
> it is in the format "web_projects/year/slug/". The problem I am having
> is that the ForeignKey model is getting saved before the related
> ScreenShot model is able to call it's save method to change upload_to.
> I'm trying to use a pre_save signal to reverse the order of saving but
> I'm not sure how to access the current instance of the ScreenShot
> model to call it's save method. Thanks for any suggestions.
>
> class ScreenShot(models.Model):
>         project = models.ForeignKey(WebProject)
>         image = models.ImageField(upload_to="web_projects/%Y/")
>         page_title = models.CharField(max_length=250, help_text="Maximum 250
> characters.")
>
>         def __unicode__(self):
>                 return self.page_title
>
>         def save(self):
>                 self.image.upload_to="web_projects/%Y/"+self.project.slug
>                 super(ScreenShot, self).save()
>
> def change_upload_to(sender, **kwargs):
>         s = ScreenShot() # not sure how to access current instance
>         s.save()
>
> pre_save.connect(change_upload_to, sender=WebProject)

--

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




Re: Why are collapsed fieldsets expanded on submit in the admin?

2009-11-25 Thread Bill Freeman
You could attempt to conditionalize this on browser version.

On Wed, Nov 25, 2009 at 10:14 AM, Tom Evans  wrote:
> On Mon, Nov 23, 2009 at 3:57 PM, Benjamin Wohlwend 
> wrote:
>>
>> Hi,
>>
>> currently, when a form in the admin has collapsed fieldsets, those
>> fieldsets are expanded on submit. As I find this rather distracting
>> and couldn't find an explanation why this should be desired behavior,
>> I suspected that this is probably a hard to find bug somewhere in
>> between CSS, HTML and Django's JavaScript code.
>>
>> When I finally took a look at the code, I was quite surprised that
>> this isn't a bug, but a feature:
>>
>> >    if (collapsed_seen) {
>> >            // Expand all collapsed fieldsets when form is submitted.
>> >
>> >  addEvent(findForm(document.getElementsByTagName('fieldset')[0]), 'submit',
>> > function() { CollapsedFieldsets.uncollapse_all(); });
>> >    }
>>
>> This code is in the admin since revision 96 [1]. But why? From a
>> technical view, both the client and the server couldn't care less if
>> the form fields are visible or not, they process them all the same.
>> Was it UI-motivated?
>
> If that was true, then you would be right. However it isn't true. Some
> browsers will not submit non hidden form elements if they are not rendered.
> Admittedly, only crap old browsers[1].
>
> Cheers
>
> Tom
>
> [1]
> http://bytes.com/topic/javascript/answers/89759-problems-form-elements-hidden-div-style-display-none
>
> --
>
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

--

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




Re: cannot import name settings - accessing Django environment from external script

2009-11-25 Thread Stodge
If I break the code out and write a simple python script that only
contains:

import sys, os
sys.path.append("/var/www/sites")
from project import settings
from django.core.management import setup_environ
setup_environ(settings)

Even this doesn't work yet as far as I can tell, it should. Any ideas?

--

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




Re: Form foreign key add new

2009-11-25 Thread Tim Valenta
> I don't know what to replace XXX with, I know it's a db_field
>  but I don't
> know how/where to get it from.

AutoFields are the auto-incrementing primary key of your model.  By
default, your models get an automatic "id" attribute, which is what
this is.  Django frequently deals with the raw database objects,
instead of their values.

I've never tried to do what you're trying to accomplish, so I'm not
sure that I have much else to suggest.

Tim

On Nov 25, 9:25 am, cerberos  wrote:
> I want the same add new functionality as model foreign key select
> boxes in admin, there the select widget is passed through
> django.contrib.admin.widgets.RelatedFieldWidgetWrapper to add the
> additional html (image, links etc).
>
> The __init__.py takes the admin_site instance, I want this
> functionality for my site, not admin area so I'm trying to extend the
> class and override the init method so admin_site is not required.
>
> from django.contrib.admin.widgets import RelatedFieldWidgetWrapper
>
> class MyRelatedFieldWidgetWrapper(RelatedFieldWidgetWrapper):
>     """
>     This class is a wrapper to a given widget to add the add icon.
>     """
>     def __init__(self, widget, rel):
>         self.is_hidden = widget.is_hidden
>         self.needs_multipart_form = widget.needs_multipart_form
>         self.attrs = widget.attrs
>         self.choices = widget.choices
>         self.widget = widget
>         self.rel = rel
>
> And here's how I'm using it
>
> class DDCForm(forms.ModelForm):
>     """
>     Enables a form to be created from the model
>     """
>     location = forms.ModelChoiceField(Location.objects.all(), >>>
> widget=widgets.MyRelatedFieldWidgetWrapper(forms.Select(),XXX))
>
>     class Meta:
>         model = DDC
>
> I don't know what to replace XXX with, I know it's a db_field
>  but I don't
> know how/where to get it from.

--

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




Re: string-based fields and null

2009-11-25 Thread Tim Valenta
In most cases, any string field should be allowed to be blank, and can
easily survive WITHOUT "null=True".  As stated before me, this is
preferable.  For instance, you asked about FileField, among others.
This is perfectly fine to only use "blank=True".

You'll primarily only be using "null=True" on fields that cannot
actually be blank in the database.  A Date/DateTime field, for
instance.  an empty string isn't a valid value in MySQL, therefore you
must also use "null=True", to achieve the blank effect.  The same goes
for a BooleanField in Django.  Again, a blank string isn't a valid
boolean value, so null=True is required.

In short, always try to make "blank=True" work out, and only pair it
up with "null=True" when you're dealing with database fields that
actually cannot legally have a blank string as a value.

Tim

On Nov 25, 8:58 am, Bill Freeman  wrote:
> The major problem that I see with NULL in strings is that there may be 
> databases
> out there that don't distinguish between NULL and "", that is that store them
> the same way.
>
> "" is just as good in most cases.  It behaves like False in python and
> template tag
> tests.  And it has the advantage that if you go ahead and apply a
> string operation
> to it without checking first, it won't raise an exception because the
> operation isn't
> applicable to the None object.  You can't test for it by using ISNULL
> in SQL, but
> unless NULL has a different meaning for you than "empty", who cares?
>
> There are certainly cases where you might, for example, want to
> distinguish between
> "never been set" or "is unset", and "displays as no characters", and you could
> encode the former states as NULL.  But you could also use a separate boolean.
> Think about which code is going to be easier to maintain, especially
> if by someone
> else when they don't have you to talk to.  If this table will have
> billions of rows, then
> it might be worth thinking about the memory consumed for that boolean,
>   But then
> in an year and a half, hard drives will be twice as big.
>
> Still, python (and lisp and C) programmers are used to thinking about
> the possibility
> of None (or nil or (void *)0), so experienced programmers may have an easy 
> time
> with maintenance or a NULL flag design.
>
> So, it's not a hard and fast rule.  I still think that inconsistent
> backend support is the
> major factor.
>
> Bill
>
>
>
> On Tue, Nov 24, 2009 at 1:08 AM, chefsmart  wrote:
> > The Django docs suggest "Avoid using null on string-based fields such
> > as CharField and TextField unless you have an excellent reason."
>
> > ImageField, EmailField, FileField, FilePathField, IPAddressField,
> > SlugField, URLField, XMLField are also a string-based fields at the db
> > level, so am I right in assuming that null=True is best avoided in
> > these case also, "unless you have an excellent reason."?
>
> > I am hoping Django has code to deal with the empty string value in
> > these fields. For example, I am hoping that Django understands that an
> > empty string in an ImageField means there is no corresponding image.
>
> > --
>
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/django-users?hl=en.

--

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




Re: Form foreign key add new

2009-11-25 Thread cerberos
I've realised I can't inherit from RelatedFieldWidgetWrapper because I
want to override __init__ so I've copies the entire class an made a
few changes. Still need to know what to pass in for rel.

--

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




Re: View assistance

2009-11-25 Thread Jamie Pittock
Thanks again.

On Nov 25, 4:00 pm, Javier Guerra  wrote:
> On Wed, Nov 25, 2009 at 10:42 AM, Jamie Pittock  
> wrote:
> > Rolando, thanks.  Both your and Javier's solutions work.  Do they both
> > do the same think in different ways?  Is one way better than the other
> > in any way?
>
> i guess the generated SQL is the same.
>
> and as for better it's a matter of taste
>
> --
> Javier

--

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




Re: How to resolve the view name from a url

2009-11-25 Thread Bill Freeman
Note that url pattern's aren't required to have names, so you can't capture
statistics on unnamed urls patterns in apps that you want to use unmodified.

If, on the other hand, you just want to collect statistics on url patters which
are "under your control", and thus can be required to have names, you can
add a copy of the name (or whatever token you like) to the extra context.
You could even make it less painful by providing your own implementation
of url that does it for you, either with a different name, which you apply to
the patterns of interest, or to the whole file by importing your version as
url.  You must be sure that all the views in question are prepared for the
extra context.

Bill

On Tue, Nov 24, 2009 at 5:48 AM, bcurtu  wrote:
> No, I don't.
>
> I want to know the name of the url for a given url pattern. So, when I
> get in my method the url someone is asking for (next='/people/'), I
> want to know the name of the url that identifies this pattern
> (people_name). It's not for a HttpRedirect, it's for statistical
> porpouses.
>
> It's something like resolve, but not reverse.
>
> Thanks
>
> On 24 nov, 11:15, rebus_  wrote:
>> 2009/11/24 bcurtu :
>>
>>
>>
>> > Hi,
>>
>> > I want to get the url name from a url. For example, having:
>>
>> >    url(
>> >        regex   = r'^people/$',
>> >        view    = 'people_view',
>> >        name    = 'people_name'
>> >        ),
>>
>> > and
>>
>> > @login_required
>> > def people_view(request)...
>> >     _some_code_here...
>>
>> > I'm looking for a function that accepts "people/" and returns
>> > "people_name". I have tried to use django.core.urlresolvers.resolve,
>> > however it returns a wrapper fuction for login_required.
>>
>> > Is it posible?
>>
>> > --
>>
>> > You received this message because you are subscribed to the Google Groups 
>> > "Django users" group.
>> > To post to this group, send email to django-us...@googlegroups.com.
>> > To unsubscribe from this group, send email to 
>> > django-users+unsubscr...@googlegroups.com.
>> > For more options, visit this group 
>> > athttp://groups.google.com/group/django-users?hl=en.
>>
>> Usually what you want to do is:
>>
>> from django.core.urlresolvers import reverse
>> reverse('people_name')
>>
>> http://docs.djangoproject.com/en/dev/topics/http/urls/#reverse
>>
>> I don't see why you need url name, i think the name is meant to be
>> used to resolve urls not other way around.
>
> --
>
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>
>

--

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




Form foreign key add new

2009-11-25 Thread cerberos
I want the same add new functionality as model foreign key select
boxes in admin, there the select widget is passed through
django.contrib.admin.widgets.RelatedFieldWidgetWrapper to add the
additional html (image, links etc).

The __init__.py takes the admin_site instance, I want this
functionality for my site, not admin area so I'm trying to extend the
class and override the init method so admin_site is not required.

from django.contrib.admin.widgets import RelatedFieldWidgetWrapper

class MyRelatedFieldWidgetWrapper(RelatedFieldWidgetWrapper):
"""
This class is a wrapper to a given widget to add the add icon.
"""
def __init__(self, widget, rel):
self.is_hidden = widget.is_hidden
self.needs_multipart_form = widget.needs_multipart_form
self.attrs = widget.attrs
self.choices = widget.choices
self.widget = widget
self.rel = rel


And here's how I'm using it

class DDCForm(forms.ModelForm):
"""
Enables a form to be created from the model
"""
location = forms.ModelChoiceField(Location.objects.all(), >>>
widget=widgets.MyRelatedFieldWidgetWrapper(forms.Select(),XXX))

class Meta:
model = DDC


I don't know what to replace XXX with, I know it's a db_field
 but I don't
know how/where to get it from.


--

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




cannot import name settings - accessing Django environment from external script

2009-11-25 Thread Stodge
I'm completely confused. I have a Django environment installed in /var/
www/sites/project, which is accessed using mod_python/Apache. I want
to access the Django environment from a script - actually a Mercurial
hook. So I added this to my hook:

sys.path.append("/var/www/sites")
os.environ['DJANGO_SETTINGS_MODULE'] = 'project.settings'
from project import settings
from django.core.management import setup_environ
setup_environ(settings)

But I get an exception:

cannot import name settings

I've triple checked everything and read numerous pages found through
Google that all seem to say I'm doing this right. Any ideas?

--

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




Re: reversing URLs

2009-11-25 Thread Tim Valenta
I thank you, Karen, for the pointer on that user-issue I had :)

For the sake of putting this information on the same thread, I wanted
to make note of the following:

I had not realized that models.permalink depends on the `sites`
application.  I had removed this for the sake of simplifying the admin
options as much as possible for those who would use it.  But, having
removed that app a long time ago, I now get a different exception.

'servicetrac.django_site' doesn't exist

A patch to the docs on permalink might be worthwhile, to point out
simply that this dependency.  ... or... is it a "reverse" method
dependency?  Given my confusion over how to use it in the past, I've
never really checked specifically to see if `sites` was required for
reversing to begin with.  Either way, I'm not seeing docs which state
this.

I'll correct the issue, now that I'm on the right track, but is there
anything else that you could add about the dependency I've noted?

Thanks,

Tim

On Nov 24, 10:39 pm, Tim Valenta  wrote:
> Holy cow you're right.  That was an extreme case of needing another pair of
> eyes.  I thought I had tested the view after using that syntax, but I must
> not have tested the right scenario.
>
> Many thanks. I will check it out in the morning :)
>
> Tim
>
> Sent from my iPod; pardon any typos and poor grammar!
>
> On Nov 24, 2009, at 10:33 PM, Karen Tracey  wrote:
>
> On Tue, Nov 24, 2009 at 11:20 PM, Tim Valenta 
> wrote:
>
>
>
>
>
> > Thanks for the reply.  Yes, I can give a bit more info on it.
>
> > So, for starters, my (abbreviated) main url conf looks like this:
>
> >    urlpatterns = patterns('',
> >        (r'^surveys/', include('servicetrac.surveys.urls')),
> >    )
>
> > ... which links over to the app's urls:
>
> >    urlpatterns = patterns('servicetrac.surveys.views',
> >        (r'^(?P[^/]+)/(?P\d+)/web/take/(?
> > P\d+)', 'take_survey', {
> >            'name': 'this_is_a_name',
> >        }),
>
> From what you have below it sounds like you are intending to name this url
> pattern 'this_is_a_name'.  But that is not what you have done here --
> rather, you are passing an additional keyword parameter, name, with value
> 'this_is_a_name', to your take_survey view.  (Which is going to cause an
> error an any use of this pattern, since your view isn't expecting that
> keyword parameter.)
>
> To name this pattern, you would either do:
>
>       (r'^(?P[^/]+)/(?P\d+)/web/take/(?P\d+)',
> 'take_survey', {}, 'this_is_a_name'),
>
> That is, specify the name as the 4th item in the tuple -- you must include
> an empty optional dictionary as the 3rd item since there is no way to
> specify a 4th item without a 3rd using the tuple format.  Or use the url
> function, and specify the name keyword argument to it:
>
> url(r'^(?P[^/]+)/(?P\d+)/web/take/(?P\d+)',
> 'take_survey'. name='this_is_a_name'),
>
>
>
>
>
> >        (r'^(?P[^/]+)/(?P\d+)/web/take',
> > 'take_survey', {'page': 1}),
> >    )
>
> > And the "take_survey" view signature:
>
> >    take_survey(request, company_slug, event_id, page=1)
>
> > The default parameter for 'page' is a little redundant to what the
> > urls define, but it's self-documenting, in my mind.
>
> > So, up to this point, everything works as expected.  Absolutely no
> > problems.  The view works great, tested under both of the possible
> > urls to get there.  But of course, I wanted to partake of the niceness
> > of having a "View on site ->" link on the admin page for the object,
> > so I began to implement the "get_absolute_url" method, employing the
> > decorator "models.permalink", as described previously:
>
> >    # in my "Event" model
> >   �...@models.permalink
> >    def get_absolute_url(self):
> >        return ('this_is_a_name', (), {
> >            'company_slug': self.company.slug
> >            'event_id': self.id
> >            'page': 1
> >        })
>
> Once you get the naming working, I'd expect this to work,assuming you have
> commas on the end of a couple of those lines.  Alternatively, don't use the
> name but rather specify 'servicetrac.surveys.views.take_survey' -- that is
> the full name, including prefix from the patterns() call.
>
> 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-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

--

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




Re: settings.py seems to be cached or stuck

2009-11-25 Thread Tim Valenta
> Thanks Karen. Is annoying sometimes when you see people don't bother
> reading past the single mod_wsgi page on Django site even though I put
> disclaimers at front to try and encourage people to do so without
> making it too blatant that what I wanted to say was 'STOP BEING LAZY
> AND GO READ THE REAL MOD_WSGI DOCUMENTATION'. ;-)

Since that had stemmed from what I had initially said, I'd briefly
defend the position I had taken, since my personal preference is to
not run my ever-changing development code on a production web server.
I've read that blog post Karen linked to a long time ago, but I
clearly forgot about it, given that I have never required my
production server to reload development files.

I've read the docs.  I just forgot about this capability.  I'm not
lazy :)  Just busy.  Apologies to the original thread-starter for my
inaccurate conclusion.

Tim

On Nov 24, 10:55 pm, Graham Dumpleton 
wrote:
> On Nov 25, 3:58 pm, Karen Tracey  wrote:
>
>
>
>
>
> > On Tue, Nov 24, 2009 at 11:32 PM, Tim Valenta 
> > wrote:
>
> > > Yeah, production servers aren't really very friendly to changes.
> > > Languages like PHP are specifically built to circumvent such woes.
> > > You would have to actually bounce apache in order to get the changes
> > > to take.
>
> > > This is why the development server is so nice, because when you alter
> > > certain files that it watches, it actually restarts automatically for
> > > you.  There's not really going to be a solution for this problem,
> > > since this is inherent to production-class web servers, where PHP and
> > > general CGI is the exception.
>
> > > Hope that's not a big problem!
>
> > > I still liked to run a production server version of my project, so I
> > > made a local SVN repository which I would commit changes to.  I
> > > checked out a copy of the repository to where my production server
> > > wanted to see it, and then put up a clumsy cron job would
> > > automatically update the production machine's repository each day, and
> > > bounce Apache for me.
>
> > > That's about as close as it'll get, I think :P
>
> > You don't give details on what your production environment is so I don't
> > know if you can get closer there, but with mod_wsgi you can get closer.
>
> > With mod_wsgi in daemon mode just touching the wsgi script file will result
> > in a reload on the next request.  You can even set things up so that it
> > reloads automatically on source code changes.  Graham Dumpleton sets outs
> > all the details in a blog entry here:
>
> >http://blog.dscpl.com.au/2008/12/using-modwsgi-when-developing-django...
>
> Thanks Karen. Is annoying sometimes when you see people don't bother
> reading past the single mod_wsgi page on Django site even though I put
> disclaimers at front to try and encourage people to do so without
> making it too blatant that what I wanted to say was 'STOP BEING LAZY
> AND GO READ THE REAL MOD_WSGI DOCUMENTATION'. ;-)
>
> Graham

--

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




Re: calendar.js can't find variable gettext

2009-11-25 Thread Tim Valenta


On Nov 24, 10:32 pm, Todd Blanchard  wrote:
> Yep, I solved this by ripping and copying some code out of admin/sites.py
> and adding a url conf for it.
>
> It works now, but this should be included by default through the widget media 
> dependency system.  Not very slick.  I tried filing a bug and the submission 
> was rejected as spam.

I'd just sign up for the account.  It's pretty simple.  Filing bugs is
how this thing gets better-- I'd urge you not to just let it drop.

Glad that that worked out for you.  I learned something about it,
myself.  It had never struck me that it was a view :)

Tim

>
> -Todd Blanchard
>
> On Nov 24, 2009, at 8:42 PM, Karen Tracey wrote:
>
>
>
> > On Tue, Nov 24, 2009 at 8:56 PM, Todd Blanchard  wrote:
> > I'm trying to use the date/time entry widgets from admin and I get this 
> > javascript error and the controls don't render.
>
> > Where is this supposed to come from?
>
> > In annoyance, I have copied the head section precisely from an admin page 
> > that work.  Still doesn't work in my page.
>
> >     
> >     
> >     
>
> >     
>
> > This is the one gettext would be coming from and I'm guessing the relative 
> > path here is causing a problem.  (gettext is internationalization support, 
> > and jsi18n is javascript internationalization support, I'd guess)  jsi18n 
> > is an admin view:
>
> >http://code.djangoproject.com/browser/django/tags/releases/1.1.1/djan...
> >http://code.djangoproject.com/browser/django/tags/releases/1.1.1/djan...
>
> > It is not being pulled in via a form media definition but rather looks to 
> > be hardcoded into the templates that depend on it, for example:
>
> >http://code.djangoproject.com/browser/django/tags/releases/1.1.1/djan...
>
> > It seems using the admin widgets that use the i18n javascript is a bit more 
> > involved than just importing them and using them.  Maybe there is some 
> > elegant way you're supposed to pull in this javascript, but I don't know it 
> > (I don't know much when it comes to javascript).
>
> > 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-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/django-users?hl=en.

--

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




Re: View assistance

2009-11-25 Thread Javier Guerra
On Wed, Nov 25, 2009 at 10:42 AM, Jamie Pittock  wrote:
> Rolando, thanks.  Both your and Javier's solutions work.  Do they both
> do the same think in different ways?  Is one way better than the other
> in any way?

i guess the generated SQL is the same.

and as for better it's a matter of taste

-- 
Javier

--

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




Re: string-based fields and null

2009-11-25 Thread Bill Freeman
The major problem that I see with NULL in strings is that there may be databases
out there that don't distinguish between NULL and "", that is that store them
the same way.

"" is just as good in most cases.  It behaves like False in python and
template tag
tests.  And it has the advantage that if you go ahead and apply a
string operation
to it without checking first, it won't raise an exception because the
operation isn't
applicable to the None object.  You can't test for it by using ISNULL
in SQL, but
unless NULL has a different meaning for you than "empty", who cares?

There are certainly cases where you might, for example, want to
distinguish between
"never been set" or "is unset", and "displays as no characters", and you could
encode the former states as NULL.  But you could also use a separate boolean.
Think about which code is going to be easier to maintain, especially
if by someone
else when they don't have you to talk to.  If this table will have
billions of rows, then
it might be worth thinking about the memory consumed for that boolean,
  But then
in an year and a half, hard drives will be twice as big.

Still, python (and lisp and C) programmers are used to thinking about
the possibility
of None (or nil or (void *)0), so experienced programmers may have an easy time
with maintenance or a NULL flag design.

So, it's not a hard and fast rule.  I still think that inconsistent
backend support is the
major factor.

Bill

On Tue, Nov 24, 2009 at 1:08 AM, chefsmart  wrote:
> The Django docs suggest "Avoid using null on string-based fields such
> as CharField and TextField unless you have an excellent reason."
>
> ImageField, EmailField, FileField, FilePathField, IPAddressField,
> SlugField, URLField, XMLField are also a string-based fields at the db
> level, so am I right in assuming that null=True is best avoided in
> these case also, "unless you have an excellent reason."?
>
> I am hoping Django has code to deal with the empty string value in
> these fields. For example, I am hoping that Django understands that an
> empty string in an ImageField means there is no corresponding image.
>
> --
>
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>
>

--

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




Re: View assistance

2009-11-25 Thread Jamie Pittock
Rolando, thanks.  Both your and Javier's solutions work.  Do they both
do the same think in different ways?  Is one way better than the other
in any way?

On Nov 25, 3:40 pm, Jamie Pittock  wrote:
> Well that was ridiculously easy!  Thanks very much for responding
> Javier.
>
> On Nov 25, 3:25 pm, Javier Guerra  wrote:
>
>
>
> > On Wed, Nov 25, 2009 at 9:43 AM, Jamie Pittock  
> > wrote:
> > > This is working as expected.  However, the view is checking that the
> > > project_slug is found, and also that the task_id is found, but it's
> > > not checking that the found task is related to the found project.
>
> > def task_detail(request, project_slug, task_id):
> >        project = get_object_or_404(Project, slug=project_slug)
> >        return object_detail(
> >                                request,
> >                                queryset=project.task_set,
> >                                object_id=task_id,
> >                                template_object_name="task",
> >                                extra_context = { 'project': project }
> >                                )
>
> > --
> > Javier

--

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




Re: View assistance

2009-11-25 Thread Jamie Pittock
Well that was ridiculously easy!  Thanks very much for responding
Javier.


On Nov 25, 3:25 pm, Javier Guerra  wrote:
> On Wed, Nov 25, 2009 at 9:43 AM, Jamie Pittock  
> wrote:
> > This is working as expected.  However, the view is checking that the
> > project_slug is found, and also that the task_id is found, but it's
> > not checking that the found task is related to the found project.
>
> def task_detail(request, project_slug, task_id):
>        project = get_object_or_404(Project, slug=project_slug)
>        return object_detail(
>                                request,
>                                queryset=project.task_set,
>                                object_id=task_id,
>                                template_object_name="task",
>                                extra_context = { 'project': project }
>                                )
>
> --
> Javier

--

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




Re: View assistance

2009-11-25 Thread Rolando Espinoza La Fuente
Try
queryset=Task.objects.filter(project=project)

Regards,

On 11/25/09, Jamie Pittock  wrote:
> I have two models, Project and Task.  They are related via a foreign
> key in the task model.
>
> The view that displays a task is below...
>
> def task_detail(request, project_slug, task_id):
>   project = get_object_or_404(Project, slug=project_slug)
>   return object_detail(
>   request,
>   queryset=Task.objects.all(),
>   object_id=task_id,
>   template_object_name="task",
>   extra_context = { 'project': project }
>   )
>
> The URL would look like this...
>
> /projects/project_slug/tasks/task_id/
>
> This is working as expected.  However, the view is checking that the
> project_slug is found, and also that the task_id is found, but it's
> not checking that the found task is related to the found project.
>
> Could someone get me started on how best to write a view that would do
> that?  I'm presuming I'd have to part company with generic views for
> this?
>
> --
>
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>
>

-- 
Sent from Gmail for mobile | mobile.google.com

Rolando Espinoza La fuente
qoSoftware

www.qosoftware.com

--

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




Re: View assistance

2009-11-25 Thread Javier Guerra
On Wed, Nov 25, 2009 at 9:43 AM, Jamie Pittock  wrote:
> This is working as expected.  However, the view is checking that the
> project_slug is found, and also that the task_id is found, but it's
> not checking that the found task is related to the found project.

def task_detail(request, project_slug, task_id):
   project = get_object_or_404(Project, slug=project_slug)
   return object_detail(
   request,
   queryset=project.task_set,
   object_id=task_id,
   template_object_name="task",
   extra_context = { 'project': project }
   )




-- 
Javier

--

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




Re: Why are collapsed fieldsets expanded on submit in the admin?

2009-11-25 Thread Tom Evans
On Mon, Nov 23, 2009 at 3:57 PM, Benjamin Wohlwend wrote:

> Hi,
>
> currently, when a form in the admin has collapsed fieldsets, those
> fieldsets are expanded on submit. As I find this rather distracting
> and couldn't find an explanation why this should be desired behavior,
> I suspected that this is probably a hard to find bug somewhere in
> between CSS, HTML and Django's JavaScript code.
>
> When I finally took a look at the code, I was quite surprised that
> this isn't a bug, but a feature:
>
> >if (collapsed_seen) {
> >// Expand all collapsed fieldsets when form is submitted.
> >
>  addEvent(findForm(document.getElementsByTagName('fieldset')[0]), 'submit',
> function() { CollapsedFieldsets.uncollapse_all(); });
> >}
>
> This code is in the admin since revision 96 [1]. But why? From a
> technical view, both the client and the server couldn't care less if
> the form fields are visible or not, they process them all the same.
> Was it UI-motivated?
>

If that was true, then you would be right. However it isn't true. Some
browsers will not submit non hidden form elements if they are not rendered.
Admittedly, only crap old browsers[1].

Cheers

Tom

[1]
http://bytes.com/topic/javascript/answers/89759-problems-form-elements-hidden-div-style-display-none

--

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




View assistance

2009-11-25 Thread Jamie Pittock
I have two models, Project and Task.  They are related via a foreign
key in the task model.

The view that displays a task is below...

def task_detail(request, project_slug, task_id):
project = get_object_or_404(Project, slug=project_slug)
return object_detail(
request,
queryset=Task.objects.all(),
object_id=task_id,
template_object_name="task",
extra_context = { 'project': project }
)

The URL would look like this...

/projects/project_slug/tasks/task_id/

This is working as expected.  However, the view is checking that the
project_slug is found, and also that the task_id is found, but it's
not checking that the found task is related to the found project.

Could someone get me started on how best to write a view that would do
that?  I'm presuming I'd have to part company with generic views for
this?

--

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




Re: Why are collapsed fieldsets expanded on submit in the admin?

2009-11-25 Thread Benjamin Wohlwend
Sorry for the bump, but does no one have an explanation for this weird
behavior? The question comes up regularly when I show the admin
interface to a client.

On 23 Nov., 16:57, Benjamin  Wohlwend  wrote:
> Hi,
>
> currently, when a form in the admin has collapsed fieldsets, those
> fieldsets are expanded on submit. As I find this rather distracting
> and couldn't find an explanation why this should be desired behavior,
> I suspected that this is probably a hard to find bug somewhere in
> between CSS, HTML and Django's JavaScript code.
>
> When I finally took a look at the code, I was quite surprised that
> this isn't a bug, but a feature:
>
> >    if (collapsed_seen) {
> >            // Expand all collapsed fieldsets when form is submitted.
> >            addEvent(findForm(document.getElementsByTagName('fieldset')[0]), 
> > 'submit', function() { CollapsedFieldsets.uncollapse_all(); });
> >    }
>
> This code is in the admin since revision 96 [1]. But why? From a
> technical view, both the client and the server couldn't care less if
> the form fields are visible or not, they process them all the same.
> Was it UI-motivated?
>
> I, for one, find it quite disturbing that input fields appear all over
> the place when I click submit, just to vanish moments later to be
> replaced by a new page :)
>
> Regards,
> Benjamin
>
> [1]http://code.djangoproject.com/browser/django/trunk/media/js/admin/Col...

--

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




Re: Error message customization

2009-11-25 Thread Benjamin Wolf
Hi,
use a normal form and do it like this:
shipping_character  = forms.CharField(error_messages={'required': 'Your 
game character name'}, label='Charakter Name')

dr.NO schrieb:
> Hi,
>
> How can i display field name using verbose_name not just field name in
> validation of ModelForm ?
>
> For egz.
>
>   shipping_character = models.CharField('Your game character name
> ',max_length=50) <-- field from model
>
> if it's empty validatior error is shipping_character - field is
> required
> and i want it to be
> Your game character name - filed is required
>
> --
>
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>
>
>   

--

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




Re: how to import a library in only in django project

2009-11-25 Thread Tim Sawyer
Hi Amit,

It depends how you're running.

If you're using ./manage.py testserver, then change manage.py to add in 
your new path.

If you're using mod-wsgi, then change the site-wsgi.py file:

import os, sys
sys.path.append('/home/path/to/add')
os.environ['DJANGO_SETTINGS_MODULE'] = 'MySite.settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

Hope that helps,

Tim.

Amit Sethi wrote:
> 
> Hi ,
> I want to use a library in a django project but I don't want to put it 
> in python path. Where am I supposed to put the sys.append so that it 
> will available to the whole django project.
> -- 
> A-M-I-T S|S
> 
> --
> 
> You received this message because you are subscribed to the Google 
> Groups "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.

--

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




Re: Django with GXmlHttp

2009-11-25 Thread Tim Sawyer
Not quite sure what you're looking for, but I've used google maps with 
django, without using GeoDjango.

http://www.brassbandresults.co.uk/map/

The script used in this page is here:

http://www.brassbandresults.co.uk/map/map_script.js

which is generated using this template:

  function initialize() {
   if (GBrowserIsCompatible()) {
 var map = new GMap2(document.getElementById("map_canvas"));
{% if Band %}
 map.setCenter(new GLatLng({{Band.latitude}}, 
{{Band.longitude}}), 12);
{% else %}
map.setCenter(new GLatLng(53.800651, -1.454), 8);
{% endif %}
 map.setUIToDefault();
var mgr = new MarkerManager(map);
var lBandMarkers = [];
{% for band in Bands %}
{% if band.latitude %}
{% if band.longitude %}
lPoint{{band.id}} = new GLatLng({{band.latitude}}, 
{{band.longitude}});
lMarker{{band.id}} = new GMarker(lPoint{{band.id}}, {title: 
"{{band.name}}"});
GEvent.addListener(lMarker{{band.id}}, "click", function() {
var myHtml = "{{band.name}}{% if 
band.rehearsal_night_1 
%}Rehearsals {{band.rehearsal_nights}}{%endif%}[ContestResults] [BandWebsite]";
map.openInfoWindowHtml(lPoint{{band.id}}, myHtml);
});
lBandMarkers.push(lMarker{{band.id}});
{% endif %} 
{% endif %}
{% endfor %}
mgr.addMarkers(lBandMarkers, 0);
mgr.refresh();
   }
 }

Hope that helps,

Tim.

504Django wrote:
> Hmm ... the lack of a suggested solution to my question is
> discouraging. The lack of common knowledge in the developer community
> leads me to think that, aside from using the GeoDjango module, Django
> may not be able to elegantly integrate with Google Maps AJAX API. It
> that's truly the case, perhaps I should consider looking at a
> different framework before I invest too much more effort.
> 
> 
> On Nov 23, 10:01 pm, 504Django <504cr...@gmail.com> wrote:
>> There seems to be a dearth of examples illustrating best practices in
>> deploying Google Maps with Django.
>>
>> Common recommendations are to use GeoDjango.
>>
>> Of course, it doesn't have to be Google Maps. It could be
>> OpenSteetMap, Yahoo Maps, or some other mapping API.
>>
>> Not necessarily related, there are also suggestions to use JQuery to
>> handle AJAX requests.
>>
>> I'm trying to understand how to take the next step -- to make the
>> required GXmlHttp GET requests calling a Django view that returns
>> marker points, while not violating the RESTful nature of Django URLs.
>>
>> What would be the recommendation?
>>
>> To help the discussion along with an example, this might be the
>> implementation of a pure AJAX solution returning XML with a Get
>> request to a PHP page:
>>
>> var request = GXmlHttp.create();
>> request.open('GET','query.php?var1=' + val1 + '=' + val1, true);
>> request.onreadystatechange = function() {
>> if (request.readyState == 4) {
>> if (request.status == 200) {
>> var xmlsource = request.responseXML;
>> var markers = 
>> xmlsource.documentElement.getElementsByTagName
>> ("marker");
>> for (var i = 0; i < markers.length; i++) {
>> var lat = 
>> parseFloat(markers[i].getAttribute("lat"));
>> var lng = 
>> parseFloat(markers[i].getAttribute("lng"));
>> var latlng = new GLatLng(lat,lng);
> 
> --
> 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 
> 
> 

--

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




Re: Per-object permissions

2009-11-25 Thread rebus_
2009/11/25 Gamliel Roi :
> Any idea when 1.2 will be released?
>
>
>
> On Wed, Nov 25, 2009 at 3:31 PM, rebus_  wrote:
>>
>> 2009/11/25 Russell Keith-Magee :
>> > On Tue, Nov 24, 2009 at 11:16 PM, rebus_  wrote:
>> >> 2009/11/24 nek4life :
>> >>> You should look into django-authority.  I'm pretty sure that has per-
>> >>> object-permissions.
>> >>>
>> >>> http://packages.python.org/django-authority/index.html
>> >>>
>> >>> On Nov 24, 7:00 am, gamliel roi  wrote:
>>  Hello all,
>> 
>>  I have the admin site up and running but I need to create a group of
>>  users,
>>  such that each of the users will be able to edit objects that are
>>  only
>>  relevant to them (e.g Project objects that the user is also the
>>  ProjectManager).
>> 
>>  I know that in the past Django had a Per-object permissions branch,
>>  which is
>>  now abandoned.
>> 
>>  Should I peruse this direction and try to incorporate this branch to
>>  my
>>  current code? is it documented and running properly?
>> 
>>  Any other ideas/suggestions/resources regarding this problem?
>> 
>> >>>
>> >> Row level permisions should be implemented in Django version  1.2 [1]
>> >> if you have the time to wait...
>> >>
>> >> [1] http://code.djangoproject.com/wiki/Version1.2Features
>> >
>> > To be clear - that ticket *doesnt'* implement row-level permissions;
>> > it modifies the calls for permission checks to allow you to build a
>> > row-level permissions checker external to Django.
>> >
>> > Yours,
>> > Russ Magee %-)
>> >
>>
>> That's true, i probably wasn't too clear on this.
>>
>> But i would rather use Django API to implement row-level permissions
>> then start building my own implementation from scratch, if you have
>> the luxury of waiting till it hits trunk or comes out in 1.2 that is.
>>
>> Davor
>>
>> --
>>
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To post to this group, send email to django-us...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/django-users?hl=en.
>>
>>
>
>
>
> --
> Best
> Roi Gamliel
>
> --

http://code.djangoproject.com/wiki/Version1.2Roadmap

--

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




Re: Per-object permissions

2009-11-25 Thread Gamliel Roi
Any idea when 1.2 will be released?



On Wed, Nov 25, 2009 at 3:31 PM, rebus_  wrote:

> 2009/11/25 Russell Keith-Magee :
> > On Tue, Nov 24, 2009 at 11:16 PM, rebus_  wrote:
> >> 2009/11/24 nek4life :
> >>> You should look into django-authority.  I'm pretty sure that has per-
> >>> object-permissions.
> >>>
> >>> http://packages.python.org/django-authority/index.html
> >>>
> >>> On Nov 24, 7:00 am, gamliel roi  wrote:
>  Hello all,
> 
>  I have the admin site up and running but I need to create a group of
> users,
>  such that each of the users will be able to edit objects that are only
>  relevant to them (e.g Project objects that the user is also the
>  ProjectManager).
> 
>  I know that in the past Django had a Per-object permissions branch,
> which is
>  now abandoned.
> 
>  Should I peruse this direction and try to incorporate this branch to
> my
>  current code? is it documented and running properly?
> 
>  Any other ideas/suggestions/resources regarding this problem?
> 
> >>>
> >> Row level permisions should be implemented in Django version  1.2 [1]
> >> if you have the time to wait...
> >>
> >> [1] http://code.djangoproject.com/wiki/Version1.2Features
> >
> > To be clear - that ticket *doesnt'* implement row-level permissions;
> > it modifies the calls for permission checks to allow you to build a
> > row-level permissions checker external to Django.
> >
> > Yours,
> > Russ Magee %-)
> >
>
> That's true, i probably wasn't too clear on this.
>
> But i would rather use Django API to implement row-level permissions
> then start building my own implementation from scratch, if you have
> the luxury of waiting till it hits trunk or comes out in 1.2 that is.
>
> Davor
>
> --
>
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>
>


-- 
Best
Roi Gamliel

--

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




Error message customization

2009-11-25 Thread dr.NO
Hi,

How can i display field name using verbose_name not just field name in
validation of ModelForm ?

For egz.

shipping_character = models.CharField('Your game character name
',max_length=50) <-- field from model

if it's empty validatior error is shipping_character - field is
required
and i want it to be
Your game character name - filed is required

--

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




Re: Per-object permissions

2009-11-25 Thread rebus_
2009/11/25 Russell Keith-Magee :
> On Tue, Nov 24, 2009 at 11:16 PM, rebus_  wrote:
>> 2009/11/24 nek4life :
>>> You should look into django-authority.  I'm pretty sure that has per-
>>> object-permissions.
>>>
>>> http://packages.python.org/django-authority/index.html
>>>
>>> On Nov 24, 7:00 am, gamliel roi  wrote:
 Hello all,

 I have the admin site up and running but I need to create a group of users,
 such that each of the users will be able to edit objects that are only
 relevant to them (e.g Project objects that the user is also the
 ProjectManager).

 I know that in the past Django had a Per-object permissions branch, which 
 is
 now abandoned.

 Should I peruse this direction and try to incorporate this branch to my
 current code? is it documented and running properly?

 Any other ideas/suggestions/resources regarding this problem?

>>>
>> Row level permisions should be implemented in Django version  1.2 [1]
>> if you have the time to wait...
>>
>> [1] http://code.djangoproject.com/wiki/Version1.2Features
>
> To be clear - that ticket *doesnt'* implement row-level permissions;
> it modifies the calls for permission checks to allow you to build a
> row-level permissions checker external to Django.
>
> Yours,
> Russ Magee %-)
>

That's true, i probably wasn't too clear on this.

But i would rather use Django API to implement row-level permissions
then start building my own implementation from scratch, if you have
the luxury of waiting till it hits trunk or comes out in 1.2 that is.

Davor

--

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




Re: Translate models

2009-11-25 Thread Alessandro Pasotti
2009/11/25 Alessandro Ronchi 

> I need to make my model translatable into different languages.
> Is there any simple way to handle that in a transparent manner?
> I've fround transmeta project on google, anyone is using that?
>


Hi,

yes, I'm using transmeta, I had to modify a couple of things to suit my
needs but it's working fine so far.


-- 
Alessandro Pasotti
w3:   www.itopen.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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Re: Translate models

2009-11-25 Thread andreas schmid
ciao alessandro,

i am using transmeta for a project im developing and it seems to fit my
needs.
transmeta is easy to use and it creates a db column for every field you
defined as translatable.
the default and required language is the one you define as site language
in settings.py, and its also the "neutral" language which is shown even
on the other languages if you didnt write a translation.

in the last days i found a way to have a better behaviour for fields
which language doesnt exist but i dont want to show the default language:
in the template:
   {% ifequal LANGUAGE_CODE 'en' %}
{% if object.body_en %}
{{ object.body_en|safe }}
{% else %}
Sorry but the requested content doesnt exist in this
language. 
{% endif %}
   {% endifequal %}

i think in this way im having a clean way to avoid an ugly language mix.
im also using localeurl to get the language choice directly in the url
like http://www.mysite.com/en/my-content or
http://www.mysite.com/it/my-content

i hope this can help you

Alessandro Ronchi wrote:
> I need to make my model translatable into different languages.
> Is there any simple way to handle that in a transparent manner?
> I've fround transmeta project on google, anyone is using that?
>
> -- 
> Alessandro Ronchi
>
> SOASI
> Sviluppo Software e Sistemi Open Source
> http://www.soasi.com
> http://www.linkedin.com/in/ronchialessandro
>
> --
>
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.

--

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




Translate models

2009-11-25 Thread Alessandro Ronchi
I need to make my model translatable into different languages.
Is there any simple way to handle that in a transparent manner?
I've fround transmeta project on google, anyone is using that?

-- 
Alessandro Ronchi

SOASI
Sviluppo Software e Sistemi Open Source
http://www.soasi.com
http://www.linkedin.com/in/ronchialessandro

--

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




How to tell whether the current module is loaded under `manage.py test`

2009-11-25 Thread Alex Dong
Hi all,

During the `manage.py test` process, django will automatically change
the database from `hivemind` to `test_hivemind`,  For similar reason,
I'd like to change a file path from `sphinx.conf` to
`sphinx_test.conf` but unfortunately I couldn't find a proper way to
do it.

Ideally, if there is a django method called `django.test.is_testing()
`, then I should be able to change the filename based on the return
value.  Any hints on how I could do this?

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




many-to-many relation field__in - how to AND instead of OR?

2009-11-25 Thread anentropic
I have a query like:
Product.objects.filter(categories__in=cat_ids).distinct()

where categories is a m2m field.

As I understand it this loads products which have belong to ANY of the
categories in cat_ids

How would I load only products which belong to ALL of the categories
in cat_ids?

(is this possible in ORM?)

I think in SQL you'd have to change the one IN clause to a series of
ANDs

--

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




Extend Admin Search Form

2009-11-25 Thread Marco Minutoli
Hi Everybody,
I would like to add a complex search form in the change_list.html admin
template (for example to add possibility to search something from date
to date)
Is there a way to do this?
Thanks in advance.
Marco Minutoli

--

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




Class-based views, metaclasses and view validation

2009-11-25 Thread Alexander Dutton
Hi all,

I'd like to describe a little of the way we're using Django for our
site, http://m.ox.ac.uk/. I'd very much like to find out whether other
peoplethink that our approach is sensible, and if it is, I thought this
post might be useful for other people in tackling some of the issues
we've come across.

We're using class-based views, a concept that doesn't seem to have much
of a presence on the Internet[0]. The usual approach is to define a
method __call__(self, request, ...) on a class, an instance of which is
then placed in an urlconf. Our approach is the following:

 * Have a base view called, oddly enough, BaseView.
 * Define a method __new__(cls, request, ...) that despatches to other
   class methods depending on the HTTP method.
 * The __new__ method also calls a method to add common context for each
   of the handlers.
 * We use a metaclass to save having to put @classmethod decorators in
   front of every method.
 * We never create instances of the view classes; instead, __new__
   returns an HttpResponse object and the class itself is place in the
   urlconf.

Here's the code:

> from inspect import isfunction
> from django.template import RequestContext
>
> class ViewMetaclass(type):
> def __new__(cls, name, bases, dict):
> # Wrap all functions but __new__ in a classmethod before
> # constructing the class
> for key, value in dict.items():
> if isfunction(value) and key != '__new__':
> dict[key] = classmethod(value)
> return type.__new__(cls, name, bases, dict)
>
> class BaseView(object):
> __metaclass__ = ViewMetaclass
>
> def method_not_acceptable(cls, request):
> """
> Returns a simple 405 response.
> """
>
> response = HttpResponse(
> 'You can't perform a %s request against this resource.' %
> request.method.upper(),
> status=405,
> )
> return response
>
> # We could go on defining error status handlers, but there's
> # little need. These can also be overridden in subclasses if
> # necessary.
>
> def initial_context(cls, request, *args, **kwargs):
> """
> Returns common context for each of the HTTP method
> handlers. You will probably want to override this in
> subclasses.
> """
>
> return {}
>
> def __new__(cls, request, *args, **kwargs):
> """
> Takes a request and arguments from the URL despatcher,
> returning an HttpResponse object.
> """
>
> method_name = 'handle_%s' % request.method
> if hasattr(cls, method_name):
> # Construct the initial context to pass to the HTTP
> # handler
> context = RequestContext(request)
> context.update(cls.initial_context(request,
>*args, **kwargs))
>
> # getattr returns a staticmethod , which we pass the
> # request and initial context
> handler_method = getattr(cls, method_name)
> return handler_method(request, context,
>   *args, **kwargs)
> else:
> # Our view doesn't want to handle this method; return
> # a 405
> return cls.method_not_acceptable(request)

Our actual view code can then look a little something like this (minus
all the faff with input validation and authentication):

> class CheeseView(BaseView):
> def initial_context(cls, request, slug):
> return {
> 'cheese': get_object_or_404(Cheese, slug=slug)
> }
>
> def handle_GET(cls, request, context, slug):
> return render_to_response('cheese_detail.html', context)
>
> def handle_DELETE(cls, request, context, slug):
> context['cheese'].delete()
> # Return a 204 No Content response to acknowledge the cheese
> # has gone.
> return HttpResponse('', status=204)
>
> def handle_POST(cls, request, context, slug):
> # Allow a user to change the smelliness of the cheese
> context['cheese'].smelliness = request.POST['smelliness']
> context['cheese'].save()
> return HttpResponse('', status=204)

For those who aren't familiar with metaclasses, I'll give a brief
description of class creation in Python. First, the class statement
executes all the code in the class body, using the newly bound objects
(mostly the methods) to populate a dictionary. This dictionary is then
passed to the __new__ method on the metaclass, along with the name of
the class and its base classes. Unless otherwise specified, the
metaclass will be type, but the __metaclass__ attribute is used to
override this. The __new__ method can alter the name, base classes and
attribute dictionary as it sees fit. In our case 

Re: settings.py seems to be cached or stuck

2009-11-25 Thread Graham Dumpleton


On Nov 25, 6:43 pm, Crispin Wellington
 wrote:
> On Tue, 2009-11-24 at 21:52 -0800, Graham Dumpleton wrote:
> > Your imagination is running amuck, no such thing happens. You can
> > quite happily run multiple Django instances in embedded mode, they
> > just need to be separated into distinct Python sub interpreters, which
> > is the default behaviour of mod_wsgi. So, unless you have played with
> > WSGIApplicationGroup to override the default, there should be an
> > issue.
>
> We run multiple Django apps through mod_wsgi, have not touched
> WSGIApplicationGroup, and we see these applications occasionally shift
> environment contexts under load. We know this because we get tracebacks
> emailed to us from one application, with the environment and Django
> settings of another application. Each application has its own .wsgi file
> in its own directory running its own virtual python. We use
> WSGIScriptAlias to map a URI path to the wsgi file. The wsgi file sets
> up the virtualpython using site.addsitedir(). The wsgi file sets the
> DJANGO_SETTINGS_MODULE to point to the applications settings file. When
> we run mod_wsgi in daemon mode, the problems go away.

I cant find your name against any posts to suggest that you have ever
reported this on the mod_wsgi mailing list, or if you have you cant
have hung around to help resolve it as this is something which would
have been investigated quite thoroughly to get to the bottom of it.

The closest similar problem can remember is people with badly
configured Apache such that they had duplicate or overlapping
VirtualHost configurations and Apache was executing requests in
context of wrong VirtualHost in some cases. They fixed up their Apache
configurations and all was fine. Most obvious case is people not
setting NameVirtualHost properly and the other as mentioned is people
fiddling with WSGIApplicationGroup.

At the moment there is only a suggestion of an issue. No details on
what version of mod_wsgi being used at the time or anything else in
the way of detail. Not much to go on.

One of the things that is most annoying about developing mod_wsgi is
people asking about or saying they have a problem, usually with
insufficient details, and you asking for more information, giving
answers or suggestions about how to investigate and those people then
never actually bother to come back and tell you what you need to know,
what they found and whether or how they fixed or worked around the
problem. You thus never know if there was a problem to be fixed or
not. For Django related stuff, a lot of the time you don't even get
that as people instead go off to #django IRC channel rather than
bringing the issue to the mod_wsgi mailing list where it belongs.
Sometimes I only find out about potential issues by trolling the
#django IRC logs after the fact and even then you can only speculate
whether it was a real issue or not.

Perhaps next time you will consider reporting the problem to the
mod_wsgi mailing list and helping to fully investigate it and help
determine if there is a problem in mod_wsgi or not. At the moment
there isn't believed to be any issues which would cause this.

Graham

--

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




how to import a library in only in django project

2009-11-25 Thread Amit Sethi
Hi ,
I want to use a library in a django project but I don't want to put it in
python path. Where am I supposed to put the sys.append so that it will
available to the whole django project.
-- 
A-M-I-T S|S

--

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