Creating an object with a FileField programmatically

2009-04-14 Thread Vincent Foley

Hello,

I want to be able to add files inside a model to test that model.
However, I'm unable to find in the documentation any mention on how to
do so.  I asked on IRC and somebody suggested the following:

from django.core.files import File
from myproject.myapp.models import MyModel
fd = open('/path/to/file')
f = File(fd)
obj = MyModel.objects.create(file_field=f)
f.close()
fd.close()


However, when I try to access obj, I get the following exception:
SuspiciousOperation: Attempted access to '/path/to/file' denied.

Is it how one is supposed to "attach" file into a model?  If so, what
could be causing my problem?

Thanks,

Vincent

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



What happened to the template engine in SVN?

2008-03-26 Thread Vincent Foley

Hello,

I have been looking at the Jinja templating engine lately to be used
in our web sites.  Their web site claims that it is in average three
times faster than Django's templating engine.   I decided to see that
for myself by designing a few, simple test cases.  The biggest
surprise came not from the fact that Jinja was faster, but how much
slower the Django SVN template engine was compared to the Django 0.96
engine.

I have posted the result as an Excel chart here:
http://www.flickr.com/photos/[EMAIL PROTECTED]/2363195045/

Could anyone tell me if they have similar experiences with the latest
Django builds?

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



ManyToMany fields in database lookups

2008-03-04 Thread Vincent Foley

Hello,

I have a curious problem with a complex filter in 0.96:

Merchant.objects.filter(Q(categories_fr__name__icontains=s) |
Q(categories_en__name__icontains=s))

this returns an empty queryset even when 's' is in categories_fr.
Changing categories_fr__name with an attribute directly in the object
has the same effect.  It seems that a ManyToMany field with no
elements nullifies the entire query.

Is this a bug, or am I misunderstanding something?

Thank you,

Vincent.

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



Re: Float Field not displaying the two zeros at the end of a price

2007-08-19 Thread Vincent Foley

{{ price|floatformat:2 }}

On Aug 19, 4:44 pm, Greg <[EMAIL PROTECTED]> wrote:
> I have a FloatField called price that stores the price of different
> elements.  When the price is 19.99, 19.79, 19.01 etc... everything is
> displayed correctly.  However, when I have a price of 19.00.  The
> price when viewed in a browser is just 19.  Is there anyway that I can
> have it display the two zeros so that it is displayed as 19.00?
>
> Thanks


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



Generalizing media files URLs

2007-08-14 Thread Vincent Foley

Hello,

My coworker and I have a sizable Django project called Gestio.  We're
pretty much done writing it, so now we're making sure that it'll work
without hitches wherever we may install it.  Thanks to the {% url %}
tag, we can choose to place the application under /, /gestio, /webapps/
gestio or whatever, the URLs are dynamically resolved.  The same
cannot be said for media files however.

We are trying to come up with a general and simple way to refer to
static files, but so far, we haven't come up with anything we like.
Here are some things we considered:

1. Writing our own {% media_file "images/foo.png" %} tag.  The problem
is that tags are not embeddable in other tags, so we couldn't use some
of our other tags (e.g.: {% icon {% media_file "images/foo.png" %} %})

2. Using {% url %}.  Same problem as above, but with the added down-
side that the tags code would be even longer.

3. Concatenating MEDIA_URL with the image file (e.g.:
{{ MEDIA_URL }}images/foo.png)  This is very ugly IMHO, because the
two parts of the URL are not visually "connected".  If braces are
involved, I'd rather have all my information inside rather than a
little inside and a little outside.

4. Using a filter such as {{ "images/foo.png"|media_file }}, but this
is pretty ugly.  It would however work in tags and keep everything in
braces.  This is currently the best solution I can think of.

If anyone has other ideas or experience with this particular problem,
please share!

Thanks,

Vincent.


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



Re: Multilingual site best practices

2007-08-10 Thread Vincent Foley

There's django-multilingual for that.

On Aug 10, 1:05 pm, Grupo Django <[EMAIL PROTECTED]> wrote:
> Vincent Foley ha escrito:
>
>
>
> > Hello,
>
> > I work for a company who develops web sites and web applications for
> > clients in Quebec.  People in Quebec mainly speak french, but there
> > are english speaking people too.  Most sites we make eventually want
> > to have a french and english version with french being the "main"
> > version.
>
> > I would like to know if anyone could share best practices for
> > multilingual sites.  I also have some questions:
>
> > 1. In the {% trans %} and {% blocktrans %} tags, should I include the
> > full text, or just a quick description and enter the full text in
> > the .po files?
>
> > 2. As I said, french is the main language in Quebec, so if I write a
> > site in french and am later asked to translate it, will the accented
> > characters cause a problem if they're used in the msgid of the .po
> > files?
>
> > 3. It seems the server always has to be restarted after the .po files
> > have been compiled.  Is that so?  If I don't have root access to the
> > server to restart Apache, is there a way I can have the new
> > definitions appear on the site?
>
> > Thanks for the input,
>
> > Vincent.
>
> I'd like to extend this questions.
> 4. Best practice to use a multilingual database. i.e. News in English
> and French from an app. I need it for a project. I'll write some docs
> about it when I get it to work, if I get it ;-) IMHO, multilingual in
> the interface but monolingual in database, is not very useful.
> Thanks,


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



Re: Presentations about Django?

2007-08-10 Thread Vincent Foley

Has your "Django Master Class" at OSCON 07 been taped?

Vincent

On Aug 10, 11:12 am, "Jacob Kaplan-Moss" <[EMAIL PROTECTED]>
wrote:
> On 8/10/07, Brian Rosner <[EMAIL PROTECTED]> wrote:
>
> > I saw the video of you presenting Django to Google at one of their Tech
> > Talks and I am not sure if I read/heard this somewhere, but is that
> > presentation freely available under the Creative Commons license or
> > something?
>
> It's athttp://video.google.com/videoplay?docid=-70449010942275062. I
> don't think the video itself is CC licensed, but as far as I'm
> concerned, anyone who wants to use the content in their own Django
> talks can certainly do so.
>
> The slides themselves are 
> athttp://toys.jacobian.org/presentations/2006/baypiggies/, btw, and a
> similar offer applies to them.
>
> Jacob


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



Multilingual site best practices

2007-08-10 Thread Vincent Foley

Hello,

I work for a company who develops web sites and web applications for
clients in Quebec.  People in Quebec mainly speak french, but there
are english speaking people too.  Most sites we make eventually want
to have a french and english version with french being the "main"
version.

I would like to know if anyone could share best practices for
multilingual sites.  I also have some questions:

1. In the {% trans %} and {% blocktrans %} tags, should I include the
full text, or just a quick description and enter the full text in
the .po files?

2. As I said, french is the main language in Quebec, so if I write a
site in french and am later asked to translate it, will the accented
characters cause a problem if they're used in the msgid of the .po
files?

3. It seems the server always has to be restarted after the .po files
have been compiled.  Is that so?  If I don't have root access to the
server to restart Apache, is there a way I can have the new
definitions appear on the site?

Thanks for the input,

Vincent.


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



SQLite + float vs MySQL + Decimal

2007-08-09 Thread Vincent Foley

Hello,

I found a curious problem in my application when I put it into
production this week: when a models.FloatField is "extracted" from the
database, its type changes depending on the database.  With SQLite in
development, I got back floats, while on MySQL in production I have
decimals.  As mentionned in other posts, decimals are not serializable
in JSON.

We are using Django 0.96 (and have no intention to use the Subversion
branch.)  Is it possible to fix the problem without applying a patch?
I don't have root access to the production environment, so I can't
apply patches.

Vincent.


>>> # Development environment w/ SQLite
>>> from gestio.inventory.models import *
>>> import django
>>> type(Item.objects.all()[0].loss)

>>> django.VERSION
(0, 96, None)
>>>

>>> # Production environment w/ PostgreSQL
>>> from gestio.inventory.models import *
>>> import django
>>> type(Item.objects.all()[0].loss)

>>> django.VERSION
(0, 96, None)
>>>


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



Re: Will Django.core.validators remain stable

2007-08-08 Thread Vincent Foley

Use validators in newforms.

class MyForm(newforms.Form):
secret_phrase = newforms.CharField(label='Secret phrase',
required=True)

def clean_secret_phrase(self):
if self.cleaned_data.get('secret_phrase') == 'xyzzy':
return True
else:
raise newforms.ValidationError(u'This is not the secret
phrase.')

On Aug 8, 8:14 am, Ramdas S <[EMAIL PROTECTED]> wrote:
> It is clear that old forms and manipulators will be replaced with new
> forms. But what about Django.core.validators. Will that too go off? If
> so, what do we use?


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



Re: Object list generic view + list

2007-07-12 Thread Vincent Foley

My problem is that I need to sort on a field in a another table.  I
found a workaround:

File.objects.select_related().filter(...).order_by('app_table.column')

It works for me because the foreign key cannot be NULL.

Vincent.

On Jul 11, 6:27 pm, Drasty <[EMAIL PROTECTED]> wrote:
> Have you tried using the http://www.djangoproject.com/
> documentation/db-api/#order-by-fields">order_by method on your
> queries?
>
> Even though it may get cumbersome, you could also add something along
> these lines to your url.py file for each specific query you might want
> to call:
>
> def some_list():
>  return Model.objects.all().order_by('some_field')


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



Re: Hard-coded sting in IFEQUAL

2007-07-10 Thread Vincent Foley

It works fine with me:

>>> from django.template import Template, Context

>>> t = Template('''{% ifequal s "Some Thing" %}Equal{% else %}Not equal{% 
>>> endifequal %}''')

>>> t.render(Context({'s': 'foo'}))
'Not equal'

>>> t.render(Context({'s': 'Some Thing'}))
'Equal'

What version of Django are you using?

Vincent


On Jul 10, 6:58 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
> I don't see why this {% ifequal theclass "Some Thing"  %} throws a
> TemplateSyntaxError  "  'ifequal' takes two arguments " while this  {%
> ifequal theclass "SomeThing"  %}  does not?
>
> Any clarity would be welcomed.
>
> Best


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



Re: Developing without tempplates

2007-06-18 Thread Vincent Foley

There's more than one way to do it (with apologies if you don't like
Perl).  One thing I like to use is IPython which allows you to start a
Python interpreter from any point in your code with the entire
context.
So to test a function, you could add the following lines at the bottom
of
the function body:

from IPython.Shell import IPShellEmbed
IPShellEmbed()()

When this point is reached, you will have a complete interactive
Python
interpreter to play around with your variables.

Another way would be to use the pprint module (standard in Python) to
display only the variables you want.

On Jun 18, 1:04 pm, shabda <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I am prototyping an app. Since I am just prtotyping I do not want to
> write templates yet. SO is there some way wherein all my variables in
> the view method get out put to the screen, so that I can debug them?


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