Re: staticfiles ManifestStaticFilesStorage and Form Media

2015-12-07 Thread Brian Neal

Thank you Denis. I will keep my eye on this ticket: 
https://code.djangoproject.com/ticket/21221

Best,
BN

On Monday, December 7, 2015 at 12:42:23 AM UTC-6, Denis Cornehl wrote:
>
> Hi Brian, 
>
> a sidenote, this will be fixed: 
> https://github.com/django/django/pull/5571
>
> -- 
> Denis
>
> Am Sonntag, 6. Dezember 2015 um 17:17 schrieb Brian Neal:
>
> I'm investigating using staticfiles ManifestStaticFilesStorage. Unless I'm 
> missing something, there seems to be a hole with Django forms Media class. 
> If you use an inner Media class you do not get the hashed versions of the 
> assets filenames. 
>
> This leads me to believe you can't use the Forms Media technique with 
> ManifestStaticFilesStorage. 
>
> I noticed there was an undocumented function called static in 
> staticfiles.templatetags.staticfiles. I tried calling this function inside 
> my inner Media classes to make it return the hashed version of the files, 
> and this does work as long as collectstatic has been run. But if you have 
> an empty STATIC_DIR, you can't even call the management command to run 
> collectstatic as it tries to resolve these Media classes at import time. So 
> it seems to be a chicken and egg problem. A possible work around was found 
> on stackoverflow to delay the evaluation of the Media classes: 
> http://stackoverflow.com/questions/28366281/django-cachedstaticfilesstorage-in-modeladmin-media
>
> So it seems I have a couple of options:
>
> 1) Give up on form Media classes and explicitly use {% static %} in my 
> templates instead of {% form.media %}
> 2) Defer the resolution of {% form.media %} using the stackoverflow trick
>
> Since I'm not doing any dynamic decision making in my views about what 
> forms to use (yet), I always know what static files I need in my templates 
> to support my forms, so I'm leaning toward option 1. But just wanted to 
> bounce this off the community in case I am missing something.
>
> Thanks.
>
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users...@googlegroups.com .
> To post to this group, send email to django...@googlegroups.com 
> .
> Visit this group at http://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/39a230f1-3025-4964-b543-b7d48a0798ab%40googlegroups.com
>  
> <https://groups.google.com/d/msgid/django-users/39a230f1-3025-4964-b543-b7d48a0798ab%40googlegroups.com?utm_medium=email_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
>
>

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


staticfiles ManifestStaticFilesStorage and Form Media

2015-12-06 Thread Brian Neal
I'm investigating using staticfiles ManifestStaticFilesStorage. Unless I'm 
missing something, there seems to be a hole with Django forms Media class. 
If you use an inner Media class you do not get the hashed versions of the 
assets filenames. 

This leads me to believe you can't use the Forms Media technique with 
ManifestStaticFilesStorage. 

I noticed there was an undocumented function called static in 
staticfiles.templatetags.staticfiles. I tried calling this function inside 
my inner Media classes to make it return the hashed version of the files, 
and this does work as long as collectstatic has been run. But if you have 
an empty STATIC_DIR, you can't even call the management command to run 
collectstatic as it tries to resolve these Media classes at import time. So 
it seems to be a chicken and egg problem. A possible work around was found 
on stackoverflow to delay the evaluation of the Media 
classes: 
http://stackoverflow.com/questions/28366281/django-cachedstaticfilesstorage-in-modeladmin-media

So it seems I have a couple of options:

1) Give up on form Media classes and explicitly use {% static %} in my 
templates instead of {% form.media %}
2) Defer the resolution of {% form.media %} using the stackoverflow trick

Since I'm not doing any dynamic decision making in my views about what 
forms to use (yet), I always know what static files I need in my templates 
to support my forms, so I'm leaning toward option 1. But just wanted to 
bounce this off the community in case I am missing something.

Thanks.

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


Guide for migrating to a custom user model?

2013-04-17 Thread Brian Neal
Hello -

I have a Django site that I've been maintaining for 4 years. It is running 
Django 1.4 now and is using the usual Django User model plus the 
get_profile() method to retrieve some extra information for each user. Now 
that Django 1.5 has landed and we can substitute our own custom user model 
[1], I'm weighing my options for going forward. The get_profile() stuff is 
now deprecated and will go away in Django 1.7 [2]. I'm trying to decide if 
I should just keep my profile model around and do the joins [3], or 
substitute my own model. 

I'm wondering if there is a guide somewhere on how to do a migration to a 
custom user model? In a few places people recommend South, but I have no 
experience with South. Is it time to learn, or is it overkill? Or can I 
just write my own script to fix things up? Then I have to go through all my 
apps and refactor the user.get_profile() calls, right? And all those FK's 
to Django's User model will have to be changed?

I was hoping there was a guide or some blog posts about how to do this but 
I haven't seen anything other than a few stackoverflow questions.

Thanks,
-BN


[1]: 
https://docs.djangoproject.com/en/1.5/topics/auth/customizing/#substituting-a-custom-user-model
[2]: https://docs.djangoproject.com/en/1.5/internals/deprecation/#id4
[3]: 
https://docs.djangoproject.com/en/1.5/topics/auth/customizing/#extending-the-existing-user-model


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




Re: ANNOUNCE: Django 1.4 released

2012-03-24 Thread Brian Neal
On Friday, March 23, 2012 12:11:22 PM UTC-5, James Bennett wrote:
>
> Django 1.4 is finally here!
>
> For details, checkout the weblog:
>
> https://www.djangoproject.com/​weblog/2012/mar/23/14/
>
> And the release notes:
>
> https://docs.djangoproject.​com/en/dev/releases/1.4/
>

Great! Congratulations!

Now might be a good time to consider making a donation to the Django 
Software Foundation to show appreciation:

https://www.djangoproject.com/foundation/donate/

-BN

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



Re: CACHE_MIDDLEWARE_ANONYMOUS_ONLY isn't working for me

2011-12-29 Thread Brian Neal
I did some more experimenting. Perhaps I misunderstood the purpose of
CACHE_MIDDLEWARE_ANONYMOUS_ONLY.

The view in my example below is a simple generic list view, and it did
not interrogate request.user or make any
request.user.is_authenticated() type checks. If I add those checks to
the template, then after I change a model in the admin, I see the view
update with those changes when I am logged in. Unfortunately it also
updates even when I'm not logged in (testing with a 2nd browser).

So unless I am missing something, the usefulness of
CACHE_MIDDLEWARE_ANONYMOUS_ONLY is much more limited than I thought.


On Dec 28, 10:25 am, Brian Neal <bgn...@gmail.com> wrote:
> I have CACHE_MIDDLEWARE_ANONYMOUS_ONLY = True. It seems to cache pages
> even for people who have logged in. For example, I can log into the
> admin, and edit an object. If I then visit the view for that app, my
> changes do not get seen until the 5 minute cache timeout hits.
>
> I suspect my middleware order is not correct, but I have read and re-
> read the docs and I'm still confused.
>
> Here are my cache related settings:
>
> CACHES = {
>     'default': {
>         'BACKEND':
> 'django.core.cache.backends.memcached.MemcachedCache',
>         'LOCATION': '127.0.0.1:11211',
>         'TIMEOUT': 600,
>     },
>
> }
>
> CACHE_MIDDLEWARE_ALIAS = 'default'
> CACHE_MIDDLEWARE_SECONDS = 600
> CACHE_MIDDLEWARE_KEY_PREFIX = 'BNS'
> CACHE_MIDDLEWARE_ANONYMOUS_ONLY = True
>
> MIDDLEWARE_CLASSES.insert(0,
> 'django.middleware.cache.UpdateCacheMiddleware')
> MIDDLEWARE_CLASSES.append('django.middleware.cache.FetchFromCacheMiddleware ')
>
> Does anyone see anything wrong or have suggestions on how to debug
> this?
>
> Thanks,
> BN

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



Re: YouTube Integration

2011-12-28 Thread Brian Neal
On Dec 28, 11:46 am, Hassan  wrote:
> Dear All,
>
> I want to know if there is a way that i can get youtube videos to my
> website using a video url ?
>
> Best Regards ,
>
> Hassan AL-Natour

Have you seen the oEmbed specification?
http://oembed.com/

I believe there is a Django application that incorporates this, but it
isn't hard to roll yourself either.

https://github.com/ericflo/django-oembed

Best,
BN

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



CACHE_MIDDLEWARE_ANONYMOUS_ONLY isn't working for me

2011-12-28 Thread Brian Neal
I have CACHE_MIDDLEWARE_ANONYMOUS_ONLY = True. It seems to cache pages
even for people who have logged in. For example, I can log into the
admin, and edit an object. If I then visit the view for that app, my
changes do not get seen until the 5 minute cache timeout hits.

I suspect my middleware order is not correct, but I have read and re-
read the docs and I'm still confused.

Here are my cache related settings:

CACHES = {
'default': {
'BACKEND':
'django.core.cache.backends.memcached.MemcachedCache',
'LOCATION': '127.0.0.1:11211',
'TIMEOUT': 600,
},
}

CACHE_MIDDLEWARE_ALIAS = 'default'
CACHE_MIDDLEWARE_SECONDS = 600
CACHE_MIDDLEWARE_KEY_PREFIX = 'BNS'
CACHE_MIDDLEWARE_ANONYMOUS_ONLY = True

MIDDLEWARE_CLASSES.insert(0,
'django.middleware.cache.UpdateCacheMiddleware')
MIDDLEWARE_CLASSES.append('django.middleware.cache.FetchFromCacheMiddleware')

Does anyone see anything wrong or have suggestions on how to debug
this?

Thanks,
BN

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



Re: how to create a hidden field

2011-08-02 Thread Brian Neal
On Aug 2, 3:14 pm, webcomm  wrote:
> ...
> Non-interactively, in the automatic admin, what I get is a visible
> text input below the title field and above the summary field.  Here's
> the relevant model and modelform:http://pastebin.com/azKgdraw
>
> -Ryan

Oh...you are trying to do this in the *admin*? Are you sure you just
don't need to "exclude" the form field?

https://docs.djangoproject.com/en/1.3/ref/contrib/admin/#django.contrib.admin.ModelAdmin.exclude

If you really want the admin to use your custom form you have to tell
it to:

https://docs.djangoproject.com/en/1.3/ref/contrib/admin/#django.contrib.admin.ModelAdmin.form

Best,
BN

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



Re: throttling login attempts to avoid brute force attacks

2011-07-09 Thread Brian Neal
On Jul 8, 11:03 am, Shawn Milochik  wrote:
> This topic came up on the list a few months back, and I just wanted to
> share the solution I've put into place.
>
> Short version:
>
> 1. Ensure that my Web server (nginx) passes the user's real IP address
> in the request.
>
> 2. For POST requests to the login URL only (to avoid any performance
> side-effects), keep a rolling count of number of requests by the IP in
> the past five minutes and use that to limit the number of attempts.
> Return HttpResponseForbidden with a message about too many log in attempts.
>
> Justification:
>
>      I'm using IP instead of user because this prevents an attacker from
> inconveniencing a legit user or getting a "fresh start" just by guessing
> a different username.
>
>      I'm throttling instead of locking the account (temporarily or
> permanently) to prevent attackers from locking out legitimate users.
>
> Details (implemented in middleware):
>
>      Middleware file creates an in-memory sqlite3 database.
>
>      All requests that aren't POSTs or to the login URL are ignored.
>
>      POST requests to the login URL cause these actions, in this order:
>          Get count of requests in last five minutes.
>          Return HttpResponseForbidden message if count is excessive.
>          Delete database entries greater than five minutes old.
>          Log this attempt.
>
> That's it. Pretty simple and effective. I hope others find it useful,
> and point out any flaws I may have missed.

Thanks for sharing your technique. I've been thinking about doing this
too. I was considering using Redis since I'm already using it for a
few other things and it has nice key expire functionality so it can do
the timeouts for you.

In addition to Simon W's solution, posted earlier, here are some other
related projects:

Instead of middleware, this one uses a decorator around any given URL.
It uses memcached, but it has a backend architecture so you could use
something else:

https://github.com/jsocol/django-ratelimit

This one also uses a decorator to wrap the contrib.auth login view,
but it also only flags POST requests that fail (don't redirect). It
seems a bit more heavy-weight since it is writing to the DB to do the
logging.

https://bitbucket.org/codekoala/django-axes

BN

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



Re: The import staticfiles_urlpatterns is not working in django 1.3

2011-04-21 Thread Brian Neal
On Apr 21, 12:48 pm, Guevara  wrote:
> Hello!
> My project is failing to import the staticfiles_urlpatterns, using
> Eclipse Helios:
>
> urls.py
>
> import from django.contrib.staticfiles.urls staticfiles_urlpatterns
>
> In django 1.3 I already have:
>
> INSTALLED_APPS = (
> 'django.contrib.staticfiles'
> )
>
> In the folder:
> / usr/local/lib/python2.6/dist-packages/django/contrib/staticfiles
>
> Why do not you think the staticfiles_urlpatterns?
>
> Thanks!

Please post your code and the exact error. For one thing, your import
statement isn't valid Python. It should be:

from django.contrib.staticfiles.urls import staticfiles_urlpatterns

Best,
BN

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



Re: base.html (extended by others) has to be in project (not app) root?

2011-04-15 Thread Brian Neal
On Apr 15, 2:23 pm, Jeff Blaine  wrote:
> Thank you all.  I will digest the replies when I have the time to properly
> focus back on the issue (it's obviously small, since I have a workaround in
> place by shoving base.html into the project root).
>
> It still, regardless of solutions, even in light of the words shared in this
> thread (which I've only skimmed for now), makes no sense to me how it's "the
> right thing" that my index.html is found but base.html cannot be found just
> because it is referenced by "extend".  I will have to decide for the
> time-being that there's some underlying good reason/concept that I just am
> not savvy to.
>
> You found index.html fine!  It says in it to extend "base.html"!  Find it in
> the same place you found index.html!

You didn't post how you loaded the template in your view function. In
particular, what path string you used.

In any event, this isn't magic. I suggest you read this section of the
docs:

http://docs.djangoproject.com/en/1.3/ref/templates/api/#loading-templates

In particular, pay attention to the TEMPLATE_DIRS and TEMPLATE_LOADERS
settings in your project. Those settings control the template search
order.

Best,
BN

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



Re: OPTIMISING OVERHEAD IN DJANGO WITH MYSQL DATABASE

2011-03-30 Thread Brian Neal
On Mar 30, 9:36 am, Dipo Elegbede  wrote:
> Hi all,
>
> I have a django application that uses mysql database.
>
> Everything works just fine except that I noticed some queries do spend a lot
> of time to load.
>
> I have about 15,000 checklists the system would have to browse through to
> render my dashboard, which indicates which checklists is totally complete or
> partial and all.
>
> I would love to know if there is a way to make these queries work faster.
>
> I have tried caching but that would be useful for as long no new data is
> hitting the database which is most unlikely, it also disable filters which
> are key part of the application.
>
> Is there a way to optimise mysql queries?
>
> kindly help.
>
> Documentations and explanations would be most appreciated.
>

Have you looked at the queries to see what they are? Do they make
sense? Are you using the django debug toolbar? Can you use
select_related()? Have you run "explain" on the queries? Have you seen
this:

http://docs.djangoproject.com/en/1.3/topics/db/optimization/

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



Re: Slow query on MySQL

2011-03-23 Thread Brian Neal
On Mar 23, 9:55 pm, Javier Guerra Giraldez <jav...@guerrag.com> wrote:
> On Wed, Mar 23, 2011 at 8:49 PM, Brian Neal <bgn...@gmail.com> wrote:
> > items = Post.objects(filter=forum__topic__in=forums).order_by('-
> > topic__update_date', '-update_date').select_related(# as before)[:30]
>
> > But this had the same result as before. I checked the resulting SQL,
> > and it looked right, so I did an explain and it was pretty much as
> > before. It decided not to use the index.
>
> bummer :-(
>
> > So I broke it up into two queries:
>
> > topic_ids = list(Topic.objects.filter(forum__in=forums).order_by(
> >        '-update_date').values_list('id', flat=True)[:30])
> > items = Post.objects.filter(topic__in=topic_ids).select_related(# as
> > before)[:30]
>
> did you try:
>
> items = 
> Post.objects.filter(topic__in=Topic.objects.filter(forum__in=forums).order_ 
> by('-update_date')[:30]).select_related(#
> as before)[:30]
>
> IOW: use the first queryset for the '__in' clause, no need to flatten
> to a list of IDs.  that allows the ORM to weave a subselect 
> (seehttp://docs.djangoproject.com/en/1.3/ref/models/querysets/#in).
> unfortunately, the docs also warn about the less-than-ideal MySQL
> optimizer, so in many cases it turns to be faster to do just like you
> did.  (i guess that specially in these limited-size queries).

I did try that. In fact, just remove the list() around the Topic query
from the code I posted above and that was what I tried first. I got a
DatabaseError with an elaborate message about how this type of nested
query or something wasn't supported by the version of MySQL I had.
Sorry I didn't save the exact error message.

Again, many thanks.
BN

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



Re: Slow query on MySQL

2011-03-23 Thread Brian Neal
On Mar 23, 1:47 pm, Javier Guerra Giraldez <jav...@guerrag.com> wrote:
> On Wed, Mar 23, 2011 at 1:35 PM, Brian Neal <bgn...@gmail.com> wrote:
> > So you are suggesting I need to shrink the number of topics or
> > possibly link the posts directly to the forum?
>
> right.  since you only want the 30 latest posts, scanning 12k topics
> is absurd.  i guess just ordering by (topic.update_date DESC,
> post_creationdate DESC) would allow the server to stop searching as
> soon as it has the required 30 posts.
>
> just be sure to have an index on topic.update_date
>

Hello again Javier,

I put an index on Topic.update_date. I then tried to change my Django
query to this:

items = Post.objects(filter=forum__topic__in=forums).order_by('-
topic__update_date', '-update_date').select_related(# as before)[:30]

But this had the same result as before. I checked the resulting SQL,
and it looked right, so I did an explain and it was pretty much as
before. It decided not to use the index.

So I broke it up into two queries:

topic_ids = list(Topic.objects.filter(forum__in=forums).order_by(
'-update_date').values_list('id', flat=True)[:30])
items = Post.objects.filter(topic__in=topic_ids).select_related(# as
before)[:30]

This was 2 queries, but it was blazingly fast compared to the
original. The performance should be fine for my application, and my
Munin graph of IOstat activity fell off dramatically.

If you have any ideas on how to get it down to one query, that would
be extra credit. As it is though, it's 2 orders of magnitude faster
than what it was. Thanks again for your insights into the problem! I
owe you one. :)

Best,
BN

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



Re: Django 1.3 released -- say thanks!

2011-03-23 Thread Brian Neal
On Mar 23, 8:58 am, Shawn Milochik  wrote:
> Everyone:
>
>     I just donated $25 to the Django Software Foundation. I would like
> to suggest that others who appreciate all the hard work chip in a
> couple of bucks if they are able. Especially those who, like me, want
> to express their gratitude but haven't yet contributed back to the
> community by helping with ticket triage and patches.
>
> http://www.djangoproject.com/foundation/
>
> Go Django! Thanks to the core devs and everyone who has helped to
> close a ticket!
>
> Shawn

An excellent idea. I just made a donation.

I also found a bug. :)  I got a 403 CSRF failure when Paypal sent me
to http://www.djangoproject.com/foundation/donate/thanks/

Thanks to the Django team and all the people who contributed.

-BN

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



Re: Slow query on MySQL

2011-03-23 Thread Brian Neal
On Mar 23, 12:59 pm, Javier Guerra Giraldez 
wrote:
> On Wed, Mar 23, 2011 at 12:56 PM, Javier Guerra Giraldez
>
>  wrote:
> > in this case the problem arises because of the big mismatch between
> > the forums_forum table (just 15 records) and the forums_topic table
> > (12k records)  that, and the need to sort by a field on another
> > (bigger) table: forums_post.created_date
>
> PS:  i concur that 7secs for 12k records is pretty bad; definitely
> it's doing the sort on disk and seems to have be using a badly chosen
> set of memory parameters.  still, optimizing the RAM usage for a bad
> case is a last resort.  I'd first be sure that it's not possible to
> optimize the query and _only_then_ try to optimize RAM layout to
> soften the hit

Yes, I think it is spilling out onto the disk. In my Munin graphs I
can definitely see a lot more IOStat activity since this query went
live.

BN

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



Re: Slow query on MySQL

2011-03-23 Thread Brian Neal
On Mar 23, 11:45 am, Javier Guerra Giraldez 
wrote:
>
> >http://dpaste.com/524865/
>
> ok, now it's obvious.
>
> the second query (the one with topic__forum__in=forums, right?) is
> scanning the whole topic table (12Krows).  it seems to be guessing
> that picking a significant fraction of a very small space (5 forums
> out of 15, right?) wouldn't be so much better using the index.
>
> the first query is using the topic->forum key, narrowing the loop to
> the ~1388 topics of the given forum.
>
> now, how to improve this?  it seems a little denormalization is in
> order.  i can thing of two different options:
>
> A: add a 'last_post_date' field to the topics table, and select only
> the most recent 10 or so topics.
>
> B: add a new post->forum relation, and maybe a (forum,post_date) index
>

Thank you very much for your insight Javiar. I've learned a lot here.
I will try to denormalize. I might already have such a field in the
topic model I could use. I have an "update_date" field in the topic
model that I denormalized for display purposes; it is just the date of
the last post in the topic. It isn't quite clear to me how to proceed
yet, but you've given me some things to think about.

So you are suggesting I need to shrink the number of topics or
possibly link the posts directly to the forum?

Thanks again,
BN

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



Re: Slow query on MySQL

2011-03-23 Thread Brian Neal
On Mar 23, 8:49 am, Javier Guerra Giraldez  wrote:
> are the EXPLAINs from these exact SQL queries?  i don't see why it
> cares about the forum_forum table, which isn't mentioned on the
> queries.

Sorry, my bad. I've been tweaking things in vain. Here are the correct
EXPLAINS.

http://dpaste.com/524865/

Thanks.

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



Re: Slow query on MySQL

2011-03-23 Thread Brian Neal
On Mar 22, 11:01 pm, Javier Guerra Giraldez <jav...@guerrag.com>
wrote:
> On Tue, Mar 22, 2011 at 10:42 PM, Brian Neal <bgn...@gmail.com> wrote:
> > This is what I came up with to reduce the long times I was
> > seeing (but it still is slow). This is probably going to get ugly in
> > email, maybe I should have dpasted it:
>
> ugliness is assumed in SQL :-)
>
> is there an index on Post.creation_date ?
>
> --
> Javier

Hi Javier. I have db_index=True on the creation_date field in Post.
Any other thoughts? Thanks.

BN

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



Re: Slow query on MySQL

2011-03-22 Thread Brian Neal
On Mar 22, 10:15 pm, Javier Guerra Giraldez <jav...@guerrag.com>
wrote:
> On Tue, Mar 22, 2011 at 10:06 PM, Brian Neal <bgn...@gmail.com> wrote:
> > I see. There are in fact only 15 forums. But why does it take 40
> > seconds? I can get much better results if I do a select on each forum
> > individually and combine them together in Python code. So in this case
> > 15 selects is far better than 1. Maybe that's an expected result in
> > some cases, but it sure surprised me.
>
> can you post the full SQL query?
>

Sure. This is what I came up with to reduce the long times I was
seeing (but it still is slow). This is probably going to get ugly in
email, maybe I should have dpasted it:

items = Post.objects.filter(topic__forum=8).order_by('-
creation_date').select_related('topic', 'user', 'topic_forum')[:30]

produces (time 0.289 seconds):

SELECT `forums_post`.`id`, `forums_post`.`topic_id`,
`forums_post`.`user_id`, `forums_post`.`creation_date`,
`forums_post`.`update_date`, `forums_post`.`body`,
`forums_post`.`html`, `forums_post`.`user_ip`, `forums_topic`.`id`,
`forums_topic`.`forum_id`, `forums_topic`.`name`,
`forums_topic`.`creation_date`, `forums_topic`.`user_id`,
`forums_topic`.`view_count`, `forums_topic`.`sticky`,
`forums_topic`.`locked`, `forums_topic`.`post_count`,
`forums_topic`.`update_date`, `forums_topic`.`last_post_id`,
`auth_user`.`id`, `auth_user`.`username`, `auth_user`.`first_name`,
`auth_user`.`last_name`, `auth_user`.`email`, `auth_user`.`password`,
`auth_user`.`is_staff`, `auth_user`.`is_active`,
`auth_user`.`is_superuser`, `auth_user`.`last_login`,
`auth_user`.`date_joined` FROM `forums_post` INNER JOIN `forums_topic`
ON (`forums_post`.`topic_id` = `forums_topic`.`id`) INNER JOIN
`auth_user` ON (`forums_post`.`user_id` = `auth_user`.`id`) WHERE
`forums_topic`.`forum_id` = 8  ORDER BY `forums_post`.`creation_date`
DESC LIMIT 30

This:
items = Post.objects.filter(topic__forum__in=forums).order_by('-
creation_date').select_related('topic', 'user', 'topic_forum')[:30]

produces (in 7.357 seconds)

SELECT `forums_post`.`id`, `forums_post`.`topic_id`,
`forums_post`.`user_id`, `forums_post`.`creation_date`,
`forums_post`.`update_date`, `forums_post`.`body`,
`forums_post`.`html`, `forums_post`.`user_ip`, `forums_topic`.`id`,
`forums_topic`.`forum_id`, `forums_topic`.`name`,
`forums_topic`.`creation_date`, `forums_topic`.`user_id`,
`forums_topic`.`view_count`, `forums_topic`.`sticky`,
`forums_topic`.`locked`, `forums_topic`.`post_count`,
`forums_topic`.`update_date`, `forums_topic`.`last_post_id`,
`auth_user`.`id`, `auth_user`.`username`, `auth_user`.`first_name`,
`auth_user`.`last_name`, `auth_user`.`email`, `auth_user`.`password`,
`auth_user`.`is_staff`, `auth_user`.`is_active`,
`auth_user`.`is_superuser`, `auth_user`.`last_login`,
`auth_user`.`date_joined` FROM `forums_post` INNER JOIN `forums_topic`
ON (`forums_post`.`topic_id` = `forums_topic`.`id`) INNER JOIN
`auth_user` ON (`forums_post`.`user_id` = `auth_user`.`id`) WHERE
`forums_topic`.`forum_id` IN (3, 4, 14, 2, 6, 9, 8, 10, 5, 7, 11, 12,
13, 16) ORDER BY `forums_post`.`creation_date` DESC LIMIT 30

Each Post has a foreign key to a Topic and each Topic has a foreign
key to a Forum.

I guessing all those INNER JOIN's are killing me here.

Thanks.

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



Re: Another problem with django static files

2011-03-22 Thread Brian Neal
On Mar 22, 9:58 pm, jim_rain  wrote:
> Brian -
>
> Thanks for the reply - I missed that step. But when I added it the
> behavior changed but still no joy. The form has text field in addition
> to the date picker - it looks like this:
>
> class JTestForm(forms.Form):
>     input          = forms.CharField(label='Please enter some input',
> max_length=100)
>     start_time =
> JqSplitDateTimeField(widget=JqSplitDateTimeWidget(attrs={'date_class':'date 
> picker','time_class':'timepicker'})),
>
> In my template I was outputting {{ form.as_p }}
>
> I would see the CharField but not the date picker. So I changed my
> template to {{ form.media }} then I don't see anything (neither
> field) .
>
> Also when I do that the out put from runserver changed to: "GET /myApp/
> jtest/ HTTP/1.1" 200 283
>
> Any other suggestions or ideas are very welcome as I'm pretty
> stumped.
>
> Jim

Well it is really hard to say without knowing what that javascript
does or seeing your code. The javascript might be error-ing out mid-
way through and leaving your HTML in a bad way.

Get it working first without the fancy javascript. Then add one thing
in at a time, it will be easier to debug that way.

Also, look in the debug server output for HTTP responses to requests
for the javascript and CSS assets. If you see 404 then you know
something isn't right with your static files setup. If you don't see
any requests for the javascript or CSS, you probably forgot to output
the  and 

Re: Slow query on MySQL

2011-03-22 Thread Brian Neal
On Mar 22, 9:56 pm, Javier Guerra Giraldez <jav...@guerrag.com> wrote:
> On Tue, Mar 22, 2011 at 9:49 PM, Brian Neal <bgn...@gmail.com> wrote:
> > I studied the SQL that Django generated and it seemed fine to me.
> > That's why I wonder if it is a MySQL issue since the EXPLAIN said it
> > had a possible key (PRIMARY) but then ended up not using it (bottom
> > one):
>
> that's because it saw so few rows (just 15) that it was cheaper to
> scan the whole thing instead of using the index
>

I see. There are in fact only 15 forums. But why does it take 40
seconds? I can get much better results if I do a select on each forum
individually and combine them together in Python code. So in this case
15 selects is far better than 1. Maybe that's an expected result in
some cases, but it sure surprised me.

Thank you for that, that helps a bit.

Best,
BN

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



Re: Slow query on MySQL

2011-03-22 Thread Brian Neal
On Mar 22, 8:17 pm, smallfish xy  wrote:
> hi, you can try split the in statement, with less with "in".
>
> forums = [1, 2, 3, 4, 5]
> r = []
> for f in forums :
>     r.append(Post.objects.filter(topic__forum=f.id)
> return r

That's what I did to work around it. I'd still like to know why it was
so excruciatingly slow.

>
> perhaps try to use the pure sql statement.

I studied the SQL that Django generated and it seemed fine to me.
That's why I wonder if it is a MySQL issue since the EXPLAIN said it
had a possible key (PRIMARY) but then ended up not using it (bottom
one):

http://dpaste.com/524697/

BN

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



Re: Another problem with django static files

2011-03-22 Thread Brian Neal
On Mar 22, 6:49 pm, jim_rain  wrote:
> I'm running Django 1.2.5 on a linux (Centos 5.5) server and I'm trying
> to use a datepicker widget written by Aaron Williamson (http://
> copiesofcopies.org/webl/2010/04/26/a-better-datetime-widget-for-
> django/)
>
> I followed all the steps in his write up but when I try to access the
> form with the datepicker on it I don't see anything and the runserver
> outputs: "GET /myApp/jtest/ HTTP/1.1" 200 409
>
> I'm pretty sure this is because Django can't find my media files but I
> can't figure out why. I have added this to my urls.py:
>
>     (r'^site_media/(?P.*)$', 'django.views.static.serve',
>         {'document_root': '/home/jim/work_area/site_base/site_media',
> 'show_indexes': True}),
>
> and when I go tohttp://localhost/site_mediaI see a directory listing
> of all the media directories and files.
>
> In my widget class I have the following inner class:
>
>     class Media:
>         css = {
>             'all' : ("site_media/css/ui-lightness/jquery-
> ui-1.8.11.custom.css", ),
>             }
>         js = (
>             "site_media/js/jqsplitdatetime.js",
>             "site_media/js/jquery-1.5.1.min.js",
>             "site_media/js/jquery-ui-1.8.11.custom.min.js",
>             )
>
> I thought that would do it but apparently not. Can anybody tell me
> what I"m missing?
>
> Thank you.

Did you output {{ form.media }} in your template?

Best,
BN

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



Slow query on MySQL

2011-03-22 Thread Brian Neal
I apologize in advance as this is probably only tangentially related
to Django.

I have a forums type Django application. In my RSS feed class I had
this Django model query:

return Post.objects.filter(topic__forum__id=obj.id).order_by(
'-creation_date').select_related(depth=2)[:30]

It seemed to work okay, but was slow (2 seconds). I was able to reduce
the time it took by more carefully extracting only the fields I needed
with values_list().

But then I changed it to use an "in" operation:

forums = [1, 2, 3, 4, 5]
return Post.objects.filter(topic__forum__in=forums).order_by(
'-creation_date').select_related(depth=2)[:30]

This query took over 40 seconds! Again, I can reduce this time using
values_list and a smaller list of fields, but even then it is 4
seconds or so.

I did an EXPLAIN on each of the queries, see the link below. The top
one is the fast one, and the bottom one is the slow one:

http://dpaste.com/524697/

I am not a MySQL expert and I need help interpreting the results. It
looks like for whatever reason, on the slow one, MySQL identified a
possible index, but then decided not to use it?

I ended up working around it by doing the work in Python: I looped
over all the forum ids in the "in" list, making the first query for
each, and then had to combine and sort the results myself.

I'm using InnoDB if that matters. Did I do something wrong or is this
a MySQL issue?

Thanks for any insights.

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



Cycle & Include tags

2011-03-07 Thread Brian Neal
I'm using a recent checkout of Django trunk.

If I have a template "test.html" which is this:

{{ rowcolors }}

the only way I could make cycle and include behave together is to do
this:

{% for obj in page.object_list %}

{% include 'test.html' %}
{% endfor %}

I thought that perhaps the new "silent" keyword would eliminate the
need to HTML comment out the cycle tag:

{% for obj in page.object_list %}
{% cycle 'odd' 'even' as rowcolors silent %}
{% include 'test.html' %}
{% endfor %}

However, the very first time through the for loop, rowcolors is not
set in the included template. It works on subsequent cycles though.

Is there a way to make this work without having to HTML comment out
the cycle tag output? Admittedly it's a minor annoyance.

Thanks!

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



Re: How To Populate A Dropdown List

2011-02-08 Thread Brian Neal
On Feb 8, 10:03 am, hank23  wrote:
> I have coded a form which will display some data in a dropdown
> selection box. The data is being populated from a a queryset that I
> have setup in the form's code. However the entries in the dropdown
> only display as objects of the table from which they're being
> retrieved, and don't display the actual field data that I was hoping
> to have it display. So how do I specify in the form which of the table
> fields is to be the display field and which is suppoed to be the
> underying key value to be passed when and entry is selected? Thanks
> for the help.

Post your code somewhere, e.g. dpaste.com so we have a better idea
what you are trying to do.

Best,
BN

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



Re: Why django not found static files?

2011-02-03 Thread Brian Neal
On Feb 3, 6:04 am, Marc Aymerich  wrote:
> On Thu, Feb 3, 2011 at 12:51 PM, Marc Aymerich  wrote:
> > Hi,
> > I just installed the django-admin-tools app but my django installation
> > doesn't load the css, js and other static files.
>
> > in settings.py I have:
> > STATIC_ROOT = '/home/ucp/trunk/static/'
> > STATIC_URL = '/static/'
>
> > and when i try to load
> >http://localhost:8081/static/admin_tools/css/dashboard.cssI get a
> > "page not found" error :(
>
> > but this file seems to be in the right directory and have read
> > permisons for my user!
> > /home/ucp/trunk/static/admin_tools/css/dashboard.css
>
> > what I'm missing?
>
> I solve it setting staticfiles_dirs var:
>
> STATICFILES_DIRS = ('/home/ucp/trunk/static/',)
>

STATIC_ROOT is the location of where the management command is going
to place all the static files it collects. So normally (?) I think
you'll want STATIC_ROOT to be a different directory than what you put
in STATICFILES_DIRS. Think of it this way: your non-app specific
static files will appear in a directory that is listed in
STATICFILES_DIRS, your app-specifc files typically would appear under
your_app/static, and all of the static files will be copied to
STATIC_ROOT after running the management command. In production, you'd
likely configure your server to serve files out of STATIC_ROOT.

Hope that helps,

BN

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



Re: Confusion about the new staticfiles contrib app

2011-01-26 Thread Brian Neal
I can answer one of my own questions now:

On Jan 25, 11:46 pm, Brian Neal <bgn...@gmail.com> wrote:
...
> My second confusion point:
> I am running the dev server with -Wall and I am seeing warnings:
> PendingDeprecationWarning: The view at `django.views.static.serve` is
> deprecated; use the path `django.contrib.staticfiles.views.serve`
> instead.
>
> I don't understand why I'm getting these warnings.

This warning is being generated by the django debug toolbar calling
into the deprecated view function.

-BN

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



Re: Confusion about the new staticfiles contrib app

2011-01-26 Thread Brian Neal
On Jan 26, 8:46 am, Jonas Geiregat  wrote:
>
> MEDIA_ROOT is the path to the directory where your files will live.
>
> MEDIA_URL is the URL the get to those files.
>
> So if MEDIA_ROOT='/home/you/media'
> and MEDIA_URL='site-media/'
>
> Then if you want to view a file located at /home/you/media/thisFile.jpg you 
> enterhttp://yoursite.com/site-media/thisFile.jpg.

I understand the settings just fine. Are you saying that the dev
server is serving your media files? Because it isn't for me. It is
only serving the static media.

> The same counts for STATIC_ROOT and STATIC_URL.

What do you have STATIC_URL set to? Is it different than your
MEDIA_URL?

Thanks.

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



Re: Confusion about the new staticfiles contrib app

2011-01-26 Thread Brian Neal
On Jan 26, 1:46 am, Jonas Geiregat <jo...@geiregat.org> wrote:
> Op 26-jan-2011, om 06:46 heeft Brian Neal het volgende geschreven:
>
> > Hi -
> > I'm trying to cut over my project to use the new staticfiles
> > application. I'm using the dev server with DEBUG = True on a recent
> > SVN trunk checkout. My STATIC_URL is '/static/' and my MEDIA_URL is
> > 'http://localhost:8000/media/'in this environment.
>
> STATIC_URL and MEDIA_URL are two different things.

Agree.

>
> if you want to serve static files that are related to your 
> webdesign/development you should use STATIC.
> User related files such as uploaded files such be placed inside the MEDIA 
> path.

That is what I'm trying to do.

>
> so change STATIC_URL into MEDIA_ROOT='static/'.

I don't understand this. One is a URL, the other is a file path. Why
would I set STATIC_URL = MEDIA_ROOT? Or did you make a typo and mean
MEDIA_URL? That might make more sense to me.

My question is, if I want to serve my apps' static files at the URL /
static/ and user-uploaded media at /media/ (Is this an unusual
requirement? Maybe this is typically only done in production?) what is
the best way to do this with the dev server, and should the docs be
strengthened to support this? The dev server, with DEBUG=True, does a
good job of serving my apps' static files at the URL rooted at /
static/, but it (obviously) 404's when a request is made for /media/.
So here I think I need to configure the new static serving view with
the URL pattern /media/ (and point it at my MEDIA_ROOT as I showed in
my original post).

Or, do most people (in dev. mode) set MEDIA_URL = STATIC_URL, and then
add the MEDIA_ROOT path to the STATICFILES_DIRS setting? Or do
something else?

Could some people could post their full (STATIC|MEDIA)_(ROOT|URL) and
STATICFILES_* settings for their dev server environment? I guess I am
looking for some "best practice" examples; for some reason this is
really tripping me up. Thank you.

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



Confusion about the new staticfiles contrib app

2011-01-25 Thread Brian Neal
Hi -
I'm trying to cut over my project to use the new staticfiles
application. I'm using the dev server with DEBUG = True on a recent
SVN trunk checkout. My STATIC_URL is '/static/' and my MEDIA_URL is
'http://localhost:8000/media/' in this environment.

My first confusion point:
Maybe it was just me, but I got confused about serving my media
(MEDIA_ROOT/MEDIA_URL) files with the dev server. After cutting over
to staticfiles, my MEDIA_URL files started getting 404s. Eventually I
came to the conclusion that I had do this:

urls.py:
if settings.DEBUG:
   urlpatterns += patterns('django.contrib.staticfiles.views',
  (r'^media/(?P.*)$', 'serve', {'document_root':
settings.MEDIA_ROOT}),
   )

The docs don't seem to mention using this view for this purpose.
Should they?

My second confusion point:
I am running the dev server with -Wall and I am seeing warnings:
PendingDeprecationWarning: The view at `django.views.static.serve` is
deprecated; use the path `django.contrib.staticfiles.views.serve`
instead.

I don't understand why I'm getting these warnings. My code no longer
references django.views.static.serve. I even see this warning when
looking at an admin page. Any thoughts on why this is occurring?

Thanks.

PS After coming to terms with staticfiles, I think it is a great idea.
I like being able to separate my apps' static files from user uploaded
media files.

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



Re: forms, hidden fields

2011-01-18 Thread Brian Neal
On Jan 18, 8:32 am, niall-oc  wrote:
> ...
> There is a simple form.  My question is how do you set a field to be
> hidden.
>
> http://docs.djangoproject.com/en/1.1/topics/forms/#looping-over-the-f...
>
> This document explains how you may check if a field is hidden, however
> there seems to be no information on how to initially set the field to
> be hidden. I've tried adding hidden=True and is_hidden=True to the
> above class but to no avail.
>
> Any help would be really appreciated

Hi - please see the docs on form widgets and how you can change out a
form field's default widget:

http://docs.djangoproject.com/en/1.2/ref/forms/widgets/
http://docs.djangoproject.com/en/1.2/ref/forms/widgets/#specifying-widgets

I suspect you'll want to specify a HiddenInput widget for one or more
of your form fields.

Best,
BN

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



Re: Can I add custom field to ModelForm?

2011-01-08 Thread Brian Neal
On Jan 7, 8:55 am, robos85  wrote:
> Is it possible to add field (I want it to be visible in generated form and
> after post) to form which is not included in Model? I need it to make a
> check after form.is_valid(), but this field won't go to DB.
>
> If yes - how can I do that?

It is possible. Google for django dynamic forms. The same techniques
can be used for model forms, but you'll have to decide what to do with
the extra fields.

Some links to get you started:
http://jacobian.org/writing/dynamic-form-generation/
http://www.b-list.org/weblog/2008/nov/09/dynamic-forms/
http://www.hindsightlabs.com/blog/2010/02/11/adding-extra-fields-to-a-model-form-in-djangos-admin/

Best regards,
BN

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, 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: Updating a video rating using AJAX

2010-10-20 Thread Brian Neal
On Oct 20, 8:23 am, Sithembewena Lloyd Dube  wrote:
> Hi all,
>
> I have a page where users can rate a video, and in models.py I have a video
> model with a 'rating' property. I wish to find out how I can AJAXify the
> rating button on the page, so that if a user clicks on it, the button can
> call a custom function and pass the video id (cannot call a view as that
> would return an entire response). Am thinking of a function roughly as
> follows:
>
> from myproject.myapp.models import Video
>
> def save_rating(video_id, rating):
>     video = Video.objects.filter(pk=video_id)
>     video.rating += rating
>     video.save()
>     return video.rating #* The rating label on the page would then be
> updated with the returned rating.*
>
> I would like to do this without using a view or doing a form POST or GET of
> any kind. Any pointers?

AJAX does in fact do a POST or GET. So you do need to make a view
function that your javascript can issue a POST to update the rating.
Your javascript will need to pass the video ID to the view somehow,
either as part of the URL or as a POST parameter. Your view then needs
to return a response to the javascript, and you can do this as either
plain old text, JSON, XML, or HTML, depending on what makes the most
sense for you. I'd recommend you use a javascript library like jQuery,
simply because these libraries hide some of the very tedious things
you have to do if you were to code the request by hand.

I'd suggest you take a look at some jQuery AJAX tutorials on the web.

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



Re: form validation for empty checkboxes that are not required (and they are the only fields present)

2010-09-28 Thread Brian Neal
On Sep 27, 11:35 am, Skylar Saveland 
wrote:
> I have some modelforms within a .  Each form has one
> checkboxselectmultiple that is not required.  If I post nothing (all
> checkboxes are empty) then all of the forms are invalid.  If I post
> anything then all of the forms are valid.  This anything could be that
> one of the forms has a box checked, or that I add  name='omg' value='wtf'> to the form.
>
Can you please post your model and form code? Perhaps in a pastebin?

BN

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, 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 clear wrong form data (e.g password field), but still show error?

2010-09-16 Thread Brian Neal
On Sep 16, 9:55 pm, Brian Neal <bgn...@gmail.com> wrote:
> On Sep 16, 7:37 pm, Karen Tracey <kmtra...@gmail.com> wrote:
>
> > Use this widget for the field:
>
> >http://docs.djangoproject.com/en/1.2/ref/forms/widgets/#django.forms
>
> > with render_value=False
>
> Note that the docs indicate the default value for render_value is True
> but in the code it is False:
>
> http://code.djangoproject.com/browser/django/trunk/django/forms/widgets.py#L232

Oh sorry, the documentation is correct in the development docs:

http://docs.djangoproject.com/en/dev/ref/forms/widgets/#django.forms.PasswordInput

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, 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 clear wrong form data (e.g password field), but still show error?

2010-09-16 Thread Brian Neal
On Sep 16, 7:37 pm, Karen Tracey  wrote:
>
> Use this widget for the field:
>
> http://docs.djangoproject.com/en/1.2/ref/forms/widgets/#django.forms
>
> with render_value=False
>
Note that the docs indicate the default value for render_value is True
but in the code it is False:

http://code.djangoproject.com/browser/django/trunk/django/forms/widgets.py#L232

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, 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: PayPAL-IPN-request doesn't call the view

2010-09-10 Thread Brian Neal
On Sep 10, 12:01 pm, Bill Freeman  wrote:
>
> My advice is to protect everything with try or by using get,
> log your progress (we had a logging model, but you can
> also append to a file, wrapping everything in a try-finally
> that closes the filehandle to be sure things get flushed
> out), and when you get something you haven't provided
> for, log the contents of request.POST.  It will be something
> simple, such as there's some field they no longer provide
> or don't always provide.

I have to echo Bill's advice here. Use the Python logger generously in
your IPN view handling code. Paypal has a habit of subtly changing
their API or their POST parameters periodically. Anyway, unless you
are getting hundreds of IPN's a day, I'd log all kinds of stuff to a
file and study it to see where it is going wrong. Good luck,

BN

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, 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: Please wait page trouble

2010-09-08 Thread Brian Neal
On Sep 8, 5:56 pm, Bradley Hintze  wrote:
> This is what I have in my please_wait.html
>
>  src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js";>
> $.getJSON('{% url run_DHM %}')});
>
> 

I don't think that is right, is it? At least I've never seen it done
that way. I think you need two script tags:

http://ajax.googleapis.com/ajax/
libs/jquery/1.4/jquery.min.js">

   // Your javascript goes here...


>
> This is the django error
>
> Caught NoReverseMatch while rendering: Reverse for 'run_DHM' with
> arguments '()' and keyword arguments '{}' not found.
>
> run_DHM takes 'request' as an argument. How do I pass it the argument??
>

All views take request as a first argument. But that isn't the
problem. Please post your urls.py that has your run_DHM view in it.

Regards,
BN

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, 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: python manage.py runserver - can't see error stack traces when an Ajax handler throws an exception

2010-09-08 Thread Brian Neal
On Sep 7, 5:10 pm, Phlip  wrote:
> [...]
>
> How do I get Ajax errors to print a simple exception trace to STDOUT,
> instead of going through all that baloney?
>

Firebug can display these Ajax errors quite easily and give you a lot
more information.

-BN

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, 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: broken default view of the django admin site

2010-07-15 Thread Brian Neal


On Jul 15, 2:05 pm, Colleen A Josephson  wrote:
> Hello,
>
> I'm very new to django. I just set up my first site using apache and mod_wsgi.
>
> The admin area does not seem to have the nice, neat blue default theme...its 
> horrifically ugly and difficult to navigate.
> Here's a screenshot of the login 
> area:http://web.mit.edu/~cjoseph/Public/fugly.png
>

You probably need to configure apache/mod_wsgi to serve static files:

http://docs.djangoproject.com/en/1.2/howto/deployment/modwsgi/#serving-media-files

After that, you have to get the admin media files served somehow. What
I do is put a symlink in my media folder to django/contrib/admin/media
directory.

Good luck,
BN

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, 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: Log errors to file

2010-07-07 Thread Brian Neal
On Jul 7, 4:35 pm, Jonathan Hayward
 wrote:
> I'm working on a view made to output JSON for Ajax use. My log has:
>
> [07/Jul/2010 17:47:13] "POST /ajax/login HTTP/1.1" 500 50678
>
> That looks like Django gave a helpful and detailed stacktrace page, albeit
> to jQuery expecting JSON.

If there is a "human in the loop", you can use the Firebug extension
on Firefox to monitor requests and responses made via AJAX. I look at
Django 500 pages through Firebug all the time. ;-)

http://getfirebug.com/

Best,
BN

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, 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: AJAX request does not seem to have request.user

2010-06-02 Thread Brian Neal
On Jun 2, 10:14 am, Carl Nobile  wrote:
>
> Could the new code not work with a class. I'm still looking into this
> and may discover the answer myself, but if anybody knows or has an
> idea I'd be much appreciative.
>
> ~Carl

Carl, those decorators no longer work on class methods without some re-
jiggering. See the release notes:

http://docs.djangoproject.com/en/dev/releases/1.2/#user-passes-test-login-required-and-permission-required

BN

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, 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: Turning "DEPUG=False" results in missing CSS

2010-05-25 Thread Brian Neal
On May 25, 2:51 pm, tom  wrote:
> Hi,
>
> I have currently built a website with Django. After developing
> everything locally with "python manage.py runserver", I have switched
> for testing to Apache and mod_python.
>
> Everything worked fine there as well. All pages are rendered correctly
> (PS: For the layouting, I use 3 CSS files).
>
> Now, I want to go into production mode. The only thing I did so far:
> turning DEPUG to False in my settings.py.
>
> RESULT:  All my pages seems to have lost the CSS files. The text parts
> are there, but the layouting doesn't work.
>
> When I turn DEPUG back to True in my "settings.py", the layouting of
> the pages works again.
>
> ???

I'm assuming you mean DEBUG, not DEPUG.

Anyway, you probably have configured the dev server to server static
files for you when DEBUG is on. Look in your urls.py for DEBUG.

You'll need to configure Apache to server the static files when you
deploy in that configuration:

http://docs.djangoproject.com/en/dev/howto/deployment/modpython/#id1

Best,
BN

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, 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: List of Users online

2010-05-19 Thread Brian Neal
On May 19, 12:31 pm, EmileZola  wrote:
> I want to list the logged in users on my index page and was wondering
> what was the right way to do this.
>
> Can I do it similar to this ?
> def index(request):
>     return render_to_response('index.html', {
>         'online_users': User.objects.filter(last_login > delay)
>     })
> delay being "now - 15 minutes" or something like that...
>
> Is there a way to use is_authenticated() in that context ?
> Should I use a MiddleWare instead to acheive this ?
>

I don't think basing it off of last_login will work, because they may
login and then stay logged in for 2 weeks or whatever you have your
cookie settings set to.

I have a piece of middleware that maintains a dictionary of username,
datetime key/value pairs in the cache. If the requesting user is
authenticated I update their timestamp in the dictionary. I then
iterate over the dictionary and delete entries that are older than
some threshold.

I then have a template tag that retrieves the dictionary from the
cache and displays the names.

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

2010-05-18 Thread Brian Neal
On May 18, 9:57 am, Matt W  wrote:
> Hello Everyone,
>
> I just started to use Django and I was wondering how I could setup
> javascipt (AJAX to be more specfic) in my djagno project in order to
> run a script. Here is the script code.
>
[snip]
>
> In specific I was wondering where I place the source code for the
> javascipt file along with what files I need to configure in the
> project folder. I'm very new to django so I don't really know how to
> even start this.
>

Django is a server-side framework, it doesn't require configuration
for client-side javascript, save for perhaps your MEDIA_URL. Your
script doesn't reference any local javascript files, but if you had
them, you'd probably want to put them in your media directory, say
media/js. Your templates would just reference them, perhaps using
{{ MEDIA_URL }} or just hard-coding a path to them. You are free to
sprinkle javascript 

Re: insert html in html

2010-05-18 Thread Brian Neal
On May 18, 2:00 pm, CrabbyPete  wrote:
> I want to insert a html calendar into an existing web page. What is
> the best way to insert html into a template that I have for the web
> page?

In what form do you have this calendar HTML? Do you compute it in a
view? Is it already in a file? If you have it in a view, then one way
to do it would be to pass it to a template and in the template:

My Calendar

{{ my_calendar_data|safe }}


You could make this a template tag, or {% include %} it, or put it in
your base template...

We'd need more information to help further.

Hope that helps.
BN

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, 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: No stylesheet in administration panel

2010-05-18 Thread Brian Neal
On May 18, 10:47 am, Carlo Trimarchi  wrote:
> Hi,
> I'm following the django tutorial to build the poll application. I'm
> working mostly on a remote server (using wsgi), but I'm also trying
> stuff on my local machine, just running the manage.py runserver
> command.
> I've just enabled the admin site and it works. But when I access the
> page on the server it just doesn't use any style. I mean, I don't see
> coloured boxes, no cool fonts or the correct layout. If I run the
> local version it is displayed correctly. I'm sure that the code is the
> same for both versions, since the local one is just the remote
> directory mounted through ssh.
>
> So, what can be the problem?
>
You need to configure Apache / mod_wsgi to serve the static files.
Here is a place to start:

http://docs.djangoproject.com/en/1.2/howto/deployment/modwsgi/#howto-deployment-modwsgi

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, 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: Considering Django: How simple is customising django-admin?

2010-04-08 Thread Brian Neal
On Apr 8, 5:15 am, UnclaimedBaggage  wrote:
> Hi folks,
>
[..]
> Any
> suggestions on the following would be very appreciated:
>
> #1.) For usability's sake, I'd like to have foreign key models
> embedded in the same admin form as the model they're referencing. For
> example, if there's a "products" model with a one-to-many relationship
> to "product options", I'd like to add "product options" from within
> the "product" admin form. (Eg javascript adds another field each time
> all existing "product option" fields are filled out...or something).
> Anything that will help (or hurt)  me in trying to add this sort of
> functionality? Is this commonly done?

Yes. See InlineModelAdmin objects.
http://docs.djangoproject.com/en/1.1/ref/contrib/admin/#inlinemodeladmin-objects

>
> #2.) Adding javascript to individual admin forms. Simple?

Yes, see model admin media:
http://docs.djangoproject.com/en/1.1/ref/contrib/admin/#modeladmin-media-definitions

>
> #3.) Customising the HTML (not CSS) output of django-admin. For
> example, putting a thumbnailed image next to each product in the
> Admin-->Products table list. Simple?

I suspect this can be done in a variety of ways. One way may be to
define a method on a model to return the HTML for the thumbnail image
and using it in the list_display admin option.

>
> #4.) A lot of what I do is basic (but custom) e-commerce & CMS stuff.
> Django's CMS potential looks very solid, although I'm wondering if
> tacking on basic e-commerce features to django-admin could be a little
> cumbersome. Features such as basic order reports/stats etc don't seem
> to fit too freely into the django-admin approach.

You can create your own admin views to do arbitrary things.

>  I'll also need to
> auto-create thumbnails from model.ImageField inputs. Easily doable?

With the PIL library, yes. There are also third party snippets and
apps to help with this.

>
> #5.) 'Convenience' form fields in admin forms. For example, a select
> box that lets you choose a parent category, which in turn presents a
> 'child category' select box, etc...or tree-structured checkboxes. I'm
> comfortable writing up the javascript, but from a quick inspection
> django-admin didn't seem to like the inclusion of select fields that
> weren't intended to interact with the model. Was this just my clumsy
> newbieness or is this going to be a problem?

Not really sure what you mean, but you can supply your own forms,
templates, and custom javascript to the admin.

I think you'll find the admin pretty customizable for small and
moderately complex websites. If the complexity is very high you'll
likely have to write your own admin views.

The docs for the admin app are here:
http://docs.djangoproject.com/en/1.1/ref/contrib/admin/#module-django.contrib.admin

Regards,
BN

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, 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: url template tag taking a long time

2010-04-07 Thread Brian Neal
On Apr 6, 11:53 pm, Russell Keith-Magee <freakboy3...@gmail.com>
wrote:
> On Wed, Apr 7, 2010 at 12:08 PM, Brian Neal <bgn...@gmail.com> wrote:
> > I am on trunk, somewhere around revision 127xx and just updated to
> > 12936. A couple of my views render this one particular template, which
> > used to take less than a second to see a response. Now it is taking
> > almost a minute. [...]
>
> > I started removing junk from my template until it started responding
> > normally, and I isolated it down to a {% url %} tag. Well, I don't
> > think it was just one, maybe a few of them combined was adding up to a
> > minute.
>
> > 
>
> > Anyone else seeing this? Thoughts?
>
> Are you running on SVN trunk? If so, it's possible that you're seeing
> the effects of #13275 [1].

Yes, I'm on SVN trunk.
>
> This is a major regression that was introduced recently to solve a
> different problem (#12945, which was in turn a fix for #12072). This
> problem is on the 1.2 critical list, so it needs to be fixed before
> 1.2 is released.
>
> [1]http://code.djangoproject.com/ticket/13275

Thanks for the confirmation. If there is anything I can help with let
me know. My laptop's CPU fan really kicks on when I hit that code. =:-
O

>
> > Maybe unrelated, but I also noticed that after I updated, I had to
> > change this:
>
> > {% url bio-members_full type="user",page="1" %}
>
> > to this:
>
> > {% url bio-members_full type='user',page=1 %}"
>
> > (switch to single quotes in the kwargs to pass a string literal) or I
> > got a template syntax error.
>
> This sounds like you may have found an additional regression case
> caused by the same chain of tickets.
>
> Yours,
> Russ Magee %-)

Regards,
BN

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



url template tag taking a long time

2010-04-06 Thread Brian Neal
I am on trunk, somewhere around revision 127xx and just updated to
12936. A couple of my views render this one particular template, which
used to take less than a second to see a response. Now it is taking
almost a minute. The Django debug toolbar reports nothing out of the
ordinary in terms of SQL queries. Something like 12 queries in 6.42
ms. But user CPU time is nearly 1 minute.

I started removing junk from my template until it started responding
normally, and I isolated it down to a {% url %} tag. Well, I don't
think it was just one, maybe a few of them combined was adding up to a
minute.



Anyone else seeing this? Thoughts?

Maybe unrelated, but I also noticed that after I updated, I had to
change this:

{% url bio-members_full type="user",page="1" %}

to this:

{% url bio-members_full type='user',page=1 %}"

(switch to single quotes in the kwargs to pass a string literal) or I
got a template syntax error.

Thanks,
BN

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, 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: Formatting datetimes - simple question

2010-04-06 Thread Brian Neal
On Apr 6, 5:29 pm, Paweł Roman  wrote:
> Hi all,
>
> Django has this DATETIME_FORMAT setting, which allows to format all
> datetime values, whenever they are displayed. But the problem is this
> is a _global_ setting, so whoever uses the application would see all
> the datetimes formatted exactly the same way. I'd like to allow
> individual users to select their own favorite datetime format. What I
> don't know is which method I should override to be able to manually
> format a datetime field on a model when it is being rendered.
>

Off the top of my head:

I would probably store in the user profile model the user's preferred
format string. Then I'd create a template tag that would format a
given datetime with that setting, e.g.:

{% now_in_user_format user %}

Inside that tag you would get the user's profile (user.get_profile())
and then return a string that is now().strftime(users_format).

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, 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: Hostmonster shared hosting and django tinymce

2010-03-21 Thread Brian Neal
On Mar 21, 7:49 am, Bobby Roberts  wrote:
> can anyone help me out here?  I'm stuck and cannot get the text areas
> to work using ckeditor.

Does any static media work? How are you deploying? mod_python,
mod_wsgi? What is the configuration? Can you access the javascript in
your browser at the URL you think it should be at?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, 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: Using markdown to clean html

2010-03-20 Thread Brian Neal
On Mar 19, 8:35 am, Tor Nordam  wrote:
> I'm currently writing a blog application in django, and a part of what
> I want to do is allow some HTML in posts and comments. I discovered
> yesterday, more or less by accident, that the markdown filter actually
> allows some HTML.

Are you using it in "safe" mode? If you specifiy safe=True it will
strip out HTML.

http://www.freewisdom.org/projects/python-markdown/Using_as_a_Module

Read the source code in django/contrib/markup/templatetags/markup.py
to see how Django integrates the Python Markdown module and what you
need to do to use "safe" mode.

Regards,
BN

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, 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 cache the output of Django 1.2 RSS class based views?

2010-03-11 Thread Brian Neal
On Mar 7, 10:48 pm, Brian Neal <bgn...@gmail.com> wrote:
> Before the Django 1.2 beta and the class-based Feed views, I was doing
> this to cache my RSS feeds:
>
> urls.py:
> from django.contrib.syndication.views import feed as syndication_feed
> from django.views.decorators.cache import cache_page
>
> urlpatterns = patterns('',
>    url(r'^feeds/(?P.*)/$',
>       cache_page(syndication_feed, 60 * 15),
>       {'feed_dict': feeds},
>       'feeds-news'),
>
> Is there a way to do something similar to this now with the 1.2 Feed
> classes? This doesn't seem to work when the argument to cache_page is
> now an instance of a Feed object (I get an AttributeError; my feed
> class has no attribute '__name__'):
>
>    url(r'^feeds/news/$',
>        cache_page(LatestNewsFeed(), 60 * 15),
>        name='feeds-news'),
>

Well, I'm not sure if it was the intent to break this use case. Any
thoughts?

But I found a work around after talking to Rob Hudson. You can
override the syndication base class __call__ function and decorate
that. But another new thing here is you have to use the new
method_decorator [1]:

class MyFeed(Feed):

@method_decorator(cache_page(60 * 60))
def __call__(self, request, *args, **kwargs):
return super(MyFeed, self).__call__(request, *args, **kwargs)

Again, I'm not sure if this was supposed to break like this, as there
are certain advantages to do this in the URLconf, as noted in the docs
for cache_page.

BN

[1] 
http://docs.djangoproject.com/en/dev/releases/1.2/#user-passes-test-login-required-and-permission-required

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



How to cache the output of Django 1.2 RSS class based views?

2010-03-07 Thread Brian Neal
Before the Django 1.2 beta and the class-based Feed views, I was doing
this to cache my RSS feeds:

urls.py:
from django.contrib.syndication.views import feed as syndication_feed
from django.views.decorators.cache import cache_page

urlpatterns = patterns('',
   url(r'^feeds/(?P.*)/$',
  cache_page(syndication_feed, 60 * 15),
  {'feed_dict': feeds},
  'feeds-news'),

Is there a way to do something similar to this now with the 1.2 Feed
classes? This doesn't seem to work when the argument to cache_page is
now an instance of a Feed object (I get an AttributeError; my feed
class has no attribute '__name__'):

   url(r'^feeds/news/$',
   cache_page(LatestNewsFeed(), 60 * 15),
   name='feeds-news'),

Or am I going about this wrong and I need to put the cache_page
decorator on an overridden __call__ method on my derived Feed class
(which simply calls the base class)?

Thanks,
BN

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, 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 display PendingDeprecationWarning using dev. server?

2010-03-06 Thread Brian Neal
On Mar 6, 10:29 am, Karen Tracey  wrote:
> This appears to be due to the way runserver reloads the process when
> monitoring for source code changes.  If you specify --noreload on runserver
> I bet you will see the warnings. The behavior appears to be OS-specific: I
> can recreate what you describe on Ubuntu, but on Windows machine the
> warnings are printing properly.
>
> Karen
>
Thanks Karen. Yes, I'm using Ubuntu, and running with --noreload
allows me to see the PendingDeprecationWarning. Is this worthy of a
bug report?

Regards,
BN

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, 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 display PendingDeprecationWarning using dev. server?

2010-03-05 Thread Brian Neal
Any ideas? Can anyone else try this and report back? Just insert the
code below into a view function and start the dev. server with "python
-Wall manage.py runserver". Thanks.

On Feb 28, 5:28 pm, Brian Neal <bgn...@gmail.com> wrote:
> I'm having trouble seeing PendingDeprecationWarning's on stderr when
> using the dev server.
>
> To make sure I'm not crazy, I wrote a simple Python program that looks
> like this:
>
> print "** WARNING **"
> import warnings
> warnings.warn(
>     "Testing the warnings module!",
>     PendingDeprecationWarning
> )
>
> And here are some sample runs:
>
> $ python warning.py
> ** WARNING **
> $ python -Wall warning.py
> ** WARNING **
> warning.py:5: PendingDeprecationWarning: Testing the warnings module!
>   PendingDeprecationWarning
>
> Now when I put that code in some view function in my Django app, I
> always see the print statement output, but never the actual warning
> message. I've tried starting the dev. server various ways, but none of
> them seem to work:
>
> $python -Wall manage.py runserver
> $python -Wd manage.py runserver
>
> I only seem to have this trouble with PendingDeprecationWarning.
> UserWarning, for example, works as expected.
>
> What am I doing wrong? I am using Python 2.5.2 and Django SVN r12623.
> Thanks.

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



How to display PendingDeprecationWarning using dev. server?

2010-02-28 Thread Brian Neal
I'm having trouble seeing PendingDeprecationWarning's on stderr when
using the dev server.

To make sure I'm not crazy, I wrote a simple Python program that looks
like this:

print "** WARNING **"
import warnings
warnings.warn(
"Testing the warnings module!",
PendingDeprecationWarning
)

And here are some sample runs:

$ python warning.py
** WARNING **
$ python -Wall warning.py
** WARNING **
warning.py:5: PendingDeprecationWarning: Testing the warnings module!
  PendingDeprecationWarning

Now when I put that code in some view function in my Django app, I
always see the print statement output, but never the actual warning
message. I've tried starting the dev. server various ways, but none of
them seem to work:

$python -Wall manage.py runserver
$python -Wd manage.py runserver

I only seem to have this trouble with PendingDeprecationWarning.
UserWarning, for example, works as expected.

What am I doing wrong? I am using Python 2.5.2 and Django SVN r12623.
Thanks.

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



Re: Added-value over PHP?

2010-02-06 Thread Brian Neal
On Feb 3, 1:39 am, Delifisek Tux  wrote:
>
> A decent framework eats up your %50 of
> cpu resource. For example that Uber Zend FW gives you 1/6 in a hello world
> app comparing plain php.

Why would you want to write a Hello World program in a framework?

Try writing a very large app in a framework and then try using bare
PHP. Compare how much longer and how many more bugs do you get using
bare PHP. Compare how many SLOC it took in each. Which is easier to
maintain? Caching can be used to recover speed.

BN

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

2010-01-14 Thread Brian Neal
On Jan 14, 7:30 pm, E17  wrote:
> Hi,
>
> in my Django application I need a way to track logged users presence.
>
> User gets an 'online' status when he/she logs in and 'offline' status
> when logs out, it's pretty simple. But what is the best way to handle
> non-logged-out sessions? One need to periodically check all sessions
> on last activity age and make some decisions depending on that age -
> i.e. set user status to 'away' of 'offline'.
>
> I wouldn't like to use cron, as running full python execution stack is
> quite expensive in terms of performance. For the same reason I don't
> like to run this code on [every] request handlers.
>
> Seems to me like better solution would be to use some outer deamon or
> deamon-like proces that would handle this functionality. I've googled
> out at least 2 solutions for that - django-cron (http://
> code.google.com/p/django-cron/) and a standalone Django Cron Jobs
> Daemon (http://www.djangosnippets.org/snippets/1348/).
>
> What is a better way or I missed something else?
>
> Thank you

Use some middleware to keep track of the last time you see a logged in
user.

BN
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, 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: Overhead of using django.contrib.markup vs. pre-rendered HTML field

2009-12-21 Thread Brian Neal
On Dec 21, 7:12 am, Jesaja Everling  wrote:
> Hi All!
>
> I'm wondering how expensive it is in terms of processing power to use
> the django.contrib.markup filters for displaying blog posts instead of
> storing pre-rendered HTML in a db field.
> The Pinax blog application makes use of these markup-filters to render
> HTML on the fly, for example. I assume that especially with caching
> enabled this won't pose a problem, but it still might be advisable to
> store pre-rendered HTML once a new blog-post is saved.
> Does the reStructuredText filter introduce noticeable overhead or is
> it negligible?

This question always generates a lot of heat when it crops up on sites
like reddit and digg, so you are bound to get a lot of varied and
strongly held opinions.

The only way you are really going to know is to take some benchmarks
and see what the difference is, then you have to decide if the
overhead is too great for your specific application and site. The
overhead is probably acceptable for a great majority of sites, but
only you should decide that for yourself.

I almost always pre-render it and save it in the database. On my site,
my content is going to be read many, many orders of magnitude more
than it is written, so I just get the conversion from markup to HTML
over with once. It's a trade-off between database space and CPU, and
one that I am very willing to make given my circumstances of my site
and my applications. Your mileage may vary, of course.

Best,
BN

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, 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: Cron vs event triggered action

2009-12-14 Thread Brian Neal
On Dec 14, 12:27 pm, Tim Daniel  wrote:
> ...
>
> Creecode what do you mean with "custom management commands"? I just
> wrote a simple python script that can be called from bash like this
> python myscript.py, inside it I set up the enviroment to be able to
> call my models and perform actions using the simplicity of the django
> webframework.

http://docs.djangoproject.com/en/dev/howto/custom-management-commands/

The advantage here is that the environment is already setup for you.
You do have to look at some of the django source to figure out what
needs to be done, but it is pretty self-explanatory.

BTW, I use cron to fire off custom management commands.

Regards,
BN

--

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




Re: {{ form.as_table }} not displaying in template

2009-12-12 Thread Brian Neal
On Dec 12, 5:04 pm, GoSantoni  wrote:
> Hey i've got a very basic question about django form processing. Got
> haystack installed and searching works fine in the standard search
> template (http://haystacksearch.org/docs/tutorial.html#search-
> template) in the /search . Though i want to use the search box defined
> by {{ form.as_table }} in another template in /blog . Just copying
> {{ form.as_table }} fails to display the input field so what part of
> the views.py or the forms.py needs to be copied from the haystack app?
> Or what is another solution? So far in /blogs/blogs.html
>
> 
>         
>             {{ form.as_table }}
>
>                 
>                 
>                 
>                     
>                 
>             
>         
>
> My goal is just to display the input box and send the query to /search
> so the results are displayed on that page
>
> Thanks in advance!

I'm not really sure what you are asking. If the {{ form }} isn't
displaying, then look to your view that renders the template. Are you
building the form right and passing it to the template correctly?

--

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

2009-12-06 Thread Brian Neal
On Dec 6, 7:40 pm, XtraGreen  wrote:
> I've changed settings.TIME_ZONE to 'UTC' and restarted my server but
> when I create records (postgresql) they're not UTC, they're 'America/
> Chicago' (-6) in the table.
>
> Am I missing something or is settings.TIME_ZONE useless?

What is your server setup? Apache on Linux? mod_python or mod_wsgi?
Are you running anything else on your server like PHP apps? The
timezone setting is process-wide, so depending on how you deployed
your server another application could be overwriting you.

BN

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, 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 show site down for maintenance page

2009-12-05 Thread Brian Neal
On Dec 5, 6:54 pm, zweb  wrote:
> What is the best way to show site down for maintenance page ?

If you are using mod_wsgi:

http://www.caktusgroup.com/blog/2009/05/25/seamlessly-switch-off-and-on-a-django-or-other-wsgi-site-for-upgrades/

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, 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: overridden delete method not being called on cascade

2009-12-03 Thread Brian Neal
On Dec 3, 12:53 pm, "eric.frederich"  wrote:
>
...
>
> The problem now it that when I delete an Offering object through the
> Django admin it cascade deletes the Enrollment objects as it should
> but it is not calling the delete method and thus restoring their
> interest.
>
> When deleting an Enrollment through the admin it calls the delete
> method but not on cascades.
>
> Is it documented anywhere that this is the behavior?  I noticed that
> the post_save signal is being dispatched on each of those so I could
> re-factor my code.  But I'm curious... is it documented?  Is this a
> bug?

The admin app uses the bulk delete method when cascading. I'm not sure
that is documented. But bulk delete behavior is documented:

http://docs.djangoproject.com/en/dev/topics/db/queries/#deleting-objects

See also the warning under admin actions:

http://docs.djangoproject.com/en/dev/ref/contrib/admin/actions/#admin-actions

You could create your own admin action to do the delete any way you
want.

Best regards,
BN

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, 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: Adding a dashboard to admin

2009-12-01 Thread Brian Neal
On Dec 1, 10:56 am, Bill Freeman  wrote:
> > I then created my own template file in one of my TEMPLATE_DIRS called
> > 'admin/custom_index.html" that extends 'admin/index.html'. I ended up
> > copying the {% block content %} from the admin/index.html and
> > inserting my template tag into it.
>
> I, too, think you're going the right way.  One point is, if you really meant
> "copying", consider whether you can use the block.super variable to
> minimize the number of things you need to redo when you take an update
> to admin.

Thanks for the response. I did initially try using block.super, but
because of the HTML my dashboard pushed the sidebar down. I really
wanted to get my dashboard inside the main content div for aesthetic
reasons, so I ended up copying the block contents. I really wish there
was there was a empty {% block custom-dashboard %}{% endblock %} in
there for just this purpose, but there wasn't. I suppose they can't
anticipate everything and leave "holes" everywhere. But you're right,
I'll have to diff my template with the admin template whenever I
upgrade to see if I am missing a change.

Best regards,
BN

--

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




Adding a dashboard to admin

2009-11-30 Thread Brian Neal
On my site, users submit content that needs to be approved before
getting published. Thus I wanted a simple "dashboard" on the admin
page to show me how many pending items from each model are waiting for
approval. I created a template tag for the dashboard. I then mulled my
options for getting this template tag on the admin index page. Here is
what I came up with and I'd like some feedback.

Reading the Django docs, it says that if you want to change the index
page, "you are better off creating your own AdminSite instance [...],
and changing the AdminSite.index_template". [1]

I started research that option, but I didn't need any custom behavior
from my admin site, and I already have about a dozen applications that
have admin.py files and are they are registering with the default
admin site.

So in my main urls.py file, right before the admin.autodiscover()
call, I just did this:

admin.site.index_template = 'admin/custom_index.html'
admin.autodiscover()

I then created my own template file in one of my TEMPLATE_DIRS called
'admin/custom_index.html" that extends 'admin/index.html'. I ended up
copying the {% block content %} from the admin/index.html and
inserting my template tag into it.

It works great but I can't help but be haunted by that "you are better
off creating your own AdminSite instance" bit. Am I missing something
by not doing that?

Thanks!

[1] 
http://docs.djangoproject.com/en/dev/ref/contrib/admin/#root-and-login-templates

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, 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: Use Subversion to Download the Latest Django Version

2009-11-17 Thread Brian Neal
On Nov 17, 12:05 pm, Angel Cruz  wrote:
> So it seems TortoiseSVN does not include svn.exe?

No, it doesn't.

>
> You need to install Subversion packaging then
>

No, he doesn't have to. He's got TortoiseSVN, which is a GUI for svn.
He can checkout Django by creating a new folder, opening it, then
right clicking inside it, then choosing "SVN Checkout..." from the
context menu. Then fill out the dialog and click OK.

Regards,
BN

--

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




Re: datetime problems with Django application

2009-11-11 Thread Brian Neal

On Nov 10, 5:41 pm, BEC  wrote:
> I have a Django application running with mod_python on Apache. In
> settings.py I have set TIME_ZONE="America/New_York". Within my
> application I verify that os.environ['TZ'] is indeed set to this
> value. Within my view.py I use datetime.datetime.now() to create a
> time stamp that is stored in a model as a DateTimeField and viewed on
> a rendered html page.
>
> However, the times that I generate in my view are all off from what
> they should be by five hours. I've changed the time zone around
> "America/Chicago", "America/Anchorage" etc. no matter what I set
> TIME_ZONE to, I get the same wrong time (5 hours off).

Perhaps as Graham said there is a conflict with another application on
the server.

>
> If I go to the admin page and use the change entry page to modify the
> values stored in the database, the Time now link gives the correct
> time?

Explain this a bit more. You click on the little javascript thingy to
enter a time into the select box? Well that is purely client side.
That is your browser filling in the current time, not Django on the
server.

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



Re: how to exclude DateTime that are None

2009-11-02 Thread Brian Neal

On Nov 2, 3:44 pm, Felipe Reyes  wrote:
> Hi everybody,
>
> I'm using django 0.96, one of my models has a DateTimeField, I'm
> trying to exclude the from the queryset the rows that have null in the
> datetimefield, I'm using something like this:
>
> MyObject.objects.exclude(somedatecol=None)

I think you want the isnull field lookup:
http://docs.djangoproject.com/en/dev/ref/models/querysets/#isnull

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



Debugging SQL Queries: Correlating with Python Code

2009-10-22 Thread Brian Neal

Currently I am keeping an eye on SQL queries by displaying at the
bottom of my base template sql_queries. I'm seeing some queries that
look kind of strange to me, and I was wondering if there was a way to
somehow correlate the queries with my app's Python code.

For example, amongst the SQL queries on one of my pages, I see this
curious pair:

SELECT (1) AS `a` FROM `forums_topic` WHERE `forums_topic`.`id` = 10
UPDATE `forums_topic` SET `forum_id` = 4, `name` = Split Test #1,
`creation_date` = 2009-10-19 21:45:05, `user_id` = 2, `view_count` =
28, `sticky` = False, `locked` = False, `post_count` = 7,
`update_date` = 2009-10-22 20:46:11, `last_post_id` = 34 WHERE
`forums_topic`.`id` = 10

I *think* these two queries are coming from this code:

topic.view_count += 1
topic.save()

but I'm not sure. Is there a debugging technique or tool that could
tell me what line in the user code the SQL came from?

I'm curious what the SELECT (1) is doing and where it came from. Is
Django's ORM checking to see if the topic object exists before
updating it?

Thanks,
BN

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



Re: Showing unescaped HTML in Admin pages

2009-10-12 Thread Brian Neal

On Oct 12, 11:15 am, "ruidevie...@googlemail.com"
 wrote:
> Hi everyone,
>
> Is is possible to render unescaped HTML in admin pages?
>
Does this help? Start here:

http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_display

and then search for allow_tags.

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



Re: nested block definitions

2009-09-21 Thread Brian Neal

On Sep 21, 10:37 am, Daniel Roseman  wrote:
>
> Anything in a child template that is outside of a
> {% block %} is ignored.
>

I usually have a few {% load %} tags in child templates above {% block
%} to bring in needed template tags.

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



Re: django forum

2009-09-20 Thread Brian Neal

On Sep 20, 11:10 am, dijxtra  wrote:
> Is there a free robust django forum app? Or more precisely, a free and
> robust forum app which uses django.contrib.auth for authentication?
>
> Or should I just try out those several projects enabling django to
> access phpBB's user info and use phpBB3?

There are many that seem to be in progress. Not mentioned on the
Django wiki [1] is DjangoBB [2].

The quality and functionality seem to vary wildly. Ultimately I
decided to write my own. With the tools that Django provides, it
really isn't that hard (much to my surprise). I wanted some features
that the other projects didn't have, but more importantly I want to
know how it works, and for my hobby site, rolling my own was the best
course of action for me. YMMW of course.

[1] http://code.djangoproject.com/wiki/ForumAppsComparison
[2] http://djangobb.org/
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: DST or not

2009-09-05 Thread Brian Neal

On Sep 5, 4:03 pm, zweb  wrote:
> Is there any way to know if for a timezone , on a praticular date
> time, is DST active or not?
> it is required by localize command of pytz. How to find it
> programatically?
>
> >>> est_dt = eastern.localize(loc_dt, is_dst=True)
> >>> edt_dt = eastern.localize(loc_dt, is_dst=False)

I think normally you let pytz figure that out for you. That is_dst
parameter is not required by the localize function. I think it is only
used if you are doing tricky things.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: how to deploy an app that gets used by people in multiple time zones

2009-09-04 Thread Brian Neal

On Sep 4, 10:47 am, Margie  wrote:
>
> Can someone clarify what format dates and times are stored in when
> using just a standard DateTimeField?  Is my timezone encoded in the
> database or is some generic, non-timezone-specific date/time stored?

There is no timezone encoded. The dates/times are said to be "naive".

It is up to you to assign meaning to the time and to convert to the
appropriate timezone for your users.

You should probably review this:

http://docs.python.org/library/datetime.html

Regards,
BN

PS. The pytz library is useful for performing conversions between
timezones.
http://pytz.sourceforge.net/
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Does post_save signal need to be in models.py?

2009-07-11 Thread Brian Neal

On Jul 11, 12:54 pm, Ryan K  wrote:
> I am trying to avoid circular dependency issues  between signals.py
> and models.py. Is there any reason why I can't connect the post_save
> signal in signals.py itself (the function is connects with would be in
> the same file? Should I import it in the apps/__init__.py file to
> ensure the signal is installed?
>
That's what I typically do. In my __init__.py, I import signals. In
signals.py I have my signal handlers and connect calls.

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



Re: context objects get cached/stored across requests, somehow

2009-07-06 Thread Brian Neal

On Jul 6, 10:08 am, Haes  wrote:
> Hi,
>
> I've created a view which displays a simple list of all objects of one
> model. If a 'search_string' URL parameter is defined, the list is
> filtered by this search string and the search string itself will be
> displayed in the template as well.
> Please have a look at the complete view here:http://dpaste.com/hold/63722/
>
> The problem now is, that the 'search_string' context dict entry is
> always set to the last defined value, even if no 'search_string' URL
> parameter is passed.

I believe you have been hit with one of the famous Python gotchas.

http://www.ferg.org/projects/python_gotchas.html#contents_item_6

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



Re: Using formfield_overrides to add TinyMCE

2009-06-25 Thread Brian Neal

On Jun 25, 2:33 pm, Pes  wrote:
> Hi All,
>
> I feel like there’s something simple I’m overlooking here. I can't
> seem to get TinyMCE to work when I use the built-in widget from Django-
> TinyMCE. This works if I uncomment the Media class at the bottom, but
> the widget version of TinyMCE simply doesn't show up. Is there a
> better way to tell the formfield to render with the TinyMCE widget
> instead of formfield_overrides?
>

Maybe off-topic, but what are the advantages to using django-tinymce?
It was easy to use tinymce without any 3rd party support. I'm using
tinymce in some public views, in the admin, and on the admin for
flatpages. It was easy to do an in all cases without any external app
or code.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Encryption question

2009-06-23 Thread Brian Neal

On Jun 23, 8:39 am, daniel  wrote:
> Good morning,
>
> I have a MySQL (version 5.0.5 running on Ubuntu 8.04) database
> containing encrypted fields (the encryption was done using mysql's
> AES_ENCRYPT). The database is normally accessed by an application
> written in C++ and Qt. However, I also need to access the database
> thru a web server and I am getting started with django  (1.0).
>
[snip]
> Any suggestions on how I can mix the encryption/decryption of values
> using these two applications?
> Or is it possible for django to use MySQL functions such as
> AES_ENCRYPT/AES_DECRYPT in a query?
>

I don't know about the first part of your question, but you can use
raw SQL in Django:

http://docs.djangoproject.com/en/dev/topics/db/sql/#topics-db-sql

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



Re: Question IMAGE in Django

2009-06-23 Thread Brian Neal

Also check the permissions on your images. I had set the
FILE_UPLOAD_PERMISSIONS to 0640 in development, but this wasn't
correct for my production server. Ensure that Apache or whatever user
the webserver is running has read access to your images.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Apache 2.2 >> Forbidden You don't have a permission to access /static_media on this server

2009-06-23 Thread Brian Neal

On Jun 23, 5:29 am, MarcoCanali  wrote:
> I have this error message from apache 2.2 server when i try to access
> at mine static_media for my django project. Apache serve my project in
> django without static file such as css or image ...

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



Re: Django and CSS

2009-06-18 Thread Brian Neal

On Jun 18, 2:50 pm, Chris DPS  wrote:
> Hi,
>
> I'm new to Django.
> I've read the 
> doc:http://docs.djangoproject.com/en/dev/howto/static-files/?from=olddocs
> which is about static files but still do not quite understand what to
> call everything and it isn't working
> On my development machine, I want to use this hack and not deal with
> other servers.
> Please help.
>
> here is my file structure:
>
> /mysite/  - has all the .py files
> /mysite/templates/  - has all the html templates
> /mysite/templates/path_media/ - has the CSS document and pictures
>
> Now, how should I modify this:
>
> (r'^site_media/(?P.*)$', 'django.views.static.serve',
>         {'document_root': '/path/to/media'})
>
> '/path/to/media' should be changed to what?

Mine looks like this:

from django.conf import settings
...
if settings.DEBUG:
   urlpatterns += patterns('',
  (r'^static/(?P.*)$', 'django.views.static.serve',
{'document_root': settings.MEDIA_ROOT}),
   )

>
> And is this what I want for my style href? :
>
> 

http://docs.djangoproject.com/en/dev/ref/templates/api/#django-core-context-processors-media

>
> What about when I pull an image using the css document:
>
> url("site_media/foo.jpg")

Paths inside CSS files are relative to the CSS files themselves. I
typically use relative paths inside CSS files, e.g.

url("../images/foo.jpg")

Best,
BN

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



Re: Django for Google API - Google Search, Google Map

2009-06-18 Thread Brian Neal

On Jun 18, 5:42 pm, Olavgo  wrote:
> I want to write a website that I think will be using the Google API
> (search and map).
>
> Is there any special reason the do it with Python?  Django?

Well, I'm not real sure about the search API, but the Maps API is all
Javascript.

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



Re: Memcached, out of sockets

2009-06-16 Thread Brian Neal

On Jun 15, 7:28 pm, Miles  wrote:
> I've been running the python memcached connector for a while, without
> much trouble. But just today during a stress test of one of the feeds
> (read: many many requests expected), I've ran into an out of sockets
> situation.
>
> After every single request, the cache backend forces a disconnect from
> all memcached servers. That's no problem if you don't get too many
> hits, but after about ~5k requests in a minute, python just fails to
> connect to memcached and falls back to database access.
>
> Cause:
>
> Fixed #5133 -- Explicitly close memcached connections after each
> request
> (similar to database connection management). We can't effectively
> manage the
> lifecycle by pooling connections and recent versions of python-
> memcache can
> lead to connection exhaustion in some quite reasonable setups.
>
> Memcached is designed to help web apps hit insane throughput, not kill
> the whole server by exhausting all available sockets by forcing them
> all in TIME_WAIT... Without a decent amount of traffic, people
> wouldn't even bother to run memcached.
>
> Oh well, I'll be nooping the fix locally. That it added another 30%
> throughput on windows is just a bonus. If you plan to disable close
> with something like
> django.core.cache.backends.memcached.CacheClass.close = lambda x:
> None, make sure you also set memcache._Host._DEAD_RETRY = 5. Otherwise
> a broken socket can cause 30s of no cache on a thread, or worse, 30s
> of no cache at all when you restart memcached, instead of reconnecting
> on the next request. I thought I hit a bug the first I saw it happen.
>
> With a mod_wsgi deamon mode setup, max-requests=500, I'm not scared of
> leaking some sockets which gets freed after a few minutes at most.

Wellinstead of ranting about this here, why don't you open a
ticket and detail your findings. It is in the communities best
interest to have something like this fixed if it is indeed a problem.
Thanks.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Is there a version of @login_required that requires the user to log in as a specific user?

2009-05-25 Thread Brian Neal

On May 25, 3:41 am, Andy  wrote:
>
> But how do I stop user A from trying to edit the profile of user B?

You don't let them. You control which profile you get from and save to
the database, right? You look at the request.user object and only
manipulate the data associated with the user specified by request.user.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Is there a version of @login_required that requires the user to log in as a specific user?

2009-05-24 Thread Brian Neal

On May 24, 6:50 pm, Continuation  wrote:
> For example, I have a view edit_profile that edits a user's profile.
> Obviously I want to make sure that each user can edit his own profile
> only.
>
> So before the profile of user A is being edited by edit_profile, I
> want to make sure the current user is logged in as user A.
>
> Is there a decorator that can do that?
>
> Is there a decorator similar to @login_required that requires not only
> the user to be logged in, but also that he needs to be logged in as a
> specific user (user A in the above example)?

Well, typically you don't worry about that. If a user is requesting to
edit a profile, you simple pull up that user's profile.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Callable objects instead of functions in views.py

2009-05-20 Thread Brian Neal

On May 20, 8:33 am, Filip Gruszczyński  wrote:
> I was wondering: have you considered using some callable objects to
> serve requests in views.py instead of functions?

Sure, check out this blog post (not the only example):

http://www.screeley.com/entries/2009/apr/01/class-based-views-and-reusable-apps/

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



Re: A puzzling problem with admin

2009-05-13 Thread Brian Neal

On May 13, 10:13 am, andybak  wrote:
> Getting somewhere...
>
> I'm running on Django 1.0 via nginx/fcgi
>
> When I run via the dev server (leaving everything else the same) the
> problem goes away.
>
> How can the effects of a POST to a model form in admin be affected
> purely by switching between fcgi and the dev server?

What else is different? What versions of Django and Python are you
running in each environment?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Flatpages only works when settings.DEBUG = True

2009-05-04 Thread Brian Neal

On May 4, 10:28 am, Ronghui Yu  wrote:
> Hi,All,
>
> I am going to use Flatpages app for those simple pages. And everything
> works fine when settings.DEBUG is True, but when it is turned to False,
> a URL not configured in urlpatterns will trigger 500, not 404.

Do you have a 404.html error template? You need to have that before
flatpages will work when DEBUG is False. See the note titled "Ensure
that your 404 template works" in this section:

http://docs.djangoproject.com/en/dev/ref/contrib/flatpages/#module-django.contrib.flatpages

Its also a good idea to have a 500.html error template.

Best,
BN


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



Re: Problem with in long text fields in templates

2009-04-20 Thread Brian Neal

On Apr 20, 11:31 am, NoviceSortOf  wrote:
[...]
> When attempt to using {{ book.description }} in the template, it
> outputs all the  tags onto the screen,
> when what we want is actual line breaks.
>
[...]
>
> Can someone please give me a clue as to how to make this work or where
> to find information to make this work.

Check the Django docs for the filters linebreaks, linebreaksbr, and
safe.

http://docs.djangoproject.com/en/dev/ref/templates/builtins/#built-in-template-tags-and-filters
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: TemplateSyntaxError: Settings issue?

2009-04-16 Thread Brian Neal

On Apr 16, 11:33 am, Aneesh K  wrote:
>
> Why is the TemplateSyntaxError raised, and why don't I see this
> problem on my development server?
>
> Thanks!
> Aneesh

Could be a python path problem? Put the directory that has your
application in it on the python path. I think when you do the
manage.py command it puts the parent directory on the python path for
you (as an aid to new users).

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



Re: newbie: syncdb doesnt update schema after model change?

2009-04-16 Thread Brian Neal

On Apr 16, 11:00 am, gry  wrote:
> [django: 1.1 beta 1 SVN-10407, python 2.5.2, ubuntu]
> My first django toy app.  I've been working through the 
> tutorialhttp://docs.djangoproject.com/en/dev/intro/tutorial02/.
> I've already done a few cycles of  (change-model, ./manage.py syncdb)
> with success.
> I just added email and birthday fields to my Person model:
>
[snip]
>
> Why is my change not making it into the DB?  I even did "./manage.py
> flush" and it still fails on the email field.
>
> -- George

Because syncdb doesn't do that. See the note in the documentation as
to why:

http://docs.djangoproject.com/en/dev/ref/django-admin/#syncdb

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



Re: Converting from local DST to UTC

2009-04-14 Thread Brian Neal

On Apr 14, 7:26 pm, Jamie  wrote:
> I am working on an app that will export a calendar event to Google
> Calendar. Google Calendar requires that event datetimes be in UTC
> format. I can make the conversion from local (America/New_York) to UTC
> using pytz, but the time is off by an hour due to daylight savings
> time (Python thinks the offset is -0500 rather than -0400) so all of
> my exported events are off as a result.

pytz does adjust for daylight savings time, that is one of its primary
jobs.

>
> I'm first taking the naive datetime stored by Django and adding the
> local timezone pulled from settings.py then using astimezone(pytz.utc)
> to make the conversion to UTC. I'm not sure how to adjust for DST,
> especially since all the events will be in the future and DST will
> have to be calculated for each of them.

Try using 'US/Eastern' instead of 'America/New_York'. It might be
different.

This is how I am doing it (I'm also integrating with Google Calendar):

from django.utils.tzinfo import FixedOffset

d = datetime.datetime.now()
tz_name = 'US/Eastern'  # or whatever
tz = pytz.timezone(tz_name)  # create timezone
local = tz.localize(d)  # make naive datetime localized
zulu = local.astimezone(FixedOffset(0))  # convert to UTC
s = zulu.strftime('%Y-%m-%dT%H:%M:%S.000Z')

I think I probably could have used pytz.utc instead of FixedOffset(0).
It's the same idea. But at least now this thread has Django
content. :-)

Hope that helps,
BN





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



Re: Trouble with DateField

2009-04-13 Thread Brian Neal

On Apr 13, 11:47 am, Brandon Taylor  wrote:
> Hi everyone,
>
> I need a sanity check here. I'm using a jQueryUI DatePicker, with the
> dateFormat option set to 'yy-mm-dd', which is returning a date in -
> MM-DD format, if I check my request.POST values.
>
> I have a DateField - "effective_from", on my model, and am using a
> corresponding ModelForm. When I check the form.cleaned_data
> ['effective_from'], I get a Python datetime object as: 2009-04-13.
>
> However, I'm getting an exception error for the view, saying:
> ValidationError at /codes/create/
> Enter a valid date in -MM-DD format.
>
> I have also parsed the date by hand:
> , MM, DD = map(int, request.POST['effective_from'].split('-'))
> effective_from = datetime.date(, MM, DD)
>
> The portion of the view in question is:
> form = ActivityCodeForm(request.POST)
>         if form.is_valid():
>             activity_code = form.save(commit=False)
>             activity_code.created_by = request.user
>             activity_code.category = Category.objects.get(pk=int
> (form.cleaned_data['kategory']))
>             activity_code.effective_from = form.cleaned_data
> ['effective_from']
>             activity_code.slug = slugify(form.cleaned_data['title'])
>             activity_code.save()
>
> Can anyone see what I'm doing wrong here?

Here:

activity_code.effective_from = form.cleaned_data['effective_from']

You are assigning a string to what I assume is a models.DateTimeField
or DateField. I don't think that works. You need to turn the string
into a Python datetime object first. I think this is done
automatically for you if you were using a ModelForm.

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



Re: Use Python to parse HTML and integrating said script into Django

2009-04-13 Thread Brian Neal

On Apr 13, 9:44 am, Tonne  wrote:
> It's the calendar with the unusual form/structure  that I'm
> struggling to implement with the stock Django tools.
>
> I'll take a step back and give it another shot with logic in view and
> parsing in the template.

I'm not sure what you mean by "parsing"...I am assuming you mean
"generating".

But it sounds to me like you might want to look into creating your own
template tag to generate the calendar HTML. I'd rather do that than go
nuts with nested loops inside a template.

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



Re: Mulitple Time Zone support?

2009-04-12 Thread Brian Neal

On Apr 12, 7:15 pm, ydjango  wrote:
> What is the best way to provide multiple Time zone support?

Definitely check out the Python pytz module.

> (Also where can I get list of all time zones to populate the  select
> dropdown.)
>

There is almost 400 time zones in the "common timezones" in pytz. The
timezones are of the forum "area/city", so I created a drop down for
area and then a 2nd drop down for city (with Javascript that populates
the city based on the area chosen). That's still a lot of timezones to
choose from but it was better than having 400 in one list.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



  1   2   >