admin sorting in ManyToMany fields

2008-12-23 Thread Aaron Lee
Hi I have a ManyToMany field names in my class and I would like to show the
names in sorted order (according to 'name') in the admin interface when I
edit a Person. Right now it's showing by the pk order of Name. What's the
right way to override this order? Thanks
class Name(models.Model):
  name = models.CharField()

class Person(models.Model):
  code = models.CharField()
  names = models.ManyToManyField(Name)

class PersonAdmin(admin.ModelAdmin):
  list_display = ('code',)
  ordering = ('code',)

admin.site.register(Person, PersonAdmin)

-Aaron

--~--~-~--~~~---~--~~
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: Serializing QuerySets and Python objects best practices

2008-12-23 Thread Jeff Anderson
vernon wrote:
> Hi,
>
> I'm trying to do something fairly simple (and doable), but I was
> wondering if there was a "best practices" approach. I'm developing a
> client-heavy app, and I'd like to return something like this to my
> JavaScript:
>
> {"posts": Post.objects.all(), "comments": Comment.objects.all()}
>
> Right now, I'm just running serializer.serialize on each of the query
> sets and constructing the JSON string myself, but I have more
> complicated use case where that becomes messy.
>   
I believe there is a python json module. I know that Django makes use of
it for importing/exporting database fixtures. It is bundled with django
at: django.utils.simplejson. I'd start there, and poke around in the
Django code for more examples. I'm no expert here, this is just where
I'd start looking.

Happy coding!


Jeff Anderson



signature.asc
Description: OpenPGP digital signature


Serializing QuerySets and Python objects best practices

2008-12-23 Thread vernon

Hi,

I'm trying to do something fairly simple (and doable), but I was
wondering if there was a "best practices" approach. I'm developing a
client-heavy app, and I'd like to return something like this to my
JavaScript:

{"posts": Post.objects.all(), "comments": Comment.objects.all()}

Right now, I'm just running serializer.serialize on each of the query
sets and constructing the JSON string myself, but I have more
complicated use case where that becomes messy.

Is there a clean way to do this?

Best,
Vernon
--~--~-~--~~~---~--~~
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: "Building you first Django app, Part 1" example not working

2008-12-23 Thread Chris

Thanks :-)

On Dec 22, 4:01 am, leveille  wrote:
> You're 14.  You recognize that you're having a problem and you post to
> the Django group for help.  You're not stupid at all.  I would say
> you're very intelligent!
>
> On Dec 21, 2:43 pm, Chris  wrote:
>
> > Oh shit, that's awesome! Thanks! I thought it had already created the
> > DB and wanted me to fill in that info... I'm so stupid sometimes.
> > Thanks a bunch mrtot...
>
> > On Dec 21, 3:50 am, mrtot  wrote:
>
> > > Hi Chris,
>
> > > maybe it's the best to just do what the error message suggest:
>
> > > "Please fill out DATABASE_NAME in the settings module before using the
> > > database. "
>
> > > Put in something like '/home/chris/projects/django-tutorial/db/db.db'
>
> > > You can create your own name. Django just wants to know where it
> > > should store the database.
> > > No need to install MySQL for your local sandboxes :)
>
> > > Greets,
> > > Martin
>
> > > On 21 Dez., 12:40, Chris  wrote:
>
> > > > Okay... I'm on part two of the tut now and I am attemping to use
> > > > Python's built-in SQLite Database just to get a feel for Django.
> > > > However, the tutorial confuses me in part one when it defines
> > > > DATABASE_NAME, "The name of your database. If you're using SQLite, the
> > > > database will be a file on your computer; in that case, DATABASE_NAME
> > > > should be the full absolute path, including filename, of that file. If
> > > > the file doesn't exist, it will automatically be created when you
> > > > synchronize the database for the first time (see below)."
>
> > > > It say, "see below," but all that is below is the reference, "If
> > > > you're using SQLite, you don't need to create anything beforehand -
> > > > the database file will be created automatically when it is needed."
> > > > which is wonderful, but I recieve the error shown below when I try to
> > > > run the admin interface, as I haven't specified the DATABASE_NAME. How
> > > > can I if I don't know where it was created?
>
> > > > Anyway, here's my error. Running almost any other command at the promt
> > > > gives me an error ending with "ImproperlyConfigured: Please fill out
> > > > DATABASE_NAME in the settings module before using the database.", but
> > > > the error shown when I try to run the admin is included below...
>
> > > > ---
> > > >  
>
> > > > Traceback (most recent call last):
>
> > > >   File "/Library/Python/2.5/site-packages/django/core/servers/
> > > > basehttp.py", line 278, in run
> > > >     self.result = application(self.environ, self.start_response)
>
> > > >   File "/Library/Python/2.5/site-packages/django/core/servers/
> > > > basehttp.py", line 635, in __call__
> > > >     return self.application(environ, start_response)
>
> > > >   File "/Library/Python/2.5/site-packages/django/core/handlers/
> > > > wsgi.py", line 243, in __call__
> > > >     response = middleware_method(request, response)
>
> > > >   File "/Library/Python/2.5/site-packages/django/contrib/sessions/
> > > > middleware.py", line 35, in process_response
> > > >     request.session.save()
>
> > > >   File "/Library/Python/2.5/site-packages/django/contrib/sessions/
> > > > backends/db.py", line 52, in save
> > > >     session_key = self.session_key,
>
> > > >   File "/Library/Python/2.5/site-packages/django/contrib/sessions/
> > > > backends/base.py", line 152, in _get_session_key
> > > >     self._session_key = self._get_new_session_key()
>
> > > >   File "/Library/Python/2.5/site-packages/django/contrib/sessions/
> > > > backends/base.py", line 144, in _get_new_session_key
> > > >     if not self.exists(session_key):
>
> > > >   File "/Library/Python/2.5/site-packages/django/contrib/sessions/
> > > > backends/db.py", line 25, in exists
> > > >     Session.objects.get(session_key=session_key)
>
> > > >   File "/Library/Python/2.5/site-packages/django/db/models/
> > > > manager.py", line 93, in get
> > > >     return self.get_query_set().get(*args, **kwargs)
>
> > > >   File "/Library/Python/2.5/site-packages/django/db/models/query.py",
> > > > line 304, in get
> > > >     num = len(clone)
>
> > > >   File "/Library/Python/2.5/site-packages/django/db/models/query.py",
> > > > line 160, in __len__
> > > >     self._result_cache = list(self.iterator())
>
> > > >   File "/Library/Python/2.5/site-packages/django/db/models/query.py",
> > > > line 275, in iterator
> > > >     for row in self.query.results_iter():
>
> > > >   File "/Library/Python/2.5/site-packages/django/db/models/sql/
> > > > query.py", line 206, in results_iter
> > > >     for rows in self.execute_sql(MULTI):
>
> > > >   File "/Library/Python/2.5/site-packages/django/db/models/sql/
> > > > query.py", line 1733, in execute_sql
> > > >     cursor = self.connection.cursor()
>
> > > >   File 

Re: Problems when searching acute or tilde letters in a textfield under tiny_mce.js

2008-12-23 Thread Vizcayno

I want to share the solution to my problem. I appreciate the kindness
of Malcolm for the suggestions.
After some searching in tinyMCE site, I found a note that recommends
to explicitly leave
option "entities" to empty, I show you a sample:

   tinyMCE.init({
   // General options
   mode : "textareas",
   theme : "advanced",
   entities : "",
 ... etc.

It was then necessary for me to recover and inmediately save all
previous records which TextFields were under influence of TinyMCE and
that contained acute or tilde
characters.
I feel happy.
Regards.

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



Re: a clean_tarfile() for my form

2008-12-23 Thread Alan
Sorry guys, apparently I found a solution, but...
Well I swear I tried it before, but now it's working. I did this:

try:

   tarfile.open(fileobj=file)

except:

   raise forms.ValidationError(msg2)

Anyway.

Cheers,
Alan

On Tue, Dec 23, 2008 at 21:18, Alan  wrote:

> Hi,
> Thanks for the hint, however, they only applies to tar archive file (give
> by path) and not to 'file objects' as you get from "file =
> self.cleaned_data['file']" in django models.
>
> More specifically, how to make class tarfile to
> handle django.core.files.uploadedfile.InMemoryUploadedFile objects.
>
> Any help is always welcome. Thanks in advance,
> Alan
>
>
> On Tue, Dec 23, 2008 at 12:09, Paul van der Linden wrote:
>
>>
>> Hi,
>> look at the module reference at python documentation:
>> http://www.python.org/doc/2.5.2/lib/module-tarfile.html
>> You can see there an is_tarfile to check if it is a tar file, or you can
>> use TarFileCompat to check if it is a tar_gzipped file.
>> Alan wrote:
>> > Hi There,
>> >
>> > So I have a form where users can upload zip and tgz file. In my def
>> > clean_file() for class MyForm, I can clean zip files smoothly and now
>> > I am trying the same for a tgz file but missing things.
>> >
>> > First, fileobj = self.cleaned_data['file'] will return a fileobj, so I
>> > tried:
>> >
>> > tar = tarfile.open(fileobj=fileobj)
>> >
>> > but then I cannot do anything with 'tar'. I mean, tar.list() returns
>> > nothing. Even worse, my fileobj can be any thing, a 'zip' for example,
>> > and tarfile.open doesn't seem to check for that as it does if it was a
>> > file like 'myfile.tgz' or 'myfile.zip', failing to open for the former.
>> >
>> > I tried google and also StringIO, but without success. All I want is
>> > to check if the supposed tgz file is a valid tgz file as I do for a
>> > zip file.
>> >
>> > Many thanks in avance,
>> > Alan
>> >
>> > --
>> > Alan Wilter S. da Silva, D.Sc. - CCPN Research Associate
>> > Department of Biochemistry, University of Cambridge.
>> > 80 Tennis Court Road, Cambridge CB2 1GA, UK.
>> > >>http://www.bio.cam.ac.uk/~awd28 <<
>> >
>> > >
>>
>>
>> >>
>>
>
>
> --
> Alan Wilter S. da Silva, D.Sc. - CCPN Research Associate
> Department of Biochemistry, University of Cambridge.
> 80 Tennis Court Road, Cambridge CB2 1GA, UK.
> >>http://www.bio.cam.ac.uk/~awd28<<
>



-- 
Alan Wilter S. da Silva, D.Sc. - CCPN Research Associate
Department of Biochemistry, University of Cambridge.
80 Tennis Court Road, Cambridge CB2 1GA, UK.
>>http://www.bio.cam.ac.uk/~awd28<<

--~--~-~--~~~---~--~~
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: dynamically instantiate a model at run time

2008-12-23 Thread bruno desthuilliers

On 23 déc, 20:23, "dick...@gmail.com"  wrote:
> i'm trying to do some instantiation of models, based on run time
> parameters. i'm new to django/python so not sure the term, but the
> relative java term is reflection.

The term in Python is... well, it isn't. With a dynamic language, it's
just daily programming, you know ?-)

(ok, nitpicking, sorry. Please don't hold it against me - or at least
read the practical solution at the bottom before).

> for example, if i have a model, in my django models.py:
>
> class Foo(models.Model):
> name = models.CharField(max_length=20)
>
> now in some views.py code, i'm given, say some xml that defines a new
> Foo object, so i want to dynamically create a new Foo object and save
> it.  bar
>
> i've tried a few things below, but namely, what i'm trying to do is
> parse the xml, see that i need to create "Foo" and set it's name to
> bar:
>
> tag = "Foo"
> key = "name"
> value = "bar"
>
>  _temp = __import__('project.test.models', globals(), locals(),
> ['Foo'], -1)
>  createobj = getattr(_temp, tag)

This returns a class object, not an instance.

> setattr(createobj, key, value)

This sets the "name" attribute of *class* Foo to "bar".

> createobj.save()
>
> i'm getting unbound method on save,

Not surprinsing since you're calling it on a class object... An
unbound method (IOW: an instance method looked up on the class) takes
an instance as first param - you know, the (in)famous  'self'
argument ?


What is defined (using the 'def' statement) in a class statement is
_really_ a function. It only becomes a "method" (in fact just a thin
wrapper around the class, instance and function - name it, a partial
evaluation of the function) when looked up on an instance - and an
"unbound method" (same thing modulo the instance) when looked up on
the class.

IOW and to make a long story short:

instance.method(arg)
# is equivalent to
cls.method(instance, arg)
# which - if and only if "method" is defined in "cls"  (_not_
inherited)
# is equivalent to:
cls.__dict__['method'](instance, arg)

If you want to learn more about it, google for python+descriptor
+protocol. It's the same thing that powers computed attributes (aka
properties), and it's something worth learning about.


> and tried various ways to save.
> but i'm thinking it is in the class instantiation where the problem
> is.

Indeed. You didn't create a Foo instance.


Ok, now for the solution(s):

# 1/ Django's models are all loaded at startup and cached.
#To get a model by appname/model, just use:

from db.models.loading import get_model
model_class = get_model("test", tag)

# NB : at this point, "model_class" is what you named "createobj"

# 2/ once you have the class, you need an instance:

instance = model_class()

# 3/ then you can set the attribute and save the instance:

setattr(instance, key, value)
instance.save()

# ALT 1
# you can save on typing, using keyword args
# to instanciate your model:

from db.models.loading import get_model
model_class = get_model("test", tag)
instance = model_class(**{key:value})
instance.save()

# ALT2
#  and save even more typing using the
#  model's manager "create" method:

from db.models.loading import get_model
model_class = get_model("test", tag)
# create and save the instance in one step
instance = model_class.objects.create(**{key:value})


HTH.

Oh, and welcome onboard BTW - we all hope you'll enjoy the trip !-)
--~--~-~--~~~---~--~~
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: xml -> django model

2008-12-23 Thread dick...@gmail.com

thanks DR! yeah, i'm just learning python, and was fuzzy on the object
model stuff.

works perfect.



On Dec 23, 1:09 pm, Daniel Roseman 
wrote:
> On Dec 23, 8:11 pm, "dick...@gmail.com"  wrote:
>
>
>
> > i'm working on a simple concept i'm sure others have solved, but i
> > can't get it.
>
> > basically, given some  input, i parse it, find which objects to
> > create, and do it.
>
> > so with a model:
>
> > class Foo(models.Model):
> >       name = models.CharField(max_length=20)
>
> > and input xml of bar
>
> > my view would parse that xml, find the Element Request name "Foo",
> > instantiate Foo, set the "name" value to bar, and save it.
>
> > import myproject.test.models as test_models
> > createobj = getattr(test_models, "Foo")
> > setattr(createobj, "name", "bar")
> > createobj.save()
>
> > the current code there above gives me
>
> > unbound method save() must be called with Foo instance as first
> > argument (got nothing instead)
>
> > i've also tried
> > save =  getattr(createobj, "save")
> > save(createobj)
>
> > unbound method save() must be called with Foo instance as first
> > argument (got ModelBase instance instead)
>
> > i've probably gone about the whole problem all wrong, so feel feel to
> > correct this approach if it is way off base
>
> I wouldn't say you were way off base, but you haven't quite grasped
> the Python object model, nor what Django does specifically to model
> classes.
>
> By going getattr(test_models, 'Foo') you're simply getting the model
> class, not instantiating it. In Python, classes themselves are first-
> class objects, and you can pass them around and set attributes on them
> just like any object. So using setattr to set a 'name' property on the
> object does nothing more than give the class object a value for name.
>
> So the missing step is instantiation - and you can do this with your
> dynamic class variable just like any other class name, by simply
> calling it.
> obj_class = getattr(test_models, "Foo")
> createobj = obj_class()
> setattr(createobj, "name", "bar")
> createobj.save()
>
> However, having said all this, there is a much easier way using some
> Django helper models.
>
> from django.db.loader import get_model
> obj_class=get_model('test', 'Foo')
> values = {'name':'bar'}
> createobj = obj_class.objects.create(**values)
>
> The last line here is using the create method, which instantiates and
> saves an object all in one. It also uses the fact that Python allows
> you to use a dictionary to pass in keyword arguments - eg name='bar' -
> and of course dictionary keys can be strings, so could be loaded
> directly from your XML.
>
> Hope that helps,
> --
> 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
-~--~~~~--~~--~--~---



django deserialize and save new model object from xml

2008-12-23 Thread dick...@gmail.com

looking at the serialization serializers, is is possible to save "new"
instance of a model object represented in xml?

i'm getting an error:

 node is missing the 'pk' attribute, but basically, there
isn't one, because i don't want the object retrieved from the db, i
want to instantiate it from the xml, then save it?

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



Re: a clean_tarfile() for my form

2008-12-23 Thread Alan
Hi,
Thanks for the hint, however, they only applies to tar archive file (give by
path) and not to 'file objects' as you get from "file =
self.cleaned_data['file']" in django models.

More specifically, how to make class tarfile to
handle django.core.files.uploadedfile.InMemoryUploadedFile objects.

Any help is always welcome. Thanks in advance,
Alan


On Tue, Dec 23, 2008 at 12:09, Paul van der Linden  wrote:

>
> Hi,
> look at the module reference at python documentation:
> http://www.python.org/doc/2.5.2/lib/module-tarfile.html
> You can see there an is_tarfile to check if it is a tar file, or you can
> use TarFileCompat to check if it is a tar_gzipped file.
> Alan wrote:
> > Hi There,
> >
> > So I have a form where users can upload zip and tgz file. In my def
> > clean_file() for class MyForm, I can clean zip files smoothly and now
> > I am trying the same for a tgz file but missing things.
> >
> > First, fileobj = self.cleaned_data['file'] will return a fileobj, so I
> > tried:
> >
> > tar = tarfile.open(fileobj=fileobj)
> >
> > but then I cannot do anything with 'tar'. I mean, tar.list() returns
> > nothing. Even worse, my fileobj can be any thing, a 'zip' for example,
> > and tarfile.open doesn't seem to check for that as it does if it was a
> > file like 'myfile.tgz' or 'myfile.zip', failing to open for the former.
> >
> > I tried google and also StringIO, but without success. All I want is
> > to check if the supposed tgz file is a valid tgz file as I do for a
> > zip file.
> >
> > Many thanks in avance,
> > Alan
> >
> > --
> > Alan Wilter S. da Silva, D.Sc. - CCPN Research Associate
> > Department of Biochemistry, University of Cambridge.
> > 80 Tennis Court Road, Cambridge CB2 1GA, UK.
> > >>http://www.bio.cam.ac.uk/~awd28 <<
> >
> > >
>
>
> >
>


-- 
Alan Wilter S. da Silva, D.Sc. - CCPN Research Associate
Department of Biochemistry, University of Cambridge.
80 Tennis Court Road, Cambridge CB2 1GA, UK.
>>http://www.bio.cam.ac.uk/~awd28<<

--~--~-~--~~~---~--~~
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: xml -> django model

2008-12-23 Thread Daniel Roseman

On Dec 23, 8:11 pm, "dick...@gmail.com"  wrote:
> i'm working on a simple concept i'm sure others have solved, but i
> can't get it.
>
> basically, given some  input, i parse it, find which objects to
> create, and do it.
>
> so with a model:
>
> class Foo(models.Model):
>       name = models.CharField(max_length=20)
>
> and input xml of bar
>
> my view would parse that xml, find the Element Request name "Foo",
> instantiate Foo, set the "name" value to bar, and save it.
>
> import myproject.test.models as test_models
> createobj = getattr(test_models, "Foo")
> setattr(createobj, "name", "bar")
> createobj.save()
>
> the current code there above gives me
>
> unbound method save() must be called with Foo instance as first
> argument (got nothing instead)
>
> i've also tried
> save =  getattr(createobj, "save")
> save(createobj)
>
> unbound method save() must be called with Foo instance as first
> argument (got ModelBase instance instead)
>
> i've probably gone about the whole problem all wrong, so feel feel to
> correct this approach if it is way off base

I wouldn't say you were way off base, but you haven't quite grasped
the Python object model, nor what Django does specifically to model
classes.

By going getattr(test_models, 'Foo') you're simply getting the model
class, not instantiating it. In Python, classes themselves are first-
class objects, and you can pass them around and set attributes on them
just like any object. So using setattr to set a 'name' property on the
object does nothing more than give the class object a value for name.

So the missing step is instantiation - and you can do this with your
dynamic class variable just like any other class name, by simply
calling it.
obj_class = getattr(test_models, "Foo")
createobj = obj_class()
setattr(createobj, "name", "bar")
createobj.save()

However, having said all this, there is a much easier way using some
Django helper models.

from django.db.loader import get_model
obj_class=get_model('test', 'Foo')
values = {'name':'bar'}
createobj = obj_class.objects.create(**values)

The last line here is using the create method, which instantiates and
saves an object all in one. It also uses the fact that Python allows
you to use a dictionary to pass in keyword arguments - eg name='bar' -
and of course dictionary keys can be strings, so could be loaded
directly from your XML.

Hope that helps,
--
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: xml -> django model

2008-12-23 Thread dick...@gmail.com


yeah, but that's hardcoding in the "Foo" and "name" value, where they
may be dynamic. Ie, imagine the xml is today
would require the python code to instantiate a Bar(date="today")
class.


> Does this work?
>
> from myproject.test.models import Foo
> f = Foo(name="bar")
> f.save()
>
> Colin
--~--~-~--~~~---~--~~
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: xml -> django model

2008-12-23 Thread Colin Bean

On Tue, Dec 23, 2008 at 12:11 PM, dick...@gmail.com  wrote:
>
> i'm working on a simple concept i'm sure others have solved, but i
> can't get it.
>
> basically, given some  input, i parse it, find which objects to
> create, and do it.
>
> so with a model:
>
> class Foo(models.Model):
>  name = models.CharField(max_length=20)
>
> and input xml of bar
>
> my view would parse that xml, find the Element Request name "Foo",
> instantiate Foo, set the "name" value to bar, and save it.
>
> import myproject.test.models as test_models
> createobj = getattr(test_models, "Foo")
> setattr(createobj, "name", "bar")
> createobj.save()
>
> the current code there above gives me
>
> unbound method save() must be called with Foo instance as first
> argument (got nothing instead)
>
> i've also tried
> save =  getattr(createobj, "save")
> save(createobj)
>
> unbound method save() must be called with Foo instance as first
> argument (got ModelBase instance instead)
>
> i've probably gone about the whole problem all wrong, so feel feel to
> correct this approach if it is way off base
>
> >
>

Does this work?

from myproject.test.models import Foo
f = Foo(name="bar")
f.save()


Colin

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



xml -> django model

2008-12-23 Thread dick...@gmail.com

i'm working on a simple concept i'm sure others have solved, but i
can't get it.

basically, given some  input, i parse it, find which objects to
create, and do it.

so with a model:

class Foo(models.Model):
  name = models.CharField(max_length=20)

and input xml of bar

my view would parse that xml, find the Element Request name "Foo",
instantiate Foo, set the "name" value to bar, and save it.

import myproject.test.models as test_models
createobj = getattr(test_models, "Foo")
setattr(createobj, "name", "bar")
createobj.save()

the current code there above gives me

unbound method save() must be called with Foo instance as first
argument (got nothing instead)

i've also tried
save =  getattr(createobj, "save")
save(createobj)

unbound method save() must be called with Foo instance as first
argument (got ModelBase instance instead)

i've probably gone about the whole problem all wrong, so feel feel to
correct this approach if it is way off base

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



dynamically instantiate a model at run time

2008-12-23 Thread dick...@gmail.com

i'm trying to do some instantiation of models, based on run time
parameters. i'm new to django/python so not sure the term, but the
relative java term is reflection.

for example, if i have a model, in my django models.py:

class Foo(models.Model):
name = models.CharField(max_length=20)

now in some views.py code, i'm given, say some xml that defines a new
Foo object, so i want to dynamically create a new Foo object and save
it.  bar

i've tried a few things below, but namely, what i'm trying to do is
parse the xml, see that i need to create "Foo" and set it's name to
bar:

tag = "Foo"
key = "name"
value = "bar"

 _temp = __import__('project.test.models', globals(), locals(),
['Foo'], -1)
 createobj = getattr(_temp, tag)
setattr(createobj, key, value)
createobj.save()

i'm getting unbound method on save, and tried various ways to save.
but i'm thinking it is in the class instantiation where the problem
is.

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



saving unicode data in file

2008-12-23 Thread Matias Surdi

Hi, I'm trying to save on a FileField some generated data (a text file 
obtained from a template):

The relevant code is:

 out = Template(open("/path/to/template").read())
 context = Context({})
 if request.POST["name"] != "":
 name = request.POST["name"]
 else:
 name = "GeneratedDocument_%i" % obj.id
 data = out.render(context)
 obj.file.save("file",ContentFile(data))


the problem arises with ContentFile(data), if data is just a string like 
"a simple string" the everything is correct, but the actual data content 
is an unicode string, so raw binary data is saved to the resulting file 
instead of the actual text.

Simplifying, what I want is to save the output of a rendered template to 
a FileField.

Any help will be very appreciated.


Thanks a lot.


--~--~-~--~~~---~--~~
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: Problem with url tag

2008-12-23 Thread patrick91

Almost resolved :)

I tried everything to find the error and finally I did, but I don't
know how to resolve :(

the error is casued by this line in a imported script:

CITY_URL = reverse('get_city_list')

if I remove that line the project works fine, but I need that line :(

Ps. the url get_city_list is correct indeed when I call this template:

{% url get_city_list %}

i get the url without errors, also when, from a view I call this code:

print reverse('get_city_list')

in the console I could see the correct url.

PS. The file with the line:
CITY_URL = reverse('get_city_list')

is in the same directory as the urls.py with the get_city_list url

could this help?


Thanks for any reply :)
--~--~-~--~~~---~--~~
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 set defaults['empty_permitted'] = False in a BaseFormSet

2008-12-23 Thread sergioh

Hi,

I would like to find a straightforward way to get the defaults
['empty_permitted'] = False in a BaseFormSet to True, which means that
all forms in a formset should be not empty by default.

Thanks in advance,

Sergio Hinojosa
--~--~-~--~~~---~--~~
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: Customizing ModelForm fields appearance

2008-12-23 Thread sergioh

You can always add your own custom fields, by default they override
the default fields that becomes with the modelform, and there is an
optional parameter "attributes", which is used to add css class to
your fields.

On Dec 23, 9:47 am, sagi s  wrote:
> I really like the concept of generating a form from a model using
> ModelForm but would like to customize the apprearance slightly (e.g.
> size of the TextInput etc.).
>
> Any suggestion as to how to do this?
>
> I looked at the forms module code but got lost in the maze of the meta
> programming...
>
> Thanks in advance
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: MultiValueDictKeyError when accessing POST items

2008-12-23 Thread DragonSlayre

Cheers :)

Damn, I must have been a bit tired coding that up lol

Here's my working code (incase anyone else is as stupid as me):


  Login:
  Username: 
  
  Password:
  
  


On Dec 23, 4:23 pm, Malcolm Tredinnick 
wrote:
> On Mon, 2008-12-22 at 19:03 -0800, DragonSlayre wrote:
> > I've created my own form:
>
> > 
> >   Login:
> >   Username: 
> >   
> >   Password:
> >   
> >   
> > 
>
> > I am mappying /accounts/login/ to a view of mine, which is then
> > calling:
>
> > if request.method == 'POST':
> >         username = request.POST['login_username']
>
> > I have no idea why I'm getting the error - "Key 'login_username' not
> > found in ".
>
> > What am I doing wrong?
>
> login_username is the value of the id attribute on the label, not on the
> form input element. Basically, your HTML isn't correct for the type of
> form you're after. You need to identify the form input elements, rather
> than the label elements. Compare the output from a Django form to what
> you have an you should see the difference fairly quickly.
>
> Regards,
> Malcolm
--~--~-~--~~~---~--~~
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: Serving Static Pages with Dev server.

2008-12-23 Thread tom.s.macken...@gmail.com

Thanks Rajesh! it works!

On Dec 23, 10:47 am, Rajesh Dhawan  wrote:
> On Dec 23, 10:38 am, "tom.s.macken...@gmail.com"
>
>
>
>  wrote:
> > Hello,
>
> > I am having some trouble serving static files with the development
> > server. I have read the docs and various blogs out there and nothing
> > seems to work. I am going nuts over this :) I have tried tweaking the
> > values in my settings.py but I reverted them back to their defaults.
> > Below is the info for my project.
>
> > myProject/
> >     templates/
> >         appX/
> >         admin/
> >     media/
> >         appX/
> >             css/
> >             img/
> >       admin/
> >             css/
> >             img/
>
> > settings.py
> > BASE_PATH=os.path.dirname(__FILE__)
> > MEDIA_ROOT=BASE_PATH+/media
> > MEDIA_URL=/media/
> > ADMIN_MEDIA_PREFIX
>
> > In, myProject/templates/base.html I link the css as, "/media/appX/css/
> > default.css"
>
> > urls.py
>
> > (r'^site_media/(?P.*)$', 'django.views.static.serve',
> >         {'document_root': '/webapps/myProj/media' }),
>
> Your MEDIA_URL is /media/ but urls.py is hooked into /site_media/.
> Change your URL config to the following:
>
> (r'^media/(?P.*)$', 'django.views.static.serve',
>         {'document_root': '/webapps/myProj/media' }),
>
> -Rajesh D
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Slowness on a Mac with 10.5.6

2008-12-23 Thread bmclaughlin

Hello,
I am having slowness issues with my local set-up.

My system was 10.4.x when django was set up and everything was fine.

I upgraded to 1.5.6 (went from a 10.5.4 install disc to 10.5.6 via
updates). After the update my local django is very slow.
It seems to struggle with serving up the css and images. Particularly
the images.

Any ideas?

Thanks

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



Re: Dynamic age count

2008-12-23 Thread Rajesh Dhawan



On Dec 23, 9:53 am, Alfonso  wrote:
> Hi,
>
> Trying to implement a very simple template tag that will output a
> company's age.  So idea being if company was established in 1860 then
> it should output '148 years old' if my math is right ;-)
>
> this is what I've got:
>
> from django.template import *
>
> register = Library()
>
> @register.filter
> def age(comp_age):
> d = datetime.date.today()
> b = 1860
> comp_age = int(d.year - b)
> return comp_age
>
> No joy -  any ideas, must be pretty simple !?

You didn't say what "No joy" means. Did you receive an error?

You say you want to implement a simple tag but what you've implemented
above is a filter. If you did mean to implement a tag, change change
@register.filter to @register.simple_tag.

-Rajesh D

--~--~-~--~~~---~--~~
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: Customizing ModelForm fields appearance

2008-12-23 Thread Rajesh Dhawan

sagi s wrote:
> I really like the concept of generating a form from a model using
> ModelForm but would like to customize the apprearance slightly (e.g.
> size of the TextInput etc.).
>
> Any suggestion as to how to do this?

A standard way to do this is via CSS. When you render your form in
your template, add suitable class or id attributes to the fields you
want to customize. Then, define styles for those elements in your CSS
in order to customize their appearance.

-Rajesh D

--~--~-~--~~~---~--~~
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: Serving Static Pages with Dev server.

2008-12-23 Thread Rajesh Dhawan



On Dec 23, 10:38 am, "tom.s.macken...@gmail.com"
 wrote:
> Hello,
>
> I am having some trouble serving static files with the development
> server. I have read the docs and various blogs out there and nothing
> seems to work. I am going nuts over this :) I have tried tweaking the
> values in my settings.py but I reverted them back to their defaults.
> Below is the info for my project.
>
> myProject/
> templates/
> appX/
> admin/
> media/
> appX/
> css/
> img/
>   admin/
> css/
> img/
>
> settings.py
> BASE_PATH=os.path.dirname(__FILE__)
> MEDIA_ROOT=BASE_PATH+/media
> MEDIA_URL=/media/
> ADMIN_MEDIA_PREFIX
>
> In, myProject/templates/base.html I link the css as, "/media/appX/css/
> default.css"
>
> urls.py
>
> (r'^site_media/(?P.*)$', 'django.views.static.serve',
> {'document_root': '/webapps/myProj/media' }),

Your MEDIA_URL is /media/ but urls.py is hooked into /site_media/.
Change your URL config to the following:

(r'^media/(?P.*)$', 'django.views.static.serve',
{'document_root': '/webapps/myProj/media' }),

-Rajesh D
--~--~-~--~~~---~--~~
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: Serving Static Pages with Dev server.

2008-12-23 Thread tom.s.macken...@gmail.com

Sorry...

ADMIN_MEDIA_PREFIX=/media/admin/

On Dec 23, 9:38 am, "tom.s.macken...@gmail.com"
 wrote:
> Hello,
>
> I am having some trouble serving static files with the development
> server. I have read the docs and various blogs out there and nothing
> seems to work. I am going nuts over this :) I have tried tweaking the
> values in my settings.py but I reverted them back to their defaults.
> Below is the info for my project.
>
> myProject/
>     templates/
>         appX/
>         admin/
>     media/
>         appX/
>             css/
>             img/
>       admin/
>             css/
>             img/
>
> settings.py
> BASE_PATH=os.path.dirname(__FILE__)
> MEDIA_ROOT=BASE_PATH+/media
> MEDIA_URL=/media/
> ADMIN_MEDIA_PREFIX
>
> In, myProject/templates/base.html I link the css as, "/media/appX/css/
> default.css"
>
> urls.py
>
> (r'^site_media/(?P.*)$', 'django.views.static.serve',
>         {'document_root': '/webapps/myProj/media' }),
>
> Any help is greatly 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
-~--~~~~--~~--~--~---



Serving Static Pages with Dev server.

2008-12-23 Thread tom.s.macken...@gmail.com

Hello,

I am having some trouble serving static files with the development
server. I have read the docs and various blogs out there and nothing
seems to work. I am going nuts over this :) I have tried tweaking the
values in my settings.py but I reverted them back to their defaults.
Below is the info for my project.

myProject/
templates/
appX/
admin/
media/
appX/
css/
img/
  admin/
css/
img/

settings.py
BASE_PATH=os.path.dirname(__FILE__)
MEDIA_ROOT=BASE_PATH+/media
MEDIA_URL=/media/
ADMIN_MEDIA_PREFIX

In, myProject/templates/base.html I link the css as, "/media/appX/css/
default.css"

urls.py

(r'^site_media/(?P.*)$', 'django.views.static.serve',
{'document_root': '/webapps/myProj/media' }),

Any help is greatly 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: order_with_respect_to fail any workaround ?

2008-12-23 Thread Thierry Stiegler

I answer django developpers (http://groups.google.com/group/django-
developers/t/280bca5001faca07) so wait and see.

On 6 déc, 09:34, Thierry Stiegler  wrote:
> Hello,
>
> I got some errors by using the Meta optionsorder_with_respect_to:
> 
> class Category(PublicationBase, LocalisationBase):
>     ITEM_PER_PAGE = 12
>     name = models.CharField(max_length=255)
>     pictogram = models.ImageField(upload_to="categories", blank=True)
>     old_id = models.PositiveIntegerField(blank=True)
>     parent = models.ForeignKey("Category", blank=True, null=True)
>
>     class Meta:
>         ordering = ['name']
>        order_with_respect_to= 'parent'
>
>     def __unicode__(self):
>         return self.name
> 
>
> An I got this error :
> 
> Validating models...
> Unhandled exception in thread started by  0x010ABBF0>
> Traceback (most recent call last):
>   File "C:\Python25\django-trunk\django\core\management\commands
> \runserver.py", line 48, in inner_run
>     self.validate(display_num_errors=True)
>   File "C:\Python25\django-trunk\django\core\management\base.py", line
> 249, in validate
>     num_errors = get_validation_errors(s, app)
>   File "C:\Python25\django-trunk\django\core\management
> \validation.py", line 28, in get_validation_errors
>     for (app_name, error) in get_app_errors().items():
>   File "C:\Python25\django-trunk\django\db\models\loading.py", line
> 128, in get_app_errors
>     self._populate()
>   File "C:\Python25\django-trunk\django\db\models\loading.py", line
> 57, in _populate
>     self.load_app(app_name, True)
>   File "C:\Python25\django-trunk\django\db\models\loading.py", line
> 72, in load_app
>     mod = __import__(app_name, {}, {}, ['models'])
>   File "C:\www\zebest-3000.com\trunk\zebest3000\..\apps\messages
> \models.py", line 113, in 
>     notification = get_app('notification')
>   File "C:\Python25\django-trunk\django\db\models\loading.py", line
> 111, in get_app
>     self._populate()
>   File "C:\Python25\django-trunk\django\db\models\loading.py", line
> 57, in _populate
>     self.load_app(app_name, True)
>   File "C:\Python25\django-trunk\django\db\models\loading.py", line
> 72, in load_app
>     mod = __import__(app_name, {}, {}, ['models'])
>   File "C:\www\zebest-3000.com\trunk\zebest3000\..\apps\portail
> \models.py", line 50, in 
>     class Category(PublicationBase, LocalisationBase):
>   File "C:\Python25\django-trunk\django\db\models\base.py", line 153,
> in __new__
>     new_class._prepare()
>   File "C:\Python25\django-trunk\django\db\models\base.py", line 178,
> in _prepare
>     setattr(opts.order_with_respect_to.rel.to, 'get_%s_order' %
> cls.__name__.lower(), curry(method_get_order, cls))
> AttributeError: 'str' object has no attribute 'get_category_order'
> 
>
> I found this ticket (http://code.djangoproject.com/ticket/2740), but I
> don"t want to patch django.AnyIdea for aworkaround?
--~--~-~--~~~---~--~~
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: problem with adding foreign key to table

2008-12-23 Thread Ana

Thank you all for your response.  I will try the encoding resolution.

Ana

On Dec 23, 1:29 am, SteveMc  wrote:
> The other reply was correct; it's a character encoding issue. Take a
> look athttp://www.postgresql.org/docs/8.3/static/multibyte.html- I
> suspect you will need to run initdb -E UTF8 to set the default
> character set for the postgres install. Alternatively that page
> instructs how to create a specific database with a character set.
> Running
>  $ psql -l
> will tell you what character sets your databases are using.
>
> On Dec 22, 9:14 pm, Ana  wrote:
>
> > Hello,
>
> > I migrated my MySQL tables to Postgres.  Generally, the migration was
> > fine with one exception.  I have a table researchproj that included
> > two foreign keys (institution_id and contact_id).  I received the
> > following error:
>
> > Caught an exception while rendering: ('ascii', u'Jorge Gir\xf3n', 9,
> > 10, 'ordinal not in range(128)')
>
> > when I tried to access the researchproj table through admin.  If I
> > delete the column contact_id, the error goes away.  If I add the
> > column back onto the table the error returns.  All the tables contain
> > data, although I created a test researchproj table with just one
> > tuple.  I've added, deleted and done acrobats trying to get the admin
> > to accept the column contact_id in the researchproj table.  I have
> > checked the sequence numbers for all tables, and also any referential
> > integrity issues with all the tables.  Can someone help?
>
> > Thanks,
>
> > Ana
--~--~-~--~~~---~--~~
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: Complete layout (template) switching.

2008-12-23 Thread bruno desthuilliers

On 23 déc, 11:57, Kura  wrote:
> Thanks. Sadly though I don't want it to extend base.html, I want it to
> replace base.html but only under certain circumstances.

Either I don't get you or you didn't get what I said...

> As an example, base.html will have the current structure:
>
> __header__
>   | |
> nav | content | content
>   | |
> __footer___
>
> Where as base2.html will have a different structure:
>
> __header__
>   content
> --
>   content
> --
> __footer___
>
> So as you can tell the first variation of base.html will have a column
> based layout where as the second variation will have row based
> content.

In this case, you want your Page / Section / whatever template to
extend either base.html or base2.html, right ? If so, what's wrong
with my solution ? Else, please bear with me and try to explain a bit
more clearly...



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



Dynamic age count

2008-12-23 Thread Alfonso

Hi,

Trying to implement a very simple template tag that will output a
company's age.  So idea being if company was established in 1860 then
it should output '148 years old' if my math is right ;-)

this is what I've got:

from django.template import *

register = Library()

@register.filter
def age(comp_age):
d = datetime.date.today()
b = 1860
comp_age = int(d.year - b)
return comp_age

No joy -  any ideas, must be pretty simple !?

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: dynamic mod wsgi

2008-12-23 Thread Ben Eliott

I just saw your message below after sending the vhost.

I don't think i'd mind whether it's separate processes or one really  
fat one. I think perhaps separate processes with a quite a short  
inactivity timeout might work quite well? I'd rather keep the overall  
footprint as  small as feasible, especially since i'm only using a  
memory starved VPS for the time being. But this is for alpha-testing  
purposes really so not crucial concern.

I don't know the answer really to your questions, but perhaps if i can  
give you some background:  I'm looking to set up/demonstrate a django  
app for users according to a set of specific settings they choose.  
Subdomains are to identify the client accounts where they can see  
their django app . The subdomain would be temporary for demonstration/ 
set-up purposes and a client account  would get moved across to a  
dedicated domain name in due course.

Based on users entry in a form i can write/re-write python settings,  
and mod_wsgi allows me to programmatically restart a site - this is  
what led me to think it might be possible. The crunch is obviously  
that i want it to create these instances on the fly, so that the user  
completes the form and *bam* their subdomain is there complete with  
their customized django app.









On 23 Dec 2008, at 01:13, Graham Dumpleton wrote:

>
> Have some further questions about what you want to do.
>
> Do you want a separate daemon process for each distinct Django site,
> or are you happy with one really fat process which contains each
> Django site in a separate sub interpreter of that process?
>
> How much memory does each Django site instance take up?
>
> How many different site instances would you have?
>
> Are all the site instances distinguishable by server name alone?
>
> Graham
>
> On Dec 23, 9:00 am, Graham Dumpleton 
> wrote:
>> On Dec 22, 9:44 pm, Ben Eliott  wrote:
>>
>>> Hi Graham,
>>> I've finally managed to get back to the wildcard subdomains &  
>>> mod_wsgi
>>> today. Unfortunately the discussion thread you mentioned has
>>> disappeared and after a few hours i still seem to be doing a good  
>>> job
>>> of getting nowhere.
>>
>> I can still access thread with no problems.
>>
>>> Although you mentioned using mod_rewrite to get hold of the url
>>> variable, it looks like the %{SERVER} variable in mod_wsgi might  
>>> take
>>> care of this already?
>>
>>> My main issue seems to be to accessing the %{SERVER} (or relevant
>>> mod_rewrite) variable in the .wsgi script, to specify a particular
>>> settings file.
>>
>>> Within a VirtualHost i have:
>>> WSGIApplicationGroup %{SERVER}
>>> WSGIDaemonProcess %{SERVER} ...threads etc
>>> WSGIProcessGroup %{SERVER}
>>
>> The %{SERVER} value is only magic when used with WSGIApplicationGroup
>> directive.
>>
>>> So this is probably hoplessly wrong also, but if you can give some
>>> further pointers that would be most kind.
>>
>> Can you post a more complete example of your Apache configuration
>> showing what you are trying to achieve.
>>
>> Sorry I didn't get back to you last time, it was a hectic few weeks.
>> Things have settled down somewhat now, so I'll go back over your
>> original post and work out again what it is you were trying to do.
>>
>> Graham
>>
>>> Thanks and Regards,
>>> Ben
>>
>>> On 9 Dec 2008, at 10:18, Graham Dumpleton wrote:
>>
 On Dec 9, 8:05 pm, Ben Eliott  wrote:
> Graham,
> Thank you for coming back personally to such a lowly wsgi  
> question! I
> started reading your email and thinking the answer was 'no', then
> ended up thinking 'definitely maybe'. I'll keep an eye out in case
> you
> post more, otherwise i'll follow those links and your directions  
> and
> hope to report back with some progress.
>>
 I'll definitely try and say more later when get a chance.
>>
 Just do be aware of one thing. By using a single WSGI script file  
 for
 multiple sites, you loose the ability with mod_wsgi daemon mode to
 touch the WSGI script file and cause a single site to be  
 reloaded. One
 would normally use this as a way of reloading a single site without
 the need to restart the whole of Apache. When sharing the single  
 WSGI
 script file across sites, touching the WSGI script file will  
 restart
 all sites using that WSGI script file. If they share the code  
 this may
 actually be want you want, so not a problem, but worth mentioning.
>>
 In this arrangement, if you did want to reload one site, for  
 example
 because you change its settings file, you would need to use 'ps' to
 identify process(es) in that daemon process group, based on what
 display-name option was set to, and send all those processes in  
 that
 daemon process group a SIGINT using the 'kill' command.  
 Alternatively,
 you would need to setup a background thread which 

Re: Django site - CSS doesn't render in Safari/Webkit

2008-12-23 Thread Alfonso

OK tracked it down - appears Safari doesn't sit well with a
master .css file and @import url(blah.css);  I guess that's because of
the way I'm serving up static files.

Direct " wrote:
> Hey,
>
> I'm getting a weird issue in Django with my css and Safari - displays
> great in all browsers except for Safari.  Happens in two different
> django installations on two separate servers so clearly I'm doing
> something wrong.  CSS files are accessible directly via URL in both
> cases... odd
>
> Apart from the fact I'm prob missing something obvious in my code,
> anyone else come across that?!
>
> Thanks
>
> Al
--~--~-~--~~~---~--~~
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 site - CSS doesn't render in Safari/Webkit

2008-12-23 Thread Alfonso

Hey,

I'm getting a weird issue in Django with my css and Safari - displays
great in all browsers except for Safari.  Happens in two different
django installations on two separate servers so clearly I'm doing
something wrong.  CSS files are accessible directly via URL in both
cases... odd

Apart from the fact I'm prob missing something obvious in my code,
anyone else come across that?!

Thanks

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



Customizing ModelForm fields appearance

2008-12-23 Thread sagi s


I really like the concept of generating a form from a model using
ModelForm but would like to customize the apprearance slightly (e.g.
size of the TextInput etc.).

Any suggestion as to how to do this?

I looked at the forms module code but got lost in the maze of the meta
programming...

Thanks in advance

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

2008-12-23 Thread Ben Eliott

Strange, that thread is down for me. Maybe it has something to do with  
cacheing in a different locale...

Anyhow, the idea is to create a new django instance and point to  
different settings.py files  for different wildcard subdomains.  here  
is current Vhost:


ServerAlias *.stayunstuck.co.uk
RewriteEngine On
RewriteCond %{HTTP_HOST} ^([^.]+)\.stayunstuck\.co\.uk$ [NC]
RewriteRule . - [E=subdomain:%1]

WSGIDaemonProcess test  user=ben group=ben threads=10 processes=1
WSGIProcessGroup %{ENV:subdomain}
WSGIScriptAlias / /home/ben/mod_wsgi/django.wsgi


WSGIApplicationGroup %{ENV:subdomain}
Order deny,allow
Allow from all



The rewrite is assigning the ENV value correctly but  the  
WSGIDaemonProcess has a fixed name. So it  works for a subdomain  
'test', but then fails for anything else.
I'm also not getting how to access the ENV value in the wsgi script to  
specify a different settings file.




On 22 Dec 2008, at 22:00, Graham Dumpleton wrote:

>
>
>
> On Dec 22, 9:44 pm, Ben Eliott  wrote:
>> Hi Graham,
>> I've finally managed to get back to the wildcard subdomains &  
>> mod_wsgi
>> today. Unfortunately the discussion thread you mentioned has
>> disappeared and after a few hours i still seem to be doing a good job
>> of getting nowhere.
>
> I can still access thread with no problems.
>
>> Although you mentioned using mod_rewrite to get hold of the url
>> variable, it looks like the %{SERVER} variable in mod_wsgi might take
>> care of this already?
>>
>> My main issue seems to be to accessing the %{SERVER} (or relevant
>> mod_rewrite) variable in the .wsgi script, to specify a particular
>> settings file.
>>
>> Within a VirtualHost i have:
>> WSGIApplicationGroup %{SERVER}
>> WSGIDaemonProcess %{SERVER} ...threads etc
>> WSGIProcessGroup %{SERVER}
>
> The %{SERVER} value is only magic when used with WSGIApplicationGroup
> directive.
>
>> So this is probably hoplessly wrong also, but if you can give some
>> further pointers that would be most kind.
>
> Can you post a more complete example of your Apache configuration
> showing what you are trying to achieve.
>
> Sorry I didn't get back to you last time, it was a hectic few weeks.
> Things have settled down somewhat now, so I'll go back over your
> original post and work out again what it is you were trying to do.
>
> Graham
>
>> Thanks and Regards,
>> Ben
>>
>> On 9 Dec 2008, at 10:18, Graham Dumpleton wrote:
>>
>>
>>
>>> On Dec 9, 8:05 pm, Ben Eliott  wrote:
 Graham,
 Thank you for coming back personally to such a lowly wsgi  
 question! I
 started reading your email and thinking the answer was 'no', then
 ended up thinking 'definitely maybe'. I'll keep an eye out in case
 you
 post more, otherwise i'll follow those links and your directions  
 and
 hope to report back with some progress.
>>
>>> I'll definitely try and say more later when get a chance.
>>
>>> Just do be aware of one thing. By using a single WSGI script file  
>>> for
>>> multiple sites, you loose the ability with mod_wsgi daemon mode to
>>> touch the WSGI script file and cause a single site to be reloaded.  
>>> One
>>> would normally use this as a way of reloading a single site without
>>> the need to restart the whole of Apache. When sharing the single  
>>> WSGI
>>> script file across sites, touching the WSGI script file will restart
>>> all sites using that WSGI script file. If they share the code this  
>>> may
>>> actually be want you want, so not a problem, but worth mentioning.
>>
>>> In this arrangement, if you did want to reload one site, for example
>>> because you change its settings file, you would need to use 'ps' to
>>> identify process(es) in that daemon process group, based on what
>>> display-name option was set to, and send all those processes in that
>>> daemon process group a SIGINT using the 'kill' command.  
>>> Alternatively,
>>> you would need to setup a background thread which monitored  
>>> something
>>> like the distinct settings file for each site and have the process
>>> itself send a SIGINT to itself. This would be a variation on
>>> background reloader described in:
>>
>>>  http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode#Restarting_ 
>>> ...
>>
>>> More later.
>>
>>> Graham
>>
 Thanks and Regards,
 Ben
>>
 On 9 Dec 2008, at 08:23, Graham Dumpleton wrote:
>>
> On Dec 9, 6:53 pm, "ben.dja...@googlemail.com"
>  wrote:
>> Hi, I'm converting to the excellent mod_wsgi and wondering if  
>> it's
>> possible to make a single httpd virtual host/wsgi file to manage
>> wildcard subdomains.
>>
>> Basically I have an app where i'm creating a new instance for  
>> each
>> client and using subdomains. So client1.example.com and
>> client2.example.com both point to the same app, but their own
>> settings.py/django instance.
>>
>> So far so fine.  I've been happily converting to 

Re: Subprocess module in Python CGI

2008-12-23 Thread Kenneth Gonsalves

On Monday 22 Dec 2008 4:21:31 pm Anurag wrote:
> comd = [\
>         "tar -xf x.tar.gz", \

nothing to do with python:
[law...@localhost programs]$ tar -xf x.tar.gz
tar: x.tar.gz: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now

btw, there is no need to put '\' when putting a list in more than one line. In 
general, in python, you can put anything within (), [] or {} on more than one 
line without any escaping.

-- 
regards
KG
http://lawgon.livejournal.com

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



Re: Model with CharField primary key, force_update=True to prevent saving other object

2008-12-23 Thread Jeff Kowalczyk

Jeff Kowalczyk wrote:
> I'm working with a model using a CharField primary key, ...
> I need to prevent other objects from being created/updated
> if save() is called with a changed pk value.
>
> class Widget(models.Model):
>     identifier = models.CharField(primary_key=True, max_length=10)

I worked on handling this with model save() overrides, or pre_save()
signal handlers. I haven't tried subclassing the CharField pk to add a
pre_save() override, but that's next on my agenda.

Using the admin change_form and a breakpoint, I inspected the self
Widget in Widget.save(self) or the instance kwarg pre_save() in ipdb.
The data is already updated at that point, which makes sense.

However, I could not find any private or _meta attributes which
carried the old data forward for comparison to the new data with the
django save machinery. Is the request-like old data available anywhere
during Model save ?

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: a clean_tarfile() for my form

2008-12-23 Thread Paul van der Linden

Hi,
look at the module reference at python documentation:
http://www.python.org/doc/2.5.2/lib/module-tarfile.html
You can see there an is_tarfile to check if it is a tar file, or you can
use TarFileCompat to check if it is a tar_gzipped file.
Alan wrote:
> Hi There,
>
> So I have a form where users can upload zip and tgz file. In my def
> clean_file() for class MyForm, I can clean zip files smoothly and now
> I am trying the same for a tgz file but missing things.
>
> First, fileobj = self.cleaned_data['file'] will return a fileobj, so I
> tried:
>
> tar = tarfile.open(fileobj=fileobj)
>
> but then I cannot do anything with 'tar'. I mean, tar.list() returns
> nothing. Even worse, my fileobj can be any thing, a 'zip' for example,
> and tarfile.open doesn't seem to check for that as it does if it was a
> file like 'myfile.tgz' or 'myfile.zip', failing to open for the former.
>
> I tried google and also StringIO, but without success. All I want is
> to check if the supposed tgz file is a valid tgz file as I do for a
> zip file.
>
> Many thanks in avance,
> Alan
>
> -- 
> Alan Wilter S. da Silva, D.Sc. - CCPN Research Associate
> Department of Biochemistry, University of Cambridge.
> 80 Tennis Court Road, Cambridge CB2 1GA, UK.
> >>http://www.bio.cam.ac.uk/~awd28 <<
>
> >


--~--~-~--~~~---~--~~
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 access SplitDateTime field elements in template

2008-12-23 Thread rtmie

I have found a workaroud to this, by using the AdminSplitDateTime
widget and then rendering field in the template, the right thing
happens:

in form code:

from django.contrib.admin import widgets as adminWidgets

class Dummy1Form(forms.ModelForm):
name = forms.CharField(max_length = 100)
created = forms.SplitDateTimeField(initial=datetime.datetime.now
(),
 
widget=adminWidgets.AdminSplitDateTime)

in template:
{% trans "Created:" %}

{{ form.created }}


I'm still curious on the original question though

Rob


On Dec 22, 12:45 pm, rtmie  wrote:
> I have a form with a  SplitDateTimeField and cannot figure out how to
> access the individual date and time elements in it from my template:
>
> class Dummy1(models.Model):
>     name =  models.CharField(max_length = 100)
>     created = models.DateTimeField(default = datetime.datetime.now())
>
> class Dummy1Form(forms.Form):
>     name = forms.CharField(max_length = 100)
>     created = forms.SplitDateTimeField(widget=forms.SplitDateTimeWidget
> ())
>     class Meta:
>         model = Dummy1
>
> In my template:
> {% trans "Created:" %} label>
> 
> {{ form.created }}
> 
>  will give me access to the 2 fields but if I want to do something
> like the old form , what syntax do I need to get at the individual
> elements:
>
> {% trans "Created:" %} label>
> 
>         {% trans "Date: "%}{{ form.created_date }}
>         
>         {% trans "Time: "%}{{ form.created_time }}
> 
>
> I haven't found any doc on this
>
> Rgds
> Rob
--~--~-~--~~~---~--~~
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: Subprocess module in Python CGI

2008-12-23 Thread Anurag

I have also missed out a last line at the end of the Traceback ...
this may be important in fishing out the error. The last line is:

OSError: [Errno 2] No such file or directory

Looking forward to some kind of suggestions.
Thanking you all once again and with Regards.

On Dec 22, 11:51 am, Anurag  wrote:
> Hello,
>
> I have started using python recently and would like to call a short
> python script via
> browser using a CGI script, but initially I am trying to call the same
> python script directly through python command line. The script intends
> to
> perform a few command line in a pipe and I have written the script (a
> short
> one) as follows. I would later also like to import this application to
> Django.
>
> #!/usr/bin/python
>
> import cgi, string, os, sys, cgitb, commands, subprocess
> import posixpath, macpath
> #file = "x.tar.gz"
> #comd = "tar -xf %s" % (file)
> #os.system(comd)
> #commands.getoutput('tar -xf x.tar.gz | cd demo; cp README ../')
> comd = [\
>         "tar -xf x.tar.gz", \
>         "cd demo", \
>         "cp README ../", \
>       ]
> outFile = os.path.join(os.curdir, "output.log")
> outptr = file(outFile, "w")
> errFile = os.path.join(os.curdir, "error.log")
> errptr = file(errFile, "w")
> retval = subprocess.call(comd, 0, None, None, outptr, errptr)
> errptr.close()
> outptr.close()
> if not retval == 0:
>         errptr = file(errFile, "r")
>         errData = errptr.read()
>         errptr.close()
>         raise Exception("Error executing command: " + repr(errData))
>
> but after trying to execute this independently, I get the following
> error
> which I am unable to interpret :
>
> Traceback (most recent call last):
>   File "process.py", line 18, in 
>     retval = subprocess.call(comd, 0, None, None, outptr, errptr)
>   File "/usr/lib/python2.5/subprocess.py", line 443, in call
>     return Popen(*popenargs, **kwargs).wait()
>   File "/usr/lib/python2.5/subprocess.py", line 593, in __init__
>     errread, errwrite)
>   File "/usr/lib/python2.5/subprocess.py", line 1135, in
> _execute_child
>     raise child_exception
>
> Could someone suggest where am I going wrong and if corrected, what is
> the
> probability of this script being compatible with being called through
> the
> browser. Thanking you people in advance.
>
> Regards.
--~--~-~--~~~---~--~~
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: Complete layout (template) switching.

2008-12-23 Thread Kura

Thanks. Sadly though I don't want it to extend base.html, I want it to
replace base.html but only under certain circumstances.

As an example, base.html will have the current structure:

__header__
  | |
nav | content | content
  | |
__footer___

Where as base2.html will have a different structure:

__header__
  content
--
  content
--
__footer___


So as you can tell the first variation of base.html will have a column
based layout where as the second variation will have row based
content.

This needs to be done at a project template level rather than at an
application level and extending from what I can tell simply won't cut
it.

We also won't be able to have a simple base.html that has a page
wrapper and then in each template define an extension for it because
that's too much replication.

On Dec 22, 8:04 pm, bruno desthuilliers
 wrote:
> On 22 déc, 13:34, Kura  wrote:
>
> > Hey guys, I'm currently working on a content management system built
> > on the Django framework, currently the whole cms works on a 
> > section->page(s) basis which is working well, we've run in to some issues 
> > with
>
> > our designs in that the blocks for content on some pages are in
> > different locations and the overall layout is different, to combat
> > this we've added a field to the page table that tells Django which
> > layout template it should use, the issue is I'm not sure how to
> > actually make Django read that column and actually switch the whole
> > layouts template for that page on a project level as a replacement to
> > base.html while keeping base.html as default for other pages.
>
> > Any ideas?
>
> if it's a field of the Page model object and you have a Page model
> instance in your context, then {% extends page.template|
> default:"base.html" %} should do.
>
> http://docs.djangoproject.com/en/dev/ref/templates/builtins/#extends
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



ModelAdmin and the ghost datas !

2008-12-23 Thread degans...@gmail.com

Hello :) (sorry I'm French)

When I create a ticket (for a blog), I select various tags.
I would save these with the save_model and save_tagged_items methods
below :


class TicketAdmin(admin.ModelAdmin):

# ...

def save_model(self, request, ticket, form, change):
# Save the author if it's a new ticket
if not change:
ticket.author = request.user
ticket.save()
# Save tags
self.save_tagged_items(ticket, form)


def save_tagged_items(self, ticket, form):
for tag in form.cleaned_data['tags']:
print tag
ti = TaggedItem(tag=tag, item=ticket)
print ti
ti.save()
print ti.id
print TaggedItem.objects.all()


It seems to be a success :
http://nsa03.casimages.com/img/2008/12/23/08122311171655683.png

But in ma table (django_tagged_item), there is nothing ! It's empty.

I don't understand why, have you a solution ?

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: login_required redirects always to LOGIN_REDIRECT_URL?

2008-12-23 Thread Jarek Zgoda

Wiadomość napisana w dniu 2008-12-22, o godz. 20:40, przez Matias:

> You can add a hidden input named "next" where you put the value of  
> next in the GET variable.
> Like this
> 
> 
> 
> 
> 
>
> Or you can change the action variable of the form to include the  
> current GET variables. like this
>
> 
> 
> 
>
> If your view that handles GET and POST aren't the same you must add  
> the "next" var in the action field on your own.
>
>
> The latter is the best IMHO.


Thanks. I was hoping there's something that would save me from writing  
actual code. Django makes me too lazy, I have to get my hands dirty  
with Spring again. ;)

-- 
We read Knuth so you don't have to. - Tim Peters

Jarek Zgoda, R, Redefine
jarek.zg...@redefine.pl


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



a clean_tarfile() for my form

2008-12-23 Thread Alan
Hi There,
So I have a form where users can upload zip and tgz file. In my def
clean_file() for class MyForm, I can clean zip files smoothly and now I am
trying the same for a tgz file but missing things.

First, fileobj = self.cleaned_data['file'] will return a fileobj, so I
tried:

tar = tarfile.open(fileobj=fileobj)

but then I cannot do anything with 'tar'. I mean, tar.list() returns
nothing. Even worse, my fileobj can be any thing, a 'zip' for example, and
tarfile.open doesn't seem to check for that as it does if it was a file like
'myfile.tgz' or 'myfile.zip', failing to open for the former.

I tried google and also StringIO, but without success. All I want is to
check if the supposed tgz file is a valid tgz file as I do for a zip file.

Many thanks in avance,
Alan

-- 
Alan Wilter S. da Silva, D.Sc. - CCPN Research Associate
Department of Biochemistry, University of Cambridge.
80 Tennis Court Road, Cambridge CB2 1GA, UK.
>>http://www.bio.cam.ac.uk/~awd28<<

--~--~-~--~~~---~--~~
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: problem with adding foreign key to table

2008-12-23 Thread SteveMc

The other reply was correct; it's a character encoding issue. Take a
look at http://www.postgresql.org/docs/8.3/static/multibyte.html - I
suspect you will need to run initdb -E UTF8 to set the default
character set for the postgres install. Alternatively that page
instructs how to create a specific database with a character set.
Running
 $ psql -l
will tell you what character sets your databases are using.

On Dec 22, 9:14 pm, Ana  wrote:
> Hello,
>
> I migrated my MySQL tables to Postgres.  Generally, the migration was
> fine with one exception.  I have a table researchproj that included
> two foreign keys (institution_id and contact_id).  I received the
> following error:
>
> Caught an exception while rendering: ('ascii', u'Jorge Gir\xf3n', 9,
> 10, 'ordinal not in range(128)')
>
> when I tried to access the researchproj table through admin.  If I
> delete the column contact_id, the error goes away.  If I add the
> column back onto the table the error returns.  All the tables contain
> data, although I created a test researchproj table with just one
> tuple.  I've added, deleted and done acrobats trying to get the admin
> to accept the column contact_id in the researchproj table.  I have
> checked the sequence numbers for all tables, and also any referential
> integrity issues with all the tables.  Can someone help?
>
> Thanks,
>
> Ana
--~--~-~--~~~---~--~~
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: where are the code that handle image file upload in Django admin page?

2008-12-23 Thread krylatij

http://docs.djangoproject.com/en/dev/topics/http/file-uploads/
here is a sample how to handle file upload

And have tried:
MyForm.save()?
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---