How should I organize my news site's backend - needing some feedback

2009-08-06 Thread chyea

Hi all,

I recently sent an email to another Django coder asking for some
possible feedback on my situation. I'll simply restate the email here,
because I figured why not ask a bunch of other Django coders, too!
Here it goes...

Hi,

I'm trying to design a django-based gaming news site, and have been
just confusing myself. I think I'm over-complicating it by trying to
make it highly dynamic/scalable. Perhaps I can just run my design
ideas by you and see if you have any feedback for me.

Conceptually, it's very simple. I want the site to revolve around
various types of articles - news, interviews, reviews. My thoughts
were that all of these articles are essentially, at the core, the same
set of data - a title, slug and the article text (simplified example).
So, with this in mind I created an abstract base class called Article,
with those essential elements. Then, I just created classes for News,
Interview and Review, that subclass the abstract Article base class.
So, now I've got the core article model classes for my site.

I'm starting to confuse myself, though, when trying to figure out what
to do with all the media involved with the site.

How I have it invisioned is a highly dynamic and scalable setup that
allows me to tag any number of pictures, videos, or any other model
really, to any type of Article object. This would result in media
objects that aren't exactly coupled to any specific Article, and can
therefor be tagged to any of them, none of them, all of them, etc.

With this in mind, I thought it'd make sense to create another
abstract base class for all types of media. Somehow, this abstract
base class for media objects would contain the proper code that'd
allow any classes that subclass it to be tagged to any other model.

The reason I'm thinking of it like this is because imagine a page on
my site for a News article object. Lets say this News article is about
how a game developer company is down in profits this year because they
haven't released a game they announced, yet. This News article would
have several things related, or 'tagged' to it - a Developer, a Game,
perhaps some Pictures, maybe a Movie. I'd have existing models for
Developer, Game, Picture and Movie (ideally). While creating this News
article, I'd have the ability to just select these related items in
the admin page. All of this related data would be available to the
News article object when you query for it, and then all passed to the
template where I can sort it out there.

What I've described above sounds like it'd be a very dynamic setup
that'd allow me to basically create some pretty interesting Articles
and tag them with relevant data. This beats just using TinyMCE and
using the formatting it creates to link to YouTube videos, and images
in my article, on a per-article basis. Does it sounds like I've
thought this to death, or is what I'm describing possible at all?

All day today I messed around with generic relationships and
ContentType. I tried creating an abstract base classes with generic
relations to other abstract base classes: Article <-> Media

In the end I'm just high confused and wondering if I'm completely
complicating this. I know this was long and if you read it this far
then I greatly appreciate it. I'm looking forward to any insight, or
advice/feedback you may have!

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



Re: Runtime error when uploading image files

2009-08-06 Thread Malcolm MacKinnon
Karen, you're recommendations were great. After fixing the model form
problem, I found that I and others had problems with PILL. Apparently, it's
not easy to install correctly on Ubuntu, and if it isn't you may get
ImageField validation errors when saving images. Here's a link that might
help fix the problem for others who may run into it:

http://www.answermysearches.com/fixing-pil-ioerror-decoder-jpeg-not-available/320/

Thanks again for taking the time to respond.


On Thu, Aug 6, 2009 at 5:02 PM, Malcolm MacKinnon wrote:

> Thanks, Karen. I really appreciate all the time you put in looking at this
> and your comments are very informative. You were right about naming the
> primary key PK (I thought Django would like that, but it doesn't). I changed
> it to PRIM and the model form renders the way it should in photos.html. I
> did run into one more problem: when I try to save a jpeg image, I get a
> ValueError exception:
>
> The Images could not be created because the data didn't validate.
>
> I know the file is a jpeg file. Here is my new form and view:
>
> class PictureForm(ModelForm):
>class Meta:
>model=Images
>exclude = ('prim',)
>
> def image_loads(request):
> form=PictureForm()
> if request.method=='POST':
> form=PictureForm(request.POST,  request.FILES)
> if form.is_multipart:
> form.save(commit=False)
> form.save()
> form=PictureForm()
> return render_to_response('photos.html', {'form':form,  },
> context_instance = RequestContext(request))
>
>
>
>
> return render_to_response('photos.html', {'form':form,  },
> context_instance = RequestContext(request))
> Here is the error:
> Environment:
>
> Request Method: POST
> Request URL: http://localhost:8000/photos/
> Django Version: 1.1 beta 1 SVN-10891
> Python Version: 2.5.2
> Installed Applications:
> ['django.contrib.auth',
>  'django.contrib.contenttypes',
>  'django.contrib.sessions',
>  'django.contrib.sites',
>  'django.contrib.admin',
>  'orders1.onhand',
>  'registration']
> Installed Middleware:
> ('django.middleware.common.CommonMiddleware',
>  'django.contrib.csrf.middleware.CsrfMiddleware',
>  'django.contrib.sessions.middleware.SessionMiddleware',
>  'django.contrib.auth.middleware.AuthenticationMiddleware')
>
>
> Traceback:
> File "/usr/lib/python2.5/site-packages/django/core/handlers/base.py" in
> get_response
>   92. response = callback(request, *callback_args,
> **callback_kwargs)
> File "/home/malcolm/data1/orders1/../orders1/onhand/views.py" in
> image_loads
>   49. form.save(commit=False)
> File "/usr/lib/python2.5/site-packages/django/forms/models.py" in save
>   407.  fail_message, commit,
> exclude=self._meta.exclude)
> File "/usr/lib/python2.5/site-packages/django/forms/models.py" in
> save_instance
>   42.  " validate." % (opts.object_name,
> fail_message))
>
> Exception Type: ValueError at /photos/
> Exception Value: The Images could not be created because the data didn't
> validate.
>
> I get the same error when I include the field PRIM. Again, thanks for your
> time. I've put in hours trying to figure this out, and your comments were
> great.
>
>
> On Thu, Aug 6, 2009 at 3:32 PM, Karen Tracey  wrote:
>
>>
>> On Aug 6, 1:56 am, Mac  wrote:
>> > Hi,
>> >
>> > I'm new to django. When I try to upload image files, I get runtime
>> > errors. Here's my model:
>> > models.py
>> >
>> > class Images(models.Model):
>> > pk = models.IntegerField(primary_key=True, db_column='PK') # Field
>> > name made lowercase.
>>
>> Unless you are going to be manually assigning values here -- and I
>> don't see any evidence of that in your code -- you probably want this
>> to be an AutoField, not an IntegerField.  Based on the comments in
>> this model I'm guessing that it was auto-generated by inspectdb.  Note
>> the results of inspectdb are meant to serve as a starting point for
>> your models, and in most cases will require some tweaking, such as
>> changing this generated IntegerField to an AutoField, assuming you
>> want this to be the automatically-assigned primary key field for the
>> model.
>>
>> There's also another problem with this field but we'll get to that
>> later.
>>
>> > photos = models.ImageField(db_column='PHOTOS', upload_to='img',
>> > blank=True) # Field name made lowercase.
>> > items = models.CharField(max_length=255, db_column='ITEMS',
>> > blank=True) # Field name made lowercase.
>> > date = models.DateField(null=True, db_column='DATE', blank=True) #
>> > Field name made lowercase.
>> > class Meta:
>> > db_table = u'IMAGES'
>> >
>> > Here's my view:
>> > rom django.core.files.uploadedfile import SimpleUploadedFile
>> > from PIL import Image
>> > Image.init()
>> > class PictureForm(forms.Form):
>> >pic=forms.ImageField()
>> >def create(self, file):
>> > mymodel = Images()
>> > mymodel.save_image_file(fil

Defining subsets of "list" variable at template level

2009-08-06 Thread bweiss

Is there a simple way to do the following that I'm just not seeing, or
am I looking at trying to write a custom tag?  The functionality I
need is similar to {% regroup %} but not quite the same...

My app currently has a custom admin view in which I've defined a whole
bunch of different lists, which are all objects of the same model,
filtered according to different options of a field called "Type".
(eg. type_A_list = mymodel.objects.filter(Type="A"); type_B_list =
mymodel.objects.filter(Type="B"); etc.)

I've realised that the number of database hits this involves is
inefficient, and it would be cleaner to have a single list of objects
and try to perform the logic I need at the template level.

What I'd like to be able to do is, for a single variable,
"object_list", define subsets of this list containing objects that
meet a certain condition.  So, to filter by the field "Type", I could
define lists called "type_A_list", "type_B_list", etc, that could be
iterated through in the same way as the original list.

The reason I need to do this is to be able to use the {% if
type_A_list %} tag in order to flag when there are NO objects of a
given type.  This is why (as far as I can see) the {% regroup %} tag
won't quite work, as it only lists the groups that actually have
members.

Output would look something like:

Type 1:
Object 1, Object 5, Object 6

Type 2:
There are no objects of Type 2

Type 3:
Object 2, Object 4

Does anyone have any suggestions?

Thanks,
Bianca

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



post_save timeout with twitter

2009-08-06 Thread Kenneth Gonsalves

hi,

I use a post_save signal to send a tweet on twitter. Just now I have had some 
ugly timeout crashes since twitter was not responding and my saves were 
getting b0rked. How does one get around that?
-- 
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
-~--~~~~--~~--~--~---



Admin, two links to different views ?

2009-08-06 Thread Asinox

Hi guys, in django admin the views that show the register's just have
a link to "edit", but what happen if a need an extra(S) links to
another views?

for example:

i have view that my show list of registered People, the nick is
linking to the Edit page (the normal way of Django), but i need
another links that will show me the "articles" of the people and
another the "comments" of the people.

how ill make this with django admin?


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: checking/using model data in form save

2009-08-06 Thread zayatzz

Thank you!

Alan.

On Aug 6, 10:51 pm, Daniel Roseman  wrote:
> On Aug 6, 8:36 pm, zayatzz  wrote:
>
>
>
>
>
> > Hello
>
> > I am not entirely sure if i am asking the right question, but here is
> > what am trying to do.
>
> > I am saving user mugshot with form and it works just fine. I rename
> > the uploaded file to mugshot.[insert imagefile extension here], but i
> > want to do more in form save method than just that.
>
> > 1) i want to check if the model, whos form im saving already has
> > imagefile saved. I have this in view:
> > pform = ProfileForm(instance=profile)
>
> > but this in form save:
> >                         os.remove(settings.MEDIA_ROOT+self.instance.img)
>
> > returns me ImageFieldFile not the data that is saved in it... and i
> > get typeerror:
> > TypeError at /profile/edit/
>
> > cannot concatenate 'str' and 'ImageFieldFile' objects
>
> > 2) if it exists, then remove it - can do it os.remove(), but the
> > problem is similar to last point - i need to know the name of existing
> > file, that is saved in model data
> > 3) if the file has been removed or did not exist in the first place
> > then i want to save different sizes of the file - thumbnail, bigger
> > pic and so on. i do not need the examples for that.
>
> > Alan
>
> self.instance.img.name will give you the relative path from
> MEDIA_ROOT. 
> See:http://docs.djangoproject.com/en/dev/ref/files/file/#django.core.file...
> --
> DR.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-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: DateInput widget, format attr & ugettext

2009-08-06 Thread Malcolm Tredinnick

On Fri, 2009-08-07 at 11:56 +1000, Malcolm Tredinnick wrote:
> On Thu, 2009-08-06 at 08:06 -0700, cArkraus wrote:
> > Hey all,
> > 
> > I cant seem to get my (non-model-)forms datefield localized.
> > 
> > Here's my first attempt:
> > some_date = fields.DateField(widget=widgets.DateInput(format=ugettext
> > ('%d.%m.%Y')))
> 
> This would do the translation when the file is imported, which won't
> reflect the user's current locale. The working rule is that you don't
> use ugettext() outside of a view function (or something called directly
> by a view).
> 
> > That's working fine, until the user switches his sessions language.
> > Then, the date is still shown in the format(ie. '%d.%m.%Y') and not
> > the correctly localized one(ie. '%Y-%m-%d').
> > 
> > Now, if I change to ugettext_lazy() like this:
> > 
> > some_date = fields.DateField(widget=widgets.DateInput
> > (format=ugettext_lazy('%d.%m.%Y')))
> > 
> > I get a TemplateSyntaxError 'strftime() argument 1 must be string or
> > read-only buffer, not __proxy__'
> 
> That's a bug in Django and Python (both sides share some blame: Python's
> string handling is retarded in cases like this and Django doesn't work
> around it correctly here). It's not particularly easy to work around it,
> either.

This came about ambiguously: without hunting down the offending place
right at the moment, I'm still fairly certain it's easy to fix this in
Django's core. I can't think of an easy way to work around it in Django
apps, however (that might be because I'm not imaginative enough).

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: Pagination in the admin , where is?

2009-08-06 Thread Asinox

oh man :) thanks :) so easy :)

On Aug 6, 10:55 pm, "Adam V."  wrote:
> ModelAdmin.list_per_page will let you control how many items appear on
> a particular admin 
> list:http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contri...
>
> On Aug 6, 7:50 pm, Asinox  wrote:
>
>
>
> > Well, i cant find any about it, i want to know if the pagination exist
> > in the admin... i think that "yes"..but .. i cant see any thing
> > about..
>
> > 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: Pagination in the admin , where is?

2009-08-06 Thread Adam V.

ModelAdmin.list_per_page will let you control how many items appear on
a particular admin list:
http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.list_per_page

On Aug 6, 7:50 pm, Asinox  wrote:
> Well, i cant find any about it, i want to know if the pagination exist
> in the admin... i think that "yes"..but .. i cant see any thing
> about..
>
> 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
-~--~~~~--~~--~--~---



Pagination in the admin , where is?

2009-08-06 Thread Asinox

Well, i cant find any about it, i want to know if the pagination exist
in the admin... i think that "yes"..but .. i cant see any thing
about..

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: python md5

2009-08-06 Thread James Bennett

On Thu, Aug 6, 2009 at 7:20 PM, Kenneth Gonsalves wrote:
> is it not deprecated?

The documentation covers that question, too.


-- 
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."

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



Re: creating a list of sql that is executed

2009-08-06 Thread Stephen Moore

On Fri, Aug 7, 2009 at 2:56 AM, Shawn Milochik wrote:
>
> Look for the post_save signal.
>
> Once you can attach your own function to that signal (make it listen
> for the signal and kick something off), you can probably have Django
> dump the raw SQL query that is created to a text file. I don't know
> the syntax for that, but check the django.db docs.
>

ok then

>
>The only exception is if you're doing some development at home in
> a test bed, but then the data you create wouldn't be "real" and
> shouldn't go into the production database.
>

True..

I also thought of some other problems that could come from this since
posting anyway.

Thankyou for your help though :)

Regards
Stephen

--~--~-~--~~~---~--~~
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: DateInput widget, format attr & ugettext

2009-08-06 Thread Malcolm Tredinnick

On Thu, 2009-08-06 at 08:06 -0700, cArkraus wrote:
> Hey all,
> 
> I cant seem to get my (non-model-)forms datefield localized.
> 
> Here's my first attempt:
> some_date = fields.DateField(widget=widgets.DateInput(format=ugettext
> ('%d.%m.%Y')))

This would do the translation when the file is imported, which won't
reflect the user's current locale. The working rule is that you don't
use ugettext() outside of a view function (or something called directly
by a view).

> That's working fine, until the user switches his sessions language.
> Then, the date is still shown in the format(ie. '%d.%m.%Y') and not
> the correctly localized one(ie. '%Y-%m-%d').
> 
> Now, if I change to ugettext_lazy() like this:
> 
> some_date = fields.DateField(widget=widgets.DateInput
> (format=ugettext_lazy('%d.%m.%Y')))
> 
> I get a TemplateSyntaxError 'strftime() argument 1 must be string or
> read-only buffer, not __proxy__'

That's a bug in Django and Python (both sides share some blame: Python's
string handling is retarded in cases like this and Django doesn't work
around it correctly here). It's not particularly easy to work around it,
either.

Please open a ticket with this short example (only the ugettext_lazy()
case). Although you might also check that the i18n component in Trac
doesn't have a ticket open like this. I'm a little surprised it hasn't
been noticed before.

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: How-to use SelectMultiple widget with CommaSeparatedIntegerField ?

2009-08-06 Thread Malcolm Tredinnick

On Thu, 2009-08-06 at 07:35 -0700, nono wrote:
> I was reading my post and though it was not very clear
> 
> My model uses CommaSeparatedIntegerField to store some integer values.
> I want my users to use SelectMultiple widget to create/update those
> integer so I put a ChoiceField with widget=SelectMultiple in my form.
> My problem is that all I can get from this is a list of values (for
> example [u'2', u'3']) where I expect comma separated values ("2, 3").
> 
> I hope this is a better explanation and somebody could help me

If you want to normalise the values that are submitted to something
other than what happens automatically, write a clean_()
method for that form field. Have a look at

http://docs.djangoproject.com/en/dev/ref/forms/validation/

for details.

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: multi-table inheritance and modification of OneToOneField options

2009-08-06 Thread Malcolm Tredinnick

On Thu, 2009-08-06 at 07:15 -0700, Jan Ostrochovsky wrote:
> Hello,
> 
> http://docs.djangoproject.com/en/dev/topics/db/models/#multi-table-inheritance
> says:
> The inheritance relationship introduces links between the child model
> and each of its parents (via an automatically-created OneToOneField).
> 
> http://docs.djangoproject.com/en/dev/ref/models/fields/#onetoonefield
> says: Multi-table inheritance is implemented by adding an implicit one-
> to-one relation from the child model to the parent model...
> 
> The question is: how can I set options of that implicit OneToOneField?
> Most interesting is null=True / null=False.

You don't. Model inheritance is a Python-level thing and things like
"optional" inheritance doesn't existence for Python inheritance. It's a
shortcut for emulating Python class inheritance as much as possible.

If you want this level of control, model the relations explicitly and
set the options on the OneToOneField to whatever you like.

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: Getting Started, tutorial newbie

2009-08-06 Thread zignorp

figured it out, but I'm not sure I can articulate what I did.  I had
to start the shell first, then import my model.

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



Re: syncdb does not find app on the PYTHONPATH

2009-08-06 Thread Matthew

It looks like the issue is resolved.  Many thanks to Kenneth and
Daniel.  Here's the summary to help others:

It looked at first like the PYTHONPATH was not picking any of my apps
or the third-party apps up when running syncdb.  This was not the
case.  Instead, coltrane's classes weren't loading because errors in
its imports.  Here's the RCA.

import User
===

The top of models.py in the coltrane app looked like this.

import datetime

from django.db import models
from django.contrib.auth import User

from markdown import markdown
from tagging.fields import TagField
...

Using the python shell, I determined it could not import User; no
module.  Looking closer, I noticed that I forgot the "models" part of
the import.  I changed it to look like this:

import datetime

from django.db import models
from django.contrib.auth.models import User

from markdown import markdown
from tagging.fields import TagField
...

markdown
==

I again turned to the python shell to test the import of Category.
Again it failed, this time complaining about markdown.

But I installed markdown using its own installer.  Wasn't that good
enough?

No.  The markdown directory had to be on the PYTHONPATH, so I
downloaded it again and placed it there.

django-tagging
=

The last problem was with the tagging app, specifically a class
parse_lookup, which was deprecated.  I uninstalled the tagging app
from /usr/lib/python2.5/site-packages, then checked out the latest SVN
trunk to my PYTHONPATH.
--~--~-~--~~~---~--~~
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: python md5

2009-08-06 Thread Kenneth Gonsalves

On Friday 07 Aug 2009 12:02:19 am James Bennett wrote:
> On Thu, Aug 6, 2009 at 1:16 PM, Asinox wrote:
> > Thanks Alex Gaynor :) is working :)
>
> It's very important to note that the documentation for this module
> would have given you the same information. In general, you should be
> doing your best to read and familiarize yourself with documentation so
> that you'll be able to answer your own questions and be more
> productive.

is it not deprecated?
-- 
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: django-threadedcomments app

2009-08-06 Thread Margie

Hi Eric,

Thanks for the info.  A couple questions:

  * Does the .5 version work with django 1.1?
  * Do you have any sort of ETA on when you think the GitHub version
will be ready for public use?  Is it in a form now that it could
actually be used?  IE, if I am willing to dive in and look at the
code, does the GitHub code have a reasonable level of functionality or
is it completley torn up and non-working?

Just trying to get an idea if I should go for the new or stick with
the old.  I'm fine with diving in and trying to fix bugs as needed,
but obviously it is better if there is a base level of functionality
working.

Thanks very much for the package, it seems very nice.  My goal is to
provide a comment interface to my users that is similar to the google
groups interface - it seems that threadedcomments is very well suited
to that, do you agree?

Margie



On Aug 6, 4:40 pm, Margie  wrote:
> Anyone know any status on the django-threadedcomments app?  The google
> group on it seems to be inactive.  The last update I see about it is:
>
> March 31, 2009: Released version 0.5 of the application and moved.
> This is the last of this line--the next release will be a large
> rewrite to use the comment extension hooks provided in Django 1.1 and
> will be backwards incompatible.
>
> Anyway, just wondering if anyone here knows anything more?
>
> Margie
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: django-threadedcomments app

2009-08-06 Thread Eric Florenzano

I moved development over to GitHub [1] and have actually gone ahead
with that big rewrite (thanks also to Honza and team Ella, as well as
Thejaswi Puthraya).  It's a total rewrite with very little common
code, so none of the documentation is up to date.  The old 0.5.X
version is stable enough, and in widespread enough use, that I think I
will continue to support that branch of code for the foreseeable
future with bugfixes and branches.  I'll probably support that even
after I officially release the rewritten comments app.

That being said, I am no longer using django-threadedcomments in any
current projects of mine, so my motivation for maintaining it is a bit
lower than it was when I was responsible for its use in production.
I'm still dedicated to maintaining it, but it's a lower priority for
me.

Hope that helps!

Thanks,
Eric Florenzano

[1]  http://github.com/ericflo/django-threadedcomments/tree/master

On Aug 6, 4:40 pm, Margie  wrote:
> Anyone know any status on the django-threadedcomments app?  The google
> group on it seems to be inactive.  The last update I see about it is:
>
> March 31, 2009: Released version 0.5 of the application and moved.
> This is the last of this line--the next release will be a large
> rewrite to use the comment extension hooks provided in Django 1.1 and
> will be backwards incompatible.
>
> Anyway, just wondering if anyone here knows anything more?
>
> Margie
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Mod_wsgi and Apache Problems - Unhandled request return Internal Server Error / Premature end of script headers

2009-08-06 Thread Graham Dumpleton



On Aug 7, 7:43 am, pcrutch  wrote:
> So I run the dev server for my project and everything comes up fine,
> map shows properly and loads the data correctly. However, using wsgi
> the map loads and gives " Unhandled request return Internal Server
> Error" and I checked the log file and I have the " premature end of
> script headers" error. I have no clue why it won't load the data on
> the map properly.
>
> here is my sites-available file
> 
>
>    
>         ServerName dragonfly.cens.ucla.edu
>
>         WSGIDaemonProcess dragonfly.cens.ucla.edu threads=25
>         WSGIProcessGroup dragonfly.cens.ucla.edu
>
>         WSGIScriptAlias / /home/patrick/geodj/apache/sitez.wsgi
>         
>             Order deny,allow
>             Allow from all
>         
>
>         ErrorLog /var/log/apache2/error.log
>         LogLevel warn
>
>         CustomLog /var/log/apache2/access.log combined
>     
>
> -
> sites-enabled file
>
> 
>     #Basic setup
>     ServerAdmin pcrutc...@ucla.edu
>     ServerName dragonfly.cens.ucla.edu
>     ServerAlias dragonfly.cens.ucla.edu
>
>     
>         Order deny,allow
>         Allow from all
>     
>
>     LogLevel warn
>     ErrorLog  /home/patrick/geodj/apache_error.log
>     CustomLog /home/patrick/geodj/apache_access.log combined
>
>     WSGIDaemonProcess dragonfly.cens.ucla.edu threads=25
>     WSGIProcessGroup dragonfly.cens.ucla.edu
>
>     WSGIScriptAlias / /home/patrick/geodj/apache/sitez.wsgi
> 
>
> -
> my project .wsgi file
>
> import os, sys
> sys.path.append('/home/patrick/geodj')
> sys.path.append('/home/patrick/geodj/templates')
>
> os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
>
> import django.core.handlers.wsgi
>
> application = django.core.handlers.wsgi.WSGIHandler()
>
> What gives?

Since you have 'geodj' and going to guess you are using GeoDjango.

GeoDjango is either not thread safe, or uses a C extension module
which isn't safe to use in sub interpreters, I don't remember which.

Use:

  WSGIDaemonProcess dragonfly.cens.ucla.edu processes=4 threads=1
  WSGIApplicationGroup %{GLOBAL}

That is, use single thread daemon processes and force it to run in
main interpreter.

So, change the WSGIDaemonProcess directive and add
WSGIApplicationGroup. Leave other directives as is.

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



Re: access to REQUEST_URI ?

2009-08-06 Thread Graham Dumpleton



On Aug 7, 7:37 am, Rebecca K  wrote:
> I'm working on an ARK (Archival Resource Key) resolver in django, and
> as part of the ARK spec I need to recognize and distinguish urls
> ending with '?' and '??'  (no query string or anything else
> following).
>
> When I run my django app throughmod_wsgi, I have access to
> request.META['REQUEST_URI'], which contains the path plus the question
> mark.  When I run my django app with manage.py runserver, I get a key
> error when I try to access REQUEST_URI.  Same thing when I use the
> django test client.
>
> Anyone have any thoughts on how I can access the REQUEST_URI
> consistently no matter what environment the django app is running in?
>
> I'm not tied to using REQUEST_URI-- if there are other ways to detect
> the '?' on the end of the url, that serves my purpose just as well.
> But it seems that the all of the django HttpRequest object functions
> and properties have path and query string values that are too
> sanitized and don't give me access to this.
>
> Thanks in advance for any help or suggestions.

REQUEST_URI is not a value one should ever rely on for dispatch. This
is because it is entirely optional and will not be supplied by hosting
mechanisms. It is also the raw URL from the request and has not had
decoding of duplicate slashes removed, nor had any web server rewrite
rules applied. It therefore can be difficult to actually relate it to
the final SCRIPT_NAME and PATH_INFO unless you are going to duplicate
all the stuff that a specific web hosting mechanism may do to derive
SCRIPT_NAME and PATH_INFO from it.

Anyway, you shouldn't even need to access the REQUEST_URI unless
Django or the Django development server is doing something odd. For a
standard web server with WSGI support, you possibly should be able to
look at QUERY_STRING.

PATH_INFO: ''
QUERY_STRING: '?'
REQUEST_METHOD: 'GET'
REQUEST_URI: '/echo.wsgi??'
SCRIPT_NAME: '/echo.wsgi'

Well, at least to capture the case where the double question mark
occurs, as in that case the second question mark will be in
QUERY_STRING.

You can't through variables other than REQUEST_URI determine if there
was a question mark with an empty query string. Relying on that is
arguably going to be somewhat dodgy anyway.

In terms of what I was talking about with encoding and the problems it
can cause as far as blind matching without decoding, see examples
below.

PATH_INFO: ''
QUERY_STRING: '?'
REQUEST_METHOD: 'GET'
REQUEST_URI: '/%65cho.wsgi??'
SCRIPT_NAME: '/echo.wsgi'

PATH_INFO: '/e'
QUERY_STRING: '?'
REQUEST_METHOD: 'GET'
REQUEST_URI: '/echo.wsgi/%65??'
SCRIPT_NAME: '/echo.wsgi'

End result is that if some standard is based on a single question mark
and no actual query string content being different to no question mark
at all, they have been pretty stupid in doing that.

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



Re: syncdb does not find app on the PYTHONPATH

2009-08-06 Thread Matthew

I tried your suggestion and got this:

>>> from coltrane.models import Category
Traceback (most recent call last):
  File "", line 1, in 
  File "/home/matthew/dev/source/coltrane/models.py", line 3, in

from django.db import models
  File "/usr/local/lib/python2.6/dist-packages/django/db/__init__.py",
line 10, in 
if not settings.DATABASE_ENGINE:
  File "/usr/local/lib/python2.6/dist-packages/django/utils/
functional.py", line 269, in __getattr__
self._setup()
  File "/usr/local/lib/python2.6/dist-packages/django/conf/
__init__.py", line 38, in _setup
raise ImportError("Settings cannot be imported, because
environment variable %s is undefined." % ENVIRONMENT_VARIABLE)
ImportError: Settings cannot be imported, because environment variable
DJANGO_SETTINGS_MODULE is undefined.

I then found a thread about DJANGO_SETTINGS_MODULE here
http://groups.google.com/group/django-users/browse_thread/thread/be0f814d1cf896f
and set DJANGO_SETTINGS_MODULE to simply 'settings' like it suggests.
I then got this:

>>> from coltrane.models import Category
Traceback (most recent call last):
  File "", line 1, in 
  File "/home/matthew/dev/source/coltrane/models.py", line 4, in

from django.contrib.auth import User
ImportError: cannot import name User

I also imported Django, which worked fine.  Any thoughts?

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



Re: syncdb does not find app on the PYTHONPATH

2009-08-06 Thread Matthew

I tried your suggestion and got this:

>>> from coltrane.models import Category
Traceback (most recent call last):
  File "", line 1, in 
  File "/home/matthew/dev/source/coltrane/models.py", line 3, in

from django.db import models
  File "/usr/local/lib/python2.6/dist-packages/django/db/__init__.py",
line 10, in 
if not settings.DATABASE_ENGINE:
  File "/usr/local/lib/python2.6/dist-packages/django/utils/
functional.py", line 269, in __getattr__
self._setup()
  File "/usr/local/lib/python2.6/dist-packages/django/conf/
__init__.py", line 38, in _setup
raise ImportError("Settings cannot be imported, because
environment variable %s is undefined." % ENVIRONMENT_VARIABLE)
ImportError: Settings cannot be imported, because environment variable
DJANGO_SETTINGS_MODULE is undefined.

I then found a thread about DJANGO_SETTINGS_MODULE here
http://groups.google.com/group/django-users/browse_thread/thread/be0f814d1cf896f
and set DJANGO_SETTINGS_MODULE to simply 'settings' like it suggests.
I then got this:

>>> from coltrane.models import Category
Traceback (most recent call last):
  File "", line 1, in 
  File "/home/matthew/dev/source/coltrane/models.py", line 4, in

from django.contrib.auth import User
ImportError: cannot import name User

I also imported Django, which worked fine.  Any thoughts?

Thanks,
Matt
--~--~-~--~~~---~--~~
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-threadedcomments app

2009-08-06 Thread Margie

Anyone know any status on the django-threadedcomments app?  The google
group on it seems to be inactive.  The last update I see about it is:

March 31, 2009: Released version 0.5 of the application and moved.
This is the last of this line--the next release will be a large
rewrite to use the comment extension hooks provided in Django 1.1 and
will be backwards incompatible.

Anyway, just wondering if anyone here knows anything more?

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



Getting Started, tutorial newbie

2009-08-06 Thread zignorp

Hello,
I'm going through the tutorial when I have time.  A few weeks back, I
created the polls app, was able to retrieve data and use the admin
interface and everything was beautiful.  Now I'm trying to catch up
where I left off and am having problems.  When I do the runserver
command, it tells me that the dev server is running, but I get a 404
if I click on the link.  And while I have the polls app installed, I
can't retrieve any information. I think I need some more basic info on
moving from unix to the python shell (and back). when I type python
manage.py shell, I don't get the >>> prompt.
I'm wondering if I can make some kind of startup file for myself, so I
can execute the basic commands I need to get started and set up.  Do
others do this?
Thanks for any help, I am only able to focus on this periodically.
Z
--~--~-~--~~~---~--~~
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: Why two identical entries in django.test.utils.ContextList while testing?

2009-08-06 Thread ristretto.rb

Ah, that's it.  Thanks Karen.  What an awesome quick response.   My
mistake.

Thanks
gene


On Aug 7, 10:28 am, Karen Tracey  wrote:
> On Thu, Aug 6, 2009 at 5:41 PM, ristretto.rb  wrote:
>
> > Hello,
>
> > I'm working on some unit tests using the Client that comes with
> > subclassing django.test.TestCase.
>
> > When run code like this
>
> >  response = self.client.get("/project/usecase")
>
> > The object response.context is a list type object containing two
> > identical Dictionaries.
>
> The doc for this test response 
> attribute:http://docs.djangoproject.com/en/dev/topics/testing/#django.test.clie...
>
> notes that "If the rendered page used multiple templates, then context will
> be a list of Context objects, in the order in which they were rendered."
>
> So I expect your page used multiple templates?
>
> Karen
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Why two identical entries in django.test.utils.ContextList while testing?

2009-08-06 Thread Karen Tracey
On Thu, Aug 6, 2009 at 5:41 PM, ristretto.rb  wrote:

>
> Hello,
>
> I'm working on some unit tests using the Client that comes with
> subclassing django.test.TestCase.
>
> When run code like this
>
>  response = self.client.get("/project/usecase")
>
> The object response.context is a list type object containing two
> identical Dictionaries.


The doc for this test response attribute:
http://docs.djangoproject.com/en/dev/topics/testing/#django.test.client.Response.context

notes that "If the rendered page used multiple templates, then context will
be a list of Context objects, in the order in which they were rendered."



So I expect your page used multiple templates?

Karen

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



Re: ValueError when uploading image

2009-08-06 Thread Malcolm MacKinnon
I think I've fixed the problem. It had to so with  PIL not being installed
correctly. Check out this link:
http://www.answermysearches.com/fixing-pil-ioerror-decoder-jpeg-not-available/320/for
a possible solution. Now, jpeg images are uploaded and saved.


On Thu, Aug 6, 2009 at 6:42 PM, Mac  wrote:

>
> Hi,
>
> I'm new to Django and programming in general. I've been trying to
> create a form that simply uploads images and saves them to a app
> folder. I'm using MySql with Django svn. Here's my model:
>
> class Images(models.Model):
>prim = models.AutoField(primary_key=True, db_column='PRIM') #
> Field name made lowercase.
>photos = models.ImageField(db_column='PHOTOS', upload_to='img',
> blank=True) # Field name made lowercase.
>items = models.CharField(max_length=255, db_column='ITEMS',
> blank=True) # Field name made lowercase.
>date = models.DateField(null=True, db_column='DATE', blank=True) #
> Field name made lowercase.
>class Meta:
>db_table = u'IMAGES'
>
> Here's my view:
> class PictureForm(ModelForm):
>   class Meta:
>   model=Images
>   exclude = ('prim',)
>
> def image_loads(request):
>form=PictureForm()
>if request.method=='POST':
>form=PictureForm(request.POST,  request.FILES)
>if form.is_multipart():
>form.save()
>form=PictureForm()
>return render_to_response('photos.html', {'form':form,  },
> context_instance = RequestContext(request))
>
>return render_to_response('photos.html', {'form':form,  },
> context_instance = RequestContext(request))
>
> Here's photo.html:
>
> {%extends "base.html" %}
>
> {%block head%}
> {%endblock%}
> {%block content%}
>
> 
>
> {{ form.as_p }}
> 
> 
> {% if comment %}
> {{comment}}
> {%endif%}
>
> {%endblock%}
>
> Here's the error message:
> Environment:
>
> Request Method: POST
> Request URL: http://localhost:8000/photos/
> Django Version: 1.1 beta 1 SVN-10891
> Python Version: 2.5.2
> Installed Applications:
> ['django.contrib.auth',
>  'django.contrib.contenttypes',
>  'django.contrib.sessions',
>  'django.contrib.sites',
>  'django.contrib.admin',
>  'orders1.onhand',
>  'registration']
> Installed Middleware:
> ('django.middleware.common.CommonMiddleware',
>  'django.contrib.csrf.middleware.CsrfMiddleware',
>  'django.contrib.sessions.middleware.SessionMiddleware',
>  'django.contrib.auth.middleware.AuthenticationMiddleware')
>
>
> Traceback:
> File "/usr/lib/python2.5/site-packages/django/core/handlers/base.py"
> in get_response
>  92. response = callback(request, *callback_args,
> **callback_kwargs)
> File "/home/malcolm/data1/orders1/../orders1/onhand/views.py" in
> image_loads
>  49. form.save()
> File "/usr/lib/python2.5/site-packages/django/forms/models.py" in save
>  407.  fail_message, commit,
> exclude=self._meta.exclude)
> File "/usr/lib/python2.5/site-packages/django/forms/models.py" in
> save_instance
>  42.  " validate." % (opts.object_name,
> fail_message))
>
> Exception Type: ValueError at /photos/
> Exception Value: The Images could not be created because the data
> didn't validate.
>
> Any help or suggestions would be greatly appreciated. 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: access to REQUEST_URI ?

2009-08-06 Thread Alex Koshelev
Hi, Rebecca!

Try to use request's `get_full_path` [1] method. It's environment
independent and produces full path string with query.

[1]:
http://docs.djangoproject.com/en/dev/ref/request-response/#django.http.HttpRequest.get_full_path

---
Alex Koshelev


On Fri, Aug 7, 2009 at 1:37 AM, Rebecca K  wrote:

>
> I'm working on an ARK (Archival Resource Key) resolver in django, and
> as part of the ARK spec I need to recognize and distinguish urls
> ending with '?' and '??'  (no query string or anything else
> following).
>
> When I run my django app through mod_wsgi, I have access to
> request.META['REQUEST_URI'], which contains the path plus the question
> mark.  When I run my django app with manage.py runserver, I get a key
> error when I try to access REQUEST_URI.  Same thing when I use the
> django test client.
>
> Anyone have any thoughts on how I can access the REQUEST_URI
> consistently no matter what environment the django app is running in?
>
> I'm not tied to using REQUEST_URI-- if there are other ways to detect
> the '?' on the end of the url, that serves my purpose just as well.
> But it seems that the all of the django HttpRequest object functions
> and properties have path and query string values that are too
> sanitized and don't give me access to this.
>
> Thanks in advance for any help or suggestions.
>
> >
>

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



Mod_wsgi and Apache Problems - Unhandled request return Internal Server Error / Premature end of script headers

2009-08-06 Thread pcrutch

So I run the dev server for my project and everything comes up fine,
map shows properly and loads the data correctly. However, using wsgi
the map loads and gives " Unhandled request return Internal Server
Error" and I checked the log file and I have the " premature end of
script headers" error. I have no clue why it won't load the data on
the map properly.

here is my sites-available file


   
ServerName dragonfly.cens.ucla.edu

WSGIDaemonProcess dragonfly.cens.ucla.edu threads=25
WSGIProcessGroup dragonfly.cens.ucla.edu

WSGIScriptAlias / /home/patrick/geodj/apache/sitez.wsgi

Order deny,allow
Allow from all


ErrorLog /var/log/apache2/error.log
LogLevel warn

CustomLog /var/log/apache2/access.log combined


-
sites-enabled file


#Basic setup
ServerAdmin pcrutc...@ucla.edu
ServerName dragonfly.cens.ucla.edu
ServerAlias dragonfly.cens.ucla.edu


Order deny,allow
Allow from all


LogLevel warn
ErrorLog  /home/patrick/geodj/apache_error.log
CustomLog /home/patrick/geodj/apache_access.log combined

WSGIDaemonProcess dragonfly.cens.ucla.edu threads=25
WSGIProcessGroup dragonfly.cens.ucla.edu

WSGIScriptAlias / /home/patrick/geodj/apache/sitez.wsgi


-
my project .wsgi file

import os, sys
sys.path.append('/home/patrick/geodj')
sys.path.append('/home/patrick/geodj/templates')


os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'

import django.core.handlers.wsgi

application = django.core.handlers.wsgi.WSGIHandler()

What gives?


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



Why two identical entries in django.test.utils.ContextList while testing?

2009-08-06 Thread ristretto.rb

Hello,

I'm working on some unit tests using the Client that comes with
subclassing django.test.TestCase.

When run code like this

  response = self.client.get("/project/usecase")

The object response.context is a list type object containing two
identical Dictionaries.  So, this errors ...

  self.assertTrue(response.context.has_key('blah'),"Blah not home.")

But, this works

  self.assertTrue(response.context[0].has_key('blah'),"Blah not
home.")

or this

  self.assertTrue(response.context[1].has_key('blah'),"Blah not
home.")

Not sure why there are two.  Any ideas?

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



access to REQUEST_URI ?

2009-08-06 Thread Rebecca K

I'm working on an ARK (Archival Resource Key) resolver in django, and
as part of the ARK spec I need to recognize and distinguish urls
ending with '?' and '??'  (no query string or anything else
following).

When I run my django app through mod_wsgi, I have access to
request.META['REQUEST_URI'], which contains the path plus the question
mark.  When I run my django app with manage.py runserver, I get a key
error when I try to access REQUEST_URI.  Same thing when I use the
django test client.

Anyone have any thoughts on how I can access the REQUEST_URI
consistently no matter what environment the django app is running in?

I'm not tied to using REQUEST_URI-- if there are other ways to detect
the '?' on the end of the url, that serves my purpose just as well.
But it seems that the all of the django HttpRequest object functions
and properties have path and query string values that are too
sanitized and don't give me access to this.

Thanks in advance for any help or suggestions.

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



linking to an image in an HttpResponse on development web server

2009-08-06 Thread cabenson

Hello,
Using the builtin/development web server, I am trying to embed an  tag in an html response within HttpResponse, but am having no
luck with the link to the image.  Specifically:

Here's my return statement:
return HttpResponse('')

Here are the relevant strings in settings.py:
MEDIA_ROOT = '/yadda1/yadda2/yadda3/yadda4/images/'
MEDIA_URL = 'http://localhost:8000/'

(The image file mygraphic.png is in the path indicated by MEDIA_ROOT).


When I try this at the browser (for which there is  URL regex to map
it to the right view):
http://localhost:8000/

I get the broken image icon in the browser with this source:


and I get this at the command line where I launched the server:
[06/Aug/2009 13:57:29] "GET / HTTP/1.1" 200 79
[06/Aug/2009 13:57:29] "GET /billingbarchart.png HTTP/1.1" 404 1999


Other observations:
I know that I'm getting to the view function, because I am able to
successfully get the image when I replace the above return statement
with:

 image_data = open( "/mylocalpath/mygraphic.png","rb" ).read()
 return HttpResponse(image_data,mimetype="image/png")


Any help or suggestions are appreciated.
Chuck



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



Re: Django/ Python 3 - nervous about starting large project

2009-08-06 Thread Wayne Koorts

Hi Tony,

> @Wayne: Thanks for the welcome.  Why are you using 2.5 for your new/
> large project instead of 2.6?

It just seems to be the "sweet spot" release at the moment.  I just
found that a few of the libraries I had been using, even in the last
couple of months, had some kind of problem with anything over 2.5.  I
really wanted to start using 2.6 but for some reason 2.5 seems to be
the most all-round compatible release of them all.  Also it seems that
most shared hosting providers use 2.5 by default.

Regards,
Wayne

--~--~-~--~~~---~--~~
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: python md5

2009-08-06 Thread Asinox

Thanks guys :)

On Aug 6, 2:32 pm, James Bennett  wrote:
> On Thu, Aug 6, 2009 at 1:16 PM, Asinox wrote:
> > Thanks Alex Gaynor :) is working :)
>
> It's very important to note that the documentation for this module
> would have given you the same information. In general, you should be
> doing your best to read and familiarize yourself with documentation so
> that you'll be able to answer your own questions and be more
> productive.
>
> --
> "Bureaucrat Conrad, you are technically correct -- the best kind of correct."
--~--~-~--~~~---~--~~
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: getting current page URL in a Django Template

2009-08-06 Thread Daniel Roseman

On Aug 6, 9:33 pm, NealWalters  wrote:
> Is there a keyword that will automatically put the URL of the current
> page in the Django form?
> Or do I have to do that in code and pass it to the form as a normal
> user variable?
>
> Here's what I'm trying to accomplish. I have a feedback form on a base
> template.  When the user clicks the feedback button, it will post to /
> submitFeedback.  One of my database fields is the URL, so I know which
> screen the users was commenting on.
>
> Thanks,
> Neal Walters

If you use RequestContext with the request context_processor, your
template context will always include the request object - from where
you can get request.path which is the current URL. See
http://docs.djangoproject.com/en/dev/ref/templates/api/#id1
http://docs.djangoproject.com/en/dev/ref/request-response/
--
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: Customzing form fields in Admin in list_editable mode?

2009-08-06 Thread Adam V.

Bug entered w/ patch: http://code.djangoproject.com/ticket/11651

On Jun 18, 1:24 pm, Alex Gaynor  wrote:
> On Thu, Jun 18, 2009 at 3:21 PM, Adam V.  wrote:
>
> > Alex, thanks; that's what I was afraid of.
> > If no one else has, I'd be willing to take a stab at a patch for 1.2.
>
> > On Jun 18, 12:40 pm, Alex Gaynor  wrote:
> > > On Thu, Jun 18, 2009 at 2:38 PM, Adam V.  wrote:
>
> > > > When enabling bulk edit mode for an Admin list view, is it possible to
> > > > control the widgets used? For the normal editor you can of course
> > > > specify a custom form, but I'm not seeing a way to customize the
> > > > fields in the list view.
>
> > > > Basically, I want to specify that some text fields fields in the list
> > > > view render shorter than the default.
>
> > > > I can hack this in with some fairly gross after-the-fact client-side
> > > > JavaScript, but I'd rather be able to specify this behavior in my
> > > > admin.ModelAdmin if the ability exists.
>
> > > Unfortunately there isn't a super good way to do this.  list_editalbe
> > uses
> > > the formfield_for_dbfield option just like rendering the normal form
> > does,
> > > however this obviously doesn't give you a ton of flexibility.  One thing
> > you
> > > could do for now, until we fix this, is to check the URL of the request
> > > object that formfield_for_dbfield gets.
>
> > > Alex
>
> > > --
> > > "I disapprove of what you say, but I will defend to the death your right
> > to
> > > say it." --Voltaire
> > > "The people's good is the highest law."--Cicero
>
> Yeah, my instinct for the patch would just be to create a new method,
> formfield_for_dbfield_for_list_editable (but with a better name ;) ) and
> have it by defualt just call formfield_for_dbfield and make the
> list_editable form creation use it.  Then by default people will see the
> same behavior, but there will be a specific method users can override to
> change it.  If you're interested in working on a patch I'd be more than
> happy to look it over, although as you've said, it won't make it in until
> 1.2.
>
> Alex
>
> --
> "I disapprove of what you say, but I will defend to the death your right to
> say it." --Voltaire
> "The people's good is the highest law."--Cicero
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



getting current page URL in a Django Template

2009-08-06 Thread NealWalters

Is there a keyword that will automatically put the URL of the current
page in the Django form?
Or do I have to do that in code and pass it to the form as a normal
user variable?

Here's what I'm trying to accomplish. I have a feedback form on a base
template.  When the user clicks the feedback button, it will post to /
submitFeedback.  One of my database fields is the URL, so I know which
screen the users was commenting on.

Thanks,
Neal Walters
--~--~-~--~~~---~--~~
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: checking/using model data in form save

2009-08-06 Thread Daniel Roseman

On Aug 6, 8:36 pm, zayatzz  wrote:
> Hello
>
> I am not entirely sure if i am asking the right question, but here is
> what am trying to do.
>
> I am saving user mugshot with form and it works just fine. I rename
> the uploaded file to mugshot.[insert imagefile extension here], but i
> want to do more in form save method than just that.
>
> 1) i want to check if the model, whos form im saving already has
> imagefile saved. I have this in view:
> pform = ProfileForm(instance=profile)
>
> but this in form save:
>                         os.remove(settings.MEDIA_ROOT+self.instance.img)
>
> returns me ImageFieldFile not the data that is saved in it... and i
> get typeerror:
> TypeError at /profile/edit/
>
> cannot concatenate 'str' and 'ImageFieldFile' objects
>
> 2) if it exists, then remove it - can do it os.remove(), but the
> problem is similar to last point - i need to know the name of existing
> file, that is saved in model data
> 3) if the file has been removed or did not exist in the first place
> then i want to save different sizes of the file - thumbnail, bigger
> pic and so on. i do not need the examples for that.
>
> Alan

self.instance.img.name will give you the relative path from
MEDIA_ROOT. See:
http://docs.djangoproject.com/en/dev/ref/files/file/#django.core.files.File.name
--
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
-~--~~~~--~~--~--~---



checking/using model data in form save

2009-08-06 Thread zayatzz

Hello

I am not entirely sure if i am asking the right question, but here is
what am trying to do.

I am saving user mugshot with form and it works just fine. I rename
the uploaded file to mugshot.[insert imagefile extension here], but i
want to do more in form save method than just that.

1) i want to check if the model, whos form im saving already has
imagefile saved. I have this in view:
pform = ProfileForm(instance=profile)

but this in form save:
os.remove(settings.MEDIA_ROOT+self.instance.img)

returns me ImageFieldFile not the data that is saved in it... and i
get typeerror:
TypeError at /profile/edit/

cannot concatenate 'str' and 'ImageFieldFile' objects

2) if it exists, then remove it - can do it os.remove(), but the
problem is similar to last point - i need to know the name of existing
file, that is saved in model data
3) if the file has been removed or did not exist in the first place
then i want to save different sizes of the file - thumbnail, bigger
pic and so on. i do not need the examples for that.

Alan
--~--~-~--~~~---~--~~
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: cache and multple languages

2009-08-06 Thread cwurld

Hi,

Thanks for the response and for sharing your code. It looks like it is
exactly what I need. I am somewhat surprised that functionality is not
a standard part of django.

I will give it a try sometime next week!

Thanks again,
Chuck

On Aug 5, 5:17 pm, kmike  wrote:
> Hi,
> I've recently create an app for advanced view caching. It allow pages
> to be cached based on anything in request, specific cookies for
> example.
> Please checkhttp://bitbucket.org/kmike/django-view-cache-utils/wiki/Home
>
> If you have any questions about it feel free to ask.
>
> On 5 авг, 20:11, cwurld  wrote:
>
> > Hi,
>
> > I have been successfully running a multi-language site for a while
> > now. The users language pref is stored (along with other data) in a
> > cookie.
>
> > Recently, I have been trying to cache some of the more common and
> > processor intensive views. Since the language code is not in the url,
> > I can't figure out how to cache pages based on language.
>
> > I looked in to the vary_on_header decorator, but I do not see how to
> > get that to work since the cookies vary on lots of stuff in addition
> > to language and I doubt I can get my users to change the Accept-
> > Language attribute in the request header.
>
> > Any ideas?
>
> > Thanks,
> > Chuck
>
>
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: creating a list of sql that is executed

2009-08-06 Thread Shawn Milochik

Look for the post_save signal.

Once you can attach your own function to that signal (make it listen  
for the signal and kick something off), you can probably have Django  
dump the raw SQL query that is created to a text file. I don't know  
the syntax for that, but check the django.db docs.

Having said that, this seems like a really hacky workaround. I'd see  
if there's some "best practices" method of having distributed  
databases that can sync. I'm guessing it's not going to work with  
sqlite3, though.


If it's a Django site, why aren't you hitting the same database from  
work that you are from home, anyway? I'd think you'd be using the same  
URL. The only exception is if you're doing some development at home in  
a test bed, but then the data you create wouldn't be "real" and  
shouldn't go into the production database.

Shawn

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



Re: python md5

2009-08-06 Thread James Bennett

On Thu, Aug 6, 2009 at 1:16 PM, Asinox wrote:
> Thanks Alex Gaynor :) is working :)

It's very important to note that the documentation for this module
would have given you the same information. In general, you should be
doing your best to read and familiarize yourself with documentation so
that you'll be able to answer your own questions and be more
productive.


-- 
"Bureaucrat Conrad, you are technically correct -- the best kind of correct."

--~--~-~--~~~---~--~~
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 much DB queries is too much?

2009-08-06 Thread Daniel Roseman

On Aug 6, 5:07 pm, koranthala  wrote:
> Hi,
>    I am designing a website with Django and Apache. This is my first
> foray to web designing, even though I have quite a bit of experience
> in another area.
>    The logic for the site is somewhat involved - It is better to think
> of it as more of an application rather than a site.
>    The problem is as follows:
>    On an average, every GET query for the home page takes about 400 DB
> Queries. I am now running it in my personal machine, with the Apache
> and PostgreSQL DB all running in my machine itself. Here, it takes
> around 5 seconds to complete a GET query. Please note that  have used
> the select_related etc quite liberally.
>    I feel that the query count is too high. I earlier tried to solve
> it using memoization - wherein the query count came down to ~100, but
> since I have moved from development server to Apache, I removed it
> since I had written a thread-unsafe memoization.
>    One of the reasons the query count is this high is because of the
> high modularization - I reuse many code again and again, so each code
> tries to get the data again. One way I can think of improving
> performance is by destroying the modularization. But that would be my
> last choice.
>
>    Since this is my first application, could you please let me know
> whether this is too high?
>    Should I try to improve the memoization code - say using a memoized
> data passed all over?
>
>    What are the other ways to improve the performance?
>
> TIA
> K

How long is a piece of string? How many is too many depends on your
hardware, the rest of your stack (are you caching the page?), the
expectations of your users (if they're internal they might not mind a
slow page render), and all sorts of things.

400 queries *is* high, but we have a high-traffic website with a very
complex home page that has a similar query count. That said, I've been
spending a lot of time on it to reduce that, and have a version in
development which renders the same page in about 80 queries - quite an
improvement. I guess I've been using similar techniques to you -
memoization of complex queries within model instances.

In my experience there isn't any issue with thread safety. As long as
you're keeping it within a specific instance, there's no reason to
think it should be unsafe. For example:

class MyModel(models.Model):

def get_complexquery(self):
if not hasattr(self, '_complexquery'):
self._complexquery = do_complex_stuff()
return self._complexquery

Now the value of '_complexquery' is stored solely within the model
instance, which is created within the context of a specific request
and discarded at the end. No doubt someone will correct me, but I
can't see how that would be thread-unsafe.

There are various other optimisations that can be done - judicious use
of select_related can work wonders, for example - and of course you
can always fall back on raw SQL if there's really no way of expressing
a multiply-joined query within the ORM.

--
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: python md5

2009-08-06 Thread Asinox

Thanks Alex Gaynor :) is working :)

On Aug 6, 1:57 pm, Alex Gaynor  wrote:
> On Thu, Aug 6, 2009 at 12:55 PM, Asinox wrote:
>
> > Hi guys, please i need to know why md5 return this:
>
> > 
>
> > the way that im using:
>
> > def encriptar():
> >    toEncode = pickle.dumps(datetime.now)
> >    encoded = md5.new(toEncode)
>
> >    return encoded
>
> > Thanks
>
> You can call the hexdigest() method on the md5 object to get a string
> of the hash.
>
> Alex
>
> --
> "I disapprove of what you say, but I will defend to the death your
> right to say it." -- Voltaire
> "The people's good is the highest law." -- Cicero
> "Code can always be simpler than you think, but never as simple as you
> want" -- Me
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: python md5

2009-08-06 Thread Peter Herndon

On 08/06/2009 01:55 PM, Asinox wrote:
> Hi guys, please i need to know why md5 return this:
>
> 
>
>
> the way that im using:
>
> def encriptar():
>  toEncode = pickle.dumps(datetime.now)
>  encoded = md5.new(toEncode)
>
>  return encoded
>

Because encoded is an md5 hash *object*.  You can add more strings to 
the hash with the update() method.  Then, when you are finished adding 
things, you call the digest() or hexdigest() method to retrieve the 
value of the hash.  It isn't just a one-time hashing function that 
returns the value of the single item you pass to it.

--~--~-~--~~~---~--~~
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: Im lost with Save function in model and saving data from Form

2009-08-06 Thread Asinox

Thanks Daniel for reply

ill tell u my problem, this form work fine in the User Panel , but in
the Admin dont work.

exactly my problem:

i have a form... when the form is saved, im saving "pub_date" data in
another database table, that is fine in the User Panel, but in the
Admin panel don't work. i know that im lost with overriding the Save()
function, bcz i dont know where exactly ill put this, im reading
django doc's a lot, but im lost with this part.

Thanks



On Aug 6, 2:00 pm, Daniel Roseman  wrote:
> On Aug 6, 6:38 pm, Asinox  wrote:
>
>
>
>
>
> > Hi guys, i need a litter help, i know that if i want a Form from Model
> > i need to use ModelForm, but im lost with something... i have a view
> > that render a Form (ModelFrom) and save this, but now i need to use
> > the  funcion SAVE in the  Model (for use in the admin)... but im
> > lost... bcz in the view form i have a litter code saving some data
> > like Date, etc... in this way:
>
> > obj = form.save(commit = false)
>
> > obj.pub_date = datetime.now
>
> > ---
>
> > but now i need to know if the SAVE function need to be in the both
> > place's (model and view function) sorry i need a litter sample...
>
> > Thanks and sorry
>
> I don't understand your problem. You've used form.save with
> commit=False to create an unsaved model instance, then changed the
> pub_date. Now all you need to do is obj.save() to save it to the
> database.
> --
> DR.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Im lost with Save function in model and saving data from Form

2009-08-06 Thread Daniel Roseman

On Aug 6, 6:38 pm, Asinox  wrote:
> Hi guys, i need a litter help, i know that if i want a Form from Model
> i need to use ModelForm, but im lost with something... i have a view
> that render a Form (ModelFrom) and save this, but now i need to use
> the  funcion SAVE in the  Model (for use in the admin)... but im
> lost... bcz in the view form i have a litter code saving some data
> like Date, etc... in this way:
>
> obj = form.save(commit = false)
>
> obj.pub_date = datetime.now
>
> ---
>
> but now i need to know if the SAVE function need to be in the both
> place's (model and view function) sorry i need a litter sample...
>
> Thanks and sorry

I don't understand your problem. You've used form.save with
commit=False to create an unsaved model instance, then changed the
pub_date. Now all you need to do is obj.save() to save it to the
database.
--
DR.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django TimeField Model without seconds

2009-08-06 Thread Paulo Almeida
Hi,

Streamweaver wasn't suggesting assigning 00 to every time, just hiding what
you don't want to show using views or templates. For instance:

http://docs.djangoproject.com/en/dev/ref/templates/builtins/#time

- Paulo

On Thu, Aug 6, 2009 at 6:47 PM, Hellnar  wrote:

>
> Hello,
> I need this because it is a task specific requirement for my project
> (a television broadcast flow management which only consists of HH:MM
> format).I will let the user login via the admin panel and add these
> broadcast flows includint those times thus each addition with
> assigning HH:MM:00  would be royal pain :)
> Cheers
>
> On 6 Ağustos, 20:37, Streamweaver  wrote:
> > I'm not really sure you can but I'm also not clear why this is a
> > problem.  It would seem easy to just not use seconds and filter them
> > out in the template and views as needed.  Is this practical for your
> > needs or is there a specific benefit you're seeking by filtering out
> > seconds from the field?
> >
> > On Aug 6, 1:26 pm, Hellnar  wrote:
> >
> >
> >
> > > Greetings, I am trying to implement a TimeField model which only
> > > consists of HH:MM (ie 16:46) format, I know it is possible to format a
> > > regular Python time object but I am lost about how to manage this with
> > > Django.
> >
> > > Cheers
> >
>

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



Re: python md5

2009-08-06 Thread Alex Gaynor

On Thu, Aug 6, 2009 at 12:55 PM, Asinox wrote:
>
> Hi guys, please i need to know why md5 return this:
>
> 
>
>
> the way that im using:
>
> def encriptar():
>    toEncode = pickle.dumps(datetime.now)
>    encoded = md5.new(toEncode)
>
>    return encoded
>
>
> Thanks
> >
>

You can call the hexdigest() method on the md5 object to get a string
of the hash.

Alex

-- 
"I disapprove of what you say, but I will defend to the death your
right to say it." -- Voltaire
"The people's good is the highest law." -- Cicero
"Code can always be simpler than you think, but never as simple as you
want" -- Me

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



python md5

2009-08-06 Thread Asinox

Hi guys, please i need to know why md5 return this:




the way that im using:

def encriptar():
toEncode = pickle.dumps(datetime.now)
encoded = md5.new(toEncode)

return encoded


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: Django TimeField Model without seconds

2009-08-06 Thread Hellnar

Hello,
I need this because it is a task specific requirement for my project
(a television broadcast flow management which only consists of HH:MM
format).I will let the user login via the admin panel and add these
broadcast flows includint those times thus each addition with
assigning HH:MM:00  would be royal pain :)
Cheers

On 6 Ağustos, 20:37, Streamweaver  wrote:
> I'm not really sure you can but I'm also not clear why this is a
> problem.  It would seem easy to just not use seconds and filter them
> out in the template and views as needed.  Is this practical for your
> needs or is there a specific benefit you're seeking by filtering out
> seconds from the field?
>
> On Aug 6, 1:26 pm, Hellnar  wrote:
>
>
>
> > Greetings, I am trying to implement a TimeField model which only
> > consists of HH:MM (ie 16:46) format, I know it is possible to format a
> > regular Python time object but I am lost about how to manage this with
> > Django.
>
> > Cheers
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Re: Django/ Python 3 - nervous about starting large project

2009-08-06 Thread Streamweaver

I came from the PHP world myself and am even doing some of it still
but I don't think what you're saying is of particular concern.

Even in PHP you have to worry about differences in PHP 4 and 5 and so
on so the concern itself isn't just a Python one.  I can say that
support for Python 2.6 will be around for a long time and transitions
in Python for me have always been much easier than in PHP.   If you're
fairly new to Python I doubt you're really venturing into the areas
that will be of major concern in a transition as well.

Good luck with it and Welcome to the Python end of the pool.

On Aug 5, 4:47 pm, snfctech  wrote:
> Hello.
>
> We are researching technologies to begin what may become a pretty
> large intranet Dashboard project.
>
> I'm a PHP developer, so the fact that Django uses Python doesn't give
> me a head-start - but I've been wanting to consider it, because I am
> interested in learning Python.
>
> However, I'm nervous about the Python 3 situation.  What if I start
> building a large project based on Django/Python 2.6, and then a year
> or two down the road the project starts limping because of all of the
> cool new Python 3 modules coming out?  And I've got a bunch of Django/
> Python 2.6 code that needs to be ported?
>
> Any tips would be greatly appreciated.  Thanks.
>
> Tony
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Im lost with Save function in model and saving data from Form

2009-08-06 Thread Asinox

Hi guys, i need a litter help, i know that if i want a Form from Model
i need to use ModelForm, but im lost with something... i have a view
that render a Form (ModelFrom) and save this, but now i need to use
the  funcion SAVE in the  Model (for use in the admin)... but im
lost... bcz in the view form i have a litter code saving some data
like Date, etc... in this way:

obj = form.save(commit = false)

obj.pub_date = datetime.now


---

but now i need to know if the SAVE function need to be in the both
place's (model and view function) sorry i need a litter sample...

Thanks and sorry



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



Re: Django TimeField Model without seconds

2009-08-06 Thread Streamweaver

I'm not really sure you can but I'm also not clear why this is a
problem.  It would seem easy to just not use seconds and filter them
out in the template and views as needed.  Is this practical for your
needs or is there a specific benefit you're seeking by filtering out
seconds from the field?

On Aug 6, 1:26 pm, Hellnar  wrote:
> Greetings, I am trying to implement a TimeField model which only
> consists of HH:MM (ie 16:46) format, I know it is possible to format a
> regular Python time object but I am lost about how to manage this with
> Django.
>
> Cheers
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



Django TimeField Model without seconds

2009-08-06 Thread Hellnar

Greetings, I am trying to implement a TimeField model which only
consists of HH:MM (ie 16:46) format, I know it is possible to format a
regular Python time object but I am lost about how to manage this with
Django.

Cheers

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



Re: comparing date and datetime

2009-08-06 Thread Gustavo Henrique

Sorry, it were an human error!
Solved!



-- 
Gustavo Henrique
http://www.gustavohenrique.net
http://blog.gustavohenrique.net

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



ValueError when uploading image

2009-08-06 Thread Mac

Hi,

I'm new to Django and programming in general. I've been trying to
create a form that simply uploads images and saves them to a app
folder. I'm using MySql with Django svn. Here's my model:

class Images(models.Model):
prim = models.AutoField(primary_key=True, db_column='PRIM') #
Field name made lowercase.
photos = models.ImageField(db_column='PHOTOS', upload_to='img',
blank=True) # Field name made lowercase.
items = models.CharField(max_length=255, db_column='ITEMS',
blank=True) # Field name made lowercase.
date = models.DateField(null=True, db_column='DATE', blank=True) #
Field name made lowercase.
class Meta:
db_table = u'IMAGES'

Here's my view:
class PictureForm(ModelForm):
   class Meta:
   model=Images
   exclude = ('prim',)

def image_loads(request):
form=PictureForm()
if request.method=='POST':
form=PictureForm(request.POST,  request.FILES)
if form.is_multipart():
form.save()
form=PictureForm()
return render_to_response('photos.html', {'form':form,  },
context_instance = RequestContext(request))

return render_to_response('photos.html', {'form':form,  },
context_instance = RequestContext(request))

Here's photo.html:

{%extends "base.html" %}

{%block head%}
{%endblock%}
{%block content%}



{{ form.as_p }}


{% if comment %}
{{comment}}
{%endif%}

{%endblock%}

Here's the error message:
Environment:

Request Method: POST
Request URL: http://localhost:8000/photos/
Django Version: 1.1 beta 1 SVN-10891
Python Version: 2.5.2
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.admin',
 'orders1.onhand',
 'registration']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.csrf.middleware.CsrfMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware')


Traceback:
File "/usr/lib/python2.5/site-packages/django/core/handlers/base.py"
in get_response
  92. response = callback(request, *callback_args,
**callback_kwargs)
File "/home/malcolm/data1/orders1/../orders1/onhand/views.py" in
image_loads
  49. form.save()
File "/usr/lib/python2.5/site-packages/django/forms/models.py" in save
  407.  fail_message, commit,
exclude=self._meta.exclude)
File "/usr/lib/python2.5/site-packages/django/forms/models.py" in
save_instance
  42.  " validate." % (opts.object_name,
fail_message))

Exception Type: ValueError at /photos/
Exception Value: The Images could not be created because the data
didn't validate.

Any help or suggestions would be greatly appreciated. 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
-~--~~~~--~~--~--~---



comparing date and datetime

2009-08-06 Thread Gustavo Henrique

Hi!
I'm trying to compare 2 dates and appears the error message:
can't compare datetime.datetime to datetime.date

But in the shell is ok. why?

date1 = models.DateField()
date2 = datetime.date.today()

--~--~-~--~~~---~--~~
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: Get current user outside a view / without an request object

2009-08-06 Thread Julián C . Pérez

Bingo!!!
:D
I follow this:
http://oebfare.com/blog/2008/feb/23/changing-modelchoicefield-queryset/
and now I'm happy with mi desired current user based queryset
Thank you all!

BTW, my form class finally looks like...
---
class SendMessageForm(forms.Form):

recipientUser = ShowValidContactList
(queryset=None,label=u'Send to')
messageSubject= forms.CharField(label=u'Subject')
messageContent = forms.CharField
(label=u'Content',widget=forms.Textarea())

def __init__(self, inputUser, *args, **kwargs):
   self.user= inputUser
   super(SendMessageForm, self).__init__(*args, **kwargs)
   self.fields['recipientUser'].queryset = # Anything with
the current user, in this case 'self.user'
---

On Aug 6, 11:14 am, Julián C. Pérez  wrote:
> Thanks for reply, Paulo
> But if I...
> ---
> class SendMessageForm(forms.Form):
>
>         recipientUser = ShowValidContactList(currentUser=self.user,
> label=u'Send to')
>         messageSubject= forms.CharField(label=u'Subject')
>         messageContent = forms.CharField(label=u'Content',
> widget=forms.Textarea())
>
>         def __init__(self, inputUser, *args, **kwargs):
>                self.user= inputUser
>                super(SendMessageForm, self).__init__(*args, **kwargs)
> ---
> the 'recipientUser = ShowValidContactList(currentUser=self.user,
> label=u'Send to')' raises error because of that 'self.user' ('self'
> wouldn't be defined and be out of scope)
>
> On Aug 6, 11:09 am, Paulo Almeida  wrote:
>
> > It doesn't have to be a callable, you can just do something like:
>
> > recipientUser = ShowValidContactList(currentUser=self.currentUser)
>
> > I never used that kwargs.pop function (I didn't know you could do that),
> >  but I have code like this:
>
> > class ExperimentForm(ModelForm):
> >     """ Generate form to handle experiment information. """
> >     def __init__(self, user, *args, **kwargs):
> >         super(ExperimentForm, self).__init__(*args, **kwargs)
> >         try:
> >             preferences = Preferences.objects.get(user=user)
>
> > That last 'user' is just what came from the function call in the view.
>
> > - Paulo
>
> > 2009/8/6 Julián C. Pérez 
>
> > > My real problem it that the field should looks like:
> > > ---
> > > recipientUser = ShowValidContactList(currentUser=_something_,
> > > label=u'Send to')
> > > ---
> > > and if I have a form's init method like...
> > > ---
> > > def __init__(self, *args, **kwargs):
> > >    self.currentUser = kwargs.pop('currentUser', None)
> > >    super(SendMessageForm, self).__init__(*args, **kwargs)
> > > ---
> > > it won't change the current user already defined in the field
>
> > > Now, I want to make something like...
> > > ---
> > > recipientUser = ShowValidContactList(currentUser=getCurrentUser,
> > > label=u'Send to')
> > > ---
> > > where 'getCurrentUser' is a callable function similar to:
> > > ---
> > > def get_image_path(instance, filename):
> > >    return 'photos/%s/%s' % (instance.id, filename)
>
> > > class Photo(models.Model):
> > >    image = models.ImageField(upload_to=get_image_path)
> > > ---
> > > how can I do that?
>
> > > On Aug 6, 9:58 am, Daniel Roseman  wrote:
> > > > On Aug 6, 3:34 pm, Julián C. Pérez  wrote:
>
> > > > > Hi
> > > > > I tried doing that...
> > > > > But it does not work
> > > > > For example, if I do something like...
> > > > > ---
> > > > > class SendMessageForm(forms.Form):
> > > > >         recipientUser = ShowValidContactList(label=u'Send to')
> > > > >         messageSubject= forms.CharField(label=u'Subject')
> > > > >         messageContent = forms.CharField
> > > > > (label=u'Content',widget=forms.Textarea())
> > > > >         def __init__(self, currentUser):
> > > > >                 self.currentUser = currentUser
> > > > >                 super(SendMessageForm, self).__init__(*args, **kwargs)
> > > > > ---
> > > > > that init method in my custom form class won't change anything in the
> > > > > already defined ShowValidContactList field
>
> > > > Because you are clobbering the existing parameters to __init__. You
> > > > should do it like this:
>
> > > > def __init__(self, *args, **kwargs):
> > > >     self.currentUser = kwargs.pop('currentUser', None)
> > > >     super(SendMessageForm, self).__init__(*args, **kwargs)
>
> > > > --
> > > > 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: Get current user outside a view / without an request object

2009-08-06 Thread Paulo Almeida
But why don't you put:

recipientUser = ShowValidContactList(currentUser=self.user)

inside the __init__?

- Paulo

2009/8/6 Julián C. Pérez 

>
> Thanks for reply, Paulo
> But if I...
> ---
> class SendMessageForm(forms.Form):
>
>recipientUser = ShowValidContactList(currentUser=self.user,
> label=u'Send to')
>messageSubject= forms.CharField(label=u'Subject')
>messageContent = forms.CharField(label=u'Content',
> widget=forms.Textarea())
>
> def __init__(self, inputUser, *args, **kwargs):
>   self.user= inputUser
>super(SendMessageForm, self).__init__(*args, **kwargs)
> ---
> the 'recipientUser = ShowValidContactList(currentUser=self.user,
> label=u'Send to')' raises error because of that 'self.user' ('self'
> wouldn't be defined and be out of scope)
>
> On Aug 6, 11:09 am, Paulo Almeida  wrote:
> > It doesn't have to be a callable, you can just do something like:
> >
> > recipientUser = ShowValidContactList(currentUser=self.currentUser)
> >
> > I never used that kwargs.pop function (I didn't know you could do that),
> >  but I have code like this:
> >
> > class ExperimentForm(ModelForm):
> > """ Generate form to handle experiment information. """
> > def __init__(self, user, *args, **kwargs):
> > super(ExperimentForm, self).__init__(*args, **kwargs)
> > try:
> > preferences = Preferences.objects.get(user=user)
> >
> > That last 'user' is just what came from the function call in the view.
> >
> > - Paulo
> >
> > 2009/8/6 Julián C. Pérez 
> >
> >
> >
> > > My real problem it that the field should looks like:
> > > ---
> > > recipientUser = ShowValidContactList(currentUser=_something_,
> > > label=u'Send to')
> > > ---
> > > and if I have a form's init method like...
> > > ---
> > > def __init__(self, *args, **kwargs):
> > >self.currentUser = kwargs.pop('currentUser', None)
> > >super(SendMessageForm, self).__init__(*args, **kwargs)
> > > ---
> > > it won't change the current user already defined in the field
> >
> > > Now, I want to make something like...
> > > ---
> > > recipientUser = ShowValidContactList(currentUser=getCurrentUser,
> > > label=u'Send to')
> > > ---
> > > where 'getCurrentUser' is a callable function similar to:
> > > ---
> > > def get_image_path(instance, filename):
> > >return 'photos/%s/%s' % (instance.id, filename)
> >
> > > class Photo(models.Model):
> > >image = models.ImageField(upload_to=get_image_path)
> > > ---
> > > how can I do that?
> >
> > > On Aug 6, 9:58 am, Daniel Roseman  wrote:
> > > > On Aug 6, 3:34 pm, Julián C. Pérez  wrote:
> >
> > > > > Hi
> > > > > I tried doing that...
> > > > > But it does not work
> > > > > For example, if I do something like...
> > > > > ---
> > > > > class SendMessageForm(forms.Form):
> > > > > recipientUser = ShowValidContactList(label=u'Send to')
> > > > > messageSubject= forms.CharField(label=u'Subject')
> > > > > messageContent = forms.CharField
> > > > > (label=u'Content',widget=forms.Textarea())
> > > > > def __init__(self, currentUser):
> > > > > self.currentUser = currentUser
> > > > > super(SendMessageForm, self).__init__(*args,
> **kwargs)
> > > > > ---
> > > > > that init method in my custom form class won't change anything in
> the
> > > > > already defined ShowValidContactList field
> >
> > > > Because you are clobbering the existing parameters to __init__. You
> > > > should do it like this:
> >
> > > > def __init__(self, *args, **kwargs):
> > > > self.currentUser = kwargs.pop('currentUser', None)
> > > > super(SendMessageForm, self).__init__(*args, **kwargs)
> >
> > > > --
> > > > 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
-~--~~~~--~~--~--~---



Different types of users, requiring different models

2009-08-06 Thread Ludwik Trammer

Hello,

I'm a developer for a Polish NGO, owning 5 schools in Warsaw. My
organization decided to throw out our antiquated custom PHP intranet
system (everything school needs: timetables, grades, reports,
announcements, forums, etc. ) and design a brand new one using Django.
And to Open Source it. I hope we will do a good job, since it's our
first project in Django. Anyway, here is our question:

There will be 3 distinct types of users: teachers, students and
parents. Each type needs model with different fields extending the
User model (for example only parent has ManyToMany relationship with
students, to connect him with his children, and only student has a
ForeignKey connecting him to a class etc.).

Given a User instance we need to be able to easily check for its
account type (teacher/student/parent) and then to retrieve appropriate
fields. What is the best way to design this models?

I can think of at least 3 ways to do this, but I don't know if any of
them really make sense. For example we can have a simple field with
account type in user's profile and then separate Student, Teacher, and
Parent models, each with a one-to-one field pointing back at user
model. It would allow us to do things like this:

profile = request.user.get_profile()
if profile.objects.account_type == 'parent':
children = request.user.parent.children

Another idea is to make a subclass of the User model for every type of
account. It would work very similarly to the example above (are there
any pros or cons of this method?)

We could also use a generic relationship connecting user profile to
appropriate account type model (either Teacher, Student or Parent). We
could then have instance methods with common names for all three
models, for example instance method get_type() would return "student"
for Student model and "teacher" for teacher model, and instance method
get_schools() would return list of schools user is linked to (one of
requirement for the system is support for multiple schools; every
account is linked with schools in different way - student can only be
in one school at the time, but teacher can work in many schools, and
parent is linked to all schools his kids are attend. That's why you
need
an instance method, different for every model). The code could work
like that (granted that generic relationship's field name is "type"):

account_type = request.user.type.get_type()
if account_type == 'parent':
children = request.user.type.children
elif account_type == 'student':
 class = request.user.type.class

and also:

schools = request.user.type.get_schools() # schools linked to this
account

So, is there a proper way to do this?

Thanks,
Ludwik
--~--~-~--~~~---~--~~
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: Get current user outside a view / without an request object

2009-08-06 Thread Julián C . Pérez

Thanks for reply, Paulo
But if I...
---
class SendMessageForm(forms.Form):

recipientUser = ShowValidContactList(currentUser=self.user,
label=u'Send to')
messageSubject= forms.CharField(label=u'Subject')
messageContent = forms.CharField(label=u'Content',
widget=forms.Textarea())

def __init__(self, inputUser, *args, **kwargs):
   self.user= inputUser
   super(SendMessageForm, self).__init__(*args, **kwargs)
---
the 'recipientUser = ShowValidContactList(currentUser=self.user,
label=u'Send to')' raises error because of that 'self.user' ('self'
wouldn't be defined and be out of scope)

On Aug 6, 11:09 am, Paulo Almeida  wrote:
> It doesn't have to be a callable, you can just do something like:
>
> recipientUser = ShowValidContactList(currentUser=self.currentUser)
>
> I never used that kwargs.pop function (I didn't know you could do that),
>  but I have code like this:
>
> class ExperimentForm(ModelForm):
>     """ Generate form to handle experiment information. """
>     def __init__(self, user, *args, **kwargs):
>         super(ExperimentForm, self).__init__(*args, **kwargs)
>         try:
>             preferences = Preferences.objects.get(user=user)
>
> That last 'user' is just what came from the function call in the view.
>
> - Paulo
>
> 2009/8/6 Julián C. Pérez 
>
>
>
> > My real problem it that the field should looks like:
> > ---
> > recipientUser = ShowValidContactList(currentUser=_something_,
> > label=u'Send to')
> > ---
> > and if I have a form's init method like...
> > ---
> > def __init__(self, *args, **kwargs):
> >    self.currentUser = kwargs.pop('currentUser', None)
> >    super(SendMessageForm, self).__init__(*args, **kwargs)
> > ---
> > it won't change the current user already defined in the field
>
> > Now, I want to make something like...
> > ---
> > recipientUser = ShowValidContactList(currentUser=getCurrentUser,
> > label=u'Send to')
> > ---
> > where 'getCurrentUser' is a callable function similar to:
> > ---
> > def get_image_path(instance, filename):
> >    return 'photos/%s/%s' % (instance.id, filename)
>
> > class Photo(models.Model):
> >    image = models.ImageField(upload_to=get_image_path)
> > ---
> > how can I do that?
>
> > On Aug 6, 9:58 am, Daniel Roseman  wrote:
> > > On Aug 6, 3:34 pm, Julián C. Pérez  wrote:
>
> > > > Hi
> > > > I tried doing that...
> > > > But it does not work
> > > > For example, if I do something like...
> > > > ---
> > > > class SendMessageForm(forms.Form):
> > > >         recipientUser = ShowValidContactList(label=u'Send to')
> > > >         messageSubject= forms.CharField(label=u'Subject')
> > > >         messageContent = forms.CharField
> > > > (label=u'Content',widget=forms.Textarea())
> > > >         def __init__(self, currentUser):
> > > >                 self.currentUser = currentUser
> > > >                 super(SendMessageForm, self).__init__(*args, **kwargs)
> > > > ---
> > > > that init method in my custom form class won't change anything in the
> > > > already defined ShowValidContactList field
>
> > > Because you are clobbering the existing parameters to __init__. You
> > > should do it like this:
>
> > > def __init__(self, *args, **kwargs):
> > >     self.currentUser = kwargs.pop('currentUser', None)
> > >     super(SendMessageForm, self).__init__(*args, **kwargs)
>
> > > --
> > > 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: Get current user outside a view / without an request object

2009-08-06 Thread Paulo Almeida
It doesn't have to be a callable, you can just do something like:

recipientUser = ShowValidContactList(currentUser=self.currentUser)

I never used that kwargs.pop function (I didn't know you could do that),
 but I have code like this:

class ExperimentForm(ModelForm):
""" Generate form to handle experiment information. """
def __init__(self, user, *args, **kwargs):
super(ExperimentForm, self).__init__(*args, **kwargs)
try:
preferences = Preferences.objects.get(user=user)

That last 'user' is just what came from the function call in the view.

- Paulo

2009/8/6 Julián C. Pérez 

>
> My real problem it that the field should looks like:
> ---
> recipientUser = ShowValidContactList(currentUser=_something_,
> label=u'Send to')
> ---
> and if I have a form's init method like...
> ---
> def __init__(self, *args, **kwargs):
>self.currentUser = kwargs.pop('currentUser', None)
>super(SendMessageForm, self).__init__(*args, **kwargs)
> ---
> it won't change the current user already defined in the field
>
> Now, I want to make something like...
> ---
> recipientUser = ShowValidContactList(currentUser=getCurrentUser,
> label=u'Send to')
> ---
> where 'getCurrentUser' is a callable function similar to:
> ---
> def get_image_path(instance, filename):
>return 'photos/%s/%s' % (instance.id, filename)
>
> class Photo(models.Model):
>image = models.ImageField(upload_to=get_image_path)
> ---
> how can I do that?
>
> On Aug 6, 9:58 am, Daniel Roseman  wrote:
> > On Aug 6, 3:34 pm, Julián C. Pérez  wrote:
> >
> >
> >
> > > Hi
> > > I tried doing that...
> > > But it does not work
> > > For example, if I do something like...
> > > ---
> > > class SendMessageForm(forms.Form):
> > > recipientUser = ShowValidContactList(label=u'Send to')
> > > messageSubject= forms.CharField(label=u'Subject')
> > > messageContent = forms.CharField
> > > (label=u'Content',widget=forms.Textarea())
> > > def __init__(self, currentUser):
> > > self.currentUser = currentUser
> > > super(SendMessageForm, self).__init__(*args, **kwargs)
> > > ---
> > > that init method in my custom form class won't change anything in the
> > > already defined ShowValidContactList field
> >
> > Because you are clobbering the existing parameters to __init__. You
> > should do it like this:
> >
> > def __init__(self, *args, **kwargs):
> > self.currentUser = kwargs.pop('currentUser', None)
> > super(SendMessageForm, self).__init__(*args, **kwargs)
> >
> > --
> > 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
-~--~~~~--~~--~--~---



How much DB queries is too much?

2009-08-06 Thread koranthala

Hi,
   I am designing a website with Django and Apache. This is my first
foray to web designing, even though I have quite a bit of experience
in another area.
   The logic for the site is somewhat involved - It is better to think
of it as more of an application rather than a site.
   The problem is as follows:
   On an average, every GET query for the home page takes about 400 DB
Queries. I am now running it in my personal machine, with the Apache
and PostgreSQL DB all running in my machine itself. Here, it takes
around 5 seconds to complete a GET query. Please note that  have used
the select_related etc quite liberally.
   I feel that the query count is too high. I earlier tried to solve
it using memoization - wherein the query count came down to ~100, but
since I have moved from development server to Apache, I removed it
since I had written a thread-unsafe memoization.
   One of the reasons the query count is this high is because of the
high modularization - I reuse many code again and again, so each code
tries to get the data again. One way I can think of improving
performance is by destroying the modularization. But that would be my
last choice.

   Since this is my first application, could you please let me know
whether this is too high?
   Should I try to improve the memoization code - say using a memoized
data passed all over?

   What are the other ways to improve the performance?

TIA
K

--~--~-~--~~~---~--~~
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: Application decoupling - project architecture question

2009-08-06 Thread Paulo Almeida
I'm far from being an expert, but maybe you can look at the django-tagging
code for inspiration:

http://code.google.com/p/django-tagging/

What they do is to provide a TagField in the tagging application, and then
you can use that field in the form of the application using tags. You can
probably do something similar with an AvatarField.

- Paulo

On Thu, Aug 6, 2009 at 4:07 PM, Andrin Riiet  wrote:

>
> Hi, I'd like to shed some light on the "the right way" to make
> applications in django by an example and a few questions.
>
> Let's say that I have a 'users' application (acting as "user profiles"
> on the built-in user authentication system) and I want to add an
> avatar image feature to it.
> I'd like to have the avatars in a separate application in case my next
> project doesn't require them (this is the right way to do things i
> guess?)
>
> Now I want to have the user to be able to upload an avatar image in
> the "edit profile" form. The default edit-profile form is defined in
> my 'users' application of course. I'd like to "add" the avatar feature
> (form field) to it somehow. - This is part 1 of the problem
>
> The 2nd part is in the form handling: the request object is going to
> contain form field values from 2 different applications, none of which
> should be responsible for processing the other's forms.
>
> Obviously the 'avatars' application is dependent on the 'users'
> application but the 'users' application should be oblivious of the
> avatars...
>
> How would I go about doing that?
>
> Andrin
>
> >
>

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



Re: Django/ Python 3 - nervous about starting large project

2009-08-06 Thread snfctech

Thanks for the tips, Berco, Wayne.

@Wayne: Thanks for the welcome.  Why are you using 2.5 for your new/
large project instead of 2.6?

Tony

On Aug 5, 2:22 pm, Wayne Koorts  wrote:
> Hi Tony,
>
> > However, I'm nervous about the Python 3 situation.  What if I start
> > building a large project based on Django/Python 2.6, and then a year
> > or two down the road the project starts limping because of all of the
> > cool new Python 3 modules coming out?  And I've got a bunch of Django/
> > Python 2.6 code that needs to be ported?
>
> First of all, welcome to the Python world, we'll do our best to make
> you feel comfortable here.
>
> You'll find that the Python crowd is very good at supporting legacy
> versions.  You'll see that you can even still download [1] Python
> 1.5.2 (April 1999!).  That's not to say that your favourite libraries
> will be available for such old versions, but many libraries still make
> releases for at least as far back as Python 2.3.  Also, I don't think
> you'll find that Python 3.x will introduce anything so radically new
> and innovative that it will severely limit what you can accomplish
> with older releases.  I'm working on a team starting a new (large)
> project now which we are basing around Python 2.5.
>
> Remember that Python has been around for a long time, since 1991, and
> releases like 2.5, 2.6 etc. are extremely mature and by now all of the
> common programming problems have already been encountered, solved and
> accomodated in the core and standard libraries.
>
> If you do decide to port your application to 3.x (think very carefully
> about it first - make sure that any of the associated libraries you
> require have mature 3.x releases) there are tools available to make
> the job a lot easier, like the 2to3 [2] script.
>
> [1]http://www.python.org/download/
> [2]http://www.python.org/doc/2.6/library/2to3.html
>
> HTH,
>
> Regards,
> Wayne Koortshttp://www.wkoorts.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: Use of the ORM in long running (non web) daemon

2009-08-06 Thread wam

On Aug 6, 3:20 am, Russell Keith-Magee  wrote:
> What you have described shouldn't require any particularly special
> handling. I have code in production that does exactly the same thing -
> a daemonized process that responds to requests on a port, does some
> processing, and saves the result to the database. You shouldn't need
> to do anything exotic with connection or transaction handling.
>
> As for the cause of your problem - my immediate thought is that your
> processing+save steps aren't as simple as you think they are. In
> particular, if you're getting:
>
> >   InternalError: current transaction is aborted, commands ignored
> > until end of transaction block
>
> then something is going wrong in your code - somewhere, an error isn't
> being handled properly. However, without specifics, it's hard to
> narrow down the problem. Time to crack open the debugger to see
> exactly what sequence of events is leading to errors.

Except that I can't seem to reproduce the problem reliably. It's an
error I only see in production, none of my test cases activate it and
even when I run it within a test environment, the problem has yet to
crop up.

> The only other alarm bell that is ringing for me is that your errors
> are related to SET ISOLATION LEVEL requests, and you're using
> Postgres.

There are two things odd about these errors. The first is that db
backed for postgresql appears to set an isolation level on every new
database connection, immediately after opening the connection (in the
django.db.backends.postgresql.base.DatabaseWrapper._cursor() method).
The second  is that the errors are being triggered by a simple get()
on queryset.

  File "mycode.py", line 165, in task
job = models.Job.objects.get(id=int(job.body))
  File ".../lib/python2.5/site-packages/django/db/models/manager.py",
line 93, in get
return self.get_query_set().get(*args, **kwargs)
  File ".../lib/python2.5/site-packages/django/db/models/query.py",
line 304, in get
num = len(clone)
  File ".../lib/python2.5/site-packages/django/db/models/query.py",
line 160, in __len__
self._result_cache = list(self.iterator())
  File ".../lib/python2.5/site-packages/django/db/models/query.py",
line 275, in iterator
for row in self.query.results_iter():
  File ".../lib/python2.5/site-packages/django/db/models/sql/
query.py", line 206, in results_iter
for rows in self.execute_sql(MULTI):
  File ".../lib/python2.5/site-packages/django/db/models/sql/
query.py", line 1734, in execute_sql
cursor.execute(sql, params)
  File ".../lib/python2.5/site-packages/django/db/backends/util.py",
line 19, in execute
return self.cursor.execute(sql, params)
  InternalError: SET TRANSACTION ISOLATION LEVEL must be called before
any query

This particular daemon does a lot of reading before it ever (if ever)
actually does a write. Looking into how the ORM is set up by default,
it appears a transaction is opened up and stays open until a save()
occurs. If a save() doesn't occur, will I hit a limit on my
transaction size?

> Out of interest - are you using the autocommit feature added
> to Django in v1.1?

Nope, I'm currently using Django v1.0.2 (likely upgrading to 1.0.3
rsn).

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



Admin Image upload control disabled?

2009-08-06 Thread Daniel Brown

Good morning list,

I've been working on a simple Django blog as a learning exercise and
today I've been following this blog post about a simple way to add
images to blog posts. My changes run fine on Django's test server
without errors, however the image related part of the BlogPost's admin
page seems to be disabled, its visible but not interactive. I've made
sure the images folder exists and I've even deleted and rebuilt the
database but I cannot seem to get the images part of the admin form to
be enabled in Firefox (I'm on Mac OS X and using Django 1.1 with the
latest release of PIL).

The complete contents of my models.py is as follows:

from django.db import models
from django.contrib import admin
from markdown import markdown

class Image( models.Model ):
name = models.CharField( max_length=100 )
image = models.ImageField( upload_to="images" )

def __unicode__( self ):
return self.name

class BlogPost( models.Model ):
title = models.CharField( max_length = 150 )
body = models.TextField()
body_html = models.TextField(editable=False, blank=True, null=True)
images = models.ManyToManyField( Image, blank=True )
timestamp = models.DateTimeField()

def save(self):
# Save first to get keys (etc) created
super( BlogPost, self).save()
# Now process images and markdown
image_ref = ""
for image in self.images.all():
image_url = settings.MEDIA_URL + image.image.url
image_ref = "%s\n[%s]: %s" % ( image_ref, image, image_url )

mdText = "%s\n%s" % ( self.body, image_ref )
self.body_html = markdown( mdText, ['codehilite(force_linenos=True)'] )
# Save again to save processed Markdown
super( BlogPost, self).save()

class Meta:
ordering = ( '-timestamp', )

class BlogPostAdmin( admin.ModelAdmin ):
list_display = ( 'title', 'timestamp' )

class Media:
js = ( 'js/wmd/wmd.js', )

admin.site.register(BlogPost, BlogPostAdmin)

I've also tried disabling the Markdown related parts and that save
function without success.

--~--~-~--~~~---~--~~
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: Get current user outside a view / without an request object

2009-08-06 Thread Julián C . Pérez

My real problem it that the field should looks like:
---
recipientUser = ShowValidContactList(currentUser=_something_,
label=u'Send to')
---
and if I have a form's init method like...
---
def __init__(self, *args, **kwargs):
self.currentUser = kwargs.pop('currentUser', None)
super(SendMessageForm, self).__init__(*args, **kwargs)
---
it won't change the current user already defined in the field

Now, I want to make something like...
---
recipientUser = ShowValidContactList(currentUser=getCurrentUser,
label=u'Send to')
---
where 'getCurrentUser' is a callable function similar to:
---
def get_image_path(instance, filename):
return 'photos/%s/%s' % (instance.id, filename)

class Photo(models.Model):
image = models.ImageField(upload_to=get_image_path)
---
how can I do that?

On Aug 6, 9:58 am, Daniel Roseman  wrote:
> On Aug 6, 3:34 pm, Julián C. Pérez  wrote:
>
>
>
> > Hi
> > I tried doing that...
> > But it does not work
> > For example, if I do something like...
> > ---
> > class SendMessageForm(forms.Form):
> >         recipientUser = ShowValidContactList(label=u'Send to')
> >         messageSubject= forms.CharField(label=u'Subject')
> >         messageContent = forms.CharField
> > (label=u'Content',widget=forms.Textarea())
> >         def __init__(self, currentUser):
> >                 self.currentUser = currentUser
> >                 super(SendMessageForm, self).__init__(*args, **kwargs)
> > ---
> > that init method in my custom form class won't change anything in the
> > already defined ShowValidContactList field
>
> Because you are clobbering the existing parameters to __init__. You
> should do it like this:
>
> def __init__(self, *args, **kwargs):
>     self.currentUser = kwargs.pop('currentUser', None)
>     super(SendMessageForm, self).__init__(*args, **kwargs)
>
> --
> 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
-~--~~~~--~~--~--~---



Application decoupling - project architecture question

2009-08-06 Thread Andrin Riiet

Hi, I'd like to shed some light on the "the right way" to make
applications in django by an example and a few questions.

Let's say that I have a 'users' application (acting as "user profiles"
on the built-in user authentication system) and I want to add an
avatar image feature to it.
I'd like to have the avatars in a separate application in case my next
project doesn't require them (this is the right way to do things i
guess?)

Now I want to have the user to be able to upload an avatar image in
the "edit profile" form. The default edit-profile form is defined in
my 'users' application of course. I'd like to "add" the avatar feature
(form field) to it somehow. - This is part 1 of the problem

The 2nd part is in the form handling: the request object is going to
contain form field values from 2 different applications, none of which
should be responsible for processing the other's forms.

Obviously the 'avatars' application is dependent on the 'users'
application but the 'users' application should be oblivious of the
avatars...

How would I go about doing that?

Andrin

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



Re: looking for a clean, easy way to force user to change password on first login

2009-08-06 Thread ZhangZheng

you can use
process_response(self,request,response)

in the process_response, you can do :
if requst.user is in the first-login table, you can redirect URL to 
change-passwd page

a little suggestion,


pjv 写道:
> i thought of something along those lines. that's exactly the kind of
> thing that i was originally searching for -- a way to do it without
> cluttering things up and without building a bunch of unnecessary
> infrastructure or hacking core django code.
>
> unfortunately, when you do those nice reset emails, the token that
> gets generated is only good for ten minutes. since we'll be triggering
> the email to go out to a bunch of users, there is no way to know when
> they will get the email or respond to it.
>
> it would be really cool if there were a checkbox on the standard
> django user admin page that said "Force password change on next
> login".
>
> On Jul 26, 10:54 am, Roland van Laar  wrote:
>   
>> Ronghui Yu wrote:
>> 
>>> How about writing a decorator?
>>>   
>> That's possible, although there is an easier way:
>>
>> The best way imho is to generate a random password when you
>> create the user, and to send them a password reset email.
>> Which can be implemented using django.contrib.auth.
>>
>> That way they don't have to know the random password, and
>> they can't login until they have set a new password.
>>
>> And that way there is no need to have extra fields in the models.
>>
>> Regards,
>>
>> Roland van Laar
>> 
>
> >
>
>   


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



DateInput widget, format attr & ugettext

2009-08-06 Thread cArkraus

Hey all,

I cant seem to get my (non-model-)forms datefield localized.

Here's my first attempt:
some_date = fields.DateField(widget=widgets.DateInput(format=ugettext
('%d.%m.%Y')))

That's working fine, until the user switches his sessions language.
Then, the date is still shown in the format(ie. '%d.%m.%Y') and not
the correctly localized one(ie. '%Y-%m-%d').

Now, if I change to ugettext_lazy() like this:

some_date = fields.DateField(widget=widgets.DateInput
(format=ugettext_lazy('%d.%m.%Y')))

I get a TemplateSyntaxError 'strftime() argument 1 must be string or
read-only buffer, not __proxy__'

I'm pretty stuck - it's my first i18n project. Could somebody help me
out, please?

Cheers & thx for any pointer!
Carsten

--~--~-~--~~~---~--~~
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: Runtime error when uploading image files

2009-08-06 Thread Malcolm MacKinnon
Thanks, Karen. I really appreciate all the time you put in looking at this
and your comments are very informative. You were right about naming the
primary key PK (I thought Django would like that, but it doesn't). I changed
it to PRIM and the model form renders the way it should in photos.html. I
did run into one more problem: when I try to save a jpeg image, I get a
ValueError exception:

The Images could not be created because the data didn't validate.

I know the file is a jpeg file. Here is my new form and view:

class PictureForm(ModelForm):
   class Meta:
   model=Images
   exclude = ('prim',)

def image_loads(request):
form=PictureForm()
if request.method=='POST':
form=PictureForm(request.POST,  request.FILES)
if form.is_multipart:
form.save(commit=False)
form.save()
form=PictureForm()
return render_to_response('photos.html', {'form':form,  },
context_instance = RequestContext(request))




return render_to_response('photos.html', {'form':form,  },
context_instance = RequestContext(request))
Here is the error:
Environment:

Request Method: POST
Request URL: http://localhost:8000/photos/
Django Version: 1.1 beta 1 SVN-10891
Python Version: 2.5.2
Installed Applications:
['django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.admin',
 'orders1.onhand',
 'registration']
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.csrf.middleware.CsrfMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware')


Traceback:
File "/usr/lib/python2.5/site-packages/django/core/handlers/base.py" in
get_response
  92. response = callback(request, *callback_args,
**callback_kwargs)
File "/home/malcolm/data1/orders1/../orders1/onhand/views.py" in image_loads
  49. form.save(commit=False)
File "/usr/lib/python2.5/site-packages/django/forms/models.py" in save
  407.  fail_message, commit,
exclude=self._meta.exclude)
File "/usr/lib/python2.5/site-packages/django/forms/models.py" in
save_instance
  42.  " validate." % (opts.object_name,
fail_message))

Exception Type: ValueError at /photos/
Exception Value: The Images could not be created because the data didn't
validate.

I get the same error when I include the field PRIM. Again, thanks for your
time. I've put in hours trying to figure this out, and your comments were
great.

On Thu, Aug 6, 2009 at 3:32 PM, Karen Tracey  wrote:

>
> On Aug 6, 1:56 am, Mac  wrote:
> > Hi,
> >
> > I'm new to django. When I try to upload image files, I get runtime
> > errors. Here's my model:
> > models.py
> >
> > class Images(models.Model):
> > pk = models.IntegerField(primary_key=True, db_column='PK') # Field
> > name made lowercase.
>
> Unless you are going to be manually assigning values here -- and I
> don't see any evidence of that in your code -- you probably want this
> to be an AutoField, not an IntegerField.  Based on the comments in
> this model I'm guessing that it was auto-generated by inspectdb.  Note
> the results of inspectdb are meant to serve as a starting point for
> your models, and in most cases will require some tweaking, such as
> changing this generated IntegerField to an AutoField, assuming you
> want this to be the automatically-assigned primary key field for the
> model.
>
> There's also another problem with this field but we'll get to that
> later.
>
> > photos = models.ImageField(db_column='PHOTOS', upload_to='img',
> > blank=True) # Field name made lowercase.
> > items = models.CharField(max_length=255, db_column='ITEMS',
> > blank=True) # Field name made lowercase.
> > date = models.DateField(null=True, db_column='DATE', blank=True) #
> > Field name made lowercase.
> > class Meta:
> > db_table = u'IMAGES'
> >
> > Here's my view:
> > rom django.core.files.uploadedfile import SimpleUploadedFile
> > from PIL import Image
> > Image.init()
> > class PictureForm(forms.Form):
> >pic=forms.ImageField()
> >def create(self, file):
> > mymodel = Images()
> > mymodel.save_image_file(file.name, file, save=True)
> > return mymodel
> >
>
> This looks very odd.  If you want a form to allow you to upload an
> image and save an Images model instances, why not use a ModelForm?
>
> > def image_loads(request):
> > form=PictureForm()
> > if request.method=='POST':
> > form=PictureForm(request.POST,  request.FILES)
> > if form.is_valid:
>
> This line will always evaluate to True, regardless of whether or not
> the form would pass validation.  is_valid is a method, so you need to
> call it:
>
> if form.is_valid():
>
> They way you have written it you are simply checking to see if the
> form has the attribute is_valid, which it always will.
>
>
> > form.create(req

Re: Get current user outside a view / without an request object

2009-08-06 Thread Daniel Roseman

On Aug 6, 3:34 pm, Julián C. Pérez  wrote:
> Hi
> I tried doing that...
> But it does not work
> For example, if I do something like...
> ---
> class SendMessageForm(forms.Form):
>         recipientUser = ShowValidContactList(label=u'Send to')
>         messageSubject= forms.CharField(label=u'Subject')
>         messageContent = forms.CharField
> (label=u'Content',widget=forms.Textarea())
>         def __init__(self, currentUser):
>                 self.currentUser = currentUser
>                 super(SendMessageForm, self).__init__(*args, **kwargs)
> ---
> that init method in my custom form class won't change anything in the
> already defined ShowValidContactList field

Because you are clobbering the existing parameters to __init__. You
should do it like this:

def __init__(self, *args, **kwargs):
self.currentUser = kwargs.pop('currentUser', None)
super(SendMessageForm, self).__init__(*args, **kwargs)

--
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: How-to use SelectMultiple widget with CommaSeparatedIntegerField ?

2009-08-06 Thread nono

I was reading my post and though it was not very clear

My model uses CommaSeparatedIntegerField to store some integer values.
I want my users to use SelectMultiple widget to create/update those
integer so I put a ChoiceField with widget=SelectMultiple in my form.
My problem is that all I can get from this is a list of values (for
example [u'2', u'3']) where I expect comma separated values ("2, 3").

I hope this is a better explanation and somebody could help me


On 6 août, 14:21, nono  wrote:
> Hi,
>
> my model uses CommaSeparatedIntegerField to store a list of integer. I
> want my users to use SelectMultiple widget to create/update this field
> so I put a ChoiceField with widget=SelectMultiple in my form. My
> problem is that all I can get from this is a list of values where I
> expect comma separated values.
> Do you have a solution for me ?
>
> 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: Get current user outside a view / without an request object

2009-08-06 Thread Julián C . Pérez

Hi
I tried doing that...
But it does not work
For example, if I do something like...
---
class SendMessageForm(forms.Form):
recipientUser = ShowValidContactList(label=u'Send to')
messageSubject= forms.CharField(label=u'Subject')
messageContent = forms.CharField
(label=u'Content',widget=forms.Textarea())
def __init__(self, currentUser):
self.currentUser = currentUser
super(SendMessageForm, self).__init__(*args, **kwargs)
---
that init method in my custom form class won't change anything in the
already defined ShowValidContactList field

I also tried threadlocal's approach... but it didn't work either and
it's a weird way to do that...
I'm gonna go in a different direction, inspired by similar former
problem
Thank you alll, now I'll report with my status

On Aug 6, 1:40 am, Daniel Roseman  wrote:
> On Aug 6, 2:24 am, Julián C. Pérez  wrote:
>
>
>
> > Hi everyone
> > I'm in trouble because of a form class
> > I have a form class with attributes defined, but with one thing:
> > One of the attributes requires the current user, or al least its
> > username
>
> > The form definition in as shown below:
> > ---
> > class SendMessageForm(forms.Form):
> >         recipientUser = ShowValidContactList(label=u'Send to')
> >         messageSubject= forms.CharField(label=u'Subject')
> >         messageContent = forms.CharField(label=u'Content',
> > widget=forms.Textarea())
> > ---
>
> > As you can tell I'm trying to make a 'Send message' form to make
> > message sending available in my project... but the recipient user must
> > be in the contacts list of the current user...
> > The 'recipientUser' field is a ShowValidContactList
> > (forms.ModelChoiceField) instance... so it works with a fixed queryset
> > based on that user (the currently logged-in one)
>
> > My problem is that... how can I get the current user information
> > outside a view and without request objects??
> > Or... how can I make that form works with a different approach??
>
> > Any help would be appreciate!
>
> This is asked frequently on this group. The answer is to override the
> form's __init__ method and pass the request in there, and store it on
> a form attribute for later use.
> --
> 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
-~--~~~~--~~--~--~---



multi-table inheritance and modification of OneToOneField options

2009-08-06 Thread Jan Ostrochovsky

Hello,

http://docs.djangoproject.com/en/dev/topics/db/models/#multi-table-inheritance
says:
The inheritance relationship introduces links between the child model
and each of its parents (via an automatically-created OneToOneField).

http://docs.djangoproject.com/en/dev/ref/models/fields/#onetoonefield
says: Multi-table inheritance is implemented by adding an implicit one-
to-one relation from the child model to the parent model...

The question is: how can I set options of that implicit OneToOneField?
Most interesting is null=True / null=False.

(I want to "inherit" to one class optionally (Invoice Address) and to
one class it is required (Residence Address). Base class is Address.)

Thanks in advance.

Jan Ostrochovsky

--~--~-~--~~~---~--~~
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-pagination with search form

2009-08-06 Thread Streamweaver

Simple Pagination in Django is great but I'm having some trouble with
the best way to design pagination with querysets derived from Search
Forms.

I'm currently using the Django-Pagination middleware and it works
great but there's really pretty bad documentation on it (as with many
projects) and I can't figure the best way to pass search form
parameters between pages.

Is there a recommended Django way to handle this? GET paams, Sessions,
Cache?

I'm surprised I can't find more discussion or examples on this so that
could indicate I'm missing something very obvious and apologize before
hand if I am but could use a point in the right direction.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



formsets with internet explorer

2009-08-06 Thread Jeff Green

I am using formsets with my application but I have noticed some
behavior with internet explorer. It seems when I submit the form on
internet explorer I will get a mixture of page has expired, page not
found or blank page. But, when I use a firefox I have no problems.
Does anyone have any suggestions on resolving this issue

Thanks,
Jeff

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



ANNOUNCE:- ibm_db_django-0.1.2 IBM Dataservers backend support for Django 1.1 Released

2009-08-06 Thread Tarun Pasrija

IBM_DB_DJANGO-0.1.2
---

IBM_DB_DJANGO adaptor enables access to IBM databases from Django
applications http://www.djangoproject.com/. The adaptor is developed
and maintained by IBM.

What's New?

We are pleased to announce the release of ibm_db_django-0.1.2 to
support Django 1.1 and 1.0.x. We have kept the backward compatibility
so that users who have not migrated from 1.0.x to 1.1 can still use
the same adaptor.

Note:- Updation from from ibm_db_django-0.1.0 to ibm_db_django-0.1.2
-
The name of the adaptor (in Django terminology, the DATABASE_ENGINE)
has been changed to 'ibm_db_django' from this version onwards (in
earlier versions it was 'db2'). For your existing apps please remember
to change this once you upgrade to ibm_db_django-0.1.2

The 'DATABASE_ENGINE' field in settings.py should as below when using
ibm_db_django-0.1.2
   DATABASE_ENGINE= 'ibm_db_django'

(In version 0.1.0, it is "DATABASE_ENGINE= 'db2' " )


SVN access to the source
---
http://code.google.com/p/ibm-db/source/browse/trunk/IBM_DB/ibm_db_django/


Installation

$ easy_install ibm_db_django


Feedback/Suggestions/Issues

You can provide us feedback/suggestions, or report a bug/defect, or
ask for help by using any of the following channels:
1. Mailing us at open...@us.ibm.com
2. Opening a new issue at http://code.google.com/p/ibm-db/issues/list.
3. By opening new discussion at http://groups.google.co.in/group/ibm_db.

For prerequisites, installation steps and help details, visit -
http://code.google.com/p/ibm-db/wiki/ibm_db_django_README

Try this out and let us know you valuable feedback. Have fun.

Cheers,
Tarun Pasrija
Open Source Application Development
IBM India Software Labs

DB2 Cobra is now available. Download Express-C for free, go to:

https://www14.software.ibm.com/webapp/iwm/web/preLogin.do?source=swg-db2expressc&S_CMP=ECDDWW01&S_TACT=ACDB206

--~--~-~--~~~---~--~~
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: Runtime error when uploading image files

2009-08-06 Thread Karen Tracey

On Aug 6, 1:56 am, Mac  wrote:
> Hi,
>
> I'm new to django. When I try to upload image files, I get runtime
> errors. Here's my model:
> models.py
>
> class Images(models.Model):
>     pk = models.IntegerField(primary_key=True, db_column='PK') # Field
> name made lowercase.

Unless you are going to be manually assigning values here -- and I
don't see any evidence of that in your code -- you probably want this
to be an AutoField, not an IntegerField.  Based on the comments in
this model I'm guessing that it was auto-generated by inspectdb.  Note
the results of inspectdb are meant to serve as a starting point for
your models, and in most cases will require some tweaking, such as
changing this generated IntegerField to an AutoField, assuming you
want this to be the automatically-assigned primary key field for the
model.

There's also another problem with this field but we'll get to that
later.

>     photos = models.ImageField(db_column='PHOTOS', upload_to='img',
> blank=True) # Field name made lowercase.
>     items = models.CharField(max_length=255, db_column='ITEMS',
> blank=True) # Field name made lowercase.
>     date = models.DateField(null=True, db_column='DATE', blank=True) #
> Field name made lowercase.
>     class Meta:
>         db_table = u'IMAGES'
>
> Here's my view:
> rom django.core.files.uploadedfile import SimpleUploadedFile
> from PIL import Image
> Image.init()
> class PictureForm(forms.Form):
>    pic=forms.ImageField()
>    def create(self, file):
>         mymodel = Images()
>         mymodel.save_image_file(file.name, file, save=True)
>         return mymodel
>

This looks very odd.  If you want a form to allow you to upload an
image and save an Images model instances, why not use a ModelForm?

> def image_loads(request):
>     form=PictureForm()
>     if request.method=='POST':
>         form=PictureForm(request.POST,  request.FILES)
>         if form.is_valid:

This line will always evaluate to True, regardless of whether or not
the form would pass validation.  is_valid is a method, so you need to
call it:

if form.is_valid():

They way you have written it you are simply checking to see if the
form has the attribute is_valid, which it always will.


>             form.create(request.FILES)

Note that request.FILES is a dictionary-like object.  However your
create method above seems to be expecting an individual file.  I think
you'd see a problem here if you ever got far enough for create to try
to access its file parameter.

>
>     return render_to_response('photos.html', {'form':form,  },
> context_instance = RequestContext(request))
>
> Here's my photos.html template:
>
[snip] because I don't notice any problem there.
>
> Any ideas why? I also tried creating a ModelForm using Images as the
> model, and I got the same runtime error. Here's the details:
>

Oh, you have tried a ModelForm.  That is the right approach, go back
to it. The problem you are seeing is in no way related to using a
ModelForm and moving away from the right approach didn't get you any
closer to solving the real problem.

> Environment:
>
> Request Method: POST
> Request URL:http://localhost:8000/photos/
> Django Version: 1.1 beta 1 SVN-10891
> Python Version: 2.5.2
> Installed Applications:
> ['django.contrib.auth',
>  'django.contrib.contenttypes',
>  'django.contrib.sessions',
>  'django.contrib.sites',
>  'django.contrib.admin',
>  'orders1.onhand',
>  'registration']
> Installed Middleware:
> ('django.middleware.common.CommonMiddleware',
>  'django.contrib.csrf.middleware.CsrfMiddleware',
>  'django.contrib.sessions.middleware.SessionMiddleware',
>  'django.contrib.auth.middleware.AuthenticationMiddleware')
>
> Traceback:
> File "/usr/lib/python2.5/site-packages/django/core/handlers/base.py"
> in get_response
>   92.                 response = callback(request, *callback_args,
> **callback_kwargs)
> File "/home/malcolm/data1/orders1/../orders1/onhand/views.py" in
> image_loads
>   50.             form.create(request.FILES)
> File "/home/malcolm/data1/orders1/../orders1/onhand/views.py" in
> create
>   41.         mymodel = Images()
> File "/usr/lib/python2.5/site-packages/django/db/models/base.py" in
> __init__

Note how far you have gotten into your code.  This problem has nothing
to do with uploading files: you are running into trouble simply trying
to create an Images instance.  I suggest you take some time to do some
basic verification that things like your model definitions are working
before jumping into creating views and forms and templates, etc.
Playing around in the Python shell with your models, making sure you
can properly access existing ones and create new ones, is really
something that should be done before you start writing a lot of other
code.  It is very worthwhile and makes everything go smoother if you
make sure that piece A works before building B,C, and D which all
depend on A.

>   313.                 setattr(self, field.attname, val)
> File "/usr/lib/python2.5/site-packages/django/d

Re: syncdb does not find app on the PYTHONPATH

2009-08-06 Thread Daniel Roseman

On Aug 6, 1:32 pm, Matthew  wrote:
> $ ~/dev/source/cms: pwd
> /home/matthew/dev/source/cms
> $ ~/dev/source/cms: python
> Python 2.6.2 (release26-maint, Apr 19 2009, 01:58:18)
> [GCC 4.3.3] on linux2
> Type "help", "copyright", "credits" or "license" for more information.>>> 
> import coltrane
> >>> from coltrane import *
> >>> c = coltrane.Category()

But Category is in coltrane.models. So do:

from coltrane.models import Category
c = Category()

--
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: checking if db schema and model match

2009-08-06 Thread Sam Lai

Thanks for that, I'll take a look at it. I just thought given
manage.py has the ability to inspectdb, it shouldn't be that much of a
stretch to just check if the model and DB schema match.

Cheers

2009/8/6 kmike :
>
> That's a question about database migration. Django doesn't have built-
> in solution for that.
> Try using South (http://bitbucket.org/andrewgodwin/south/overview/),
> it is a very good db migration app. I suggest using development
> version because (based on my experience) it is more robust than last
> official release (0.5).
>
> On 5 авг, 18:28, Sam Lai  wrote:
>> I hope this hasn't been asked before; had a quick look through the
>> archives and docs but couldn't find anything.
>>
>> Is it possible to get django (e.g. via manage.py) to CHECK if the db
>> schema and model match? I don't want it to change anything, just to
>> tell me if there is a mismatch, and what that is.
>>
>> I thought syncdb did this, but it doesn't seem to. I think this would
>> be quite useful to have, and could pre-empt errors later on when
>> non-existent fields are used in views etc.
>>
>> Sam
> >
>

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



problems with generic object_detail view

2009-08-06 Thread andreas schmid

hi,

im trying to build an app which basically is based on the practical
django projects weblog.

my problem now is that i have a "Project" model and i can get the
archive_index view but i cant solve the object_detail url and i dont
understand where im doing wrong.

my model:

class Project(models.Model):
title   =   models.CharField(max_length=250)
type=   models.ManyToManyField(Type)
sicurezzaFinanziamento= models.BooleanField(default=False)
pub_date=  
models.DateTimeField(default=datetime.datetime.now, editable=False)
author  =   models.ForeignKey(User)
slug=   models.SlugField(unique_for_date='pub_date')
   
class Meta:
ordering=['-pub_date']
verbose_name_plural = "Projects"
   
def __unicode__(self):
return self.title
  
def get_absolute_url(self):
return ('EUprojects_project_detail', (), {'year':
self.pub_date.strftime("%Y"),
  'month':
self.pub_date.strftime("%b").lower(),
  'day':
self.pub_date.strftime("%d"),
  'slug': self.slug })
get_absolute_url = models.permalink(get_absolute_url)

the urlpattern

 
(r'^(?P\d{4})/(?P\w{3})/(?P\d{2})/(?P[-\w]+)/$',
   'object_detail',
   projects_info_dict,
   'EUprojects_project_detail'),   

{{ object.get_absolute_url }} does not output anything in the
template... why?

is something missing?

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

2009-08-06 Thread Luke Seelenbinder

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Could we have the full traceback? That really isn't enough information
to determine your problem.

Regards,

Luke
luke.seelenbin...@gmail.com


rekha wrote:
> Hi, im getting ValueError when try to redirect to an html page.. also
> the validation code in forms.py doesnt work when i test it with wrong
> inputs. it accepts the wrong input also.. what would be the bug?
> ===views.py code==
> def register(request):
>   if request.method == 'POST':
>   form = form_register(request.POST)
>   if form.is_valid():
>   reg = loginform( usr_name = 
> form.cleaned_data['usr_name'], pswd =
> form.cleaned_data['pswd'])
>   reg.save()
>   return HttpResponseRedirect('/index/')
>   #return render_to_response('thanks.html')
>   else:
>   form = form_register()
>   variables = RequestContext(request, {'form':form})
>   return render_to_response('register.html',variables)
> 
> ===forms.py code===
> class form_register(forms.Form):
>   usr_name = forms.CharField(label='Enter your user
> name:',max_length=50)
>   pswd = forms.CharField(label='Password:',widget=forms.PasswordInput
> (render_value=False))
>   def clean_usr_name(self):
>   usr_name = self.cleaned_data['usr_name']
>   if not re.search(r'^\w+$',usr_name):
>   raise forms.ValidationError('Username can only contain 
> alphanumeric
> characters and the underscore.')
>   return usr_name
> --
> ===urls.py code===
> 
> urlpatterns = patterns('',(r'^$',index),(r'^register/$',register),
> (r'^login/$',login),(r'^index/$',index),(r'^logout/$',logout_page),
> > 
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.9 (GNU/Linux)

iEYEARECAAYFAkp607UACgkQXQrGVCncjPw8XQCgknqhHrD5b6dQtZu0nvom2/Sy
P8UAoKPUkHsSbgtYHGM0gtmw6n4d5Q1B
=51xf
-END PGP SIGNATURE-

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



Re: syncdb does not find app on the PYTHONPATH

2009-08-06 Thread Matthew

==
models.py

import datetime

from django.db import models
from django.contrib.auth import User

from markdown import markdown
from tagging.fields import TagField

class Category(models.Model):
title = models.CharField(max_length=250,
help_text='Maximum 250 characters.')
slug = models.SlugField(unique=True,
help_text="Suggested automatically from
the title. Must be unique.")
description = models.TextField()

class Meta:
ordering = ['title']
verbose_name_plural = "Categories"

def __unicode__(self):
return self.title

def get_absolute_url(self):
return "/categories/%s" % self.slug

class Entry(models.Model):
LIVE_STATUS = 1
DRAFT_STATUS = 2
HIDDEN_STATUS = 3
STATUS_CHOICES = (
  (LIVE_STATUS, 'Live'),
  (DRAFT_STATUS, 'Draft'),
  (HIDDEN_STATUS, 'Hidden'),
  )

# Core fields
title = models.CharField(max_length=250,
 help_text='Maximum 250 characters.')
excerpt = models.TextField(blank=True,
   help_text="A short summary of the
entry. Optional.")
body = models.TextField()
pub_date = models.DateTimeField(default=datetime.datetime.now)

# Fields to store generated HTML
body_html = models.TextField(editable=False, blank=True)
excerpt_html = models.TextField(editable=False, blank=True)

# Metadata
author = models.ForeignKey(User)
enable_comments = models.BooleanField(default=True)
featured = models.BooleanField(default=False)
slug = models.SlugField(unique_for_date='pub_date',
help_text="Suggested value automatically
generated from title. Must be unique.")
status = models.IntegerField(choices=STATUS_CHOICES,
 default=LIVE_STATUS,
 help_text="Only entries with live
status will be publicly displayed.")

# Categorization and tagging
categories = models.ManyToManyField(Category)
tags = TagField(help_text="Separate tags with spaces.")


class Meta:
verbose_name_plural = "Entries"
ordering = ['-pub_date']

def __unicode__(self):
return self.title

def save(self, force_insert=False, force_update=False):
self.body_html = markdown(self.body)
if self.excerpt:
self.excerpt_html = markdown(self.excerpt)
super(Entry, self).save(force_insert, force_update)

def get_absolute_url(self):
return "/weblog/%s/%s/" % (self.pub_date.strftime("%Y/%b/
%d").lower(),
   self.slug)

==
Traceback:

$ ~/dev/source/cms: pwd
/home/matthew/dev/source/cms
$ ~/dev/source/cms: python
Python 2.6.2 (release26-maint, Apr 19 2009, 01:58:18)
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import coltrane
>>> from coltrane import *
>>> c = coltrane.Category()
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'module' object has no attribute 'Category'
>>> e = coltrane.Entry()
Traceback (most recent call last):
  File "", line 1, in 
AttributeError: 'module' object has no attribute 'Entry'
>>> c = Category()
Traceback (most recent call last):
  File "", line 1, in 
NameError: name 'Category' is not defined
>>> e = Entry()
Traceback (most recent call last):
  File "", line 1, in 
NameError: name 'Entry' is not defined
>>>

==
PYTHONPATH

$ ~/dev/source/cms: echo $PYTHONPATH
/home/matthew/dev/source:/home/matthew/dev/external_source

--~--~-~--~~~---~--~~
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: HttpResponseRedirect with POST

2009-08-06 Thread Sławek Tuleja

Thank you!

On 6 Sie, 14:21, Daniel Roseman  wrote:
> On Aug 6, 1:09 pm, Sławek Tuleja  wrote:
>
>
>
> > HI everyone!
>
> > Can I redirect to view with form passing few variables in POST method
> > (request.POST) and showing them in the form? (i need this in admin
> > action)
>
> > for example this works:
> > def add_mailing(self, request, queryset):
> >         return HttpResponseRedirect('%s?subject=halo' % \
> >                                         urlresolvers.reverse
> > ('admin:tenders_mailing_add'))
>
> > but this does not:
> > def add_mailing(self, request, queryset):
> >         post = request.POST.copy()
> >         post.update({'subject': 'halo'})
> >         request.POST = post
> >         return HttpResponseRedirect(urlresolvers.reverse
> > ('admin:tenders_mailing_add'))
>
> > * subject is name of text field in a form
>
> No, you can't do that - it's a limitation of http, not of Django. The
> solution is to do as in your first example and send the parameters in
> the GET, or to use the session to store them.
> --
> 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
-~--~~~~--~~--~--~---



How-to use SelectMultiple widget with CommaSeparatedIntegerField ?

2009-08-06 Thread nono

Hi,

my model uses CommaSeparatedIntegerField to store a list of integer. I
want my users to use SelectMultiple widget to create/update this field
so I put a ChoiceField with widget=SelectMultiple in my form. My
problem is that all I can get from this is a list of values where I
expect comma separated values.
Do you have a solution for me ?

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



ValueError

2009-08-06 Thread rekha

Hi, im getting ValueError when try to redirect to an html page.. also
the validation code in forms.py doesnt work when i test it with wrong
inputs. it accepts the wrong input also.. what would be the bug?
===views.py code==
def register(request):
if request.method == 'POST':
form = form_register(request.POST)
if form.is_valid():
reg = loginform( usr_name = 
form.cleaned_data['usr_name'], pswd =
form.cleaned_data['pswd'])
reg.save()
return HttpResponseRedirect('/index/')
#return render_to_response('thanks.html')
else:
form = form_register()
variables = RequestContext(request, {'form':form})
return render_to_response('register.html',variables)

===forms.py code===
class form_register(forms.Form):
usr_name = forms.CharField(label='Enter your user
name:',max_length=50)
pswd = forms.CharField(label='Password:',widget=forms.PasswordInput
(render_value=False))
def clean_usr_name(self):
usr_name = self.cleaned_data['usr_name']
if not re.search(r'^\w+$',usr_name):
raise forms.ValidationError('Username can only contain 
alphanumeric
characters and the underscore.')
return usr_name
--
===urls.py code===

urlpatterns = patterns('',(r'^$',index),(r'^register/$',register),
(r'^login/$',login),(r'^index/$',index),(r'^logout/$',logout_page),
--~--~-~--~~~---~--~~
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: HttpResponseRedirect with POST

2009-08-06 Thread Daniel Roseman

On Aug 6, 1:09 pm, Sławek Tuleja  wrote:
> HI everyone!
>
> Can I redirect to view with form passing few variables in POST method
> (request.POST) and showing them in the form? (i need this in admin
> action)
>
> for example this works:
> def add_mailing(self, request, queryset):
>         return HttpResponseRedirect('%s?subject=halo' % \
>                                         urlresolvers.reverse
> ('admin:tenders_mailing_add'))
>
> but this does not:
> def add_mailing(self, request, queryset):
>         post = request.POST.copy()
>         post.update({'subject': 'halo'})
>         request.POST = post
>         return HttpResponseRedirect(urlresolvers.reverse
> ('admin:tenders_mailing_add'))
>
> * subject is name of text field in a form

No, you can't do that - it's a limitation of http, not of Django. The
solution is to do as in your first example and send the parameters in
the GET, or to use the session to store them.
--
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: HttpResponseRedirect with POST

2009-08-06 Thread Spajderix

Hi,

wouldn't it be easier to put this data to session?

Sławek Tuleja pisze:
> HI everyone!
>
> Can I redirect to view with form passing few variables in POST method
> (request.POST) and showing them in the form? (i need this in admin
> action)
>
> for example this works:
> def add_mailing(self, request, queryset):
> return HttpResponseRedirect('%s?subject=halo' % \
> urlresolvers.reverse
> ('admin:tenders_mailing_add'))
>
> but this does not:
> def add_mailing(self, request, queryset):
> post = request.POST.copy()
> post.update({'subject': 'halo'})
> request.POST = post
> return HttpResponseRedirect(urlresolvers.reverse
> ('admin:tenders_mailing_add'))
>
> * subject is name of text field in a form
> >
>   


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



HttpResponseRedirect with POST

2009-08-06 Thread Sławek Tuleja

HI everyone!

Can I redirect to view with form passing few variables in POST method
(request.POST) and showing them in the form? (i need this in admin
action)

for example this works:
def add_mailing(self, request, queryset):
return HttpResponseRedirect('%s?subject=halo' % \
urlresolvers.reverse
('admin:tenders_mailing_add'))

but this does not:
def add_mailing(self, request, queryset):
post = request.POST.copy()
post.update({'subject': 'halo'})
request.POST = post
return HttpResponseRedirect(urlresolvers.reverse
('admin:tenders_mailing_add'))

* subject is name of text field in a form
--~--~-~--~~~---~--~~
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: Memory error

2009-08-06 Thread Tom Evans

On Wed, 2009-08-05 at 13:09 -0700, drakkan wrote:
> The code is something like this
> 
> obj=DBModels.objects.filter(somefilter)
> results=[]
> for o in obj:
>   results.append({'field1':o.field1,'field2':o.field2})
> 
> return JsonResponse(results)
> 
> where JsonResponse is a class derived from HttpResponse that add a
> simplejson.dumps
> 
> I have a really large database and in some edge case I need to return
> a large number of results (about 150.000 when I get the error). I make
> only one query with select_related and I tried also with DEBUG=False
> but nothing changed only the detailed stack trace isn't printed,
> 
> thanks
> drakkan
> 
> 

Then don't build up a big list, use and consume:

def worker():
yield '['
first = True
for o in DBModels.objects.filter(somefilter).iterator():
   if not first:
   yield ','
   else:
   first = False
   yield simplejson.dumps({'field1':o.field1,'field2':o.field2})
yield ']'
return HttpResponse(worker(), mimetype='application/json')

PS - AJAX applications aren't nice and snappy when dealing with that
quantity of information...

Tom


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



Re: Select Table or Database based on User

2009-08-06 Thread Wojciech Gryc

Hi everyone,

All right, you have convinced me. I'll implement this way.

Thank you all for the advice and help!

- Wojciech

On Aug 6, 7:30 am, Daniel Roseman  wrote:
> On Aug 5, 11:38 pm,WojciechGryc  wrote:
>
> > Thanks for your replies!
>
> > The problem with storing the user ID for each table and then filtering
> > by the ID is that once the data set grows very large, this will become
> > extremely slow (as far as I understand).
>
> > I expected to have about 2000 pieces of information per user, with
> > several dozen users (at least). Filtering by user ID each time would
> > be extremely wasteful, would it not?
>
> > Thanks,
> >Wojciech
>
> No, not at all. This is what databases are *designed* to do, and they
> do it super-efficiently. 2000 rows per user * dozens of users is
> absolutely nothing - there are dbs with many millions of rows out
> there. This is absolutely the right solution.
> --
> 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: django queryset based on when data created

2009-08-06 Thread krylatij

You can use ordering by primary key (id by default) because it
increments by every insert.
So newly created rows in db will have greater  id than others.
In most cases it can be enough.
--~--~-~--~~~---~--~~
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: Get current user outside a view / without an request object

2009-08-06 Thread krylatij

> ..go back and read the original poster's
> message. Having the user in threadlocals doesn't solve any problem,
> since he's trying to create a form class based on information in the
> request and that only happens at import time, not every time something
> in the file is looked at.
Yes, my mistake
--~--~-~--~~~---~--~~
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: multiple projects shared database

2009-08-06 Thread Robin Becker

derek wrote:
> 
>>> On the other hand, if the two websites are entirely independent, putting
>>> them into a single database is simply poor design. It's trivial to
>>> create a separate database and why not use the tools that are available
>>> instead of adding extra complexity?!
>> I think the idea is to allow common authorisation between the two sites.
> 
> I am a complete newbie here, so pardon me chipping in, but... would it
> not be possible to do authorisation in one database and then have the
> groups-specific databases being separate?
> 
> Derek
..
I don't think django allows multiple databases except via table name hacks and 
similar.
-- 
Robin Becker

--~--~-~--~~~---~--~~
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: multiple projects shared database

2009-08-06 Thread derek


> > On the other hand, if the two websites are entirely independent, putting
> > them into a single database is simply poor design. It's trivial to
> > create a separate database and why not use the tools that are available
> > instead of adding extra complexity?!
>
> I think the idea is to allow common authorisation between the two sites.

I am a complete newbie here, so pardon me chipping in, but... would it
not be possible to do authorisation in one database and then have the
groups-specific databases being separate?

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



  1   2   >