Re: how to open a new page when clicking a url

2009-09-22 Thread li kai
Jani Tiainen,

Thanks.

It works.

On Wed, Sep 23, 2009 at 1:40 PM, Jani Tiainen  wrote:

>
> That is something that is not Django specific but can be found in HTML
> specification.
>
> HINT: "target" attribute in ""-tag.
>
> Depending on browser (and/or plugins in browser) results may vary.
>
> li kai kirjoitti:
> > Suppose I have these items in my homepage's header.
> >
> > * E-shop 
> > * E-coupon 
> >
> > source code :
> >E-shop
> > E-coupon
> >
> >
> > Now, I click the "E-shop" item, it will jump to the E-shop address in my
> > current web browser window.
> > But I expect it open a new web browser window and jump to the web
> address.
> >
> > Just like this:
> >   We click the search results of  google search result, and a new page
> > will pop up.
> >
> > Did I make it clear?
> >
> > On Wed, Sep 23, 2009 at 1:22 PM, Jani Tiainen  > > wrote:
> >
> >
> > li kai kirjoitti:
> >  > Hi,
> >  >
> >  > How to implement this in my template html file?
> >  >
> >  > When an user clicks an url address, a new webpage will pop up.
> >
> > That is standard behaviour of any browser that I know of. Or did you
> > meant something else?
> >
> > --
> > Jani Tiainen
> >
> >
> >
> >
> > >
>
>
> --
> 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-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 open a new page when clicking a url

2009-09-22 Thread Jani Tiainen

That is something that is not Django specific but can be found in HTML 
specification.

HINT: "target" attribute in ""-tag.

Depending on browser (and/or plugins in browser) results may vary.

li kai kirjoitti:
> Suppose I have these items in my homepage's header.
> 
> * E-shop 
> * E-coupon 
> 
> source code :
>E-shop
> E-coupon
> 
> 
> Now, I click the "E-shop" item, it will jump to the E-shop address in my 
> current web browser window.
> But I expect it open a new web browser window and jump to the web address.
> 
> Just like this:
>   We click the search results of  google search result, and a new page 
> will pop up.
> 
> Did I make it clear?
> 
> On Wed, Sep 23, 2009 at 1:22 PM, Jani Tiainen  > wrote:
> 
> 
> li kai kirjoitti:
>  > Hi,
>  >
>  > How to implement this in my template html file?
>  >
>  > When an user clicks an url address, a new webpage will pop up.
> 
> That is standard behaviour of any browser that I know of. Or did you
> meant something else?
> 
> --
> Jani Tiainen
> 
> 
> 
> 
> > 


-- 
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-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 open a new page when clicking a url

2009-09-22 Thread li kai
 Suppose I have these items in my homepage's header.

   - E-shop 
   - E-coupon 

source code :
   E-shop
E-coupon


Now, I click the "E-shop" item, it will jump to the E-shop address in my
current web browser window.
But I expect it open a new web browser window and jump to the web address.

Just like this:
  We click the search results of  google search result, and a new page will
pop up.

Did I make it clear?

On Wed, Sep 23, 2009 at 1:22 PM, Jani Tiainen  wrote:

>
> li kai kirjoitti:
> > Hi,
> >
> > How to implement this in my template html file?
> >
> > When an user clicks an url address, a new webpage will pop up.
>
> That is standard behaviour of any browser that I know of. Or did you
> meant something else?
>
> --
> 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-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 open a new page when clicking a url

2009-09-22 Thread Jani Tiainen

li kai kirjoitti:
> Hi,
> 
> How to implement this in my template html file?
> 
> When an user clicks an url address, a new webpage will pop up.

That is standard behaviour of any browser that I know of. Or did you 
meant something else?

-- 
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-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



how to open a new page when clicking a url

2009-09-22 Thread li kai
Hi,

How to implement this in my template html file?

When an user clicks an url address, a new webpage will pop up.

--~--~-~--~~~---~--~~
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: Multi table inheritance and reverse lookup

2009-09-22 Thread Jani Tiainen

Jani Tiainen kirjoitti:
> model.py:
> 
> from django.db import models
> 
> class Order(models.Model):
> name = models.CharField(max_length=64)
> 
> def __unicode__(self):
> return self.name
> 
> class Product(models.Model):
> name  = models.CharField(max_length=64)
> 
> def __unicode__(self):
> return self.name
> 
> class SubProduct1(Product):
> prop1 = models.FloatField()
> 
> def __unicode__(self):
> return self.name
> 
> class SubProduct2(Product):
> prop2 = models.EmailField()
> 
> def __unicode__(self):
> return self.name
> 
> class OrderProduct(models.Model):
> order = models.ForeignKey(Order)
> product = models.ForeignKey(Product)
> 
> amount = models.IntegerField()
> 
> def __unicode__(self):
> return u'%s - %s - %s' % (self.order.name, self.product.name, 
> self.amount)
> 
> 
> Now it's trivial play with sub products and add spesific subproducts to 
> orderproduct.
> 
> But, then, how to list all SubProducts that belongs to spesific order?
> 
> Specially thing stops at "Product", it doesn't know which one of those 
> two subproducts it actually is.
> 
> I did following quick hack to get around this problem (added this to 
> Product model):
> 
> def _get_subproduct(self):
> for attr in ['subproduct1', 'subproduct2', ]:
> try:
> return getattr(self, attr)
> except ObjectDoesNotExist:
> pass
> 
> subproduct = property(_get_subproduct)
> 
> 
> This just don't feel optimal solution, specially it hits database for 
> every subitem tried.
> 
> Any better way to achieve same without hitting that much database?

Or rather I would like to make "product" proterty in OrderProduct to 
return correct subtype right away since I'm not really interested in 
Product model itself but spesific sub types.

Should I do something like:


class OrderProduct(models.Model):
 order = models.ForeignKey(Order)
 product_ = models.ForeignKey(Product)

 amount = models.IntegerField()

 def _get_product(self):
 return product_.subproduct

 product = property(_get_product)

-- 
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-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: django forum

2009-09-22 Thread Wiiboy

Looking at the demo, I think that is the best Python forum I've ever
seen.  Congrats.  This would be my site's saving grace.

However, I installed all the necessary programs, and I get "Cannot
import name utils" from djapian.  If you ever read this again, perhaps
you could help with 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-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: Efficiently searching a tree of FKs

2009-09-22 Thread Rama Vadakattu

Below are some thoughts on how to do the above efficiently:


1) Create a temporary table (or Model) with two fields

   Class Temp(...):
 personid = FK(Person)
 searchstring =  TextField()


2)  When every a person is  saved you will embed a string into the
above table as follows
  ===>  (personid,personname)
whenever a album is stored you modify the search string as follows
   ===> (personid,personname + albumname )==>(the same
row which has foriegn key to person)
whenever a Song is saved you modify the search string as follows
==> (personid, personname + albumname + songname)

 2a)   Basciall if any node is added or updated or deleted we will
form a search string by concatenating the search strings of every node
  until the top and store it  into the Temp table /models , we also
associate the search string with person as this is what we really
want.

2b) To do the above you should rely on Django signals


3) Now define a search function on top TEMP table
  TempTable.objects.filter(searchstring__icontains=search_string)

4) IT may take up bit of memory but it will be superfast.

5) Instead of temporary table you can replace it with simple/basic
full text search engines like
 (whoosh) advanced ones like (solr,sphinx etc)



--rama


















On Sep 22, 7:32 pm, Jeff Gentry  wrote:
> Hello ...
>
> I have a tree like structure created out of models using ForeignKey
> linkages.  As an example:
>
> Model Person:
>    name = CharField
>
> Model Book:
>    name = CharField
>    author = FK(Person)
>
> Model Movie:
>    name = CharField
>    director = FK(Person)
>
> Model Album:
>    name = CharField
>    director = FK(Person)
>
> Model Chapter:
>    name = CharField
>    book = FK(Book)
>
> Model Scene:
>    name = CharField
>    movie = FK(Movie)
>
> Model Song:
>    name = CharField
>    album = FK(Album)
>
> The caveat here is the real structure is both deeper and broader, and a
> node might have multiple non-FK fields (ie not just 'name').
>
> What I'd like to do is have a search function such that there is a string
> supplied which will return any Person that either matches a Person object
> itself, or a field in any of the child nodes.  IOW, if "beat it" is the
> string, and the name of a song associated with an album associated w/ the
> person matches, the person will be returned.
>
> What I've done so far is the following:
>
> For any leaf node, have a Manager object w/ a search method which does
> something like:
>    return Song.objects.filter(name__icontains=search_string)
>
> Then for the root node (Person) and any interior nodes, there is also a
> Manager object w/ a search() method which looks something like:
>     class AlbumManager(models.Model):
>         def search(self, search_string):
>            from_songs = 
> Album.objects.filter(song__in=Song.objects.search(search_string))
>            return 
> Album.objects.filter(name__icontains=search_string)|from_songs
>
> As you might imagine, once you get to the root node, this unleashes a
> massive number of queries and is really inefficient.  I'd be pretty
> surprised if there wasn't a better way to do this ... one idea is to just
> have one search() method at the top of the tree that manually searches
> through everything, but a) that seems very messy (albeit probably more
> efficient) and b) it would be nice to be able to search individual nodes
> arbitrarily.
>
> So with all of this said, what would be a more efficient method of getting
> where I want to be instead of my bonehead method here?
>
> Thanks
> -J
--~--~-~--~~~---~--~~
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: wierd apache and mod_python problem with templates

2009-09-22 Thread Graham Dumpleton



On Sep 22, 11:41 pm, andreas schmid  wrote:
> hi,
>
> im expierencing a strange problem on my server with mod_pyton.
>
> while testing my project on the server launching it with runserver
> everything looks fine.
>
> using apache and mod_python the templates at the root of the templates
> dir in my project are loaded but all the others
> (templates/myproject/template.html ,
> templates/registration/template.html - for example) are not loaded. the
> section content is not loaded and i really cant understand how this is
> possible. the content area is empty.
>
> here is my apache configuration:
>
>     
>
>     
>         SetHandler python-program
>         PythonHandler django.core.handlers.modpython
>         SetEnv DJANGO_SETTINGS_MODULE myproject.production
>         PythonOption django.root /myproject

Wrong. Delete the line setting 'django.root'. You are hosting at root
site and don't need it.

Graham

>         PythonDebug On
>         PythonPath "['/var/www',
>     '/opt/django/myproject/parts/site-packages' ] + sys.path"
>     
>
>     LogLevel warn
>     CustomLog /var/log/apache2/access.log combined
>     ErrorLog /var/log/apache2/error.log
>
>     Alias /media/
>     /usr/lib/python2.5/site-packages/django/contrib/admin/media/
>     
>         SetHandler None
>     
>
>     Alias /site_media/ /var/www/myproject/media/
>     
>         SetHandler None
>     
>
>     
>
> the source in the browser for the content looks like:
>
>         
>
>         
>
>               
>
>           
>           
>
>           
>
> i have another project on the same server working fine... can anybody
> help me?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Python 2.6.2 + Django 1.1 fails to install..

2009-09-22 Thread Jon Cage

I have Python installed and working but when I try and install Django
using:

python setup.py install

..it chunters through a load of stuff and then fails:


creating C:\Python26\Lib\site-packages\django\contrib\localflavor\sk
copying build\lib\django\contrib\localflavor\sk\forms.py -> C:
\Python26\Lib\site-packages\django\contrib\localflavor\sk
copying build\lib\django\contrib\localflavor\sk\sk_districts.py -> C:
\Python26\Lib\site-packages\django\contrib\localflavor\sk
copying build\lib\django\contrib\localflavor\sk\sk_regions.py -> C:
\Python26\Lib\site-packages\django\contrib\localflavor\sk
copying build\lib\django\contrib\localflavor\sk\__ini
creating C:\Python26\Lib\site-packages\django\contrib\localflavor\uk
cerror: Invalid argument

The docs say that Python 2.5 and later (but not 3.0) is supported so
surely this should work?
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Trouble implementing "Password Reset"

2009-09-22 Thread Matt H.

I'm trying to implement Django 1.0.2's "Forgot Password" feature. I've
got far enough that http://127.0.0.1:8000/password_reset/ displays a
form asking for my email address. So far, so good. However, once I
submit the email address for my (django) account I get a
TemplateSyntaxError:

Here is the error message:
---
TemplateSyntaxError at /password_reset/
Caught an exception while rendering: new_password


And here is the (default) Template Code:
---
Template error:
In template /home/matt/Web/django_projects/mpmain/templates/
registration/password_reset_email.html, error at line 5
Caught an exception while rendering: new_password
1 : {% load i18n %}
2 : {% trans "You're receiving this e-mail because you requested a
password reset" %}
3 : {% blocktrans %}for your user account at {{ site_name }}{%
endblocktrans %}.
4 :
5 : {% blocktrans %} Your new password is: {{ new_password }}{%
endblocktrans %}
6 :
7 : {% trans "Feel free to change this password by going to this
page:" %}
8 :
9 : http://{{ domain }}/password_change/
10 :
11 : {% trans "Your username, in case you've forgotten:" %}
{{ user.username }}
12 :
13 : {% trans "Thanks for using our site!" %}
14 :
15 : {% blocktrans %}The {{ site_name }} team{% endblocktrans %}


The exact line that seems to be throwing the exception is line #5:
5 : {% blocktrans %} Your new password is: {{ new_password }}{%
endblocktrans %}


Anyone got any clues for me?

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



Re: limit_choices_to & get_sql()

2009-09-22 Thread Daniel Roseman

On Sep 22, 10:16 pm, Nicolas Steinmetz  wrote:
> Hello,
>
> I would like to present only a subset of a given models. But so far,
> in the admin, I have no value whereas there should be some.
>
> I tried several syntax but did not find the right one.
>
> Here are my implicated (and simplified) models :
>
> class Dns(models.Model):
>     """
>     DNS description
>     """
>     TYPEDNS_CHOICES = (
>         ('1', 'Reference'),
>         ('2', 'Normal'),
>     )
>     name = models.CharField(blank=True, max_length=100)
>     dnstype = models.CharField(max_length=100,
> choices=TYPEDNS_CHOICES)
>
> class Url(models.Model):
>     """
>     Url description
>     """
>     name = models.CharField(blank=True, max_length=100)
>     [...]
>     cnamevalue = models.ForeignKey(Dns, limit_choices_to = {'dns':
> 'get_sql(Dns.dnstype="2")'}, blank=True)
>
> Could someone explain me what is the right syntax ?
>
> I could use formfield_for_foreignkey for admin contrib but I would
> prefer using limit_choices_to that I see as a native solution.
>
> http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contri...
>
> Thanks,
> Nicolas

Seems like you're looking at the ForeignKey documentation. The
reference to get_sql() is confusing and very out of date on that page
- Q objects don't have such a method, although they may have done back
before the merge of queryset-refactor before version 1.0 was released.

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



Slugify doesn't match pre-populated slug field.

2009-09-22 Thread Amos
I have an Admin form with a slugfield prepopulated from the name of the news 
item I'm creating.

In one of my templates I have a link created using the slugify filter applied 
to the name of the news item.

When I create an object with a name such as "A New Story" the prepoulated field 
contains "new-story", but slugify generates "a-new-story" and hence my link 
doesn't point to the correct news story.

Is there any way of ensuring that the two functions generate the same slug?

Cheers
Amos
-- 

My Web Design Business 

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



limit_choices_to & get_sql()

2009-09-22 Thread Nicolas Steinmetz

Hello,

I would like to present only a subset of a given models. But so far,
in the admin, I have no value whereas there should be some.

I tried several syntax but did not find the right one.

Here are my implicated (and simplified) models :

class Dns(models.Model):
"""
DNS description
"""
TYPEDNS_CHOICES = (
('1', 'Reference'),
('2', 'Normal'),
)
name = models.CharField(blank=True, max_length=100)
dnstype = models.CharField(max_length=100,
choices=TYPEDNS_CHOICES)

class Url(models.Model):
"""
Url description
"""
name = models.CharField(blank=True, max_length=100)
[...]
cnamevalue = models.ForeignKey(Dns, limit_choices_to = {'dns':
'get_sql(Dns.dnstype="2")'}, blank=True)

Could someone explain me what is the right syntax ?

I could use formfield_for_foreignkey for admin contrib but I would
prefer using limit_choices_to that I see as a native solution.

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

Thanks,
Nicolas

--~--~-~--~~~---~--~~
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 updating fields which are not being set

2009-09-22 Thread Daniel Roseman

On Sep 22, 8:59 pm, PlanetUnknown  wrote:
> Thanks Tom.
>
> But with this approach -
>
> > foo = Foo.objects.get(pk=foo_id)
> > foo.field = new_value
> > foo.save()
>
> There is an extra DB call, first the the data, and then another one to
> save it.
> If you have the primary_key with you, only one should suffice.
> I mean, when we step back and look at the whole scenario, there are
> thousand consumers doing this, and each has one extra DB call. That's
> pretty expensive.
>

Beware of hyper-optimizing. One extra database call per request is
almost insignificant.

Django's ORM is built to make the common use cases easier, and hence
make application development quicker (rather than necessarily more
efficient in terms of raw speed). The common use case is as Tom
describes. If you want to go outside that, there's nothing to stop
you, but you'll need to run custom SQL.
--
DR.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: passing information from a form instance to a field in that form

2009-09-22 Thread Daniel Roseman

On Sep 22, 8:59 pm, Jim  wrote:
> Hello,
>
> I have a widget that makes suckerfish menus (the kind of menu that is
> written in css and where if you hover your mouse over a menu item any
> subitems appear).
>
> I have some data that can be displayed according to three dimensions.
> (For instance, I could characterize contributers by gender, by
> political persuasion, and by nationality.)  I want to get the tree of
> choices out of the database and to the widget, by dimension.
>
> Thus, if the url is contributer/gender then the choices might be
>   [ ('male', ['male'] ),  ('female', ['female'])  ]
> while if the url is contributer/politics then the choices given to the
> widget might be this.
>   [ ('democrat', ['democrat']), ('republican', ['republican']),
> ('looney', ['looney']),
>        ('looney > right wing', ['looney','right wing']),  ('looney >
> left wing', ['looney','left wing'])]
> (I could show the widget if folks thought it would be helpful.)
>
> I have this form and field.
>
> class CharacterizationForm(forms.Form):
>     def __init__(self,*args,**keywords):
>         if dimen in keywords:  # make any sense?
>             self.dimen=dimen
>         super(CharacterizationForm,self).__init__(*args,**keywords)
>
>     pick=CharacterizationField
> (required=True,widget=widgets.CharacterizationWidget)
>
> class CharacterizationField(forms.ChoiceField):
>            --some stuff--
>         super(CharacterizationField, self).__init__(choices=choices,
> required=required, widget=widget, label=label, initial=initial)
>         self.widget.choices=self.choices
>
> Of course, in the view I initialize the form in some way.
>   f=MenuForm(initial={'dimen',dimen})
> came to mind, although perhaps that is not right?  Now, how do I get
> the information about the dimen into the "--some stuff--", where I can
> then set up the choices from it?
>
> I have been looking at the forms and fields, but I admit I'm not
> getting it.  Any help greatly appreciated.
>
> Jim

Do it all in the form's __init__.

class CharacterizationForm(forms.Form):
def __init__(self, *args, **kwargs):
dimen = kwargs.pop('dimen', None)
super(CharacterizationForm,self).__init__(*args, **kwargs)
if dimen:
self.fields['pick'].dimen = dimen

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



ConFoo.ca call for speakers

2009-09-22 Thread Yannick Gingras

Greetings Djangoers, 
  I'm coordinator for the Python track at the ConFoo.ca conference and I
have an announcement to make that will certainly be of interest to
many of you.

PHP-Québec, Montréal-Python, Ruby Montréal, W3Qc, and OWASP Montréal
are organizing the first edition of the ConFoo.ca conference,
which will be held in Montréal on March 10th through 12th at the
Hilton Bonaventure Hotel.  With over 500 expected attendees,
ConFoo.ca is the largest Web development conference in North
America.

We are looking for the best speakers willing to share their experience
and skills with programmers, managers, marketers and decision
makers. The conference is divided into two parts:

  A technical part, encompassing different aspects of Web development:
  PHP, Python, Ruby, security, project management, CMSs and
  frameworks, databases, systems administration, Web standards,
  accessibility and agile methods.

  A decision-making part: referencing (SEO), Web marketing analysis,
  and social networking.

Presenters can decide to present in English or French.  Presentations
are roughly one hour long and these may be recorded for later
broadcast in digital format.  All relevant details concerning the
conference are available on the call for speaker website [1].

Even though Python can be used for a wide range of programming tasks,
the Python track at ConFoo.ca will focus on Web development with
Python.  For all the other fascinating aspects of Python, do not
hesitate to submit a talk to PyCon [2], which is also running its
call for speakers as I write this.

Share the word!

[1]: http://confoo.ca/en/cfp
[2]: http://us.pycon.org/2010/about/

-- 
Yannick Gingras
http://ygingras.net


signature.asc
Description: This is a digitally signed message part.


Re: URL Parameter is not found, 404 error

2009-09-22 Thread Malcolm MacKinnon
Thanks for your help, Daniel. I made the change.

On Mon, Sep 21, 2009 at 11:47 PM, Daniel Roseman wrote:

>
> On Sep 22, 2:31 am, Malcolm MacKinnon  wrote:
> > Thanks, Karen. With your help, I manged to fix it.
>
> Note that - quite apart from your original problem - you've got a
> serious inefficiency in this view. You iterate through every customer
> to find a matching customer number which, once you get more than a
> few, is going to take some time and use up tons of memory.
>
> Instead of getting all the customers and looping through, just do
> this:
>
> try:
>Customer.objects.get(custno=custnum)
> except Customer.DoesNotExist:
>return HttpResponseRedirect('/denied/')
>
> --
> DR.
> >
>

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



Re: Finding unique ForeignKey enties.

2009-09-22 Thread Joshua Russo
On Tue, Sep 22, 2009 at 7:23 PM, MV  wrote:

>
> I have a Movie model
> and I have a Image model
> the Image model has a ForeignKey(Movie)
>
> Each Movie has an arbitrary amount of Images.
>
> I have a view where I list all the Movies.
> For each Movie entry, I want one Image.
>
> How do I do that?
>
> I can do a "movies = Movies.objects.all()" and pass "movies" to the
> template, but I don't know how to attach an image
> How do I get one, and only one, Image for each Movie?
>
> The only thing I can think about is using a for-loop on the returned
> list of movies, but that will hit the database an awfully lot.
>

You can access the images via moves.images_set.filter()...

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



Finding unique ForeignKey enties.

2009-09-22 Thread MV

I have a Movie model
and I have a Image model
the Image model has a ForeignKey(Movie)

Each Movie has an arbitrary amount of Images.

I have a view where I list all the Movies.
For each Movie entry, I want one Image.

How do I do that?

I can do a "movies = Movies.objects.all()" and pass "movies" to the 
template, but I don't know how to attach an image
How do I get one, and only one, Image for each Movie?

The only thing I can think about is using a for-loop on the returned 
list of movies, but that will hit the database an awfully lot.

--
-0.5


--~--~-~--~~~---~--~~
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 updating fields which are not being set

2009-09-22 Thread PlanetUnknown

Thanks Tom.

But with this approach -
> foo = Foo.objects.get(pk=foo_id)
> foo.field = new_value
> foo.save()

There is an extra DB call, first the the data, and then another one to
save it.
If you have the primary_key with you, only one should suffice.
I mean, when we step back and look at the whole scenario, there are
thousand consumers doing this, and each has one extra DB call. That's
pretty expensive.

On Sep 22, 11:41 am, Tom Evans  wrote:
> On Tue, 2009-09-22 at 08:13 -0700, PlanetUnknown wrote:
> > I'm sure I'm missing something simple here, since its a common flow -
>
> > 1.) e.g. model Person - has 4 fields -
> >     person_id = models.AutoField(primary_key=True)
> >     person_name = models.CharField(max_length=50)
> >     comments = models.TextField(blank=True)
> >     create_dt = models.DateTimeField(auto_now_add=True)
> >     modify_dt = models.DateTimeField(auto_now_add=True)
> >     class Meta:
> >        unique_together = ("person_id", "person_name")
>
> > 2.) When I save a new person, everything works normal, since I'm
> > giving -
> > p1 = Person(person_id=None, person_name=personNameArg,
> > comments=pComment)
>
> > 3.) After this save is performed, I have the "person_id" of this
> > person. When someone hits save again, I do this -
>
> > p1 = Person(person_id=personIdArg, person_name=personNameArg,
> > comments=pComment)
> > where personIdArg is the earlier saved id.
>
> > I get the error - "create_dt cannot be Null", I see that dJango is
> > correctly trying to update, but since I didn't pass create_dt, it is
> > setting it to NULL in the update query.
>
> > I just want it to be left alone, since it already has a value. Is
> > there a way to tell django to not touch these fields ?
>
> > Thanks!
>
> It isn't that common; I haven't got that in any of my views.
>
> The canonical way to update an item, AFAICT, is like so:
>
> foo = Foo.objects.get(pk=foo_id)
> foo.field = new_value
> foo.save()
>
> Cheers
>
> Tom
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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
-~--~~~~--~~--~--~---



passing information from a form instance to a field in that form

2009-09-22 Thread Jim

Hello,

I have a widget that makes suckerfish menus (the kind of menu that is
written in css and where if you hover your mouse over a menu item any
subitems appear).

I have some data that can be displayed according to three dimensions.
(For instance, I could characterize contributers by gender, by
political persuasion, and by nationality.)  I want to get the tree of
choices out of the database and to the widget, by dimension.

Thus, if the url is contributer/gender then the choices might be
  [ ('male', ['male'] ),  ('female', ['female'])  ]
while if the url is contributer/politics then the choices given to the
widget might be this.
  [ ('democrat', ['democrat']), ('republican', ['republican']),
('looney', ['looney']),
   ('looney > right wing', ['looney','right wing']),  ('looney >
left wing', ['looney','left wing'])]
(I could show the widget if folks thought it would be helpful.)

I have this form and field.

class CharacterizationForm(forms.Form):
def __init__(self,*args,**keywords):
if dimen in keywords:  # make any sense?
self.dimen=dimen
super(CharacterizationForm,self).__init__(*args,**keywords)

pick=CharacterizationField
(required=True,widget=widgets.CharacterizationWidget)

class CharacterizationField(forms.ChoiceField):
   --some stuff--
super(CharacterizationField, self).__init__(choices=choices,
required=required, widget=widget, label=label, initial=initial)
self.widget.choices=self.choices

Of course, in the view I initialize the form in some way.
  f=MenuForm(initial={'dimen',dimen})
came to mind, although perhaps that is not right?  Now, how do I get
the information about the dimen into the "--some stuff--", where I can
then set up the choices from it?

I have been looking at the forms and fields, but I admit I'm not
getting it.  Any help greatly appreciated.

Jim


--~--~-~--~~~---~--~~
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: download file

2009-09-22 Thread J. Cliff Dyer

That should do what you are trying to do, though I would say it was
better before.  You essentially broke the web.

Let your users know that it is a PDF, and let them decide whether to
download or open the file themselves.  That should be a browser-side
decision.  If your users want to save it, they can right click the link,
just like they do other places on the web.  

Cheers,
Cliff


On Tue, 2009-09-22 at 01:19 -0700, luca72 wrote:
> i Have solved using this:
> luca = HttpResponse(open('/home/luca72/webapps/django/myproject/
> disegni/'+nome, 'rb').read(), mimetype='application/octet-stream')
> luca['Content-Disposition'] = 'attachment; filename='+nome
> return luca
> 
> Is it ok or i can make it better
> 
> Thanks
> 
> Luca
> 
> On 22 Set, 10:05, luca72  wrote:
> > So i have try this:
> > file_da_scar = F_d.objects.get(pk=id)
> > nom = file_da_scar.nome_fil
> > return HttpResponse(open('/home/luca72/webapps/django/myproject/
> > disegni/'+nom+'.pdf', 'r').read(), mimetype='application/pdf')
> >
> > And it open the pdf file, but if i need only to download without open
> > it how i
> > can proceed.
> >
> > Thanks
> >
> > Luca
> >
> > On 22 Set, 09:02, luca72  wrote:
> >
> > > Thanks I use cherry py because i don't know how to download file with
> > > django, can you tell me how to do it with django
> >
> > > regards
> >
> > > Luca
> >
> > > On 14 Set, 12:46, "J. Cliff Dyer"  wrote:
> >
> > > > On Mon, 2009-09-14 at 07:57 -0700, luca72 wrote:
> > > > > Hello i have try with cherrypy but i get this error:
> >
> > > > > def scarico(request, id):
> > > > > from cherrypy.lib.static import serve_file
> > > > > fil_da_scar = F_d.objects.get(pk=id)
> > > > > nome_file = fil_da_scar.nome_fil
> > > > > return serve_file('/home/luca111/Desktop/Luca/Webframework/
> > > > > off_bert/disegni/'+nome_file+'.pdf','application/x-download',
> > > > > 'attachment')
> >
> > > > > Traceback (most recent call last):
> >
> > > > >   File "/usr/local/lib/python2.6/site-packages/django/core/servers/
> > > > > basehttp.py", line 278, in run
> > > > > self.result = application(self.environ, self.start_response)
> >
> > > > >   File "/usr/local/lib/python2.6/site-packages/django/core/servers/
> > > > > basehttp.py", line 636, in __call__
> > > > > return self.application(environ, start_response)
> >
> > > > >   File "/usr/local/lib/python2.6/site-packages/django/core/handlers/
> > > > > wsgi.py", line 245, in __call__
> > > > > response = middleware_method(request, response)
> >
> > > > >   File "/usr/local/lib/python2.6/site-packages/django/middleware/
> > > > > common.py", line 83, in process_response
> > > > > if response.status_code == 404:
> >
> > > > > AttributeError: 'generator' object has no attribute 'status_code'
> >
> > > > > What is wrong?
> >
> > > > > Regards
> >
> > > > > Luca
> >
> > > > Well, assuming that scarico is getting called as "middleware_method
> > > > within the code, I'd have to say your problem is that cherrypy's
> > > > serve_file returns a generator object of some sort, rather than a django
> > > > HttpResponse object.  This is not surprising, as cherrypy has no reason
> > > > to interoperate properly with django.  What you need to do is either
> > > > catch the generator returned by serve_file, and adapt it to an
> > > > HttpResponse.  
> >
> > > > Something like.
> >
> > > > def cherrypy_to_HttpResponse(generator):
> > > > #???
> > > > return HttpResponse(*args, **kwargs)
> >
> > > > def scarico(request, id):
> > > > # same as before
> > > > served_file = serve_file('/home/luca111/Desktop/Luca/Webframework/'
> > > >+ 'off_bert/disegni/'+nome_file+'.pdf','application/x-download',
> > > >'attachment')
> > > > return cherrypy_to_HttpResponse(served_file)
> >
> > > > Or figure out a way to do it directly in django.
> >
> > > > I'm not sure exactly what you're trying to do, but if you just return
> > > > the content of the file with an appropriate Content-type set in your
> > > > response headers, I think it will work fine.
> >
> > > > Cheers,
> > > > Cliff
> > 


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



Merge models?

2009-09-22 Thread Almost George

Wondering if there is already work being/been done on making it easy
to merge models. It may be much easier than I think, but I thought I
would ask anyway.

Here's my specific scenario:

On a site where users contribute a good deal of content, someone might
come across a piece of content that could be considered a duplicate -
an item, an article about a person, (a "question" in the case of stuff
like StackOverflow).

I'd like to be able to allow certain users to very easily be able to
flag a duplicate, find the "other" model, and easily merge/fix the
differences. One example is a Wiki with a page about "John Smith", and
another about "Jhon Smith". In one case, the user simply spelled the
name wrong. But perhaps there's some valuable meta-data, like "Links
to John Smith Websites", and the first article has a few that aren't
listed on the second.

I'd like to make it fairly simple for a user to say "Hey, *this*
article/item/model is correct, *this other one* is a duplicate, and
keep the unique links from #2" make some final edits, and be done. The
2nd model would (probably) be (soft) deleted.

I'm definitely not wanting to reinvent any wheels - so I'm looking for
other projects that include some functionality like this, to at least
look at as a starting point for how to do this correctly.

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: msgfmt error while attempting to compile po files

2009-09-22 Thread DjangoDragon

That did it. Thanks :D

On Sep 21, 5:14 pm, Ramiro Morales  wrote:
> On Mon, Sep 21, 2009 at 4:51 PM, DjangoDragon  wrote:
>
> > Whenever I try to compile the po files to mo files using 'python
> > django-admin.py compilemessages' command i get the error:
> > "sh:msgfmt: not found"
>
> > I'm in a Ubuntu 9.04 system.
>
> You need to install the gettext package that includes (among others)
> themsgfmtutility from the GNU gettext suite.
>
> http://packages.ubuntu.com/search?searchon=contents=msgfmt...
>
> Regards,
>
> --
> Ramiro Morales  |  http://rmorales.net
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Saving ModelForm with commit=False seems to be generating an INSERT in the database

2009-09-22 Thread Parag Shah

Thanks, you both are right.

user_form.save() is causing the INSERT of the related UserProfile
object. The User object in question here is django.contrib.auth's User
object.

It knows about the UserProfile model object from the following line in
settings.py
AUTH_PROFILE_MODULE = 'courses.userprofile'

I can unserstand the need to create a blank UserProfile object when a
User object is created (perhaps to ensure that a User always has a
UserProfile... even if it's an empty one)

I tried to changing my code, so I update the user_profile_form after
saving the user_form. But that gives me an error because it cannot
find the related object.

Now I am in a situation where if I try to save both the forms, I get a
duplicate key error, and if I try to update the user_profile_form, the
primary key of the related User is not found. I think this may be
because the save and update are happening on the same transaction
because of the transaction middleware I am using.

Is there a good solution to this problem?

-- 
Thanks & Regards
Parag Shah
http://blog.adaptivesoftware.biz



 wrote:
>
>> Why is an INSERT statement being generated even though I have
>> commit=False? The two inserts are causing an Exception which prevent
>> the actual user data from being saved (a row in the
>> courses_userprofile table does get created, but with all columns
>> except the id being blank)
>
> Its odd that the two insert statements have different values for email,
> since between the user_profile_form.save and user_profile.save, you
> arent adding the email in. As Daniel suggested, its more likely the save
> is coming from elsewhere.
>
> Install django-debug-toolbar, then click on the "explain" link on the
> SQL statement, this will tell you exactly where the statement is coming
> from.
>
>
> >
>

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



Multi table inheritance and reverse lookup

2009-09-22 Thread Jani Tiainen

model.py:

from django.db import models

class Order(models.Model):
 name = models.CharField(max_length=64)

 def __unicode__(self):
 return self.name

class Product(models.Model):
 name  = models.CharField(max_length=64)

 def __unicode__(self):
 return self.name

class SubProduct1(Product):
 prop1 = models.FloatField()

 def __unicode__(self):
 return self.name

class SubProduct2(Product):
 prop2 = models.EmailField()

 def __unicode__(self):
 return self.name

class OrderProduct(models.Model):
 order = models.ForeignKey(Order)
 product = models.ForeignKey(Product)

 amount = models.IntegerField()

 def __unicode__(self):
 return u'%s - %s - %s' % (self.order.name, self.product.name, 
self.amount)


Now it's trivial play with sub products and add spesific subproducts to 
orderproduct.

But, then, how to list all SubProducts that belongs to spesific order?

Specially thing stops at "Product", it doesn't know which one of those 
two subproducts it actually is.

I did following quick hack to get around this problem (added this to 
Product model):

 def _get_subproduct(self):
 for attr in ['subproduct1', 'subproduct2', ]:
 try:
 return getattr(self, attr)
 except ObjectDoesNotExist:
 pass

 subproduct = property(_get_subproduct)


This just don't feel optimal solution, specially it hits database for 
every subitem tried.

Any better way to achieve same without hitting that much database?

-- 
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-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 updating fields which are not being set

2009-09-22 Thread Tom Evans

On Tue, 2009-09-22 at 08:13 -0700, PlanetUnknown wrote:
> I'm sure I'm missing something simple here, since its a common flow -
> 
> 1.) e.g. model Person - has 4 fields -
> person_id = models.AutoField(primary_key=True)
> person_name = models.CharField(max_length=50)
> comments = models.TextField(blank=True)
> create_dt = models.DateTimeField(auto_now_add=True)
> modify_dt = models.DateTimeField(auto_now_add=True)
> class Meta:
>   unique_together = ("person_id", "person_name")
> 
> 2.) When I save a new person, everything works normal, since I'm
> giving -
> p1 = Person(person_id=None, person_name=personNameArg,
> comments=pComment)
> 
> 3.) After this save is performed, I have the "person_id" of this
> person. When someone hits save again, I do this -
> 
> p1 = Person(person_id=personIdArg, person_name=personNameArg,
> comments=pComment)
> where personIdArg is the earlier saved id.
> 
> I get the error - "create_dt cannot be Null", I see that dJango is
> correctly trying to update, but since I didn't pass create_dt, it is
> setting it to NULL in the update query.
> 
> I just want it to be left alone, since it already has a value. Is
> there a way to tell django to not touch these fields ?
> 
> Thanks!

It isn't that common; I haven't got that in any of my views.

The canonical way to update an item, AFAICT, is like so:

foo = Foo.objects.get(pk=foo_id)
foo.field = new_value
foo.save()

Cheers

Tom


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

2009-09-22 Thread Tom Evans

On Tue, 2009-09-22 at 08:12 -0700, Charles Wang wrote:
> I have a question for "make apache deliver it". How to control the
> access right? Integrate apache access auth model with Django?
> 
> On Sep 22, 10:37 pm, Javier Guerra  wrote:
> > On Tue, Sep 22, 2009 at 8:09 AM, Jonas Obrist  wrote:
> > > I wanna store files (attachments to forum posts) outside the MEDIA_ROOT
> > > to restrict file downloads to registered users. So I'd have to server
> > > them through django instead of apache. What would be the better way to
> > > do this: Store them in a the database or store them in the filesystem as
> > > actual files?
> >
> > - store in the filesystem
> > - in the view that would serve them, don't read the data, but send an
> > "X-SendFile" header to make apache deliver it.
> >
> > --
> > Javier
> 

It is handled by django, so you can apply all the access control you
want. When you have approved the download in django, instead of reading
in the file in django and sending it to the user, set X-SendFile header
so that apache sees this, and efficiently sends the file.

Tom


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



extending comments views

2009-09-22 Thread anentropic

Hi,

I am trying to extend the comments app so that I can use an alternate
view for post_comment in some situations (i.e. posting via ajax...)

This question is probably largely down to relative python ignorance on
my part, but

1) I have made a new app in my project and set COMMENTS_APP in
settings as per docs
2) in __init__.py I have made a new get_form_target() function which
returns the url to my new ajax_post_comment view

3) I want to reuse all the code in the existing post_comment view
function but just ask it to use a different template.

in django.contrib.comments.views.comments there is:

def post_comment(request, next=None):
... ...
return next_redirect(data, next, comment_done,
c=comment._get_pk_val())

post_comment = require_POST(post_comment)

comment_done = confirmation_view(
template = "comments/posted.html",
doc = """Display a "comment was posted" success page."""
)


So you can see, what I want to do is change the value of comment_done
from my ajax_post_comment view, then maybe call the existing
post_comment view function.

I can't work out how to do this though, and it's looking like I will
have to just copy and paste the existing view code into my new view.
Is there some way to import post_comment and comment_done into my new
views.py such that I can actually affect the value of comment_done
used by the post_comment function?

Any help with my DRY headache much 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-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Using 'django-filter' on a field with choices

2009-09-22 Thread Godshall

I ran into the same problem a few weeks ago.  I solved it by manually
entering a blank field into my filter choices.  Yours could look like
this:

TICKET_STATUS_CHOICES = (
('new', 'New'),
('accepted', 'Accepted'),
('assigned', 'Assigned'),
('reopened', 'Reopened'),
('closed', 'Closed'),
)
class Ticket(models.Model):
assigned_to = models.ForeignKey(User, null=True, blank=True)
status = models.CharField(max_length=20,
choices=TICKET_STATUS_CHOICES, default='new')

import django_filters

FILTER_STATUS_CHOICES = (
('', '-'), #using single quotes
('new', 'New'),
('accepted', 'Accepted'),
('assigned', 'Assigned'),
('reopened', 'Reopened'),
('closed', 'Closed'),
)
class TicketFilter(django_filters.FilterSet):
status = django_filters.ChoiceFilter
(choices=FILTER_STATUS_CHOICES, label='Status')
class Meta:
model = Ticket
fields = ['assigned_to', 'status']

That should give you what you're looking for.  I'm using a LinkWidget
for mine, and it automatically displays an "All" option for the blank
value.

On Sep 21, 1:59 pm, Almost George 
wrote:
> On Sep 21, 8:54 am, Almost George 
> wrote:
>
>
>
>
>
> > I'm using the very cool django-filter 
> > (via:http://github.com/alex/django-filter)
> > and either can't seem to wrap my head around the docs, or maybe just
> > need a little boost.
>
> > When I show the filter form on an object list page, for a FK field I
> > get the dropdown that includes a "-" which kind of results in an
> > "any" type filter. But I have some choices set to a field on that
> > model, and I'd like to get the same "any" type option, but I don't.
>
> > Here's a relevant example portion from models.py:
>
> > ---
>
> > TICKET_STATUS_CHOICES = (
> >     ('new', 'New'),
> >     ('accepted', 'Accepted'),
> >     ('assigned', 'Assigned'),
> >     ('reopened', 'Reopened'),
> >     ('closed', 'Closed'),
> > )
>
> > class Ticket(models.Model):
> >     assigned_to = models.ForeignKey(User, null=True, blank=True)
> >     status = models.CharField(max_length=20,
> > choices=TICKET_STATUS_CHOICES, default='new')
>
> > import django_filters
>
> > class TicketFilter(django_filters.FilterSet):
> >     class Meta:
> >         model = Ticket
> >         fields = ['assigned_to', 'status']
>
> > --
>
> > When I display the filter form, 'assigned_to' gets an 'any' option, as
> > well as listing the available users. The 'status' field, however, is
> > limited to only the options listed in the actual '_CHOICES'.
>
> > How do I add an 'any' option to the fields based on _CHOICES?
>
> I figured out a decent-enough solution to this. I'm sure others could
> point out a more Pythonic or DRY way. 
> See:http://stackoverflow.com/questions/1455415/using-django-filter-with-c...
--~--~-~--~~~---~--~~
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: File storage: Filesystem vs Database

2009-09-22 Thread Javier Guerra

On Tue, Sep 22, 2009 at 10:12 AM, Charles Wang  wrote:
> I have a question for "make apache deliver it". How to control the
> access right? Integrate apache access auth model with Django?

not exactly, the idea is that the file isn't under apache's
DocumentRoot, so it won't have it's own URL.  instead, you have your
Django view that would serve the file by reading it and stuffing the
data in the HttpResponse object.  something like that:

def servefile(request):
--- verify that the user is allowed ---
data = open('filepathname').read()
return HttpResponse (data)

but that makes Django serve the data itself, not a good situation.
so, stop short of actually reading the file, and tell apache to to it:

def servefile(request):
-- verify that the user is allowed ---
resp = HttpResponse ()
resp['X-SendFile'] = 'filepathname'
return resp

note, i've done this with NginX (which uses 'X-Accelerate' instead of
'X-SendFile'), but i've heard it works on Apache too

-- 
Javier

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



Re: File storage: Filesystem vs Database

2009-09-22 Thread Jonas Obrist

Thanks to both Javiers!

--~--~-~--~~~---~--~~
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: File storage: Filesystem vs Database

2009-09-22 Thread Javier Rivera

Charles Wang escribiu:
> I have a question for "make apache deliver it". How to control the
> access right? Integrate apache access auth model with Django?

X-Send-File could send any file that apache can access not only files on 
the "www path". It can send a file that is not accessible by url as long 
as apache can read it.

I don't know if this is enough security for your app.

Javier (a different one, BTW).

--~--~-~--~~~---~--~~
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: File storage: Filesystem vs Database

2009-09-22 Thread Charles Wang

I have a question for "make apache deliver it". How to control the
access right? Integrate apache access auth model with Django?

On Sep 22, 10:37 pm, Javier Guerra  wrote:
> On Tue, Sep 22, 2009 at 8:09 AM, Jonas Obrist  wrote:
> > I wanna store files (attachments to forum posts) outside the MEDIA_ROOT
> > to restrict file downloads to registered users. So I'd have to server
> > them through django instead of apache. What would be the better way to
> > do this: Store them in a the database or store them in the filesystem as
> > actual files?
>
> - store in the filesystem
> - in the view that would serve them, don't read the data, but send an
> "X-SendFile" header to make apache deliver it.
>
> --
> Javier

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



dJango updating fields which are not being set

2009-09-22 Thread PlanetUnknown

I'm sure I'm missing something simple here, since its a common flow -

1.) e.g. model Person - has 4 fields -
person_id = models.AutoField(primary_key=True)
person_name = models.CharField(max_length=50)
comments = models.TextField(blank=True)
create_dt = models.DateTimeField(auto_now_add=True)
modify_dt = models.DateTimeField(auto_now_add=True)
class Meta:
unique_together = ("person_id", "person_name")

2.) When I save a new person, everything works normal, since I'm
giving -
p1 = Person(person_id=None, person_name=personNameArg,
comments=pComment)

3.) After this save is performed, I have the "person_id" of this
person. When someone hits save again, I do this -

p1 = Person(person_id=personIdArg, person_name=personNameArg,
comments=pComment)
where personIdArg is the earlier saved id.

I get the error - "create_dt cannot be Null", I see that dJango is
correctly trying to update, but since I didn't pass create_dt, it is
setting it to NULL in the update query.

I just want it to be left alone, since it already has a value. Is
there a way to tell django to not touch these fields ?

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



success story - thanks to all

2009-09-22 Thread mettwoch

Hi,

I'd just like to share with you all a great moment. We switched today
from our old inventory/invoicing app to a new Django/PostGreSQL based
solution. Thank you so much for all the kind hints and help that I got
over the last 3 month and that helped getting to this point.

Some facts:
- Up to 8 concurrent users (6 PCs and 2 Smartphones)
- 1+ registered customers
- 4+ active products
- 1+ documents/year (invoices, offers, ...)
- Full log of every single user action
- Spiltted responsibility front-office (sales) / back-office
(procurement, validation, ...)
- Barcode support
- Automatic procurement order generated for customer orders and on
minimum product stock
- Minimal workflow (documents, products and partners run through a
series of status)
- PDF invoice generation and distributed printing

Missing features:
- Automatic email generation from validated procurement order
- Automatic email generation for customer information (repair status,
order status, ...)
- A lot of statistics
- A lot of printing (barcode stickers, ...)
- Discount structure

Technical/Design:
- 2500 lines of code
- 1 view (for front- and back-office)
- 1 model (17 application specific tables)
- 1 template (yes! everything fits on 1 screen)

Thank's again so much

Marc

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



opener.dismissAddAnotherPopup error tinymce

2009-09-22 Thread Ali Rıza Keleş

Hi all,

There is something strange with popups on admin page while this page
includes tinymce editor.

When i click  to add a relating object, a popup is being opened and i
enter values and try to save. It is saved but popup is not closed and
give this error on firefox:

"""
opener.dismissAddAnotherPopup(window,"2",
"some_value");

Permission denied to get property Window.dismissAddAnotherPopup
http://local.arha.com.tr/admin/content/author/add/?_popup=1
Line 1



and this error on opera:

"""
opener.dismissAddAnotherPopup(window,"2", "some_value");

Inline script thread
Error:
name: ReferenceError
message: Security error: attempted to read protected variable
'dismissAddAnotherPopup'
stacktrace: n/a; see  opera:config#UserPrefs|Exceptions Have Stacktrace



If same page has no tinymce, everything works very well.

My tinymce initializer has 

"""
document.domain = 'arha.com.tr'
tinyMCE.init({
mode: "textareas",



"""

because media files are being served via another server named as a
subdomain.

Thanks..

--
Ali Rıza Keleş,



--~--~-~--~~~---~--~~
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: ImportError: Could not import settings 'WWlove.settings'

2009-09-22 Thread Jose Sibande

File permissions "seems" to have been the problem. Website is now up
and running after trying almost everything (I felt like the day I lost
my phone security number).

Thank you for the responses.

On Sep 22, 1:48 am, Graham Dumpleton 
wrote:
> On Sep 21, 7:50 am, Jose Sibande  wrote:
>
>
>
> > Hi,
> > I get this error in /var/log/apache2/error.log:
>
> > [Mon Sep 21 01:38:14 2009] [error] [client 41.157.12.3] ImportError:
> > Could not import settings 'WWlove.settings' (Is it on sys.path? Does
> > it have syntax errors?): No module named settings
>
> > And my /home/jose/WWlove/apache/django.wsgi Looks like this:
> > import os, sys
> > sys.path.append('/home/jose')
> > sys.path.append('/home/jose/WWlove')
> > os.environ['DJANGO_SETTINGS_MODULE'] = 'WWlove.settings'
>
> > import django.core.handlers.wsgi
>
> > application = django.core.handlers.wsgi.WSGIHandler()
>
> > *Themod_wsgidocumentation address this issue and says that if this
> > error occurs then that means I haven't spelled my path welll.
> > I looked, trying to spot the error, but evrything seems spelt ok.
>
> As the error says 'No module named settings' and not 'No module named
> WWlove.settings', it suggests it found the package directory called
> 'WWlove' but the directory it found doesn't actually contain a
> settings.py file, or that it isn't readable by user the web server is
> running.
>
> Add to WSGI script:
>
>   import WWlove
>   import sys
>   print >> sys.stderr, WWlove.__path__
>
> and verify where WWlove package root is being picked up from. Then
> check permissions of files in that directory and that it is the
> directory you want used.
>
> Graham
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: File storage: Filesystem vs Database

2009-09-22 Thread Javier Guerra

On Tue, Sep 22, 2009 at 8:09 AM, Jonas Obrist  wrote:
> I wanna store files (attachments to forum posts) outside the MEDIA_ROOT
> to restrict file downloads to registered users. So I'd have to server
> them through django instead of apache. What would be the better way to
> do this: Store them in a the database or store them in the filesystem as
> actual files?

- store in the filesystem
- in the view that would serve them, don't read the data, but send an
"X-SendFile" header to make apache deliver it.



-- 
Javier

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



Efficiently searching a tree of FKs

2009-09-22 Thread Jeff Gentry

Hello ...

I have a tree like structure created out of models using ForeignKey
linkages.  As an example:

Model Person:
   name = CharField

Model Book:
   name = CharField
   author = FK(Person)

Model Movie:
   name = CharField
   director = FK(Person)

Model Album:
   name = CharField
   director = FK(Person)

Model Chapter:
   name = CharField
   book = FK(Book)

Model Scene:
   name = CharField
   movie = FK(Movie)

Model Song:
   name = CharField
   album = FK(Album)

The caveat here is the real structure is both deeper and broader, and a
node might have multiple non-FK fields (ie not just 'name').

What I'd like to do is have a search function such that there is a string
supplied which will return any Person that either matches a Person object
itself, or a field in any of the child nodes.  IOW, if "beat it" is the
string, and the name of a song associated with an album associated w/ the
person matches, the person will be returned.

What I've done so far is the following:

For any leaf node, have a Manager object w/ a search method which does
something like:
   return Song.objects.filter(name__icontains=search_string)

Then for the root node (Person) and any interior nodes, there is also a
Manager object w/ a search() method which looks something like:
class AlbumManager(models.Model):
def search(self, search_string):
   from_songs = 
Album.objects.filter(song__in=Song.objects.search(search_string))
   return Album.objects.filter(name__icontains=search_string)|from_songs

As you might imagine, once you get to the root node, this unleashes a
massive number of queries and is really inefficient.  I'd be pretty
surprised if there wasn't a better way to do this ... one idea is to just
have one search() method at the top of the tree that manually searches
through everything, but a) that seems very messy (albeit probably more
efficient) and b) it would be nice to be able to search individual nodes
arbitrarily.

So with all of this said, what would be a more efficient method of getting
where I want to be instead of my bonehead method here?

Thanks
-J


--~--~-~--~~~---~--~~
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, MySQL, unicode

2009-09-22 Thread mechanix

I have recently faced the same thing while developing a Django app
that processes emails too.
But I found a quick fix, unicode() accepts argument, that tells it
what to do when it stumbles upon non-valid character:

email.mail_from = unicode(email['From'], errors = 'ignore')

Possible values for "errors" are 'strict' (which is default - raises
exception), 'ignore' - just removes invalid character from string and
'replace' - replaces invalid character with U+FFFD

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



Re: Form Select Selected Choice

2009-09-22 Thread Leonel Nunez

>>> Can you give a more detailed example of your code?
>>>
>>
>> This is what basically I'm doing:
>>
>>
>> class MyForm(forms.Form):
>> myfield = forms.CharField(widget=forms.Select)
>>
>>
>> C =[]
>> u = User.objects.all()
>> for r in u:
>> l1 = []
>> l1.append(r.id)
>> l1.append(r.username)
>> C.append(l1)
>>
>> data = {'myfield':'nothing',}
>>
>> form = MyForm(data)
>> form.base_fields['myfield'].widget=widgets.Select(choices=C)
>>
>>
>> The Select gets filled fine with the users data
>> But I can't find how to add the Selected  user to the   tag.
>>
>> By default shows the first user in the query.
>>
>> I hope I've made more clear.
>>
>>
>> Thank  you very much
>>
>>
>> Leonel
>>
>
>
> Don't know if this is valid but is working Ive added this
>
> z = '%s selected=selected' % selecteduid
> CA.insert(0, {z,'the selected user'})
>
> And is working ..
>
> Saludos
>
> Leonel
>
>


No, doesn't work, displays fine but when I submit the form I get the value
 with the selected=selected..

..




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



Re: Form Select Selected Choice

2009-09-22 Thread Leonel Nunez

>> Can you give a more detailed example of your code?
>>
>
> This is what basically I'm doing:
>
>
> class MyForm(forms.Form):
> myfield = forms.CharField(widget=forms.Select)
>
>
> C =[]
> u = User.objects.all()
> for r in u:
> l1 = []
> l1.append(r.id)
> l1.append(r.username)
> C.append(l1)
>
> data = {'myfield':'nothing',}
>
> form = MyForm(data)
> form.base_fields['myfield'].widget=widgets.Select(choices=C)
>
>
> The Select gets filled fine with the users data
> But I can't find how to add the Selected  user to the   tag.
>
> By default shows the first user in the query.
>
> I hope I've made more clear.
>
>
> Thank  you very much
>
>
> Leonel
>


Don't know if this is valid but is working Ive added this

z = '%s selected=selected' % selecteduid
CA.insert(0, {z,'the selected user'})

And is working ..

Saludos

Leonel



--~--~-~--~~~---~--~~
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 can I refresh iframe use the django?

2009-09-22 Thread Tom Evans

On Tue, 2009-09-22 at 21:41 +0800, List Mail wrote:
> When something changed, I want refresh iframe page and pass some
> values to the iframe
> 
> such as when addMethod(a, b) is invoked, the iframe will be refreshed
> and use the parameter a and b
> 
> def addMethod(a, b)
> //need refresh the iframe and pass the value a and b to the iframe
>
> 
> I know I can refresh the page with value a and b.
> t = get_template("New.html")
> c = Context({'a': a, 'b':b })
> return HttpResponse(t.render(c)):
> 
> 

This is more to do with javascript than django; see [1] for how you
might achieve this with the prototype library.

Cheers

Tom

[1] http://www.prototypejs.org/api/ajax/updater



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



How can I refresh iframe use the django?

2009-09-22 Thread List Mail
When something changed, I want refresh iframe page and pass some values to
the iframe

such as when addMethod(a, b) is invoked, the iframe will be refreshed and
use the parameter a and b

def addMethod(a, b)
//need refresh the iframe and pass the value a and b to the iframe
   

I know I can refresh the page with value a and b.
t = get_template("New.html")
c = Context({'a': a, 'b':b })
return HttpResponse(t.render(c)):

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



wierd apache and mod_python problem with templates

2009-09-22 Thread andreas schmid

hi,

im expierencing a strange problem on my server with mod_pyton.

while testing my project on the server launching it with runserver
everything looks fine.

using apache and mod_python the templates at the root of the templates
dir in my project are loaded but all the others
(templates/myproject/template.html ,
templates/registration/template.html - for example) are not loaded. the
section content is not loaded and i really cant understand how this is
possible. the content area is empty.

here is my apache configuration:




SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE myproject.production
PythonOption django.root /myproject
PythonDebug On
PythonPath "['/var/www',
'/opt/django/myproject/parts/site-packages' ] + sys.path"


LogLevel warn
CustomLog /var/log/apache2/access.log combined
ErrorLog /var/log/apache2/error.log

Alias /media/
/usr/lib/python2.5/site-packages/django/contrib/admin/media/

SetHandler None

 
Alias /site_media/ /var/www/myproject/media/

SetHandler None

 



the source in the browser for the content looks like:

 





  


  
  


  
  




i have another project on the same server working fine... can anybody
help me?

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



{{ change }} and {{ add }} in admin

2009-09-22 Thread Peter2108

When the admin renders a change-form it supplies two boolean variables
change and add. 'change' is True when changing an existing instance
and 'add' when adding a new one. Is this behaviour documented because
I find the variables are quite useful?

-- Peter
--~--~-~--~~~---~--~~
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: Comments and objects

2009-09-22 Thread Daniel Roseman

On Sep 22, 2:07 pm, Rodney Topor  wrote:
> Suppose a user posts a comment about a particular object, using
> django.contrib.comments, as described in Practical Django Projects.
> How can one get access to this object in a template such as
> posted.html, so that one can include a link directly back to the
> object?

There's a generic foreign key, called content_object, back to the
object. So {{ comment.content_object.get_absolute_url }} will do the
trick.
See http://docs.djangoproject.com/en/dev/ref/contrib/comments/models/

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



File storage: Filesystem vs Database

2009-09-22 Thread Jonas Obrist

Hi django-users

I wanna store files (attachments to forum posts) outside the MEDIA_ROOT 
to restrict file downloads to registered users. So I'd have to server 
them through django instead of apache. What would be the better way to 
do this: Store them in a the database or store them in the filesystem as 
actual files?

Jonas

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



Comments and objects

2009-09-22 Thread Rodney Topor

Suppose a user posts a comment about a particular object, using
django.contrib.comments, as described in Practical Django Projects.
How can one get access to this object in a template such as
posted.html, so that one can include a link directly back to the
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-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
-~--~~~~--~~--~--~---



IN query problem with 2 for loops on a template

2009-09-22 Thread hinnack

I have 2 querysets:

events = event_dates.objects.select_related('evid', 'evid__type',
'evid__category').all()
inner_qs = event_dates.objects.all().values('pk').query
loc = locations.objects.filter(locid__in=inner_qs).all()
render_to_response('backup.xml', {'events': events, 'locations': loc,
'conn': connection}, mimetype='text/xml')

if I only loop events or loc on my template I only have 2 selects (one
"normal" and one witha "where .. in ()"

if I loop events and loc in 2 seperate loops (not nested) I get 1
select for events and as much selects for loc as rows in the result of
the second query - no
IN select is generated instead each row is fetched itself.

how can I prevent this?

-- Hinnack
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: Pseudo random order for Paginator

2009-09-22 Thread Tim Chase

> I need ordering units in random order, but keep the order for browsing
> per pages and also keep the order for changeable filtering options,
> like startswith and contains. What are the best solutions? There is
> huge amount of units and I read the order by RANDOM() or especialy
> MySQL RAND() is very slow. Have you any experience/solutions?

My first thought would be to bring back the results in a 
predictable order that can't be changed.  That will ensure that 
they don't change over time.  You can then use the "random" 
module's seed/shuffle calls to shuffle the given instance.  You 
merely have to set the seed in your session information:

   import random
   ...
   data = list(MyObject.objects.filter(...).order('predictable'))
   seed = request.GET.get('seed', random.randint(0, 1))
   r = random.Random()
   r.seed(seed)
   r.shuffle(data)
   do_stuff(data, seed) # pass the seed to the template
 # paginator so it can be passed in on the next page


This works because if you take data in a known-order sequence, 
set the random-generator's seed, and then shuffle the data based 
on that sed, you should get the same pseudo-random order each 
time you use the same seed.  So the trick is to choose a random 
seed once per "browsing".

-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-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 templated: iterating through fields in a database record

2009-09-22 Thread Gonzalo Delgado
El Mon, 21 Sep 2009 08:43:57 -0700 (PDT)
Paul Lundberg  escribió:

> Hi:
> I have several Django applications running and I am trying to tidu up
> some code.
> 
> I am trying to make a generic way of viewing a database table on a web
> page using a YUI control.
> 
> I am using the Django template to attempt to create the required
> javascript for the YUI controls.
> 
> I become a bit stuck, in that I can't seem to iterate over the fields
> in a record in a Django template.
> 
> For example I have a project table as follows:
> 
> class projects(models.Model):
> projectName   = models.CharField('Project Name',
> max_length=50, null=False)
> projectDescription= models.TextField('Project Description',
> null=True)
> projectManager= models.CharField('Project Manager',
> max_length=50, null=True)
> projectOwner  = models.CharField('Project Owner',
> max_length=50, null=True)
> projectDate = models.DateField('Project Date',
> null=False)
> projectHidden = models.BooleanField('Project Hidden',
> null=True)
> 
> Then there is a Django view that is used to get the data to render, in
> that I get a list of all the projects:
> 
>  projList = projects.objects.all()
> 
> projList is then passed into the function that renders the page.
> 
> I can go through each record in the projList using:
> 
> {% for projectItem in projList %}
> :
> :
> {% endfor %}
> 
> However I can't seem to go through each field in an individual record
> for example this doesn't work:
> 
> {% for projectItem in projList %}
> {% for fieldval in projectItem.fields %}
> {{fieldval.name }} -:-
> {{ fiieldVal.str }}
> {% endfor %}
> {% endfor %}
> 
> This doesn't cause an error but it doesn't produce any output.

Model instances are not iterable (forms are, they're different type of objects)

> I can access the fields using the field names
> 
> {% for projectItem in projList %}
> {{ projList.projectName }}
> :
> {% endfor %}
> 
> This produces an output but this gets away from the point of making a
> generic function..
> 
> Is this possible? Is this because the fields are not bound to a form's
> fields?
> 
> Any help or advice would be greatly apprecriated!

You could write a method that outputs what you want and call it from the
template.

-- 
P.U. Gonzalo Delgado 
http://gonzalodelgado.com.ar/


pgpvnWYhmhVwf.pgp
Description: PGP signature


Re: About using django-tinymce

2009-09-22 Thread Joost Cassee

On 22 sep, 08:17, taijirobot  wrote:
> well, guys, I've solved this problem, but in a bad way.
>
> Since I'm running the site locally with the default django server, the
> MEDIA_URL became a confusing thing to me. Luckily I have an Apache
> server running on my machine, so I just set the MEDIA_URL to 'http://
> localhost/media/' and copied the files needed in to it.
>
> I think it's a bad way, even no way worse. But it works :)

Check out [1] for more tips on serving static media.

[1] http://docs.djangoproject.com/en/dev/howto/static-files/


Regards,

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



specifying test-only dependencies with djangorecipe

2009-09-22 Thread Chris Withers

Hi Jeroen,

I use two libraries a lot of the time when I'm testing:

http://pypi.python.org/pypi/testfixtures

http://pypi.python.org/pypi/mock

However, I only use these in testing and don't really want them deployed 
for bin/django, only for bin/test.

How would I go about doing this?

cheers,

Chris

-- 
Simplistix - Content Management, Batch Processing & Python Consulting
- http://www.simplistix.co.uk

--~--~-~--~~~---~--~~
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: Prefix primary key

2009-09-22 Thread Tim Bowden

2009/9/22 Michael Anckaert :
>
> Hello everyone,
>
> I'm sure this is something that has been done before, I just can't
> figure out (or google) how to do it.
>
> I want to create PK's on a model that are in the form of 2009001,
> 2009002, 2009003, etc. Simple creating a model method that appends the
> year is not an option because I need models from 2010 to start with
> 2010001, 2010002, etc.
>
> Is there an elegant automatic solution or am I stuck with manually
> creating the PK?
>
> Kind regards,
> Michael

After building the model and runing syncdb, log into the database and do:
SELECT setval('my_pk_seq', 2009001);
where 'my_pk_seq' is the name of the sequence for the primary key of
the table in question.

HTH,
Tim Bowden

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



Prefix primary key

2009-09-22 Thread Michael Anckaert

Hello everyone,

I'm sure this is something that has been done before, I just can't
figure out (or google) how to do it.

I want to create PK's on a model that are in the form of 2009001,
2009002, 2009003, etc. Simple creating a model method that appends the
year is not an option because I need models from 2010 to start with
2010001, 2010002, etc.

Is there an elegant automatic solution or am I stuck with manually
creating the PK?

Kind regards,
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: Records doesn't sometimes get upated

2009-09-22 Thread Daniel Roseman

On Sep 22, 9:48 am, Szymon  wrote:
> On 21 Wrz, 22:47, Javier Guerra  wrote:
>
> > only if you include it in the parameter list:
>
> Oh, yes. I forget about self in my example, but in function that makes
> problem there is of course self in parameter list.

I suspect the problem isn't quite what you think it is. It looks like
the new value of the object will always be saved to the database, and
that instance will carry the new value. However, Django model
instances are independent of the database and of other instances that
refer to the same database row. So, if you have another instance
somewhere else in your code with the same database id, it won't be
updated even if you save this one - you'll need to get it again from
the database,
--
DR.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Using shell to add images

2009-09-22 Thread Richard

No sorry it's late was just typing up the scenario to be more ledgible
(i'm doing a lot with random) meant while x < 20.

Basically looks like this to add a single image model:

from django.core.files import File
from job.models import Job, JobPhoto

job = Job.objects.get(pk=1544)
lp = JobPhoto()
lp.job = job
lp.position = 1
lp.image = File(open('blah.jpg', 'r'))

lp.save()


On Sep 22, 1:48 am, nausikaa  wrote:
> Hi Timboy
>
> Sorry but I've never seen:
>
> for x in 20:
>     # do sth.
>
> 20 is an int object and not an iterable.
> Is this snippet your code?
>
> Nausikaa
>
> On Sep 22, 10:15 am, Timboy  wrote:
>
> > Having issues saving model from within the shell.
>
> > Using File from from django.core.files import File
>
> >http://pastebin.com/f3030ca1e
>
> > Tried this several different ways...
>
> > TIA
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: multi-db vs. data warehouse

2009-09-22 Thread nausikaa


Hi snfctech


With warehouse I assume you mean keeping the datasources and periodic
transfer into a central db (the warehouse).
Why not migrate all your datasources into e.g. a PostgreDQL db?
It is easy to write forms and implement logins/access rights in
django so that your non-technical users can read or edit the
data. Besides you'd remove some (unnecessary) heterogenity and thereby
complexity from your system.
But since I don't know your system I might be missing the point
completely.

Nausikaa

On Sep 22, 3:10 am, snfctech  wrote:
> I understand that there is a Django branch being actively worked on
> for connections to multiple DB vendors, or that Django + Elixir may be
> a good option.  But I'm wondering if building a single data warehouse
> may still be a better way to go?
>
> Here's an example of some of the relations I'm going to have to build
> for my project:
>
> I've got order and order_item tables with their own data and relations
> to members (Access DB), products (flat file) and employees (MySQL).
>
> I initially thought that the best way to manage this would be to
> create a new DB for the order and order_item tables, and then create
> cross-vendor joins in the ORM.  But then I came across an unexpected
> advantage of having all the data in an updated warehouse - my semi-
> technical staff could still use products like OOBase, that are limited
> to a single vendor connection, to make reports and forms based on the
> warehouse data.
>
> So now I'm wondering - are direct connections to multiple databases
> really the best way to go?  Or are there more advantages to building a
> data warehouse (keeping in mind the complexities of the data
> replication, scripts for pushing and pulling data, etc.)
>
> Thanks in advance for any tips.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Using shell to add images

2009-09-22 Thread nausikaa


Hi Timboy


Sorry but I've never seen:

for x in 20:
# do sth.

20 is an int object and not an iterable.
Is this snippet your code?


Nausikaa

On Sep 22, 10:15 am, Timboy  wrote:
> Having issues saving model from within the shell.
>
> Using File from from django.core.files import File
>
> http://pastebin.com/f3030ca1e
>
> Tried this several different ways...
>
> TIA
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Records doesn't sometimes get upated

2009-09-22 Thread Szymon

On 21 Wrz, 22:47, Javier Guerra  wrote:
> only if you include it in the parameter list:

Oh, yes. I forget about self in my example, but in function that makes
problem there is of course self in parameter list.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: composite primary keys?

2009-09-22 Thread nausikaa

Hi Chris


I hope this helps:

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

So there is a "patch" but I didn't try it.
The way I worked around it was by adapting my db model.
Assuming you have an existing db you might want to try the patch.

Nausikaa



On Sep 22, 10:17 am, Chris Withers  wrote:
> Hi All,
>
> Is it really the case that the Django ORM doesn't support composite
> primary keys?
>
> I'm looking to do the equivalent of the following sqlalchemy model:
>
> Base = declarative_base(...)
>
> class Month(Base):
>      __tablename__ = 'months'
>      username = Column(
>                  String,ForeignKey('users.name'),primary_key=True
>                  )
>      monthname = Column(String,primary_key=True,index=True)
>      signins = Column(Integer,index=True)
>      signouts = Column(Integer,index=True)
>      total_pages = Column(Integer,index=True)
>      last_viewed = Column(DateTime,index=True)
>
> cheers,
>
> Chris
>
> --
> Simplistix - Content Management, Batch Processing & Python Consulting
>             -http://www.simplistix.co.uk
--~--~-~--~~~---~--~~
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: download file

2009-09-22 Thread luca72

i Have solved using this:
luca = HttpResponse(open('/home/luca72/webapps/django/myproject/
disegni/'+nome, 'rb').read(), mimetype='application/octet-stream')
luca['Content-Disposition'] = 'attachment; filename='+nome
return luca

Is it ok or i can make it better

Thanks

Luca

On 22 Set, 10:05, luca72  wrote:
> So i have try this:
> file_da_scar = F_d.objects.get(pk=id)
>     nom = file_da_scar.nome_fil
>     return HttpResponse(open('/home/luca72/webapps/django/myproject/
> disegni/'+nom+'.pdf', 'r').read(), mimetype='application/pdf')
>
> And it open the pdf file, but if i need only to download without open
> it how i
> can proceed.
>
> Thanks
>
> Luca
>
> On 22 Set, 09:02, luca72  wrote:
>
> > Thanks I use cherry py because i don't know how to download file with
> > django, can you tell me how to do it with django
>
> > regards
>
> > Luca
>
> > On 14 Set, 12:46, "J. Cliff Dyer"  wrote:
>
> > > On Mon, 2009-09-14 at 07:57 -0700, luca72 wrote:
> > > > Hello i have try with cherrypy but i get this error:
>
> > > > def scarico(request, id):
> > > >     from cherrypy.lib.static import serve_file
> > > >     fil_da_scar = F_d.objects.get(pk=id)
> > > >     nome_file = fil_da_scar.nome_fil
> > > >     return serve_file('/home/luca111/Desktop/Luca/Webframework/
> > > > off_bert/disegni/'+nome_file+'.pdf','application/x-download',
> > > > 'attachment')
>
> > > > Traceback (most recent call last):
>
> > > >   File "/usr/local/lib/python2.6/site-packages/django/core/servers/
> > > > basehttp.py", line 278, in run
> > > >     self.result = application(self.environ, self.start_response)
>
> > > >   File "/usr/local/lib/python2.6/site-packages/django/core/servers/
> > > > basehttp.py", line 636, in __call__
> > > >     return self.application(environ, start_response)
>
> > > >   File "/usr/local/lib/python2.6/site-packages/django/core/handlers/
> > > > wsgi.py", line 245, in __call__
> > > >     response = middleware_method(request, response)
>
> > > >   File "/usr/local/lib/python2.6/site-packages/django/middleware/
> > > > common.py", line 83, in process_response
> > > >     if response.status_code == 404:
>
> > > > AttributeError: 'generator' object has no attribute 'status_code'
>
> > > > What is wrong?
>
> > > > Regards
>
> > > > Luca
>
> > > Well, assuming that scarico is getting called as "middleware_method
> > > within the code, I'd have to say your problem is that cherrypy's
> > > serve_file returns a generator object of some sort, rather than a django
> > > HttpResponse object.  This is not surprising, as cherrypy has no reason
> > > to interoperate properly with django.  What you need to do is either
> > > catch the generator returned by serve_file, and adapt it to an
> > > HttpResponse.  
>
> > > Something like.
>
> > > def cherrypy_to_HttpResponse(generator):
> > >     #???
> > >     return HttpResponse(*args, **kwargs)
>
> > > def scarico(request, id):
> > >     # same as before
> > >     served_file = serve_file('/home/luca111/Desktop/Luca/Webframework/'
> > >        + 'off_bert/disegni/'+nome_file+'.pdf','application/x-download',
> > >        'attachment')
> > >     return cherrypy_to_HttpResponse(served_file)
>
> > > Or figure out a way to do it directly in django.
>
> > > I'm not sure exactly what you're trying to do, but if you just return
> > > the content of the file with an appropriate Content-type set in your
> > > response headers, I think it will work fine.
>
> > > Cheers,
> > > Cliff
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



composite primary keys?

2009-09-22 Thread Chris Withers

Hi All,

Is it really the case that the Django ORM doesn't support composite 
primary keys?

I'm looking to do the equivalent of the following sqlalchemy model:

Base = declarative_base(...)

class Month(Base):
 __tablename__ = 'months'
 username = Column(
 String,ForeignKey('users.name'),primary_key=True
 )
 monthname = Column(String,primary_key=True,index=True)
 signins = Column(Integer,index=True)
 signouts = Column(Integer,index=True)
 total_pages = Column(Integer,index=True)
 last_viewed = Column(DateTime,index=True)

cheers,

Chris

-- 
Simplistix - Content Management, Batch Processing & Python Consulting
- http://www.simplistix.co.uk

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



Using shell to add images

2009-09-22 Thread Timboy

Having issues saving model from within the shell.

Using File from from django.core.files import File

http://pastebin.com/f3030ca1e

Tried this several different ways...

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



Re: download file

2009-09-22 Thread luca72

So i have try this:
file_da_scar = F_d.objects.get(pk=id)
nom = file_da_scar.nome_fil
return HttpResponse(open('/home/luca72/webapps/django/myproject/
disegni/'+nom+'.pdf', 'r').read(), mimetype='application/pdf')

And it open the pdf file, but if i need only to download without open
it how i
can proceed.

Thanks

Luca

On 22 Set, 09:02, luca72  wrote:
> Thanks I use cherry py because i don't know how to download file with
> django, can you tell me how to do it with django
>
> regards
>
> Luca
>
> On 14 Set, 12:46, "J. Cliff Dyer"  wrote:
>
> > On Mon, 2009-09-14 at 07:57 -0700, luca72 wrote:
> > > Hello i have try with cherrypy but i get this error:
>
> > > def scarico(request, id):
> > >     from cherrypy.lib.static import serve_file
> > >     fil_da_scar = F_d.objects.get(pk=id)
> > >     nome_file = fil_da_scar.nome_fil
> > >     return serve_file('/home/luca111/Desktop/Luca/Webframework/
> > > off_bert/disegni/'+nome_file+'.pdf','application/x-download',
> > > 'attachment')
>
> > > Traceback (most recent call last):
>
> > >   File "/usr/local/lib/python2.6/site-packages/django/core/servers/
> > > basehttp.py", line 278, in run
> > >     self.result = application(self.environ, self.start_response)
>
> > >   File "/usr/local/lib/python2.6/site-packages/django/core/servers/
> > > basehttp.py", line 636, in __call__
> > >     return self.application(environ, start_response)
>
> > >   File "/usr/local/lib/python2.6/site-packages/django/core/handlers/
> > > wsgi.py", line 245, in __call__
> > >     response = middleware_method(request, response)
>
> > >   File "/usr/local/lib/python2.6/site-packages/django/middleware/
> > > common.py", line 83, in process_response
> > >     if response.status_code == 404:
>
> > > AttributeError: 'generator' object has no attribute 'status_code'
>
> > > What is wrong?
>
> > > Regards
>
> > > Luca
>
> > Well, assuming that scarico is getting called as "middleware_method
> > within the code, I'd have to say your problem is that cherrypy's
> > serve_file returns a generator object of some sort, rather than a django
> > HttpResponse object.  This is not surprising, as cherrypy has no reason
> > to interoperate properly with django.  What you need to do is either
> > catch the generator returned by serve_file, and adapt it to an
> > HttpResponse.  
>
> > Something like.
>
> > def cherrypy_to_HttpResponse(generator):
> >     #???
> >     return HttpResponse(*args, **kwargs)
>
> > def scarico(request, id):
> >     # same as before
> >     served_file = serve_file('/home/luca111/Desktop/Luca/Webframework/'
> >        + 'off_bert/disegni/'+nome_file+'.pdf','application/x-download',
> >        'attachment')
> >     return cherrypy_to_HttpResponse(served_file)
>
> > Or figure out a way to do it directly in django.
>
> > I'm not sure exactly what you're trying to do, but if you just return
> > the content of the file with an appropriate Content-type set in your
> > response headers, I think it will work fine.
>
> > Cheers,
> > Cliff
--~--~-~--~~~---~--~~
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: download file

2009-09-22 Thread luca72

So i have try this:
file_da_scar = F_d.objects.get(pk=id)
nom = file_da_scar.nome_fil
return HttpResponse(open('/home/luca72/webapps/django/myproject/
disegni/'+nom+'.pdf', 'r').read(), mimetype='application/pdf')

And it open the pdf file, but if i need only to without open it how i
can proceed.

Thanks

Luca

On 22 Set, 09:02, luca72  wrote:
> Thanks I use cherry py because i don't know how to download file with
> django, can you tell me how to do it with django
>
> regards
>
> Luca
>
> On 14 Set, 12:46, "J. Cliff Dyer"  wrote:
>
> > On Mon, 2009-09-14 at 07:57 -0700, luca72 wrote:
> > > Hello i have try with cherrypy but i get this error:
>
> > > def scarico(request, id):
> > >     from cherrypy.lib.static import serve_file
> > >     fil_da_scar = F_d.objects.get(pk=id)
> > >     nome_file = fil_da_scar.nome_fil
> > >     return serve_file('/home/luca111/Desktop/Luca/Webframework/
> > > off_bert/disegni/'+nome_file+'.pdf','application/x-download',
> > > 'attachment')
>
> > > Traceback (most recent call last):
>
> > >   File "/usr/local/lib/python2.6/site-packages/django/core/servers/
> > > basehttp.py", line 278, in run
> > >     self.result = application(self.environ, self.start_response)
>
> > >   File "/usr/local/lib/python2.6/site-packages/django/core/servers/
> > > basehttp.py", line 636, in __call__
> > >     return self.application(environ, start_response)
>
> > >   File "/usr/local/lib/python2.6/site-packages/django/core/handlers/
> > > wsgi.py", line 245, in __call__
> > >     response = middleware_method(request, response)
>
> > >   File "/usr/local/lib/python2.6/site-packages/django/middleware/
> > > common.py", line 83, in process_response
> > >     if response.status_code == 404:
>
> > > AttributeError: 'generator' object has no attribute 'status_code'
>
> > > What is wrong?
>
> > > Regards
>
> > > Luca
>
> > Well, assuming that scarico is getting called as "middleware_method
> > within the code, I'd have to say your problem is that cherrypy's
> > serve_file returns a generator object of some sort, rather than a django
> > HttpResponse object.  This is not surprising, as cherrypy has no reason
> > to interoperate properly with django.  What you need to do is either
> > catch the generator returned by serve_file, and adapt it to an
> > HttpResponse.  
>
> > Something like.
>
> > def cherrypy_to_HttpResponse(generator):
> >     #???
> >     return HttpResponse(*args, **kwargs)
>
> > def scarico(request, id):
> >     # same as before
> >     served_file = serve_file('/home/luca111/Desktop/Luca/Webframework/'
> >        + 'off_bert/disegni/'+nome_file+'.pdf','application/x-download',
> >        'attachment')
> >     return cherrypy_to_HttpResponse(served_file)
>
> > Or figure out a way to do it directly in django.
>
> > I'm not sure exactly what you're trying to do, but if you just return
> > the content of the file with an appropriate Content-type set in your
> > response headers, I think it will work fine.
>
> > Cheers,
> > Cliff
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Confirming GeoDjango OSMAdmin Bug

2009-09-22 Thread Kevin Systrom

Hey all,

I've been having an issue using the filter on a GeoQuerySet with
Django 1.1.

I have a "Locations" table that looks more or less like this:

class Location(models.Model):
pnt = models.PointField()
name = models.CharField(max_length=255)

To query, I look for an object like this:

>>> Location.objects.filter(pnt="POINT(-122.421961 37.767019)")
[]

Then, I go into the admin, view this object, don't make any changes,
but then click "Save".

I run this command again and get nothing:

>>> Location.objects.filter(pnt="POINT(-122.421961 37.767019)")
[]

Interesting Shouldn't the admin not change this object at all? It
turns out that simply by clicking save in the admin, the object
changed to have the following point:

>>> l=Location.objects.filter(name='Fourbarrel Coffee')
>>> print l.pnt
POINT (-122.42196060 37.767018999835)
>>> print l.pnt.x
-122.421961
>>> print l.pnt.y
37.767019

Hmm.. Maybe searching for the location using the Point object will be
more accurate?

>>> from django.contrib.gis.geos import *
>>> pnt  = Point(-122.421961, 37.767019)
>>> Location.objects.filter(pnt=pnt)
[]

Nope. Well let's go with the wkt text we got back:

>>> wkt = "POINT (-122.42196060 37.767018999835)"
>>> Location.objects.filter(pnt=wkt)
[]


Clearly something is wrong here if viewing an object in admin, not
changing anything, and then clicking save *changes* the object. I'm
assuming that this is a bug in the OSMAdmin that places the point on
the map for the view, and then on save, uses the point on the map to
save... but for some reason saves it ever so slightly off.  I'm using
django 1.1 (official release) and Postgres 8.4 for my database. This
is the admins file I'm using for the Location object:

from django.contrib.gis import admin
from models import Location

class LocationAdmin(admin.OSMGeoAdmin):
search_fields = ['name']

admin.site.register(Location, LocationAdmin)


I'm assuming this is a bug -- but I'm sending it to you all to confirm
that I'm not just missing something obvious.

--~--~-~--~~~---~--~~
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: About using django-tinymce

2009-09-22 Thread Daniel Roseman

On Sep 22, 7:17 am, taijirobot  wrote:
> well, guys, I've solved this problem, but in a bad way.
>
> Since I'm running the site locally with the default django server, the
> MEDIA_URL became a confusing thing to me. Luckily I have an Apache
> server running on my machine, so I just set the MEDIA_URL to 'http://
> localhost/media/' and copied the files needed in to it.
>
> I think it's a bad way, even no way worse. But it works :)
>

I don't know why you think this is a bad way to do it. It's a
perfectly good method. Django doesn't usually serve your media for
you, although it can be made to do it via the development server only,
so using Apache is the normal way to do 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-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: About using django-tinymce

2009-09-22 Thread Daniel Roseman

On 2009/9/22, taijirobot  wrote:

> Thank you very much. The problem was solved after I changed the
> MEDIA_URL setting.
>
> But now I have a new question, it is about the display of the rich
> text.
>
> I used code like this to display it:
>
> {{ post.title }}
> {{ post.timestamp|date }}
> {{ post.body }}
>
> the body was edited in rich text editor. as you know, the body will be
> displayed in html format with html tags with it, but not a formatted
> text.
>
> What should I do to display the body as it edited?
>
> Thank you.

Look at the documentation on autoescaping:
http://docs.djangoproject.com/en/dev/topics/templates/#id2
--
DR.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: download file

2009-09-22 Thread luca72

Thanks I use cherry py because i don't know how to download file with
django, can you tell me how to do it with django

regards

Luca

On 14 Set, 12:46, "J. Cliff Dyer"  wrote:
> On Mon, 2009-09-14 at 07:57 -0700, luca72 wrote:
> > Hello i have try with cherrypy but i get this error:
>
> > def scarico(request, id):
> >     from cherrypy.lib.static import serve_file
> >     fil_da_scar = F_d.objects.get(pk=id)
> >     nome_file = fil_da_scar.nome_fil
> >     return serve_file('/home/luca111/Desktop/Luca/Webframework/
> > off_bert/disegni/'+nome_file+'.pdf','application/x-download',
> > 'attachment')
>
> > Traceback (most recent call last):
>
> >   File "/usr/local/lib/python2.6/site-packages/django/core/servers/
> > basehttp.py", line 278, in run
> >     self.result = application(self.environ, self.start_response)
>
> >   File "/usr/local/lib/python2.6/site-packages/django/core/servers/
> > basehttp.py", line 636, in __call__
> >     return self.application(environ, start_response)
>
> >   File "/usr/local/lib/python2.6/site-packages/django/core/handlers/
> > wsgi.py", line 245, in __call__
> >     response = middleware_method(request, response)
>
> >   File "/usr/local/lib/python2.6/site-packages/django/middleware/
> > common.py", line 83, in process_response
> >     if response.status_code == 404:
>
> > AttributeError: 'generator' object has no attribute 'status_code'
>
> > What is wrong?
>
> > Regards
>
> > Luca
>
> Well, assuming that scarico is getting called as "middleware_method
> within the code, I'd have to say your problem is that cherrypy's
> serve_file returns a generator object of some sort, rather than a django
> HttpResponse object.  This is not surprising, as cherrypy has no reason
> to interoperate properly with django.  What you need to do is either
> catch the generator returned by serve_file, and adapt it to an
> HttpResponse.  
>
> Something like.
>
> def cherrypy_to_HttpResponse(generator):
>     #???
>     return HttpResponse(*args, **kwargs)
>
> def scarico(request, id):
>     # same as before
>     served_file = serve_file('/home/luca111/Desktop/Luca/Webframework/'
>        + 'off_bert/disegni/'+nome_file+'.pdf','application/x-download',
>        'attachment')
>     return cherrypy_to_HttpResponse(served_file)
>
> Or figure out a way to do it directly in django.
>
> I'm not sure exactly what you're trying to do, but if you just return
> the content of the file with an appropriate Content-type set in your
> response headers, I think it will work fine.
>
> Cheers,
> Cliff
--~--~-~--~~~---~--~~
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 Parameter is not found, 404 error

2009-09-22 Thread Daniel Roseman

On Sep 22, 2:31 am, Malcolm MacKinnon  wrote:
> Thanks, Karen. With your help, I manged to fix it.

Note that - quite apart from your original problem - you've got a
serious inefficiency in this view. You iterate through every customer
to find a matching customer number which, once you get more than a
few, is going to take some time and use up tons of memory.

Instead of getting all the customers and looping through, just do
this:

try:
Customer.objects.get(custno=custnum)
except Customer.DoesNotExist:
return HttpResponseRedirect('/denied/')

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



Pseudo random order for Paginator

2009-09-22 Thread gentlestone

Hello,

I need ordering units in random order, but keep the order for browsing
per pages and also keep the order for changeable filtering options,
like startswith and contains. What are the best solutions? There is
huge amount of units and I read the order by RANDOM() or especialy
MySQL RAND() is very slow. Have you any experience/solutions?
--~--~-~--~~~---~--~~
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: About using django-tinymce

2009-09-22 Thread taijirobot

well, guys, I've solved this problem, but in a bad way.

Since I'm running the site locally with the default django server, the
MEDIA_URL became a confusing thing to me. Luckily I have an Apache
server running on my machine, so I just set the MEDIA_URL to 'http://
localhost/media/' and copied the files needed in to it.

I think it's a bad way, even no way worse. But it works :)

On Sep 21, 12:22 pm, taijirobot  wrote:
> Hi, guys,
>
> I'm learning django recently and I am trying to add a rich text editor
> to the places where long formated text like blog post are needed (the
> site is running on local machine with the default django server).
>
> I tried to use django-tinymce :http://code.google.com/p/django-tinymce/
> and all the things I did was:
>
> 1. download the django-tinymce package, extract, and run 'sudo python
> setup.py install'
>
> 2. get a tinymce distribution(new enough) and copy the jscripts/
> tiny_mce to the media root of my local machine.
>
> my config:
> MEDIA_ROOT = '/home/taijirobot/mysite/media/'
> MEDIA_URL = ''
>
> 3. add 'tinymce' to INSTALLED_APPS in settings
>
> 4. Change the definition of the BlogForm (a form defined to generate
> form for blog mode), like this:
> ..
> class BlogPost(models.Model):
>     title = models.CharField(max_length=150)
>     body = models.TextField()
>     timestamp = models.DateTimeField(default=datetime.datetime.now)
>     class Meta:
>         ordering = ('-timestamp',)
> ..
> class BlogForm(ModelForm):
>     body = forms.CharField(widget=TinyMCE(attrs={'cols':80, 'rows':
> 30}))
>     class Meta:
>         model = BlogPost
>         exclude = ['timestamp']
> ..
>
> The document says we can get a tinymce editor in the admin site after
> this. But nothing different shows with mine.
>
> What might be the problem?
> Is it because the wrong MEDIA_URL setting? Or I've missed something
> when installing or using?
>
> Thank you.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---