Re: How to pre-cache model data?

2011-03-02 Thread Alex Robbins
If you need to run tasks outside the request/response cycle, then you
should be using celery.

http://celeryproject.org/

Celery includes something called periodic tasks.
http://ask.github.com/celery/userguide/periodic-tasks.html

You just need to make a task that updates the value in cache, and then
set it to run with a schedule=timedelta(minutes=3) (or schedule=60*3).

Hope that helps!
Alex

On Mar 1, 9:10 am, Helgi Borg  wrote:
> I need my Django app to poll data in DB regularly  (say once every 3
> minutes) and cache the data. I have some queries that take up to 20
> sec. The users must never wait this long for response from my app.
> What is the must natural way to go about this in Django?
>
> I know that I can use memcache, but that way the users will once in
> while have to wait a long time while the cache is being refreshed.
>
> Best regards,
> Helgi Borg

-- 
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: Ordering/sort_by from a custom method

2011-02-10 Thread Alex Robbins
Wow, you are right. This is a tricky lookup. The generic relation
makes it pretty tough. I'd just use the python sort unless you see a
real performance problem.

class LinkGetTopScores(models.Manager):
def get_top_score(self):
return sorted(self.all(), key=lambda n: n.get_score)

Maybe you need to make it n.get_score(), instead of n.get_score in the
lambda.


Alex

On Feb 10, 8:54 am, Andres Lucena <andresluc...@gmail.com> wrote:
> On Thu, Feb 10, 2011 at 2:52 PM, Alex Robbins
>
> <alexander.j.robb...@gmail.com> wrote:
> > Do you want the episode with the highest individual score, or the
> > highest average score?
>
> I want the links (within that episode) sorted by highest score.
>
> (Sorry for no making it clear before)
>
> Thank you,
> Andres
>
>
>
>
>
>
>
> > Alex
>
> > On Thu, Feb 10, 2011 at 7:41 AM, Andres Lucena <andresluc...@gmail.com> 
> > wrote:
> >> On Thu, Feb 10, 2011 at 2:29 PM, Alex Robbins
> >> <alexander.j.robb...@gmail.com> wrote:
> >>> Yeah, you'll definitely want to find some aggregate to do the sorting.
>
> >> Ok, didn't know it. I'll take a look at it...
>
> >>> The only way to sort by a custom method is doing an in-python sort,
> >>> which is going to be much slower than having the db sort for you.
>
> >> Yeah, I tought so but it seems (to me) the only way of doing this...
>
> >>>  If you post the score models, we could probably help more.
>
> >> The score models are from django-voting:
>
> >>http://django-voting.googlecode.com/svn/trunk/voting/models.py
> >>http://django-voting.googlecode.com/svn/trunk/voting/managers.py
>
> >> Thanks for the help!
>
> >> Andres
>
> >>> Alex
>
> >>> On Feb 9, 8:49 am, "Casey S. Greene" <csgre...@princeton.edu> wrote:
> >>>> I haven't used django-voting but it sounds to me like you want something
> >>>> like:
> >>>> Link.objects.aggregate(Avg(score = 'vote__score')).order_by('score')
>
> >>>> If I recall correctly you can chain aggregate and order_by.
>
> >>>> Anyway, that example and this link should get you started at 
> >>>> least:http://docs.djangoproject.com/en/dev/topics/db/aggregation/
>
> >>>> Hope this helps!
> >>>> Casey
>
> >>>> On Wed, 2011-02-09 at 10:08 +0100, Andres Lucena wrote:
> >>>> > On Tue, Feb 8, 2011 at 6:00 PM, Andres Lucena <andresluc...@gmail.com> 
> >>>> > wrote:
> >>>> > > Dear Gurus,
>
> >>>> > > I've made a custom method for getting the score (from django-voting)
> >>>> > > for a giving Model:
>
> >>>> > > class Link(models.Model):
> >>>> > >    episode = models.ForeignKey("Episode", related_name="links")
> >>>> > >    url = models.CharField(max_length=255, unique=True, db_index=True)
>
> >>>> > >    def __unicode__(self):
> >>>> > >        return self.url
>
> >>>> > >    def get_score(self):
> >>>> > >        return Vote.objects.get_score(self)['score']
>
> >>>> > > Now I want to make a custom manager to getting the top-scored links
> >>>> > > for the given episode. AFAIK, you can't sort by a custom method, so
> >>>> > > I'm trying to apply the ordering through sorted(), like this links
> >>>> > > says:
>
> >>>> > >http://stackoverflow.com/questions/981375/using-a-django-custom-model...
> >>>> > >http://stackoverflow.com/questions/883575/custom-ordering-in-django
>
> >>>> > > So, what I have now is this:
>
> >>>> > > class LinkGetTopScores(models.Manager):
> >>>> > >    def get_top_score(self):
> >>>> > >        return sorted(self.filter(episode=self.episode), key=lambda n:
> >>>> > > n.get_score)
>
> >>>> > > class Link(models.Model):
> >>>> > >    episode = models.ForeignKey("Episode", related_name="links")
> >>>> > >    url = models.CharField(max_length=255, unique=True, db_index=True)
> >>>> > >    get_top_score = LinkGetTopScores()
> >>>> > > 
>
> >>>> > > So of course this isn't working because of the self.episode stuff...
> >>>> > > But I've to filter somehow b

Re: Ordering/sort_by from a custom method

2011-02-10 Thread Alex Robbins
Do you want the episode with the highest individual score, or the
highest average score?

Alex

On Thu, Feb 10, 2011 at 7:41 AM, Andres Lucena <andresluc...@gmail.com> wrote:
> On Thu, Feb 10, 2011 at 2:29 PM, Alex Robbins
> <alexander.j.robb...@gmail.com> wrote:
>> Yeah, you'll definitely want to find some aggregate to do the sorting.
>
> Ok, didn't know it. I'll take a look at it...
>
>> The only way to sort by a custom method is doing an in-python sort,
>> which is going to be much slower than having the db sort for you.
>
> Yeah, I tought so but it seems (to me) the only way of doing this...
>
>>  If you post the score models, we could probably help more.
>
> The score models are from django-voting:
>
> http://django-voting.googlecode.com/svn/trunk/voting/models.py
> http://django-voting.googlecode.com/svn/trunk/voting/managers.py
>
> Thanks for the help!
>
> Andres
>
>
>>
>> Alex
>>
>> On Feb 9, 8:49 am, "Casey S. Greene" <csgre...@princeton.edu> wrote:
>>> I haven't used django-voting but it sounds to me like you want something
>>> like:
>>> Link.objects.aggregate(Avg(score = 'vote__score')).order_by('score')
>>>
>>> If I recall correctly you can chain aggregate and order_by.
>>>
>>> Anyway, that example and this link should get you started at 
>>> least:http://docs.djangoproject.com/en/dev/topics/db/aggregation/
>>>
>>> Hope this helps!
>>> Casey
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> On Wed, 2011-02-09 at 10:08 +0100, Andres Lucena wrote:
>>> > On Tue, Feb 8, 2011 at 6:00 PM, Andres Lucena <andresluc...@gmail.com> 
>>> > wrote:
>>> > > Dear Gurus,
>>>
>>> > > I've made a custom method for getting the score (from django-voting)
>>> > > for a giving Model:
>>>
>>> > > class Link(models.Model):
>>> > >    episode = models.ForeignKey("Episode", related_name="links")
>>> > >    url = models.CharField(max_length=255, unique=True, db_index=True)
>>>
>>> > >    def __unicode__(self):
>>> > >        return self.url
>>>
>>> > >    def get_score(self):
>>> > >        return Vote.objects.get_score(self)['score']
>>>
>>> > > Now I want to make a custom manager to getting the top-scored links
>>> > > for the given episode. AFAIK, you can't sort by a custom method, so
>>> > > I'm trying to apply the ordering through sorted(), like this links
>>> > > says:
>>>
>>> > >http://stackoverflow.com/questions/981375/using-a-django-custom-model...
>>> > >http://stackoverflow.com/questions/883575/custom-ordering-in-django
>>>
>>> > > So, what I have now is this:
>>>
>>> > > class LinkGetTopScores(models.Manager):
>>> > >    def get_top_score(self):
>>> > >        return sorted(self.filter(episode=self.episode), key=lambda n:
>>> > > n.get_score)
>>>
>>> > > class Link(models.Model):
>>> > >    episode = models.ForeignKey("Episode", related_name="links")
>>> > >    url = models.CharField(max_length=255, unique=True, db_index=True)
>>> > >    get_top_score = LinkGetTopScores()
>>> > > 
>>>
>>> > > So of course this isn't working because of the self.episode stuff...
>>> > > But I've to filter somehow by episode (the ForeignKey), and I don't
>>> > > know how. Is there anyway of doing this?? What I'm doing is right or
>>> > > there would be an easier way of doing this?
>>>
>>> > I noticed that the .filter isn't necesary, so now I have this:
>>>
>>> > class LinkGetTopScores(models.Manager):
>>> >     def get_top_score(self):
>>> >         return sorted(self.all(), key=lambda n: n.get_score)
>>>
>>> > But it don't sort by score, and I don't know what I'm doing wrong :S
>>>
>>> > Any idea?
>>>
>>> > Thanks,
>>> > Andres
>>>
>>> > > Thank you,
>>> > > Andres
>>
>> --
>> 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.
>
>

-- 
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: Ordering/sort_by from a custom method

2011-02-10 Thread Alex Robbins
Yeah, you'll definitely want to find some aggregate to do the sorting.
The only way to sort by a custom method is doing an in-python sort,
which is going to be much slower than having the db sort for you. If
you post the score models, we could probably help more.

Alex

On Feb 9, 8:49 am, "Casey S. Greene"  wrote:
> I haven't used django-voting but it sounds to me like you want something
> like:
> Link.objects.aggregate(Avg(score = 'vote__score')).order_by('score')
>
> If I recall correctly you can chain aggregate and order_by.
>
> Anyway, that example and this link should get you started at 
> least:http://docs.djangoproject.com/en/dev/topics/db/aggregation/
>
> Hope this helps!
> Casey
>
>
>
>
>
>
>
> On Wed, 2011-02-09 at 10:08 +0100, Andres Lucena wrote:
> > On Tue, Feb 8, 2011 at 6:00 PM, Andres Lucena  
> > wrote:
> > > Dear Gurus,
>
> > > I've made a custom method for getting the score (from django-voting)
> > > for a giving Model:
>
> > > class Link(models.Model):
> > >    episode = models.ForeignKey("Episode", related_name="links")
> > >    url = models.CharField(max_length=255, unique=True, db_index=True)
>
> > >    def __unicode__(self):
> > >        return self.url
>
> > >    def get_score(self):
> > >        return Vote.objects.get_score(self)['score']
>
> > > Now I want to make a custom manager to getting the top-scored links
> > > for the given episode. AFAIK, you can't sort by a custom method, so
> > > I'm trying to apply the ordering through sorted(), like this links
> > > says:
>
> > >http://stackoverflow.com/questions/981375/using-a-django-custom-model...
> > >http://stackoverflow.com/questions/883575/custom-ordering-in-django
>
> > > So, what I have now is this:
>
> > > class LinkGetTopScores(models.Manager):
> > >    def get_top_score(self):
> > >        return sorted(self.filter(episode=self.episode), key=lambda n:
> > > n.get_score)
>
> > > class Link(models.Model):
> > >    episode = models.ForeignKey("Episode", related_name="links")
> > >    url = models.CharField(max_length=255, unique=True, db_index=True)
> > >    get_top_score = LinkGetTopScores()
> > > 
>
> > > So of course this isn't working because of the self.episode stuff...
> > > But I've to filter somehow by episode (the ForeignKey), and I don't
> > > know how. Is there anyway of doing this?? What I'm doing is right or
> > > there would be an easier way of doing this?
>
> > I noticed that the .filter isn't necesary, so now I have this:
>
> > class LinkGetTopScores(models.Manager):
> >     def get_top_score(self):
> >         return sorted(self.all(), key=lambda n: n.get_score)
>
> > But it don't sort by score, and I don't know what I'm doing wrong :S
>
> > Any idea?
>
> > Thanks,
> > Andres
>
> > > Thank you,
> > > Andres

-- 
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: What's the best way to develop an app that is similar the django admin?

2010-09-21 Thread Alex Robbins
I think you'll definitely want to use ModelForms.
http://docs.djangoproject.com/en/dev/topics/forms/modelforms/

Alex

On Sep 20, 8:13 am, Federico Capoano  wrote:
> Hi all,
>
> I try to explain it clearly.
>
> I have to develop an application that will implement similar
> functionality and look of the django admin, but in the frontend.
>
> So this application will have files management, clients management,
> and much more similar stuff, with add new, edit, delete, file upload
> and so on.
>
> Is there a way you would advice to do this?
>
> Thanks a lot.
> Federico

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email 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: New-by Model traps and other questions...

2010-09-08 Thread Alex Robbins
Lance,

I wouldn't worry too much about having empty fields vs an extra table
in your database. I think having data models that are easy to work
with is far more important than making sure you don't have fields that
are empty some time. I wouldn't worry at all about a field that is
empty a lot. I would just setup my models however made the app logic
simplest.

Just my 2 cents...
Alex

On Wed, Sep 8, 2010 at 6:35 PM, Lance F. Squire  wrote:
>
> On the many to many field,
>
> Great info, I'll look into those.
>
> On combining the fields,
>
> 'Thumbs' is really Thumbnail images of 'Images'.
>
> However, not all 'Images' have 'Thumbs'
>
> Thinking that 3 possibly blank fields in 'Images' is more efficient
> than 9 fields in a different table for each actual thumbnail image...
> (Of course enough 'Images' without Thumbs could weigh the other way,
> But for what I'm doing I'm sure there will be more 'Images' with
> 'Thumbs' than without.
>
> Again, Thanks.
>
> Lance
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: New-by Model traps and other questions...

2010-09-08 Thread Alex Robbins
Lance,

Regarding the many to many field that shows too many images:

I've used this project with some success in the past:
http://code.google.com/p/django-ajax-filtered-fields/
They allow you to setup some ajax filtering for the field, which can
make it a lot easier to find what you are looking for.
Also, if you can think of a way to make it work, there is a
limit_choices_to kwarg that you can use to cut down on all the
choices.

As far as combining the fields, if they are really are different
objects, I wouldn't combine them. You want to combine them because
they have lots of fields that are the same, not because they are the
same object. I'd say you should just make an abstract base model class
and have them both inherit from it. That way you don't have repeated
code, but you aren't forcing data into a place it doesn't fit. On the
other hand, if they really are the same kind of thing, then adding a
couple fields makes sense.

Hope that helps,
Alex

On Sep 7, 8:13 pm, "Lance F. Squire"  wrote:
> Ok, I'm just getting back to a project I had to put on hold for a
> while.
>
> I recently read an article on problems new Django users fall into, and
> I think I hit one.
>
> The bottom of my 'Systems' model looks like this:
>
>         keyboard = models.CharField(max_length=80)
>         cart = models.CharField(max_length=80)
>         ram = models.CharField(max_length=40)
>         rom = models.CharField(max_length=40)
>         media = models.CharField(max_length=80)
>         options = models.CharField(max_length=120)
>         quick = models.TextField()
>         info = models.TextField()
>         system_pictures = models.ManyToManyField('Image')
>         public = models.BooleanField()
>
>         def __unicode__(self):
>             return self.name
>
>         def get_header_pic(self):
>             return
> self.system_pictures.filter(image_category__name='Header_Pic')[0]
>
>         def get_header_logo(self):
>             return
> self.system_pictures.filter(image_category__name='Header_Logo')[0]
>
> The problem is that when using the admin to enter the data for the
> Systems, I get a list of every pic in the 'Image' model to choose
> from.
>
> I can see this getting frustrating very fast.
>
> I'm thinking that I can just use the fields in the 'Image' model to
> find the appropriate pics, but don't know how to re-structure
> 'get_header_pic' to work with that. Or should I be doing something
> different in the View or Template to access these pics?
>
> Also, I added and 'Thumb' model when I added functionality I hadn't
> originally though of. Unfortunately, it's almost an exact copy of the
> "Image' model I made.
>
> As seen here:
>
> class Image(models.Model):
>         name = models.CharField(max_length=80)
>         slug = models.CharField(max_length=80)
>         location = models.URLField()
>         height = models.IntegerField()
>         width = models.IntegerField()
>         image_category = models.ForeignKey('ImageCat')
>         info = models.TextField()
>         primary = models.BooleanField()
>
>         def __unicode__(self):
>             return self.name
>
> class Thumb(models.Model):
>     name = models.CharField(max_length=80)
>     slug = models.CharField(max_length=80)
>     location = models.URLField()
>     height = models.IntegerField()
>     width = models.IntegerField()
>     system = models.ForeignKey('System')
>     image_category = models.ForeignKey('ImageCat')
>     big = models.ForeignKey('Image')
>     primary = models.BooleanField()
>
>     def __unicode__(self):
>         return self.name
>
> I'm thinking I should merge them by adding t_height, t_width and
> t_location to the 'Image' model. Am I missing any downside to doing
> this?
>
> Lance

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



Re: python manage.py runserver - can't see error stack traces when an Ajax handler throws an exception

2010-09-08 Thread Alex Robbins
I think Firebug can help with this. If you open the "Net" tab, you can
see the ajax requests. Then click on the ajax request that errored. I
think you can look at the exception in html down in the firebug
window, or possibly click open in new tab to see it bigger. I'm not
doing it right now, so my instructions may be a little off, but I'm
pretty sure I remember doing something like this.

Alex

On Sep 7, 3:10 pm, Phlip  wrote:
> Djangoists:
>
> Under runserver, when I click on an Ajaxy thing on my web site, and
> its handler throws an exception...
>
> ...the console says nothing (in DEBUG = True mode)
>
> ...and Django renders a beautiful HTML exception report
>
> ...and sends this over the wire into my browser
>
> ...who then throws it away because it's not Ajax
>
> ...and I must dig it out with a developer toolkit tool
>
> ...and paste it into a file yo.html
>
> ...and render this in a browser
>
> ...to see the actual error.
>
> I'm probably missing some configuration option, subsidiary to DEBUG
> mode. (v1.2, BTW)
>
> How do I get Ajax errors to print a simple exception trace to STDOUT,
> instead of going through all that baloney?
>
> --
>   Phlip
>  http://c2.com/cgi/wiki?SamuraiPrinciple<-- re: django.db!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email 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: manage.py: syncdb/sql do not pick up models from custom directory structure

2010-08-30 Thread Alex Robbins
If you define your models somewhere django doesn't expect, I think you
need to add the app_label in the model's Meta class.

http://docs.djangoproject.com/en/1.2/ref/models/options/#app-label

They mention the models submodule use case in the docs.

Hope that helps,
Alex

On Aug 30, 6:56 am, Daniel Roseman  wrote:
> On Aug 30, 7:46 am, Dan  wrote:
>
>
>
> > On 30 Aug., 08:26, Kenneth Gonsalves  wrote:> import 
> > lib.models
>
> > > from lib.models import * - you may get an error here
>
> > Both commands work without giving any error messages. However they do
> > not actually import anything, since the models reside in seperate
> > files in the models subdir and need to be imported by "import
> > lib.models.ModelFileName". If you do not know what I am talking about,
> > this is what I mean:
>
> >http://www.nomadjourney.com/2009/11/splitting-up-django-models/
>
> > Any other ideas?
>
> > Regards,
> > Dan
>
> In your lib/models/__init__.py, do `from FooModels import *` for each
> model file.
> --
> 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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: Error working on many-to-many lookups

2010-08-26 Thread Alex Robbins
Jonathan,

Pretty much any time you use __exact='text', you could use
='text' instead. I think the orm treats those two cases the
same. (It adds __exact if there isn't another lookup specified.

Alex

On Aug 25, 1:37 pm, Christos Jonathan Hayward
 wrote:
> I think I found the problem; for the record, I wanted text__exact, not
> text__equals.
>
> On Wed, Aug 25, 2010 at 1:27 PM, Christos Jonathan Hayward <
>
>
>
> christos.jonathan.hayw...@gmail.com> wrote:
> > I am trying to get a many-to-many tagging setup working, and I am getting
> > an error which may or may not be an issue with many-to-many specifically. An
> > Entity has a many-to-many field to Tag models; a Tag model only has one
> > (declared) field, text, a TextField. My code:
>
> > tag = directory.models.Tag.objects.filter(text__equals = name)[0]
>
> > is getting:
>
> > Exception Value: Join on field 'text' not permitted. Did you misspell
> > 'equals' for the lookup type?
>
> > Is text a reserved word here, or do I need to prepend the model name? I'm
> > trying to get the first Tag, if any exists, where the text field equals a
> > name I am testing against.
>
> > --
> > [image: Christos Jonathan Hayward] 
> > Christos Jonathan Hayward, an Orthodox Christian author.
>
> > Author Bio  • 
> > Books
> >  • *Email * • 
> > Facebook
> >  • LinkedIn  • 
> > Twitter
> >  • *Web * • What's 
> > New?
> > I invite you to visit my "theology, literature, and other creative works"
> > site.
>
> --
> [image: Christos Jonathan Hayward] 
> Christos Jonathan Hayward, an Orthodox Christian author.
>
> Author Bio  • 
> Books
>  • *Email * •
> Facebook
>  • LinkedIn  •
> Twitter
>  • *Web * • What's
> New?
> I invite you to visit my "theology, literature, and other creative works"
> site.

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

2010-08-17 Thread Alex Robbins
Maybe the ChoiceField should just be a CharField that just uses the
Select widget class? That way it won't have choices hardcoded into the
field validation. Your clean method could check that the domain is
valid.

Alex
On Aug 16, 1:39 pm, ringemup  wrote:
> I have a domain search form with two fields: a Textarea for inputting
> a list of domains to check, and a ChoiceField for selecting a domain
> based on suggestions.
>
> The ChoiceField is required, and on the first submission is auto-
> populated with suggestions based on the domains listed in the
> textarea.  Subsequently, the user may either enter a new list of
> domains to check, or select a domain from the radio buttons.
>
> However, when they select one of the radio buttons, the form never
> validates because the selected domain "is not one of the available
> choices" -- because, of course, the choices are populated only after
> the form is submitted.
>
> I'm having trouble working around this because of the messiness that
> is Django's FormWizard.  Any suggestions?
>
> Thanks!

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



Re: Long running process and time outs?

2010-08-17 Thread Alex Robbins
This is exactly the sort of issue that celery was created to solve. It
is a task queue management system.

http://celeryproject.org/

Alex

On Aug 14, 1:28 pm, ydjango  wrote:
> I have a online user initiated synchronous process which runs anywhere
> between 1-5 minutes and gives user status message at the end. It is a
> very DB intensive process that reads and updates lots of mysql rows
> and does many calculations. The process is run as part of a view
> method.
>
> It causes nginx to time out after 2-3 minutes with following message -
> "upstream timed out (110: Connection timed out) while reading response
> header from upstream".  User sees  504 gateway error on his browser.
>
> 1) How can I prevent time out. Can I ping the server via ajax or
> something to prevent time out.
> 2) How can I display to user - progress bar or in progress indicator -
> so that user can wait 3 - 5 minutes.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email 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: CSRF verification failures (admin)

2010-08-17 Thread Alex Robbins
Have you done any admin template customization? If you copied a
template from django before 1.2, then upgraded, your admin template
might be missing the csrf_token template tag.

Alex

On Aug 17, 7:55 am, PieterB  wrote:
> For an internal application, I constantly receive CSRF verification
> failed" errors... most of the times when using the admin interface
>
> It doesn't happen with the local dev version (dev http server) but
> happens with the deployment version (custom port, cherokee web server)
>
> I can only use the admin interface (very) temporarily with a Clear
> Recent History command
>
> This is very annoying :-S
>
> I've included
> 'django.middleware.csrf.CsrfViewMiddleware',
> 'django.middleware.csrf.CsrfResponseMiddleware'
>
> What am I doing wrong? Do I need also some sort of token for Django's
> admin interface?
>
> -- PieterB

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email 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: multiple forms for same model

2010-08-17 Thread Alex Robbins
contract_form.is_valid() looks at the data that was bound to the form.
This is normally the data in request.POST. It doesn't matter what a
form's initial data happened to be. It only matters what data you POST
back to it. If someone doesn't modify the form, then the initial and
the POSTed data are probably the same. However, if your form doesn't
have the read-only fields displayed in the template, they won't be
POSTing their data back.

Alex

On Tue, Aug 17, 2010 at 3:03 AM, Mess  wrote:
> Thx both for helping, I guess there isn't a straight forward solution,
> I'll prob add the missing fields manually.
>
> However I still don't get why contract_form.is_valid() doesn't return
> true since contract_form still contains the correct data when viewing
> in browser.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: multiple forms for same model

2010-08-16 Thread Alex Robbins
I think the problem is that your form doesn't have all the required
data. When you assign the instance, you provide initial data, and
something for form.save to modify. However, when the data is posted
back, It looks like maybe the non-editable fields aren't in the POST
data. You could add the fields you don't want edited as readonly on
the front end, then do validation like this:
http://stackoverflow.com/questions/324477/in-a-django-form-how-to-make-a-field-readonly-or-disabled-so-that-it-cannot-be#answer-331550

I'm only guessing since I don't think you showed your forms.py or
template code.

Hope that helps,
Alex

On Aug 16, 8:14 am, Mess  wrote:
> Sorry, I had cut out some unimportant parts of the view causing that
> error. The update_contract is called from another method only if it is
> a POST.
>
> My main issue is that it works as it should when logged in as admin
> (probably because all the fields are in the admin version of the
> form). But when logged in as external user and using different form
> with only some of the fields, I get missing fields error. But the
> contract_form still contains the data from all the fields.

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

2010-07-30 Thread Alex Robbins
You could look here: http://djangopeople.net/us/ny/
Or try posting here: http://djangogigs.com/
or here: http://djangozen.com/jobs/

Hope that helps,
Alex

On Jul 29, 11:27 am, Ken  wrote:
> Looking for a django developer in the NYC area!
> I would appreciate any help, if you know of anyone!
> Thank you!
>
> Ken

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email 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: Regex problem in urls

2010-07-30 Thread Alex Robbins
Based on the urls.py file you are showing us, it seems like /start/
should be a valid url.

Are you running the dev server with automatic reloading? Sometimes you
need to force a reload on it to see changes. (I normally notice that
in the admin, but it could come up anywhere stuff gets cached in
memory for performance on startup).

Alex

On Jul 29, 4:18 pm, Gordy  wrote:
> I'm a rookie at Django so this is probably something obvious.
>
> My urls.py looks like this:
>
> from django.conf.urls.defaults import *
>
> # Uncomment the next two lines to enable the admin:
> from django.contrib import admin
> admin.autodiscover()
>
> urlpatterns = patterns('',
>     # Example:
>     # (r'^sunlight/', include('sunlight.foo.urls')),
>
>     # Uncomment the admin/doc line below and add
> 'django.contrib.admindocs'
>     # to INSTALLED_APPS to enable admin documentation:
>     (r'^admin/doc/', include('django.contrib.admindocs.urls')),
>
>     # Uncomment the next line to enable the admin:
>     (r'^admin/(.*)', 'admin.site.root'),
>     (r'^start/', 'sunlight.start.views.index'),
>     (r'req/','sunlight.requests.views.index'),
> )
> ~
>
> When I hit the site, I get:
>
> Page not found (404)
> Request Method:         GET
> Request URL:    http://server2/start/
>
> Using the URLconf defined in sunlight.urls, Django tried these URL
> patterns, in this order:
>
>    1. ^admin/doc/
>    2. ^admin/(.*)
>    3. ^[/]$
>    4. req/
>
> The current URL, start/, didn't match any of these.
>
> So it looks like it isn't properly interpreting the regex on line 3.
>
> Any help would be appreciated.

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



Re: How to access a MySQL table in Django?

2010-07-29 Thread Alex Robbins
Whenever I have to pull data from legacy databases, I use './manage.py
inspectdb > models.py'. That will dump models for the database. Then I
rename the models to make more sense, and use the orm to get my data.

Alex

On Jul 28, 12:58 pm, snipinben 
wrote:
> I have the python-mysqldb installed already and i have  django up and
> running. when i installed the python-mysqldb i had to hack the code kind of
> so that it didnt check if the versions were the same so that it would work.
> I got this idea from online. but anyways, I am wondering how to access
> records that were already in the database before I started the project. i
> know how to access records from data that i inserted through tables in the
> models.py file. but i have no idea how to access them straight from the
> database itself. please give me any info you got. thanks
> --
> View this message in 
> context:http://old.nabble.com/How-to-access-a-MySQL-table-in-Django--tp292893...
> Sent from the django-users mailing list archive at Nabble.com.

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



Re: Calculate distance between 2 latitude/longitude Point

2010-07-29 Thread Alex Robbins
Geopy has a distance function build in, if you want something a little
more widely used/tested:
http://code.google.com/p/geopy/wiki/GettingStarted#Calculating_distances

Alex

On Jul 29, 5:23 am, Alexandre González  wrote:
> I've solved translating a JavaScript function to python:
>
> from math import *
>
> RADIUS = 6371 #Earth's mean raadius in km
>
> def distance(origin, destiny):
>     (latitude1, longitude1) = (origin[0], origin[1])
>     (latitude2, longitude2) = (destiny[0], destiny[1])
>
>     dLat = radians(latitude1 - latitude2)
>     dLong = radians(longitude1 - longitude2)
>
>     # matter of faith
>     a = sin(dLat/2) * sin(dLat/2) + cos(radians(latitude1)) *
> cos(radians(latitude2)) * sin(dLong/2) * sin(dLong/2)
>     c = 2 * atan2(sqrt(a), sqrt(1-a))
>
>     return (RADIUS * c)
>
> # a test
> origin = (40.96312364002175, -5.661885738372803)
> destiny = (40.96116097790996, -5.66283792257309)
> print distance(origin, destiny)
>
> 2010/7/29 Alexandre González 
>
>
>
> > I going to try it now, but the unique results that I obtain in google
> > searching [1] gd2gcc is this thread :)
>
> > [1]
> >http://www.google.com/search?hl=en=off=gd2gcc=f==...
>
> > Did
> > you make some mistake writting it?
>
> > Thanks,
> > Álex González
>
> > On Wed, Jul 28, 2010 at 19:34, !!CONDORIOUS!! wrote:
>
> >> (lat , lon in radians)
>
> >> pt 1 = lat, lon, alt=0
> >> pt 2 = lat, lon, alt=0
>
> >> p1_gcc = gd2gcc(p1)
> >> p1_gcc = gd2gcc(p2)
>
> >> gd2gcc ( is a standard operation found on the itnernet)
>
> >> dis = sqrt(sum(pow(p1_gcc-p2-gcc, 2)))
>
> >> cheers,
>
> >> 2010/7/28 Alexandre González :
> >> > Hi! I'm using the Django GEOS API [1] in my project to see the distance
> >> > between two users.
> >> > I get the coordinates from google maps in latitude/longitude mode and I
> >> need
> >> > to calculate the distance between them. I'm testing with .distance()
> >> method
> >> > at GEOSGeometry but I receive a strange value.
> >> > This is the result of one of my test:
> >> > In [45]: Point(40.96312364002175,
> >> > -5.661885738372803).distance(Point(40.96116097790996,
> >> -5.66283792257309))
> >> > Out[45]: 0.0021814438604553388
> >> > In Google Maps Distance Calculator [2] I can see that the result is:
> >> 0.145
> >> > miles = 0.233 km = 0.126 nautical miles = 233 meters = 764.436 feet
> >> > A friend told me on Google that perhaps I must calculate the distance in
> >> > UTMs and the results surely is a lat/long distance. To test it I need
> >> pygps
> >> > that is a project not maintained to import
> >> > LLtoUTMfrom from LatLongUTMconversion
> >> > Any idea about this?
> >> > [1]http://docs.djangoproject.com/en/dev/ref/contrib/gis/geos/
> >> > [2]
> >>http://www.daftlogic.com/projects-google-maps-distance-calculator.htm
>
> >> > --
> >> > Please, don't send me files with extensions: .doc, .docx, .xls, .xlsx,
> >> .ppt
> >> > and/or .pptx
> >> >http://mirblu.com
>
> >> > --
> >> > You received this message because you are subscribed to the Google
> >> Groups
> >> > "Django users" group.
> >> > To post to this group, send email to django-us...@googlegroups.com.
> >> > To unsubscribe from this group, send email to
> >> > django-users+unsubscr...@googlegroups.com
> >> .
> >> > For more options, visit this group at
> >> >http://groups.google.com/group/django-users?hl=en.
>
> >> --
> >> Condor
> >> 310.951.1177
> >> condor.c...@gmail.com
>
> >> :%s/war/peace/g
>
> >> --
> >> You received this message because you are subscribed to the Google Groups
> >> "Django users" group.
> >> To post to this group, send email 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.
>
> > --
> > Please, don't send me files with extensions: .doc, .docx, .xls, .xlsx, .ppt
> > and/or .pptx
> >http://mirblu.com
>
> --
> Please, don't send me files with extensions: .doc, .docx, .xls, .xlsx, .ppt
> and/or .pptxhttp://mirblu.com

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



Re: modelformset vs. inlineformset vs. DIY

2010-07-24 Thread Alex Robbins
If you need to edit the race and the candidates on the same page, and
the candidates are FK'ed to the race, I'd do it like this:

(Warning, just coding off the top of my head, might have bad syntax/
imports)

forms.py
-
from django import forms
from django.forms.models import modelformset_factory

from models import Candidate, Race

class RaceForm(forms.ModelForm):
class Meta:
model = Race

CandidateFormSet = modelformset_factory(Candidate, extra=0)

views.py
--
from django.shortcuts import get_object_or_404, redirect
from django.views.generic.simple import direct_to_template

from forms import RaceForm, CandidateFormSet
from models import Candidate, Race

def edit_race(request, race_slug):
race = get_object_or_404(slug=race_slug)
race_form = RaceForm(request.POST or None, instance=race)
candidate_formset = (request.POST or None,
queryset=Candidate.objects.filter(race=race))
if race_form.is_valid() and candidate_formset.is_valid():
race_form.save()
candidate_formset.save()
return redirect('.') #Or whatever page you want them to go to
after saving
return direct_to_template(request, 'edit_race.html', {
'race_form': race_form,
'candidate_formset': candidate_formset,
})

edit_race.html
-
{% block content %}

{{ race_form }}
{{ candidate_formset }}
Save

{% endblock %}

Hope I understood the question and that this helps,
Alex

On Jul 23, 8:23 am, Nick  wrote:
> I have inherited a project with a tight deadline and I am lost for how
> to proceed.
>
> There are two tables: Canididates and Race.
>
> The race table holds 145 different races with information about
> precincts, winners of different stages of the race (primary, runoff,
> gneral)
>
> The Candidates table has 1100+ candidates, each one is assigned to a
> specific race via a FK and a list of three race vote totals (general,
> runoff, primary)
>
> I am supposed to create a way to display each race based on a search
> and then return the candidates associated with that race so that the
> race vote totals can be updated. I will also need to be able to update
> values in the Race table.
>
> It would be highly preferable for this to be seemless for the data
> input people. I am looking at producing something like this:
>
> Race 1
> precincts reporting input - precincts total (static value)
> Candidate 1 primary vote input - Candidate 1 status (active,
> eliminated)
> Candidate 2 primary vote input - Candidate 2 status (active,
> eliminated)
>
> winner of primary (list of candidates)
>
> I have most of the form fields and widgets ready to go, but being able
> to edit multiple entries in two different tables seemless has me
> stuck.  Is this something that I should handle in inlineformsets since
> I am spanning an FK? Would I need modelformsets to display all of the
> candidates?
>
> I can easily truncate the Race table and change it so that it has a
> many to many relationship to all of the candidates instead of the
> Candidates having an FK relationship to the race? Would that give me
> more flexibility?
>
> Thanks for the help in figuring this out, this has been an incredibly
> stressful project.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email 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: Two apps with same url's in one project.

2010-07-24 Thread Alex Robbins
It sounds like you need to use url namespacing. When you include the
urls in your main urls.py file, add a namespace for each one. Then you
should be able to reverse them.
Define them:
http://docs.djangoproject.com/en/dev/topics/http/urls/#defining-url-namespaces

Reverse them:
http://docs.djangoproject.com/en/dev/topics/http/urls/#topics-http-reversing-url-namespaces

Hope that helps,
Alex

On Jul 22, 2:48 am, maciekjbl  wrote:
> Hi,
>
> I wrote two apps in same project. There're quite similar, and this is
> the problem here. They have two idetical urls.py files :
>
> App 1 :
>
> from django.conf.urls.defaults import *
> from web_aplikacje.promocje.models import Promocja, Producent, Dodatek
>
> info = { 'queryset' : Producent.objects.all(),
>          'template_object_name': 'producent',
>          'extra_context': { 'dodatek' : Dodatek.objects.all }
>
> }
>
> urlpatterns = patterns('web_aplikacje.promocje.views',
>    url(r'^search/$', 'search', name="link-search"),
> )
>
> urlpatterns += patterns('django.views.generic.list_detail',
>     url(r'^(?P[-\w]+)/$', 'object_detail', info, name="link-
> prod"),
>     url(r'^$','object_list', info, name="link-home"),
>
> )
>
> App 2:
>
> from django.conf.urls.defaults import *
> from web_aplikacje.cenniki.models import Opis, Producent, Cennik
>
> info = { 'queryset' : Producent.objects.all(),
>          'template_object_name': 'producent',
>          'extra_context': { 'cennik' : Cennik.objects.all }
>
> }
>
> urlpatterns = patterns('web_aplikacje.cenniki.views',
>    url(r'^search/$', 'search', name="link-search"),
> )
>
> urlpatterns += patterns('django.views.generic.list_detail',
>     url(r'^(?P[-\w]+)/$', 'object_detail', info, name="link-
> prod"),
>     url(r'^$','object_list', info, name="link-home"),
>
> )
>
> My main urls.py in root catalog for project :
>
> from django.conf.urls.defaults import *
> from django.conf import settings
> from django.contrib import admin
>
> admin.autodiscover()
>
> urlpatterns = patterns('',
>     (r'^promocje/', include('web_aplikacje.promocje.urls')),
>     (r'^cenniki/', include('web_aplikacje.cenniki.urls')),
>     (r'^admin/', include(admin.site.urls)),
> )
>
> if settings.DEBUG:
>     urlpatterns += patterns('',
>     (r'^site_media/(?P.*)$', 'django.views.static.serve',
>     {'document_root': '/home/virtual/web_aplikacje/img/'}),
> )
>
> Now every url which is generated by generic views have word 'cennik'.
> 'promocje' just gone from displaying in url's. I know this is because
> same generic view with slug in it, but I don't have idea how to
> separate them. I would like to have access to data in this form:
>
> http://some_site_name/promocje/producent-1/http://some_site_name/promocje/producent-2/
>
> http://some_site_name/cenniki/producent-1/http://some_site_name/cenniki/producent-2/
>
> Is it possible with this form of two apps in one project ? I can be
> even :
>
> http://some_site_name/some_main_site/promocje/producent-1/http://some_site_name/some_main_site/cenniki/producent-1/
>
> Any ideas ?

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



Re: URL reverse on username failing when username has a '.' literal in it

2010-07-23 Thread Alex Robbins
That probably means that the regex url pattern you defined for
feed_user in your urls.py file doesn't allow '.'

Hope that helps,
Alex

On Jul 22, 11:11 am, Roboto  wrote:
> I didn't expect this to occur, but when I attempt
> {% url feed_user entry.username %}
>
> I will get a 500 error when the username contains a '.'
> In this case rob.e as a username will fail.
>
> Any ideas how to deal with this?

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



Re: django + serving static CSS

2010-07-23 Thread Alex Robbins
Thomas,

MEDIA_URL isn't always defined in templates. Make sure that you have
the MEDIA context preprocessor installed:
http://docs.djangoproject.com/en/dev/ref/templates/api/#django-core-context-processors-media

Also, when you actually render the template, are you using
RequestContext? If you aren't then the context preprocessors won't
run. I normally use this shortcut, which works since
direct_to_template takes care of making a RequestContext instance:

from django.views.generic.simple import direct_to_template

def view_func(request):
some_variable = Model.objects.get(pk=1)
return direct_to_template(request, 'template.html', {
'some_variable': some_variable,
})

Hope that helps,
Alex

On Jul 23, 7:35 am, Thomas  wrote:
> Michale many thanks for your help.
> I added your suggestions. But that did not change the django GET
> request...
>
> It still tries to load the file
>
> http://127.0.0.1:8000/css/base.css
>
> instead of
>
> http://127.0.0.1:80/media/css/base.css
>
> Maybe it helps mentioning that this is with the Development server...
> and also an apache running on the same machine.
> If I put this in the base template it also works:
>
> http://localhost:80/media/css/base.css; rel="stylesheet" /
>
>
>
> But I would have to change that each time...
>
> On 23 Jul., 13:35, "Michael P. Soulier" 
> wrote:
>
> > On 23/07/10 Thomas said:
>
> > > Hi I am trying to include a css file and I've tried this in
> > > settings.py:
>
> > > MEDIA_URL = "http://localhost:80;
> > > MEDIA_ROOT = '/media/'
>
> > > I have an apache running there and navigating tohttp://localhost/media
> > > works fine.
> > > In my base template I have this:
>
> > > 
>
> > > But it's not working as I hoped. So how can I make the request
>
> > >http://127.0.0.1:80/media/css/base.css
>
> > > instead of this:
>
> > >http://127.0.0.1:8000/css/base.css
>
> > > Did I misunderstand MEDIA_URL and/or MEDIA_ROOT ?
>
> > Your media config needs to correspond to apache config.
>
> > For example:
>
> > 
> > SetHandler default
> > 
> > Alias /media/admin /usr/lib/python2.6/django/contrib/admin/media
> > Alias /media /path/to/my/project/media
>
> > Mike
> > --
> > Michael P. Soulier 
> > "Any intelligent fool can make things bigger and more complex... It takes a
> > touch of genius - and a lot of courage to move in the opposite direction."
> > --Albert Einstein
>
> >  signature.asc
> > < 1 KBAnzeigenHerunterladen

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

2010-07-21 Thread Alex Robbins
You'll have to write your own javascript to add forms dynamically.
Django doesn't provide front-end javascript.
Here are some ideas:
http://stackoverflow.com/questions/501719/dynamically-adding-a-form-to-a-django-formset-with-ajax

Hope that helps,
Alex



On Wed, Jul 21, 2010 at 9:52 AM, Ramesh <basukalaram...@gmail.com> wrote:
> I had already gone through those tutorial, they are really great.
>
> Here is my problem:
> At django tutorial it has two tables defined at models, Poll and
> Choice, Choice table has a foreign key that refers to Polls table.
>
> When adding Poll questions, I can add choices at the same time which
> eventually add records at two tables.
> I can add as many choices as I want by clicking at "Add another
> Choice".
> I would like to have same feature on my form which is outside the
> admin site. How can do that ?
>
> Thanks!
> Ramesh
>
>
>
> On Jul 21, 8:53 am, Alex Robbins <alexander.j.robb...@gmail.com>
> wrote:
>> The ability to make multiple forms of the same type is a 
>> formset.http://docs.djangoproject.com/en/1.2/topics/forms/formsets/#topics-fo...
>>
>> If you want those forms to represent models, then you want a model
>> formset.http://docs.djangoproject.com/en/1.2/topics/forms/modelforms/#id1
>>
>> Hope that helps!
>> Alex
>>
>> On Jul 20, 1:00 pm, Ramesh <basukalaram...@gmail.com> wrote:
>>
>>
>>
>> > Hi,
>>
>> > I would like to have inline forms for my project (not admin site) as
>> > shown in django tutorials "Writing your first Django app, part 
>> > 2",http://docs.djangoproject.com/en/dev/intro/tutorial02/
>>
>> > Here is the form image 
>> > url:http://docs.djangoproject.com/en/dev/_images/admin12.png
>>
>> > This works fine on my admin site, obviously I followed the tutorial.
>>
>> > Now I would like to have same kind of inline form which is outside the
>> > admin site. How can I do that?
>> > I want to add as many field as I want similar to the example shown for
>> > poll admin sit.
>>
>> > Can someone please provide me some idea/resource from where I can
>> > start with ?
>>
>> > Thanks!
>> > Ramesh
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Inline forms

2010-07-21 Thread Alex Robbins
The ability to make multiple forms of the same type is a formset.
http://docs.djangoproject.com/en/1.2/topics/forms/formsets/#topics-forms-formsets

If you want those forms to represent models, then you want a model
formset.
http://docs.djangoproject.com/en/1.2/topics/forms/modelforms/#id1

Hope that helps!
Alex

On Jul 20, 1:00 pm, Ramesh  wrote:
> Hi,
>
> I would like to have inline forms for my project (not admin site) as
> shown in django tutorials "Writing your first Django app, part 
> 2",http://docs.djangoproject.com/en/dev/intro/tutorial02/
>
> Here is the form image 
> url:http://docs.djangoproject.com/en/dev/_images/admin12.png
>
> This works fine on my admin site, obviously I followed the tutorial.
>
> Now I would like to have same kind of inline form which is outside the
> admin site. How can I do that?
> I want to add as many field as I want similar to the example shown for
> poll admin sit.
>
> Can someone please provide me some idea/resource from where I can
> start with ?
>
> Thanks!
> Ramesh

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

2010-07-16 Thread Alex Robbins
PostgreSQL is better supported by South, the leading django database
migration tool. It allows you to make schema altering migrations
within a transaction, so they can be rolled back if the migration
fails. On MySQL you are just left with a half-migrated database.

Also, if you are going to use much GeoDjango functionality, you'll
probably need PostgreSQL.

Alex

On Jul 16, 7:10 am, Doane  wrote:
> I'm a new Django user. Which database management system should I use
> in developing Django apps, MySQL or PostgreSQL?  Why?
>
> Thanks...Doane

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

2010-06-29 Thread Alex Robbins
Eduan,

This might be a little technical for a beginner, but you'll have to
learn sometime :)

Python looks for modules according to the python path. If your module
isn't available on the path, then you'll get an error like you are
seeing. I believe that manage.py adds the directory it is in to the
python path. However, it is looking inside the mysite folder for a
module called mysite, with a folder inside it called polls. (mysite/
mysite/polls). You either need to add the folder above the manage.py
file to the python path or rename the installed app to just "polls".

You can see your python path from the shell by typing:
import sys
print sys.path

Also, make sure anything that python should be looking at has an
__init__.py file in it. The __init__.py file is what makes a directory
a python module. Without that __init__.py file python will mostly
ignore it.

Hope that helps!
Alex

On Jun 29, 7:00 am, Eduan  wrote:
> Okay thanks that you all are so helpful.
> I went through the whole tutorial allot of times and can't even
> complete part 1.
> I thought that it was my setup that i was using.
> I am using Windows 7 and Eclipse SDK Version: 3.5.2 for my programming
> environment. I am using a MySQL 5.5 database.
>
> It all goes fluently till I get to the part where you add
> 'mysite.polls' under installed apps.
> After adding that in there I can't run any command(like
> syncdb,runserver) without getting back an error stating:
> Error: No module named mysite.polls.
> I tried renaming it and I still get that error.
>
> I have downloaded an full Django app called friends here 
> :http://github.com/jtauber/django-friends/
> If I syncdb or runserver I get the similar error:
> Error: No module named friends
>
> Now please any help. This could be a simple beginners mistake that I
> am making. Thanks allot
> Eduan

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email 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: Looking for unavailable table?

2010-06-29 Thread Alex Robbins
You can also use ./manage.py validate to get django to check over your
models. Sometimes syncdb or others will fail because of a model
validation issue.

Alex

On Jun 28, 3:20 pm, Jonathan Hayward
 wrote:
> P.S. This problem did not resurface after I made other changes discussed
> elsewhere in the thread; it seems to be secondary damage.
>
> On Mon, Jun 28, 2010 at 2:46 PM, Jonathan Hayward <
>
>
>
> christos.jonathan.hayw...@gmail.com> wrote:
> > Thanks for pointing me to South. I've glanced over it, but I did have one
> > question:
>
> > My understanding is that Django will introduce tables for models that have
> > been added on a syncdb, but not alter tables for models that have been
> > changed. And from a glance at the documentation, it looks like South would
> > provide more granularity.
>
> > However, it is my understanding that this should have the consequence that
> > if you start with a fresh database and run syncdb, then that should result
> > in appropriate tables. This might not be a first choice way to update the
> > database as normally wiping the database when you implement a schema update
> > is not desirable if you have any real data, but my understanding from the
> > documentation is that this forceful solution should work. If I'm mistaken,
> > I'd like to know both how I presently misunderstand, and what an appropriate
> > way is to generate a fresh database with tables matching your models.
>
> > On Fri, Jun 25, 2010 at 5:25 PM, Mark Linsey  wrote:
>
> >> I don't quite understand what changes you made before producing this
> >> error, and I'm totally unfamiliar with sqllite.
>
> >> But I do know that for many (really, most) different model changes, just
> >> running syncdb will not make the appropriate changes to your tables.  You
> >> probably need to look into south migrations.
>
> >> On Fri, Jun 25, 2010 at 2:09 PM, Jonathan Hayward <
> >> christos.jonathan.hayw...@gmail.com> wrote:
>
> >>> P.S. Renaming the (SQLite) database file and running syncdb again
> >>> produces (basically) the same behavior. I had to do some initialization
> >>> things again, but outside of that I got equivalent behavior to what I 
> >>> pasted
> >>> below.
>
> >>> What I am trying to do is create a few instances of the Entity model
> >>> defined in my [directory/]models.py. So far I have managed to get them to
> >>> show up as an option to manage in the admin interface, but not yet to save
> >>> one.
>
> >>> Should it be looking for directory_models_entity instead of
> >>> directory_entity? "entity" seems not to be populated; from the command 
> >>> line
> >>> sqlite3:
>
> >>> sqlite> .tables
> >>> auth_group                  auth_user_user_permissions
> >>> auth_group_permissions      django_admin_log
> >>> auth_message                django_content_type
> >>> auth_permission             django_session
> >>> auth_user                   django_site
> >>> auth_user_groups
>
> >>> On Fri, Jun 25, 2010 at 3:00 PM, Jonathan Hayward <
> >>> christos.jonathan.hayw...@gmail.com> wrote:
>
>  I received the error below from the admin interface; I thought it was
>  because I needed to run a syncdb, but stopping the server, running a 
>  syncdb,
>  and restarting has generated the same error:
>
>  OperationalError at /admin/directory/entity/
>
>  no such table: directory_entity
>
>   Request Method:GET Request URL:
> http://linux:8000/admin/directory/entity/Exception Type:
>  OperationalError Exception Value:
>
>  no such table: directory_entity
>
>  Exception 
>  Location:/usr/lib/pymodules/python2.6/django/db/backends/sqlite3/base.py
>  in execute, line 193 Python Executable:/usr/bin/python Python Version:
>  2.6.5 Python Path:['/home/jonathan/directory',
>  '/usr/local/lib/python2.6/dist-packages/pip-0.6.3-py2.6.egg',
>  '/home/jonathan/store/src/satchmo/satchmo/apps',
>  '/usr/local/lib/python2.6/dist-packages/django_threaded_multihost-1.3_3-py2.6.egg',
>  '/usr/local/lib/python2.6/dist-packages/django_signals_ahoy-0.1_1-py2.6.egg',
>  '/usr/local/lib/python2.6/dist-packages/django_tagging-0.3.1-py2.6.egg',
>  '/usr/lib/python2.6', '/usr/lib/python2.6/plat-linux2',
>  '/usr/lib/python2.6/lib-tk', '/usr/lib/python2.6/lib-old',
>  '/usr/lib/python2.6/lib-dynload', '/usr/lib/python2.6/dist-packages',
>  '/usr/lib/python2.6/dist-packages/PIL',
>  '/usr/lib/python2.6/dist-packages/gst-0.10', 
>  '/usr/lib/pymodules/python2.6',
>  '/usr/lib/python2.6/dist-packages/gtk-2.0',
>  '/usr/lib/pymodules/python2.6/gtk-2.0',
>  '/usr/local/lib/python2.6/dist-packages'] Server time:Fri, 25 Jun 2010
>  14:56:26 -0500
>
>  I have an Entity class/model defined in my models.py and want to
>  manually create some dummy data in the table. Any suggestions?
>
>  --
>  → Jonathan Hayward, christos.jonathan.hayw...@gmail.com
>  → An Orthodox 

Re: Help: Custom ManyRelatedManager Behavior

2010-06-10 Thread Alex Robbins
I recently ran into this same problem (I wanted to only show related
episodes that had been marked live). I ended up just making a method
on Podcasts to do it.

class Podcast(models.Model):
  ...some data fields...

  def live_episodes(self):
return self.episode_set.filter(live=True)

class Episode(models.Model):
  episode = models.ForeignKey(Podcast)
  live = models.BooleanField()

Hope that helps,
Alex

On May 31, 6:26 pm, Tim  wrote:
> Hi, I am having trouble getting the behavior I would like from a
> ManyRelatedManager.
>
> I have a many to many relationship with User and ModelB, with a join
> table ModelJ. Instead of deleting items in my database, I am simply
> marking them as deleted. I have a custom manager that filters out
> deleted objects as a first step. Everything was working fine until I
> ran across the following problem:
>
> To access objects of ModelB that a belong to a User, say user1, I use
> user1.modelb_set. Let's say user1.modelb_set returns modelb1, modelb2,
> and modelb3. Finally let modelj2 describe the relationship between
> user1 and modelb2.
>
> If I set modelj2.deleted = True, I was hoping that user1.modelb_set
> would only return modelb1 and modelb3. Unfortunately it still returns
> all three modelb objects. I guess this is because the "deleted"
> attribute is being set on the join table, and not the ModelB table.
>
> Does anybody know how to set up custom behavior for a
> ManyRelatedManager? Basically, I would like to break links between
> User and ModelB by marking their ModelJ link as deleted, not actually
> deleting it from the database.
>
> Thank you,
> Tim

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email 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: assigning data based on a comparison between two tables

2010-06-10 Thread Alex Robbins
It is probably better to use candidates.count(), rather than
len(candidates). len will cause the whole queryset to be loaded into
memory. It doesn't look like you use it later, so that is kind of a
waste.

Hope that helps,
Alex

>From django docs:
Note: Don't use len()  on QuerySets if all you want to do is determine
the number of records in the set. It's much more efficient to handle a
count at the database level, using SQL's SELECT COUNT(*), and Django
provides a count()  method for precisely this reason. See count()
below.

On Jun 9, 1:24 pm, Nick  wrote:
> Just to let you know, this code worked out nicely.
>
> I made a few changes to the bottom save function:
>
> if len(candidates) > 1:
>     raise Exception
> candidates.update(incumbent=True)
>
> On Jun 8, 6:11 pm, Nick  wrote:
>
> > Thanks Dan, I'll give it a shot
>
> > On Jun 8, 6:00 pm, Dan Harris  wrote:
>
> > > Perhaps not the greatest way of doing things, but simple to code/read:
>
> > > class Candidate(models.Model):
> > >    first_name = models.CharField(max_length=30)
> > >    last_name = models.CharField(max_length=30)
> > >    incumbent = models.BooleanField()
>
> > > class HoldsOffice(models.Model):
> > >    first_name = models.CharField(max_length=30)
> > >    last_name = models.CharField(max_length=30)
>
> > > for officer in HoldsOffice.objects.all():
> > >    candidates =
> > > Candidate.objects.filter(first_name__iequals=officer.first_name).filter(last_name__iequals=officer.last_name)
>
> > >    if len(candidates)>0:
> > >       raise Exception("More than 1 match found")
> > >    candidates[0].incumbent = True
> > >    candidates[0].save()
>
> > > Something like that might work for you assuming that the models and
> > > stuff are similar. Also, this code is just off the top of my head, so
> > > who knows if it will actually work :)
>
> > > Cheers,
>
> > > Dan Harris
> > > dih0...@gmail.com
>
> > > On Jun 8, 6:30 pm, Nick  wrote:
>
> > > > I have two models. One is a list of candidates that have filed to run
> > > > for office. The second is a list of people who currently hold
> > > > office.
>
> > > > I'd like to compare the two tables and whenever a match is found
> > > > between the two (an entry in the candidate table shares the same
> > > > last_name and first_name with an office holder from the holds office
> > > > table) I'd like to check off a box in the Candidate table called
> > > > 'incumbent'.
>
> > > > how would I begin to do this. They both have columns called last_name
> > > > and first_name that I can use to compare but I don't know the syntax.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email 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: multiple databases -- database across sites?

2010-06-10 Thread Alex Robbins
Chris,

The sites contrib app seems to address your use case.
http://docs.djangoproject.com/en/dev/ref/contrib/sites/

You could just add a foreign key to site in the second app and modify
the manager to only get items for the current site.

class SiteSpecificManager(db.Manager):
  def get_query_set(self):
return super(SiteSpecificManager,
self).get_query_set().filter(site=Site.objects.get_current())

or something like that. Hope that helps,

Alex

On Jun 10, 3:11 am, chris  wrote:
> Hi there,
>
> I have the following problem:
>
> There is one django site, which consists of two apps, the data for
> these apps are stored in a database.  Some of the models in one app
> access models from the other app.
>
> Now I want to create a new site (on the same server), which contains
> new data for one of the apps, but needs to re-use and extend the data
> from the second app (the first site will also continue to use the data
> in this part).
>
> I realized that Django 1.2.1 supports multiple databases, but I am
> still not sure if this is possible and if yes, how it can be done.
> Any help appreciated.
>
> Chris

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email 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: Upgrading Python from 2.4 to 2.6 - can I just copy site-packages folder?

2010-06-08 Thread Alex Robbins
you could do a pip freeze in your old install, then do a pip install
-r requirements in the new one. That would probably catch most things.

Alex

On Tue, Jun 8, 2010 at 9:50 AM, Bill Freeman <ke1g...@gmail.com> wrote:
> Additionally, the .pyc files are version specific. IF you had no specific
> incompatibilities, you could consider deleting all .pyc files in the copy,
> then import every .py file running as root, to make new .pyc files.
>
> But then there are likely to be plenty of other issues anyway, as Alex
> points out.
>
> This is all much more work than just installing stuff fresh, in these bold
> new days of distribute and pip install.
>
> Bill
>
> On Tue, Jun 8, 2010 at 10:32 AM, Alex Robbins
> <alexander.j.robb...@gmail.com> wrote:
>> You don't want to just copy site-packages. If you have any compiled
>> modules (pyyaml, PIL, etc) they won't work, since they were compiled
>> for the old version of python.
>>
>> Alex
>>
>> On Jun 8, 4:25 am, Nick <n...@njday.com> wrote:
>>> Hi,
>>>
>>> I'm currently running Django on CentOS using the supplied Python 2.4.
>>> I now need to use Python 2.6.  I have installed Python 2.6 from the
>>> EPEL repositories, which sits alongside 2.4 (which is required for
>>> CentOS things such as "yum").
>>>
>>> Django (and other Python modules) are all located in Python 2.4's site-
>>> packages folder.  When I upgrade to 2.6, is it just a case of copying
>>> these over into 2.6's site-packages folder, or do I need to install
>>> the modules afresh?
>>>
>>> Thanks,
>>> Nick
>>
>> --
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To post to this group, send email to django-us...@googlegroups.com.
>> To unsubscribe from this group, send email to 
>> django-users+unsubscr...@googlegroups.com.
>> For more options, visit this group at 
>> http://groups.google.com/group/django-users?hl=en.
>>
>>
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email 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: Good idea to process form data in separate thread or process to avoid blocking? How?

2010-06-08 Thread Alex Robbins
Celery is a python job queue system that a lot of people really like.
I think it would allow you to do the form processing asynchronously.

http://celeryproject.org/

Hope that helps,
Alex

On Jun 7, 11:31 pm, Chris Seberino  wrote:
> I don't want Django site to block while form data is being processed.
>
> What is easiest way to run a separate script in a separate thread or
> process with form data as input parameters?
>
> e.g. commands.getoutput("my_script arg1 arg2") or
>        os.system("my_script arg1 arg2") <--- possible to run these in
> separate thread or process easily so Django app doesn't have to wait
> on it?  How?
>
> Thanks!
>
> Chris

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email 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: Upgrading Python from 2.4 to 2.6 - can I just copy site-packages folder?

2010-06-08 Thread Alex Robbins
You don't want to just copy site-packages. If you have any compiled
modules (pyyaml, PIL, etc) they won't work, since they were compiled
for the old version of python.

Alex

On Jun 8, 4:25 am, Nick  wrote:
> Hi,
>
> I'm currently running Django on CentOS using the supplied Python 2.4.
> I now need to use Python 2.6.  I have installed Python 2.6 from the
> EPEL repositories, which sits alongside 2.4 (which is required for
> CentOS things such as "yum").
>
> Django (and other Python modules) are all located in Python 2.4's site-
> packages folder.  When I upgrade to 2.6, is it just a case of copying
> these over into 2.6's site-packages folder, or do I need to install
> the modules afresh?
>
> Thanks,
> Nick

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



Re: Using array of URLs for MEDIA_URL

2010-06-08 Thread Alex Robbins
I haven't tested this, but it seems like you could do it one of two
ways:

Define media root as a function in your settings.py. If you pass a
callable to the template, it will be called.
MEDIA_ROOTS = ['server1', 'server2', 'server3']
def MEDIA_ROOT():
from random import choice
return choice(MEDIA_ROOTS)

OR

Use a context processor to add MEDIA_ROOTS to the context and use the
random template tag.

{{ MEDIA_ROOTS|random }}


Steven's custom template tag works too.

Alex
On Jun 8, 7:32 am, Martin Siniawski  wrote:
> Steve,
>
> Thanks for the answer.
>
> If I understand correctly your idea and code, each template would have
> only one value for the MEDIA_URL (randomly chosen from the array),
> right?
>
> What I was looking for was a way of distributing the value of the
> MEDIA_URL uniformly along the values of an array, in each template. So
> in a certain template the MEDIA_URL would have more than one value.
> Maybe if I set it as a callable (with the logic that choses the values
> inside it) that would work.
>
> I cannot quite understand why there isn't anymore people running into
> this issue.
>
> Best and thanks again for the answer,
> Martin
>
> On Jun 7, 10:46 am, Steven L Smith  wrote:
>
> > Hi Martin-
>
> > I don't know what the "official" answer would be, but you could write your 
> > own
> > context processor that had something like:
>
> > from random import choice
> > MEDIA_URLS =  'static1.site.com', 'static2.site.com', 'static3.site.com' ]
> > def media(request):
> >     return {'MEDIA_URL': choice(MEDIA_URLS)}
>
> > Then, in settings.py, include your custom context processor instead of the 
> > one
> > built-in to to Django.
>
> > -Steve
>
> > 
> > Steven L Smith, Web Developer
> > Department of Information Technology Services
> > Nazareth College of Rochester
> > 585-389-2085   |   ssmit...@naz.eduhttp://www.naz.edu/pub/~ssmith46
> > 

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



Re: How to write the reverse function for the following

2010-06-07 Thread Alex Robbins
Clark,

The reverse call just uses kwargs to find out which pattern it matches
to. If your url regex was r'^register/(?P\w+)/', then you
would pass kwarg1 as a kwarg to reverse. You are not trying to find a
url with a kwarg in the regex, so you shouldn't be adding that in the
reverse call. You just need to make a second url entry that has the
special success kwarg setup already. Give it a different name and
regex, then reverse to it directly.

Hope that helps,
Alex

On Jun 7, 6:54 am, Superman  wrote:
> The urlconf:
>                    url(r'^register/$',
>                        register,
>                        { 'backend':
> 'registration.backends.default.DefaultBackend' },
>                        name='registration_register'),
> The view:
>                     def register(request, backend, success_url=None,
> form_class=None,
>
> disallowed_url='registration_disallowed',
>                                  template_name='registration/
> registration_form.html',
>                                  extra_context=None):
>
> What i want to do is redirect users to the register page and specify a
> success_url. I tried reverse('registration.views.register',
> kwargs={'success_url':'/test/' }) but that doesn't seem to work. I've
> been trying for hours and can't get my mind around getting it right.
> Thanks

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



Re: How can I test the correctness of my models against the schema of a database?

2010-06-01 Thread Alex Robbins
Its been a while since I worked with a live db and unit tests for this
sort of thing, but I think this is how we did it:
Put the tests in a tests.py file in an app like normal, but for the db
test, inherit from the python test framework's UnitTest. That test
will not get a special test db, so be very, very careful.

Alex

On May 31, 8:16 am, David Horat  wrote:
> Thanks for the info Jani.
>
> One question: How did you manage to make the tests in Django?
> Because it forces you to create a test database and the idea of our
> tests is to do them on an already full test database.
> My idea if I can't skip it is to try and make them with the Python
> Unit Testing Framework. But I would prefer all tests to be together in
> Django.
>
> Regards,
> David
>
> On May 31, 8:34 am, Jani Tiainen  wrote:
>
> > Not really.
>
> > If you're specially working with legacy databases trying to figure out that 
> > do
> > Django models match underlying schema is PITA.
>
> > We resolved this partially by doing few simple tests, namely running through
> > all models and doing empty query. Since Django ORM queries for every field 
> > it
> > revealed most of the problems right away. Of course we didn't checked 
> > lenghts
> > or types of field.
>
> > Also this could be useful in development phase when you add new fields.
>
> > In django-command-extensions exists dbdiff command which produces somekind 
> > of
> > diff against underlying database but it's in very early stages.
>
> > > Sorry. I haven't use other methods for that.
> > > But isn't it enough to test it using loremiser or something like that
> > > and like an addition debug toolbar?
>
> > > On May 31, 12:53 am, David Horat  wrote:
> > > > Dear group,
>
> > > > How can I test the correctness of my models against the schema of a
> > > > database?
>
> > > > To solve this question, I have tried unsuccessfully several options:
> > > > - Using ./manage.py test triggers the creation and destruction of a
> > > > database, but I want to check the correctness of the model against a
> > > > production database, since I just want to check the schema, not the
> > > > content.
> > > > - Creating my own test runner as specified
> > > > herehttp://stackoverflow.com/questions/138851whichbasically hacks the
> > > > Django stack and gives you other problems. In any case this seems not to
> > > > be the correct way.
>
> > > > Has anyone of you faced this situation before? Any clues?
>
> > > > Thank you in advance.
>
> > > > Best Regards,
> > > > David Horat
>
> > --
>
> > Jani Tiainen

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



Re: Installation problem (version 1.2.1)

2010-05-28 Thread Alex Robbins
I think Daniel might mean you can also use the __file__ attribute, as
in:
>>> import django
>>> django.__file__

Hope that helps,
Alex

On May 28, 4:07 am, Daniel Roseman  wrote:
> On May 28, 9:56 am, Derek  wrote:
>
>
>
> > I have just upgraded my version of Ubuntu, which then also installed
> > Python 2.6.  I thought this was a good opportunity to upgrade to
> > Django 1.2.  I removed all traces of Django 1.1.1 that I could find,
> > along with extra plugins/modules/apps etc, and ran the install for
> > Django 1.2.1, checking that I was specifying "python2.6" when doing
> > so.
>
> > However when I try and start a new project (django-admin.py
> > startproject test), I get:
>
> > Traceback (most recent call last):
> >   File "/usr/local/bin/django-admin.py", line 2, in 
> >     from django.core import management
> >   File "/usr/lib/pymodules/python2.6/django/core/management/__init__.py",
> > line 11, in 
> > AttributeError: 'module' object has no attribute 'get_version'
>
> > If I start a Python session, I can do:
>
> > >>> import django
> > >>> dir(django)
>
> > ['__builtins__', '__doc__', '__file__', '__name__', '__package__', 
> > '__path__']
>
> > which seems incomplete?
>
> > What (probably obvious) step or action have I missed or messed up?
>
> > Thanks
> > Derek
>
> Sounds like you have an old 'django' directory somewhere on your
> pythonpath that is empty apart from an __init__.py.
>
> In your shell, do:
>
> >>> import django
> >>> django.__path__
>
> to see where it is, and delete it.
> --
> 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-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: Grouping of applications in admin

2010-05-26 Thread Alex Robbins
You should check out django-admin-tools [0]
It lets you make lots of changes to the admin index page.

Hope that helps,
Alex

[0]http://bitbucket.org/izi/django-admin-tools/wiki/Home
On May 25, 9:54 am, Dejan Noveski  wrote:
> Hello,
>
> Is there a way i can group admin models from different applications to show
> in one container in admin initial page?
>
> Thanks,
> Dejan
>
> --
> --
> Dejan Noveski
> Web Developer
> dr.m...@gmail.com
> Twitter:http://twitter.com/dekomote| 
> LinkedIn:http://mk.linkedin.com/in/dejannoveski
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

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



Re: testing the comment framework using the test client

2010-05-26 Thread Alex Robbins
The way I've tested it in the past is:

GET the page, using the client. Scrape the values you need.
(BeautifulSoup makes this really easy, but you can do it with python's
builtin stdlib I guess.)
POST the comment message, along with all the values you just scraped.

Hope that helps,
Alex

On May 25, 10:41 am, Thierry  wrote:
> How do you guys test implementations of the django comment framework?
> A regular post doesnt seem to work because it depends on data from a
> previous get.
> An thoughts?
>
>     def test_comment(self):
>         item_url = reverse('item', args=['4558'])
>         self.client.login(username=self.username,
> password=self.password)
>         import datetime
>         test_message = 'test at %s' % datetime.datetime.today()
>         item_view = self.client.get(item_url)
>         comment_submit = self.client.post(item_url, {'comment':
> test_message})
>         test = open('test.html', 'w')
>         import os
>         print dir(test)
>         print test.name
>         print os.path.abspath(test.name)
>
>         test.write(unicode(comment_submit))
>         item_view = self.client.get(item_url)
>         self.assertContains(item_view, test_message)
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

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



Re: EmailField etc. and VARCHAR / TEXT

2010-05-26 Thread Alex Robbins
If you are using 1.2, then you could make a TextField with an email
validator. That gets bonus points for using a new feature :)
http://docs.djangoproject.com/en/dev/ref/forms/validation/#using-validators

Alex

On May 26, 8:24 am, Jonathan Hayward
 wrote:
> Thanks!
>
> On Wed, May 26, 2010 at 5:32 AM, Daniel Roseman wrote:
>
>
>
> > On May 25, 10:49 pm, Jonathan Hayward
> >  wrote:
> > > For CharField, EmailField, URLField, etc., is VARCHAR implementation
> > > (meaning a fixed limit on length) absolutely non-negotiable, or there a
> > way
> > > to make e.g. a CharField that won't truncate if you cross some arbitrary
> > > length?
>
> > > (If you don't specify a length, does it assign a default length, or use
> > TEXT
> > > instead of VARCHAR so that a field of indefinite length is accommodated,
> > > resources permitting?)
>
> > EmailField is a subclass of CharField, so it always uses a varchar. As
> > the documentation notes, the default length if you don't specify one
> > is 75.
>
> > If you really want an email field based on TEXT, you could subclass
> > EmailField with a get_internal_type method that returns 'TextField'.
> > --
> > 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-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.
>
> --
> → Jonathan Hayward, christos.jonathan.hayw...@gmail.com
> → An Orthodox Christian author: theology, literature, et cetera.
> → My award-winning collection is available for free reading online:
> ☩ I invite you to visit my main site athttp://JonathansCorner.com/

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



Re: Security Question...

2010-05-25 Thread Alex Robbins
Yeah, I understand that the data doesn't need to be encrypted. I just
agree with you that SSL would be ideal.

If you had SSL, then I don't think you'd need to work as hard with the
public/private key hashing stuff. If all the transmitted data was
encrypted (SSL) you could just send a clear-text password in the post
data. No hashing, no public/private key, just easy.

Alex



On Tue, May 25, 2010 at 9:17 AM, ringemup <ringe...@gmail.com> wrote:
>
> By app-level solution you mean some sort of custom encryption /
> decryption scheme for the data dictionaries?
>
> I'm still not convinced the data needs encryption -- I mean, it
> wouldn't hurt and in an ideal world I'd just push everything over SSL,
> but the worst thing that happens if someone gets hold of the data
> we're exchanging is a customer who has to call support because their
> activation key registers as already in-use, not any sort of identity
> theft or loss of financial credentials.
>
> Mostly with this I'm just trying to make sure that I can prevent
> unauthorized users from using the API to make themselves free
> activation keys.
>
>
> On May 25, 10:02 am, Alex Robbins <alexander.j.robb...@gmail.com>
> wrote:
>> It might be worth a try to see if the self-signed cert gets you into
>> trouble or not. Some url libraries might complain about it, but I
>> don't think that the behavior is universal. As I think about it, I
>> think it is normally browsers that whine about self-signed certs.
>> Maybe the other server wouldn't even mention it? Anyway, it'd be a lot
>> easier to setup an ssl cert than roll your own app level solution.
>>
>> Good luck!
>> Alex
>>
>> On May 24, 10:57 am, ringemup <ringe...@gmail.com> wrote:
>>
>>
>>
>> > Not a bad idea, actually, but the other site is on shared hosting, so
>> > I don't expect the host to be willing to add a self-signed cert as
>> > trusted.
>>
>> > On May 24, 10:07 am, Alex Robbins <alexander.j.robb...@gmail.com>
>> > wrote:
>>
>> > > Just a thought, but if you are the only person using the url, you
>> > > could make your own self-signed security cert. It would be free and
>> > > protect your data. It won't show up as trusted to users, but your
>> > > other server can be set to accept it. (Assuming the lack of ssl is a
>> > > budget issue, that wouldn't fix a technical issue.)
>>
>> > > Alex
>>
>> > > On May 23, 10:10 am, ringemup <ringe...@gmail.com> wrote:
>>
>> > > > Hi folks --
>>
>> > > > I'm putting together a simple API to allow a separately-hosted but
>> > > > trusted site to perform a very limited set of actions on my site.  I'm
>> > > > wondering whether the design I've come up with is reasonably secure:
>>
>> > > > - Other site gets an API key, which is actually in two parts, public
>> > > > key and private key, each of which is a uuid generated by Python's
>> > > > uuid module.
>>
>> > > > - The API key object in the DB references a User object, whose
>> > > > permissions determine what actions the API key owner may take
>>
>> > > > - Other site submits a POST request to a special URL on my site.  POST
>> > > > request contains 3 vars: public_key, data (as JSON), hash.
>>
>> > > > - Hash is a SHA1 of the data concatenated with the private key
>>
>> > > > - I use the public key to search the database for the API key and
>> > > > permissions.
>>
>> > > > - I generate the SHA1 of the data concatenated with the private key
>> > > > from the DB, and check it against the submitted hash; only if they
>> > > > match do I decode the data dict and take the actions specified within
>>
>> > > > - I then return an HTTP response containing a JSON object of the
>> > > > format:
>>
>> > > > {
>> > > >     return_data: [object containing success / failure codes, messages,
>> > > > any other data],
>> > > >     hash: [SHA1 of return_data concatenated with private key]
>>
>> > > > }
>>
>> > > > - All data will be transmitted in the clear (no SSL currently
>> > > > available -- *sigh*), but there will be no sensitive data in the
>> > > > incoming data dict.  return_data may contain values that aren't meant
>> > > > to be broadcasted, but aren't really sensitive (along the lines of
>> > > > activa

Re: Security Question...

2010-05-25 Thread Alex Robbins
It might be worth a try to see if the self-signed cert gets you into
trouble or not. Some url libraries might complain about it, but I
don't think that the behavior is universal. As I think about it, I
think it is normally browsers that whine about self-signed certs.
Maybe the other server wouldn't even mention it? Anyway, it'd be a lot
easier to setup an ssl cert than roll your own app level solution.

Good luck!
Alex

On May 24, 10:57 am, ringemup <ringe...@gmail.com> wrote:
> Not a bad idea, actually, but the other site is on shared hosting, so
> I don't expect the host to be willing to add a self-signed cert as
> trusted.
>
> On May 24, 10:07 am, Alex Robbins <alexander.j.robb...@gmail.com>
> wrote:
>
>
>
> > Just a thought, but if you are the only person using the url, you
> > could make your own self-signed security cert. It would be free and
> > protect your data. It won't show up as trusted to users, but your
> > other server can be set to accept it. (Assuming the lack of ssl is a
> > budget issue, that wouldn't fix a technical issue.)
>
> > Alex
>
> > On May 23, 10:10 am, ringemup <ringe...@gmail.com> wrote:
>
> > > Hi folks --
>
> > > I'm putting together a simple API to allow a separately-hosted but
> > > trusted site to perform a very limited set of actions on my site.  I'm
> > > wondering whether the design I've come up with is reasonably secure:
>
> > > - Other site gets an API key, which is actually in two parts, public
> > > key and private key, each of which is a uuid generated by Python's
> > > uuid module.
>
> > > - The API key object in the DB references a User object, whose
> > > permissions determine what actions the API key owner may take
>
> > > - Other site submits a POST request to a special URL on my site.  POST
> > > request contains 3 vars: public_key, data (as JSON), hash.
>
> > > - Hash is a SHA1 of the data concatenated with the private key
>
> > > - I use the public key to search the database for the API key and
> > > permissions.
>
> > > - I generate the SHA1 of the data concatenated with the private key
> > > from the DB, and check it against the submitted hash; only if they
> > > match do I decode the data dict and take the actions specified within
>
> > > - I then return an HTTP response containing a JSON object of the
> > > format:
>
> > > {
> > >     return_data: [object containing success / failure codes, messages,
> > > any other data],
> > >     hash: [SHA1 of return_data concatenated with private key]
>
> > > }
>
> > > - All data will be transmitted in the clear (no SSL currently
> > > available -- *sigh*), but there will be no sensitive data in the
> > > incoming data dict.  return_data may contain values that aren't meant
> > > to be broadcasted, but aren't really sensitive (along the lines of
> > > activation keys for a game)
>
> > > Do you see any major potential flaws in this plan?
>
> > > Thanks!
>
> > > --
> > > You received this message because you are subscribed to the Google Groups 
> > > "Django users" group.
> > > To post to this group, send email to django-us...@googlegroups.com.
> > > To unsubscribe from this group, send email to 
> > > django-users+unsubscr...@googlegroups.com.
> > > For more options, visit this group 
> > > athttp://groups.google.com/group/django-users?hl=en.
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/django-users?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

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



Re: view permission on django admin

2010-05-25 Thread Alex Robbins
If you want something like the admin, that lets users view objects
from the database but not edit them, you could check out the
databrowse contrib app. It is kind of a read-only admin.

http://docs.djangoproject.com/en/dev/ref/contrib/databrowse/

Hope that helps,
Alex

On May 24, 3:49 pm, rahul jain  wrote:
> Hi Django,
>
> I know this has been discussed lot of times but not implemented on
> admin because django developers think that django admin will not be
> just used for viewing.
>
> Anyways, I need it for my model.
>
> I went through the path but was not able to solve this problem.
>
> http://code.djangoproject.com/ticket/7150
>
> I think this patch is for some old code
>
> Here what its missing
>
> a/django/contrib/admin/sites.py
> old     new    
> 281     281                         'add': 
> model_admin.has_add_permission(request),
> 282     282                         'change':
> model_admin.has_change_permission(request),
> 283     283                         'delete':
> model_admin.has_delete_permission(request),
>         284                         'view': 
> model_admin.has_view_permission(request),
> 284     285                     }
> 285     286    
> 286     287                     # Check whether user has any perm for this 
> module.
>
> I checked sites.py but none of the above exists now.
>
> Anyone know the recent patch for this.
>
> Thanks.
>
> --RJ
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

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



Re: Security Question...

2010-05-24 Thread Alex Robbins
Just a thought, but if you are the only person using the url, you
could make your own self-signed security cert. It would be free and
protect your data. It won't show up as trusted to users, but your
other server can be set to accept it. (Assuming the lack of ssl is a
budget issue, that wouldn't fix a technical issue.)

Alex

On May 23, 10:10 am, ringemup  wrote:
> Hi folks --
>
> I'm putting together a simple API to allow a separately-hosted but
> trusted site to perform a very limited set of actions on my site.  I'm
> wondering whether the design I've come up with is reasonably secure:
>
> - Other site gets an API key, which is actually in two parts, public
> key and private key, each of which is a uuid generated by Python's
> uuid module.
>
> - The API key object in the DB references a User object, whose
> permissions determine what actions the API key owner may take
>
> - Other site submits a POST request to a special URL on my site.  POST
> request contains 3 vars: public_key, data (as JSON), hash.
>
> - Hash is a SHA1 of the data concatenated with the private key
>
> - I use the public key to search the database for the API key and
> permissions.
>
> - I generate the SHA1 of the data concatenated with the private key
> from the DB, and check it against the submitted hash; only if they
> match do I decode the data dict and take the actions specified within
>
> - I then return an HTTP response containing a JSON object of the
> format:
>
> {
>     return_data: [object containing success / failure codes, messages,
> any other data],
>     hash: [SHA1 of return_data concatenated with private key]
>
> }
>
> - All data will be transmitted in the clear (no SSL currently
> available -- *sigh*), but there will be no sensitive data in the
> incoming data dict.  return_data may contain values that aren't meant
> to be broadcasted, but aren't really sensitive (along the lines of
> activation keys for a game)
>
> Do you see any major potential flaws in this plan?
>
> Thanks!
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

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



Re: Disabling (or find a workaround for) the comment security checks

2010-05-06 Thread Alex Robbins
Also, as I think more about this, are you sure you need static
generator? You might get sufficient speed just by using cache.
Premature optimization is bad

On May 6, 8:37 am, Alex Robbins <alexander.j.robb...@gmail.com> wrote:
> Disclaimer:
> Disabling the security stuff makes it really likely you'll get comment
> spammed. You should set up some kind of akismet protection on the
> backend if you disable the security.
>
> If you don't want the checking then you probably want a custom comment
> form.
> You can use this method to setup a new 
> form:http://docs.djangoproject.com/en/dev/ref/contrib/comments/custom/#dja...
>
> Then use the form base classes with the functionality you want.
> (You'll probably want to exclude the CommentSecurityForm, and include
> the generic foreign key information some other 
> way.)http://docs.djangoproject.com/en/dev/ref/contrib/comments/forms/
>
> Hope that helps!
> Alex
>
> On May 5, 5:59 pm, Federico Capoano <nemesis.des...@libero.it> wrote:
>
>
>
> > Hello to all,
>
> > I've just launched my new web-site powered by django and i'm very
> > satisfied.
>
> > I've implemented StaticGenerator to improve the performance and
> > loading speed and I have to admit is brilliant.
>
> > Unfortunately i've noticed the comment system doesn't work. This
> > happens because the pages of the blog are saved as static html pages,
> > so the timestamp and csfr security stuff are the one saved when the
> > page was generated.
>
> > I gotta find a fix for this, because I really want my blog pages to be
> > saved as static html cos this is the best solution to obtain fast
> > loading speed without overloading my little VPS.
>
> > I think I can generate the timestamp with javascript, but what about
> > the other two fields (csrfmiddlewaretoken and security hash)?
>
> > If you want to take a look closely this is the 
> > url:http://nemesisdesign.net/blog/
> > I hope i'm not breaching any rule by posting the url.
>
> > Thanks
> > Federico
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to 
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group 
> > athttp://groups.google.com/group/django-users?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

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



Re: Disabling (or find a workaround for) the comment security checks

2010-05-06 Thread Alex Robbins
Disclaimer:
Disabling the security stuff makes it really likely you'll get comment
spammed. You should set up some kind of akismet protection on the
backend if you disable the security.

If you don't want the checking then you probably want a custom comment
form.
You can use this method to setup a new form:
http://docs.djangoproject.com/en/dev/ref/contrib/comments/custom/#django.contrib.comments.get_form

Then use the form base classes with the functionality you want.
(You'll probably want to exclude the CommentSecurityForm, and include
the generic foreign key information some other way.)
http://docs.djangoproject.com/en/dev/ref/contrib/comments/forms/

Hope that helps!
Alex

On May 5, 5:59 pm, Federico Capoano  wrote:
> Hello to all,
>
> I've just launched my new web-site powered by django and i'm very
> satisfied.
>
> I've implemented StaticGenerator to improve the performance and
> loading speed and I have to admit is brilliant.
>
> Unfortunately i've noticed the comment system doesn't work. This
> happens because the pages of the blog are saved as static html pages,
> so the timestamp and csfr security stuff are the one saved when the
> page was generated.
>
> I gotta find a fix for this, because I really want my blog pages to be
> saved as static html cos this is the best solution to obtain fast
> loading speed without overloading my little VPS.
>
> I think I can generate the timestamp with javascript, but what about
> the other two fields (csrfmiddlewaretoken and security hash)?
>
> If you want to take a look closely this is the 
> url:http://nemesisdesign.net/blog/
> I hope i'm not breaching any rule by posting the url.
>
> Thanks
> Federico
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group 
> athttp://groups.google.com/group/django-users?hl=en.

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



Re: MySQLdb setup on snow leopard help

2010-04-12 Thread Alex Robbins
If you are planning to deploy to linux servers, you might have a nicer
time developing on a linux vm. I have a mac, but do my development in
an ubuntu vm. Many difficult installations become a simple "sudo apt-
get install ".
YMMV,
Alex

On Apr 12, 2:09 am, Bdidi  wrote:
> I reinstalled XCode to include 10.4 support and tried again, and
> MySQLdb is now installed, but now I get this:
>
> File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/
> site-packages/django/db/backends/mysql/base.py", line 13, in 
>     raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e)
> django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb
> module: dlopen(/Users/bduncan/.python-eggs/MySQL_python-1.2.3c1-py2.6-
> macosx-10.3-fat.egg-tmp/_mysql.so, 2): Symbol not found:
> _mysql_affected_rows
>
> Can anyone point in the right direction on this?

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



Re: Simple export of CSV

2010-03-25 Thread Alex Robbins
Not sure if this will help, but the docs have a pretty in-depth
explanation of doing csv export. 
http://docs.djangoproject.com/en/dev/howto/outputting-csv/

HTH,
Alex

On Mar 24, 3:03 pm, jlwlynn  wrote:
> I'm trying to simply export CSV, but have failed miserably.  First I
> perform a search and the query set is displayed in a template.  I want
> to have an export button that will export the data on the page, but
> unfortunately, I lost the query set and even if I were to have it as a
> parameter, it would only see it as a string to my exportCSV function.
> Any ideas?  THANKS IN ADVANCE
>
> jason

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email 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: Upload image file, resize using PIL, then save into ImageField - what to save to ImageField?

2010-03-18 Thread Alex Robbins
I think Satchmo uses http://code.google.com/p/sorl-thumbnail/
I think it uses PIL underneath a layer of abstraction. That might work
for you if you are just wanting to generate alternate versions of
uploaded images.

Alex

On Mar 18, 12:10 am, robinne  wrote:
> I can save an uploaded image to a FileField like this (where
> "ProductFile" is a model) and "TempFile" is an ImageField:
>
> uploadedfile = request.FILES['uploadfile']
> ProductFile.objects.create(FileName=UploadDate=datetime.datetime.now(),
> TempFile=uploadedfile)
>
> But, how do I manipulate the image size and then save to this model? I
> am working with PIL, but I can't save a PIL Image to a ImageField. Can
> I save the file to disk using PIL and then pass in the file path and
> name to the model? If so, what is the syntax for saving the ImageFile
> when you are no longer working with the original uploadedfile object?

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



Re: {% url %} not working

2010-03-04 Thread Alex Robbins
I think the issue is the "|" characters in your url here:
http://bitbucket.org/codethief/pybsd/src/e3b41c08ed90/devices/urls.py#cl-7

>From 
>http://docs.djangoproject.com/en/dev/topics/http/urls/#django.core.urlresolvers.reverse

The reverse() function can reverse a large variety of regular
expression patterns for URLs, but not every possible one. The main
restriction at the moment is that the pattern cannot contain
alternative choices using the vertical bar ("|") character. You can
quite happily use such patterns for matching against incoming URLs and
sending them off to views, but you cannot reverse such patterns.

Hope that helps,
Alex

On Mar 4, 2:13 am, codethief  wrote:
> Hello dear Django community,
>
> I'm desperately trying to get the url template tag working. This is my
> template's source 
> code:http://bitbucket.org/codethief/pybsd/src/e3b41c08ed90/tpl/devices/ger...
> And here are my URL 
> settings:http://bitbucket.org/codethief/pybsd/src/e3b41c08ed90/urls.py
> andhttp://bitbucket.org/codethief/pybsd/src/e3b41c08ed90/devices/urls.py
>
> Surprisingly, I don't even get a NoReverseMatch exception but a
> TemplateSyntaxError when trying to 
> visithttp://localhost:8000/devices/geraetegruppen:
>
> TemplateSyntaxError at /devices/geraetegruppen
> Caught an exception while rendering: Reverse for
> 'pybsd.devices.views.html.geraete' with arguments '()' and keyword
> arguments '{'geraetegruppe': 104}' not found.
> In template /home/simon/projekte/pybsd/tpl/devices/
> geraetegruppen.xhtml, error at line 26
>
> ... which is the line: {% for geraetegruppe in geraetegruppen %}
> (Shouldn't line 33 get highlighted? BTW: Please ignore the #s which I
> added to commit a working version.)
>
> By the way: I also tried {% url devices.views.html.geraete ... %}, {%
> url views.html.geraete ... %}, {% url html.geraete ... %} and named
> URL patterns. None of this worked.
>
> Thanks in advance!

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



Re: Restrict choices in ModelForm for ForeginKey field

2010-03-02 Thread Alex Robbins
If you set limit_choices_to on the underlying foreign key, I think
that shows up in any modelform derived from it too.

http://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.ForeignKey.limit_choices_to

Hope that helps,
Alex

On Mar 1, 8:24 am, AlienBaby  wrote:
> Hi.
>
> I have a situation very similar to the following;
>
> [code]
>
> class chars(models.Model):
>          name=moels.CharField('Name',max_length=32)
>
> associated_id=models.IntegerField('Associated',blank=False,null=False)
>          associated_id.default=0
>
> class ctor(models.Model):
>           A=models.ForeignKey(chars,blank=False,null=False)
>           B=models.CharField('Text',max_length=512)
>
> [/code]
>
> I would like to generate a form using ModelForm. I started with
>
> [code]
>
> class ctorForm(ModelForm):
>     class Meta:
>         model=ctor
>
> [/code]
>
> This generates a form, but when rendered the A field of ctor becomes a
> selectable list of all entries in chars.
>
> I would like the A field of the ctorForm to be a selectable list of
> only the entries in chars whose associated_id matches the ID of the
> currently logged in user. (login sessions are handled by django auth,
> or django authopenid)
>
> I'd like to stick to creating the form using ModelForm if it's
> possible.
>
> cheers,

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email 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: Just deployed to 1.2 w/mod-wsgi, app works, admin's busted

2010-03-02 Thread Alex Robbins
I think the problem is that you are using the old admin.site.root. You
should use the include(admin.site.urls) form instead.

http://docs.djangoproject.com/en/dev/ref/contrib/admin/#hooking-adminsite-instances-into-your-urlconf

Hope that helps!
Alex

On Mar 2, 12:01 am, ssteinerX  wrote:
> This app worked under 1.1 most recently and works under the dev server
> in 1.2.
>
> I got it set up the last way it ran under 1.2 and the the app all
> seems to work fine, but the admin won't even come up at all; just
> hangs the server.
>
> The apache logs show nothing about the /admin request at all which
> makes me thing it's getting hung up before it even figures out what to
> ask Apache for.
>
> I'm using the new  style URL patterns like:
>
>      (r'^admin/doc/', include('django.contrib.admindocs.urls')),
>      (r'^admin/(.*)', admin.site.root),
>
> and it's just hangin...
>
> Anyone seen this?  Any advice would be much appreciated; my brain
> hurts.
>
> Thanks,
>
> S
> SteinerX
> Steve Steiner

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email 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: preventing template from converting html entities

2010-02-25 Thread Alex Robbins
Oops, it would actually be
title={% filter force_escape %}{{ villa.name }}{% endfilter %}

Sorry.
--
Alex Robbins
5Q Communications, Inc.
http://www.5Qcommunications.com/
alex.robb...@5qcommunications.com
800-747-4214 ext 913 (p)
http://www.ask5q.com/twitter/



On Thu, Feb 25, 2010 at 8:33 AM, Alex Robbins
<alexander.j.robb...@gmail.com> wrote:
> I think you can do that with title={% filter force_escape
> %}"{{ villa.name }}"{% endfilter %}. Haven't tried it though.
>
> Alex
>
> On Feb 24, 8:36 am, Federico Capoano <nemesis.des...@libero.it> wrote:
>> Hello to all,
>>
>> simple question:
>>
>> I have the following HTML in a template:
>> 
>>
>> But it gets rendered this way:
>> 
>>
>> That is, the  entity is converted to the respective character,
>> ". Very nice, but i'd need 
>>
>> Is there a filter or something i can use to tell the Django Template
>> System to render  ?
>>
>> Thanks in advance.
>>
>> Federico
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: preventing template from converting html entities

2010-02-25 Thread Alex Robbins
I think you can do that with title={% filter force_escape
%}"{{ villa.name }}"{% endfilter %}. Haven't tried it though.

Alex

On Feb 24, 8:36 am, Federico Capoano  wrote:
> Hello to all,
>
> simple question:
>
> I have the following HTML in a template:
> 
>
> But it gets rendered this way:
> 
>
> That is, the  entity is converted to the respective character,
> ". Very nice, but i'd need 
>
> Is there a filter or something i can use to tell the Django Template
> System to render  ?
>
> Thanks in advance.
>
> Federico

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email 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: Passing RequestContext as dict vs. context_instance=RequestContext

2010-02-25 Thread Alex Robbins
If you get tired of forgetting to add the RequestContext you can use
direct_to_template[1] instead. (I almost always forget it the first
time)

It is almost exactly like render_to_response, you'd use it like this:

def index(request):
return direct_to_template(request, 'index.html', {
'extra_context_var': value,
})

Alex

[1] 
http://docs.djangoproject.com/en/dev/ref/generic-views/#django-views-generic-simple-direct-to-template

On Feb 24, 6:00 am, Jesaja Everling  wrote:
> Hi all!
>
> Is there any difference between these two ways of using
> RequestContext?
> I'm asking because I usually use the first approach, but I want to
> make sure that there are no subtle differences.
>
> 1)
> def index(request):
>     return render_to_response('index.html',
>                               RequestContext(request,
>                                              {}
>                                              ))
>
> 2)
> def index(request):
>     return render_to_response('index.html',
>                              {},
>                               context_instance =
> RequestContext(request))
>
> Thanks!
>
> Jesaja Everling

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email 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: Optimize large table view

2010-02-24 Thread Alex Robbins
One tool that can be really helpful for helping with understanding
database activity is http://github.com/robhudson/django-debug-toolbar

It has an SQL panel that shows all the queries that happened, and how
long they took. You'll at least know what is happening now. Should
help you figure out how to combine some of those queries.

Also, you could try and bridge the relationships in the query instead
of doing it in python. I think this would give a list of all samurai
in a given province.
Samurai.objects.filter(room__province=current_province)

Sayonara,
Alex

On Feb 24, 2:08 am, Timothy Kinney  wrote:
> I have models which describe a game. There are 61 provinces with 9
> rooms in each province, for a total of 549 locations. There are
> several hundred samurai, each assigned to a particular room id.
>
> Province(name, id, exits)
> Room(id, name, foreignkey('Province'))
> Samurai(id, name, foreignkey('Room'))
>
> I want to display a list of samurai (by id) for each province on the
> admin/change_list.html.
>
> I created a method in the Province model:
>
> def samurai(self):
>             r = self.room_set.filter(province = self.pk).all()
>             output = []
>             for i in r:
>                 output.extend(i.samurai())
>             return unicode(output)
>
> I use list_detail.object_list as the generic view and call the
> province.samurai method from my template:
>
>         {% for province in object_list %}
>     
>               {{ province.name }} [{{ province.id }}] 
>             {{ province.exits }}
>                 {{ province.samurai }} 
>     
>         {% endfor %}
>
> This is very slow, taking almost 4 seconds for 260 samurai.
>
> I know that the reason this is slow is because I am hitting the
> database so inefficiently. I have a for loop where each province is
> iterating 9 times and I am iterating this loop 61times.
>
> I'm new to databases and to django, so I'm trying to understand how I
> can grab all the data in one query and then just use it. I think I
> should do this from the view?
>
> Can you give me a list of steps (in pseudo-code) for optimizing this
> query?
>
> eg:
> 1) Get all objects in province from the view
> 2) create a dictionary
> 3) and so on...
>
> I just don't grok how the template, view, model method, and ORM fit
> together to make an efficient query. :/
>
> -Tim

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



Re: Use django auth system with ruby on rails

2010-02-18 Thread Alex Robbins
You could have a secure url that the RoR apps redirect to if the user
isn't authenticated with Rails. That url would have the login_required
decorator. If they successfully login on the django side (or are
already logged in), then they get redirected with some sort of get
variable user id + hash combo. You could check the validity of the
user id from the hash (using a shared secret).

Alex

On Feb 17, 4:09 pm, geraldcor  wrote:
> Hello all,
>
> Internally, we have some RoR apps and Django apps. Our main website
> runs on Django and is considered to be the main portal for all other
> apps. Currently, we have a Rails authentication system and a Django
> authentication system. We want to have one user table to authorize
> against.
>
> The only problem I see is that the password stored in auth_user is
> salted and hashed and impossible to get at because the salt is not
> saved. How can I use the django auth_user in Ruby On Rails?
>
> I have found this:http://docs.djangoproject.com/en/dev/howto/apache-auth/
> but I don't know if that will work on the ruby server. Both ror and
> django applications that we want to authenticate are on the same
> server and use the same db (except our main website which is on
> webfaction - but that's a different story I will tackle later -
> possibly replication?).
>
> So, anyone know how to a) access the raw string from auth_user or b)
> set up ruby (or other language and extrapolate) to properly interpret
> the password hash?
>
> Thanks for listening.
>
> Greg

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



Re: Problem with apache server

2010-02-04 Thread Alex Robbins
If you are in development, you can just use django dev server. "./
manage.py runserver" from your project.

If you have deployed your app, then the best way to avoid restarting
is to use mod_wsgi's reloading feature.
If you deploy in daemon mode, you can just touch the wsgi file to
trigger a reload. That is the easiest way.

If you want django dev server-like automatic reload on change, you
should look at this:
http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode

Some links for deploying django using mod_wsgi.
http://docs.djangoproject.com/en/1.1/howto/deployment/modwsgi/#howto-deployment-modwsgi
http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango

Hope that helps,
Alex

On Feb 3, 5:30 am, Zygmunt  wrote:
> Hi!
> When i create some changes in my page, i need restart apache server.
> How can i avoid restarting?

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

2010-02-03 Thread Alex Robbins
Daishy,

I don't think you can do that with an include tag. You could do it by
defining a "base_with_menu.html" and having it extend "base.html" You
could make a menu block in base and override it in
base_with_menu.html.

Hope that helps,
Alex

On Feb 3, 3:28 am, Daishy <dai...@web.de> wrote:
> Hi,
> Oh, sorry, but i guess it really was a bit wague:
>
> -- base.html --
> 
> 
> {% block extrahead %}
> 
> 
> {% endblock %}
> 
> 
> {% include "menu.html" %}
> 
> 
>
> sub_page would look like you wrote and that works fine. But what i
> want now (and i guess isnt possible and im just on the wrong way here
> ^^) is :
>
> -- menu.html --
> {% block extrahead %}
> {{ block.super }}
> 
> 
> {% endblock extrahead %}
> 
>  ...
> 
>
> So the content of menu will be inserted at the include-tag and the
> extra js should be inserted into the extrahead-block. I hope thats a
> better example of what i want to do. Again, i wouldnt be suprised if
> thats not the right way, but is there a way to achive such seperation
> of the templates?
>
> On Feb 2, 4:41 pm, Alex Robbins <alexander.j.robb...@gmail.com> wrote:
>
> > Daishy, it would help if you posted the template code you already
> > tried.
>
> > This is basically how you could do what you are describing:
> > base.html
>
> > 
> > 
> > {% block extrahead %}
> > 
> > 
> > {% endblock %}
> > 
> > 
> > 
>
> > sub_page.html
> > {% extends "base.html" %}
> > {% block extrahead %}
> > {{block.super}}
> > 

Re: Template-Include and block.super

2010-02-02 Thread Alex Robbins
Daishy, it would help if you posted the template code you already
tried.

This is basically how you could do what you are describing:
base.html



{% block extrahead %}


{% endblock %}




sub_page.html
{% extends "base.html" %}
{% block extrahead %}
{{ block.super }}

Re: Rebuild admin site after dropping field from models.py?

2010-02-02 Thread Alex Robbins
John,
I don't think the problem is as fixed as it appears. You probably
still have the foreign key in your database. Like Shawn said, syncdb
only adds new models as tables in the db. It doesn't do anything to
existing models. It won't delete a model that you delete, or change
fields on a model that you change. You have only removed the field
from django, not your database.

This could be a problem if that field happened to be set NOT NULL in
the database, as you'll get integrity errors whenever you try and add
an object. (The object won't have the required field, which some
databases enforce.)

To bring the databases into sync you can:
1) Use Shawn's method which uses South, a database migration tool.
South is awesome.
2) Use a ./manage.py reset .  This will drop all the tables
in the app, and remake them. If you don't care about your data, this
is easiest.
3) Make the change using SQL against the database. (Using the
interactive tool that comes with most databases.)

Hope that helps,
Alex

On Feb 1, 1:54 pm, John Abraham  wrote:
> I figured this out.  I my __unicode__(self) still refered to the
> field! Doh!
>
> I changed it, reran syncdb, and restarted the server and it worked.
> Not sure if rerunning syncdb was necessary.
>
> --
> John
>
> On Feb 1, 12:44 pm, John Abraham  wrote:
>
>
>
> > Hi.
>
> > I changed models.py to remove a foreign key (user_id field in table
> > Client), and reran syncdb, but now if I try to create a record of that
> > type in the admin interface I get an error when I try to save a new
> > object.

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

2010-01-29 Thread Alex Robbins
It sounds like the databrowse[1] contrib app may be what you are
looking for. It is basically a read-only admin. You'll have to
register classes with it the same way you register with the admin, but
it might be nicer than trying to force the admin to be read-only.

Hope that helps,
Alex

[1] http://docs.djangoproject.com/en/dev/ref/contrib/databrowse/

On Jan 28, 8:55 pm, zweb  wrote:
> Is it possible to have a read only django admin, ie user cannot add,
> delete or update. User can only view data.
>
> or may be one user can be view only and other user has add/delete /
> update as well in Django admin.
>
> How to do that?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email 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: Efficient access through two manytomany layers

2010-01-18 Thread Alex Robbins
Probably need to solve the problem individually:

First problem: Performance.
Have you looked at using select_related[1] in your query? That might
speed up the loop since it would do all the lookups in one big query.
(It'll need more memory since it is loading it all at once, but it
will probably be faster since the db doesn't have to do a query for
every forloop iteration.

Hmm, you might also look at just doing something like
Event.objects.values_list
('classes_involved__parent_disciplines__name', flat=True).distinct().
That works on some relations, but I haven't tested it in your case.

Second problem: Save doesn't work right.
Sorry, don't have any good ideas here. Maybe the relations aren't
being updated until you call the superclass's save method? (ManyToMany
fields are a separate table internally. It probably isn't updated
until you save.) That happens after you compute self.disciplines. You
could try doing a super(Event, self).save(*args, **kwargs) before you
compute the disciplines list, and then again after you have computed
it, to save the value. That is two saves into the db for one admin
save, but it shouldn't be too hard on your db.

new save method:

super(Event, self).save(*args, **kwargs)
# variable the will be saved in a charfield on the event.
disciplines = []
 # get the related many to many field which has all the 'classes'
classes = self.classes_involved.all()
 for this_class in classes:
  parent_disciplines = this_class.parent_discipline.all()
  for disc in parent_disciplines:
  disciplines.append(str(disc.name))
self.disciplines = ', '.join(set(disciplines))
super(Event, self).save(*args, **kwargs)

Hope that helps,
Alex

[1] http://docs.djangoproject.com/en/dev/ref/models/querysets/#id4

On Jan 18, 10:32 am, Alastair Campbell <ala...@gmail.com> wrote:
> On Mon, Jan 18, 2010 at 2:59 PM, Alex Robbins
>
> <alexander.j.robb...@gmail.com> wrote:
> > Hmm, you posted the save method for your Event model, but not the
> > definition. I think you haven't gotten any feed back because no one
> > really knows what you are asking. Could you show the Event model, and
> > then show what a finished save should look like? What should the data
> > end up like?
>
> Thanks for the reply Alex, I hadn't posted the model definition
> because there's a lot of irrelevant stuff, but point taken, here's
> most of it:
>
> class Event(models.Model):
>         name = models.CharField("Listings title", max_length=100)
>         disciplines = models.CharField(max_length=250)
>         classes_involved =  models.ManyToManyField("categories.Class",
> blank=True, null=True)
>         start_date = models.DateField("First day of the event")
>         end_date = models.DateField("Last day of the event")
>         approved = models.BooleanField()
>         # some removed.
>         def __unicode__(self):
>                 return self.name
>
> It's fairly simple, the complex bit is filling in the disciplines. I
> tried to add something to the save() to fill it in.
>
> In the Admin area, the event form shows the classes_involved (a choice
> of about 20), but doesn't show the disciplines.
> I was hoping to fill in the disciplines from the classes_involved.
> It's just used in listings, not for comparison, so a text string is
> fine.
>
> There are two problems:
> 1. The performance hit by going through 2 levels of manytomany fields.
> The first to get all classes_involved and then for each of those, to
> get it's parent. (I assume this is bad, my laptop seems to think so.)
> 2. When I edit an event, the save() doesn't seem to work from the
> form-data, it works on the previously saved data. I.e. if edit the
> classes_involved once and save, the discipline is not adjusted. If I
> save it twice, the discipline is adjusted.
>
> I was aiming for a cheap way to do two-level categorisation, however,
> I'm now thinking I just keep the categories separate and make admin
> users fill in the discipline manually.
>
> Kind regards,
>
> -Alastair
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email 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: Efficient access through two manytomany layers

2010-01-18 Thread Alex Robbins
Hmm, you posted the save method for your Event model, but not the
definition. I think you haven't gotten any feed back because no one
really knows what you are asking. Could you show the Event model, and
then show what a finished save should look like? What should the data
end up like?

Alex

On Jan 17, 3:41 pm, Alastair Campbell  wrote:
> Hi everyone,
>
> I have something that works, but I'm guessing it's *very* inefficient,
> I'm guessing that nested for-loops for two layers of many to many
> fields is bad, but how could I go about this better?
>
> The aim is for my admin users to fill in the sub-categories (classes),
> and for the system to work out which parent categories (disciplines)
> are involved.
>
> I have a separate model for taxonomy, and within my 'categories'
> models.py I have:
>
> class Discipline(models.Model):
>         name = models.CharField(max_length=50)
>         slug = models.SlugField(unique=True)
>
> class Class(models.Model):
>         name = models.CharField(max_length=50)
>         slug = models.SlugField(unique=True)
>         parent_discipline = models.ManyToManyField("Discipline")
>
> Sorry about using 'Class' as the model name, but unfortunately it's
> the only thing that makes sense for this categorisation.
> (E.g. the discipline might be slalom, which has a class of amatuer within it.)
>
> This is added to the save method for my Events model:
>
> # variable the will be saved in a charfield on the event.
> disciplines = []
>  # get the related many to many field which has all the 'classes'
> classes = self.classes_involved.all()
>
>  for this_class in classes:
>       parent_disciplines = this_class.parent_discipline.all()
>       for disc in parent_disciplines:
>           disciplines.append(str(disc.name))
>
> this_set = set(disciplines)
> this_list = list(this_set)
> self.disciplines = ', '.join(this_list)
>
> super(Event, self).save(*args, **kwargs)
>
> Any ideas on how I could go about this better? I'd hoped to make
> things easier with a centrally defined taxonomy, but so far it isn't
> worked to well.
>
> Kind regards,
>
> -Alastair
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email 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: Admin list_display loop though sub objects and output sum of values - newbie

2010-01-18 Thread Alex Robbins
There is also an online version of one of the django books here:
http://djangobook.com/

On Jan 17, 5:08 pm, pfwd  wrote:
> Thanks fantastic thank you
> I was also able to do:
> result = obj.task_set.aggregate(Count('id'))['id__count']
> to get the a count of the tasks for quote
>
> I don't suppose you know any good books regarding Python/Django that I
> could buy to help me learn the syntax better?
>
> Many thanks
>
> On Jan 17, 10:15 pm, Daniel Roseman  wrote:
>
>
>
> > On Jan 17, 8:28 pm, pfwd  wrote:
>
> > > Hi am very new to Django/Python and I need some help with a model
> > > method
>
> > > I have two tables Linked by a foreign key and their forms are embedded
> > > in the admin interface.
> > > One table is called Quote and one table is called Task. The task table
> > > has a field called time_taken
> > > In the Quote list I want to display the total amount of time to under
> > > go all the tasks in each quote.
>
> > > This is what I'm doing and its just displaying (None) in the list
>
> > > class QuoteAdmin(admin.ModelAdmin):
> > >         fieldset = [
> > >                 (None, {'fields': ['q_number']})
> > >         ]
> > >         inlines = [TaskInline]
>
> > >         list_display = ('q_number', 'total_time','created_date')
>
> > >         def total_time(self,queryset):
> > >                 task_objs = self.Task.objects.all()
>
> > >                 total_time = 'No time taken'
>
> > >                 for record in task_objs:
> > >                         total_time = total_time + record.time_taken
> > >                 return total_time
>
> > > I'm trying to get all the tasks for each quote by doing
> > > self.Task.objects.all() and then looping through them and adding the
> > > time_taken to the var total_time.
>
> > > I guess this syntax is just plain wrong or the method is not being
> > > called as its not showing any errors
> > > I have a javascript/PHP background and I would like to learn more
> > > Python
> > > - Please be kind :)
>
> > OK a few pointers.
>
> > * a custom list_display method takes parameters (self, obj), where obj
> > is the object being displayed in that row - here it's an instance of
> > Quote.
> > * 'self.Task' means nothing. You want to get the tasks related to the
> > Quote, which is in 'obj', so you use 'obj.task_set.all()'. With this,
> > your code would work as is.
> > * A nicer way of doing it would be to get the DB to sum the time_taken
> > values. This should work:
> >     from django.db.models import Sum
> >     return obj.task_set.aggregate(Sum('time_taken'))
> > ['time_taken__sum']
> > (the square brackets at the end are needed because 'aggregate' returns
> > a dictionary, and we just want the value from there).
> > --
> > 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-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: Linked list of abstract objects

2010-01-18 Thread Alex Robbins
Also, I think you'll need to make those relations to a class that
isn't abstract. Right now you have a 'class Meta: abstract=True' That
means your model doesn't really exist for the relations to link to.

Hope that helps,
Alex

On Jan 18, 2:26 am, Kerrick  wrote:
> I'm trying to implement a linked list of abstract objects in my
> models.py; however, it is throwing an error.
> --activenotes/models.py--
> class Element(models.Model):
>     class Meta:
>         abstract = True
>     prev = models.OneToOneField('Element', null=True, blank=True)
>     next = models.OneToOneField('Element', null=True, blank=True)
>
> class Text(Element):
>     contents = models.TextField()
> --end--
> --output of python manage.py syncdb--
> Error: One or more models did not validate:
> activenotes.text: 'prev' has a relation with model Element, which has
> either not been installed or is abstract.
> activenotes.text: 'next' has a relation with model Element, which has
> either not been installed or is abstract.
> --end--
> How can I rectify the 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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Re: how can a test log in as a given user before calling client.get()?

2010-01-07 Thread Alex Robbins
I would use the create_user[1] function, then you can just enter the
password, instead of the hash value. Might make your code a little
more readable.

Alex

[1]http://docs.djangoproject.com/en/dev/topics/auth/#creating-users

On Jan 6, 3:19 pm, Phlip  wrote:
> > Google cannot find any traffic on this topic, so I'm warming up the
> > question here before researching it myself. If I figure out how to
> > write login_as() for tests, I will post it here.
>
> Do I always have to see the same hands??
>
>         from django.contrib.auth.models import User
>         hell_yeah = True
>
>         u = User.objects.create(username=u'admin', is_active=True,
> email=u'ad...@admin.admin',
>                                 is_superuser=hell_yeah, is_staff=True,
>                                 password=u'sha1$e34de
> $49632495b9ab78a54ff53a0d1145e2b9e8eb2af6')
>
>         self.client.login(username='admin', password='admin') # <--
> the money line
>
>         self.get('/shop-admin/')  #  TODO  get should demand a 200
>
> Some of you might see fit to put that User into a reusable (but test-
> only) JSON file... to each her or his own.
>
>
>
> > --
> >   Phlip
> >  http://twitter.com/Pen_Bird
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email 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: get_absolute_url not recognized

2009-12-23 Thread Alex Robbins
Is the second line of your url function outdented? Maybe python thinks
your class is finished at that point? You could try indenting it?

If that doesn't fix it I would drop the decorator for now to see if
that fixes it. Then you could try dropping the body of the
get_absolute_url function and replacing it with pass. Then try moving
the function higher in the class.

Hopefully you'll find the problem at one of those stages.

Alex

On Dec 22, 1:21 pm, neridaj  wrote:
> I'm trying to add a get_absolute_url method to a Tweet model from
> django-syncr and do not understand why the method is not recognized.
>
> class Tweet(models.Model):
>     pub_time    = models.DateTimeField()
>     twitter_id  = models.PositiveIntegerField()
>     text        = models.TextField()
>     user        = models.ForeignKey('TwitterUser')
>
>     def __unicode__(self):
>         return u'%s %s' % (self.user.screen_name, self.pub_time)
>
>     def url(self):
>         return u'http://twitter.com/%s/statuses/%s'%
> (self.user.screen_name, self.twitter_id)
>
>     @models.permalink
>     def get_absolute_url(self):
>                 return ('blog_tweet_detail', (), { 'year': 
> self.pub_time.strftime
> ("%Y"),
>                                                                   'month': 
> self.pub_time.strftime("%b").lower(),
>                                                                   'day': 
> self.pub_time.strftime("%d"),
>                                                                   'slug': 
> self.tweet.twitter_id })
>
> >>> from syncr.twitter.models import Tweet
> >>> t = Tweet.objects.get(pk=1)
> >>> t
>
> >>> t.url
>
>  
> t.get_absolute_url
>
> Traceback (most recent call last):
>   File "", line 1, in 
> AttributeError: 'Tweet' object has no attribute 'get_absolute_url'

--

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

2009-12-22 Thread Alex Robbins
You could also try the free online book. http://djangobook.com/

On Dec 22, 3:46 am, Amine  wrote:
> Hi,
> I'm new in django and i'm searching a book :
> django 1.0 web site development PDF
>
> can u help me please !
> inhttp://my.softarchive.net/search/?q=django=0=0   I could not
> download it.
>
> Is there another way ?
>
> thanks for help.

--

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




Re: Filter (AND excluding empty values)

2009-12-15 Thread Alex Robbins
Does it work for one case at a time? Have you tried

q = request.GET.get('city')
properties = Property.objects.filter(city=q)

I would make sure it is working for each variable before combining
them together. (Maybe you already have, I don't know.)

Alex

On Dec 14, 5:32 pm, Osiaq  wrote:
> Andy, I couldn't manage it. Could you (please) give me some example?
> It looks like this case is NOT simple at all, googling through
> multiple websites didn't bring anything even close to  required
> solution.
>
> MODEL:
> class Property(models.Model):
>         name = models.CharField(max_length=200)
>         category =models.ForeignKey(PropertyCategory)
>         city =models.ForeignKey(City)
>         status=models.ForeignKey(PropertyStatus)
>         def __unicode__(self):
>                 return self.name
>
> VIEW:
> def search(request):
> q=request.GET['city']
> c=request.GET['category']
> s=request.GET['status']
> properties = Property.objects.filter( HERE_COMES_WHAT_IM_LOOKING_FOR)
>
> HTML:
> 
>         
>         ALL
>         Tokyo
>         Nashville
>         
>
>         
>         ALL
>         House
>         Apartment
>         
>
>         
>         ALL
>         For Sale
>         For Rent
>         
>
>         
> 
>
> ...and now I want to display i.e.
> all from Tokyo or
> all Houses or
> all For Sale in Tokyo
> 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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Re: how to allow RSS aggregators to use feeds available only for logged-in users?

2009-12-08 Thread Alex Robbins
Maybe you could just make another url that wasn't password protected.
If the token doesn't get used up in your plan, you have roughly the
same security (not much).

def rss_view(request):
   askdmalkdmakds

protected_rss_view = login_required(rss_view)

Hope that helps,
Alex

On Dec 7, 8:57 am, Miernik  wrote:
> I want to have RSS feeds in my Django application, which should be
> viewable only by a logged-in user. I want to allow users to add these
> RSS feeds to all aggregators, so I would need something which would
> work like this: supply the feed URL with a token, for 
> example:http://example.com/feed/rss=AeYQtFjQfjU5m so that token will
> cause the feed to be seen as if the user would be logged in.
>
> Is there some library in Django which would provide such a
> functionality?

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email 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: What apps do besides provide views?

2009-12-03 Thread Alex Robbins
> Yeah, app integration right now seems very non-DRY and much too fiddly.  
> Stands to reason
> that including an app implies you include the app's urls and templates - or 
> why include it?  I
> definitely cringe when copying an integrated app's templates into my 
> project's template
> hierarchy.

As long as you have an app in INSTALLED_APPS and the app_directories
template loader in the TEMPLATE_LOADERS setting, you don't need to
copy an app's templates. Any templates inside the template folder of
that app will be included.
http://docs.djangoproject.com/en/dev/ref/templates/api/#loader-types

--

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




Re: Sick of defining urls

2009-12-03 Thread Alex Robbins
>You are welcomed to disagree with it, all of us hackers view things 
>differently.
>That said, understanding what Tim is saying will help you understand Python and
>the people who use it. Most of us agree with most of Tim's points. I believe 
>this
>was mentioned not to tell you to walk away.

Exactly. Todd, I'm not saying "agree or get out." All of the points in
the Zen of Python are opinion points. You could just as easily believe
the opposite of most of those points. It is just that, most Python
(and Django) programmers believe those things. The framework is built
with that mindset. It guides design decisions and allows us to move
beyond arguments over personal preference.

If you disagree with all (or most) of the Zen of Python, you are
welcome to stay, but unlikely to be happy.

If you start to complain about significant whitespace too, you aren't
welcome to stay either. :)

Alex

On Thu, Dec 3, 2009 at 12:46 PM, Javier Guerra  wrote:
> On Thu, Dec 3, 2009 at 1:30 PM, Todd Blanchard  wrote:
>> Not sure what you mean?  You mean something that looks through the code and
>> generates/expands urls for the view methods it finds?
>
> not exactly, just something like i wrote before: a small function that
> takes a list of views and constructs the url mapping from a template.
> remember that the mapping is not code, it's a data structure.  it's
> usually constructed explicitly line by line, but if you have a
> repeating pattern, you could factor it out.
>
>> I don't see the point of that exactly.  The dynamic dispatch I'm doing does
>> the same thing and I prefer dynamic dispatch to code generation (I abhor
>> code generation).
>
> to each his poison.
>
>> I do have one additional little complaint about url handling and application
>> integration in general.
>> settings.py has a list of applications to include (INSTALLED_APPS).  Fine.
>>  But then, in urls.py I have to repeat myself by importing each
>> application's urls.py to add them.      (r'^admin/', include(admin.urls)),
>
> remember that an app can do a lot more than provide views.
> autogenerating the mappings without being asked, would be definitely
> un-django-ist.  (and quite likely non-pythonic too).
>
> OTOH, a shortcut to deal with repeating code would be really welcomed.
>  again, just don't assume by default that it would have to be used,
> wait until it's called.
>
>
>
> --
> Javier
>
> --
>
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>
>

--

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




Re: Sick of defining urls

2009-12-03 Thread Alex Robbins
Todd,

If you are just trying to define a restful interface to your objects,
you might look at django-piston[1]

If you really want the Rails approach, you are going to be pretty
frustrated working with Django. The python equivalent of "convention
over configuration" is "explicit is better than implicit." The
following poem sums up Python's philosophy, which I think also
motivates Django:

The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!



[1] http://bitbucket.org/jespern/django-piston/wiki/Home

On Dec 3, 3:29 am, Daniel Roseman  wrote:
> On Dec 3, 7:37 am, Todd Blanchard  wrote:
>
> > I think you've kind of missed my point as there's not a view that can 
> > render any object - but rather the name of the view is in the url.
>
> > This is the url conf for a typical rails app.
>
> >   map.connect '', :controller => "public"
> >   # Install the default route as the lowest priority.
> >   map.connect ':controller/:action/:id.:format'
> >   map.connect ':controller/:action/:id'
>
> > That is the whole thing.  Controllers are analogous to applications in 
> > django, actions are like view functions, id is typically the primary key of 
> > the object being viewed.  format is new and could be .json, .xml, 
> > .html. I don't really use it just now.
>
> > I see no reason ever to specify a more elaborate url.  I want the 
> > equivalent setup in my urls.py and then I never want to open that file 
> > again - relying entirely on naming convention rather than configuration.
>
> 
>
> I really can't help thinking, based on this and some of your other
> messages, that Django isn't a good fit with the way you think. You
> might like to try another Python framework. Pylons might be better for
> you, as it uses Routes for its url despatch mechanism, and I believe
> that is quite close to the controller/action paradigm of Rails.
> --
> 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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.




Re: Is there a way to integrate php to a django app?

2009-11-23 Thread Alex Robbins
Great,

If you want to get any sort of meaningful feedback you are going to
have to be much more specific when you say integrate. Honestly, this
type of post is normally just ignored because no one really knows what
you are talking about. You only get (good) feedback if you ask good
questions.

Can both django and php/jsp share a database? Sure. Databases can have
lots of connections, even from different programs.

Can a single server serve both php and python? Sure, although web
server optimization will be a little tricky.

However, as Juan said, using a whole different framework is probably
not worth it. Especially if you are only implementing the login and a
bulletin board. Getting the login/auth accounts to work on both PHP
and django will be far more work than implementing a bulletin board in
any sane web framework.

Hope that helps,
Alex





On Nov 20, 8:01 am, GreatEntrepreneur  wrote:
> HI!
>
> I am also really wondering this.
>
> Cuz our project is not started yet and we haven't decided which
> framework we will use.
>
> But I wanna develop certain part like login or bulletin board with
> DJango before actual project starts.
>
> So, Even though later my supervisor develops php or jsp for whole
> website, my app will be well integrated?
>
> Let's say, my supervisor will develop php webframework, and my app
> should be worked on php webframework.
>
> Hm..just setup apache configs may solve my worry? :)
>
> Like Juan said, it looks possible. But I am not good at web
> programming yet.
>
> I will really appreciate if someone give me more detail info about how
> to integrate with php whatever webframework.
>
> Thanks in advance.!!

--

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




Re: Auth and Sites in Admin

2009-11-15 Thread Alex Robbins
Those sections won't show up for anyone who doesn't have edit
permissions. As long as you don't give the admin user superuser status
or permissions for those apps they won't show up.

On Nov 14, 6:34 pm, Zeynel  wrote:
> Is it possible to remove "Auth" and "Sites" sections from the Admin
> panel?

--

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




Re: Is there a way to integrate php to a django app?

2009-11-14 Thread Alex Robbins
I guess the answer depends on what you mean by "integrate." If you
have both written parts that serve html pages, just setup apache
configs so that part of the urls are routed to django and the other
urls are routed to php.

Another way to integrate would be by setting up one of the installs as
an api and just making calls against it by the other half.

You aren't going to get good help unless you tell us what exactly you
are doing.

Hope that helps.
Alex

On Nov 13, 7:59 pm, Allen  wrote:
> Hi, all:
>
>   I've build a application with django, and my friends build a part of
> the application with php.
> now both of us are finished, the final step is to integrate the php
> part to django, is there a way
> to do this?
>
>   I've google for this, but no solution found.
>
>   Thanks!
>
> Best Regards!
>
> Allen

--

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




Re: Databrowse: Loading a large number of records

2009-11-10 Thread Alex Robbins

That error happens if you refresh the page while it is still loading
from the dev server. You may have gotten impatient, refreshed and
caused that error. It is possible that this isn't really the problem
you are having, but just a secondary issue caused by the long load
time and a page refresh.

On Nov 9, 6:49 am, Ismail Dhorat  wrote:
> Hi Guys,
>
> I am currently testing the contrib app databrowse in Django ver 1.1.1,
> the current setup for testing purposes is:
>
> OS: Mac OsX 10.6
> DB: Sqlite3
> Django: 1.1.1
> Python: 2.5
>
> Here is what i have done, i have a model and i am trying to see what
> the capabilities and limits of this app (since i will most likely be
> working with a huge number of records), i loaded +- 300,000 records
> into the DB current SQLITE file size is 30mb
>
> When trying to access /databrowse i get errors, and the page refuses
> to load. It basically hangs, from the looks of it the page seems to be
> displaying all the contents. Here is the traceback:
>
> Traceback (most recent call last):
>   File 
> "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/core/servers/basehttp.py",
> line 280, in run
>     self.finish_response()
>   File 
> "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/core/servers/basehttp.py",
> line 320, in finish_response
>     self.write(data)
>   File 
> "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/core/servers/basehttp.py",
> line 399, in write
>     self.send_headers()
>   File 
> "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/core/servers/basehttp.py",
> line 463, in send_headers
>     self.send_preamble()
>   File 
> "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/core/servers/basehttp.py",
> line 381, in send_preamble
>     'Date: %s\r\n' % http_date()
>   File 
> "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/socket.py",
> line 261, in write
>     self.flush()
>   File 
> "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/socket.py",
> line 248, in flush
>     self._sock.sendall(buffer)
> error: (32, 'Broken pipe')
>
> I also see there has been a ticket logged for this issue about 2 years ago.
>
> http://code.djangoproject.com/ticket/4481
>
> Has this been implemented? If not would would a simple paginate tag in
> the template suffice?
>
> Regards,
> Ismail
--~--~-~--~~~---~--~~
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: Display a view of a single record?

2009-11-10 Thread Alex Robbins

Derek,

If you want something that display data but doesn't allow you to edit
it, you should check out the databrowse[1] contrib app. You just
register a model with it (like the admin) and it generates all the
pages. It lets users look through the data, but not edit it.

[1]http://docs.djangoproject.com/en/dev/ref/contrib/databrowse/

Hope that helps,
Alex

On Nov 10, 3:36 am, derek  wrote:
> Yes, the fields should not be editable in a "view".
>
> However, I do not see it as "a problem" - more as "a desirable
> feature".  There are any number of use cases for letting users see
> detailed record data but not be able (or not need, at that point in
> time) to edit it.   This feature is not meant to replace the existing
> ability to edit a record; but to add another option to the interface.
>
> It just seems strange to me that the admin interface allows for
> display of multiple records in a listing, but has no facility to
> display a complete, single record "view".  I do not want to have
> redevelop an admin-like interface just to allow for this option (given
> that is such a generic one).
>
> It is not clear from what you say - but I assume that it is not
> possible to readily alter the current admin interface to incorporate
> the generic views you refer to?  If it is, any guidance, or examples,
> along these lines would be appreciated.
>
> On Nov 9, 2:37 pm, Ludwik  Trammer  wrote:
>
> > I have a really hard time understanding what do you need, and I
> > suspect I'm not the only one. You are talking about the admin
> > interface, right? It displays a list containing all records, and when
> > you click on a record you go to a page that shows all fields for this
> > record (and lets you change their values). Isn't that exactly what you
> > want?
>
> > If the problem is that you don't want the fields to be editable,
> > because you just want to display read-only lists of records: re-think
> > using admin interface. It is meant specifically for managing records
> > on your website. Just use
> > "django.views.generic.list_detail.object_list" (display list of
> > records) and "django.views.generic.list_detail.object_detail" (display
> > detailed view of a single record) generic views:
>
> >http://docs.djangoproject.com/en/dev/ref/generic-views/#django-views-..
--~--~-~--~~~---~--~~
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: syncdb for INSTALLED_APPS throws errors

2009-10-29 Thread Alex Robbins

The warning on line 2 is because you are using python2.6, default in
Ubuntu9.04. You don't need to worry about it. It is just telling the
authors of mysqldb that ImmutableSet is going away in newer versions
of python. Not something you need to care about.

On Oct 29, 3:37 am, sridharpandu  wrote:
> Skylar
>
> Thanks. It works. Here is the trace. Should warning on line 2 be
> ignored?
>
> srid...@sridhar:~$ python manage.py syncdb
> /var/lib/python-support/python2.6/MySQLdb/__init__.py:34:
> DeprecationWarning: the sets module is deprecated
>   from sets import ImmutableSet
> Creating table auth_permission
> Creating table auth_group
> Creating table auth_user
> Creating table auth_message
> Creating table django_content_type
> Creating table django_session
> Creating table django_site
>
> You just installed Django's auth system, which means you don't have
> any superusers defined.
> Would you like to create one now? (yes/no): y
> Please enter either "yes" or "no": yes
> Username (Leave blank to use 'sridhar'):
> E-mail address: sridharpa...@gmail.com
> Password:
> Password (again):
> Superuser created successfully.
> Installing index for auth.Permission model
> Installing index for auth.Message model
> srid...@sridhar:~$
>
> Best regards
>
> Sridhar
--~--~-~--~~~---~--~~
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: {% url in templates

2009-10-29 Thread Alex Robbins

Maybe it is just me, but I feel like writing out the view functions
like that is a beating. I just name[1] all the urls. Then the url tag
is easy. I just do things like {% url home-page %} or {% url blog-
index %}. If you set up a generic view in the views and name it, it
will work like normal.

[1]http://docs.djangoproject.com/en/dev/topics/http/urls/#id2

On Oct 28, 3:29 pm, Umapathy S  wrote:
> On Wed, Oct 28, 2009 at 8:03 PM, Gabriel .  wrote:
>
> > On Wed, Oct 28, 2009 at 4:16 PM, Umapathy S  wrote:
> > > view_xyz is the view function.  No arguments.
>
> > > exps is the application.  pams is project.
>
> > > pams/urls.py
>
> > > urlpatterns = patterns('',
> > >     # Example:
> > >     # (r'^pams/', include('pams.foo.urls')),
> > >     (r'pams/', include('pams.exps.urls')),
>
> > > pams/exps.urls.py
>
> > > from django.conf.urls.defaults import *
> > > from django.views.generic import list_detail
> > > from pams.exps.models import *
>
> > > urlpatterns = patterns('pams.exps.views',
> > >     (r'exps/xyz/$', 'view_xyz'),
>
> > Try with {% url exps.views.view_xyz 
>
> > or "pams.exps.views.view_xyz"
>
> > {%
>
> Thanks.
>
>  {% url exps.views.view_xyz %} worked.
>
> Is it possible to do this for generic views?
>
> Thanks
>
> Umapathy
--~--~-~--~~~---~--~~
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 why deleting related(null=True) objects?

2009-10-08 Thread Alex Robbins

This sounds related to this ticket http://code.djangoproject.com/ticket/9308,
which supposedly fixed this issue 5 months ago. You should probably
file a bug report.

On Oct 7, 4:19 pm, Peter Sagerson  wrote:
> Yes, Django always cascades deletes. There's talk about providing more  
> options in a future release, but for now it's kind of a problem. I  
> generally find this behavior potentially catastrophic, so I wrote an  
> intermediate model base class that clears all nullable foreign keys  
> before deleting an object:
>
> http://www.djangosnippets.org/snippets/1231/
>
> Note that this probably won't stop the admin app from warning about  
> the anticipated cascade.
>
> On Oct 7, 2009, at 6:37 AM, x_O wrote:
>
>
>
> > Hi
>
> > My question that I'm getting right that situation. I've two models:
>
> > class First(db.models):
> >    second_item = models.ForeignKey('Second',null=True)
> >    ...
>
> > class Second(db.models):
> >    ...
>
> > I've both models registered in admin.py as AdminModels.
>
> > Why when I'm trying to delete some object created from "Second" class
> > which is RELATED to other one created from "First" class, admin is
> > telling me that will remove also that "First" object (relation in
> > ForeignKey is null). I understand that when there is null=False
> > attribute should remove it, by why when it is null=True?
>
> > In my interpretation of that should just leave First object with
> > 'second_item' = None.
>
> > x_O
>
>
--~--~-~--~~~---~--~~
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: TinyMCE in Admin (Practical Django Projects book)

2009-09-28 Thread Alex Robbins

If you use the net tab of firebug[1] you can tell when url/file paths
are messed up. That is the only way I ever get tinymce running.

[1]http://getfirebug.com/

On Sep 27, 7:29 am, Erik Kronberg  wrote:
> On Sun, Sep 27, 2009 at 1:54 PM, James Bennett wrote:
>
>
>
>
>
> > On Sun, Sep 27, 2009 at 6:48 AM, Erik Kronberg  wrote:
> > > I'm on chapter 3 of James Bennett's Practical Django Projects. My
> > > problem is that TinyMCE isn't showing up in the Admin -> New Flatpage
> > > text area. Using Linux (Ubuntu 9.04)
>
> > First thing I'd recommend is checking it against the version here:
>
> >http://bitbucket.org/ubernostrum/practical-django-projects/src/tip/cms/
>
> > (about the first four chapters' worth of code are in the repo, the
> > rest is trickling in as I have time to fill it out)
>
> > --
> > "Bureaucrat Conrad, you are technically correct -- the best kind of
> > correct."
>
> What is the whole path to the .js file for your project? I think I'm messing
> it up somewhere along the line, I want to be sure.
>
> My document root in urls.py is /home/erik/tiny_mce/
> And the path in change_form.html is /tiny_mce/tiny_mce.js
>
> The .js file is in /home/erik/tiny_mce/tiny_mce.js
>
> Thank you for responding so fast! Liking your book so far =) (I never get
> things right the first time, it's not a reflection on your book)
--~--~-~--~~~---~--~~
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: Retrieving the request URI inside the view function?

2009-09-26 Thread Alex Robbins

> 1. Consider the user requesting a page like '/orders/9123'.  We detect  
> that the user needs to be logged in to see a particular order, so we  
> redirect to a login form, saving the '/orders/9123'.  If the user logs  
> in as the correct user, we then issue a redirect back to '/orders/9123'.

This seems like you are describing the login_required decorator[1]. It
automatically saves the current url as a query parameter (next) and
redirects to that url once login is complete. If you don't like
decorators you could still use the login view[2] that has the redirect
logic you are after.

[1] 
http://docs.djangoproject.com/en/dev/topics/auth/#the-login-required-decorator
[2] 
http://docs.djangoproject.com/en/dev/topics/auth/#django.contrib.auth.views.login

Hope that helps,
Alex
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: Firefox search plugin for Django documents

2009-09-26 Thread Alex Robbins

Very nice. I just found out you can assign a keyword to search engines
in the manage search engines menu. Now I just type "django search
term" in the location bar and I get what I need. Don't have to change
the search engine back and forth.

Thanks for the awesome plugin.

On Sep 24, 4:01 am, 玉东  wrote:
> Hi, guys,
>
> I've made a firefox search plugin for django documents. It can save your
> time if you often search the official django documents because you don't
> have to visit the djangoproject.com first. Just type in the search box,
> press enter and you'll see the page of the results.
>
> It is useful to me because I often need to search the documents and that's
> the reason why I made it. And I think it might be useful to you if you have
> the same demand, too.
>
> You can check it here:https://addons.mozilla.org/en-US/firefox/addon/14474
>
> It is experimental right now but it can work perfectly under common windows
> and linux distributions. If you meet problems, please tell me.
>
> Thank you.
> --
> 来自 广玉东
> from Guang Yudong / Dennis
> BUAA
> guangyudongb...@gmail.com
> cellphone: (+86)138-1174-5701
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: how to return ajax info in one case, and redirect to a different url in another?

2009-09-15 Thread Alex Robbins

Making the browser switch pages isn't too bad. Just set
document.location to the new url using javascript. (The document
object should be provided by the browser.)
Maybe you should check the headers of the ajax response and if it is a
redirect make the redirect happen using javascript? Or simply make one
of the ajax responses be {"redirect_to": "http://www.example.com/"}
and parse it out on the client side.

Hope that helps,
Alex

On Sep 15, 2:07 am, Margie Roginski  wrote:
> I have a situation where the user fills in a form and hits submit to
> post the form.  If my views.py code detects an error in the form, I
> want to return some info to the client and put it into the dom via
> jquery.  If there is no error, I want to redirect to another page.
> Can anyone advise me on the best way to do this?  I've succesfully
> used $.post() to grab the error info and put it in the dom.  However,
> in the case where there is no error, I can't figure out how to do the
> redirect.
>
> I've tried having the views.py code pass back the url that I want to
> redirect to, and then when my $.post() callback function is called, it
> sets window.location to that url.   But this seems to have some issues
> when the url contains an anchor (for some reason firefox seems to
> cache anchored urls and not redirect to them in the normal way).
>
> Is there any way to specify that even though $.post() started the
> server request, that the server should just redirect to a url (ie,
> using just the basic HttpResponseRedirect() or something like that)
> and not return and call the $.post callback function?
>
> Thanks for any pointers,
>
> Margie
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: haml + sass + django

2009-09-09 Thread Alex Robbins

You might look at http://sandbox.pocoo.org/clevercss/, which is python
based.

On Sep 8, 9:19 am, ThinRhino  wrote:
> Hello,
>
> I just came across haml and sass, but looks like it is built for Ruby on
> Rails.
>
> Any implementation that can work on Django?
>
> Though I also came acrosshttp://bit.ly/3el7iR, by which apache can take
> care of converting haml to html.
>
> Was looking for something where django can take care of the nitty-gritties
>
> Cheers
> ThinRhino
>
> --
> Ships are safe in the harbour
> But that is not what ships are built for
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django and SSL Deployment using mod_wsgi

2009-09-01 Thread Alex Robbins

Graham,

I'm interested in understanding what you just said. It seems like you
are saying you can get the X-Forwarded-SSL environment variable to
automatically be set, without needing the django middleware. Seems
simple enough.

The middleware also handles redirects, so that someone accidentally
going to http://mysite/credit_card_form/ will be redirected to https://
I'm guessing that overriding the wsgi.url_scheme is meant to handle
that, but I don't understand how.

Thanks,
Alex

On Aug 31, 6:02 pm, Graham Dumpleton 
wrote:
> On Sep 1, 3:39 am, Francis  wrote:
>
> > We setup a Nginx proxy in front of Apache/WSGI and got Nginx to handle
> > the SSL cert and simply pass on a flag to WSGI if the connection was
> > coming through http or https.
>
> > Next you'll want a SSL middleware, we 
> > use:http://www.djangosnippets.org/snippets/240/
>
> > Now its a matter of configuring which views you want SSL (follow
> > example in the middleware)
>
> You don't need a SSL middleware. Just add to your Apache
> configuration:
>
>   SetEnvIf X-Forwarded-SSL on HTTPS=1
>
> Apache/mod_wsgi will allow overriding of wsgi.url_scheme based on
> HTTPS variable. The HTTPS variable can be set to 'On' or '1'. Case
> ignored in comparison.
>
> Thus, you can use mod_setenvif to check for header being set and what
> value and then set HTTPS.
>
> Graham
>
> > On Aug 28, 11:04 pm, Vitaly Babiy  wrote:
>
> > > Hey guys,
> > > What is the best way to deploy an app that uses mod_wsgi that some parts 
> > > of
> > > it need to be behind SSL?
>
> > > Thanks,
> > > Vitaly Babiy
>
>
--~--~-~--~~~---~--~~
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: FormWizard: how to pass in extra keyword arguments into a form's __init__?

2009-09-01 Thread Alex Robbins

I guess the question is when you know the additional keyword argument.
If you already know what that extra keyword is when you are
constructing the form list, you could use a partial[1] to put in the
arguments you know already. Partials are python 2.5+ only, you can use
a lambda instead if you are stuck on 2.4. That doesn't help if you
need the kwarg to come at run time though.

[1] http://docs.python.org/library/functools.html#functools.partial

On Aug 31, 4:41 am, Berco Beute  wrote:
> One of the forms I'm using in a FormWizard takes an aditional keyword
> argument in its __init__, e.g.:
>
> =
> def __init__(self, arg1=None, *args, **kwargs):
>     pass
> =
>
> I'm at a loss how to make FormWizard construct my form while passing
> in the extra keyword argument (arg1). Any ideas?
>
> 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: Defining subsets of "list" variable at template level

2009-08-31 Thread Alex Robbins

First, if you aren't running into db performance problems, I wouldn't
optimize. Keep everything as simple as possible, then optimize the
parts that actually demonstrate themselves to be a performance issue.

If this really is a performance issue, you could solve it like this:

If you know that you need the whole list why not do this logic in the
view? This should only make one db query.

mylist = list(MyModel.objects.filter(type="A")|MyModel.objects.filter
(type="B"))

mylist_type_a = [ x for x in mylist if x.type == "A" ]
mylist_type_b = [ x for x in mylist if x.type == "B" ]

Then pass both mylist_type_* variables in your context.

On Aug 7, 1:35 am, bweiss  wrote:
> Is there a simple way to do the following that I'm just not seeing, or
> am I looking at trying to write a custom tag?  The functionality I
> need is similar to {% regroup %} but not quite the same...
>
> My app currently has a custom admin view in which I've defined a whole
> bunch of different lists, which are all objects of the same model,
> filtered according to different options of a field called "Type".
> (eg. type_A_list = mymodel.objects.filter(Type="A"); type_B_list =
> mymodel.objects.filter(Type="B"); etc.)
>
> I've realised that the number of database hits this involves is
> inefficient, and it would be cleaner to have a single list of objects
> and try to perform the logic I need at the template level.
>
> What I'd like to be able to do is, for a single variable,
> "object_list", define subsets of this list containing objects that
> meet a certain condition.  So, to filter by the field "Type", I could
> define lists called "type_A_list", "type_B_list", etc, that could be
> iterated through in the same way as the original list.
>
> The reason I need to do this is to be able to use the {% if
> type_A_list %} tag in order to flag when there are NO objects of a
> given type.  This is why (as far as I can see) the {% regroup %} tag
> won't quite work, as it only lists the groups that actually have
> members.
>
> Output would look something like:
>
> Type 1:
> Object 1, Object 5, Object 6
>
> Type 2:
> There are no objects of Type 2
>
> Type 3:
> Object 2, Object 4
>
> Does anyone have any suggestions?
>
> Thanks,
> Bianca
--~--~-~--~~~---~--~~
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: Advice on Subclassing a TextField

2009-08-30 Thread Alex Robbins

Also, maybe you aren't submitting all the code, but you could do the
same thing by just passing an attrs dictionary to the text area
widget.
http://docs.djangoproject.com/en/dev/ref/forms/widgets/#django.forms.Widget.attrs
Not sure that this requires two more classes.

Hope that helps,
Alex (Robbins)

On Aug 30, 12:53 am, Mark Anderson <nosrednak...@gmail.com> wrote:
> Hello,
>
> I wanted a field that would render in a rich text editor and store the data
> in a TextField so I created a field type of HtmlField and custom HtmlWidge.
> It works but I was wondering is anyone would be willing to give me feedback
> on best practices etc, This is my first attempt at subclassing and any
> points on would be great.  I would like modelform to set the class to rte
> and adjust rows/cols without me having to specify a widget.
>
> Thank you,
> Mark
>
> class HtmlWidget(Textarea):
>     def __init__(self, attrs=None):
>         super(HtmlWidget, self).__init__(attrs)
>
>     def render(self, name, value, attrs=None):
>         if value is None: value = ''
>         value = smart_unicode(value)
>
>         return mark_safe(\
>         u'%s'
> % \
>               (name, escape(value)))
>
> class HtmlField(models.TextField):
>
>     def get_internal_type(self):
>         return "HtmlField"
>
>     def formfield(self, **kwargs):
>         kwargs['widget'] = HtmlWidget
>         return super(HtmlField, self).formfield(**kwargs)
>
>     def __init__(self, *args, **kwargs):
>         super(HtmlField, self).__init__(*args, **kwargs)
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django and SSL Deployment using mod_wsgi

2009-08-29 Thread Alex Robbins

You'll probably want to look into something like this:
http://www.djangosnippets.org/snippets/880/
It allows you to set some urls to redirect so they are always https.
Otherwise those silly users will go to credit card pages without
https.


On Aug 29, 1:04 am, Vitaly Babiy  wrote:
> Hey guys,
> What is the best way to deploy an app that uses mod_wsgi that some parts of
> it need to be behind SSL?
>
> Thanks,
> Vitaly Babiy
--~--~-~--~~~---~--~~
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: Execute code after sending a http response?

2009-08-28 Thread Alex Robbins

You'll have to set something in a table and run a cron to send it
later. Django-mailer [1] has all of this set up for, along with some
other cool features. I've used it in a project before and been happy
with it.

[1] http://code.google.com/p/django-mailer/

On Aug 28, 1:10 am, Shadow  wrote:
> Hi,
>
> Is it possible to execute code after sending the actual http response?
>
> For my website, users can optionally give an email address, and if
> they do, the site sends a confirmation email. But I was thinking it's
> more logical to spend time sending the email after the signup
> confirmation page is sent to the user. Since sending the email doesn't
> affect the http reponse at all?
>
> Is this possible?
>
> cheers
--~--~-~--~~~---~--~~
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: I just need some feedback and advice about my project layout and design.

2009-07-28 Thread Alex Robbins

Sorry, I don't know anything about url namespaces, but this might
help:
If all you are doing is looking up an object and displaying it, I
would use the built-in generic views[1]. Just provide a queryset and
an object id or slug and slug field. Less code to debug and maintain.
There is also a list display for your root url[2] inside the app.

[1] 
http://docs.djangoproject.com/en/dev/ref/generic-views/#django-views-generic-list-detail-object-detail
[2] 
http://docs.djangoproject.com/en/dev/ref/generic-views/#django-views-generic-list-detail-object-list

Hope that helps,
Alex

On Jul 27, 5:13 pm, chyea  wrote:
> Hi all,
>
> I'm writing a very small, simple video game news media site. I'm
> starting off small, with just Blurbs and Reviews. The Blurbs are
> basically quick news articles. The Reviews are extensive articles
> about a video game, ofcourse.
>
> So, since both Blurbs and Reviews are both types of articles, I just
> created an abstract base class for a model - my Article model. And
> then I created a Blurb and Review model. These models live in an
> application named "articles".
>
> Now, with these two models the mission is simple - map some urls to
> views that query the database for the model data and then render the
> template. I really want my urls to look something like this...
>
> site.com/review/
> site.com/review/this-is-a-reviews-slug/
>
> site.com/blurb/
> site.com/blurb/this-is-a-blurbs-slug/
>
> Since the view for both of these urls would be identical, if i made it
> generic by passing in the model type, I decided to whip up a base
> urls.py that looked like the following:http://dpaste.com/71150/
>
> That base urls.py file includes the same url patterns for the slug and
> index views, which exist inside the actual "articles" application, and
> the included urls.py file looks like this:http://dpaste.com/71151/
>
> The two views that are being used here accept the relevant model as a
> parameter and use it to query the database and simply pass the results
> onto a generic template for displaying the data. This all sounds very
> nice and elegant. I wasn't duplicating parts of my code and everything
> I had written was very simple. The problem came though when in my
> template I was wanting to display a permalink, or just simply use a
> reverse lookup to get the link of the article currently being viewed.
>
> When using the {% url %} tag, the reverse lookup was for some odd
> reason returning the "site.com/review/" pattern, which is the second
> pattern, even if the article was a Blurb. I'm not sure why it'd choose
> the second matching pattern instead of the first, but either way this
> behavior is nothing something I was wanting to hack my way around. So,
> I added in the namespaces and in my template tried to use them in the
> reverse url lookup by doing the follow: {% url article:single
> article.slug %}. This was still returning the "site.com/review/"
> pattern match for some reason.
>
> So, I ask - is there something I'm doing wrong? Am I not properly
> using namespaces? They sound to me like they should correct this
> situation but don't appear to be working properly. Is there a better
> way to organize this site layout? I could easily just create two apps
> - one for blurbs and one for reviews but they'd both contain identical
> code, with simple a different template tag line. I could also double
> the number of views and url patterns in my articles app, and point
> them all to their own custom templates. Both of these options are much
> less elegant, though.
>
> Thanks for any advice in advance!
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: Fatal Python error: Inconsistent interned string state.

2009-07-28 Thread Alex Robbins

You mentioned that it just happens sometimes, and I see from your
traceback it happened in the autoreload.py file. Do you still see the
errors if you call runserver --noreload ?
Alex

On Jul 27, 3:57 pm, Ken  Schwencke  wrote:
> I'm working with GeoDjango and PostGIS, and I'm getting "Fatal Python
> error: Inconsistent interned string state." errors randomly while
> using the development server.
>
> It doesn't happen on any specific view (it's happened on the two main
> views), it doesn't happen while doing any specific query, it
> justhappens.
>
> I rarely get a tracebacks when it happens, though today I did:
>
> Traceback (most recent call last):
>   File "./manage.py", line 11, in 
>     execute_manager(settings)
>   File "/Users/kschwen/Dev/django_src/django/core/management/
> __init__.py", line 340, in execute_manager
>     utility.execute()
>   File "/Users/kschwen/Dev/django_src/django/core/management/
> __init__.py", line 295, in execute
>     self.fetch_command(subcommand).run_from_argv(self.argv)
>   File "/Users/kschwen/Dev/django_src/django/core/management/base.py",
> line 195, in run_from_argv
>     self.execute(*args, **options.__dict__)
>   File "/Users/kschwen/Dev/django_src/django/core/management/base.py",
> line 222, in execute
>     output = self.handle(*args, **options)
>   File "/Users/kschwen/Dev/django_src/django/core/management/commands/
> runserver.py", line 83, in handle
>     autoreload.main(inner_run)
>   File "/Users/kschwen/Dev/django_src/django/utils/autoreload.py",
> line 118, in main
>     reloader(main_func, args, kwargs)
>   File "/Users/kschwen/Dev/django_src/django/utils/autoreload.py",
> line 91, in python_reloader
>     reloader_thread()
>   File "/Users/kschwen/Dev/django_src/django/utils/autoreload.py",
> line 72, in reloader_thread
>     if code_changed():
>   File "/Users/kschwen/Dev/django_src/django/utils/autoreload.py",
> line 59, in code_changed
>     mtime = stat.st_mtime
> AttributeError: 'str' object has no attribute 'st_mtime'
> Fatal Python error: Inconsistent interned string state.
>
> Generally, if I get a preceding error, I get something along the lines
> of this:
>
> Assertion failed: (pool->ref.count > 0), function PyObject_Free, file
> Objects/obmalloc.c, line 1109.
>
> Anybody ever hit this error? From Googling, I gather it has something
> to do with a C extension either mis-managing memory or encountering
> garbage while/after allocating. I'm strapping on my debugging shoes,
> but I'm hoping someone can point me in a good direction.
>
> Django version 1.1 pre-alpha SVN-9690, Python version 2.5.1
> (r251:54863, Feb  6 2009, 19:02:12)
--~--~-~--~~~---~--~~
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: best way to format serialized data?

2009-07-28 Thread Alex Robbins

I'm not sure if this answers your question, but...
I have had better luck using the jQuery.load [1] function. It takes an
html response and just jams it into the dom. That way I can do all of
the templating and formatting on the server side. The idea of writing
"" and the like never seemed very maintainable to
me. Your html ends up strewn about your javascript in tiny little
pieces. Instead make a view that returns the whole portion of the page
you need to update (rendered from its own template.) Optionally, you
can use the same template that you used to render the first time(non-
ajax), using {% if request.is_ajax %} to control what comes through
for ajax[2].

I know that is a departure from the standard json response to ajax
calls, but then I don't have to do templating in my javascript, which
grosses me out.
Hope that helps,
Alex

[1] http://docs.jquery.com/Ajax/load
[2] 
http://docs.djangoproject.com/en/dev/ref/request-response/#django.http.HttpRequest.is_ajax

On Jul 27, 7:53 am, DaleB  wrote:
> hi all,
>
> i am just experimenting with ajax following the liveblog-example from
> 'python web development with django' (http://withdjango.com/).
> everything works really good apart from the fact the i don't manage to
> format the serialized data, that is returned by the ajax call:
> 
>  jQuery.each(data, function() {
>                             update_holder.prepend(''
>                                 + ''
>                                 + this.fields.timestamp
> 
> basically i am trying to adjust the date, which is returned as full
> date string (including (month, year etc.) to the rest of the template
> where only the hour and the minutes of a postig are displayed.
> so... django template-filters don't work and using python's strftime-
> function on the returned data has no effect either?
> do i have to format the date in my view? but then, how (and where) can
> i 'reformat' the date?
> the only thing that comes to my mind is copying the requested data to
> a list, replace the date and then hand it over to the serializer...
> but this is rather complicated, isn't it?
>
> greetings,
> andreas
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: middleware cache problem

2009-07-22 Thread Alex Robbins

It sounds like the problem is that you are caching the whole page
using the site wide cache. Maybe things would work better if you used
the low level cache api.[1]

from django.core.cache import cache

MY_STORY_CACHE_KEY = "story_list"
def story_list(request):
  story_list = cache.get(MY_STORY_CACHE_KEY)
  if story_list is None: #Cache miss
story_list = get_stories()
cache.set(MY_STORY_CACHE_KEY, story_list, 60 * 5) #Cached for five
minutes
  vote_list = get_votes()
  return render_to_response(template_name,
dict(vote_list=vote_list, story_list=story_list),
context_instance=RequestContext(request)

Also, you might just to temple level caching.[2]

Finally, if you aren't having performance issues yet, maybe don't
worry about caching. (Premature optimization and all that...)

Hope that helps,
Alex

[1]http://docs.djangoproject.com/en/dev/topics/cache/#the-low-level-
cache-api
[2]http://docs.djangoproject.com/en/dev/topics/cache/#template-
fragment-caching

On Jul 21, 9:59 am, Norman  wrote:
> per-view cache is not a solution because I need only a method to
> retrieve fresh (not cached) data from middleware.
>
> I wanna take cached list of stories and not cached vote results for
> it.
>
> regards, Norman
>
> On Jul 21, 3:13 pm, Michael  wrote:
>
> > On Tue, Jul 21, 2009 at 9:02 AM, Norman  wrote:
>
> > > Hi all,
>
> > > I cache my view that show a list of stories, but I have also small
> > > voting button (like digg). Voting is done be middleware class (it
> > > reads user IP), so I can ask for view with list of stories and tell
> > > that this list shall be cached and I have to ask middleware for vote
> > > results.
>
> > > Unfortunaltely when cache is ON my middleware voting class isn't asked
> > > for voting results.
>
> > > What can I do to mix cache from view and live results from my
> > > middleware voting class?
>
> > From the per-site cache 
> > docshttp://docs.djangoproject.com/en/dev/topics/cache/#the-per-site-cache:
>
> > New in Django 1.0: Please, see the release
> > notes<../../releases/1.0/#releases-1-0>
> > If a view sets its own cache expiry time (i.e. it has a max-age section in
> > its Cache-Control header) then the page will be cached until the expiry
> > time, rather than CACHE_MIDDLEWARE_SECONDS. Using the decorators in
> > django.views.decorators.cache you can easily set a view's expiry time (using
> > the cache_control decorator) or disable caching for a view (using the
> > never_cache decorator). See the using other
> > headers<#controlling-cache-using-other-headers> section
> > for more on these decorators.
>
> > So all you need to do is make the cache on the view different (never_cache
> > decorator might be good here).
>
> > Read more on that page for the per-view cache.
>
> > Hope that helps,
>
> > Michael
--~--~-~--~~~---~--~~
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: New to unit testing, need advice

2009-07-16 Thread Alex Robbins

Whenever I do the same query in a couple of different views, I try to
pull it out into a manager method[1]. For instance, get all the
stories that are marked published from the last two days. I would make
this a method on the manager so I can reuse it other places. Then I
write a test for that manager method to make sure it was selecting the
right stuff. (Not a mutating operation, but it is model-related)

Hope that helps,
Alex

[1] http://docs.djangoproject.com/en/dev/topics/db/managers/#topics-db-managers

On Jul 16, 4:27 am, Joshua Russo  wrote:
> > besides the testing issues (which are certainly a heated debate!), i have 
> > to say that my Django projects became far better organized and a lot more 
> > flexible when i learned to put most of the code on the models, and not on 
> > the views.
>
> I find this really interesting because I wanted to put more code into
> the models but couldn't seem to find the right hooks to accomplish my
> specific tasks.
>
> What are some examples of mutating operations (and other operations
> for that matter) that you use in your models?
>
> Thanks for your suggestions
> Josh
--~--~-~--~~~---~--~~
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: creating user directories upon account activation

2009-07-13 Thread Alex Robbins

You might try pdb[1]. Drop
"import pdb;pdb.set_trace()"
into your code the line before "if SHA1_RE". Once at the pdb prompt
you can just type n to move forward one line at a time. Any python
code you type will get evaluated so you can check the status of
variables at each step. (Pdb is a little cryptic at first, but well
worth the time to learn it.)
Hope that helps,
Alex

1 http://docs.python.org/library/pdb.html

On Jul 12, 11:34 pm, neridaj  wrote:
> moved os import to the top and got rid of try except, with no change.
>
>         if SHA1_RE.search(activation_key):
>             try:
>                 profile = self.get(activation_key=activation_key)
>             except self.model.DoesNotExist:
>                 return False
>             if not profile.activation_key_expired():
>                 media_root = dzopastudio.settings.MEDIA_ROOT
>                 user_directory_path = os.path.join(media_root,
> 'listings',  'neridaj')
>                 os.mkdir(user_directory_path)
>                 user = profile.user
>                 user.is_active = True
>                 user.save()
>                 profile.activation_key = self.model.ACTIVATED
>                 profile.save()
>                 return user
>         return False
>
> On Jul 12, 8:34 pm, Kenneth Gonsalves  wrote:
>
> > On Monday 13 Jul 2009 8:34:23 am neridaj wrote:
>
> > > I still don't get any errors or directories generated from this code,
> > > any ideas?
>
> > remove the try and except stuff - then you can see where it is failing. Also
> > import os on top of your file, not within the code.
> > --
> > regards
> > kghttp://lawgon.livejournal.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
-~--~~~~--~~--~--~---



  1   2   >