Re: problems with admin links after upgrade 1.1 -> 1.3 dev

2011-03-28 Thread jd
That worked! Thank you S much! never would have found that :)

On Mar 28, 5:59 pm, Karen Tracey  wrote:
> On Mon, Mar 28, 2011 at 1:39 PM, jd  wrote:
> > I upgraded to 1.3 dev from 1.1 and now my admin links don't work. the
> > page domain.com/admin/ works and it shows my models listed, but when
> > clicking on any of them it doesn't leave the model list page. Instead
> > it keeps stacking the url I want to visit onto the existing url. I.e.
>
> > domain.com/admin/
>
> > # shows app and model list
>
> > click on link for app: survey model: surveyResponse
>
> > url is now domain.com/admin/survey/surveyResponse/ but is still shows
> > the app/model list page.
>
> > [snipped]
> > Anyone know what this issue might be?TIA
>
> Check your admin url pattern. It should be:
>
> (r'^admin/', include(admin.site.urls)),
>
> not:
>
> (r'^admin/(.*)', include(admin.site.urls)),
>
> That 2nd one is half-converted from the old 1.0 admin.site.root pattern and
> will exhibit the behavior you describe.
>
> Karen
> --http://tracey.org/kmt/

-- 
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: problems with admin links after upgrade 1.1 -> 1.3 dev

2011-03-28 Thread Karen Tracey
On Mon, Mar 28, 2011 at 1:39 PM, jd  wrote:

> I upgraded to 1.3 dev from 1.1 and now my admin links don't work. the
> page domain.com/admin/ works and it shows my models listed, but when
> clicking on any of them it doesn't leave the model list page. Instead
> it keeps stacking the url I want to visit onto the existing url. I.e.
>
> domain.com/admin/
>
> # shows app and model list
>
> click on link for app: survey model: surveyResponse
>
> url is now domain.com/admin/survey/surveyResponse/ but is still shows
> the app/model list page.
>
> [snipped]
> Anyone know what this issue might be?TIA
>

Check your admin url pattern. It should be:

(r'^admin/', include(admin.site.urls)),

not:

(r'^admin/(.*)', include(admin.site.urls)),

That 2nd one is half-converted from the old 1.0 admin.site.root pattern and
will exhibit the behavior you describe.

Karen
-- 
http://tracey.org/kmt/

-- 
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: Looking for IDE + FTP

2011-03-28 Thread Karen McNeil
Just wanted to give you all an update:  I started using Aptana Studio
with the PyDev plug-in and I'm really liking it; I think it was just
what I needed.

Thanks for all the suggestions!

~Karen

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



Django Notification - can't send notifications

2011-03-28 Thread justin jools
can't send notifications

have tried adding (in notification models.py):

if notification:
   notification.send([self.from_user], "friends_accept",
{"invitation": self, "new_user": self.to_user})

but does nothing although I can enter notices manually in admin.

-- 
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 couple question about Feeds and GIS

2011-03-28 Thread Corey Farwell
I have learned that GeoRSSFeed is a feed_type and that there is a
current ticket for my latter problem
http://code.djangoproject.com/ticket/15707

On Mar 28, 4:30 pm, Corey Farwell  wrote:
> So i have the impression that django.contrib.gis.feeds.Feed outputs a
> georss feed when supplied geometry. what is the purpose of
> django.contrib.gis.feeds.GeoRSSFeed?
>
> Also is there any reason why gis.feeds.Feed still uses the deprecated
> syndication.feeds.Feed instead of the new syndication.views.Feed?

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



A couple question about Feeds and GIS

2011-03-28 Thread Corey Farwell
So i have the impression that django.contrib.gis.feeds.Feed outputs a
georss feed when supplied geometry. what is the purpose of
django.contrib.gis.feeds.GeoRSSFeed?

Also is there any reason why gis.feeds.Feed still uses the deprecated
syndication.feeds.Feed instead of the new syndication.views.Feed?

-- 
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: Just started Django - please help clarify web site configuration strategy

2011-03-28 Thread Jumpfroggy
> Basically, the question is - when a web
> application starts there is a number of things that needs to be
> available any time any request. Some of them are really static in
> nature - for example, pagination parameters;

If these are static values, a good place to put them is in the
settings.py file.  I put things like APP_NUMBER_POSTS_PER_PAGE = 10 in
settings.py.  As a bonus, they can be overridden with your
local_settings.py file (if you use one).  Alternately, you could have
an "app_settings.py" file where you store a bunch of static values,
and just import that file into anywhere it's needed (like your
views.py).

> some of them are more
> dynamic - for example, menu options.

If these menu options are application wide, but change often, then I'd
create models to represent them, and store them in the database.  If
these are server wide config settings that only change once in a
while, then I'd add them to settings.py (since you probably want those
hardcoded and recorded in your source-control system.  If those
settings are per-user, then they'd either be cookies (browser-based),
session vars (session-based), or a settings stored in the user's
profile (ie. stored in DB as a model, the most permanent of the 3).

> Things get more interesting when such data are read from the database.
> So far what I see is that all that stuff should be places in the
> request context (hopefully cached). It can be done more elegantly if
> custom context processor(s) are created. But we are still rely on
> request contexts. Unless I am missing something?

In django, contexts are tied to requests.  There really isn't an
"application context".  If you have a scenario that doesn't fit into
a) settings.py vars, or b) database-backed settings, give us more
details and we can figure out how best to store them.  Context
processors are convenient ways to automatically run code for each
request, but I normally just use those to automatically add certain
settings.py vars to each context (like MEDIA_URL, current user, etc).

> It seems that although request contexts combined with caching can
> help, it is way too complex for the purposes of initializing the
> application.

What's the caching for?

> Which leads me to another question - is there any callback mechanism
> when Django application starts? I guess what I am looking is a place
> to make one-time queries, store data in a static member - and viola, I
> have my application context.

There is no callback mechanism.  You can add code to any file
(models.py is a good place), and you can do some tricky python-fu to
make sure it only runs once per process, but that's a bit of a hack.
The real question is - do you really need this?  Is there a better
way?

The most helpful thing would be an example - what is a real-world
value you'd like to store in an "application context", and how would
you use it?  Then we can give you some pointers on how to do things
the django way.

As an aside, I know asp (and other web servers) run as if you have a
single process, with a single set of static vars, and you can pretend
that everything is running as a single application.  In django, it's
often better to think about things as "stateless"... ie. there's no
guarantee that there is a single, persistent app running.  There's
just your code that runs when needed.  For example, if you run apache
+ django with multiple processes, then they are separate.  Changes to
static vars in one process will not affect the same var in other
processes.  So forget all about static classes/objects/variables, as
they're probably inappropriate for most use cases.

Also, you might be over-optimizing.  If you're worried about the
performance hit of loading a set of values for each request (such as
the settings.py values above), you should profile / measure it.  The
performance hit of loading such vars would be almost completely
unmeasurable in most cases.  So you could just load up such settings
for each request instead of keeping them in static memory, which
really is an optimization (ie. trading memory space vs. CPU & disk
access).

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



django-simple-friends + notifications: how to intergrate?

2011-03-28 Thread justin jools
I have both simple-friends and notifications running and workign and
have set up notice types.

How do I use signals from friend request for instance to trigger
notice types?

examples

simple-friends:

class FriendshipRequest(models.Model):
from_user = models.ForeignKey(User,
related_name="invitations_from")
to_user = models.ForeignKey(User, related_name="invitations_to")
message = models.CharField(max_length=200, blank=True)
created = models.DateTimeField(default=datetime.datetime.now,
   editable=False)
accepted = models.BooleanField(default=False)

class Meta:
verbose_name = _(u'friendship request')
verbose_name_plural = _(u'friendship requests')
unique_together = (('to_user', 'from_user'),)

def __unicode__(self):
return _(u'%(from_user)s wants to be friends with %
(to_user)s') % \
{'from_user': unicode(self.from_user),
 'to_user': unicode(self.to_user)}

def accept(self):
Friendship.objects.befriend(self.from_user, self.to_user)
self.accepted = True
self.save()
signals.friendship_accepted.send(sender=self)

def decline(self):
signals.friendship_declined.send(sender=self, cancelled=False)
self.delete()

def cancel(self):
signals.friendship_declined.send(sender=self, cancelled=True)
self.delete()

notifications:

 
notification.send(Friendship.objects.friends_for_user(self.owner.id),
"listing_new", {'listing':self, }, )

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



How can I integrate performance measurements with unit tests?

2011-03-28 Thread Jumpfroggy
I have django testing setup, and it runs a few tests.  I would like to
measure the time each test takes to run, and record that in a data
file I can access later.

How do I record the time each test takes?  If this is not (easily)
possible with unit tests, then is there another easy way to test view
times?

My goal is to be able to run a performance test for each revision of
the code, and be able to track performance improvements / regressions
as development happens.

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: OT: Django broke my Dropbox

2011-03-28 Thread Shawn Milochik
On Mon, Mar 28, 2011 at 5:35 PM, Petite Abeille
 wrote:
>
> On Mar 28, 2011, at 11:33 PM, Xavier Ordoquy wrote:
>
>> I'm just tired of grepping code when subversion is the VC used ;)
>
> ack!
>
> http://betterthangrep.com/


Awesome! I'd never seen that before, and it looks great. It makes me
glad my Dropbox broke.

Also, when I first read your post I thought "ack!" mean
"acknowledged," with a big exclamation point because you've suffered
the same way. Ha!

Thanks,
Shawn

-- 
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: OT: Django broke my Dropbox

2011-03-28 Thread Petite Abeille

On Mar 28, 2011, at 11:33 PM, Xavier Ordoquy wrote:

> I'm just tired of grepping code when subversion is the VC used ;)

ack!

http://betterthangrep.com/

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



Re: OT: Django broke my Dropbox

2011-03-28 Thread Xavier Ordoquy
> For fun, I checked out the official Subversion, Git, and Mercurial
> repos this afternoon:
> 
> svn:
>22,986 directories
> 
> git:
>2,563 directories
> 
> hg:
>5,291 directories
> 
> I don't know whether this displays an inefficiency of Subversion or
> whether converting from Subversion to Git or Mercurial somehow cleans
> it up. But in any case I thought it was interesting enough to share,
> and might help others on this list who might unknowingly have the same
> problem.
> 
> Shawn

Hi Shawn,

It isn't really surprising as Subversion creates .svn subdirectories with other 
subdirectories for each "normal" directory of your project.
I'm just tired of grepping code when subversion is the VC used ;)

Regards,
Xavier.

-- 
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: Two way many-to-many relationships

2011-03-28 Thread Dilan
Thanks Mike !

That was a really helpful page that I missed in Doc.  In this
particular case 1 solves 2.

Dilan

On Mar 27, 10:09 pm, Mike Ramirez  wrote:
> On Sunday, March 27, 2011 02:32:15 pm Dilan wrote:
>
> > Hi All,
>
> > I'm working on a model similar to
> >http://docs.djangoproject.com/en/1.3/topics/db/models/#extra-fields-o...
> > -to-many-relationships .
>
> > Say, I need to add the field, groups = models.ManyToManyField(Group,
> > through='Membership') to Person class
>
> > Two questions:
> > 1. In Django, is this allowed?
>
> Yes.  But you'll want to have a unique related_name also, iirc.
>
> > 2. In Python, how do you forward declare Group class for this code to
> > work?
>
> This isn't really a python way but a django way [1]
>
> ManyToManyField('Group', ...)
>
> In python you can't forward declare outside of the module the object is in.
> there is no equivalent to Class Test; as in c++. (you can dynamically import
> with the imp module though but this isn't forward declaring).
>
> Django models load in such a way that it doesn't know modules that come after
> it in the same module/file and this was to address that.
>
> scroll down just a tad on the link below to get info on the related_name
> attribute.
>
> HTH,
>
> Mike
>
> [1]http://docs.djangoproject.com/en/1.3/ref/models/fields/#lazy-relation...
> --
> Adults die young.

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



[ANN] fhurl release 0.1.1

2011-03-28 Thread Amit Upadhyay
http://packages.python.org/fhurl/

This is a generic view for form handling. First release.

Feedback and comments appreciated.

-- 
Amit Upadhyay
+91-9820-295-512

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



OT: Django broke my Dropbox

2011-03-28 Thread Shawn Milochik
I've been having a lot of problems lately with Dropbox failing to sync.

To make a long story short, it's Subversion's fault. Dropbox on Linux
fails when you have more than 10,000 directories in your Dropbox
folder. The SVN checkout of Django itself has over 22,000 directories.
Deleting the svn trunk from my Dropbox brought my directory count down
to about 1,300 and fixed all my syncing problems.

For fun, I checked out the official Subversion, Git, and Mercurial
repos this afternoon:

svn:
22,986 directories

git:
2,563 directories

hg:
5,291 directories

I don't know whether this displays an inefficiency of Subversion or
whether converting from Subversion to Git or Mercurial somehow cleans
it up. But in any case I thought it was interesting enough to share,
and might help others on this list who might unknowingly have the same
problem.

Shawn

-- 
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 Problem with Django reverse()

2011-03-28 Thread Ajay
Hi Alendit,

Thanks for explanation. I understand its not necessary but want to
understand how reverse() works-checked source but did not understand
much. my doubt is if I use something like :

reverse('django.contrib.auth.views.password_change_done'),

and have url entry like as follows.

 url(r'^change-password-done/$', 'profile.views.password_change_done',
name='django.contrib.auth.views.password_change_done'),

now I do not have any entry with "function string" with
'django.contrib.auth.views.password_change_done', but I have an entry
with name='django.contrib.auth.views.password_change_done', so django
should pick this. But it complains it can not find reverse for this.
It should either pick it from
django.contrib.auth.views.password_change_done or should pick the name
entry from my urlconf.

Is it because my name is separated with '.' ? Is there any such
constraints on the name entry or is it the problem because a view with
this name already exists in auth app.

Thanks for the help.


On Mar 27, 7:09 pm, Alendit  wrote:
> Hi,
>
> if only one url is bound to a controller there is no need for a name
> argument. When you are specifying a name for an expression and it have
> got the same name as the controller a conflict arise. Just drop the
> name argument and it should work.
>
> Alendit.
>
> On 27 Mrz., 09:54, Ajay  wrote:
>
> > I am missing something really basic here.
>
> > I am trying to reuse django's change password views. I have following
> > in urls.py:
>
> > (r'^change-password/$', 'profile.views.change_password',
> > {},'change_password'),
> > url(r'^change-password-done/$', 'profile.views.password_change_done',
> > name='django.contrib.auth.views.password_change_done'),
>
> > and in corresponding views.py:
>
> > from django.contrib.auth.views import password_change,
> > password_change_done
>
> > def
> > change_password(request,template_name="password_change_form.html"):
> >     """Change Password"""
> >     return password_change(request,template_name=template_name)
>
> > def password_change_done(request,
> > template_name="password_change_done.html"):
> >     return render_to_response(template_name,(),context_instance=
> > RequestContext(request))
>
> > but I am getting following error:
>
> >     Reverse for 'django.contrib.auth.views.password_change_done' with
> > arguments '()' and keyword arguments '{}' not found.
>
> > looked at the source and saw this line:
>
> > post_change_redirect =
> > reverse('django.contrib.auth.views.password_change_done')
>
> > If I change my urls.py entry to following , I do not get the above
> > error:
>
> > url(r'^change-password-done/$',
> > 'django.contrib.auth.views.password_change_done', name='anything'),
>
> > but I am confused as reverse() should look-up using the "name"
> > parameter? What am I missing here?
>
> > I am using django 1.2.3

-- 
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: simple friends template help

2011-03-28 Thread justin jools
I think I've resolved some of my problems:

I was wondering how to list friend request but now I think I have to
use Django-Notifications to pick up the signals, would this be right?


complete models:

class FriendshipRequest(models.Model):
from_user = models.ForeignKey(User,
related_name="invitations_from")
to_user = models.ForeignKey(User, related_name="invitations_to")
message = models.CharField(max_length=200, blank=True)
created = models.DateTimeField(default=datetime.datetime.now,
   editable=False)
accepted = models.BooleanField(default=False)

class Meta:
verbose_name = _(u'friendship request')
verbose_name_plural = _(u'friendship requests')
unique_together = (('to_user', 'from_user'),)

def __unicode__(self):
return _(u'%(from_user)s wants to be friends with %
(to_user)s') % \
{'from_user': unicode(self.from_user),
 'to_user': unicode(self.to_user)}

def accept(self):
Friendship.objects.befriend(self.from_user, self.to_user)
self.accepted = True
self.save()
signals.friendship_accepted.send(sender=self)

def decline(self):
signals.friendship_declined.send(sender=self, cancelled=False)
self.delete()

def cancel(self):
signals.friendship_declined.send(sender=self, cancelled=True)
self.delete()


class FriendshipManager(models.Manager):
def friends_of(self, user, shuffle=False):
qs = User.objects.filter(friendship__friends__user=user)
if shuffle:
qs = qs.order_by('?')
return qs

def are_friends(self, user1, user2):
return bool(Friendship.objects.get(user=user1).friends.filter(
 
user=user2).count())

def befriend(self, user1, user2):
Friendship.objects.get(user=user1).friends.add(
 
Friendship.objects.get(user=user2))

def unfriend(self, user1, user2):
Friendship.objects.get(user=user1).friends.remove(
 
Friendship.objects.get(user=user2))


class Friendship(models.Model):
user = models.OneToOneField(User, related_name='friendship')
friends = models.ManyToManyField('self', symmetrical=True)

objects = FriendshipManager()

class Meta:
verbose_name = _(u'friendship')
verbose_name_plural = _(u'friendships')

def __unicode__(self):
return _(u'%(user)s\'s friends') % {'user':
unicode(self.user)}

def friend_count(self):
return self.friends.count()
friend_count.short_description = _(u'Friends count')

def friend_summary(self, count=7):
friend_list = self.friends.all().select_related(depth=1)
[:count]
return u'[%s%s]' % (u', '.join(unicode(f.user) for f in
friend_list),
u', ...' if self.friend_count() > count
else u'')
friend_summary.short_description = _(u'Summary of friends')


class UserBlocks(models.Model):
user = models.OneToOneField(User, related_name='user_blocks')
blocks = models.ManyToManyField(User,
related_name='blocked_by_set')

class Meta:
verbose_name = verbose_name_plural = _(u'user blocks')

def __unicode__(self):
return _(u'Users blocked by %(user)s') % {'user':
unicode(self.user)}

def block_count(self):
return self.blocks.count()
block_count.short_description = _(u'Blocks count')

def block_summary(self, count=7):
block_list = self.blocks.all()[:count]
return u'[%s%s]' % (u', '.join(unicode(user) for user in
block_list),
u', ...' if self.block_count() > count
else u'')
block_summary.short_description = _(u'Summary of blocks')


def create_friendship_instance(sender, instance, created, raw,
**kwargs):
if created and not raw:
Friendship.objects.create(user=instance)
models.signals.post_save.connect(create_friendship_instance,
 sender=User,
 dispatch_uid='friends.models.create_'
\
  'friendship_instance')


def create_userblocks_instance(sender, instance, created, raw,
**kwargs):
if created and not raw:
UserBlocks.objects.create(user=instance)
models.signals.post_save.connect(create_userblocks_instance,
 sender=User,
 dispatch_uid='friends.models.create_'
\
  'userblocks_instance')


On Mar 28, 6:57 pm, Joel Goldstick  wrote:
> On Mon, Mar 28, 2011 at 12:14 PM, mike171562 
> wrote:
>
>
>
> > Maybe you could use the ifequal tag in your template, not sure what
> > your trying to do , but in your view you could do a friend =
> > Friends.objects.all() and in your template,
>
> > {% ifequal friend.isfriend True %}
> > do something here
> > {%endifequal%}
>
> > {% ifequal friend.is_invited %}
> > something else
> > {%endifequal%}
>
> > On Mar 27, 7:32 pm, justin jools  wrote:

RE: How to run a file.py in the django environement

2011-03-28 Thread Sells, Fred
It was explained very clearly to me, I believe by shawn, but I've lost the 
original reference.  If the file you want to run is in your django app 
directory you just need

import datetime, sys, os, logging
os.environ['DJANGO_SETTINGS_MODULE'] = 
'YourDirectoryThatContainsTheSettingsModule.settings'

If it's running elsewhere you'll need to do more with path manipulation, but I 
did not pursue that.  

I also created an option for >python manage.py myoption   but I had to copy 
that into django.core to get it to work due to my lack of knowledge and I got 
the above working before putting more effort into alternatives.




-Original Message-
From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] On 
Behalf Of Mike Ramirez
Sent: Friday, March 25, 2011 9:23 PM
To: django-users@googlegroups.com
Subject: Re: How to run a file.py in the django environement

On Friday, March 25, 2011 06:06:39 pm José António Silva wrote:

> Is there any command like
> python manage.py shell filename.py (I know this particular command
> isn't allowed, but is there any other?)
> 
> thanks,
> JA

how about turning filename.py into a django command?

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


Mike
-- 
Paranoid Club meeting this Friday.  Now ... just try to find out where!

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


-- 
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. Any way to speed things up?

2011-03-28 Thread akaariai


On Mar 28, 3:52 pm, Fabian Büchler  wrote:
> Now this query takes about 15 seconds to run on a database with about 5,000
> Events and 50,000 EventDates.
> I'm running Django 1.3 (trunk) and PostgreSQL 9.0 on a relatively recent
> quadcore machine.
>
> Is there any way to do a more efficient query?

The easiest way to see which indexes help is to get the generated SQL
of the query and then play with PostgreSQL directly in dbshell, or if
you want a GUI, use PgAdmin. You can get the sql with
str(queryset.query). Then try to create different indexes so that the
query will be as fast as possible. I do not know what kind of SQL the
above code will generate, but even in the worst case (the generated
SQL is suboptimal) this should be relatively easy to write in raw SQL
if needed.

If you post the generated SQL here I will try to help find the right
indexes.

But I must say that having a runtime of 15 seconds for so little data
feels like the generated query could be suboptimal, or there could be
something else strange going on, like the PostgreSQL statistics for
the tables being off. Did you load the data just before running this
query? If that is the case try to run "vacuum analyze;" in dbshell
before testing.

I did a little test and without any indexes I could get a runtime of
100 milliseconds for a hand written query doing essentially the same
thing. And this is using an old laptop...

 - Anssi

-- 
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: Just started Django - please help clarify web site configuration strategy

2011-03-28 Thread javatina
Thanks for responding. It's been very important - helps "gauge"
thinking, how far I am off :)

1. I haven't yet looked at middlewares - will do.

2. custom template tags - I do not see how they can help here (BTW,
just completed my first one to loop ranges)

3. Request contexts complexity - as I said, combined with caches they
may help, and you seem to think along same lines. After reading some
Django docs, it seems that that's what mostly done. Though more
elegant than other things, still in my mind far from perfect for a
relatively simple thing I am talking about. But that's my Django
newbie thinking.

4. "Django application start" vs. "many processes and / or threads as
necessary serving your website" Well, that's not unusual - in fact, I
cannot think of anything more or less serious that would not do this.
Still, something starts the process (and manages it) of spawning
threads and processes. In many app servers it is possible to identify
along the way a lucky place for a callback(s).

5. Can you please clarify what you mean by "memorization" in "The
closest solution would be memorization"? Sounds intriguing.

Again, many thanks, Serge


On Mar 28, 12:13 pm, bruno desthuilliers
 wrote:
> On 28 mar, 16:58, javatina  wrote:
>
> > I could formulate my question differently - is there such thing as an
> > application context in Django? Basically, the question is - when a web
> > application starts there is a number of things that needs to be
> > available any time any request. Some of them are really static in
> > nature - for example, pagination parameters;
>
> They go into settings.py
>
> > some of them are more
> > dynamic - for example, menu options.
>
> > Things get more interesting when such data are read from the database.
> > So far what I see is that all that stuff should be places in the
> > request context (hopefully cached). It can be done more elegantly if
> > custom context processor(s) are created. But we are still rely on
> > request contexts. Unless I am missing something?
>
> Yes : custom template tags and middlewares.
>
> > It seems that although request contexts combined with caching can
> > help, it is way too complex for the purposes of initializing the
> > application.
>
> Why so ?
>
> > Which leads me to another question - is there any callback mechanism
> > when Django application starts?
>
> There's nothing like "Django application start" - depending on the
> deployement options, there can be as many processes and / or threads
> as necessary serving your website.
>
> > I guess what I am looking is a place
> > to make one-time queries, store data in a static member - and viola, I
> > have my application context.
>
> The closest solution would be memoization, but you'll still have at
> least one query per process (can't tell about threads). Or using the
> cache, which is still IMHO the safest solution.
>
> FWIW, there are benefits from this "share nothing" architecture when
> it comes to scaling.
>
> My 2 cents

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



problems with admin links after upgrade 1.1 -> 1.3 dev

2011-03-28 Thread jd
Hi all,
I upgraded to 1.3 dev from 1.1 and now my admin links don't work. the
page domain.com/admin/ works and it shows my models listed, but when
clicking on any of them it doesn't leave the model list page. Instead
it keeps stacking the url I want to visit onto the existing url. I.e.

domain.com/admin/

# shows app and model list

click on link for app: survey model: surveyResponse

url is now domain.com/admin/survey/surveyResponse/ but is still shows
the app/model list page.

click AGAIN on app: survey model: surveyResponse


url is now domain.com/admin/survey/surveyResponse/survey/
surveyResponse/

but the page is still the app model list "main page" that you see
after first logging in.  I've disabled my custom admin templates,
verified by the "site administration" header at the top.

Anyone know what this issue might be?TIA

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: simple friends template help

2011-03-28 Thread justin jools
I now have a different overriding problem with this simple-friends
app:

url patterns are simple:

urlpatterns = patterns('friends.views',
url(r'^$',
'friend_list',
name='friends_home'),
url(r'^list/(?P\w+)/$',
'friend_list',
name='friend_list'),
url(r'^add/(?P\w+)/$',
'friendship_request',
name='friendship_request'),
url(r'^accept/(?P\w+)/$',
'friendship_accept',
name='friendship_accept'),
url(r'^decline/(?P\w+)/$',
'friendship_decline',
name='friendship_decline'),
url(r'^cancel/(?P\w+)/$',
'friendship_cancel',
name='friendship_cancel'),
url(r'^delete/(?P\w+)/$',
'friendship_delete',
name='friendship_delete'),
url(r'^block/(?P\w+)/$',
'block_user',
name='block_user'),
url(r'^unblock/(?P\w+)/$',
'unblock_user',
name='unblock_user'),
)

but when I try /friends/add/jo

I get:

DoesNotExist at /friends/add/jo/

Friendship matching query does not exist.

Request Method: GET
Request URL:http://127.0.0.1:8000/friends/add/jo/
Django Version: 1.3 pre-alpha
Exception Type: DoesNotExist
Exception Value:

Friendship matching query does not exist.

Any ideas?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: simple friends template help

2011-03-28 Thread Joel Goldstick
On Mon, Mar 28, 2011 at 12:14 PM, mike171562 wrote:

> Maybe you could use the ifequal tag in your template, not sure what
> your trying to do , but in your view you could do a friend =
> Friends.objects.all() and in your template,
>
> {% ifequal friend.isfriend True %}
> do something here
> {%endifequal%}
>
> {% ifequal friend.is_invited %}
> something else
> {%endifequal%}
>
> On Mar 27, 7:32 pm, justin jools  wrote:
> > need some help setting up templates for friends list:
> >
> > how do I iterate a list of invited friends and are friends? I have
> > tried:
> >
> >   {% for friends in Friendship.objects.are_friends %}
> >
> >  target_user: {{ friends.target_user}}
> >  current_user:{{ friends.current_user}}
> >  are_friends: {{ friends.are_friends}}
> >  is_invited: {{ friends.is_invited}}
> >
> >   {% endfor %}
> >
> > gives me nothing but:
> >
> > {{ is_invited }}
> > {{ are_friends }}
> > {{ target_user }}
> > {{ current_user }}
> >
> > output:
> >
> > false
> > false
> > name
> > name
> >
> > I have been trying to figure this out for months. Please help.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>
Can you show us the code that produces these values?

-- 
Joel Goldstick

-- 
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: Updating to Django 1.3 - how to preserve file field previous behaviour

2011-03-28 Thread Jacob Kaplan-Moss
On Sun, Mar 27, 2011 at 6:47 PM, Russell Keith-Magee
 wrote:
> As was suggested when you raised this on django-dev, if you want the
> old behavior, write a subclass of FileField that reintroduces the old
> behavior.

... and for those who're not reading over there, here's some code you
might try: https://gist.github.com/889692. Make sure to read the
WARNING before you put that in production...

Jacob

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



I want Develop django poll app tuturial

2011-03-28 Thread cha
 
 
  Hello I Written the Poll Applicattion From the tuturial in django offical 
website But How i can Develope It ?

I want add bar graph for result and need calculate percentages for vote 

-- 
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: simple friends template help

2011-03-28 Thread mike171562
Maybe you could use the ifequal tag in your template, not sure what
your trying to do , but in your view you could do a friend =
Friends.objects.all() and in your template,

{% ifequal friend.isfriend True %}
do something here
{%endifequal%}

{% ifequal friend.is_invited %}
something else
{%endifequal%}

On Mar 27, 7:32 pm, justin jools  wrote:
> need some help setting up templates for friends list:
>
> how do I iterate a list of invited friends and are friends? I have
> tried:
>
>   {% for friends in Friendship.objects.are_friends %}
>
>          target_user: {{ friends.target_user}}
>          current_user:{{ friends.current_user}}
>          are_friends: {{ friends.are_friends}}
>          is_invited: {{ friends.is_invited}}
>
>   {% endfor %}
>
> gives me nothing but:
>
>     {{ is_invited }}
>     {{ are_friends }}
>     {{ target_user }}
>     {{ current_user }}
>
> output:
>
> false
> false
> name
> name
>
> I have been trying to figure this out for months. Please help.

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



Re: Just started Django - please help clarify web site configuration strategy

2011-03-28 Thread bruno desthuilliers
On 28 mar, 16:58, javatina  wrote:
> I could formulate my question differently - is there such thing as an
> application context in Django? Basically, the question is - when a web
> application starts there is a number of things that needs to be
> available any time any request. Some of them are really static in
> nature - for example, pagination parameters;

They go into settings.py

> some of them are more
> dynamic - for example, menu options.
>
> Things get more interesting when such data are read from the database.
> So far what I see is that all that stuff should be places in the
> request context (hopefully cached). It can be done more elegantly if
> custom context processor(s) are created. But we are still rely on
> request contexts. Unless I am missing something?

Yes : custom template tags and middlewares.

> It seems that although request contexts combined with caching can
> help, it is way too complex for the purposes of initializing the
> application.

Why so ?

> Which leads me to another question - is there any callback mechanism
> when Django application starts?

There's nothing like "Django application start" - depending on the
deployement options, there can be as many processes and / or threads
as necessary serving your website.


> I guess what I am looking is a place
> to make one-time queries, store data in a static member - and viola, I
> have my application context.

The closest solution would be memoization, but you'll still have at
least one query per process (can't tell about threads). Or using the
cache, which is still IMHO the safest solution.

FWIW, there are benefits from this "share nothing" architecture when
it comes to scaling.


My 2 cents

-- 
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 any way to override variable of parent (super) template in child template

2011-03-28 Thread Vladimir Mihailenco
AFAIK nodes outside blocks in such cases are not executed at all. But
I tried and it does not work.

So far I wrote this:

{% extends 'base.html' %}

{% block title %}
{% setget title %}{% trans 'Pages' %}{% endset %}
{% endblock %}

{% block content %}
{{ title  }}
{% endblock %}

and templatetag looks like this:

class SetNode(template.Node):
def __init__(self, key, nodelist, return_result=False):
self.key = key
self.nodelist = nodelist
self.return_result = return_result

def render(self, context):
value = self.nodelist.render(context)
for d in context.dicts:
d[self.key] = value
if self.return_result:
return value
else:
return ''

What do you think? The rationale behind this is that sometime I have
huge titles like this:

{% url foo as bar %}
{% block title %}{% blocktrans with a=b %}Title goes here {{ bar }}
{{ a }}{% endblocktrans %}{% endblock %}

and copy-pasting this from block to block is not funny... May be there
is another way to solve this?

On Mar 28, 6:34 pm, Bill Freeman  wrote:
> Try:
>
> {% extends 'base.html' %}
> {% with title="My title" %}
> {% block content %}
> Any other content stuff.
> {% endblock %}
> {% endwith %}
>
> No guarantees.  Let us know if it works.
>
> Bill
>
> On Mon, Mar 28, 2011 at 6:18 AM, Vladimir Mihailenco
>
>
>
>
>
>
>
>  wrote:
> > Is there any way to override variable of parent (super) template in
> > child template? For example, I have following templates:
>
> > base.html
> > {{ title }}
>
> > {% block body %}
> > {{ title }}
> > {% block content %}{% endblock %}
> > {% endblock %}
>
> > child.html
> > {% extends 'base.html' %}
>
> > {% block content %}
> > {% set title %}My title{% endset %}
> > {% endblock %}
>
> > How to accomplish this using Django 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-users@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/django-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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 any way to override variable of parent (super) template in child template

2011-03-28 Thread bruno desthuilliers
On 28 mar, 12:18, Vladimir Mihailenco 
wrote:
> Is there any way to override variable of parent (super) template in
> child template? For example, I have following templates:
>
> base.html
> {{ title }}
>
> {% block body %}
> {{ title }}
> {% block content %}{% endblock %}
> {% endblock %}
>
> child.html
> {% extends 'base.html' %}
>
> {% block content %}
> {% set title %}My title{% endset %}
> {% endblock %}

"title" is not even in your "content" block. But anyway: instead of
doing things backward, just define the blocks your need in your base
template, ie:

# base.html
{% block page_title %}{{ title }}{% endblock %}

{% block body %}
{% block body_title %}{{ title }}{% endblock %}
{% block content %}{% endblock %}
{% endblock %}


A block can be as "small" as you want - I often use them for
attributes like  etc.

-- 
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 any way to override variable of parent (super) template in child template

2011-03-28 Thread Bill Freeman
Try:

{% extends 'base.html' %}
{% with title="My title" %}
{% block content %}
Any other content stuff.
{% endblock %}
{% endwith %}

No guarantees.  Let us know if it works.

Bill

On Mon, Mar 28, 2011 at 6:18 AM, Vladimir Mihailenco
 wrote:
> Is there any way to override variable of parent (super) template in
> child template? For example, I have following templates:
>
> base.html
> {{ title }}
>
> {% block body %}
> {{ title }}
> {% block content %}{% endblock %}
> {% endblock %}
>
>
> child.html
> {% extends 'base.html' %}
>
> {% block content %}
> {% set title %}My title{% endset %}
> {% endblock %}
>
> How to accomplish this using Django 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-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.
>
>

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



Just started Django - please help clarify web site configuration strategy

2011-03-28 Thread javatina
I could formulate my question differently - is there such thing as an
application context in Django? Basically, the question is - when a web
application starts there is a number of things that needs to be
available any time any request. Some of them are really static in
nature - for example, pagination parameters; some of them are more
dynamic - for example, menu options.

Things get more interesting when such data are read from the database.
So far what I see is that all that stuff should be places in the
request context (hopefully cached). It can be done more elegantly if
custom context processor(s) are created. But we are still rely on
request contexts. Unless I am missing something?

It seems that although request contexts combined with caching can
help, it is way too complex for the purposes of initializing the
application.

Which leads me to another question - is there any callback mechanism
when Django application starts? I guess what I am looking is a place
to make one-time queries, store data in a static member - and viola, I
have my application context.

Please bear with me,

Serge

-- 
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: LANGUAGE_CODE inside the template of an inclusion tag

2011-03-28 Thread gontran
Still no answers.
Is it because it's impossible?

By the way, I know that inside the code of my tag I can get the
context and then the language used by the user, by I want to access to
this value inside my template, without having to pass explicitely the
value.

On 25 mar, 16:39, gontran  wrote:
> Hello everybody,
>
> I'd like to use  LANGUAGE_CODE in the template of an inclusion tag but
> this doesn't work.
> I added 'django.core.context_processors.i18n' in the settings, I load
> i18n in my template, and I specified to take context when I register
> my inclusion_tag.
> Am I missing something or is it impossible to use LANGUAGE_CODE in
> this case?
>
> Thank you for your answers.
>
> Regards,
>
> Gontran

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



Dynamically generating form fields

2011-03-28 Thread fersan
Hello,

I am trying to create a form with fields based on types of an object
property. Basically, I am setting up a system which has hardware
'demos' which are categorized by industry. I want to create a form
which has a Checkbox Select Multiple for each industry, with the
choices being the demos for that industry. Currently, my (un-working)
form code looks like:

class select_demo_apps_frm(forms.Form):
# List apps from each industry with selection boxes for each app.
def __init__(self, *args, **kwargs):
super(select_demo_apps_frm, self).__init__(*args, **kwargs)

inds = industries() # returns all industry objects

for ind in inds:
fieldname = '%s' % ind.name
self.fields[fieldname] = forms.CheckboxSelectMultiple()
self.fields[fieldname].choices = [(d.id, marksafe('%s - %s') % (d.name, d.desc)) for d in demo.objects.filter(industry =
ind)]

Unfortunately, I'm getting an error from this code:

Error when calling the metaclass bases
Cannot create a consistent method resolution
order (MRO) for bases Form, select_demo_apps_frm

It could be possible to set a static field for each industry, however
in the interest of long term maintainability I'd rather do it
dynamically in case new industries get added after I leave this job.
Just wondering if anyone can help with creating this form in such a
way that it actually works ;)

Thanks much!

Fernando Sanchez

-- 
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. Any way to speed things up?

2011-03-28 Thread Javier Guerra Giraldez
On Mon, Mar 28, 2011 at 7:52 AM, Fabian Büchler
 wrote:
>
> Events have an EventOnlineManager with a "to_expire" method which should 
> select all Events with status=online and EventDates associated which date < 
> today.
>
>> class EventOnlineManager(models.Manager):
>>
>>     def get_query_set(self):
>>     return (super(EventOnlineManager, self).get_query_set()
>>     .filter(status=Event.STATUS_ONLINE))
>>
>>     @property
>>     def to_expire(self):
>>     today = datetime.date.today()
>>     return (self.annotate(eventdate_max=models.Max('eventdate__date'))
>>     .filter(eventdate_max__lt=today))



I guess you have reasons to allow several EventDates per Event (if
not, they should be a single table).   my first attempt would be to
add an (event, date) index to EventDate.  can you add an
ordering=('event','date') ?

--
Javier

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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 success_url with reverse() in class-based generic view

2011-03-28 Thread Rytis Sileika
Had the same issue. Here's what I did in my views.py:

---
from django.utils.functional import lazy

...

class MyDeleteView(DeleteView):
...
success_url = lazy(reverse, str)("success_url_name")
---

Again, I don't know if that's the correct way of doing things, but
worked for me. I think I saw a ticket somewhere that was planning to
implement the lazy_reverse functionality in code Django, but can't
find it, or may be I'm just making things up...




On Mar 22, 10:53 pm, rb  wrote:
> I just ran into this today and was curious. My setup is this:
>
>     class MyGenericView(DeleteView):
>         success_url = reverse('my-name')
>
> This will produce the from the original author. I got around this by
> overriding get_success_url():
>
>     class MyGenericView(DeleteView):
>         def get_success_url(self):
>             return reverse('my-name')
>
> Is this the preferred/proper way to accomplish this? While looking
> around in the tickets I did find this ticket:
>
> http://code.djangoproject.com/ticket/13753
>
> This made me believe that maybe the generic views were using
> redirect() (which can accept names), but I tried setting success_url
> to 'my-name' and it sends an HttpRedirectResponse with that as the
> target. Looking in django.views.generic.edit shows that it is just
> calling HttpRedirectResponse. Should these call redirect() instead of
> HttpRedirectResponse?
>
> Thanks!
>
> Rob
>
> (django 1.3 rc 1 SVN-15894)
>
> On Feb 18, 5:00 pm, jnns  wrote:
>
>
>
> > Hi users,
>
> > I have a CreateView which I'd like to redirect to a custom success_url
> > defined in my URLconf. As I want to stick to the DRY-principle I just
> > did the following:
>
> >    success_url = reverse("my-named-url")
>
> > Unfortunately, this breaks my site by raising an
> > "ImproperlyConfigured: The included urlconf doesn't have any patterns
> > in it". Removing success_url and setting the model's
> > get_absolute_url() to the following works fine:
>
> >    def get_absolute_url(self):
> >        return reverse("my-named-url")
>
> > I could reproduce this with a brand new project/application so I don't
> > think this has something to do with my setup.
>
> > Can anyone confirm this issue?

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



AW: form has not attribute cleaned_data

2011-03-28 Thread Szabo, Patrick (LNG-VIE)
Strange.
I'm new to python and django myself but im wondering how form.is_valid() works 
when form is only initiated a line later. 

Doesnt it have to look like this:

if request.user.is_superuser:
if request.method == 'POST':
form = Form_news(request.POST)
if form.is_valid():
 mess = form.cleaned_data['messgg']

?!



. . . . . . . . . . . . . . . . . . . . . . . . . .
Patrick Szabo
 XSLT Developer 
LexisNexis
Marxergasse 25, 1030 Wien

mailto:patrick.sz...@lexisnexis.at
Tel.: +43 (1) 534 52 - 1573 
Fax: +43 (1) 534 52 - 146 


-Ursprüngliche Nachricht-

Von: django-users@googlegroups.com [mailto:django-users@googlegroups.com] Im 
Auftrag von luca72
Gesendet: Montag, 28. März 2011 15:05
An: Django users
Betreff: form has not attribute cleaned_data

hello i have a form like this:
class Form_news(forms.Form):
messgg = forms.CharField(label = 'Messaggio',max_length=1,
widget=forms.Textarea)

and in the views i do as follow:
if request.user.is_superuser:
if request.method == 'POST':
if form.is_valid():
 form = Form_news(request.POST)
 mess = form.cleaned_data['messgg']

i get the error form News has not attribute cleaned_data

Why?

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



-- 
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: form has not attribute cleaned_data

2011-03-28 Thread Daniel Roseman

On Monday, March 28, 2011 2:04:53 PM UTC+1, luca72 wrote:
>
> hello i have a form like this: 
> class Form_news(forms.Form): 
> messgg = forms.CharField(label = 'Messaggio',max_length=1, 
> widget=forms.Textarea) 
>
> and in the views i do as follow: 
> if request.user.is_superuser: 
> if request.method == 'POST': 
> if form.is_valid(): 
>  form = Form_news(request.POST) 
>  mess = form.cleaned_data['messgg'] 
>
> i get the error form News has not attribute cleaned_data 
>
> Why?


Your code makes no sense: you're testing if the form is valid before you 
instantiate it with the POST data. It should be the other way round, of 
course:

   if request.method == 'POST':
   form = Form_news(request.POST)
   if form.is_valid():
...etc...
--
DR.

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



form has not attribute cleaned_data

2011-03-28 Thread luca72
hello i have a form like this:
class Form_news(forms.Form):
messgg = forms.CharField(label = 'Messaggio',max_length=1,
widget=forms.Textarea)

and in the views i do as follow:
if request.user.is_superuser:
if request.method == 'POST':
if form.is_valid():
 form = Form_news(request.POST)
 mess = form.cleaned_data['messgg']

i get the error form News has not attribute cleaned_data

Why?

-- 
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. Any way to speed things up?

2011-03-28 Thread Fabian Büchler
Hello everyone,

maybe someone can help me to speed up a quite slow query:

I've got two models (only the important stuff outlined here): Events and
EventDates

class Event(models.Model):
> status = models.SmallIntegerField(verbose_name=_(u"status"),
> choices=STATUS_CHOICES, default=STATUS_ONLINE, db_index=True)
>

> online = EventOnlineManager()
>


class EventDate(models.Model):
> event = models.ForeignKey(Event)
>
> date = models.DateField(verbose_name=_(u"start date"), db_index=True)
>


Events have an EventOnlineManager with a "to_expire" method which should
select all Events with status=online and EventDates associated which date <
today.

class EventOnlineManager(models.Manager):
>
> def get_query_set(self):
> return (super(EventOnlineManager, self).get_query_set()
> .filter(status=Event.STATUS_ONLINE))
>
> @property
> def to_expire(self):
> today = datetime.date.today()
> return (self.annotate(eventdate_max=models.Max('eventdate__date'))
> .filter(eventdate_max__lt=today))
>

Now this query takes about 15 seconds to run on a database with about 5,000
Events and 50,000 EventDates.
I'm running Django 1.3 (trunk) and PostgreSQL 9.0 on a relatively recent
quadcore machine.

Is there any way to do a more efficient query?

Thanks in advance!
Regards, Fabian

-- 
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: AW: MEDIA_URL not treated like static

2011-03-28 Thread galgal
Thanks, I didn't know that. All works fine now.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: AW: MEDIA_URL not treated like static

2011-03-28 Thread Amao Zhao
Dear galgal:
according to the django docs for 1.3, The most likely example is
user-uploaded content in
MEDIA_ROOT
. staticfiles is intended for static assets and has no built-in handling for
user-uploaded files, but you can have Django serve your
MEDIA_ROOT
by
appending something like this to your URLconf.
And you can read the doc with
http://docs.djangoproject.com/en/1.3/howto/static-files/#serving-other-directories

On Mon, Mar 28, 2011 at 7:48 PM, galgal  wrote:

> I forgot to tell I'm using Django 1.3. In that case - how to make it work
> with separate dirs? Or it can't be done on dev server?
>
> --
> 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.
>

-- 
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: AW: MEDIA_URL not treated like static

2011-03-28 Thread galgal
I forgot to tell I'm using Django 1.3. In that case - how to make it work 
with separate dirs? Or it can't be done on dev server?

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



AW: MEDIA_URL not treated like static

2011-03-28 Thread Szabo, Patrick (LNG-VIE)
I have a static folder in my Prject and my MEDIA_URL looks like this: 
http://127.0.0.1:8000/static/

 

Von: django-users@googlegroups.com [mailto:django-users@googlegroups.com] Im 
Auftrag von galgal
Gesendet: Montag, 28. März 2011 13:38
An: django-users@googlegroups.com
Betreff: MEDIA_URL not treated like static

 

I have that dirs structure:

site_media/

|
---> static/

|

---> uploads/

 

static dir is set as STATIC_URL = '/site_media/static/'

uploads dir is set as MEDIA_URL = '/site_media/uploads/'

 

In that case on dev server (localhost:8000) media_url is not accessible via 
browser as static file, and whe I try to access it I get 404 error. How can i 
set it up to be seen as static?

In uploads dir are all files uploaded by users. static dir includes all my 
js/css/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.


. . . . . . . . . . . . . . . . . . . . . . . . . .
Patrick Szabo
 XSLT Developer 
LexisNexis
Marxergasse 25, 1030 Wien

mailto:patrick.sz...@lexisnexis.at
Tel.: +43 (1) 534 52 - 1573 
Fax: +43 (1) 534 52 - 146 





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



MEDIA_URL not treated like static

2011-03-28 Thread galgal
I have that dirs structure:
site_media/
|
---> static/
|
---> uploads/

static dir is set as STATIC_URL = '/site_media/static/'
uploads dir is set as MEDIA_URL = '/site_media/uploads/'

In that case on dev server (localhost:8000) media_url is not accessible via 
browser as static file, and whe I try to access it I get 404 error. How can 
i set it up to be seen as static?
In uploads dir are all files uploaded by users. static dir includes all my 
js/css/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.



Is there any way to override variable of parent (super) template in child template

2011-03-28 Thread Vladimir Mihailenco
Is there any way to override variable of parent (super) template in
child template? For example, I have following templates:

base.html
{{ title }}

{% block body %}
{{ title }}
{% block content %}{% endblock %}
{% endblock %}


child.html
{% extends 'base.html' %}

{% block content %}
{% set title %}My title{% endset %}
{% endblock %}

How to accomplish this using Django 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-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: user email

2011-03-28 Thread emre yılmaz
2011/3/28 luca72 :
> Hello
> How i can get all the email stored in the auth_user table of the
> default djanco database?
>
> Thanks
>

use this:
http://paste.pocoo.org/show/361380/



-- 
web developer
http://www.emreyilmaz.me

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



user email

2011-03-28 Thread luca72
Hello
How i can get all the email stored in the auth_user table of the
default djanco database?

Thanks

Luca

-- 
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: unique_for_date not working?

2011-03-28 Thread Derek
On Mar 25, 10:42 pm, Karen Tracey  wrote:
> On Fri, Mar 25, 2011 at 12:17 PM, Andre Terra  wrote:
> > Overwrite the model's save method and add the date automatically on save.
> > That is the best way to do most things "auto" in your models.
>
> But if you do this, you are past the point where you can flag non-unique for
> the date as an error on form submission. The fact that admin doesn't include
> readonly (excluded from form) fields in the unique checks is ticket #13091:
>
> http://code.djangoproject.com/ticket/13091
>
> Karen
> --http://tracey.org/kmt/

As "bystander" here... what then is the actual (best and definitive)
solution to the OP's 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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.