Upstart script

2010-09-18 Thread Bret W
Does anyone have an upstart script that they use with manage.py
runfcgi?

I have come up with the one below, but it hangs when I try to start
it.
I've tried other scripts, but they either spawn lots of instances or
don't respawn when the main instance dies.

Any help would be appreciated.


# configuration variables.
# You'll want to change thse as needed
env DJANGO_HOME=/home/django/
env DJANGO_PORT=8080
env DJANGO_HOST=127.0.0.1

respawn

expect daemon

exec /usr/bin/python /home/django/project/manage.py runfcgi
method=prefork host=$DJANGO_HOST port=$DJANGO_PORT minspare=1
maxspare=2 daemonize=false pidfile='/home/django/project/django.pid' --
pythonpath='/home/django/project/packages'

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

2009-02-03 Thread Bret W



On Feb 3, 10:03 am, brad  wrote:
> You could use the built-in __str__ method on now.year.
> In [11]: now.year.__str__()
> Out[11]: '2009'
>
> In [12]: now.year.__str__() == '2009'
> Out[12]: True
>
> In your template you'd do something like this:
> {% ifequal year month.year.__str__ %}

Doh! I didn't even think about the built-in methods being available in
templates.

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



ifequal and DateQuerySet objects

2009-02-02 Thread Bret W

I've run into a problem with ifequal in one of my templates.

I'm using date-based generic view to display all objects for a given
year.
urls.py:
(r'^taken/(?P\d{4})/$' ...

Part of the extra_context I pass is a DateQuerySet object:
months = Photo.objects.dates('date_taken', 'month', order='DESC')

In my template, I have the following:
{% for month in months %}
{% ifequal year month.year %}
...

It always evaluates to false.

I know this is because Python won't handle the casting:

>>> from datetime import datetime
>>> now = datetime.now()
>>> now.year == 2009
True
>>> now.year == "2009"
False
>>>

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



Custom middleware to integrate with Facebook Connect

2008-12-14 Thread Bret W

I just wrote a small bit of middleware to allow Facebook users to log
into my Django site with Facebook Connect.

If you're looking to do something similar, check out my post:
http://nyquistrate.com/django/facebook-connect/
--~--~-~--~~~---~--~~
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: Admin 500 Error

2008-09-09 Thread Bret W



On Sep 8, 9:43 pm, "Karen Tracey" <[EMAIL PROTECTED]> wrote:

> I am aware of one problem reported with the admin home page and debug set to
> False.  It is:
>
> http://code.djangoproject.com/ticket/8110

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



Re: Admin 500 Error

2008-09-08 Thread Bret W

Sorry to post yet again.

Two things I forgot to mention -- this error only happens on the admin
home page and all of my INSTALLED_APPS should be valid and seem to be
functioning 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-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Admin 500 Error

2008-09-08 Thread Bret W

On Sep 8, 8:57 pm, Malcolm Tredinnick <[EMAIL PROTECTED]>
wrote:
> Because that's when Django is not going to use the debugging page, but
> rather display your 500 template. When DEBUG=True, you will see the nice
> debugging page, but that's for development purposes, not for general
> production use (although it can be useful to have it on for brief
> periods in production to diagnose problems).

I probably wasn't very clear.

When DEBUG = True, the admin loads just fine.

My problem is that I can't get the admin to fail when debugging is
turned on, so I can never see the helpful Django debugging page.

Further, I don't believe any objects are passed to the 500 template,
so I can't display errors using my template. That's why I removed my
500.html template -- so that mod_python would throw the (nasty
looking) error.

I'm trying to figure out a) why the admin is throwing errors only when
DEBUG=False and b) how I can display the source of the error.

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



Admin 500 Error

2008-09-08 Thread Bret W

I can only get this error to show up if DEBUG is set to False, but it
happens consistently when debugging is off.

MOD_PYTHON ERROR

ProcessId:  10229
Interpreter:'webfaction.com'

ServerName: 'webfaction.com'
DocumentRoot:   '/home/user/webapps/mysite/django_static'

URI:'/admin/'
Location:   '/'
Directory:  None
Filename:   '/home/user/webapps/mysite/django_static/admin'
PathInfo:   '/'

Phase:  'PythonHandler'
Handler:'django.core.handlers.modpython'

Traceback (most recent call last):

  File "/home/user/lib/python2.5/mod_python/importer.py", line 1537,
in HandlerDispatch
default=default_handler, arg=req, silent=hlist.silent)

  File "/home/user/lib/python2.5/mod_python/importer.py", line 1229,
in _process_target
result = _execute_target(config, req, object, arg)

  File "/home/user/lib/python2.5/mod_python/importer.py", line 1128,
in _execute_target
result = object(arg)

  File "/home/user/lib/python2.5/django/core/handlers/modpython.py",
line 222, in handler
return ModPythonHandler()(req)

  File "/home/user/lib/python2.5/django/core/handlers/modpython.py",
line 195, in __call__
response = self.get_response(request)

  File "/home/user/lib/python2.5/django/core/handlers/base.py", line
128, in get_response
return self.handle_uncaught_exception(request, resolver, exc_info)

  File "/home/user/lib/python2.5/django/core/handlers/base.py", line
160, in handle_uncaught_exception
return callback(request, **param_dict)

  File "/home/user/lib/python2.5/django/views/defaults.py", line 88,
in server_error
t = loader.get_template(template_name) # You need to create a
500.html template.

  File "/home/user/webapps/mysite/django_projects/bretwcom/
__init__.py", line 11, in cached_get_template
template_cache[template_name] = t =
original_get_template(template_name)

  File "/home/user/webapps/mysite/django_projects/bretwcom/
__init__.py", line 11, in cached_get_template
template_cache[template_name] = t =
original_get_template(template_name)

  File "/home/user/lib/python2.5/django/template/loader.py", line 80,
in get_template
source, origin = find_template_source(template_name)

  File "/home/user/lib/python2.5/django/template/loader.py", line 73,
in find_template_source
raise TemplateDoesNotExist, name

TemplateDoesNotExist: 500.html

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Nothing shows up in the Apache log, and since
django.views.defaults.server_error passes an empty Context object, the
only way I can see what's happening is to have mod_python throw the
error.

Does anyone know why this is happening?  Any leads would be
appreciated.

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



Re: New Django Site

2008-05-22 Thread Bret W

Thanks for all of the feedback!

I no longer require users to enter employer information, and I've
listed what I track (IPs for spam).

Vault.com collects similar data, so I hope there won't be any legal
issues, but I've added a small disclaimer and I'll keep my fingers
crossed.

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



New Django Site

2008-05-21 Thread Bret W

Hey all-

Over the past few evenings, I've put together a simple site for
submitting and listing job and salary information.

There are several more complex surveys and sites for this type of
information, but none that are quick and easy.

I'd appreciate the Django Community's thoughts on the site.

It's here:  http://www.howmuchdoyoumake.net/

If this testing goes well, I hope to keep the information entered, so
please be honest.
That said, I might have to reset the app again before really
launching, so please don't be upset if what you enter is deleted.

Thanks for your thoughts and opinions!

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



Re: Can Django have unique user homepage?

2008-04-26 Thread Bret W

And that's just one way, of course.

On Apr 26, 5:01 pm, Bret W <[EMAIL PROTECTED]> wrote:
> Sure.
>
> You'd need to create a profile model where this information could be
> stored.http://www.djangoproject.com/documentation/authentication/#storing-ad...
>
> You'd then just create forms for inputing the parameters you wanted to
> let users 
> control.http://www.djangoproject.com/documentation/newforms/#generating-forms...
>
> After you've allowed users to input preferences in their profile,
> you'd just need to get the profile (see Django book), and use the
> stored parameters in your template.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Can Django have unique user homepage?

2008-04-26 Thread Bret W

Sure.

You'd need to create a profile model where this information could be
stored.
http://www.djangoproject.com/documentation/authentication/#storing-additional-information-about-users

You'd then just create forms for inputing the parameters you wanted to
let users control.
http://www.djangoproject.com/documentation/newforms/#generating-forms-for-models

After you've allowed users to input preferences in their profile,
you'd just need to get the profile (see Django book), and use the
stored parameters in your template.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Login issue

2008-04-26 Thread Bret W

I have a login form on my homepage:


Username:
Password:



The homepage uses template fragment caching, but this block is not
cached (although I don't know why it couldn't be).  I'm not using CSRF
middleware.

There are many times when I can enter a username and password, click
the "login" button, and get the username/password don't match error.

The error page (/accounts/login, using example template from docs)
automatically fills in the username and password fields, and I can
just hit "login" again and I'm successfully logged in.  This means my
credentials were posted correctly.

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



Caching and comments

2008-04-26 Thread Bret W

This may be exceedingly obvious, but it took me a little bit of
Googling for "template fragment caching expiry" before I realized
there was an easier way to do what I was looking for.

I use template fragment caching (so simple!), but it's annoying when
someone comments and his comments don't show up for several minutes.

In order to create a new cached block when a new comment is received,
one simply needs to put the comment_count into the cache tag's list of
arguments.

- E.g. -
{% get_free_comment_count for blog.entry object.id as comment_count %}
{% cache 300 entry_comments object.id user.is_authenticated
comment_count %}

The two downsides that I see are:
   * the need to hit the database to get the comment count
   * the creation of a new cache object while retaining the old one

If you are receiving hundreds of comments a minute, this system would
quickly balloon out of control, but it's a nice, simple solution for a
personal site.

Does anyone have a better way to do this, excluding using the low-
level cache API?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Manually ordering content

2008-02-18 Thread Bret W

While that will allow content items to be ordered by a field in the
model, I'm looking for a way to arbitrarily order items.  I don't
think the ordering attribute will solve this problem.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Manually ordering content

2008-02-18 Thread Bret W

I never really heard anything back on this, so I built something based
on the models in my last message.

The details and code are here:
http://www.nyquistrate.com/django/orderedlist/

I'd appreciate any feedback you might have.  Hopefully others will
find this code useful.

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



Re: Deploying Django - can't get past the welcome screen

2008-02-16 Thread Bret W

Could you post your urls.py and settings 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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Deploying Django - can't get past the welcome screen

2008-02-16 Thread Bret W

Have you restarted the Web server?  Perhaps caching is playing a role
here.
The admin section should be working no problem, as long as the
settings and urls files are as described.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Deploying Django - can't get past the welcome screen

2008-02-16 Thread Bret W

Have you edited your urls.py file?

You'll need to make sure the admin site is enabled by uncommenting
this line:
(r'^admin/', include('django.contrib.admin.urls')),

And you'll also need to make sure you have:
'django.contrib.admin',
in the INSTALLED_APPS section of your settings.py file.  Make sure to
run ./manage.py syncdb after adding it.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Manually ordering content

2008-02-16 Thread Bret W

Hello all-

I'm trying to figure out the best way to manually order objects within
a template.

I have a couple of pages on which I would like to be able to hand-pick
content to fill certain areas.

I searched through the treads of this list, and couldn't find a "best
practice," so I thought I'd throw the question out again.

Here's what I've come up with:

== Model ==
page/models.py

from django.db import models
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes import generic

class Page(models.Model):
name = models.CharField(max_length=200)
content_type = models.ForeignKey(ContentType)

class Meta:
unique_together = (('name', 'content_type'))

class Admin:
pass

def __unicode__(self):
return self.name

class OrderedItem(models.Model):
position = models.PositiveIntegerField()
page = models.ForeignKey(Page)
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
content_object = generic.GenericForeignKey('content_type',
'object_id')

class Meta:
unique_together = (('position', 'page', 'content_type'))

== End Model ===

I can then add order = generic.GenericRelation(OrderedItem) to any
other model.

This will allow me to do:
>>> p = Page(name='homepage')
>>> p.save()

(Entry is an example model, one that has order =
generic.GenericRelation(OrderedItem))
>>> e = Entry(headline='test')
>>> e.save()

>>> o1 = OrderedItem(position=1,page=p,content_object=e)
>>> o1.save()

>>> e2 = Entry(headline='fubar')
>>> e2.save()

>>> o2 = OrderedItem(position=2,page=p,content_object=e2)
>>> o2.save()

>>> ordered_items OrderedItem.objects.order_by('position').filter(page=p)
>>> for item in ordered_items:
... print item.content_object.headline
...
test
fubar

So, I could pass ordered_items to a template, which would allow me to
display objects in an order I specified, which is great.

So, I have two questions:

1.  Is there a better way to do this?
2.  I can't quite wrap my head around how to administer these items
via the admin interface.  Is there a way to do so without creating
custom admin templates?

Thanks for any guidance.




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



Re: About to give up!!!

2008-02-09 Thread Bret W

Do you have DEBUG set to True in your settings.py?

I don't understand why it would return a status code of 200 (OK) if it
didn't fetch and serve the file.

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



Template fragment caching gotcha

2008-02-09 Thread Bret W

Template fragment caching (http://www.djangoproject.com/documentation/
cache/#template-fragment-caching) tags must be within a {% block %}
tag if used in a template with inheritance.

This may be apparent to some, but my brain thought to put it outside
of the block I wanted to cache.  It fails silently (which is normal).

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



Re: About to give up!!!

2008-02-09 Thread Bret W

Brandon-

I believe that the reason it's not serving the file is because your
url pattern does not give a name to the string that you're capturing
(the .* in your pattern).  Django expects this to be given the name
"path," and in Python regular expressions, you do that with the
syntax:

(?P.*)

Try changing that section of your urls.py to:
urlpatterns += patterns('django.views',
(r'^public/(?P.*)$', 'static.serve', {'document_root': '/Users/
bt/django_projects/btaylor_design/public'}),

Here's the documentation:
http://www.djangoproject.com/documentation/static_files/

Keep in mind that Python (Django) will be serving these files, and as
the documentation says, this is inefficient.  When you make this site
live, you'll want the files to be served directly by your Web server.
There's an example configuration for Apache on the above page.

Hope this helps.  Don't give up!


Brandon Taylor wrote:

> urlpatterns = patterns('',
> (r'', home),
>
> # Uncomment this for admin:
> #(r'^admin/', include('django.contrib.admin.urls')),
> )
>
> if settings.DEBUG:
> urlpatterns += patterns('django.views',
> (r'^public/(.*)$', 'static.serve',
> {'document_root': '/Users/bt/django_projects/btaylor_design/public'}),
> )
>
>
> Can ANYONE give me a definitive answer on why this thing won't load so
> much as a simple image, with a src set to: http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---