Re: settings.py seems to be cached or stuck

2009-11-24 Thread Crispin Wellington
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.

Regards

Crispin




--

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 unregister model?

2009-11-24 Thread Hanne Moa
2009/11/25 Tomasz Zieliński :
> That patch is a hack that requires modifying live instance of Django,
> moreover I don't know what is influenced by it as I'm not that
> familiar
> with inner workings of model layer, so using it would be troublesome
> for me.
>
> So it seems that I have to write custom delete()s, using raw SQL..

There's a lot of tickets about the problems caused by implicit
cascaded deletes. Your use-case I think is new however (though, I've
been planning to use views myself...). You might want to collect all
of the "delete cascades" tickets and add your use-case to the most
relevant of them, mark all the rest as duplicates then tell the
developer-list.

Fixing this *is* on the roadmap for 1.2:
http://code.djangoproject.com/wiki/Version1.2Features
but: it has the lowest priority so there's room for you to step in.

Now for database views, what we really need is a way to mark that a
model is read-only/should never be updated in any way from/via django.


HM

--

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-24 Thread Hinnack
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?


-- Hinnack


2009/11/25 Karen Tracey 

> On Tue, Nov 24, 2009 at 5:57 AM, Hinnack wrote:
>
>> Hi,
>>
>> I have django 1.1 and a mysql database created in utf-8.
>> My tables are also utf8 as the collation is, too.
>>
>> Showing data in a view works pretty well with german umlaute, but doing
>> a search with filter and icontains always returns an empty queryset...
>>
>> if I convert the search back to iso-8859 I get results...
>>
>> what am I doing wrong?
>>
>>
>>
> What does "convert the search back to iso-8859" mean?
>
> 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.
>

--

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: Best way to use django for sql with raw LIKE statement

2009-11-24 Thread valhalla
Oh and as for breaking into fields its not really an option in the
cases I need unfortunately. he actual lookup would not be as log/
complex as the example but basically for the best functionality users
need to be able to do wildcard searches.



On Nov 25, 3:45 pm, Tim Valenta  wrote:
> It sounds like you've been using the right sorts of methods for that
> job, but the complexity of the query is getting to be too much :)
>
> There's a 'regex' 
> lookup...http://docs.djangoproject.com/en/dev/ref/models/querysets/#regex
>
> That's a pretty intense example text parsing search.  I think the
> usual Django philosophy might conclude that whatever you've got in
> that field could be broken up into multiple fields? :)  Unless it's a
> TextField, but then you might be best off with regex anyway.
>
> I can't quite wrap my brain around the requirement for such a lookup
> yet, because I've never yet come across the need for any raw SQL to go
> into my queries.  Apologies if this doesn't really address the type of
> solution you need.
>
> Tim
>
> On Nov 24, 8:50 pm, valhalla  wrote:
>
> > Hi,
>
> > I'm basically looking for the best way to implement something that
> > produces SQL similar to:
>
> > select col1, col2 from table1 where col1 like '%this%is%some%search
> > %string?with?wildcards'
>
> > I have worked around this with using the extra() method of the query
> > but this can get real messy real fast.
> > I have also split the string on the wild cards and chained startswith,
> > endswith and contains. but the contains elements don't maintain the
> > order that I would like (and sometime absolutely must have)
>
> > does anyone have a neat solution to this that I have missed?
>
>

--

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: Best way to use django for sql with raw LIKE statement

2009-11-24 Thread valhalla
I knew I forgot to mention somthingI am (not by choice) on a mssql
DB and regex is not really an option.
Thanks for the reply though, I had been using regex for this before
our db moved to MS

On Nov 25, 3:45 pm, Tim Valenta  wrote:
> It sounds like you've been using the right sorts of methods for that
> job, but the complexity of the query is getting to be too much :)
>
> There's a 'regex' 
> lookup...http://docs.djangoproject.com/en/dev/ref/models/querysets/#regex
>
> That's a pretty intense example text parsing search.  I think the
> usual Django philosophy might conclude that whatever you've got in
> that field could be broken up into multiple fields? :)  Unless it's a
> TextField, but then you might be best off with regex anyway.
>
> I can't quite wrap my brain around the requirement for such a lookup
> yet, because I've never yet come across the need for any raw SQL to go
> into my queries.  Apologies if this doesn't really address the type of
> solution you need.
>
> Tim
>
> On Nov 24, 8:50 pm, valhalla  wrote:
>
> > Hi,
>
> > I'm basically looking for the best way to implement something that
> > produces SQL similar to:
>
> > select col1, col2 from table1 where col1 like '%this%is%some%search
> > %string?with?wildcards'
>
> > I have worked around this with using the extra() method of the query
> > but this can get real messy real fast.
> > I have also split the string on the wild cards and chained startswith,
> > endswith and contains. but the contains elements don't maintain the
> > order that I would like (and sometime absolutely must have)
>
> > does anyone have a neat solution to this that I have missed?
>
>

--

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-24 Thread Graham Dumpleton


On Nov 25, 4:52 pm, Graham Dumpleton 
wrote:
> On Nov 25, 3:23 pm, Crispin Wellington
>
>  wrote:
> > Have a read of the mod_wsgi documentation, particularly the 
> > page:http://code.google.com/p/modwsgi/wiki/ApplicationIssues
>
> > Because Django uses environment variables to access the settings file,
> > all kinds of strife can occur when running Django on top of mod_wsgi.
> > Essentially Django and mod_wsgi don't play nicely when mod_wsgi is in
> > its default configuration. You get applications swapping environments
> > and all kinds of inexplicable bizarre errors occuring.
>
> 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.

That of course should have read:

"""So, unless you have played with
WSGIApplicationGroup to override the default, there should NOT be an
issue."""

I have it when I leave out 'not' like that. :-)

Graham

> FWIW, it is mod_python that doesn't separate them properly if you have
> multiple Django instances in one VirtualHost. This is because
> mod_python only gives by default a sub interpreter to each VirtualHost
> ServerName. So, sure you aren't confused.
>
> > As well as the environment problem, there is a particular insidious
> > issue with time zone settings using Django under mod_wsgi that affects
> > cookie expiry and thus django auth and login.
>
> That is only an issue where you have distinct applications, be they
> Django or PHP, with different requirements for setting TZ. Not an
> issue if all use the same.
>
> > The best approach is to run mod_wsgi in daemon mode, and allocate a
> > specific process and thread pool to each django application.
>
> Even though embedded mode will work and for very high performance
> sites, so long as Apache configured properly, is better, for most
> mortals daemon mode is safer.
>
> Graham
>
>
>
> > This way
> > you wont have python sub interpreters swapping applications they serve
> > and getting confused.
>
> > Hope this helps.
>
> > Regards
>
> > Crispin Wellington
>
> > On Tue, 2009-11-24 at 19:12 -0800, Tom wrote:
> > > Sorry, I should have mentioned that this has only come up after
> > > deploying the project to a production server using mod_wsgi.  It works
> > > absolutely fine under development.
>
> > > Tom
>
> > > On Nov 25, 2:24 am, Tim Valenta  wrote:
> > > > Are you using the development server?  There's definitely caching
> > > > funny-business in a production web server, but that should affect you
> > > > if you're using "manage.py runserver"
>
> > > > Does stopping and starting the development server change anything?
>
> > > > Tim
>
> > > > On Nov 24, 6:54 pm, Tom  wrote:
>
> > > > > Hi all,
>
> > > > > I am experiencing TemplateDoesNotExist errors.  Initially I thought I
> > > > > had my TEMPLATE_DIRS variable set incorrectly, but much
> > > > > experimentation yielded nothing.  I then noticed that on the browser
> > > > > TemplateDoesNotExist error pages the TEMPLATE_DIRS setting reads as an
> > > > > empty tuple ().  I then tried changing several other settings in
> > > > > settings.py including database name and engine, and adding and
> > > > > removing installed apps.  None of these changes are showing up in the
> > > > > settings listed on error pages.
>
> > > > > It seems like the settings file has been cached somewhere because
> > > > > nothing I do to my settings.py file is making any difference.  I have
> > > > > even tried deleting the file altogether and still nothing changes.  I
> > > > > have also tried recreating my project from scratch, but still no joy.
>
> > > > > This is really weird; does anybody have any ideas what is going on?
>
> > > > > Thanks in advance,
>
> > > > > Tom
>
> > > --
>
> > > You received this message because you are subscribed to the Google Groups 
> > > "Django users" group.
> > > To post to this group, send email to django-us...@googlegroups.com.
> > > To unsubscribe from this group, send email to 
> > > django-users+unsubscr...@googlegroups.com.
> > > For more options, visit this group 
> > > athttp://groups.google.com/group/django-users?hl=en.- Hide quoted text -
>
> - Show quoted text -

--

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-24 Thread Graham Dumpleton


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: settings.py seems to be cached or stuck

2009-11-24 Thread Graham Dumpleton


On Nov 25, 3:23 pm, Crispin Wellington
 wrote:
> Have a read of the mod_wsgi documentation, particularly the 
> page:http://code.google.com/p/modwsgi/wiki/ApplicationIssues
>
> Because Django uses environment variables to access the settings file,
> all kinds of strife can occur when running Django on top of mod_wsgi.
> Essentially Django and mod_wsgi don't play nicely when mod_wsgi is in
> its default configuration. You get applications swapping environments
> and all kinds of inexplicable bizarre errors occuring.

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.

FWIW, it is mod_python that doesn't separate them properly if you have
multiple Django instances in one VirtualHost. This is because
mod_python only gives by default a sub interpreter to each VirtualHost
ServerName. So, sure you aren't confused.

> As well as the environment problem, there is a particular insidious
> issue with time zone settings using Django under mod_wsgi that affects
> cookie expiry and thus django auth and login.

That is only an issue where you have distinct applications, be they
Django or PHP, with different requirements for setting TZ. Not an
issue if all use the same.

> The best approach is to run mod_wsgi in daemon mode, and allocate a
> specific process and thread pool to each django application.

Even though embedded mode will work and for very high performance
sites, so long as Apache configured properly, is better, for most
mortals daemon mode is safer.

Graham

> This way
> you wont have python sub interpreters swapping applications they serve
> and getting confused.
>
> Hope this helps.
>
> Regards
>
> Crispin Wellington
>
>
>
> On Tue, 2009-11-24 at 19:12 -0800, Tom wrote:
> > Sorry, I should have mentioned that this has only come up after
> > deploying the project to a production server using mod_wsgi.  It works
> > absolutely fine under development.
>
> > Tom
>
> > On Nov 25, 2:24 am, Tim Valenta  wrote:
> > > Are you using the development server?  There's definitely caching
> > > funny-business in a production web server, but that should affect you
> > > if you're using "manage.py runserver"
>
> > > Does stopping and starting the development server change anything?
>
> > > Tim
>
> > > On Nov 24, 6:54 pm, Tom  wrote:
>
> > > > Hi all,
>
> > > > I am experiencing TemplateDoesNotExist errors.  Initially I thought I
> > > > had my TEMPLATE_DIRS variable set incorrectly, but much
> > > > experimentation yielded nothing.  I then noticed that on the browser
> > > > TemplateDoesNotExist error pages the TEMPLATE_DIRS setting reads as an
> > > > empty tuple ().  I then tried changing several other settings in
> > > > settings.py including database name and engine, and adding and
> > > > removing installed apps.  None of these changes are showing up in the
> > > > settings listed on error pages.
>
> > > > It seems like the settings file has been cached somewhere because
> > > > nothing I do to my settings.py file is making any difference.  I have
> > > > even tried deleting the file altogether and still nothing changes.  I
> > > > have also tried recreating my project from scratch, but still no joy.
>
> > > > This is really weird; does anybody have any ideas what is going on?
>
> > > > Thanks in advance,
>
> > > > Tom
>
> > --
>
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > 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: reversing URLs

2009-11-24 Thread Tim Valenta
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 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: reversing URLs

2009-11-24 Thread Karen Tracey
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 at 
http://groups.google.com/group/django-users?hl=en.




Re: calendar.js can't find variable gettext

2009-11-24 Thread Todd Blanchard
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.

-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/django/contrib/admin/sites.py#L213
> http://code.djangoproject.com/browser/django/tags/releases/1.1.1/django/contrib/admin/sites.py#L253
> 
> 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/django/contrib/admin/templates/admin/change_list.html#L9
> 
> 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 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: settings.py seems to be cached or stuck

2009-11-24 Thread Tom
That is all really helpful; thanks very much everybody.  My production
environment is Apache 2.2.9 on Fedora, so it looks as if the solution
Karen suggests will be workable, and I think I will give that a try as
it looks close to ideal.

Thanks again all; much appreciated.

Tom

--

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




Re: settings.py seems to be cached or stuck

2009-11-24 Thread Karen Tracey
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.html

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.




Re: Best way to use django for sql with raw LIKE statement

2009-11-24 Thread Tim Valenta
It sounds like you've been using the right sorts of methods for that
job, but the complexity of the query is getting to be too much :)

There's a 'regex' lookup... 
http://docs.djangoproject.com/en/dev/ref/models/querysets/#regex

That's a pretty intense example text parsing search.  I think the
usual Django philosophy might conclude that whatever you've got in
that field could be broken up into multiple fields? :)  Unless it's a
TextField, but then you might be best off with regex anyway.

I can't quite wrap my brain around the requirement for such a lookup
yet, because I've never yet come across the need for any raw SQL to go
into my queries.  Apologies if this doesn't really address the type of
solution you need.

Tim

On Nov 24, 8:50 pm, valhalla  wrote:
> Hi,
>
> I'm basically looking for the best way to implement something that
> produces SQL similar to:
>
> select col1, col2 from table1 where col1 like '%this%is%some%search
> %string?with?wildcards'
>
> I have worked around this with using the extra() method of the query
> but this can get real messy real fast.
> I have also split the string on the wild cards and chained startswith,
> endswith and contains. but the contains elements don't maintain the
> order that I would like (and sometime absolutely must have)
>
> does anyone have a neat solution to this that I have missed?

--

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.




.mo file is empty - please help

2009-11-24 Thread Igor
Hi, I'm developing on windows and using gnu gettext...

I run "django-admin.py makemessages -a" and it creates the .po fine,
but then when I do my translations and run 'django-admin.py
compilemessages' . The result is an "empty" .mo file (367 bytes - only
headers as far as I understand).

This is a second question I guess, although tightly related:

I tried gettext 0.14.4 and it generates an error mentioned in the
manual so I installed 0.17
Even though 0.14.4 was showing an error, the .mo looked bigger (-->
better in this case). I could then see the translated values, but it
still wouldn't show up on the page (template-generated).

I also tried both from 'django.utils.translation import ugettext_lazy
as _' and 'from django.utils.translation import ugettext as _' - both
showed the english message.

The buit- in localization works fine.

Any ideas? I'm sure these are all newbie troubles.

Thanks,
Igor

--

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




Re: custom backend causes this error: authenticate() takes exactly 0 arguments (2 given)

2009-11-24 Thread Gloria

Oh, geez you are NEVER going to believe what caused this error.

This causes it:

user = authenticate(user_name)

This makes it work:

user = authenticate(username = user_name)

The error is vague because authenticate() accepts **kwargs.

How did I find it, you may ask? I set a breakpoint using pdb, right
before the authenticate() call. I then ran runserver, and stepped into
the callback. I saw that it was indeed authenticating against each
model given in the settings file.

Argh! Finally. Now I can sleep.

Gloria

--

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-24 Thread Karen Tracey
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/django/contrib/admin/sites.py#L213
http://code.djangoproject.com/browser/django/tags/releases/1.1.1/django/contrib/admin/sites.py#L253

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/django/contrib/admin/templates/admin/change_list.html#L9

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 at 
http://groups.google.com/group/django-users?hl=en.




Re: settings.py seems to be cached or stuck

2009-11-24 Thread Tim Valenta
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

Tim

On Nov 24, 8:12 pm, Tom  wrote:
> Sorry, I should have mentioned that this has only come up after
> deploying the project to a production server using mod_wsgi.  It works
> absolutely fine under development.
>
> Tom
>
> On Nov 25, 2:24 am, Tim Valenta  wrote:
>
>
>
> > Are you using the development server?  There's definitely caching
> > funny-business in a production web server, but that should affect you
> > if you're using "manage.py runserver"
>
> > Does stopping and starting the development server change anything?
>
> > Tim
>
> > On Nov 24, 6:54 pm, Tom  wrote:
>
> > > Hi all,
>
> > > I am experiencing TemplateDoesNotExist errors.  Initially I thought I
> > > had my TEMPLATE_DIRS variable set incorrectly, but much
> > > experimentation yielded nothing.  I then noticed that on the browser
> > > TemplateDoesNotExist error pages the TEMPLATE_DIRS setting reads as an
> > > empty tuple ().  I then tried changing several other settings in
> > > settings.py including database name and engine, and adding and
> > > removing installed apps.  None of these changes are showing up in the
> > > settings listed on error pages.
>
> > > It seems like the settings file has been cached somewhere because
> > > nothing I do to my settings.py file is making any difference.  I have
> > > even tried deleting the file altogether and still nothing changes.  I
> > > have also tried recreating my project from scratch, but still no joy.
>
> > > This is really weird; does anybody have any ideas what is going on?
>
> > > Thanks in advance,
>
> > > Tom

--

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




Re: Django with GXmlHttp

2009-11-24 Thread 504Django
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 + '&var2=' + 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.




Re: settings.py seems to be cached or stuck

2009-11-24 Thread Crispin Wellington
Have a read of the mod_wsgi documentation, particularly the page:
http://code.google.com/p/modwsgi/wiki/ApplicationIssues

Because Django uses environment variables to access the settings file,
all kinds of strife can occur when running Django on top of mod_wsgi.
Essentially Django and mod_wsgi don't play nicely when mod_wsgi is in
its default configuration. You get applications swapping environments
and all kinds of inexplicable bizarre errors occuring.

As well as the environment problem, there is a particular insidious
issue with time zone settings using Django under mod_wsgi that affects
cookie expiry and thus django auth and login.

The best approach is to run mod_wsgi in daemon mode, and allocate a
specific process and thread pool to each django application. This way
you wont have python sub interpreters swapping applications they serve
and getting confused.

Hope this helps.

Regards

Crispin Wellington

On Tue, 2009-11-24 at 19:12 -0800, Tom wrote:
> Sorry, I should have mentioned that this has only come up after
> deploying the project to a production server using mod_wsgi.  It works
> absolutely fine under development.
> 
> Tom
> 
> On Nov 25, 2:24 am, Tim Valenta  wrote:
> > Are you using the development server?  There's definitely caching
> > funny-business in a production web server, but that should affect you
> > if you're using "manage.py runserver"
> >
> > Does stopping and starting the development server change anything?
> >
> > Tim
> >
> > On Nov 24, 6:54 pm, Tom  wrote:
> >
> >
> >
> > > Hi all,
> >
> > > I am experiencing TemplateDoesNotExist errors.  Initially I thought I
> > > had my TEMPLATE_DIRS variable set incorrectly, but much
> > > experimentation yielded nothing.  I then noticed that on the browser
> > > TemplateDoesNotExist error pages the TEMPLATE_DIRS setting reads as an
> > > empty tuple ().  I then tried changing several other settings in
> > > settings.py including database name and engine, and adding and
> > > removing installed apps.  None of these changes are showing up in the
> > > settings listed on error pages.
> >
> > > It seems like the settings file has been cached somewhere because
> > > nothing I do to my settings.py file is making any difference.  I have
> > > even tried deleting the file altogether and still nothing changes.  I
> > > have also tried recreating my project from scratch, but still no joy.
> >
> > > This is really weird; does anybody have any ideas what is going on?
> >
> > > Thanks in advance,
> >
> > > Tom
> 
> --
> 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 
> 
> 

--

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-24 Thread Tim Valenta
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',
}),
(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
})


Now, my case doesn't seem too abnormal, but I find it difficult to
even track what happens after this.  Using my wishful "View on site"
link yields the same result as calling the method in the manage.py
shell:

>>> event.get_aboslute_url()
Traceback (most recent call last):
 snip...
NoReverseMatch: Reverse for 'this_is_a_name' with arguments '()' and
keyword arguments '{'event_id': 1L, 'company_slug': u'mycompany',
'page': 1}' not found.



Now, I've tried to simplify my task as much as possible, by naming the
view and everything.  I thought maybe some funny-business was going on
with the optional parameter, but changes don't seem to make any
difference.

Any thoughts?  I'm pretty sure there's no more info to give... the
full traceback stays in Django files, never directly touching my own,
and doesn't reveal anything more than I've posted.

Thanks,

Tim

On Nov 24, 8:52 pm, Karen Tracey  wrote:
> On Tue, Nov 24, 2009 at 4:49 PM, Tim Valenta 
> wrote:
>
>
>
>
>
> > Ever since day one, I've never had a firm grasp on what the heck URL
> > reversing can do.  I understand the concepts involved, even the admin
> > namespacing that can occur with different admin sites, and I know that
> > the admin uses it regularly, but it seems like a crazy unpredictable
> > wildcard when I try to use it manually.
>
> > For instance, I'm trying to get the permalink decorator to work on a
> > "get_absolute_url()" method on my model, and I haven't got the
> > slightest clue what the hell it's doing.  I'm getting errors about it
> > not being able to reverse it properly when I try to click on the admin-
> > generated "View on site ->" link from the change form.  It says that
> > it can't find the view.
>
> > Basically, I've tried making the method refer to the view object, a
> > view name as a string (explicitly setting the name in the url conf),
> > an absolute module-path string ("myproject.myapp.views.my_view"), and
> > nothing works.  It can never find it, even on a view with just a
> > single required keyword argument.
>
> > Is there any amazing breakdown on how to better wrap my brain around
> > how this url reversing thing works?  I typically don't think of myself
> > as an idiot, but I really cannot even begin to feel like I can use it
> > proficiently.
>
> I could point you to the doc 
> (http://docs.djangoproject.com/en/dev/ref/models/instances/#the-permal...)
> but it sounds like you have already read that.
>
> Alternatively I could try to explain the errors you are getting for the
> various things you have tried, but there aren't enough specifics here to do
> that.  Spell out the URLConf info, exactly what you have tried for the
> permalink/ger_abosolute_url code, and exactly what the error is, and someone
> can likely help.
>
> I'm assuming you are getting NoReverseMatch and that's what you mean when
> you say "It says that it can't find the view"?  Those can be frustrating to
> debug, but they tend be right and mean exactly what they say: given the
> URLConf in place, there is no URL pattern in there that would result in the
> specified view being called with the noted parameters.  The trick then is to
> figure out why, since clearly you're expecting the URLConf to contain a
> pattern that would result in that view being called with those
> parametersbut without specifics on what you're trying it's hard to say
> what, exactly, is going wrong with what you are trying.
>
> 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.

Re: reversing URLs

2009-11-24 Thread Karen Tracey
On Tue, Nov 24, 2009 at 4:49 PM, Tim Valenta wrote:

> Ever since day one, I've never had a firm grasp on what the heck URL
> reversing can do.  I understand the concepts involved, even the admin
> namespacing that can occur with different admin sites, and I know that
> the admin uses it regularly, but it seems like a crazy unpredictable
> wildcard when I try to use it manually.
>
> For instance, I'm trying to get the permalink decorator to work on a
> "get_absolute_url()" method on my model, and I haven't got the
> slightest clue what the hell it's doing.  I'm getting errors about it
> not being able to reverse it properly when I try to click on the admin-
> generated "View on site ->" link from the change form.  It says that
> it can't find the view.
>
> Basically, I've tried making the method refer to the view object, a
> view name as a string (explicitly setting the name in the url conf),
> an absolute module-path string ("myproject.myapp.views.my_view"), and
> nothing works.  It can never find it, even on a view with just a
> single required keyword argument.
>
> Is there any amazing breakdown on how to better wrap my brain around
> how this url reversing thing works?  I typically don't think of myself
> as an idiot, but I really cannot even begin to feel like I can use it
> proficiently.
>
>
I could point you to the doc (
http://docs.djangoproject.com/en/dev/ref/models/instances/#the-permalink-decorator)
but it sounds like you have already read that.

Alternatively I could try to explain the errors you are getting for the
various things you have tried, but there aren't enough specifics here to do
that.  Spell out the URLConf info, exactly what you have tried for the
permalink/ger_abosolute_url code, and exactly what the error is, and someone
can likely help.

I'm assuming you are getting NoReverseMatch and that's what you mean when
you say "It says that it can't find the view"?  Those can be frustrating to
debug, but they tend be right and mean exactly what they say: given the
URLConf in place, there is no URL pattern in there that would result in the
specified view being called with the noted parameters.  The trick then is to
figure out why, since clearly you're expecting the URLConf to contain a
pattern that would result in that view being called with those
parametersbut without specifics on what you're trying it's hard to say
what, exactly, is going wrong with what you are trying.

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.




Best way to use django for sql with raw LIKE statement

2009-11-24 Thread valhalla
Hi,

I'm basically looking for the best way to implement something that
produces SQL similar to:

select col1, col2 from table1 where col1 like '%this%is%some%search
%string?with?wildcards'

I have worked around this with using the extra() method of the query
but this can get real messy real fast.
I have also split the string on the wild cards and chained startswith,
endswith and contains. but the contains elements don't maintain the
order that I would like (and sometime absolutely must have)

does anyone have a neat solution to this that I have missed?

--

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-24 Thread Tom
Sorry, I should have mentioned that this has only come up after
deploying the project to a production server using mod_wsgi.  It works
absolutely fine under development.

Tom

On Nov 25, 2:24 am, Tim Valenta  wrote:
> Are you using the development server?  There's definitely caching
> funny-business in a production web server, but that should affect you
> if you're using "manage.py runserver"
>
> Does stopping and starting the development server change anything?
>
> Tim
>
> On Nov 24, 6:54 pm, Tom  wrote:
>
>
>
> > Hi all,
>
> > I am experiencing TemplateDoesNotExist errors.  Initially I thought I
> > had my TEMPLATE_DIRS variable set incorrectly, but much
> > experimentation yielded nothing.  I then noticed that on the browser
> > TemplateDoesNotExist error pages the TEMPLATE_DIRS setting reads as an
> > empty tuple ().  I then tried changing several other settings in
> > settings.py including database name and engine, and adding and
> > removing installed apps.  None of these changes are showing up in the
> > settings listed on error pages.
>
> > It seems like the settings file has been cached somewhere because
> > nothing I do to my settings.py file is making any difference.  I have
> > even tried deleting the file altogether and still nothing changes.  I
> > have also tried recreating my project from scratch, but still no joy.
>
> > This is really weird; does anybody have any ideas what is going on?
>
> > Thanks in advance,
>
> > Tom

--

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




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

2009-11-24 Thread Tim Valenta
> 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.




Re: calendar.js can't find variable gettext

2009-11-24 Thread Tim Valenta
I'm a little unclear on part of that... does this not work only on
certain pages?  If it doesn't work at all anywhere, I'm not sure where
you got the HTML for a working page.

Are you sure that all of those URLs resolve to the right JS files?  If
you go to the page which messes up, and view the source, I'd go
through the links one at a time and try to find out which one of them
may not work.  It sounds like one of those is messing up.

Can you verify whether or not all of those links *for sure* work,
right there in the browser?

Tim

On Nov 24, 6: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.
>
>     
>     
>     
>
>     
>      media="all" rel="stylesheet" />
>     
>      src="/media/js/admin/RelatedObjectLookups.js">
>      src="/media/js/getElementsBySelector.js">
>     
>     
>      src="/media/js/admin/DateTimeShortcuts.js">
>      src="http://openlayers.org/api/2.8/OpenLayers.js";>
>      src="/static/olwidget/js/olwidget.js">
>      src="http://openstreetmap.org/openlayers/OpenStreetMap.js";>

--

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-24 Thread Tim Valenta
Are you using the development server?  There's definitely caching
funny-business in a production web server, but that should affect you
if you're using "manage.py runserver"

Does stopping and starting the development server change anything?

Tim

On Nov 24, 6:54 pm, Tom  wrote:
> Hi all,
>
> I am experiencing TemplateDoesNotExist errors.  Initially I thought I
> had my TEMPLATE_DIRS variable set incorrectly, but much
> experimentation yielded nothing.  I then noticed that on the browser
> TemplateDoesNotExist error pages the TEMPLATE_DIRS setting reads as an
> empty tuple ().  I then tried changing several other settings in
> settings.py including database name and engine, and adding and
> removing installed apps.  None of these changes are showing up in the
> settings listed on error pages.
>
> It seems like the settings file has been cached somewhere because
> nothing I do to my settings.py file is making any difference.  I have
> even tried deleting the file altogether and still nothing changes.  I
> have also tried recreating my project from scratch, but still no joy.
>
> This is really weird; does anybody have any ideas what is going on?
>
> Thanks in advance,
>
> Tom

--

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




Re: Accessing model instance on pre_save signal

2009-11-24 Thread Tim Valenta
I think the answer is just in the documentation on the method:

http://docs.djangoproject.com/en/dev/ref/signals/#django.db.models.signals.pre_save

No worries though.  Signals are such a strangely uncovered topic in
the main tutorials, and aren't easy to find documentation for unless
you know what you're after.

It'll be in kwargs['instance']

Tim

On Nov 24, 6: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: creating a drop down filter in Admin site

2009-11-24 Thread Tim Valenta
Not to my knowledge.  Condensing them into drop-downs could be an
option, though.  That might make an interesting patch.  I'm not
familiar with that part of the code, but it would honestly be more of
a template tweak than much code.

I'm busy with several projects for the time being, but it would be
interesting to look into.  I know that there's a branch called "admin-
ui" which will be replacing the current admin in March, with version
1.2.  I'm only aware of just a couple of changes, and I'm not sure
that this is one of them, but there could be something in there to
help facilitate that.

Tim

On Nov 24, 4:09 pm, Jase  wrote:
> Hoping someone could help me out. I am updating an admin site and
> added a couple "list_filter"s. They are rather long so I wanted to
> turn them into a drop down filter. Can this be done? Any suggestions?
> Thanks,
> Jase

--

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.




calendar.js can't find variable gettext

2009-11-24 Thread Todd Blanchard
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.














http://openlayers.org/api/2.8/OpenLayers.js";>

http://openstreetmap.org/openlayers/OpenStreetMap.js";>

--

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.




settings.py seems to be cached or stuck

2009-11-24 Thread Tom
Hi all,

I am experiencing TemplateDoesNotExist errors.  Initially I thought I
had my TEMPLATE_DIRS variable set incorrectly, but much
experimentation yielded nothing.  I then noticed that on the browser
TemplateDoesNotExist error pages the TEMPLATE_DIRS setting reads as an
empty tuple ().  I then tried changing several other settings in
settings.py including database name and engine, and adding and
removing installed apps.  None of these changes are showing up in the
settings listed on error pages.

It seems like the settings file has been cached somewhere because
nothing I do to my settings.py file is making any difference.  I have
even tried deleting the file altogether and still nothing changes.  I
have also tried recreating my project from scratch, but still no joy.

This is really weird; does anybody have any ideas what is going on?

Thanks in advance,

Tom

--

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




Accessing model instance on pre_save signal

2009-11-24 Thread neridaj
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: Configure multi-field multi-select form in Django Admin

2009-11-24 Thread Karen Tracey
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.contrib.admin.ModelAdmin.filter_horizontal

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.




Re: german umlaute on search querys

2009-11-24 Thread Karen Tracey
On Tue, Nov 24, 2009 at 5:57 AM, Hinnack wrote:

> Hi,
>
> I have django 1.1 and a mysql database created in utf-8.
> My tables are also utf8 as the collation is, too.
>
> Showing data in a view works pretty well with german umlaute, but doing
> a search with filter and icontains always returns an empty queryset...
>
> if I convert the search back to iso-8859 I get results...
>
> what am I doing wrong?
>
>
>
What does "convert the search back to iso-8859" mean?

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.




creating a drop down filter in Admin site

2009-11-24 Thread Jase
Hoping someone could help me out. I am updating an admin site and
added a couple "list_filter"s. They are rather long so I wanted to
turn them into a drop down filter. Can this be done? Any suggestions?
Thanks,
Jase

--

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: Designing base template - how to include media properly?

2009-11-24 Thread Tim Valenta
Oops damn 'send' button on the iPod.

The media attribute is a python property which aggregates all widget
media. So everything is simplified to just using myform.media.

Widgets are specified on form fields, if you want to change it from
the default widget.

Sent from my iPod; pardon any typos and poor grammar!

On Nov 24, 2009, at 5:02 PM, Todd Blanchard  wrote:

> Thanks, I feel like I'm making progress.
>
> Widgets define media too.  I'm really fuzzy about how widgets get
> loaded and how their media declarations get collected into the media
> object list. (I'm using contrib.gis which has nifty map widgets and
> it "just works" in the admin but now I'm building my own UI).
>
> In fact, I'm pretty fuzzy in general about how code like widgets
> gets "found" and loaded.
>
> -Todd Blanchard
>
>
> On Nov 24, 2009, at 3:52 PM, Tim Valenta wrote:
>
>> Sorry-- I got out of sync with the replies.
>>
>>> Or am I missing something.  Seems like I am getting very much NON-
>>> DRY here.
>>
>> How many pages do you have dozens of forms on?  If ever, I find that
>> I've got a single form on the page.  If you're writing an app complex
>> enough to need such amazingly complicated nested forms should you
>> use the admin, and let it do all that for you?
>>
>> We're not really working with specifics here, so I'm unsure of what
>> you're trying to accomplish.
>>
>> How would you propose we get around this problem?  You've got a
>> python
>> list of form objects.  How on earth is Django supposed to know what
>> variable you've got your forms in?  By forcing you to put all your
>> forms in a single variable, it would make Django dictate too strongly
>> "the one and only variable which can hold forms".  That exactly what
>> it's trying not to do.
>>
>> Just set up a template, perhaps "base.html".  Make it something like
>> this:
>>
>> 
>> 
>>   blah
>>   {% block my_media %}
>>   {{ media }}
>>   {% endblock %}
>> 
>> 
>>   {% content %}{% endcontent %}
>> 
>> 
>>
>>
>> Then, in your views, you'll render the actual template you want to
>> use
>> (as in, don't render "base.html", render the one that you'd normally
>> render), but make sure it extends base:
>> {# mytemplate.html #}
>> {% extends "base.html" %}
>>
>> {% block content %}
>>   my content goes here...
>>   
>>   {% for form in forms %}
>>   {{ form.as_p }}
>>   {% endfor %}
>>   
>> {% endblock %}
>>
>>
>> The idea is that the 'base.html' template will *always* try to grab
>> the context variable "media" and render it.  That means that all you
>> ever have to do is make sure that the context variable "media"
>> contains the cumulative media of what you want to include.  Note,
>> though, that when you want to use this "extends" approach, you become
>> required to work in those blocks.  that's why I put a "content" block
>> in the base template, and override it in the extended one.  Stuff
>> outside of blocks in mytemplate.html won't get displayed.  This is a
>> very common approach, though, so don't feel like you're getting
>> cheated.
>>
>> Then, if you ever want to for whatever reason add more media beyond
>> the form media, you can either slap it into the 'media' context var
>> in
>> your view, or you can do that block override I kept using the first
>> examples:
>>
>> {# mytemplate.html #}
>> {% block my_media %}
>>   {{ block.super }}
>>   
>> {% endblock %}
>>
>> {% block content %}
>>   {# continue as usual #}
>> {% endblock %}
>>
>>
>>
>> I hope I'm not spouting nonsense that you are already familiar with.
>> Feel free to ask anything more, if you've got specifics that you're
>> trying to nail down, design-wise.
>>
>> Tim
>>
>> On Nov 24, 4:36 pm, Todd Blanchard  wrote:
>>> No no no, I really really appreciate the help.
>>>
>>> But I'm definitely beginning to feel like my app is 80% boilerplate.
>>>
>>> On Nov 24, 2009, at 3:35 PM, Tim Valenta wrote:
>>>
>>>
>>>
 PS -- I hope I don't sound like I'm insulting your
 intelligence--- I'm
 not.  I've often felt like there aren't enough policies in Django,
 myself.  But pick your battles.  This is an easy one.  I prefer
 Django
 over Rails, when it comes down to it.  Feel fortunate that Django
 has
 practically the best documentation on the planet.  I hate more open
 source docs, because it was written by a guy who don't know how
 to use
 proper english!
>>>
 I'm just trying to drive home the point that this isn't the worst
 thing that you could be stuck on.
>>>
 Sincerely hoping it helps,
 Tim
>>>
 On Nov 24, 4:28 pm, Tim Valenta  wrote:
> Sorry it's not working out for you, but I'd disagree about the
> comparison to X-Windows :)  I'd be defending Django, and not X-
> windows, when I say that.
>>>
> I'm serious.  Just add them together.  I'm not sure you're
> appreciating the slick objects that have been crafted for this
> very
> purpose.
>>>
> Your view:
>cumulative_media = form.media for form in 

Re: Designing base template - how to include media properly?

2009-11-24 Thread Tim Valenta
The 'media' attribute on forms are actually python proterties

Sent from my iPod; pardon any typos and poor grammar!

On Nov 24, 2009, at 5:02 PM, Todd Blanchard  wrote:

> Thanks, I feel like I'm making progress.
>
> Widgets define media too.  I'm really fuzzy about how widgets get
> loaded and how their media declarations get collected into the media
> object list. (I'm using contrib.gis which has nifty map widgets and
> it "just works" in the admin but now I'm building my own UI).
>
> In fact, I'm pretty fuzzy in general about how code like widgets
> gets "found" and loaded.
>
> -Todd Blanchard
>
>
> On Nov 24, 2009, at 3:52 PM, Tim Valenta wrote:
>
>> Sorry-- I got out of sync with the replies.
>>
>>> Or am I missing something.  Seems like I am getting very much NON-
>>> DRY here.
>>
>> How many pages do you have dozens of forms on?  If ever, I find that
>> I've got a single form on the page.  If you're writing an app complex
>> enough to need such amazingly complicated nested forms should you
>> use the admin, and let it do all that for you?
>>
>> We're not really working with specifics here, so I'm unsure of what
>> you're trying to accomplish.
>>
>> How would you propose we get around this problem?  You've got a
>> python
>> list of form objects.  How on earth is Django supposed to know what
>> variable you've got your forms in?  By forcing you to put all your
>> forms in a single variable, it would make Django dictate too strongly
>> "the one and only variable which can hold forms".  That exactly what
>> it's trying not to do.
>>
>> Just set up a template, perhaps "base.html".  Make it something like
>> this:
>>
>> 
>> 
>>   blah
>>   {% block my_media %}
>>   {{ media }}
>>   {% endblock %}
>> 
>> 
>>   {% content %}{% endcontent %}
>> 
>> 
>>
>>
>> Then, in your views, you'll render the actual template you want to
>> use
>> (as in, don't render "base.html", render the one that you'd normally
>> render), but make sure it extends base:
>> {# mytemplate.html #}
>> {% extends "base.html" %}
>>
>> {% block content %}
>>   my content goes here...
>>   
>>   {% for form in forms %}
>>   {{ form.as_p }}
>>   {% endfor %}
>>   
>> {% endblock %}
>>
>>
>> The idea is that the 'base.html' template will *always* try to grab
>> the context variable "media" and render it.  That means that all you
>> ever have to do is make sure that the context variable "media"
>> contains the cumulative media of what you want to include.  Note,
>> though, that when you want to use this "extends" approach, you become
>> required to work in those blocks.  that's why I put a "content" block
>> in the base template, and override it in the extended one.  Stuff
>> outside of blocks in mytemplate.html won't get displayed.  This is a
>> very common approach, though, so don't feel like you're getting
>> cheated.
>>
>> Then, if you ever want to for whatever reason add more media beyond
>> the form media, you can either slap it into the 'media' context var
>> in
>> your view, or you can do that block override I kept using the first
>> examples:
>>
>> {# mytemplate.html #}
>> {% block my_media %}
>>   {{ block.super }}
>>   
>> {% endblock %}
>>
>> {% block content %}
>>   {# continue as usual #}
>> {% endblock %}
>>
>>
>>
>> I hope I'm not spouting nonsense that you are already familiar with.
>> Feel free to ask anything more, if you've got specifics that you're
>> trying to nail down, design-wise.
>>
>> Tim
>>
>> On Nov 24, 4:36 pm, Todd Blanchard  wrote:
>>> No no no, I really really appreciate the help.
>>>
>>> But I'm definitely beginning to feel like my app is 80% boilerplate.
>>>
>>> On Nov 24, 2009, at 3:35 PM, Tim Valenta wrote:
>>>
>>>
>>>
 PS -- I hope I don't sound like I'm insulting your
 intelligence--- I'm
 not.  I've often felt like there aren't enough policies in Django,
 myself.  But pick your battles.  This is an easy one.  I prefer
 Django
 over Rails, when it comes down to it.  Feel fortunate that Django
 has
 practically the best documentation on the planet.  I hate more open
 source docs, because it was written by a guy who don't know how
 to use
 proper english!
>>>
 I'm just trying to drive home the point that this isn't the worst
 thing that you could be stuck on.
>>>
 Sincerely hoping it helps,
 Tim
>>>
 On Nov 24, 4:28 pm, Tim Valenta  wrote:
> Sorry it's not working out for you, but I'd disagree about the
> comparison to X-Windows :)  I'd be defending Django, and not X-
> windows, when I say that.
>>>
> I'm serious.  Just add them together.  I'm not sure you're
> appreciating the slick objects that have been crafted for this
> very
> purpose.
>>>
> Your view:
>cumulative_media = form.media for form in forms
>return render_to_response('mytemplate.html', {'media':
> cumulative_media})
>>>
> Your template:
>{% block my_media_block %}
>{{ block.super }}
> 

Re: Designing base template - how to include media properly?

2009-11-24 Thread Todd Blanchard
Thanks, I feel like I'm making progress.  

Widgets define media too.  I'm really fuzzy about how widgets get loaded and 
how their media declarations get collected into the media object list. (I'm 
using contrib.gis which has nifty map widgets and it "just works" in the admin 
but now I'm building my own UI).

In fact, I'm pretty fuzzy in general about how code like widgets gets "found" 
and loaded.

-Todd Blanchard


On Nov 24, 2009, at 3:52 PM, Tim Valenta wrote:

> Sorry-- I got out of sync with the replies.
> 
>> Or am I missing something.  Seems like I am getting very much NON-DRY here.
> 
> How many pages do you have dozens of forms on?  If ever, I find that
> I've got a single form on the page.  If you're writing an app complex
> enough to need such amazingly complicated nested forms should you
> use the admin, and let it do all that for you?
> 
> We're not really working with specifics here, so I'm unsure of what
> you're trying to accomplish.
> 
> How would you propose we get around this problem?  You've got a python
> list of form objects.  How on earth is Django supposed to know what
> variable you've got your forms in?  By forcing you to put all your
> forms in a single variable, it would make Django dictate too strongly
> "the one and only variable which can hold forms".  That exactly what
> it's trying not to do.
> 
> Just set up a template, perhaps "base.html".  Make it something like
> this:
> 
> 
> 
>blah
>{% block my_media %}
>{{ media }}
>{% endblock %}
> 
> 
>{% content %}{% endcontent %}
> 
> 
> 
> 
> Then, in your views, you'll render the actual template you want to use
> (as in, don't render "base.html", render the one that you'd normally
> render), but make sure it extends base:
> {# mytemplate.html #}
> {% extends "base.html" %}
> 
> {% block content %}
>my content goes here...
>
>{% for form in forms %}
>{{ form.as_p }}
>{% endfor %}
>
> {% endblock %}
> 
> 
> The idea is that the 'base.html' template will *always* try to grab
> the context variable "media" and render it.  That means that all you
> ever have to do is make sure that the context variable "media"
> contains the cumulative media of what you want to include.  Note,
> though, that when you want to use this "extends" approach, you become
> required to work in those blocks.  that's why I put a "content" block
> in the base template, and override it in the extended one.  Stuff
> outside of blocks in mytemplate.html won't get displayed.  This is a
> very common approach, though, so don't feel like you're getting
> cheated.
> 
> Then, if you ever want to for whatever reason add more media beyond
> the form media, you can either slap it into the 'media' context var in
> your view, or you can do that block override I kept using the first
> examples:
> 
> {# mytemplate.html #}
> {% block my_media %}
>{{ block.super }}
>
> {% endblock %}
> 
> {% block content %}
>{# continue as usual #}
> {% endblock %}
> 
> 
> 
> I hope I'm not spouting nonsense that you are already familiar with.
> Feel free to ask anything more, if you've got specifics that you're
> trying to nail down, design-wise.
> 
> Tim
> 
> On Nov 24, 4:36 pm, Todd Blanchard  wrote:
>> No no no, I really really appreciate the help.
>> 
>> But I'm definitely beginning to feel like my app is 80% boilerplate.
>> 
>> On Nov 24, 2009, at 3:35 PM, Tim Valenta wrote:
>> 
>> 
>> 
>>> PS -- I hope I don't sound like I'm insulting your intelligence--- I'm
>>> not.  I've often felt like there aren't enough policies in Django,
>>> myself.  But pick your battles.  This is an easy one.  I prefer Django
>>> over Rails, when it comes down to it.  Feel fortunate that Django has
>>> practically the best documentation on the planet.  I hate more open
>>> source docs, because it was written by a guy who don't know how to use
>>> proper english!
>> 
>>> I'm just trying to drive home the point that this isn't the worst
>>> thing that you could be stuck on.
>> 
>>> Sincerely hoping it helps,
>>> Tim
>> 
>>> On Nov 24, 4:28 pm, Tim Valenta  wrote:
 Sorry it's not working out for you, but I'd disagree about the
 comparison to X-Windows :)  I'd be defending Django, and not X-
 windows, when I say that.
>> 
 I'm serious.  Just add them together.  I'm not sure you're
 appreciating the slick objects that have been crafted for this very
 purpose.
>> 
 Your view:
 cumulative_media = form.media for form in forms
 return render_to_response('mytemplate.html', {'media':
 cumulative_media})
>> 
 Your template:
 {% block my_media_block %}
 {{ block.super }}
 {{ media }}
 {% endblock %}
>> 
 I fail to see what is so hard about this.
>> 
 Tim
>> 
 On Nov 24, 4:13 pm, Todd Blanchard  wrote:
>> 
> You know what, this is absolutely too much BS.  Why would one bother to 
> use the media declaration stuff at all if there is no mechanis

Re: Designing base template - how to include media properly?

2009-11-24 Thread Tim Valenta
Sorry-- I got out of sync with the replies.

> Or am I missing something.  Seems like I am getting very much NON-DRY here.

How many pages do you have dozens of forms on?  If ever, I find that
I've got a single form on the page.  If you're writing an app complex
enough to need such amazingly complicated nested forms should you
use the admin, and let it do all that for you?

We're not really working with specifics here, so I'm unsure of what
you're trying to accomplish.

How would you propose we get around this problem?  You've got a python
list of form objects.  How on earth is Django supposed to know what
variable you've got your forms in?  By forcing you to put all your
forms in a single variable, it would make Django dictate too strongly
"the one and only variable which can hold forms".  That exactly what
it's trying not to do.

Just set up a template, perhaps "base.html".  Make it something like
this:



blah
{% block my_media %}
{{ media }}
{% endblock %}


{% content %}{% endcontent %}




Then, in your views, you'll render the actual template you want to use
(as in, don't render "base.html", render the one that you'd normally
render), but make sure it extends base:
{# mytemplate.html #}
{% extends "base.html" %}

{% block content %}
my content goes here...

{% for form in forms %}
{{ form.as_p }}
{% endfor %}

{% endblock %}


The idea is that the 'base.html' template will *always* try to grab
the context variable "media" and render it.  That means that all you
ever have to do is make sure that the context variable "media"
contains the cumulative media of what you want to include.  Note,
though, that when you want to use this "extends" approach, you become
required to work in those blocks.  that's why I put a "content" block
in the base template, and override it in the extended one.  Stuff
outside of blocks in mytemplate.html won't get displayed.  This is a
very common approach, though, so don't feel like you're getting
cheated.

Then, if you ever want to for whatever reason add more media beyond
the form media, you can either slap it into the 'media' context var in
your view, or you can do that block override I kept using the first
examples:

{# mytemplate.html #}
{% block my_media %}
{{ block.super }}

{% endblock %}

{% block content %}
{# continue as usual #}
{% endblock %}



I hope I'm not spouting nonsense that you are already familiar with.
Feel free to ask anything more, if you've got specifics that you're
trying to nail down, design-wise.

Tim

On Nov 24, 4:36 pm, Todd Blanchard  wrote:
> No no no, I really really appreciate the help.
>
> But I'm definitely beginning to feel like my app is 80% boilerplate.
>
> On Nov 24, 2009, at 3:35 PM, Tim Valenta wrote:
>
>
>
> > PS -- I hope I don't sound like I'm insulting your intelligence--- I'm
> > not.  I've often felt like there aren't enough policies in Django,
> > myself.  But pick your battles.  This is an easy one.  I prefer Django
> > over Rails, when it comes down to it.  Feel fortunate that Django has
> > practically the best documentation on the planet.  I hate more open
> > source docs, because it was written by a guy who don't know how to use
> > proper english!
>
> > I'm just trying to drive home the point that this isn't the worst
> > thing that you could be stuck on.
>
> > Sincerely hoping it helps,
> > Tim
>
> > On Nov 24, 4:28 pm, Tim Valenta  wrote:
> >> Sorry it's not working out for you, but I'd disagree about the
> >> comparison to X-Windows :)  I'd be defending Django, and not X-
> >> windows, when I say that.
>
> >> I'm serious.  Just add them together.  I'm not sure you're
> >> appreciating the slick objects that have been crafted for this very
> >> purpose.
>
> >> Your view:
> >>     cumulative_media = form.media for form in forms
> >>     return render_to_response('mytemplate.html', {'media':
> >> cumulative_media})
>
> >> Your template:
> >>     {% block my_media_block %}
> >>         {{ block.super }}
> >>         {{ media }}
> >>     {% endblock %}
>
> >> I fail to see what is so hard about this.
>
> >> Tim
>
> >> On Nov 24, 4:13 pm, Todd Blanchard  wrote:
>
> >>> You know what, this is absolutely too much BS.  Why would one bother to 
> >>> use the media declaration stuff at all if there is no mechanism to 
> >>> properly consume it (a built in template tag for instance).
>
> >>> I think I will just hardcode them in the head in the base template.  They 
> >>> seldom change and browser caching being what it is having them never 
> >>> change is just fine.
>
> >>> After three weeks of seriously trying to get traction with django, my 
> >>> conclusion is it has all of the elegance of X-windows.  It can do 
> >>> anything but out of the box it does nothing except present a zillion 
> >>> confusing parts to the programmer and it has too many mechanisms but no 
> >>> policies.
>
> >>> I'm beginning to very much pine for rails.  At least it does something 
>

Re: Designing base template - how to include media properly?

2009-11-24 Thread Todd Blanchard
No no no, I really really appreciate the help.

But I'm definitely beginning to feel like my app is 80% boilerplate.

On Nov 24, 2009, at 3:35 PM, Tim Valenta wrote:

> PS -- I hope I don't sound like I'm insulting your intelligence--- I'm
> not.  I've often felt like there aren't enough policies in Django,
> myself.  But pick your battles.  This is an easy one.  I prefer Django
> over Rails, when it comes down to it.  Feel fortunate that Django has
> practically the best documentation on the planet.  I hate more open
> source docs, because it was written by a guy who don't know how to use
> proper english!
> 
> I'm just trying to drive home the point that this isn't the worst
> thing that you could be stuck on.
> 
> Sincerely hoping it helps,
> Tim
> 
> On Nov 24, 4:28 pm, Tim Valenta  wrote:
>> Sorry it's not working out for you, but I'd disagree about the
>> comparison to X-Windows :)  I'd be defending Django, and not X-
>> windows, when I say that.
>> 
>> I'm serious.  Just add them together.  I'm not sure you're
>> appreciating the slick objects that have been crafted for this very
>> purpose.
>> 
>> Your view:
>> cumulative_media = form.media for form in forms
>> return render_to_response('mytemplate.html', {'media':
>> cumulative_media})
>> 
>> Your template:
>> {% block my_media_block %}
>> {{ block.super }}
>> {{ media }}
>> {% endblock %}
>> 
>> I fail to see what is so hard about this.
>> 
>> Tim
>> 
>> On Nov 24, 4:13 pm, Todd Blanchard  wrote:
>> 
>> 
>> 
>>> You know what, this is absolutely too much BS.  Why would one bother to use 
>>> the media declaration stuff at all if there is no mechanism to properly 
>>> consume it (a built in template tag for instance).
>> 
>>> I think I will just hardcode them in the head in the base template.  They 
>>> seldom change and browser caching being what it is having them never change 
>>> is just fine.
>> 
>>> After three weeks of seriously trying to get traction with django, my 
>>> conclusion is it has all of the elegance of X-windows.  It can do anything 
>>> but out of the box it does nothing except present a zillion confusing parts 
>>> to the programmer and it has too many mechanisms but no policies.
>> 
>>> I'm beginning to very much pine for rails.  At least it does something out 
>>> of the box.
>> 
>>> Very frustrated today - still haven't got a single record/entry form 
>>> working.  Too many little files and indirection to keep it all straight in 
>>> my head.
>> 
>>> -Todd Blanchard
>> 
>>> On Nov 24, 2009, at 2:05 PM, Tim Valenta wrote:
>> 
 The idea is along the lines of what you initially guessed.
>> 
 The admin accomplishes the non-duplicate effect in django/django/
 contrib/admin/options.py, starting at line 770.  It loops over the
 forms and combines the existing media with the media on each form
 object.  It ends up using a series of objects to do it, including a
 Media class, but it's not doing anything too special.  When an item
 gets added, it checks to make sure that the path doesn't already exist
 in the list.
>> 
 So, short story: loop over your forms and add the media attributes
 together.  The underlying Media class ought to be dropping duplicates.
>> 
 Then just save a context variable with the result, and do the
 following in your template:
>> 
 {% block extrahead %} {# or whatever you call your header block #}
{{ block.super }}
{{ cumulative_media }}
 {% endblock %}
>> 
 Tim
>> 
 On Nov 24, 12:30 pm, Todd Blanchard  wrote:
> What about de-duping?
> If two forms want the same js file, will it get included twice?
> It seems like this is the kind of thing that the framework should handle 
> and the current "solution" is kind of half baked.
>> 
> -Todd
>> 
> On Nov 23, 2009, at 2:40 PM, Mark (Nosrednakram) wrote:
>> 
>> Hello,
>> 
>> I have something like the following in my generic genericform.html.  I
>> think this is what you're looking for if not hope you find a better
>> answer. The extramedia block is back in my base.html  template and my
>> form template extends it. I'm not sure if it's in the admin base.html
>> but you can take a look at if for there media blocks I believe are
>> something like extrastyle etc...
>> 
>> {% block extramedia %}
>> {% if forms %}
>>{% for form in forms %}
>>   {{ form.media }}
>>{% endfor %}
>> {% else %}
>>   {{ form.media }}
>> {% endif %}
>> 
>> Mark
>> 
>> On Nov 23, 1:31 pm, Todd Blanchard  wrote:
>>> I've read this:
>> 
>>> http://docs.djangoproject.com/en/dev/topics/forms/media/
>> 
>>> Nifty.  
>> 
>>> Now, how exactly do I make sure that the media urls get spewed properly 
>>> into the head section of the page?  This is apparently omitted 
>>> everywhere I've looked.  The admin template seems to pull it off 
>>> properly but I cannot figure 

Re: Designing base template - how to include media properly?

2009-11-24 Thread Tim Valenta
PS -- I hope I don't sound like I'm insulting your intelligence--- I'm
not.  I've often felt like there aren't enough policies in Django,
myself.  But pick your battles.  This is an easy one.  I prefer Django
over Rails, when it comes down to it.  Feel fortunate that Django has
practically the best documentation on the planet.  I hate more open
source docs, because it was written by a guy who don't know how to use
proper english!

I'm just trying to drive home the point that this isn't the worst
thing that you could be stuck on.

Sincerely hoping it helps,
Tim

On Nov 24, 4:28 pm, Tim Valenta  wrote:
> Sorry it's not working out for you, but I'd disagree about the
> comparison to X-Windows :)  I'd be defending Django, and not X-
> windows, when I say that.
>
> I'm serious.  Just add them together.  I'm not sure you're
> appreciating the slick objects that have been crafted for this very
> purpose.
>
> Your view:
>     cumulative_media = form.media for form in forms
>     return render_to_response('mytemplate.html', {'media':
> cumulative_media})
>
> Your template:
>     {% block my_media_block %}
>         {{ block.super }}
>         {{ media }}
>     {% endblock %}
>
> I fail to see what is so hard about this.
>
> Tim
>
> On Nov 24, 4:13 pm, Todd Blanchard  wrote:
>
>
>
> > You know what, this is absolutely too much BS.  Why would one bother to use 
> > the media declaration stuff at all if there is no mechanism to properly 
> > consume it (a built in template tag for instance).
>
> > I think I will just hardcode them in the head in the base template.  They 
> > seldom change and browser caching being what it is having them never change 
> > is just fine.
>
> > After three weeks of seriously trying to get traction with django, my 
> > conclusion is it has all of the elegance of X-windows.  It can do anything 
> > but out of the box it does nothing except present a zillion confusing parts 
> > to the programmer and it has too many mechanisms but no policies.
>
> > I'm beginning to very much pine for rails.  At least it does something out 
> > of the box.
>
> > Very frustrated today - still haven't got a single record/entry form 
> > working.  Too many little files and indirection to keep it all straight in 
> > my head.
>
> > -Todd Blanchard
>
> > On Nov 24, 2009, at 2:05 PM, Tim Valenta wrote:
>
> > > The idea is along the lines of what you initially guessed.
>
> > > The admin accomplishes the non-duplicate effect in django/django/
> > > contrib/admin/options.py, starting at line 770.  It loops over the
> > > forms and combines the existing media with the media on each form
> > > object.  It ends up using a series of objects to do it, including a
> > > Media class, but it's not doing anything too special.  When an item
> > > gets added, it checks to make sure that the path doesn't already exist
> > > in the list.
>
> > > So, short story: loop over your forms and add the media attributes
> > > together.  The underlying Media class ought to be dropping duplicates.
>
> > > Then just save a context variable with the result, and do the
> > > following in your template:
>
> > > {% block extrahead %} {# or whatever you call your header block #}
> > >    {{ block.super }}
> > >    {{ cumulative_media }}
> > > {% endblock %}
>
> > > Tim
>
> > > On Nov 24, 12:30 pm, Todd Blanchard  wrote:
> > >> What about de-duping?
> > >> If two forms want the same js file, will it get included twice?
> > >> It seems like this is the kind of thing that the framework should handle 
> > >> and the current "solution" is kind of half baked.
>
> > >> -Todd
>
> > >> On Nov 23, 2009, at 2:40 PM, Mark (Nosrednakram) wrote:
>
> > >>> Hello,
>
> > >>> I have something like the following in my generic genericform.html.  I
> > >>> think this is what you're looking for if not hope you find a better
> > >>> answer. The extramedia block is back in my base.html  template and my
> > >>> form template extends it. I'm not sure if it's in the admin base.html
> > >>> but you can take a look at if for there media blocks I believe are
> > >>> something like extrastyle etc...
>
> > >>> {% block extramedia %}
> > >>> {% if forms %}
> > >>>    {% for form in forms %}
> > >>>       {{ form.media }}
> > >>>    {% endfor %}
> > >>> {% else %}
> > >>>   {{ form.media }}
> > >>> {% endif %}
>
> > >>> Mark
>
> > >>> On Nov 23, 1:31 pm, Todd Blanchard  wrote:
> >  I've read this:
>
> > http://docs.djangoproject.com/en/dev/topics/forms/media/
>
> >  Nifty.  
>
> >  Now, how exactly do I make sure that the media urls get spewed 
> >  properly into the head section of the page?  This is apparently 
> >  omitted everywhere I've looked.  The admin template seems to pull it 
> >  off properly but I cannot figure out how.  Seems like I should be able 
> >  to do something like
>
> >  
> >  
> >  {{ media }}  
> >  
>
> >  but I cannot figure out exactly how to properly aggregate all the 
> >  forms' media's and ge

Re: Designing base template - how to include media properly?

2009-11-24 Thread Todd Blanchard
What is annoying is I have to repeat this incantation in every view function 
ever, yes?.  If its got a form, I have to do this every time.

I thought the idea was to write less code?  Not the same code over and over 
again in every view.

Or am I missing something.  Seems like I am getting very much NON-DRY here.

On Nov 24, 2009, at 3:28 PM, Tim Valenta wrote:

> Sorry it's not working out for you, but I'd disagree about the
> comparison to X-Windows :)  I'd be defending Django, and not X-
> windows, when I say that.
> 
> I'm serious.  Just add them together.  I'm not sure you're
> appreciating the slick objects that have been crafted for this very
> purpose.
> 
> Your view:
>cumulative_media = form.media for form in forms
>return render_to_response('mytemplate.html', {'media':
> cumulative_media})
> 
> Your template:
>{% block my_media_block %}
>{{ block.super }}
>{{ media }}
>{% endblock %}
> 
> I fail to see what is so hard about this.
> 
> Tim
> 
> On Nov 24, 4:13 pm, Todd Blanchard  wrote:
>> You know what, this is absolutely too much BS.  Why would one bother to use 
>> the media declaration stuff at all if there is no mechanism to properly 
>> consume it (a built in template tag for instance).
>> 
>> I think I will just hardcode them in the head in the base template.  They 
>> seldom change and browser caching being what it is having them never change 
>> is just fine.
>> 
>> After three weeks of seriously trying to get traction with django, my 
>> conclusion is it has all of the elegance of X-windows.  It can do anything 
>> but out of the box it does nothing except present a zillion confusing parts 
>> to the programmer and it has too many mechanisms but no policies.
>> 
>> I'm beginning to very much pine for rails.  At least it does something out 
>> of the box.
>> 
>> Very frustrated today - still haven't got a single record/entry form 
>> working.  Too many little files and indirection to keep it all straight in 
>> my head.
>> 
>> -Todd Blanchard
>> 
>> On Nov 24, 2009, at 2:05 PM, Tim Valenta wrote:
>> 
>> 
>> 
>>> The idea is along the lines of what you initially guessed.
>> 
>>> The admin accomplishes the non-duplicate effect in django/django/
>>> contrib/admin/options.py, starting at line 770.  It loops over the
>>> forms and combines the existing media with the media on each form
>>> object.  It ends up using a series of objects to do it, including a
>>> Media class, but it's not doing anything too special.  When an item
>>> gets added, it checks to make sure that the path doesn't already exist
>>> in the list.
>> 
>>> So, short story: loop over your forms and add the media attributes
>>> together.  The underlying Media class ought to be dropping duplicates.
>> 
>>> Then just save a context variable with the result, and do the
>>> following in your template:
>> 
>>> {% block extrahead %} {# or whatever you call your header block #}
>>>{{ block.super }}
>>>{{ cumulative_media }}
>>> {% endblock %}
>> 
>>> Tim
>> 
>>> On Nov 24, 12:30 pm, Todd Blanchard  wrote:
 What about de-duping?
 If two forms want the same js file, will it get included twice?
 It seems like this is the kind of thing that the framework should handle 
 and the current "solution" is kind of half baked.
>> 
 -Todd
>> 
 On Nov 23, 2009, at 2:40 PM, Mark (Nosrednakram) wrote:
>> 
> Hello,
>> 
> I have something like the following in my generic genericform.html.  I
> think this is what you're looking for if not hope you find a better
> answer. The extramedia block is back in my base.html  template and my
> form template extends it. I'm not sure if it's in the admin base.html
> but you can take a look at if for there media blocks I believe are
> something like extrastyle etc...
>> 
> {% block extramedia %}
> {% if forms %}
>{% for form in forms %}
>   {{ form.media }}
>{% endfor %}
> {% else %}
>   {{ form.media }}
> {% endif %}
>> 
> Mark
>> 
> On Nov 23, 1:31 pm, Todd Blanchard  wrote:
>> I've read this:
>> 
>> http://docs.djangoproject.com/en/dev/topics/forms/media/
>> 
>> Nifty.  
>> 
>> Now, how exactly do I make sure that the media urls get spewed properly 
>> into the head section of the page?  This is apparently omitted 
>> everywhere I've looked.  The admin template seems to pull it off 
>> properly but I cannot figure out how.  Seems like I should be able to do 
>> something like
>> 
>> 
>> 
>> {{ media }}  
>> 
>> 
>> but I cannot figure out exactly how to properly aggregate all the forms' 
>> media's and get them spewed into the templates properly.
>> 
>> -Todd
>> 
> --
>> 
> 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 
>>>

Re: Designing base template - how to include media properly?

2009-11-24 Thread Tim Valenta
Sorry it's not working out for you, but I'd disagree about the
comparison to X-Windows :)  I'd be defending Django, and not X-
windows, when I say that.

I'm serious.  Just add them together.  I'm not sure you're
appreciating the slick objects that have been crafted for this very
purpose.

Your view:
cumulative_media = form.media for form in forms
return render_to_response('mytemplate.html', {'media':
cumulative_media})

Your template:
{% block my_media_block %}
{{ block.super }}
{{ media }}
{% endblock %}

I fail to see what is so hard about this.

Tim

On Nov 24, 4:13 pm, Todd Blanchard  wrote:
> You know what, this is absolutely too much BS.  Why would one bother to use 
> the media declaration stuff at all if there is no mechanism to properly 
> consume it (a built in template tag for instance).
>
> I think I will just hardcode them in the head in the base template.  They 
> seldom change and browser caching being what it is having them never change 
> is just fine.
>
> After three weeks of seriously trying to get traction with django, my 
> conclusion is it has all of the elegance of X-windows.  It can do anything 
> but out of the box it does nothing except present a zillion confusing parts 
> to the programmer and it has too many mechanisms but no policies.
>
> I'm beginning to very much pine for rails.  At least it does something out of 
> the box.
>
> Very frustrated today - still haven't got a single record/entry form working. 
>  Too many little files and indirection to keep it all straight in my head.
>
> -Todd Blanchard
>
> On Nov 24, 2009, at 2:05 PM, Tim Valenta wrote:
>
>
>
> > The idea is along the lines of what you initially guessed.
>
> > The admin accomplishes the non-duplicate effect in django/django/
> > contrib/admin/options.py, starting at line 770.  It loops over the
> > forms and combines the existing media with the media on each form
> > object.  It ends up using a series of objects to do it, including a
> > Media class, but it's not doing anything too special.  When an item
> > gets added, it checks to make sure that the path doesn't already exist
> > in the list.
>
> > So, short story: loop over your forms and add the media attributes
> > together.  The underlying Media class ought to be dropping duplicates.
>
> > Then just save a context variable with the result, and do the
> > following in your template:
>
> > {% block extrahead %} {# or whatever you call your header block #}
> >    {{ block.super }}
> >    {{ cumulative_media }}
> > {% endblock %}
>
> > Tim
>
> > On Nov 24, 12:30 pm, Todd Blanchard  wrote:
> >> What about de-duping?
> >> If two forms want the same js file, will it get included twice?
> >> It seems like this is the kind of thing that the framework should handle 
> >> and the current "solution" is kind of half baked.
>
> >> -Todd
>
> >> On Nov 23, 2009, at 2:40 PM, Mark (Nosrednakram) wrote:
>
> >>> Hello,
>
> >>> I have something like the following in my generic genericform.html.  I
> >>> think this is what you're looking for if not hope you find a better
> >>> answer. The extramedia block is back in my base.html  template and my
> >>> form template extends it. I'm not sure if it's in the admin base.html
> >>> but you can take a look at if for there media blocks I believe are
> >>> something like extrastyle etc...
>
> >>> {% block extramedia %}
> >>> {% if forms %}
> >>>    {% for form in forms %}
> >>>       {{ form.media }}
> >>>    {% endfor %}
> >>> {% else %}
> >>>   {{ form.media }}
> >>> {% endif %}
>
> >>> Mark
>
> >>> On Nov 23, 1:31 pm, Todd Blanchard  wrote:
>  I've read this:
>
> http://docs.djangoproject.com/en/dev/topics/forms/media/
>
>  Nifty.  
>
>  Now, how exactly do I make sure that the media urls get spewed properly 
>  into the head section of the page?  This is apparently omitted 
>  everywhere I've looked.  The admin template seems to pull it off 
>  properly but I cannot figure out how.  Seems like I should be able to do 
>  something like
>
>  
>  
>  {{ media }}  
>  
>
>  but I cannot figure out exactly how to properly aggregate all the forms' 
>  media's and get them spewed into the templates properly.
>
>  -Todd
>
> >>> --
>
> >>> 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=.
>
> > --
>
> > 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://group

Re: Per-object permissions

2009-11-24 Thread 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 %-)

--

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: Designing base template - how to include media properly?

2009-11-24 Thread Todd Blanchard
You know what, this is absolutely too much BS.  Why would one bother to use the 
media declaration stuff at all if there is no mechanism to properly consume it 
(a built in template tag for instance).

I think I will just hardcode them in the head in the base template.  They 
seldom change and browser caching being what it is having them never change is 
just fine.

After three weeks of seriously trying to get traction with django, my 
conclusion is it has all of the elegance of X-windows.  It can do anything but 
out of the box it does nothing except present a zillion confusing parts to the 
programmer and it has too many mechanisms but no policies.

I'm beginning to very much pine for rails.  At least it does something out of 
the box.

Very frustrated today - still haven't got a single record/entry form working.  
Too many little files and indirection to keep it all straight in my head.

-Todd Blanchard

On Nov 24, 2009, at 2:05 PM, Tim Valenta wrote:

> The idea is along the lines of what you initially guessed.
> 
> The admin accomplishes the non-duplicate effect in django/django/
> contrib/admin/options.py, starting at line 770.  It loops over the
> forms and combines the existing media with the media on each form
> object.  It ends up using a series of objects to do it, including a
> Media class, but it's not doing anything too special.  When an item
> gets added, it checks to make sure that the path doesn't already exist
> in the list.
> 
> So, short story: loop over your forms and add the media attributes
> together.  The underlying Media class ought to be dropping duplicates.
> 
> Then just save a context variable with the result, and do the
> following in your template:
> 
> {% block extrahead %} {# or whatever you call your header block #}
>{{ block.super }}
>{{ cumulative_media }}
> {% endblock %}
> 
> Tim
> 
> On Nov 24, 12:30 pm, Todd Blanchard  wrote:
>> What about de-duping?
>> If two forms want the same js file, will it get included twice?
>> It seems like this is the kind of thing that the framework should handle and 
>> the current "solution" is kind of half baked.
>> 
>> -Todd
>> 
>> On Nov 23, 2009, at 2:40 PM, Mark (Nosrednakram) wrote:
>> 
>> 
>> 
>> 
>> 
>>> Hello,
>> 
>>> I have something like the following in my generic genericform.html.  I
>>> think this is what you're looking for if not hope you find a better
>>> answer. The extramedia block is back in my base.html  template and my
>>> form template extends it. I'm not sure if it's in the admin base.html
>>> but you can take a look at if for there media blocks I believe are
>>> something like extrastyle etc...
>> 
>>> {% block extramedia %}
>>> {% if forms %}
>>>{% for form in forms %}
>>>   {{ form.media }}
>>>{% endfor %}
>>> {% else %}
>>>   {{ form.media }}
>>> {% endif %}
>> 
>>> Mark
>> 
>>> On Nov 23, 1:31 pm, Todd Blanchard  wrote:
 I've read this:
>> 
 http://docs.djangoproject.com/en/dev/topics/forms/media/
>> 
 Nifty.  
>> 
 Now, how exactly do I make sure that the media urls get spewed properly 
 into the head section of the page?  This is apparently omitted everywhere 
 I've looked.  The admin template seems to pull it off properly but I 
 cannot figure out how.  Seems like I should be able to do something like
>> 
 
 
 {{ media }}  
 
>> 
 but I cannot figure out exactly how to properly aggregate all the forms' 
 media's and get them spewed into the templates properly.
>> 
 -Todd
>> 
>>> --
>> 
>>> 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=.
> 
> --
> 
> 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 unregister model?

2009-11-24 Thread Tomasz Zieliński
That patch is a hack that requires modifying live instance of Django,
moreover I don't know what is influenced by it as I'm not that
familiar
with inner workings of model layer, so using it would be troublesome
for me.

So it seems that I have to write custom delete()s, using raw SQL..

--
Tomasz Zielinski
http://pyconsultant.eu

--

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: Module ho.pis can not be found when running on apache

2009-11-24 Thread Tim Valenta
I was caught by surprise when I moved my stuff to a production server,
too.  The live pythonpath is clearly different than you're expecting,
which I'm sure you know already.

My ultimate problem was that I was taking advantage of the fact that
Django's development server puts your project on the pythonpath
environment variable.  Apache does not.  So even once you get it
successfully running, things won't work properly sometimes, because
the various files in my project were omitting the project name when I
was trying to do imports.  I had to go back and add my project name in
as part of my imports ("from myapp.models import *" -> "from
myproject.myapp.models import *").

This may or may not be the exact problem, but when I look at your
pythonpath and glanced at Brad's link he pasted, I noticed that the
contents of your projects is on the path, but not the parent directory
of the project.  You may need an extra "__init__.py" in the parent
directory, too.

It all got really confusing, especially when I was trying to deploy
multiple Django sites.

Is any of that relevant to your problem?  I'm not exactly an expert,
but I know that I got harassed by this type of issue, too.

Tim

On Nov 24, 12:43 pm, "philip.bar...@impaerospace.com"
 wrote:
> When I try running my project via Apache I get a "No module named
> ho.pisa" error message.
>
> However, when I run the same project from django's built-in dev
> server, it works just fine.
>
> Similarly, when I access python, or go through python manage.py shell,
> I can import ho.pisa without error.
>
> I've tried reinstalling Pisa. I've double checked that Pisa is one my
> site packages and that my site packages are in my python path.
>
> I'm using Ubuntu 9.10, Apache 2.2, Django 1.0.3 and Python 2.5
>
> Setting python 2.5 as default was done with the following steps:
> /usr/bin/python is a symlink to /usr/bin/python2.5
> /usr/share/python/debian_defaults has been edited to specify python2.5
> has my default python
> And a partial recompile of mod python
>
> I successfully got this working using a different system running
> Ubuntu 8.10, so it might be a problem with Ubuntu 9.10.
>
> Anyone have any thoughts as to what to try next?
>
> Something that might be related that I couldn't figure out was that
> the error page from Django claims that the Django version is 2.6.4,
> which it shouldn't be.
>
> Full error read out follows:
>
> ViewDoesNotExist at /nsr/wizard/
>
> Could not import idms.nsr.views. Error was: No module named ho.pisa
>
> Request Method:         GET
> Request URL:    http://localhost/nsr/wizard/
> Exception Type:         ViewDoesNotExist
> Exception Value:
>
> Could not import idms.nsr.views. Error was: No module named ho.pisa
>
> Exception Location:     /usr/lib/python2.5/site-packages/django/core/
> urlresolvers.py in _get_callback, line 133
> Python Executable:      /usr/bin/python
> Python Version:         2.6.4
> Python Path:    ['/usr/lib/python2.5/site-packages', '/home/ase/Desktop/
> idms_project', '/usr/lib/python2.6', '/usr/lib/python2.6/plat-linux2',
> '/usr/lib/python2.6/lib-tk', '/usr/lib/python2.6/lib-old', '/usr/lib/
> python2.6/lib-dynload', '/usr/lib/python2.6/dist-packages', '/usr/lib/
> python2.6/dist-packages/Numeric', '/usr/lib/python2.6/dist-packages/
> PIL', '/usr/lib/python2.6/dist-packages/gst-0.10', '/usr/lib/pymodules/
> python2.6', '/usr/lib/python2.6/dist-packages/gtk-2.0', '/usr/lib/
> pymodules/python2.6/gtk-2.0', '/usr/lib/python2.6/dist-packages/wx-2.8-
> gtk2-unicode', '/usr/local/lib/python2.6/dist-packages']
> Server time:    Tue, 24 Nov 2009 21:38:28 +
>
> Environment:
>
> Request Method: GET
> Request URL:http://localhost/nsr/wizard/
> Django Version: 1.0.3
> Python Version: 2.6.4
> Installed Applications:
> ['django.contrib.auth',
>  'django.contrib.contenttypes',
>  'django.contrib.sessions',
>  'django.contrib.sites',
>  'django.contrib.admin',
>  'idms.general',
>  'idms.ipl',
>  'idms.doc',
>  'idms.ssi',
>  'idms.fsr',
>  'idms.dar',
>  'idms.dmm',
>  'idms.tdm',
>  'idms.ssir',
>  'idms.nsr',
>  'idms.ssir.templatetags',
>  'idms.ffd']
> Installed Middleware:
> ('django.middleware.common.CommonMiddleware',
>  'django.contrib.sessions.middleware.SessionMiddleware',
>  'django.contrib.auth.middleware.AuthenticationMiddleware',
>  'django.middleware.doc.XViewMiddleware',
>  'django.middleware.transaction.TransactionMiddleware')
>
> Traceback:
> File "/usr/lib/python2.5/site-packages/django/core/handlers/base.py"
> in get_response
>   82.                     request.path_info)
> File "/usr/lib/python2.5/site-packages/django/core/urlresolvers.py" in
> resolve
>   183.                     sub_match = pattern.resolve(new_path)
> File "/usr/lib/python2.5/site-packages/django/core/urlresolvers.py" in
> resolve
>   183.                     sub_match = pattern.resolve(new_path)
> File "/usr/lib/python2.5/site-packages/django/core/urlresolvers.py" in
> resolve
>   124.             return self.callback, args, kwargs
> 

Re: How to unregister model?

2009-11-24 Thread Tim Valenta
> http://code.djangoproject.com/ticket/10829

Seeing as how it was last updated over a month ago, you might be best
off by downloading his patch and applying it, because there may not be
a solution very quickly.  Development for version 1.2 is going on
right now, and they're focusing on brand-new features at the moment.
Bug fixes and such tweaks (which I think this will be categorized as)
won't start getting attention until January.

If you've got an SVN checkout of Django, you can apply the patch with
some simple SVN commands (easily Google'd).  Just look for something
about applying a patch, specifically with that vocabulary.

If you've got a frozen downloaded version, you could open up the
".diff" patch in a text editor and figure out which file it's
patching, and add any lines with a "+" in front of it, and remove any
with a "-" in front of it.

I'm afraid there won't be a core update right away, and it sounds like
you're in need of one.  Unless someone more knowledgeable with the
Database layer can help out, I'm unsure of what else you might be able
to do.

On Nov 24, 3:02 pm, Tomasz Zieliński
 wrote:
> On 24 Lis, 22:42, Tim Valenta  wrote:
>
> > > I want my unmanaged models to literally disappear from Django sight,
> > > and then re-appear on demand.
>
> > That sounds rather hack-ish... I'm not sure Django can do that
> > exactly.  I'm not familiar with the situation, exactly, so I'm unsure
> > of what you might be able to do differently.
>
> I'm suffering from something similar to this:
>
> http://code.djangoproject.com/ticket/10829
>
> - and I prefer to avoid hacking Django core, resorting to raw SQL etc.
> I only I could hide those unmanaged models, things would be smooth
> again,
> even though it's not the cleanest solution.
>
> --
> Tomasz Zielinskihttp://pyconsultant.eu

--

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: Designing base template - how to include media properly?

2009-11-24 Thread Tim Valenta
The idea is along the lines of what you initially guessed.

The admin accomplishes the non-duplicate effect in django/django/
contrib/admin/options.py, starting at line 770.  It loops over the
forms and combines the existing media with the media on each form
object.  It ends up using a series of objects to do it, including a
Media class, but it's not doing anything too special.  When an item
gets added, it checks to make sure that the path doesn't already exist
in the list.

So, short story: loop over your forms and add the media attributes
together.  The underlying Media class ought to be dropping duplicates.

Then just save a context variable with the result, and do the
following in your template:

{% block extrahead %} {# or whatever you call your header block #}
{{ block.super }}
{{ cumulative_media }}
{% endblock %}

Tim

On Nov 24, 12:30 pm, Todd Blanchard  wrote:
> What about de-duping?
> If two forms want the same js file, will it get included twice?
> It seems like this is the kind of thing that the framework should handle and 
> the current "solution" is kind of half baked.
>
> -Todd
>
> On Nov 23, 2009, at 2:40 PM, Mark (Nosrednakram) wrote:
>
>
>
>
>
> > Hello,
>
> > I have something like the following in my generic genericform.html.  I
> > think this is what you're looking for if not hope you find a better
> > answer. The extramedia block is back in my base.html  template and my
> > form template extends it. I'm not sure if it's in the admin base.html
> > but you can take a look at if for there media blocks I believe are
> > something like extrastyle etc...
>
> > {% block extramedia %}
> > {% if forms %}
> >    {% for form in forms %}
> >       {{ form.media }}
> >    {% endfor %}
> > {% else %}
> >   {{ form.media }}
> > {% endif %}
>
> > Mark
>
> > On Nov 23, 1:31 pm, Todd Blanchard  wrote:
> >> I've read this:
>
> >>http://docs.djangoproject.com/en/dev/topics/forms/media/
>
> >> Nifty.  
>
> >> Now, how exactly do I make sure that the media urls get spewed properly 
> >> into the head section of the page?  This is apparently omitted everywhere 
> >> I've looked.  The admin template seems to pull it off properly but I 
> >> cannot figure out how.  Seems like I should be able to do something like
>
> >> 
> >> 
> >> {{ media }}  
> >> 
>
> >> but I cannot figure out exactly how to properly aggregate all the forms' 
> >> media's and get them spewed into the templates properly.
>
> >> -Todd
>
> > --
>
> > 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=.

--

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 unregister model?

2009-11-24 Thread Tomasz Zieliński
On 24 Lis, 22:42, Tim Valenta  wrote:
> > I want my unmanaged models to literally disappear from Django sight,
> > and then re-appear on demand.
>
> That sounds rather hack-ish... I'm not sure Django can do that
> exactly.  I'm not familiar with the situation, exactly, so I'm unsure
> of what you might be able to do differently.
>

I'm suffering from something similar to this:

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

- and I prefer to avoid hacking Django core, resorting to raw SQL etc.
I only I could hide those unmanaged models, things would be smooth
again,
even though it's not the cleanest solution.

--
Tomasz Zielinski
http://pyconsultant.eu

--

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: virtualenv, PIP, fabric and patches to external projects

2009-11-24 Thread Kevin Teague
With patching Python code, there is always the option of dynamically
modifying the code at run-time ... aka doing it monkey style. You can
do this in a bit more orderly fashion by using something like the
'monkey' package, which lets you use a signature on the function being
packaged, so that you become aware when you update the code being
patched that it's not longer the same code.

http://pypi.python.org/pypi/monkey

But beyond that, PIP is probably not the right tool for applying
patches. It's probably also not the right tool for setting up
databases, configuring LDAP, cleaning the cats liter, etc. I use
Buildout for this. Which a number of people use in conjunction with
virtualenv and pip (there is a Buildout recipe for driving pip for
example). Although there are also recipes which let you manage
packages in an isolated fashion without using virtualenv+pip - which
is usually what I do since they allow you to re-use the same packages
between deployments. I think if I installed all the deployments on my
machine using PIP where the code is repeated for every deployment I
would run out of i-nodes.

Anyways, patching in Buildout, that is patching C code, etc. ... aka
real patching or manly patching, is usually done with a 'configure;
make; make install;' recipe. With the zc.recipe.cmmi (http://
pypi.python.org/pypi/zc.recipe.cmmi) this looks like:

[buildout]
parts = foo

[foo]
recipe = zc.recipe.cmmi
url = http://url-path/to/some-file.tgz
patch = ${buildout:directory}/patches/config.patch
patch_options = -p0

I haven't actually used Fabric yet (keep meaning to switch some
deployments over some day, but I guess I'm too busy doing manuall
deployments to have time for this ;P), but it's my understanding this
is a tool for executing remote commands (e.g. commands to invoke pip
or buildout). I guess you can always accomplish quite a bit with BASH
commands, but I much prefer Buildout as it's a declarative
configuration system as opposed to an imperative series of commands.

--

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.




reversing URLs

2009-11-24 Thread Tim Valenta
Ever since day one, I've never had a firm grasp on what the heck URL
reversing can do.  I understand the concepts involved, even the admin
namespacing that can occur with different admin sites, and I know that
the admin uses it regularly, but it seems like a crazy unpredictable
wildcard when I try to use it manually.

For instance, I'm trying to get the permalink decorator to work on a
"get_absolute_url()" method on my model, and I haven't got the
slightest clue what the hell it's doing.  I'm getting errors about it
not being able to reverse it properly when I try to click on the admin-
generated "View on site ->" link from the change form.  It says that
it can't find the view.

Basically, I've tried making the method refer to the view object, a
view name as a string (explicitly setting the name in the url conf),
an absolute module-path string ("myproject.myapp.views.my_view"), and
nothing works.  It can never find it, even on a view with just a
single required keyword argument.

Is there any amazing breakdown on how to better wrap my brain around
how this url reversing thing works?  I typically don't think of myself
as an idiot, but I really cannot even begin to feel like I can use it
proficiently.

Thanks in advance.

--

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

2009-11-24 Thread Tim Valenta
> I want my unmanaged models to literally disappear from Django sight,
> and then re-appear on demand.

That sounds rather hack-ish... I'm not sure Django can do that
exactly.  I'm not familiar with the situation, exactly, so I'm unsure
of what you might be able to do differently.

Apologies.

Tim

On Nov 24, 2:18 pm, Tomasz Zieliński
 wrote:
> On 24 Lis, 22:15, Tim Valenta  wrote:
>
> > If you're not doing anything fancy with AdminSite objects (ie, you're
> > only using the default admin site), then do this:
>
> > # assuming you've already done: from django.contrib import admin
> > admin.site.unregister(MyModel)
>
> The 'unregister' word seems to have been misleading, as I wasn't
> referring
> to admin panel at all :)
>
> I want my unmanaged models to literally disappear from Django sight,
> and then re-appear on demand.
>
> --
> Tomasz Zielinskihttp://pyconsultant.eu

--

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




Re: newbie questions regarding models and admin

2009-11-24 Thread Tim Valenta
Your first question about how to separate fields is not perfectly
clear to me.  However, I can say that I typically put *all* fields on
the actual admin objects, since an admin is typically not the one
you're trying to restrict.  Then, in your own custom views (and the
forms you render in those views), you just include the items that you
want to be publicly visible.

> But as far as I understand it this only works on the
> admin page and not generally.

You are correct.  Notice how you're setting the "max_num" attribute on
your subclassed ModelAdmin.  The Admin is really just an app, though
bundled with Django.  Anything you do with the admin won't ever have a
Django- or site-wide impact.  That might seem frustrating, but it does
help a lot for people who write general apps, which they distribute to
others.  We would find it far *more* frustrating to have to deal with
site-wide side effects that only were intended for the admin site.

The actual solution, since you seem to want to make your own forms and
not use the admin, would be to code this maximum-of-8 logic into your
views.  When you render the form, you'll want to do one of two things.

  1) If you think you want to just hard code this, just copy and paste
your template HTML to a total of 8 times, so that your form will
appear that many times.  You'll of course want to take care to use
proper HTML "name" attributes on the various elements, so that each of
the 8 forms has unique values there.  Point blank, you need the 8
forms to have unique names so that they don't get in a traffic jam
when you submit the form.

  2) A better solution might be to generate the 8 forms in Python in
your actual view function.  slap them in a list, and then just use the
template language to iterate them with a for loop.  This way, you can
more easily manipulate the data before it gets to the template.

And when they submit the form back onto the same view, the view will
check for `request.method == "POST"`, and then verify that there are
no more than 8 being submitted.  Defensive coding.

> Second thing I don't know is how to have the 8 subexperiments have their
> number automatically set. Is there a way to create the 8 subexperiments
> when an experiment is created?

This can go in a couple of directions...  If all you care about is the
way the name is display, you can make your __unicode__ method do
something like the following, assuming your top-level model was
"Parent", and your sub-level model was "Child"

def __unicode__(self):
total_children = self.parent.child_set.count()
return u'Experiment %d' % (i+1,) for i in range(0,
total_children)

This is a bigger hit to the database, but it could be totally
negligible if this is a fairly small project.

The idea is that you just count how many children there are, and
dynamically render a name based on their order.  Once you create a new
one, it'll automatically get a name in sequence with the others.

I hope that helps.

On Nov 24, 8:11 am, Andreas Kuntzagk 
wrote:
> Hi
>
> nek4life wrote:
> > The philosophy of the admin app is that it is a simple CRUD interface
> > for trusted staff members to manage data.  If you need data entry for
> > non staff members (i.e. people you do not trust with the admin) you
> > should create public facing forms and setup some permissions for the
> > users to be able to use them.
>
> Ok, will look into this.
>
> > As for you second question it sounds like you need two models, one for
> > experiment_x and one for sub_experiment_x with a foreignkey to
> > experiment_x.  You could probably use inline formsets to generate the
> > extra 8 forms.  I'm not sure how you would limit the inline formsets
> > though to exactly 8.
>
> I already have it like this. But I was wondering if there is a
> possibility to set it fixed to 8. I set extra and max_num to 8 for the
> StackedInline. But as far as I understand it this only works on the
> admin page and not generally.
> Second thing I don't know is how to have the 8 subexperiments have their
> number automatically set. Is there a way to create the 8 subexperiments
> when an experiment is created?
>
> Regards, Andreas
>
>
>
>
>
> > Hope this helps.
>
> > On Nov 24, 5:33 am, Andreas Kuntzagk 
> > wrote:
> >> Hi,
>
> >> I'm quite new to django and very new to this list.
> >> I'm in the process of writing a small webapp for our lab.
> >> Working with the tutorial I already put together a small model and some
> >> admin pages.
> >> But now I came to some stumbling blocks:
>
> >> First is a broader question: I'm wondering what belongs to an admin page
> >>   and what should be in a "normal" form. I want to keep track on some
> >> experiments so some (authenticated) users should create experiment
> >> entries and add comments etc. And then I have "machines" where these
> >> experiments run. These don't change so often. So does setting these
> >> things belong into the admin area?
>
> >> Second experiments of type x always consist of 8 para

Re: How to unregister model?

2009-11-24 Thread Tomasz Zieliński
On 24 Lis, 22:18, Tim Valenta  wrote:
> Sorry for double-post.
>
> Additionally, you might experiment with the Meta class attribute,
> "abstract = True" on your wrapper models.  

Thank you, I know about 'abstract' and I am using but unfortunately
it doesn't help me much. What I need is the ability to somehow hide
for a while non-abstract unmanaged models.

--
Tomasz Zielinski
http://pyconsultant.eu

--

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-1.1.1 builtin Development WebServer crashes with a core dump

2009-11-24 Thread Tim Valenta
It's not very clear what is happening.  If you start a brand new
project, there won't be any URLs for you to visit yet.  It will most
probably give you the error page, telling you that there is no URL
matching the query.

A better copy-and-paste would be what the browser is displaying.

I hope I've understood properly,

Tim

On Nov 24, 10:24 am, lbockhold  wrote:
> Hello users,
> I am new to django, just installed Django-1.1.1.tar.gz
> but:
>
> Machine HPUX:
> th...@dex: /home/th18bl > uname -a
> HP-UX dex B.11.11 U 9000/785 4042425557 unlimited-user license
>
> python:
> th...@dex: /home/th18bl > python
> ActivePython 2.6.2.2 (ActiveState Software Inc.) based on
> Python 2.6.2 (r262:71600, Apr 21 2009, 15:06:28) [C] on hp-ux11
> Type "help", "copyright", "credits" or "license" for more information.
> dd
> 1.django-admin.py startproject mysite "ok"
> 2. python manage.py runserver "ok"
>     Validating models ...
>     0 errors found
>     ...
>     Quit the server ...
> 3. But when I use a browser to go to that page - the Dev. Server just
> quits and writes a big "core" file!
>
> Thanks for help
>
> Greetings Lars

--

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 unregister model?

2009-11-24 Thread Tim Valenta
Sorry for double-post.

Additionally, you might experiment with the Meta class attribute,
"abstract = True" on your wrapper models.  It makes Django ignore the
model when it does database table creation.  That way, your wrapper
acts more like a true Python inheritance object, where you simply get
the benefits of inherited methods and fields, without the wrapper
creating its own lonely table without any data.

Not sure if it fits your situation, but it's good to know about.  It
seems like you're having to worry a bit too much about the extra
models.  There are all kinds of uses once you figure out how to use
it.

Here's the docs on it:

http://docs.djangoproject.com/en/dev/topics/db/models/#id6

On Nov 24, 2:15 pm, Tim Valenta  wrote:
> If you're not doing anything fancy with AdminSite objects (ie, you're
> only using the default admin site), then do this:
>
> # assuming you've already done: from django.contrib import admin
> admin.site.unregister(MyModel)
>
> Note that it's exactly the opposite of the normal "admin.site.register
> ()" method, except that it only ever takes the one argument, not two.
>
> I do this for changing the default User model admin. I unregister it,
> alter the UserAdmin provided in Django, and then re-register it with
> my own.
>
> Tim
>
> On Nov 24, 1:54 pm, Tomasz Zieliñski
>
>
>
>  wrote:
> > Is there a way to unregister model from being seen by Django model
> > manager?
> > I have some unmanaged models that are wrappers around read-only
> > database views
> > and also have foreign keys to 'real' models.
>
> > Now, when I'm trying to delete instance of 'real' model that is
> > referenced by unmanaged model,
> > I'm getting OperationalErrors as Django tries to perform cascade
> > delete.
>
> > As a solution, I'd like to unregister my unmanaged models
> > before .delete(),
> > and re-registering them after, but I don't know how to do it.
>
> > --
> > Tomasz Zielinskihttp://pyconsultant.eu

--

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 unregister model?

2009-11-24 Thread Tomasz Zieliński
On 24 Lis, 22:15, Tim Valenta  wrote:
> If you're not doing anything fancy with AdminSite objects (ie, you're
> only using the default admin site), then do this:
>
> # assuming you've already done: from django.contrib import admin
> admin.site.unregister(MyModel)
>

The 'unregister' word seems to have been misleading, as I wasn't
referring
to admin panel at all :)

I want my unmanaged models to literally disappear from Django sight,
and then re-appear on demand.

--
Tomasz Zielinski
http://pyconsultant.eu

--

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 unregister model?

2009-11-24 Thread Tim Valenta
If you're not doing anything fancy with AdminSite objects (ie, you're
only using the default admin site), then do this:

# assuming you've already done: from django.contrib import admin
admin.site.unregister(MyModel)

Note that it's exactly the opposite of the normal "admin.site.register
()" method, except that it only ever takes the one argument, not two.

I do this for changing the default User model admin. I unregister it,
alter the UserAdmin provided in Django, and then re-register it with
my own.

Tim

On Nov 24, 1:54 pm, Tomasz Zieliński
 wrote:
> Is there a way to unregister model from being seen by Django model
> manager?
> I have some unmanaged models that are wrappers around read-only
> database views
> and also have foreign keys to 'real' models.
>
> Now, when I'm trying to delete instance of 'real' model that is
> referenced by unmanaged model,
> I'm getting OperationalErrors as Django tries to perform cascade
> delete.
>
> As a solution, I'd like to unregister my unmanaged models
> before .delete(),
> and re-registering them after, but I don't know how to do it.
>
> --
> Tomasz Zielinskihttp://pyconsultant.eu

--

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.




Copying files from remote server

2009-11-24 Thread bax...@gretschpages.com
I'm trying to import content from another server via RSS. My problem
is with the images. Parsing the RSS with feedparser,  I can get the
image, but from there I've run into trouble. I can save a pointer to
the remote file, but then I can't thumbnail or otherwise work with the
image like a local file, and it could disappear someday. I'm trying to
save a local copy of the files, but can't seem to get it working
properly. From what I can tell, I'm copying the file OK, but the image
model doesn't see it.

my view is here: http://pastebin.com/m7eee7ff2

--

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 unregister model?

2009-11-24 Thread Tomasz Zieliński
Is there a way to unregister model from being seen by Django model
manager?
I have some unmanaged models that are wrappers around read-only
database views
and also have foreign keys to 'real' models.

Now, when I'm trying to delete instance of 'real' model that is
referenced by unmanaged model,
I'm getting OperationalErrors as Django tries to perform cascade
delete.

As a solution, I'd like to unregister my unmanaged models
before .delete(),
and re-registering them after, but I don't know how to do it.

--
Tomasz Zielinski
http://pyconsultant.eu

--

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.




virtualenv, PIP, fabric and patches to external projects

2009-11-24 Thread Alex Rades
Hi,
I know this is probably not 100% django related (well, actually is 0%)
but I think most of you have worked with virtualenv and PIP and this
looks like a good place to talk about deployment scenarios.

Basically, I'd like to handle dependencies of my virtual environment
with PIP, but I have some patches to external projects that I have to
apply to apply before I can use them.
Looks like PIP does not offer a facility to apply patches to
downloaded dependencies. Maybe pip is not the right tool to do this.

How do you handle your patching needs in your environments? I've
started thinking about using fabric to do this, but I'm not really
sure.

Thank you very much.

--

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-24 Thread bruno desthuilliers
On 24 nov, 10:28, Elyrwen  wrote:
> Hello,
>
> I' ve been recently interested in Djagno framework and I am at the
> point of choosing it as the framework for my project. My application
> will not use database, but will use webservices to get data and then
> process it.
>
> I need a substitute for the Django model layer. Precisely I need a
> class that would parse a wsdl (this I am doing with suds) and then
> call the remote methods. There should be one instance of this class
> served by all requests to
> avoid parsing wsdl for evey request - sort of a singleton class that
> would keep parsed stubs. It is possible to place such shared class in
> Django? Can you point me to some solutions that avoid parsing wsdl
> with each new request?
>
> Maybe there is yet another way to obtain it with Django?

Others already gave you good answers - like using the db/model layer
as a local cache, which, FWIW, it's probably how I would solve this
problem. I'd just like to add a more general comment: Django is a
Python framework, and your views can act on just any Python object. So
if and when you don't need the ORM part, don't use 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: Module ho.pis can not be found when running on apache

2009-11-24 Thread brad


On Nov 24, 1:43 pm, "philip.bar...@impaerospace.com"
 wrote:
> When I try running my project via Apache I get a "No module named
> ho.pisa" error message.
>
> However, when I run the same project from django's built-in dev
> server, it works just fine.
>

Well, this sounds very similar to a problem I'm having (but with
cx_Oracle, rather than ho.pisa).  Are you using virtualenv?

I've described by problem here:
http://bradmontgomery.blogspot.com/2009/11/gahhh-django-virtualenv-and-cxoracle.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.




Module ho.pis can not be found when running on apache

2009-11-24 Thread philip.bar...@impaerospace.com
When I try running my project via Apache I get a "No module named
ho.pisa" error message.

However, when I run the same project from django's built-in dev
server, it works just fine.

Similarly, when I access python, or go through python manage.py shell,
I can import ho.pisa without error.

I've tried reinstalling Pisa. I've double checked that Pisa is one my
site packages and that my site packages are in my python path.

I'm using Ubuntu 9.10, Apache 2.2, Django 1.0.3 and Python 2.5

Setting python 2.5 as default was done with the following steps:
/usr/bin/python is a symlink to /usr/bin/python2.5
/usr/share/python/debian_defaults has been edited to specify python2.5
has my default python
And a partial recompile of mod python

I successfully got this working using a different system running
Ubuntu 8.10, so it might be a problem with Ubuntu 9.10.

Anyone have any thoughts as to what to try next?

Something that might be related that I couldn't figure out was that
the error page from Django claims that the Django version is 2.6.4,
which it shouldn't be.


Full error read out follows:

ViewDoesNotExist at /nsr/wizard/

Could not import idms.nsr.views. Error was: No module named ho.pisa

Request Method: GET
Request URL:http://localhost/nsr/wizard/
Exception Type: ViewDoesNotExist
Exception Value:

Could not import idms.nsr.views. Error was: No module named ho.pisa

Exception Location: /usr/lib/python2.5/site-packages/django/core/
urlresolvers.py in _get_callback, line 133
Python Executable:  /usr/bin/python
Python Version: 2.6.4
Python Path:['/usr/lib/python2.5/site-packages', '/home/ase/Desktop/
idms_project', '/usr/lib/python2.6', '/usr/lib/python2.6/plat-linux2',
'/usr/lib/python2.6/lib-tk', '/usr/lib/python2.6/lib-old', '/usr/lib/
python2.6/lib-dynload', '/usr/lib/python2.6/dist-packages', '/usr/lib/
python2.6/dist-packages/Numeric', '/usr/lib/python2.6/dist-packages/
PIL', '/usr/lib/python2.6/dist-packages/gst-0.10', '/usr/lib/pymodules/
python2.6', '/usr/lib/python2.6/dist-packages/gtk-2.0', '/usr/lib/
pymodules/python2.6/gtk-2.0', '/usr/lib/python2.6/dist-packages/wx-2.8-
gtk2-unicode', '/usr/local/lib/python2.6/dist-packages']
Server time:Tue, 24 Nov 2009 21:38:28 +

Environment:

Request Method: GET
Request URL: http://localhost/nsr/wizard/
Django Version: 1.0.3
Python Version: 2.6.4
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.admin',
 'idms.general',
 'idms.ipl',
 'idms.doc',
 'idms.ssi',
 'idms.fsr',
 'idms.dar',
 'idms.dmm',
 'idms.tdm',
 'idms.ssir',
 'idms.nsr',
 'idms.ssir.templatetags',
 'idms.ffd']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.middleware.doc.XViewMiddleware',
 'django.middleware.transaction.TransactionMiddleware')


Traceback:
File "/usr/lib/python2.5/site-packages/django/core/handlers/base.py"
in get_response
  82. request.path_info)
File "/usr/lib/python2.5/site-packages/django/core/urlresolvers.py" in
resolve
  183. sub_match = pattern.resolve(new_path)
File "/usr/lib/python2.5/site-packages/django/core/urlresolvers.py" in
resolve
  183. sub_match = pattern.resolve(new_path)
File "/usr/lib/python2.5/site-packages/django/core/urlresolvers.py" in
resolve
  124. return self.callback, args, kwargs
File "/usr/lib/python2.5/site-packages/django/core/urlresolvers.py" in
_get_callback
  133. raise ViewDoesNotExist, "Could not import %s. Error
was: %s" % (mod_name, str(e))

Exception Type: ViewDoesNotExist at /nsr/wizard/
Exception Value: Could not import idms.nsr.views. Error was: No module
named ho.pisa


Thank you for any help.

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: Designing base template - how to include media properly?

2009-11-24 Thread Todd Blanchard
What about de-duping?
If two forms want the same js file, will it get included twice?
It seems like this is the kind of thing that the framework should handle and 
the current "solution" is kind of half baked.

-Todd

On Nov 23, 2009, at 2:40 PM, Mark (Nosrednakram) wrote:

> 
> Hello,
> 
> I have something like the following in my generic genericform.html.  I
> think this is what you're looking for if not hope you find a better
> answer. The extramedia block is back in my base.html  template and my
> form template extends it. I'm not sure if it's in the admin base.html
> but you can take a look at if for there media blocks I believe are
> something like extrastyle etc...
> 
> {% block extramedia %}
> {% if forms %}
>{% for form in forms %}
>   {{ form.media }}
>{% endfor %}
> {% else %}
>   {{ form.media }}
> {% endif %}
> 
> Mark
> 
> 
> On Nov 23, 1:31 pm, Todd Blanchard  wrote:
>> I've read this:
>> 
>> http://docs.djangoproject.com/en/dev/topics/forms/media/
>> 
>> Nifty.  
>> 
>> Now, how exactly do I make sure that the media urls get spewed properly into 
>> the head section of the page?  This is apparently omitted everywhere I've 
>> looked.  The admin template seems to pull it off properly but I cannot 
>> figure out how.  Seems like I should be able to do something like
>> 
>> 
>> 
>> {{ media }}  
>> 
>> 
>> but I cannot figure out exactly how to properly aggregate all the forms' 
>> media's and get them spewed into the templates properly.
>> 
>> -Todd
> 
> --
> 
> 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=.
> 
> 

--

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.




Django-1.1.1 builtin Development WebServer crashes with a core dump

2009-11-24 Thread lbockhold
Hello users,
I am new to django, just installed Django-1.1.1.tar.gz
but:

Machine HPUX:
th...@dex: /home/th18bl > uname -a
HP-UX dex B.11.11 U 9000/785 4042425557 unlimited-user license

python:
th...@dex: /home/th18bl > python
ActivePython 2.6.2.2 (ActiveState Software Inc.) based on
Python 2.6.2 (r262:71600, Apr 21 2009, 15:06:28) [C] on hp-ux11
Type "help", "copyright", "credits" or "license" for more information.
dd
1.django-admin.py startproject mysite "ok"
2. python manage.py runserver "ok"
Validating models ...
0 errors found
...
Quit the server ...
3. But when I use a browser to go to that page - the Dev. Server just
quits and writes a big "core" file!


Thanks for help

Greetings Lars


--

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




Re: newbie questions regarding models and admin

2009-11-24 Thread Andreas Kuntzagk
Hi

nek4life wrote:
> The philosophy of the admin app is that it is a simple CRUD interface
> for trusted staff members to manage data.  If you need data entry for
> non staff members (i.e. people you do not trust with the admin) you
> should create public facing forms and setup some permissions for the
> users to be able to use them.

Ok, will look into this.

> As for you second question it sounds like you need two models, one for
> experiment_x and one for sub_experiment_x with a foreignkey to
> experiment_x.  You could probably use inline formsets to generate the
> extra 8 forms.  I'm not sure how you would limit the inline formsets
> though to exactly 8.

I already have it like this. But I was wondering if there is a 
possibility to set it fixed to 8. I set extra and max_num to 8 for the 
StackedInline. But as far as I understand it this only works on the 
admin page and not generally.
Second thing I don't know is how to have the 8 subexperiments have their 
number automatically set. Is there a way to create the 8 subexperiments 
when an experiment is created?

Regards, Andreas

> 
> Hope this helps.
> 
> On Nov 24, 5:33 am, Andreas Kuntzagk 
> wrote:
>> Hi,
>>
>> I'm quite new to django and very new to this list.
>> I'm in the process of writing a small webapp for our lab.
>> Working with the tutorial I already put together a small model and some
>> admin pages.
>> But now I came to some stumbling blocks:
>>
>> First is a broader question: I'm wondering what belongs to an admin page
>>   and what should be in a "normal" form. I want to keep track on some
>> experiments so some (authenticated) users should create experiment
>> entries and add comments etc. And then I have "machines" where these
>> experiments run. These don't change so often. So does setting these
>> things belong into the admin area?
>>
>> Second experiments of type x always consist of 8 parallel
>> subexperiments. How do I model this? These subexperiments should
>> (automagically) be named subexp1 to subexp8.
>>
>> Regards, Andreas
> 
> --
> 
> 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: even and odd numbers within a template

2009-11-24 Thread Kevin Renskers
{% for o in some_list %}

...

{% endfor %}


On Nov 24, 2:39 pm, Juan Hernandez  wrote:
> Hey there people...
>
> I've been coloring html tables using javascript for a while and now, we need
> to color our tables just with html. The CSS has been made to use one color
> for even rows and another one for odds. How can I know if a current template
> loop is odd or even? I've been trying many different things and none of them
> work
>
> Thanx
> jhv

--

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




Re: custom backend causes this error: authenticate() takes exactly 0 arguments (2 given)

2009-11-24 Thread Gloria
The post before this one never made it. Strange.
I have no other custom authenticate() methods. I did try to call my
own directly, and this worked, but it's not the recommended way.
Is there some more debug info I can turn on, to see what authenticate
() methods Djongo is trying to invoke? It's appanrently ignoring mine,
and gettiong one from somewhere not obvious to me.
Thanks for your help,
Gloria

--

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




Re: custom backend causes this error: authenticate() takes exactly 0 arguments (2 given)

2009-11-24 Thread Gloria
After further examination, it looks like Django is completely ignoring
my setting:

AUTHENTICATION_BACKENDS =
('pg.ip.profile.auth_backend.AuthBackend','django.contrib.auth.backends.ModelBackend')

Argh...

Gloria

--

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




Re: custom backend causes this error: authenticate() takes exactly 0 arguments (2 given)

2009-11-24 Thread Tom Evans
On Tue, Nov 24, 2009 at 5:28 PM, Gloria  wrote:


> Traceback:
> File "/usr/lib/python2.6/site-packages/Django-1.1.1-py2.6.egg/django/
> core/handlers/base.py" in get_response
>  92. response = callback(request, *callback_args,
> **callback_kwargs)
> File "/mnt/XP_D/Opencrowd/PressGaney/pg_trunk/main/pg/ip/profile/
> views.py" in local_login
>  82.   user = authenticate(user_name)
>
> Exception Type: TypeError at /login/
> Exception Value: authenticate() takes exactly 0 arguments (1 given)
>
> Thanks,
> Gloria
>

Hmm, I'm not sure you're doing this correctly. You shouldn't be trying to
call the authenticate() method on your custom backend, you should be calling
django.contrib.auth.authenticate, with whatever usernames/tokens/etc you
have to provide. Django's auth system will iterate through its backends, as
defined in settings.AUTHENTICATION_BACKENDS, calling each of them in turn
until one of them returns something other than None.

See
http://docs.djangoproject.com/en/dev/topics/auth/#writing-an-authentication-backendfor
more details.

I still think you are directly calling a function called authenticate() that
is not django.contrib.auth.authenticate()..

Cheers

Tom

--

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




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

2009-11-24 Thread rc
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?

On Nov 24, 10:13 am, rc  wrote:
> What I want to do is have a form with one field that allows you to
> select a profile. Once this profile is selected there will be two
> windows below that show available tests and selected tests. The Django
> admin interface for the user permissions uses this format. Not sure
> what it is called in Django.
>
> My current models are listed below. I have a joining table called
> Testsuite that joins tests to profiles. It works now, but the admin is
> not very easy to add or remove tests to a testsuite since you have to
> add one at a time. If someone can point me in the right direction I
> would appreciate it.
>
> Anyway I have the following models:
> ---
> Models
> --
>
> class Profile(models.Model):
>     profile_id = models.AutoField(primary_key=True)
>     profile_name = models.CharField(max_length=75)
>     description = models.CharField(max_length=1500, blank=True)
>     def __unicode__(self):
>                         return self.profile_name
>     class Meta:
>         db_table = u'profile'
>
> class Testcase(models.Model):
>     test_id = models.AutoField(primary_key=True)
>     test_name = models.CharField(max_length=300)
>     src = models.ForeignKey(Source, null=True, blank=True)
>     bitrate = models.IntegerField(null=True, blank=True)
>     test_type = models.CharField(max_length=300)
>     output_resolution = models.CharField(max_length=15, blank=True)
>     description = models.CharField(max_length=3000, blank=True)
>     ref_file = models.CharField(max_length=765, blank=True)
>     ref_encode_filesize = models.IntegerField(null=True, blank=True)
>     ref_y_psnr = models.DecimalField(null=True, max_digits=7,
> decimal_places=2, blank=True)
>     ref_u_psnr = models.DecimalField(null=True, max_digits=7,
> decimal_places=2, blank=True)
>     ref_v_psnr = models.DecimalField(null=True, max_digits=7,
> decimal_places=2, blank=True)
>     ref_yuv_psnr = models.DecimalField(null=True, max_digits=7,
> decimal_places=2, blank=True)
>     highmark_version = models.CharField(max_length=60, blank=True)
>     def __unicode__(self):
>                 return self.test_name
>     class Meta:
>         db_table = u'testcase'
>
> class Testsuite(models.Model):
>     testsuite_id = models.AutoField(primary_key=True)
>     profile = models.ForeignKey(Profile, related_name='profile')
>     test = models.ForeignKey(Testcase, related_name='test')
>     #def __unicode__(self):
>                         #                       return
> self.testsuite_id
>     def __unicode__(self):
>                return '%s,%s' % (self.profile, self.test)
>     class Meta:
>         db_table = u'testsuite'

--

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




Re: custom backend causes this error: authenticate() takes exactly 0 arguments (2 given)

2009-11-24 Thread Gloria
Environment:

Request Method: POST
Request URL: http://localhost:8000/login/
Django Version: 1.1.1
Python Version: 2.6.0
Installed Applications:
['attachments',
 'avatar',
 'soaplib',
 'notification',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.admin',
 'django.contrib.flatpages',
 'django.contrib.redirects',
 'django.contrib.humanize',
 'django.contrib.comments',
 'django_extensions',
 'ajax_validation',
 'djangoratings',
 'debug_toolbar',
 'solango',
 'voting',
 'tagging',
 'compress',
 'opencrowd.django.apps.portal_layout',
 'mailer',
 'pg_logging.singleton_logger',
 'pg.ip.misc',
 'pg.ip.taxo',
 'pg.ip.search',
 'pg.ip.client',
 'pg.ip.profile',
 'pg.ip.community',
 'pg.ip.activity',
 'pg.ip.performance',
 'pg.ip.comments']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 
'opencrowd.django.apps.portal_layout.middleware.PageLayoutFallbackMiddleware')


Traceback:
File "/usr/lib/python2.6/site-packages/Django-1.1.1-py2.6.egg/django/
core/handlers/base.py" in get_response
  92. response = callback(request, *callback_args,
**callback_kwargs)
File "/mnt/XP_D/Opencrowd/PressGaney/pg_trunk/main/pg/ip/profile/
views.py" in local_login
  82.   user = authenticate(user_name)

Exception Type: TypeError at /login/
Exception Value: authenticate() takes exactly 0 arguments (1 given)

Thanks,
Gloria

--

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-24 Thread Preston Holmes


On Nov 24, 1:28 am, Elyrwen  wrote:
> Hello,
>
> I' ve been recently interested in Djagno framework and I am at the
> point of choosing it as the framework for my project. My application
> will not use database, but will use webservices to get data and then
> process it.
>
> I need a substitute for the Django model layer. Precisely I need a
> class that would parse a wsdl (this I am doing with suds) and then
> call the remote methods. There should be one instance of this class
> served by all requests to
> avoid parsing wsdl for evey request - sort of a singleton class that
> would keep parsed stubs. It is possible to place such shared class in
> Django? Can you point me to some solutions that avoid parsing wsdl
> with each new request?

Is there a reason your app can not use a database?

Depending on how often your wsdl data changes, you could map a
response to a django model object and then check to see if it exists
(essentially using the ORM as a wsdl cache).  Or you could use
Django's cache framework itself:

http://docs.djangoproject.com/en/1.1/topics/cache/#the-low-level-cache-api

The former would let you have more class like access to the data (with
methods etc), while the latter is more pure key/value.

-Preston

>
> Maybe there is yet another way to obtain it with Django?
>
> Best regards,
> PS

--

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




Re: custom backend causes this error: authenticate() takes exactly 0 arguments (2 given)

2009-11-24 Thread Tom Evans
What does the traceback look like?

Cheers

Tom

--

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




Re: Alternative model without Database

2009-11-24 Thread Christophe Pettus

On Nov 24, 2009, at 1:28 AM, Elyrwen wrote:

> My application
> will not use database, but will use webservices to get data and then
> process it.

It can be challenging to excise all of the uses of the database from a  
Django application.  Since you'll be caching the results of your web  
services operations locally, perhaps cache them in a local database,  
such as SQLite?  You could, then, subclass Model in such a way as to  
populate the cache on demand.

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




Configure multi-field multi-select form in Django Admin

2009-11-24 Thread rc
What I want to do is have a form with one field that allows you to
select a profile. Once this profile is selected there will be two
windows below that show available tests and selected tests. The Django
admin interface for the user permissions uses this format. Not sure
what it is called in Django.

My current models are listed below. I have a joining table called
Testsuite that joins tests to profiles. It works now, but the admin is
not very easy to add or remove tests to a testsuite since you have to
add one at a time. If someone can point me in the right direction I
would appreciate it.


Anyway I have the following models:
---
Models
--

class Profile(models.Model):
profile_id = models.AutoField(primary_key=True)
profile_name = models.CharField(max_length=75)
description = models.CharField(max_length=1500, blank=True)
def __unicode__(self):
return self.profile_name
class Meta:
db_table = u'profile'

class Testcase(models.Model):
test_id = models.AutoField(primary_key=True)
test_name = models.CharField(max_length=300)
src = models.ForeignKey(Source, null=True, blank=True)
bitrate = models.IntegerField(null=True, blank=True)
test_type = models.CharField(max_length=300)
output_resolution = models.CharField(max_length=15, blank=True)
description = models.CharField(max_length=3000, blank=True)
ref_file = models.CharField(max_length=765, blank=True)
ref_encode_filesize = models.IntegerField(null=True, blank=True)
ref_y_psnr = models.DecimalField(null=True, max_digits=7,
decimal_places=2, blank=True)
ref_u_psnr = models.DecimalField(null=True, max_digits=7,
decimal_places=2, blank=True)
ref_v_psnr = models.DecimalField(null=True, max_digits=7,
decimal_places=2, blank=True)
ref_yuv_psnr = models.DecimalField(null=True, max_digits=7,
decimal_places=2, blank=True)
highmark_version = models.CharField(max_length=60, blank=True)
def __unicode__(self):
return self.test_name
class Meta:
db_table = u'testcase'

class Testsuite(models.Model):
testsuite_id = models.AutoField(primary_key=True)
profile = models.ForeignKey(Profile, related_name='profile')
test = models.ForeignKey(Testcase, related_name='test')
#def __unicode__(self):
#   return
self.testsuite_id
def __unicode__(self):
   return '%s,%s' % (self.profile, self.test)
class Meta:
db_table = u'testsuite'

--

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




Re: custom backend causes this error: authenticate() takes exactly 0 arguments (2 given)

2009-11-24 Thread Gloria
Aye, there's the rub. My authenticate takes at least one parameter:

from django.conf import settings
from django.contrib.auth.models import User
from django.contrib.auth.backends import ModelBackend

class AuthBackend(ModelBackend):
"""
Custom authentication: No password, because of SOAP
passthrough.
"""
def authenticate(self, username, password=None):
try:
user = User.objects.get(username=username)
if not user:
# Create a new user. Note that we can
set password
# to anything, because it won't be
checked; the password
# from settings.py will.
user = User(username=username,
password="default")
user.is_staff = False
user.is_superuser = False
user.save()

return user

except:
#except User.DoesNotExist:
# Create a new user. Note that we can set
password
# to anything, because it won't be checked;
the password
# from settings.py will.
user = User(username=username,
password="default")
user.is_staff = False
user.is_superuser = False
user.save()
return user


def get_user(self, user_id):
try:
return User.objects.get(pk=user_id)
except User.DoesNotExist:
return 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.




Re: custom backend causes this error: authenticate() takes exactly 0 arguments (2 given)

2009-11-24 Thread Tom Evans
On Tue, Nov 24, 2009 at 4:40 PM, Gloria  wrote:

> Hi all,
>
> I am using the SettingsBackend sample code, from here:
>
>
> http://docs.djangoproject.com/en/dev/topics/auth/#django.contrib.auth.authenticate
>
> in Django 1.1.1, python 2.6, and I get this error:
>
> TypeError at /login/
> authenticate() takes exactly 0 arguments (2 given)
>
> I've tried making SettingsBackend inherit from ModelBackend (which is
> what I really want), but this does not change the behavior.
>
> Thanks in advance,
> Gloria
>
>
Sounds like you have overridden the correct authenticate() function with one
that takes no arguments - hard to tell without seeing any code!

Do you have any methods, files etc called 'authenticate'?

Cheers

Tom

--

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




custom backend causes this error: authenticate() takes exactly 0 arguments (2 given)

2009-11-24 Thread Gloria
Hi all,

I am using the SettingsBackend sample code, from here:

http://docs.djangoproject.com/en/dev/topics/auth/#django.contrib.auth.authenticate

in Django 1.1.1, python 2.6, and I get this error:

TypeError at /login/
authenticate() takes exactly 0 arguments (2 given)

I've tried making SettingsBackend inherit from ModelBackend (which is
what I really want), but this does not change the behavior.

Thanks in advance,
Gloria

--

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 test a signal that recived request and user objects?

2009-11-24 Thread Viktor
hi,

I would like to write a signal handler that logs the user in when its
account gets activated.

My signal handler is registered with user_activated from django-
registration, and my initial guess was this:

def log_user_in(sender, **kwargs):
login(kwargs['request'], kwargs['user'])
user_activated.connect(log_user_in)

but some reason, this won't work. Could someone give me a hint on how
to debug this? As I prefer writing unit tests, the best would be an
example of how can I create a request object to call the above method.

thanks
V

--

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-24 Thread David De La Harpe Golden
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?
> 


There's a patch in the django tracker that adds support to help
integrate your own per-object permission handling auth backends  (it
does not in itself constitute per-object permissions):
http://code.djangoproject.com/ticket/11010

I haven't fully worked out how to do integration of our own
(unreleased*) object permission system  even given that patch,
though it would presumably be am  improvement as it would
enable us to use the django admin more (once the admin is
appropriately updated to pass through the object to the revised
auth backend I suppose).

* Maybe I could/should look into getting it released.  We maintain a
D.A.G. where vertices are permissions,roles and users. If a path exists
in the graph (fastish query with the transitive closure representation
used, at least for non-pathological graphs) from a permission to a user
through one or more roles, the user is considered to have that permission.
permissions are action() or action(obj1) or action(obj1,obj2)

Taking your example, in our system, each project would have its own
projectmanager role created, granted the permission to edit the project.

e.g.

perms_all_mgrs_have===>role:project_mgr # just for e.g.
   |
   v
perm:edit(project1) ---> role:project1_mgr ---> user:user1


Thus, user1 is project manager of project1.

























--

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-24 Thread rebus_
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?
>>
>> --
>> 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.
>
>
>
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

--

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




Re: newbie questions regarding models and admin

2009-11-24 Thread nek4life
The philosophy of the admin app is that it is a simple CRUD interface
for trusted staff members to manage data.  If you need data entry for
non staff members (i.e. people you do not trust with the admin) you
should create public facing forms and setup some permissions for the
users to be able to use them.

As for you second question it sounds like you need two models, one for
experiment_x and one for sub_experiment_x with a foreignkey to
experiment_x.  You could probably use inline formsets to generate the
extra 8 forms.  I'm not sure how you would limit the inline formsets
though to exactly 8.

Hope this helps.

On Nov 24, 5:33 am, Andreas Kuntzagk 
wrote:
> Hi,
>
> I'm quite new to django and very new to this list.
> I'm in the process of writing a small webapp for our lab.
> Working with the tutorial I already put together a small model and some
> admin pages.
> But now I came to some stumbling blocks:
>
> First is a broader question: I'm wondering what belongs to an admin page
>   and what should be in a "normal" form. I want to keep track on some
> experiments so some (authenticated) users should create experiment
> entries and add comments etc. And then I have "machines" where these
> experiments run. These don't change so often. So does setting these
> things belong into the admin area?
>
> Second experiments of type x always consist of 8 parallel
> subexperiments. How do I model this? These subexperiments should
> (automagically) be named subexp1 to subexp8.
>
> Regards, Andreas

--

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-24 Thread 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?
>
> --
> 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.




Re: even and odd numbers within a template

2009-11-24 Thread Colin Copeland
Juan,

The "cycle" template tag may help you here:

http://docs.djangoproject.com/en/dev/ref/templates/builtins/#cycle

  colin

On Nov 24, 2009, at 8:39 AM, Juan Hernandez wrote:

> Hey there people...
> 
> I've been coloring html tables using javascript for a while and now, we need 
> to color our tables just with html. The CSS has been made to use one color 
> for even rows and another one for odds. How can I know if a current template 
> loop is odd or even? I've been trying many different things and none of them 
> work
> 
> Thanx
> jhv
> 
> --
> 
> 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.

-- 
Colin Copeland
Caktus Consulting Group, LLC
P.O. Box 1454
Carrboro, NC 27510
(919) 951-0052
http://www.caktusgroup.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.




Creating dynamic models?

2009-11-24 Thread Kevin Renskers
Hi all,

In my Django project I want to have a model that is dynamically
created. I tried using the __init__ function for this,  something like
so:

fields = ['field_a', 'field_b', 'field_c']

class MyModel(models.Model):
def __init__(self, *args, **kwargs):
for field in fields:
setattr(self, field, models.DecimalField(decimal_places=4,
max_digits=10))

Sadly, this doesn't work. The columns don't get created when you run
the syncdb command, and even something like
MyModel._meta.get_all_field_names() doesn't return the dynamic fields.

So, is there a way I can create a "dynamic" model? I did come across
http://code.djangoproject.com/wiki/DynamicModels but I don't really
get that. It looks so much different then normal models, it seems like
I would loose a lot of functionality or would have to change a lot of
code somewhere else in my application?

Hopefully there is an easy way to do this :)

Cheers,
Kevin

--

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.




even and odd numbers within a template

2009-11-24 Thread Juan Hernandez
Hey there people...

I've been coloring html tables using javascript for a while and now, we need
to color our tables just with html. The CSS has been made to use one color
for even rows and another one for odds. How can I know if a current template
loop is odd or even? I've been trying many different things and none of them
work

Thanx
jhv

--

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-24 Thread Jani Tiainen
Most promising solution I've seen is django-authority.



I haven't (yet) used it but I'm planning to do that at some point.

Quick peek revealed that branch you mentioned is a quite outdated, last
update is "only" two and half years old..

On Tue, 2009-11-24 at 14:00 +0200, 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?
> 
> -- 
> 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.


--

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.




Per-object permissions

2009-11-24 Thread gamliel roi
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?

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




Weird en_gb locale problem

2009-11-24 Thread tawny

I have two servers which look  identical. However, one runs the Django
test page with en_gb  the other doesn't. What is even more strange is
everything was running as expected a few months back. I upgraded
Django to 1.1.1 and using en_gb no longer works. I tried going back to
the previous Django version but it makes no difference.

Any suggestions as to how I can analyse this problem would be
appreciated.

These are the steps I am taking:

django-admin.py startproject testtest
...
python2.5 manage.py runserver 0.0.0.0:8800
It worked!

Change en_us to en_gb

Validating models...
0 errors found

Django version 1.1.1, using settings 'testtest.settings'
Development server is running at http://0.0.0.0:8800/
Quit the server with CONTROL-C.
Unhandled exception in thread started by 
Traceback (most recent call last):
  File "/usr/lib/python2.5/site-packages/django/core/management/
commands/runserver.py", line 56, in inner_run
translation.activate(settings.LANGUAGE_CODE)
  File "/usr/lib/python2.5/site-packages/django/utils/translation/
__init__.py", line 73, in activate
return real_activate(language)
  File "/usr/lib/python2.5/site-packages/django/utils/translation/
trans_real.py", line 205, in activate
_active[currentThread()] = translation(language)
  File "/usr/lib/python2.5/site-packages/django/utils/translation/
trans_real.py", line 194, in translation
default_translation = _fetch(settings.LANGUAGE_CODE)
  File "/usr/lib/python2.5/site-packages/django/utils/translation/
trans_real.py", line 160, in _fetch
res._info = res._info.copy()
AttributeError: 'NoneType' object has no attribute '_info'

Django 1.1.1 Python 2.5.2 Debian Lenny
The only installed locale is en_GB.UTF-8 (although I have tried
en_US.UTF-8 too).

LANG=en_GB.UTF-8
LC_CTYPE="en_GB.UTF-8"
LC_NUMERIC="en_GB.UTF-8"
LC_TIME="en_GB.UTF-8"
LC_COLLATE="en_GB.UTF-8"
LC_MONETARY="en_GB.UTF-8"
LC_MESSAGES="en_GB.UTF-8"
LC_PAPER="en_GB.UTF-8"
LC_NAME="en_GB.UTF-8"
LC_ADDRESS="en_GB.UTF-8"
LC_TELEPHONE="en_GB.UTF-8"
LC_MEASUREMENT="en_GB.UTF-8"
LC_IDENTIFICATION="en_GB.UTF-8"
LC_ALL=

>>> import locale
>>> locale.getdefaultlocale()
>>> ('en_GB', 'UTF8')

ls -l /usr/lib/python2.5/site-packages/django/conf/locale/en/
LC_MESSAGES
total 96
-rw-r- 1 root root   358 2008-09-03 06:42 djangojs.mo
-rw-r- 1 root root  2693 2008-09-03 06:42 djangojs.po
-rw-r- 1 root root   572 2008-09-03 06:42 django.mo
-rw-r- 1 root root 81056 2008-09-03 06:42 django.po

--

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-24 Thread greatlemer
> > 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 
> > athttp://groups.google.com/group/django-users?hl=en.
>
> How about this?
>
> path = request.path
> url = request.build_absolute_uri(path)
> resolver = get_resolver(None)
> view_func, url_args, url_kwargs = resolver.resolve(path)
> sigs = resolver.reverse_dict.getlist(view_func)
> url_name = None
>
> # Loop through all the items in the reverse dictionary.
> for key, value in resolver.reverse_dict.items():
>   # Check if the value of the mapping is one of our matching signatures and
>   # that the key is a string.
>     if value in sigs and type(key) == str:
>         try:
>             # See if we have the right parameters to use this reversal and 
> that
>             # it produces the correct url.
>             if resolver.reverse(key, *url_args, **url_kwargs) == path[1:]:
>                 # No exceptions were thrown so we have the right parameters 
> and
>                 # the path matched therefore we've found the url name we were
>                 # seeking - which of course means we can stop looking.
>                 url_name = key
>                 break
>         except NoReverseMatch, e:
>             # The parameters were wrong - ah well, maybe the next one will
>             # succeed.
>             pass
> print url, url_name, url_kwargs
>
> This is taken from the greatlemers-django-tools [1]. It seems like
> lots of code, guess you could use it as middleware or
> context_processor.
> It should return something like:http://127.0.0.1:8000/home/home {}
> where "home" is url name
>
> [1]http://code.google.com/p/greatlemers-django-tools/source/browse/trunk...
>
> Hope this helps
> Davor


It would have made things a whole lot easier if the resolver would
return the url name, but that piece of code should do what you're
after.  Since all you get back is a view function the second part that
iterates over the reverse_dict is necessary to ensure that you
retrieve the name of the actual reversed url and not an alternative
one that uses the same view (probably with different parameters).

--

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-24 Thread rebus_
2009/11/24 bcurtu :
> 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.
>
>
>

How about this?

path = request.path
url = request.build_absolute_uri(path)
resolver = get_resolver(None)
view_func, url_args, url_kwargs = resolver.resolve(path)
sigs = resolver.reverse_dict.getlist(view_func)
url_name = None

# Loop through all the items in the reverse dictionary.
for key, value in resolver.reverse_dict.items():
  # Check if the value of the mapping is one of our matching signatures and
  # that the key is a string.
if value in sigs and type(key) == str:
try:
# See if we have the right parameters to use this reversal and that
# it produces the correct url.
if resolver.reverse(key, *url_args, **url_kwargs) == path[1:]:
# No exceptions were thrown so we have the right parameters and
# the path matched therefore we've found the url name we were
# seeking - which of course means we can stop looking.
url_name = key
break
except NoReverseMatch, e:
# The parameters were wrong - ah well, maybe the next one will
# succeed.
pass
print url, url_name, url_kwargs

This is taken from the greatlemers-django-tools [1]. It seems like
lots of code, guess you could use it as middleware or
context_processor.
It should return something like: http://127.0.0.1:8000/home/ home {}
where "home" is url name

[1] 
http://code.google.com/p/greatlemers-django-tools/source/browse/trunk/gdt_nav/models.py#158

Hope this helps
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: Problem with unmanaged models and unit testing

2009-11-24 Thread Tomasz Zieliński
Thank you for you responses, I think I spotted the problem.

My unmanaged model is in fact wrapper for database view.
It also inherits from Django abstract model that has ManyToManyField-s
onboard.

When trying to test my app, syncdb.py in line 93 tries to actually add
foreign key
pointing from m2m intermediate table to unmanaged model's table, which
of course
doesn't exist (in my regular app db views are pre-created manually).

BTW string ' #sql-710_139' doesn't appear in sql statement that causes
mentioned error,
the statement is perfectly ok.

--
Tomasz Zielinski
http://pyconsultant.eu

--

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: Application auth and storing user in request.

2009-11-24 Thread Piotr Czachur


On 24 Lis, 10:05, Piotr Czachur  wrote:
> Hi!
>
> Why in auth middleware, user is assigned to request.__class__.user,
> but in auth context processor it's read from request.user ? Isn't it
> inconsistent?

I've found answer here: answer
http://stackoverflow.com/questions/766733/some-internals-of-django-auth-middleware
Q: Please avdise me why such a form request._ class _.user = LazyUser
() used? Why not just request.user = LazyUser() ?
A: LazyUser is descriptor-class. According to documentation it can be
only class attribute not instance one.

--

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




newbie questions regarding models and admin

2009-11-24 Thread Andreas Kuntzagk
Hi,

I'm quite new to django and very new to this list.
I'm in the process of writing a small webapp for our lab.
Working with the tutorial I already put together a small model and some 
admin pages.
But now I came to some stumbling blocks:

First is a broader question: I'm wondering what belongs to an admin page 
  and what should be in a "normal" form. I want to keep track on some 
experiments so some (authenticated) users should create experiment 
entries and add comments etc. And then I have "machines" where these 
experiments run. These don't change so often. So does setting these 
things belong into the admin area?

Second experiments of type x always consist of 8 parallel 
subexperiments. How do I model this? These subexperiments should 
(automagically) be named subexp1 to subexp8.

Regards, Andreas

--

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.




german umlaute on search querys

2009-11-24 Thread Hinnack
Hi,

I have django 1.1 and a mysql database created in utf-8.
My tables are also utf8 as the collation is, too.

Showing data in a view works pretty well with german umlaute, but doing
a search with filter and icontains always returns an empty queryset...

if I convert the search back to iso-8859 I get results...

what am I doing wrong?

-- Hinnack

--

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: Avoiding MIME_BASE64_TEXT SpamAssassin Test when sending Email From Django?

2009-11-24 Thread rmschne
Jerek,

Thanks ...  starting now.

--

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-24 Thread bcurtu
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.




  1   2   >