Re: Auto-truncated fields at max_length

2010-08-05 Thread Masklinn
On 5 août 2010, at 01:35, Samuel Clay  wrote:
> I have a field that has a max_length set. When I save a model instance, and 
> the field's value is > than max_length, Django enforces that max_length at 
> the database level. (See Django docs on models: 
> http://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.CharField.max_length)
> 
> However, since I am using Postgres, I receive a DatabaseError exception like 
> this:
>DatabaseError: value too long for type character varying(1000)
> 
> I would prefer to instead auto-truncate the value (so I don't have an 
> exception). Now, I can do this manually, but what I would really want is to 
> have all of my models auto-truncate the value. (Not necessarily 
> intelligently. Just cutting it off at the 999th character is fine.) 
> 
> Should I just write a custom class that imports from models.Model and 
> override the save() method, looping through each _meta.field, checking for 
> the max_length, and then truncating? That seems inelegant and there must be a 
> better way.
Why not just create a custom field called e.g. DataCorruptingCharField which 
would silently perform this operation for you?

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



Re: Auto-truncated fields at max_length

2010-08-05 Thread Xavier Ordoquy
Hi,

> I would prefer to instead auto-truncate the value (so I don't have an 
> exception). Now, I can do this manually, but what I would really want is to 
> have all of my models auto-truncate the value. (Not necessarily 
> intelligently. Just cutting it off at the 999th character is fine.) 
> 
> Should I just write a custom class that imports from models.Model and 
> override the save() method, looping through each _meta.field, checking for 
> the max_length, and then truncating? That seems inelegant and there must be a 
> better way.

Is there any reason why you don't perform a check before filling the model ?
Where do you get your data from ?

Regards,
Xavier.

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



Re: Issue with loading fixtures in tests with multi database in Django 1.2

2010-08-05 Thread Russell Keith-Magee
On Thu, Jul 29, 2010 at 6:02 PM, Xavier Ordoquy  wrote:
> Hi there.
>
> I'm currently working on a project where I use a legacy database with a 
> django one.
> I've setup the multi database support and it seems to work pretty well.
> However, I'm getting an issue with testing.
>
> I need a fixture to load data to both the legacy and Django's databases.
> In order to make this work, I found that I needed to set the multi_db to True 
> in my TestCase (otherwise the legacy database data aren't loaded).
>
> However, if I do that, it turns out that Django will throw an exception 
> complaining about django_site not existing on my legacy database and would 
> stop tests.

I suspect that this might be an artefact of #14025. The flush command
was being a little too exuberant about the post-syncdb signals it was
emitting; since sites are created by a post-syncdb signal, and
overenthusiastic post-syncdb signal could be causing problems.

I've fixed the problem with flush in r13466 (and fixed the fix in
r13472); can you try a trunk checkout and let me know if it solves
your problem?

> I also noticed some weird behavior with the initial data.
> My initial_data load fine while the test framework works on the django 
> database but it will complains about corrupted file while creating the legacy 
> database (whether or not my testcase has the mult_db set).

Can you show the error message? I can't say this rings any bells for me.

Yours,
Russ Magee %-)

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



Re: Issue with loading fixtures in tests with multi database in Django 1.2

2010-08-05 Thread Xavier Ordoquy
Hi Russ,

Indeed, my investigations have lead me to #14025 which fixed the major issue.

If I remember correctly the corrupted file part was due to the fact that I was 
still using an "old style" fixture filename - ie .json instead of 
..json with data on both databases.
If you find it useful, I can investigate further about this message and make a 
patch in order to output an appropriate message.

Regards,
Xavier.

Le 5 août 2010 à 09:28, Russell Keith-Magee a écrit :

> On Thu, Jul 29, 2010 at 6:02 PM, Xavier Ordoquy  wrote:
>> Hi there.
>> 
>> I'm currently working on a project where I use a legacy database with a 
>> django one.
>> I've setup the multi database support and it seems to work pretty well.
>> However, I'm getting an issue with testing.
>> 
>> I need a fixture to load data to both the legacy and Django's databases.
>> In order to make this work, I found that I needed to set the multi_db to 
>> True in my TestCase (otherwise the legacy database data aren't loaded).
>> 
>> However, if I do that, it turns out that Django will throw an exception 
>> complaining about django_site not existing on my legacy database and would 
>> stop tests.
> 
> I suspect that this might be an artefact of #14025. The flush command
> was being a little too exuberant about the post-syncdb signals it was
> emitting; since sites are created by a post-syncdb signal, and
> overenthusiastic post-syncdb signal could be causing problems.
> 
> I've fixed the problem with flush in r13466 (and fixed the fix in
> r13472); can you try a trunk checkout and let me know if it solves
> your problem?
> 
>> I also noticed some weird behavior with the initial data.
>> My initial_data load fine while the test framework works on the django 
>> database but it will complains about corrupted file while creating the 
>> legacy database (whether or not my testcase has the mult_db set).
> 
> Can you show the error message? I can't say this rings any bells for me.
> 
> Yours,
> Russ Magee %-)
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
> 

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



Re: Forms and 'prefix' parameter

2010-08-05 Thread Daniel Roseman
On Aug 5, 7:16 am, Ed Schofield  wrote:
> On Aug 5, 2:23 pm, Karen Tracey  wrote:
>
>
>
>
>
> > On Thu, Aug 5, 2010 at 12:10 AM, Ed Schofield  wrote:
> > > Hi everyone,
>
> > > I'm trying to use a view with multiple forms under Django 1.2.1. I'm
> > > puzzled that the prefix parameter seems to screw up validation. Here's
> > > a test case:
>
> > > >>> from django import forms
>
> > > >>> class MyForm(forms.Form):
> > > >>>     field1 = forms.IntegerField(required=False)
> > > >>>     field2 = forms.IntegerField()
>
> > > >>> f1 = MyForm(data={'field1': 1, 'field2': 2})
> > > >>> f2 = MyForm(data={'field1': 1, 'field2': 2}, prefix='p')
>
> > > >>> f1.is_valid()
> > > True
>
> > > >>> f2.is_valid()
> > > False
>
> > > Can anyone explain why these are different?
>
> > You need to include the prefix in the data dictionary keys for the form.
> > See:http://code.djangoproject.com/ticket/13763#comment:3
>
> I've done some more digging. It seems that the prefix on data
> dictionary keys is required only when initializing the form, not when
> accessing the form data:
>
> >>> f1.cleaned_data
>
> {'field1': 1, 'field2': 2}
>
> >>> f2.cleaned_data
>
> {'field1': 1, 'field2': 2}
>
> rather than what I would now expect, given how the data argument is
> processed:
>
> {'p-field1': 1, 'p-field2': 2}
>
> Isn't this oddly inconsistent?
>
> -- Ed

Not at all. The prefix is added to the form fields when they are
displayed, so that form 1's field1 and form2's field1 get different
HTML names, and therefore different keys in the POST data dictionary.
However the developer still wants to access form1.field1 and
form2.field1 as they were originally defined - if they wanted form1.p-
field1, they should have defined it that way in the first place.
--
DR.

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



Re: Flexible relationships - tips/advice?

2010-08-05 Thread Daniel Roseman
On Aug 5, 12:32 am, v0idnull  wrote:
> I want to be able to link one model to another model, regardless of
> what models they are. Articles can be related to Photos, Videos, other
> Articles, etc etc etc.
>
> I have created a Relationship model to represent these relationships,
> but I'm unsure if this is the best solution. First off, my
> requirements include having a title, description, type, and priority
> to further describe the relationship.
>
> Secondly, I am using UUIDs for primary keys so I created a custom
> field to represent this (postgresql has a UUID field as well).
>
> Thirdly, I don't plan on using the out-of-box admin console, so
> whether or not a particular pattern works well in the admin console or
> not is not relevant for me.
>
> The following model accurately represents what I need, and in theory
> it works well. I can now have an abstract model that all my other
> models inherit, with an addRelationship(self, destination) method and
> various other methods to fetch relationships. In this abstract class,
> I also have this:
>
> from django.contrib.contenttypes.models import ContentType
>
> class Abstract(models.Model):
>     ...
>     def getType(self):
>         if (self._type == None):
>             self._type = ContentType.objects.get_for_model(self)
>         return self._type
>
> In order to make my life easier, as you'll see in my model below.
>
> I would like opinions about my approach, I am new to python, and newer
> still to Django. There might be things I am overlooking due to my
> ignorance.
>
> class Relationship(models.Model):
>
>     id = fields.UUID(auto_add=True,primary_key=True, unique=True)
>     created_by = fields.UUID(db_index=True,null=True,blank=True)
>     created_on = models.DateField(auto_now=False,auto_now_add=True)
>     modfied_on = models.DateField(auto_now=True,auto_now_add=False)
>     title = models.CharField(max_length=255)
>
>     source_id = fields.UUID(db_index=True)
>     source_app_label = models.CharField(db_index=True,max_length=255)
>     source_model = models.CharField(db_index=True,max_length=255)
>     destination_id = fields.UUID(db_index=True)
>     destination_app_label =
> models.CharField(db_index=True,max_length=255)
>     destination_model = models.CharField(db_index=True,max_length=255)
>
>     description = models.TextField(null=True,blank=True)
>     type =
> models.CharField(max_length=64,null=True,blank=True,db_index=True)
>     priority = models.PositiveIntegerField()
>
> Thanks in advance...

There is an out-of-the-box feature that does exactly this, Generic
Relationships. See 
http://docs.djangoproject.com/en/1.2/ref/contrib/contenttypes/#generic-relations
--
DR.

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



Re: multi_db support for doctests? How to enable?

2010-08-05 Thread Reinout van Rees

On 08/05/2010 07:27 AM, Xavier Ordoquy wrote:

I'll do some experimenting with django versions.  I clearly remember adding 
code to my router to allow django to create those 5 tables in my second 
database, so it *did* work.  Perhaps 1.2.1 broke something that 
1.2betasomething did right?   Gotta drink wine with my wife now, I'll test 
tomorrow :-)


Could it be that you weren't using doctest before and that there is some issue 
with doctest and multi db support ?
I must say I haven't used doctests with multidb yet.

Also I'm not sure I understood your issue correctly.
When you state that the second database isn't created, you mean the tables are 
not created right ?


Yes, the tables aren't created.

I found it, sigh.  I added the following lines to my settings.py 
according to one of those django-with-hudson-integration articles (like 
http://www.caktusgroup.com/blog/2010/03/08/django-and-hudson-ci-day-1/):


TEST_RUNNER = 'xmlrunner.extra.djangotestrunner.run_tests'
TEST_OUTPUT_DESCRIPTIONS = True
TEST_OUTPUT_DIR = 'xmlrunner'

Apparently that test runner doesn't work with the multi db setup.  When 
I removed those lines, the tests would work again.  I really should have 
spotted that by running the tests before and after making that config 
change...


Ok, now I'll have to figure out a different way of getting xml output 
(for hudson) out of django's tests.



Thanks,

Reinout


--
Reinout van Rees - rein...@vanrees.org - http://reinout.vanrees.org
Programmer at http://www.nelen-schuurmans.nl
"Military engineers build missiles. Civil engineers build targets"

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



Re: Django, Rails but a cost to pay ?

2010-08-05 Thread Sithembewena Lloyd Dube
You mean conclusions like "and solely written for getting hits"?

I am not saying don't critique things. Just try to remember that you don't
know the OP's intentions in asking and adapt your tone accordingly.

On Wed, Aug 4, 2010 at 5:47 PM, Masklinn  wrote:

> On 2010-08-04, at 17:35 , Sithembewena Lloyd Dube wrote:
> > Surprising that anybody would be offended by the OP's post. Why do people
> so
> > readily see red? As for the "think special" part, one would have to be
> > pretty intent on getting upset to miss the sarcasm.
>
> Surprising that anybody would read any comment in this thread as being
> offended by the OP's post. Why do people so readily jump to conclusions?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


-- 
Regards,
Sithembewena Lloyd Dube
http://www.lloyddube.com

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



Re: How to get the model name of an object in template?

2010-08-05 Thread Daniel Roseman
On Aug 4, 7:27 pm, "David.D"  wrote:
> I just wonder if there's some way requires writing nothing. Just like
> an attribute.
>
> thanks.

Yes, there is. Each model and model instance object has a _meta
attribute, which contains information about the model -
the .app_label, object_name and .verbose_name will probably be useful
to you.
--
DR.

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



Jquery-ui in admin: c is undefined

2010-08-05 Thread Alessandro Ronchi
If I load jquery-ui (a custom full download) in my admin I get this script
error:
c is undefined

If I load 2 times jquery with

~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
class Media:
js = (
settings.MEDIA_URL + 'admin/jquery-ui/js/jquery-1.4.2.min.js',
settings.MEDIA_URL +
'admin/jquery-ui/js/jquery-ui-1.8.2.custom.min.js',

)
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
It works.
There is no diff between my settings.MEDIA_URL +
'admin/jquery-ui/js/jquery-1.4.2.min.js', and
django/contrib/admin/media/js/jquery-min.js
but the first come after jquery.init.js

// Puts the included jQuery into our own namespace
var django = {
"jQuery": jQuery.noConflict(true)
};

Is there a way to avoid attaching two times the same jquery library in
admin?

Thanks in advance,

-- 
Alessandro Ronchi
http://www.soasi.com

Hobby & Giochi
http://hobbygiochi.com
http://www.facebook.com/hobbygiochi

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



Re: Django IDE

2010-08-05 Thread bagheera
Dnia 05-08-2010 o 00:12:41 Carlos Daniel Ruvalcaba Valenzuela  
 napisał(a):



If you are looking for a "Full IDE" I have used Eclipse+PyDev (and
other plugins) and works quite well, completion is reasonable and you
have a wealth of extensions such as VCS support, Mylyn Integration (to
work with remote task/issue managers), HTML editing, etc. It is a
little bloated if you are used to editors and other lightweight IDEs
though, but I can recommend it.

I haven't tried netbeans yet but I only hear good things of it so far.

As far commercial IDEs there is WingIDE and PyCharm, PyCharm is very
Django oriented right now and has very good autocompletion/code
editing tools, it may be the best option but Wing is also preparing
it's Django specific features for next release (available in beta
builds).



I have eclipse/aptana + PyDev but i did not found it comfortable, mb i  
just gave it too little time to get familiar with, or i'm too stick to  
NetBeans. However, i'll give a try to SPE mentioned in other post, never  
heard of that.

--
Linux user

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



Re: New tutorial added to Django by Example

2010-08-05 Thread Nikhil Somaru
Ah, thanks

On Tue, Aug 3, 2010 at 8:40 PM, Rainy  wrote:

>
>
> On Aug 3, 2:25 am, Nikhil Somaru  wrote:
> > How to set up a virtual python/django installation
> >
>
> There is already a tutorial for this here:
>
>
> http://codytaylor.org/2010/07/django-on-dreamhost-virtual-python-install.html
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



django mail_admins source code

2010-08-05 Thread kostia
I have a contact form on my site.

The code which send the emails after successful validation is below:

def contact(request):

if request.method == 'POST':

form = ContactForm(request.POST)

if form.is_valid():

if request.POST['send_me']:

send_mail(

request.POST['subject'],

request.POST['message'],

request.POST.get('email', 'nore...@example.com'),

[request.POST.get('email',
'nore...@example.com')],

)
mail_admins(

request.POST['subject'],

request.POST['message'],

)

return HttpResponseRedirect(reverse('home'))

else:

form = ContactForm()

return render_to_response('feedback.html',

context_instance=RequestContext(request, {'form': form}))

First I send the email to the user himself if he checked "Send me
copy" on the form.

Then I'm going to send his email to admins. The problem is I do not
see his email address to allow admins to reply him. Is this a stupid
behaviour of mail_admins?

So I decided to use send_mail, but previously I need to convert
settings.ADMINS tuples into email strings to specify in the function.

I think to use something like
recipients = []
for admin in settings.ADMINS:
 recipients += admin[1]

But it seems to be unprofessional.

How to extract email addresses from settings.ADMINS? I can't find
mail_admins code to see how django developers did that. Please, if you
can, post the code here.

Good luck!

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



newbie: how to do a simple join query?

2010-08-05 Thread xpanta
Hi.

I have read the (excellent) documentation but I can't figure out how
to do this. I know I might have to use annotations but I need some
extra help.

here it is, then.

I have a table which represents user friendships called
"Shortlist" (with fields from_user, to_user: both Foreign Keys to the
classic auth_user table. Namely, from_user befriends to_user).

I have another table into which I log user events/actions (UserLog).
In this table there are many fields including a timestamp and of
course user fields (user is again a foreign key to the auth_user
table)

how can I retrieve data from table "Shortlist" for a specific user
(from_user) ordered by the timestamp in UserLog table? Or how can I
retrieve Shortlist data for a specific from_user ordered by the total
number of "to_user" actions logged?

in other words I would like to retrieve all his/her friends that are
most active or order them by most recent action first.

Hope that makes sense,
Chris

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



Re: Django IDE

2010-08-05 Thread Kenneth Gonsalves
On Thu, 2010-08-05 at 10:10 +0200, bagheera wrote:
> I have eclipse/aptana + PyDev but i did not found it comfortable, mb
> i  
> just gave it too little time to get familiar with, or i'm too stick
> to  
> NetBeans. However, i'll give a try to SPE mentioned in other post,
> never  
> heard of that. 

geany - lightweight and easy to use
-- 
regards
Kenneth Gonsalves

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



Re: importing models to script file

2010-08-05 Thread Reinout van Rees

On 08/04/2010 08:32 PM, Tony wrote:

Hi, Im trying to import my models to another python file that I am
making to use the database data.  The problem is, I can't import the
models for some reason.  It keeps saying "ImportError: Settings cannot
be imported, because environment variable DJANGO_SETTINGS_MODULE is
undefined."
The thing is, the script works on my home computer when I do it, but
when I do it on webfaction this seems to happen.  Anyone ever have a
similar problem?  And I have tried including various paths in the py
file with sys.path.append() but that hasnt worked.  Disregard my first
message, this is actually what the error is.


That environment variable DJANGO_SETTINGS_MODULE is probably defined on 
your home computer but not on webfaction.  You use it to point django at 
your "mysite/settings.py" file so that it knows which settings to use.


See 
http://docs.djangoproject.com/en/dev/topics/settings/#designating-the-settings



Reinout

--
Reinout van Rees - rein...@vanrees.org - http://reinout.vanrees.org
Programmer at http://www.nelen-schuurmans.nl
"Military engineers build missiles. Civil engineers build targets"

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



Re: Error with Apache and mod_wsgi

2010-08-05 Thread commonzenpython
please check the apache error logs, and post the info so i can be of
more assistance to you

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



Re: Announces django-guardian: per object permissions for Django 1.2

2010-08-05 Thread derek
On Aug 4, 9:18 pm, lukaszb  wrote:
> Welll, at the django.contrib.auth there are only those (User and
> Group) models for which one may define permission sets and I wanted
> guardian to be as simply as possible - so it is not possible to assign
> permission to other model even if it "groups  users". At one point I
> thought it could be nice to implement some kind of "roles" but I've
> finally decided it would be better to stick to facilites provided by
> new Django version.
>
> On the other hand, I'm not sure if it is needed to create new
> "grouping models" - I often use intermediate models for this (i.e.
> Team model with fk to Group among other fields). Let me know if you
> have different experience.
>
> On 4 Sie, 15:26, derek  wrote:
>
> > On Aug 4, 1:20 am, lukaszb  wrote:
>
> > > Hi all,
>
> > > I'd like to announce django-guardian - very basic yet usable per
> > > object permissions
> > > implementation for Django 1.2, using new authorization backend
> > > facilities.
>
> > > It was created during 2 days sprint, code have been released and may
> > > be found athttp://github.com/lukaszb/django-guardian/.
> > > Documentation is available athttp://packages.python.org/django-guardian/.
>
> > > Currently I think there should be better integration with admin app
> > > and some shortcuts (permission assignment/removal)
> > > should support table-level permissions as well.
>
> > > If you spot a bug or have an idea how to improve this little app,
> > > please spare a minute at issue tracker, which is located 
> > > athttp://github.com/lukaszb/django-guardian/issues.
>
> > > Hope someone would find this useful.
>
> > No doubt this will be extremely useful!  For me, integration with the
> > Django admin is a must, though, as permissions will need to be
> > assigned by users themselves via the standard interface.
>
> > One (maybe stupid) question:  Can rights only be assigned to the pre-
> > specified "Group", or can any model that handles user grouping (I have
> > some custom ones in my app) be used?
>
> > Thanks
> > Derek

That's a pity; guess I will need to stick to my home-grown code in
that case.

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



Re: Error with Apache and mod_wsgi

2010-08-05 Thread Graham Dumpleton


On Aug 5, 12:27 pm, Vikas Mahajan  wrote:
> Hello to all.
> I am new baby to python and django. I have installed the django-1.21
> in my pc. I am able to create mysite as mentioned in tutorial and
> mysite also works fine using django web server (on port 8000), but now
> I am trying to run mysite on my apache server but I am facing
> problems. Apache is giving me internal server error. Below is my
> configurations-:
>
> Path to mysite-:
>
> /django/mysite
>
> Apache httpd.conf configuration-:
>
> Alias /media/ 
> /usr/local/lib/python2.6/site-packages/django/contrib/admin/media/
>
> 
> Options Indexes
> Order deny,allow
> Allow from all
> 
>
> WSGIScriptAlias /django/ /django/mysite/apache/django.wsgi

Read the documentation properly. You should not have a trailing slash
on the mount point URL. Ie., use /django and not /django/

Graham

>
> 
> Options Indexes
> Order deny,allow
> Allow from all
> 
>
> Contents of /django/mysite/apache/django.wsgi file-:
>
> import os
> import sys
>
> os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
>
> import django.core.handlers.wsgi
> application = django.core.handlers.wsgi.WSGIHandler()
> sys.path.append('/django/')
>
> Also, I noticed one thing that when I write following content in
> django.wsgi file, it is working fine i.e displaying Hello World on
> webpage but with above contents of django.wsgi file, apache  is giving
> Internal Server Error.
>
> django.wsgi test content-:
>
> def application(environ, start_response):
>     status = '200 OK'
>     output = 'Hello World!'
>
>     response_headers = [('Content-type', 'text/plain'),
>                         ('Content-Length', str(len(output)))]
>     start_response(status, response_headers)
>
>     return [output]
>
> Please help me to resolve this error.
>
> Thanks.

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



Python Segfaults with Django 1.1

2010-08-05 Thread Sven Broeckling
Hi,

i have a problem on a debian lenny machine which is not easy to track
down. It started with Apache2 mod_wsgi crashes (segfault in libapr)
after the migration from mod_python. The server crashes sporadic and
everytime with another view called, but everytime after a while (2-7
Days, depending on traffic). 

I set up a lighttpd/fastcgi/runfcgi Setup to avoid this, but now
segfaults python, imho for the same reason.

Is there any "right" way to find the reason for the segfaults beyond
letting strace dump 100s of megs of Log for a Week? We habe
dependencies to libcairo (python-cairo), librsvg, geoip and memcache,
so maybe the segfault happens in there. 

This is the Kernel log for the apache crashes : 

messages.2.gz:Jul 24 22:10:58 vshop kernel: [7816643.903087]
apache2[4686]: segfault at 28 ip 7f6f8f4c2f04 sp 7f6f84043d40 error 4
in libapr-1.so.0.2.12[7f6f8f49f000+32000] messages.2.gz:Jul 24 22:13:50
vshop kernel: [7816817.795137] apache2[4700]: segfault at 28 ip
7f6f8f4c2f04 sp 7f6f7f83ad40 error 4 in
libapr-1.so.0.2.12[7f6f8f49f000+32000] messages.4.gz:Jul  4 21:49:00
vshop kernel: [6079995.222199] apache2[7564]: segfault at 28 ip
7f98f256e655 sp 7f98e310bd40 error 4 in
libapr-1.so.0.2.12[7f98f254b000+32000] messages.4.gz:Jul  6 04:58:35
vshop kernel: [6192612.659789] apache2[10605]: segfault at 28 ip
7fae92380655 sp 7fae85f23d40 error 4 in
libapr-1.so.0.2.12[7fae9235d000+32000] messages.4.gz:Jul  6 04:58:35
vshop kernel: [6192612.701478] apache2[10565]: segfault at 28 ip
7fae92380655 sp 7fae86724d40 error 4 in
libapr-1.so.0.2.12[7fae9235d000+32000] messages.4.gz:Jul  7 04:31:08
vshop kernel: [6277733.106236] apache2[4798]: segfault at 28 ip
7f2c8d6dff04 sp 7f2c84a89d40 error 4 in
libapr-1.so.0.2.12[7f2c8d6bc000+32000] messages.4.gz:Jul  7 04:32:41
vshop kernel: [6277825.802407] apache2[4855]: segfault at 28 ip
7f2c8d6dff04 sp 7f2c84288d40 error 4 in
libapr-1.so.0.2.12[7f2c8d6bc000+32000]

Thanks in advance for any hint :) 
  Sven

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



Re: How to get the model name of an object in template?

2010-08-05 Thread Paulo Almeida
But _meta starts with an underscore, so you can't use it in the template,
right? I'm still using Django 1.0.2, so I don't know if that has changed
along the way.

- Paulo

On Thu, Aug 5, 2010 at 8:52 AM, Daniel Roseman wrote:

> On Aug 4, 7:27 pm, "David.D"  wrote:
> > I just wonder if there's some way requires writing nothing. Just like
> > an attribute.
> >
> > thanks.
>
> Yes, there is. Each model and model instance object has a _meta
> attribute, which contains information about the model -
> the .app_label, object_name and .verbose_name will probably be useful
> to you.
> --
> DR.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: no such table: django_session when doing the tutorial

2010-08-05 Thread Alexandre González
Sorry Yoji, I did a fast read and I didn't see it.

Can you paste your complete settings.py

On Wed, Aug 4, 2010 at 13:40, Yoji H  wrote:

> this is just a guess but i think the path is not set right.
> but i don know how to set it correctly.
>
>
> On Wed, Aug 4, 2010 at 8:39 PM, Yoji H  wrote:
>
>> i did as i wrote above.
>>
>> 2010/8/4 Alexandre González 
>>
>> Have you run the script manage.py with syncdb option?
>>>
>>> python manage.py syncdb
>>>
>>> On Wed, Aug 4, 2010 at 12:44, merabi  wrote:
>>>
 Hi.
 im using python 2.6, django 1.1, eclipse3.4, and pydev 1.6, macbook
 pro mac os 10.6.4.
 trying to do the tutorial:
 http://docs.djangoproject.com/en/dev/intro/tutorial02/

 first of all, i DID syncdb. -> no problem.
 i check using dbshell, .dump. -> says django_session DOES EXISTS.

 Changed urls.py:

 from django.conf.urls.defaults import *

 # Uncomment the next two lines to enable the admin:
 from django.contrib import admin
 admin.autodiscover()

 urlpatterns = patterns('',
# Example:
# (r'^mysite/', include('mysite.foo.urls')),

# Uncomment the admin/doc line below and add
 'django.contrib.admindocs'
# to INSTALLED_APPS to enable admin documentation:
# (r'^admin/doc/', include('django.contrib.admindocs.urls')),

# Uncomment the next line to enable the admin:
(r'^admin/', include(admin.site.urls)),
 )

 Added "django.contrib.admin" to INSTALLED_APPS on setting.py.
 btw,
 django.contrib.auth,
 django.contrib.session,
 django.contrib.site
 are also listed.

 When I tried to access http://localhost:8000/admin/
 it says:

 DatabaseError: no such table: django_session

 Why is that

 after the error i did syncdb, and it says No fixtures found...

 --

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


>>>
>>>
>>> --
>>> Please, don't send me files with extensions: .doc, .docx, .xls, .xlsx,
>>> .ppt and/or .pptx
>>> http://mirblu.com
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Django users" group.
>>> To post to this group, send email to django-us...@googlegroups.com.
>>> To unsubscribe from this group, send email to
>>> django-users+unsubscr...@googlegroups.com
>>> .
>>> For more options, visit this group at
>>> http://groups.google.com/group/django-users?hl=en.
>>>
>>
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>



-- 
Please, don't send me files with extensions: .doc, .docx, .xls, .xlsx, .ppt
and/or .pptx
http://mirblu.com

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



Re: django mail_admins source code

2010-08-05 Thread euan.godd...@googlemail.com
AFAIK mail_admins is designed to send error messages to the site
administrator, not for the purpose you are proposing, so you won't get
the original email. Your proposal seems reasonable enough to me since
you're not using mail_admins as designed.

Why take only the second admin email address?

On an unrelated point you might to re-think your view. Once you've
pass form.is_valid(), it is much better to read the data out of the
form.cleaned_data dictionary than directly from the POST as Django
takes care of type coercion, etc.

Euan

On Aug 5, 10:31 am, kostia  wrote:
> I have a contact form on my site.
>
> The code which send the emails after successful validation is below:
>
> def contact(request):
>
>     if request.method == 'POST':
>
>         form = ContactForm(request.POST)
>
>         if form.is_valid():
>
>             if request.POST['send_me']:
>
>                 send_mail(
>
>                     request.POST['subject'],
>
>                     request.POST['message'],
>
>                     request.POST.get('email', 'nore...@example.com'),
>
>                     [request.POST.get('email',
> 'nore...@example.com')],
>
>                 )
>             mail_admins(
>
>                 request.POST['subject'],
>
>                 request.POST['message'],
>
>             )
>
>             return HttpResponseRedirect(reverse('home'))
>
>     else:
>
>         form = ContactForm()
>
>     return render_to_response('feedback.html',
>
>         context_instance=RequestContext(request, {'form': form}))
>
> First I send the email to the user himself if he checked "Send me
> copy" on the form.
>
> Then I'm going to send his email to admins. The problem is I do not
> see his email address to allow admins to reply him. Is this a stupid
> behaviour of mail_admins?
>
> So I decided to use send_mail, but previously I need to convert
> settings.ADMINS tuples into email strings to specify in the function.
>
> I think to use something like
> recipients = []
> for admin in settings.ADMINS:
>      recipients += admin[1]
>
> But it seems to be unprofessional.
>
> How to extract email addresses from settings.ADMINS? I can't find
> mail_admins code to see how django developers did that. Please, if you
> can, post the code here.
>
> Good luck!

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



Re: Jquery-ui in admin: c is undefined

2010-08-05 Thread euan.godd...@googlemail.com
It looks like order is important. I don't think there's much you can
do other than declare it twice in this case.

On Aug 5, 8:59 am, Alessandro Ronchi 
wrote:
> If I load jquery-ui (a custom full download) in my admin I get this script
> error:
> c is undefined
>
> If I load 2 times jquery with
>
> ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
>     class Media:
>         js = (
>             settings.MEDIA_URL + 'admin/jquery-ui/js/jquery-1.4.2.min.js',
>             settings.MEDIA_URL +
> 'admin/jquery-ui/js/jquery-ui-1.8.2.custom.min.js',
>
>         )
> ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~
> It works.
> There is no diff between my settings.MEDIA_URL +
> 'admin/jquery-ui/js/jquery-1.4.2.min.js', and
> django/contrib/admin/media/js/jquery-min.js
> but the first come after jquery.init.js
>
> // Puts the included jQuery into our own namespace
> var django = {
>     "jQuery": jQuery.noConflict(true)
>
> };
>
> Is there a way to avoid attaching two times the same jquery library in
> admin?
>
> Thanks in advance,
>
> --
> Alessandro Ronchihttp://www.soasi.com
>
> Hobby & Giochihttp://hobbygiochi.comhttp://www.facebook.com/hobbygiochi

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



Re: Python Segfaults with Django 1.1

2010-08-05 Thread Reinout van Rees

On 08/05/2010 12:50 PM, Sven Broeckling wrote:


i have a problem on a debian lenny machine which is not easy to track
down. It started with Apache2 mod_wsgi crashes (segfault in libapr)
after the migration from mod_python. The server crashes sporadic and
everytime with another view called, but everytime after a while (2-7
Days, depending on traffic).


Probably not related, but you never know... I've seen this happen in ye 
olde days with a zope server that you'd start in daemon mode from the 
terminal.  After 2-4 days the terminal would die and suddenly the 
perfectly-running zope server would have nowhere to print its console 
output once an infrequent error occured. And it would die.


The wsgi stuff works differently, so this shouldn't be the problem. 
Mentioning it anyway, perhaps it rings some distant bell :-)



Reinout


--
Reinout van Rees - rein...@vanrees.org - http://reinout.vanrees.org
Programmer at http://www.nelen-schuurmans.nl
"Military engineers build missiles. Civil engineers build targets"

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



Re: Issue with loading fixtures in tests with multi database in Django 1.2

2010-08-05 Thread Russell Keith-Magee
On Thu, Aug 5, 2010 at 3:44 PM, Xavier Ordoquy  wrote:
> Hi Russ,
>
> Indeed, my investigations have lead me to #14025 which fixed the major issue.
>
> If I remember correctly the corrupted file part was due to the fact that I 
> was still using an "old style" fixture filename - ie .json instead of 
> ..json with data on both databases.
> If you find it useful, I can investigate further about this message and make 
> a patch in order to output an appropriate message.

"Old style" fixture names should still be valid -- if a database name
isn't specified, the fixture will be loaded on all available
databases. If you've got a test case where this fails, it should be
reported.

Yours,
Russ Magee %-)

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



Re: Need help with my Form.save() method. Trouble with ForeignKey and ManyToMany Fields.

2010-08-05 Thread Paulo Almeida
Can you check the POST data and see if 'username' is there? You can do it
easily with Firefox's Firebug extension.

- Paulo

On Thu, Aug 5, 2010 at 6:24 AM, strayhand  wrote:

> So I'm rolling out my own registration form that should update the
> following models:
>
> - User (auth module)
> - UserProfile
>
> Everything seems to be coming together but I'm having a hard time with
> the save() method for the form. My UserProfile model has a couple of
> fields that refer to other models and I'm having difficulty setting
> them up properly. I keep getting an error telling me:
>
> Exception Type: IntegrityError at /registration/
> Exception Value: auth_user.username may not be NULL
>
> I know where the problems are:
>
> new_user =
> User.objects.create_user(username=self.cleaned_data['username'],
> email=self.cleaned_data['email'],
> password=self.cleaned_data['password1'])
>
> and I'm getting this similar error for defining the user profile on
> the line below.
>
> new_profile.user =
> User.objects.get(username__exact=self.cleaned_data['username'])
>
> I'm just not sure how else to write this stuff. I'm including my form,
> model and the exact error message that I'm getting below. Any insight
> that you have is greatly appreciated. Thank you.
>
> # registration.forms.py
>
> import re
> from django import forms
> from django.db import models
> from django.contrib.localflavor.us.forms import USPhoneNumberField
> from django.contrib.auth.models import User
> from ylbbq.areas.models import Area
> from ylbbq.profiles.models import UserProfile
>
> STATES = (
>('WA', 'Washington'),
>('AK', 'Alaska'),
>('AL', 'Alabama'),
>('AR', 'Arkansas'),
>('AZ', 'Arizona'),
>('CA', 'California'),
>('CO', 'Colorado'),
>('CT', 'Connecticut'),
>('DE', 'Delaware'),
>('FL', 'Florida'),
>('GA', 'Georgia'),
>('HI', 'Hawaii'),
>('IA', 'Iowa'),
>('ID', 'Idaho'),
>('IL', 'Illinois'),
>('IN', 'Indiana'),
>('KS', 'Kansas'),
>('KY', 'Kentucky'),
>('LA', 'Louisiana'),
>('MA', 'Massachusetts'),
>('MD', 'Maryland'),
>('ME', 'Maine'),
>('MI', 'Michigan'),
>('MN', 'Minnesota'),
>('MO', 'Missouri'),
>('MS', 'Mississippi'),
>('MT', 'Montana'),
>('NC', 'North Carolina'),
>('ND', 'North Dakota'),
>('NE', 'Nebraska'),
>('NH', 'New Hampshire'),
>('NJ', 'New Jersey'),
>('NM', 'New Mexico'),
>('NV', 'Nevada'),
>('NY', 'New York'),
>('OH', 'Ohio'),
>('OK', 'Oklahoma'),
>('OR', 'Oregon'),
>('PA', 'Pennsylvania'),
>('RI', 'Rhode Island'),
>('SC', 'South Carolina'),
>('SD', 'South Dakota'),
>('TN', 'Tennessee'),
>('TX', 'Texas'),
>('UT', 'Utah'),
>('VT', 'Vermont'),
>('VA', 'Virginia'),
>('WI', 'Wisconsin'),
>('WV', 'West Virginia'),
>('WY', 'Wyoming'),
>('AB', 'Alberta'),
>('BC', 'British Columbia'),
>('MB', 'Manitoba'),
>('NB', 'New Brunswick'),
>('NL', 'Newfoundland and Labrador'),
>('NS', 'Nova Scotia'),
>('NT', 'Northwest Territories'),
>('NU', 'Nunavut'),
>('ON', 'Ontario'),
>('PE', 'Prince Edward Island'),
>('QC', 'Quebec'),
>('SK', 'Saskatchewan'),
>('YT', 'Yukon'),
> )
>
> COUNTRIES = (
>('USA', 'United States'),
>('Canada', 'Canada')
> )
>
> POSTAL_CODE_PATTERN = re.compile(r'^\d{5}-\d{4}|\d{5}|[A-Z]\d[A-Z]
> \d[A-Z]\d$')
>
> class RegisterForm(forms.Form):
>username = forms.CharField(max_length=30, help_text='Create a user
> name for this Web site.')
>first_name = forms.CharField(max_length=30)
>last_name = forms.CharField(max_length=30)
>password1 = forms.CharField(max_length=60, label='Password',
> widget=forms.PasswordInput)
>password2 = forms.CharField(max_length=60, label='Password
> Confirmation', widget=forms.PasswordInput)
>email = forms.EmailField(help_text='Enter a valid e-mail address.')
>phone = USPhoneNumberField(max_length=12, help_text='Enter your
> phone
> number in the following format: 253-123-5678.')
>address = forms.CharField(max_length=70, help_text='Enter mailing
> address.')
>city = forms.CharField(max_length=50)
>state_province = forms.ChoiceField(choices=STATES, label='State or
> Province')
>country = forms.ChoiceField(choices=COUNTRIES)
>zip_code = forms.CharField(max_length=10, label='Mailing Code',
> help_text='Enter your zip code (US or Canadian).')
>birth_date = forms.DateField(help_text='Enter your birthdate in the
> following format: 1979-09-29 (-MM-DD).')
>areas = forms.ModelMultipleChoiceField(queryset=Area.objects.all(),
> label='Preferred Areas', help_text='Select the areas that you\'d like

django.views.static.serve issue

2010-08-05 Thread bagheera

Hi, i set up static files for development purposes in following way:

urls.py:


if settings.DEBUG:
urlpatterns += patterns('',(r'^site_media/(?P.*)$',  
'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}),)


settings.py:

MEDIA_ROOT = '/home/bagheera/NetBeansProjects/nml-src/storage'
MEDIA_URL = 'http://localhost:8000/site_media/'

index.html template:



WHY i had to add "site_media" string, when it IS already included in  
MEDIA_URL ?

If i use

dev server gives output:
/images/clock.gif/ HTTP/1.1" 404 2155

Full path to this file is:
'/home/bagheera/NetBeansProjects/nml-src/storage/images/clock.gif'
--
Linux user

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



Re: django mail_admins source code

2010-08-05 Thread Steve Holden
On 8/5/2010 7:18 AM, euan.godd...@googlemail.com wrote:
> AFAIK mail_admins is designed to send error messages to the site
> administrator, not for the purpose you are proposing, so you won't get
> the original email. Your proposal seems reasonable enough to me since
> you're not using mail_admins as designed.
> 
> Why take only the second admin email address?
> 
He isn't. He's taking the email portion of each (name, email) tuple in
the ADMINS list.

> On an unrelated point you might to re-think your view. Once you've
> pass form.is_valid(), it is much better to read the data out of the
> form.cleaned_data dictionary than directly from the POST as Django
> takes care of type coercion, etc.
> 
Good point.

regards
 Steve


> Euan
> 
> On Aug 5, 10:31 am, kostia  wrote:
>> I have a contact form on my site.
>>
>> The code which send the emails after successful validation is below:
>>
>> def contact(request):
>>
>> if request.method == 'POST':
>>
>> form = ContactForm(request.POST)
>>
>> if form.is_valid():
>>
>> if request.POST['send_me']:
>>
>> send_mail(
>>
>> request.POST['subject'],
>>
>> request.POST['message'],
>>
>> request.POST.get('email', 'nore...@example.com'),
>>
>> [request.POST.get('email',
>> 'nore...@example.com')],
>>
>> )
>> mail_admins(
>>
>> request.POST['subject'],
>>
>> request.POST['message'],
>>
>> )
>>
>> return HttpResponseRedirect(reverse('home'))
>>
>> else:
>>
>> form = ContactForm()
>>
>> return render_to_response('feedback.html',
>>
>> context_instance=RequestContext(request, {'form': form}))
>>
>> First I send the email to the user himself if he checked "Send me
>> copy" on the form.
>>
>> Then I'm going to send his email to admins. The problem is I do not
>> see his email address to allow admins to reply him. Is this a stupid
>> behaviour of mail_admins?
>>
>> So I decided to use send_mail, but previously I need to convert
>> settings.ADMINS tuples into email strings to specify in the function.
>>
>> I think to use something like
>> recipients = []
>> for admin in settings.ADMINS:
>>  recipients += admin[1]
>>
>> But it seems to be unprofessional.
>>
>> How to extract email addresses from settings.ADMINS? I can't find
>> mail_admins code to see how django developers did that. Please, if you
>> can, post the code here.
>>
>> Good luck!
> 


-- 
I'm no expert.
"ex" == "has-been"; "spurt" == "drip under pressure"
"expert" == "has-been drip under pressure".

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



Re: Getting old projects to run on 1.2 with Ubuntu

2010-08-05 Thread Nikhil Somaru
"And one more thing, read something about python path, eggs, *.pth files,
you will need this knowledge to understand how this whole import machinery
works, else it will be very confusing."

Any links you can suggest for this?

On Sun, Jul 25, 2010 at 6:17 PM, Martin Tiršel  wrote:

> On Sun, 25 Jul 2010 07:17:48 +0200, Nikhil Somaru 
> wrote:
>
>  Hi
>>
>> I'm using Ubuntu Lucid 10.04. I had previously installed Django 1.1.1 via
>> the repos. I downloaded the django 1.2 tarball. Ran "sudo setup.py
>> install"
>> after extracting, and it seems the installation went fine. However, when I
>> run the dev server with my old project, it still shows as django version
>> 1.1.1. Suggestions
>>
>> Thanks
>>
>>
> Hi,
>
> my advice is not to use distribution packages (you can not use multiple
> versions, older package versions, ...) but use virtualenv to create virtual
> environment and there install current Django version (or any version you
> want to) with easy_install or pip. You will have to google and read about
> these tools, then uninstal distribution package (and your django 1.2
> installation) and play with. These tools are very easy to use. And one more
> thing, read something about python path, eggs, *.pth files, you will need
> this knowledge to understand how this whole import machinery works, else it
> will be very confusing.
>
> Martin
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: overriding model.save()

2010-08-05 Thread Paulo Almeida
I never tried this, but I think you could just delete the value from the
form.cleaned_data dictionary, if you don't want it:

if instance.my_field == some_value:
del form.cleaned_data['my_field']

This would be in the view, before saving, so you wouldn't need to override
anything.

- Paulo

On Wed, Aug 4, 2010 at 6:05 PM, Sells, Fred wrote:

> I would like to prevent saving a new value if the database contains a
> specific value.  This is on a per field, per record basis.
>
> If I override the save() method; is there a way to find the existing (in
> the DB) values and the new (to be stored) values?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Announces django-guardian: per object permissions for Django 1.2

2010-08-05 Thread Russell Keith-Magee
On Thu, Aug 5, 2010 at 3:32 AM, lukaszb  wrote:
> Thanks for the comment! I really do think that this "backends ready &&
> included" parts of Django are extremely useful (and fun to extend if
> needed).
>
> About the admin, I haven't really get into admin integration yet as I
> cannot answer this: should user with "flatpages.change_flatpage"
> permission for flatpage instance be able to edit it at admin if he/she
> doesn't have "flatpage.change_flatpage" global permission? I'm just
> stuck here - I suppose it would be good to "turn off" ability to
> change some objects for user with this global "app.change_obj"
> permission removal. On the other hand, wouldn't it be too much to give
> such global permission for user if we intend to allow him/her to
> change only single object?

There are two possible readings of the global obj=None case.

 a) A user must have the global permission in order to be granted the
permission for individual objects. This means that the global
permission is a 'gatekeeper' of sorts for individual object
permissions.

 b) The global permission is the 'fallback' permission if a specific
object permssion doesn't exist. That is the obj=None permission is the
"allow all" permission.

My reading of the code and docs [1] [2] is that (b) is the intended
interpretation. From a practical standpoint, this also makes sense: in
the case of (a), there is no way to grant a wildcard permission.

[1] 
http://docs.djangoproject.com/en/dev/topics/auth/#django.contrib.auth.models.User.has_perm
[2] http://code.djangoproject.com/wiki/RowLevelPermissions

So - in terms of the practical situation you describe; this means that
a user can only edit a specific flatpage if they have the change
permission for a specific instance, *or* they have the global obj=None
permission.

The issue that cascades on from this is the UX issue of how to
represent an object that you can't edit. Should it be displayed, but
not presented as a link? Should it be hidden entirely?

Yours,
Russ Magee %-)

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



Question on databases

2010-08-05 Thread cootetom
Is it better to have one large database with all the data for a web
site in it or many smaller databases that hold data for specific
area's of a web site in it?

Thinking that one database with some sort of clustering technology is
better than trying to manage many smaller databases?

Also, if data needs to be linked should multiple databases be avoided
all together?


Asking these questions because I've not faced the issue of scaling
massively as yet and would value the knowledge from those who have.

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



Re: overriding model.save()

2010-08-05 Thread Sam Lai
On 5 August 2010 03:05, Sells, Fred  wrote:
> I would like to prevent saving a new value if the database contains a
> specific value.  This is on a per field, per record basis.
>
> If I override the save() method; is there a way to find the existing (in
> the DB) values and the new (to be stored) values?

Just perform database queries as per normal inside the save() method.

You have access to the object to be stored as well, see
http://docs.djangoproject.com/en/dev/topics/db/models/#overriding-model-methods

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

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



Creating a html table...

2010-08-05 Thread ROger
I want  to create a html table containing taking from database , this
table should be sortable and searchable..
How do i do that??

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



Re: Question on databases

2010-08-05 Thread Steve Holden
On 8/5/2010 7:53 AM, cootetom wrote:
> Is it better to have one large database with all the data for a web
> site in it or many smaller databases that hold data for specific
> area's of a web site in it?
> 
> Thinking that one database with some sort of clustering technology is
> better than trying to manage many smaller databases?
> 
I'm not sure why clustering technology would be necessary to support a
single database ...

Most database engines (including MySQL, PostgreSQL and MS SQL Server)
will allow a single instance to support multiple databases if you need
that. There isn't really any reason why you should have separate
database for a single site, though. What advantage would you perceive to
this? Were they going to be on distinct server machines?

> Also, if data needs to be linked should multiple databases be avoided
> all together?
> 
It's certainly going to be slow to join data from tables in two
different databases, and you may end up having to do this in your
application code.
> 
> Asking these questions because I've not faced the issue of scaling
> massively as yet and would value the knowledge from those who have.
> 
Define "massive". It's usually best to start with one database, and
optimize as the load requires. Otherwise you might find yourself
optimizing areas where performance is already adequate.

regards
 Steve

-- 
I'm no expert.
"ex" == "has-been"; "spurt" == "drip under pressure"
"expert" == "has-been drip under pressure".

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



Re: Python Segfaults with Django 1.1

2010-08-05 Thread Sven Broeckling
> > i have a problem on a debian lenny machine which is not easy to
> > track down. It started with Apache2 mod_wsgi crashes (segfault in
> > libapr) after the migration from mod_python. The server crashes
> > sporadic and everytime with another view called, but everytime
> > after a while (2-7 Days, depending on traffic).
> Probably not related, but you never know... I've seen this happen in
> ye olde days with a zope server that you'd start in daemon mode from
> the terminal.  After 2-4 days the terminal would die and suddenly the 
> perfectly-running zope server would have nowhere to print its console 
> output once an infrequent error occured. And it would die.
> The wsgi stuff works differently, so this shouldn't be the problem. 
> Mentioning it anyway, perhaps it rings some distant bell :-)

I got another clue, it seems that the python process runs out of file
handles. After 10k requests (via ab -c 1 -n 1) i got several "not
found" io exceptions like "/dev/urandom not found", TemplateError:
Template xy not found and this one : Error Opening
file /path/to/geoip/GeoIP.dat

Maybe that is why the mod_python setup runs fine, due to the restart
for each request. 

Sven

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



Apache and mod_wsgi memory help

2010-08-05 Thread Albert Hopkins
... Or perhaps mod_wsgi is not the way to go.

Basically I have this situation.  I have a Django app that also has an
xmlrpc interface via the wiki recipe[1].  All works fine until I enabled
the ability to upload files.  Since they're binary files I use the
xmlrpc binary type. 

 Well this loads the files entirely in memory on the server side, which
ordinarily is ok since the files are only typically a few MB.  However,
python/mod_wsgi/apache are not releasing the memory.  I've tried
manually del'ing the objects and calling the garbage collector, but have
only had minimal success.  If I continue to upload files en-mass via
xmlrpc eventually Apache processes max out the available memory.

I'm hoping someone can point me to a coding or configuration solution.
Or perhaps mod_wsgi is not the best solution for this and I should go
FastCGI?

[1] http://code.djangoproject.com/wiki/XML-RPC


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



Re: Creating a html table...

2010-08-05 Thread Franklin Einspruch
I would start with learning how models work in Django.

http://docs.djangoproject.com/en/dev/topics/db/models/

Franklin



On Thu, Aug 5, 2010 at 8:00 AM, ROger  wrote:
> I want  to create a html table containing taking from database , this
> table should be sortable and searchable..
> How do i do that??
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>



-- 
Art, writing, journal: http://einspruch.com
Comics: http://themoonfellonme.com

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



Re: Jquery-ui in admin: c is undefined

2010-08-05 Thread David De La Harpe Golden
On 05/08/10 08:59, Alessandro Ronchi wrote:

> Is there a way to avoid attaching two times the same jquery library in
> admin?

Well, the noConflict(true) is a Feature, deliberately decoupling the
bundled jquery the admin uses from any jquery (and other "$" snaffling
libraries - the "true" stops it eating "jQuery" too) you might choose to
deploy.

http://api.jquery.com/jQuery.noConflict/

If the django admin didn't do that now that it's using jquery I'd be
whining about it and asking that it do so.

In theory you could probably "re-conflict" it, i.e. grab the
django.jQuery and put it back into the global scope as
 Query (and maybe $ - jquery-ui uses jQuery) ...but I wouldn't
recommend it, just look at the admin jquery as an implementation detail
and supply your own for your own uses.

You could I suppose point at the same source url twice, then the browser
may cache it even though it runs it twice.  But again, I wouldn't bother.

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



model inheritance, abtract=True

2010-08-05 Thread Roald de Vries

Dear all,

I have the following error, and don't know what it means:

Error: One or more models did not validate:
update.personupdate: 'address' has a relation with model Address,  
which has either not been installed or is abstract.


I did a pretty big refactoring, but I think the problems started when  
I separated my Person class into an abstract base class PersonProfile  
and a derived class Person, and added the class PersonUpdate, deriving  
from PersonProfile too.


Can anybody help?

Thanks in advance, cheers,

Roald

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



Re: Python Segfaults with Django 1.1

2010-08-05 Thread Reinout van Rees

On 08/05/2010 02:06 PM, Sven Broeckling wrote:


I got another clue, it seems that the python process runs out of file
handles. After 10k requests (via ab -c 1 -n 1) i got several "not
found" io exceptions like "/dev/urandom not found",


Some tempfile that isn't getting closed? Watch your /tmp size, for 
instance. Normally if you do it from views or so, the tempfile object 
gets garbage collected and closed.


Anyway, you probably already know where to look :-)


Reinout



--
Reinout van Rees - rein...@vanrees.org - http://reinout.vanrees.org
Programmer at http://www.nelen-schuurmans.nl
"Military engineers build missiles. Civil engineers build targets"

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



Re: Apache and mod_wsgi memory help

2010-08-05 Thread Graham Dumpleton


On Aug 5, 10:14 pm, Albert Hopkins  wrote:
> ... Or perhaps mod_wsgi is not the way to go.
>
> Basically I have this situation.  I have a Django app that also has an
> xmlrpc interface via the wiki recipe[1].  All works fine until I enabled
> the ability to upload files.  Since they're binary files I use the
> xmlrpc binary type.
>
>  Well this loads the files entirely in memory on the server side, which
> ordinarily is ok since the files are only typically a few MB.  However,
> python/mod_wsgi/apache are not releasing the memory.  I've tried
> manually del'ing the objects and calling the garbage collector, but have
> only had minimal success.  If I continue to upload files en-mass via
> xmlrpc eventually Apache processes max out the available memory.
>
> I'm hoping someone can point me to a coding or configuration solution.
> Or perhaps mod_wsgi is not the best solution for this and I should go
> FastCGI?

It isn't going to be a mod_wsgi issue but your Python web application.
That or how you have configured Apache/mod_wsgi.

Do realize though that the way memory allocations work, if there is a
large transient memory usage for a request which increases overall
process memory usage, then once that request finishes the size of the
process isn't then going to magically shrink. This is because the
working memory size of a process will normally remain at that level.
The memory will however go back into the free memory list for that
process and can be used for subsequent requests.

If you don't see memory usage plateau based on largest transient
memory requirement for how ever many concurrent requests can execute
that handler at a time, then you likely have a memory leak, or more
likely what I call a resource leakage. That is where Python can't
actually free objects because something is still referencing them or
cycles exist withing object dependencies and del methods exist which
mean the cycle can't be broken and the objects reclaimed.

As far as Apache/mod_wsgi configuration goes, ensure you are not using
embedded mode, especially if using prefork MPM with Apache as that can
be a recipe for disaster. Do a Google search for:

  site:blog.dscpl.com.au transient memory

And read my blog post about memory spikes and load issues for
mod_python. Same issue applies to mod_wsgi embedded mode.

So, make sure you are using daemon mode and fixed number of processes.

Otherwise use a memory profiler for Python such as Dozer to work out
where memory use is occurring for a request and why objects aren't
being released.

Graham


> [1]http://code.djangoproject.com/wiki/XML-RPC

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



Re: Python Segfaults with Django 1.1

2010-08-05 Thread Graham Dumpleton


On Aug 5, 10:06 pm, Sven Broeckling  wrote:
> > > i have a problem on a debian lenny machine which is not easy to
> > > track down. It started with Apache2 mod_wsgi crashes (segfault in
> > > libapr) after the migration from mod_python. The server crashes
> > > sporadic and everytime with another view called, but everytime
> > > after a while (2-7 Days, depending on traffic).
> > Probably not related, but you never know... I've seen this happen in
> > ye olde days with a zope server that you'd start in daemon mode from
> > the terminal.  After 2-4 days the terminal would die and suddenly the
> > perfectly-running zope server would have nowhere to print its console
> > output once an infrequent error occured. And it would die.
> > The wsgi stuff works differently, so this shouldn't be the problem.
> > Mentioning it anyway, perhaps it rings some distant bell :-)
>
> I got another clue, it seems that the python process runs out of file
> handles. After 10k requests (via ab -c 1 -n 1) i got several "not
> found" io exceptions like "/dev/urandom not found", TemplateError:
> Template xy not found and this one : Error Opening
> file /path/to/geoip/GeoIP.dat
>
> Maybe that is why the mod_python setup runs fine, due to the restart
> for each request.

But mod_python doesn't restart on each request.

Use lsof or ofiles to work out what open file handles still exist for
a process and thus what isn't being closed.

Graham


> Sven

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



Re: Creating a html table...

2010-08-05 Thread Reinout van Rees

On 08/05/2010 02:00 PM, ROger wrote:

I want  to create a html table containing taking from database , this
table should be sortable and searchable..
How do i do that??


There are javascript libraries for showing so-called grids.  The more 
elaborate ones allow you to sort on various colums. And perhaps even a 
search function.


On the template side you often only have to create a html table and tell 
the javascript to do its job.




Reinout


--
Reinout van Rees - rein...@vanrees.org - http://reinout.vanrees.org
Programmer at http://www.nelen-schuurmans.nl
"Military engineers build missiles. Civil engineers build targets"

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



Re: django.views.static.serve issue

2010-08-05 Thread Reinout van Rees

On 08/05/2010 01:36 PM, bagheera wrote:

Hi, i set up static files for development purposes in following way:

urls.py:


if settings.DEBUG:
urlpatterns += patterns('',(r'^site_media/(?P.*)$',
'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}),)

settings.py:

MEDIA_ROOT = '/home/bagheera/NetBeansProjects/nml-src/storage'
MEDIA_URL = 'http://localhost:8000/site_media/'

index.html template:



WHY i had to add "site_media" string, when it IS already included in
MEDIA_URL ?
If i use

dev server gives output:
/images/clock.gif/ HTTP/1.1" 404 2155

Full path to this file is:
'/home/bagheera/NetBeansProjects/nml-src/storage/images/clock.gif'


Probably MEDIA_URL isn't set at all in that template.  If even the 
"localhost:8000" isn't showing up...


I saw that problem once, too.  The reason was that the template is 
rendered without the proper context.  You'll need to pass along a 
RequestContext:



from django.template import RequestContext

def your_view(request):
...
return render_to_response(
your_template,
{'some': 'parameter'},
context_instance=RequestContext(request))


Reinout





--
Reinout van Rees - rein...@vanrees.org - http://reinout.vanrees.org
Programmer at http://www.nelen-schuurmans.nl
"Military engineers build missiles. Civil engineers build targets"

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



Re: model inheritance, abtract=True

2010-08-05 Thread Emily Rodgers


On Aug 5, 1:50 pm, Roald de Vries  wrote:
> Dear all,
>
> I have the following error, and don't know what it means:
>
>      Error: One or more models did not validate:
>      update.personupdate: 'address' has a relation with model Address,  
> which has either not been installed or is abstract.
>
> I did a pretty big refactoring, but I think the problems started when  
> I separated my Person class into an abstract base class PersonProfile  
> and a derived class Person, and added the class PersonUpdate, deriving  
> from PersonProfile too.
>
> Can anybody help?
>
> Thanks in advance, cheers,
>
> Roald

Can you provide some code snippets from your model definitions?

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



Re: Python Segfaults with Django 1.1

2010-08-05 Thread Graham Dumpleton


On Aug 5, 10:06 pm, Sven Broeckling  wrote:
> > > i have a problem on a debian lenny machine which is not easy to
> > > track down. It started with Apache2 mod_wsgi crashes (segfault in
> > > libapr) after the migration from mod_python. The server crashes
> > > sporadic and everytime with another view called, but everytime
> > > after a while (2-7 Days, depending on traffic).
> > Probably not related, but you never know... I've seen this happen in
> > ye olde days with a zope server that you'd start in daemon mode from
> > the terminal.  After 2-4 days the terminal would die and suddenly the
> > perfectly-running zope server would have nowhere to print its console
> > output once an infrequent error occured. And it would die.
> > The wsgi stuff works differently, so this shouldn't be the problem.
> > Mentioning it anyway, perhaps it rings some distant bell :-)
>
> I got another clue, it seems that the python process runs out of file
> handles. After 10k requests (via ab -c 1 -n 1) i got several "not
> found" io exceptions like "/dev/urandom not found", TemplateError:
> Template xy not found and this one : Error Opening
> file /path/to/geoip/GeoIP.dat
>
> Maybe that is why the mod_python setup runs fine, due to the restart
> for each request.


Also make sure you aren't still loading mod_python into Apache if
using mod_wsgi as the presence of mod_python can in some cases cause
mod_wsgi to misbehave.

Graham

> Sven

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



[solved] Re: Python Segfaults with Django 1.1

2010-08-05 Thread Sven Broeckling
> > I got another clue, it seems that the python process runs out of
> > file handles. After 10k requests (via ab -c 1 -n 1) i got
> > several "not found" io exceptions like "/dev/urandom not found",
> Some tempfile that isn't getting closed? Watch your /tmp size, for 
> instance. Normally if you do it from views or so, the tempfile object 
> gets garbage collected and closed.
> Anyway, you probably already know where to look :-)
That was exactly the right point i guess. I was caught by this one :
http://bugs.python.org/issue6875
After adding os.close(fd) to an svg -> png Function the App doesn't
leak file descriptors any more. 

In about 30k Requests i know if it was the cause for the segfaults :)

Thanks Reinout :)
  Sven

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



Re: Python Segfaults with Django 1.1

2010-08-05 Thread Sven Broeckling
> > I got another clue, it seems that the python process runs out of
> > file handles. After 10k requests (via ab -c 1 -n 1) i got
> > several "not found" io exceptions like "/dev/urandom not found",
> > TemplateError: Template xy not found and this one : Error Opening
> > file /path/to/geoip/GeoIP.dat
> > Maybe that is why the mod_python setup runs fine, due to the restart
> > for each request.
> Also make sure you aren't still loading mod_python into Apache if
> using mod_wsgi as the presence of mod_python can in some cases cause
> mod_wsgi to misbehave.
No, mod_python is deactivated, but the file descriptor leak was imho
the problem.. 

The Fix, for the record :)

--- a/apps/catalog/templatetags/composedimage.py
+++ b/apps/catalog/templatetags/composedimage.py
@@ -105,7 +105,7 @@ class ComposedImage(object):
 def _open_svg_as_image(self, fn, width, height, position, factor,
offset): import cairo
 import rsvg
-file = tempfile.mkstemp(suffix='.png', prefix='tmc_svg_')[1]
+fd,file = tempfile.mkstemp(suffix='.png', prefix='tmc_svg_')
 fn = smart_str(fn)
 svg = rsvg.Handle(file=fn)
 
@@ -123,7 +123,10 @@ class ComposedImage(object):
 surface.write_to_png(file)
 image = Image.open(file, "r")
 image.convert("RGBA")
+
+os.close(fd)
 os.unlink(file)

Thanks,
  Sven

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



Re: model inheritance, abtract=True

2010-08-05 Thread Roald de Vries

On Aug 5, 2010, at 3:00 PM, Emily Rodgers wrote:



On Aug 5, 1:50 pm, Roald de Vries  wrote:

Dear all,

I have the following error, and don't know what it means:

 Error: One or more models did not validate:
 update.personupdate: 'address' has a relation with model  
Address,

which has either not been installed or is abstract.

I did a pretty big refactoring, but I think the problems started when
I separated my Person class into an abstract base class PersonProfile
and a derived class Person, and added the class PersonUpdate,  
deriving

from PersonProfile too.

Can anybody help?

Thanks in advance, cheers,

Roald


Can you provide some code snippets from your model definitions?


I had adapted the error a little, but here the real code (in Dutch)  
and the corresponding errors. I can help you with the Dutch if it's  
necessary ;-).



#
# in core.models:
#

# ...
class Persoonprofiel(models.Model):
geslacht   = models.CharField(max_length=8, choices=(('M',  
'Man'), ('V', 'Vrouw')))

voorletters= models.CharField(max_length=12, blank=False)
# ...
class Meta:
abstract = True
# ...
class Persoon(Persoonprofiel):
foto   = models.ImageField(upload_to="personen_fotos",  
blank=True)

titel  = models.CharField(max_length=100, blank=True)
# ...
class Meta:
verbose_name = 'Persoon'
verbose_name_plural = 'Personen'
ordering = ['achternaam']


###
# in update.models:
###

# ...
class PersoonUpdate(Persoonprofiel):
persoon  = models.ForeignKey('Persoon')
bezoekadres  = models.ForeignKey('Adres',  
related_name='persoonupdates_als_bezoekadres',  blank=True, null=True)

# ...


#
# errors:
#

Error: One or more models did not validate:
update.persoonupdate: 'persoon' has a relation with model Persoon,  
which has either not been installed or is abstract.
update.persoonupdate: 'bezoekadres' has a relation with model Adres,  
which has either not been installed or is abstract.

# ...




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



Re: django mail_admins source code

2010-08-05 Thread Tom Evans
On Thu, Aug 5, 2010 at 10:31 AM, kostia  wrote:
> ...
> I think to use something like
> recipients = []
> for admin in settings.ADMINS:
>     recipients += admin[1]
>
> But it seems to be unprofessional.
>

'List comprehension'

recipients = [ email for name, email in settings.ADMINS ]

Cheers

Tom

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



Re: How to get the model name of an object in template?

2010-08-05 Thread David.D
TemplateSyntaxError at /products/Product/263/
Variables and attributes may not begin with underscores:
'object._meta'

Request Method: GET
Request URL:http://127.0.0.1:8000/products/Product/263/
Django Version: 1.3 pre-alpha
Exception Type: TemplateSyntaxError
Exception Value:
Variables and attributes may not begin with underscores:
'object._meta'
...

On Aug 5, 7:15 pm, Paulo Almeida  wrote:
> But _meta starts with an underscore, so you can't use it in the template,
> right? I'm still using Django 1.0.2, so I don't know if that has changed
> along the way.
>
> - Paulo
>
> On Thu, Aug 5, 2010 at 8:52 AM, Daniel Roseman wrote:
>
>
>
> > On Aug 4, 7:27 pm, "David.D"  wrote:
> > > I just wonder if there's some way requires writing nothing. Just like
> > > an attribute.
>
> > > thanks.
>
> > Yes, there is. Each model and model instance object has a _meta
> > attribute, which contains information about the model -
> > the .app_label, object_name and .verbose_name will probably be useful
> > to you.
> > --
> > DR.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > django-users+unsubscr...@googlegroups.com > groups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/django-users?hl=en.

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



Interpolation and comparation between 2 dates: easy and difficult at the same time

2010-08-05 Thread Alexandre González
I've develope a "simple" function to calculate the difference between 2
dates, and the time that they are interpolated.

I need it to: I arrive to a site at a hour (my_from), I go out from the site
at a hour (my_to). Some friend arrive at the site at a hour (his_from) and
let it at a hour (his_to)

If I stay in the site after he arrives and before he goes out, the
"probability" of match is 1, if I let the site after he arrives, the
probability of match is 0... You can see the samples in the documentation.

I need to know if this is a good way to do, and if compare all the kinds of
matching (I've found 6). This is the code:

def time_match(self, my_from, my_to, his_from, his_to):
"""
I've found 6 general kinds of time matching. It's better to
explain it with graphics:

  (my_from)--A--(my_to)
-
 (his_from)--B--(his_to)
"""

#|-A-|   |-A-|
#  or 
#   |--B--||--B--|
if my_to < his_from or his_to < my_from:
return 0

#  |--A--|
# 
#  |--B---|
elif my_from >= his_from and my_to <= his_to:
return 1

#|-A---|
# 
#|-B-|
elif my_from < his_from and my_to > his_to:
my_diff_to_reuse = diff_in_seconds(my_from, my_to)
diff = my_diff_to_reuse - self.diff_in_seconds(his_from, his_to)

return (diff / my_diff_to_reuse)

#   |---A---|
# 
#   |---B---|
elif my_from <= his_from and my_to <= his_to:
diff = self.diff_in_seconds(his_from, my_to)

return (diff / self.diff_in_seconds(my_from, my_to))

# |---A---|
# 
#|---B---|
elif my_from >= his_from and my_to >= his_to:
diff  = self.diff_in_seconds(my_from, his_to)

return (diff / self.diff_in_seconds(my_from, my_to))

# If I'm here I have a problem
return 0


def diff_in_seconds(date1, date2):
# Initial from: http://www.bytemycode.com/snippets/snippet/304/
timedelta = date2 - date1
diff = timedelta.days*24*3600 + timedelta.seconds

return abs(float(diff))

Thanks!
-- 
Please, don't send me files with extensions: .doc, .docx, .xls, .xlsx, .ppt
and/or .pptx
http://mirblu.com

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



Re: Jquery-ui in admin: c is undefined

2010-08-05 Thread Alessandro Ronchi
2010/8/5 David De La Harpe Golden :

>
> In theory you could probably "re-conflict" it, i.e. grab the
> django.jQuery and put it back into the global scope as
>  Query (and maybe $ - jquery-ui uses jQuery) ...but I wouldn't
> recommend it, just look at the admin jquery as an implementation detail
> and supply your own for your own uses.


It's not possible to tell jquery-ui to use the  django.query namespace?


-- 
Alessandro Ronchi
http://www.soasi.com

Hobby & Giochi
http://hobbygiochi.com
http://www.facebook.com/hobbygiochi

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



Re: Need help with my Form.save() method. Trouble with ForeignKey and ManyToMany Fields.

2010-08-05 Thread strayhand
Yep. I used Firebug to look at the HTTP information and "username" is
in there. Here's what firebug shows:

Parametersapplication/x-www-form-urlencoded
address P.O. Box 56868
areas   1
birth_date  1979-10-09
cityPuyallup
country USA
csrfmiddlewaretoken 0258a209df8a7df0ccca24ce789a448e
email   someem...@hotmail.com
first_name  Toby
last_name   Beal
password1   1234
password2   1234
phone   253-555-555
state_province  WA
usernametobybeal
zip_code98379

I believe that the problem isn't with the form creation or submission
but with my save method. The error seems to be specific to the way in
which I'm trying to create a new user. Here's my save method from the
form again.

# Taken from registration.forms.py

def save(self):

# User
new_user =
User.objects.create_user(username=self.cleaned_data['username'],
email=self.cleaned_data['email'],
password=self.cleaned_data['password1'])
new_user.first_name = self.cleaned_data['first_name']
new_user.last_name = self.cleaned_data['last_name']
new_user.is_active = True
new_user.save()

# Profile
new_profile = UserProfile.objects.create()
new_profile.user =
User.objects.get(username__exact=self.cleaned_data['username'])
new_profile.phone = self.cleaned_data['phone']
new_profile.address = self.cleaned_data['address']
new_profile.city = self.cleaned_data['city']
new_profile.state_province =
self.cleaned_data['state_province']
new_profile.country = self.cleaned_data['country']
new_profile.zip_code = self.cleaned_data['zip_code']
new_profile.birth_date =
self.cleaned_data['birth_date']
new_profile.areas = self.cleaned_data['areas']
new_profile.save()

return

What should I be doing differently with this snippet?

new_user =
User.objects.create_user(username=self.cleaned_data['username'],
email=self.cleaned_data['email'],
password=self.cleaned_data['password1'])

Thanks.

~trb

On Aug 5, 4:32 am, Paulo Almeida  wrote:
> Can you check the POST data and see if 'username' is there? You can do it
> easily with Firefox's Firebug extension.
>
> - Paulo
>
> On Thu, Aug 5, 2010 at 6:24 AM, strayhand  wrote:
> > So I'm rolling out my own registration form that should update the
> > following models:
>
> > - User (auth module)
> > - UserProfile
>
> > Everything seems to be coming together but I'm having a hard time with
> > the save() method for the form. My UserProfile model has a couple of
> > fields that refer to other models and I'm having difficulty setting
> > them up properly. I keep getting an error telling me:
>
> > Exception Type: IntegrityError at /registration/
> > Exception Value: auth_user.username may not be NULL
>
> > I know where the problems are:
>
> > new_user =
> > User.objects.create_user(username=self.cleaned_data['username'],
> > email=self.cleaned_data['email'],
> > password=self.cleaned_data['password1'])
>
> > and I'm getting this similar error for defining the user profile on
> > the line below.
>
> > new_profile.user =
> > User.objects.get(username__exact=self.cleaned_data['username'])
>
> > I'm just not sure how else to write this stuff. I'm including my form,
> > model and the exact error message that I'm getting below. Any insight
> > that you have is greatly appreciated. Thank you.
>
> > # registration.forms.py
>
> > import re
> > from django import forms
> > from django.db import models
> > from django.contrib.localflavor.us.forms import USPhoneNumberField
> > from django.contrib.auth.models import User
> > from ylbbq.areas.models import Area
> > from ylbbq.profiles.models import UserProfile
>
> > STATES = (
> >        ('WA', 'Washington'),
> >        ('AK', 'Alaska'),
> >        ('AL', 'Alabama'),
> >        ('AR', 'Arkansas'),
> >        ('AZ', 'Arizona'),
> >        ('CA', 'California'),
> >        ('CO', 'Colorado'),
> >        ('CT', 'Connecticut'),
> >        ('DE', 'Delaware'),
> >        ('FL', 'Florida'),
> >        ('GA', 'Georgia'),
> >        ('HI', 'Hawaii'),
> >        ('IA', 'Iowa'),
> >        ('ID', 'Idaho'),
> >        ('IL', 'Illinois'),
> >        ('IN', 'Indiana'),
> >        ('KS', 'Kansas'),
> >        ('KY', 'Kentucky'),
> >        ('LA', 'Louisiana'),
> >        ('MA', 'Massachusetts'),
> >        ('MD', 'Maryland'),
> >        ('ME', 'Maine'),
> >        ('MI', 'Michigan'),
> >        ('MN', 'Minnesota'),
> >        ('MO', 'Missouri'),
> >        ('MS', 'Mississippi'),
> >        ('MT', 'Montana'),
> >        ('NC', 'North Carolina'),
> >        ('ND', 'North Dakota'),
> >        ('NE', 'Nebraska'),
> >        ('NH', 'New Hampshire'),
> >        ('NJ', 'New Jersey'),
> >        ('NM', 'New Mexico'),
> >        ('NV', 'Nevada'),
> >        ('NY', 'New York'),
> >        ('OH', 'Ohio'),
>

Re: View Decorator

2010-08-05 Thread Dan Gentry
Steve, thanks for the guidance.  I'm heading in the right direction
with a better understanding of the concept, but still stymied by the
urls error.  Not seeing the connection between adding a decorator and
having trouble with urls.py.  I'll get there.  Dan

On Aug 4, 11:31 am, Steve Holden  wrote:
> On 8/4/2010 10:52 AM, Dan Gentry wrote:
>
>
>
>
>
> > When I attempt to use the decorator logic, the view becomes this:
>
> > views.py
> > @institution_required
> > def list_type(request):
>
> >     inst_id=request.session.get('inst_id',None)
>
> >     queryset = RecordType.objects.filter(institution=inst_id)
> >     return object_list(request, queryset, paginate_by = 12)
>
> > I don't make any changes to urls.py, but the error is
> > "TemplateSyntaxError at /index
> > Caught ImproperlyConfigured while rendering: The included urlconf
> > person.urls doesn't have any patterns in it"
> > However, when I take out the decorator, all of the urls work as
> > expected.
>
> > urls.py does import * from views.py
>
> Your decorator takes two arguments - its signature is
>
>   institution_required(fn, redirect_field_name=REDIRECT_FIELD_NAME)
>
> But the decorator mechanism only allows you to specify one argument (the
> decorated function). There is no way to specify anything OTHER than the
> default value for the redirect_field_name argument ...
>
> Therefore if you want to use decorators for this application you will
> have to write something more complex still: a function that takes a
> single redirect_field_name argument and /returns a decorator/ that can
> be applied to views. Then you would call it as
>
> @institution_required("Some_field_name")
> def list_type(request):
>   ...
>
> Your call to institution_required should return a decorator. That takes
> the decorated function as its single argument and returns the decorated
> function. This is getting a little complex for a beginner.
>
> regards
>  Steve
> --
> I'm no expert.
> "ex" == "has-been"; "spurt" == "drip under pressure"
> "expert" == "has-been drip under pressure".

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



Re: How to record users ip address every-time user logs in

2010-08-05 Thread Shawn Milochik
Maybe a combination of these two things will get you going.

1. A way to store additional information about users (such as IP addresses).
http://docs.djangoproject.com/en/dev/topics/auth/?from=olddocs#storing-additional-information-about-users

2. Get the IP address from the META attribute of the request object.
http://docs.djangoproject.com/en/dev/ref/request-response/#attributes

ShawnMilo

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



Linkedin Search

2010-08-05 Thread kostia
Yes, Linkedin mostly is written on Java.

Did you see its menu and the search to the right? People, Jobs,
Answers, Groups.

I would like to add something similar to this on my site.

I wish to learn about search mechanisms.

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



Re: how to make readonly in change but editable in add?

2010-08-05 Thread Shawn Milochik
You can do this very easily by tweaking your model as follows:

1. Override __init__() and store the value of that field in a
temporary value, such as self.old_status.

2. Override save() and before you call the super() save, check if
self.pk (meaning the instance is not new). If so, and self.old_status
!= self.current_status, you can raise an exception.

For extra credit you might want to tweak your ModelForm so that it
will raise a ValidationError, because otherwise it'll validate and
then you'll get a 500 error when the save() on the model is attempted.
However, I like having the exception raised at the model level because
it will protect your data in case the model is accessed by some means
other than your ModelForm.

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



Re: View Decorator

2010-08-05 Thread Steve Holden
I don't know whether it will help, but it seems that it isn't the
top-level urls.py that the error is complaining about but the one in
your persons app. Presumably the top-level urlconf includes that?

As to why applying a decorator should trigger the problem, I am a bit
stumped.

regards
 Steve

On 8/5/2010 11:14 AM, Dan Gentry wrote:
> Steve, thanks for the guidance.  I'm heading in the right direction
> with a better understanding of the concept, but still stymied by the
> urls error.  Not seeing the connection between adding a decorator and
> having trouble with urls.py.  I'll get there.  Dan
> 
> On Aug 4, 11:31 am, Steve Holden  wrote:
>> On 8/4/2010 10:52 AM, Dan Gentry wrote:
>>
>>
>>
>>
>>
>>> When I attempt to use the decorator logic, the view becomes this:
>>
>>> views.py
>>> @institution_required
>>> def list_type(request):
>>
>>> inst_id=request.session.get('inst_id',None)
>>
>>> queryset = RecordType.objects.filter(institution=inst_id)
>>> return object_list(request, queryset, paginate_by = 12)
>>
>>> I don't make any changes to urls.py, but the error is
>>> "TemplateSyntaxError at /index
>>> Caught ImproperlyConfigured while rendering: The included urlconf
>>> person.urls doesn't have any patterns in it"
>>> However, when I take out the decorator, all of the urls work as
>>> expected.
>>
>>> urls.py does import * from views.py
>>
>> Your decorator takes two arguments - its signature is
>>
>>   institution_required(fn, redirect_field_name=REDIRECT_FIELD_NAME)
>>
>> But the decorator mechanism only allows you to specify one argument (the
>> decorated function). There is no way to specify anything OTHER than the
>> default value for the redirect_field_name argument ...
>>
>> Therefore if you want to use decorators for this application you will
>> have to write something more complex still: a function that takes a
>> single redirect_field_name argument and /returns a decorator/ that can
>> be applied to views. Then you would call it as
>>
>> @institution_required("Some_field_name")
>> def list_type(request):
>>   ...
>>
>> Your call to institution_required should return a decorator. That takes
>> the decorated function as its single argument and returns the decorated
>> function. This is getting a little complex for a beginner.
>>
>> regards
>>  Steve
>> --
>> I'm no expert.
>> "ex" == "has-been"; "spurt" == "drip under pressure"
>> "expert" == "has-been drip under pressure".
> 


-- 
I'm no expert.
"ex" == "has-been"; "spurt" == "drip under pressure"
"expert" == "has-been drip under pressure".

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



Re: model inheritance, abtract=True

2010-08-05 Thread Roald de Vries

On Aug 5, 2010, at 3:15 PM, Roald de Vries wrote:

On Aug 5, 2010, at 3:00 PM, Emily Rodgers wrote:



On Aug 5, 1:50 pm, Roald de Vries  wrote:

Dear all,

I have the following error, and don't know what it means:

Error: One or more models did not validate:
update.personupdate: 'address' has a relation with model  
Address,

which has either not been installed or is abstract.

I did a pretty big refactoring, but I think the problems started  
when
I separated my Person class into an abstract base class  
PersonProfile
and a derived class Person, and added the class PersonUpdate,  
deriving

from PersonProfile too.

Can anybody help?

Thanks in advance, cheers,

Roald


Can you provide some code snippets from your model definitions?


I had adapted the error a little, but here the real code (in Dutch)  
and the corresponding errors. I can help you with the Dutch if it's  
necessary ;-).



#
# in core.models:
#

# ...
class Persoonprofiel(models.Model):
   geslacht   = models.CharField(max_length=8, choices=(('M',  
'Man'), ('V', 'Vrouw')))

   voorletters= models.CharField(max_length=12, blank=False)
   # ...
   class Meta:
   abstract = True
# ...
class Persoon(Persoonprofiel):
   foto   = models.ImageField(upload_to="personen_fotos",  
blank=True)

   titel  = models.CharField(max_length=100, blank=True)
   # ...
   class Meta:
   verbose_name = 'Persoon'
   verbose_name_plural = 'Personen'
   ordering = ['achternaam']


###
# in update.models:
###

# ...
class PersoonUpdate(Persoonprofiel):
   persoon  = models.ForeignKey('Persoon')
   bezoekadres  = models.ForeignKey('Adres',  
related_name='persoonupdates_als_bezoekadres',  blank=True, null=True)

   # ...


#
# errors:
#

Error: One or more models did not validate:
update.persoonupdate: 'persoon' has a relation with model Persoon,  
which has either not been installed or is abstract.
update.persoonupdate: 'bezoekadres' has a relation with model Adres,  
which has either not been installed or is abstract.

# ...


Solved. Solution: omit the quotes the referenced models that foreign  
keys refer to.


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



Re: Jquery-ui in admin: c is undefined

2010-08-05 Thread shacker
On Aug 5, 5:22 am, David De La Harpe Golden
 wrote:
>
> In theory you could probably "re-conflict" it, i.e. grab the
> django.jQuery and put it back into the global scope as
>  Query (and maybe $ - jquery-ui uses jQuery) ...but I wouldn't
> recommend it, just look at the admin jquery as an implementation detail
> and supply your own for your own uses.

Would be nice if this were mentioned in the Django docs somewhere - I
wasted a lot of time on this same problem the other day, not wanting
to load my own jQuery because I could plainly see that it was already
there and not wanting to double-load it, then finally realizing that
double-loading it was the only way to fix it.

./s

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



Re: how to make readonly in change but editable in add?

2010-08-05 Thread shmengie
I think it's better to let the user know the fields exist and may not
be changed, than to present them with editable fields that may not.

Has to do with consistent presentation and notification.  Data
validation needs to be implemented in either event, because you cannot
guarantee the user will show the same respect.

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



admin framework help

2010-08-05 Thread snipinben

I need help doing something probably very simple. so i have two tables,
Customers and Orders. now i know how to make access to both tables sepratly
in the admin framework. but i need something else. i was wondering if there
was a way to access the orders table through thr Customers page. like say i
chose to view the information for the customr Juan Mase. i click on his name
and i see all of his info, is there a way that along with this info, a
button is added that might say view customer orders and when i click on it,
it brings me to the  orders table page that correspond to Juan Mase. like a
link button or something? thanks
-- 
View this message in context: 
http://old.nabble.com/admin-framework-help-tp29356370p29356370.html
Sent from the django-users mailing list archive at Nabble.com.

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



Re: how to make readonly in change but editable in add?

2010-08-05 Thread Shawn Milochik
On Thu, Aug 5, 2010 at 12:31 PM, shmengie <1st...@gmail.com> wrote:
> I think it's better to let the user know the fields exist and may not
> be changed, than to present them with editable fields that may not.
>

I agree. That's not incompatible with my solution. I would expect the
user to be informed of the policy rather than just have changes
ignored.

I chose to present the simplest possible explanation you could use to
do what you wanted instead of going into great depth writing your
ModelForms for you because it was easier to do. I take for granted
that there is more than I know (or will ever know) going on in your
project and I expect that you will ignore or adapt my suggestions as
you see fit.

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



Re: admin framework help

2010-08-05 Thread Steve Holden
On 8/5/2010 12:42 PM, snipinben wrote:
> 
> I need help doing something probably very simple. so i have two tables,
> Customers and Orders. now i know how to make access to both tables sepratly
> in the admin framework. but i need something else. i was wondering if there
> was a way to access the orders table through thr Customers page. like say i
> chose to view the information for the customr Juan Mase. i click on his name
> and i see all of his info, is there a way that along with this info, a
> button is added that might say view customer orders and when i click on it,
> it brings me to the  orders table page that correspond to Juan Mase. like a
> link button or something? thanks

Are you asking how to do this using the ORM, or how to do it in the user
interface? It's actually pretty straightforward to follow foreign key
relationships, which seems to be what you are asking about.

regards
 Steve
-- 
I'm no expert.
"ex" == "has-been"; "spurt" == "drip under pressure"
"expert" == "has-been drip under pressure".

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



intermediate table in manytomany relationship not created

2010-08-05 Thread bksfu
Hi, I have the following model:

--
from django.db import models

class Phone(models.Model):
id = models.AutoField(primary_key=True, db_column='id')
type = models.CharField(max_length=1, db_column='Type',
null=False, blank=False)
status = models.CharField(max_length=1, db_column='Status',
null=False, blank=False)
country_code = models.CharField(max_length=3, db_column='Country',
blank=True)
area_code = models.CharField(max_length=3, db_column='AreaCode',
null=False, blank=False)
prefix = models.CharField(max_length=3, db_column='Prefix',
blank=True)
suffix = models.CharField(max_length=4, db_column='Suffix',
null=False, blank=False)

class Meta:
db_table = u'Phone'
app_label = u'testStuff'
db_tablespace = u'test'


class Room(models.Model):
id = models.AutoField(primary_key=True, db_column='id')
number = models.IntegerField(db_column='number', null=False,
blank=False)
building = models.CharField(max_length=5, db_column='Building',
null=False, blank=False)
type = models.CharField(max_length=1, db_column='Type',
null=False, blank=False)
campus = models.CharField(max_length=10, db_column='Campus',
null=False, blank=False)
phones = models.ManyToManyField(Phone, db_column='id', null=True)

class Meta:
db_table = u'Phone'
app_label = u'testStuff'
db_tablespace = u'test'
--

Next, I dropped the existing tables in my mysql db, then ran
'syncdb'.  The model tables were created, but not the intermediate
table. Adding phones & rooms are no problem, but I get an error when I
try to associate them, which states that the table 'Room_phones' does
not exist in the db.  I could manually create a 'through' table, I
guess, but shouldn't Django have created my intermediate table along
with the primary ones?  Thx for any help.

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



Specifying column names for ManyToMany fields

2010-08-05 Thread Steven L Smith
Hello,

I've been charged with creating a front-end in Django for a MSSQL
database. It
has to stay in MSSQL for various other reasons, so just using our
normal
Postgres stuff won't work.

It is all working, except for the internal names of ManyToMany Fields.
Our DBA
likes to follow the CamelCaseStyle, and Django likes the
underscore_style.

The two options I've found are:

1.) Define the field like this, using through:
websites = models.ManyToManyField('Website',
through='DepartmentsWebsites',
blank=True, null=True)

The problem there is that a lot of the ORM is disabled when you use
"through",
and the admin won't display the MultipleSelectWidgets for a table that
uses
"through".


2.) Define the field like this, using "db_table":
websites = models.ManyToManyField('Website',
db_table='Departments_Websites',
blank=True, null=True)

The problem there is that the Departments_Websites table contains
columns
called ID, DepartmentID, and WebsiteID, but Django is still looking
for id,
department_id, and website_id.

Any thoughts? Or would it be a LOT more difficult than just telling
the DBA
that we have to be slightly inconsistent in our naming schemes?


Thanks!


Steven L Smith, Web Developer
Department of Information Technology Services
Nazareth College of Rochester
585-389-2085   |   ssmit...@naz.edu
http://www.naz.edu/pub/~ssmith46


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



RE: overriding model.save()

2010-08-05 Thread Sells, Fred
That part makes sense, but where would I find the "new" values that have been 
set but not saved when my custom save() method is called? Like

X.a=3
X.b=4
X.save()

I want to see if b is a special value before saving.

-Original Message-
From: django-users@googlegroups.com [mailto:django-us...@googlegroups.com] On 
Behalf Of Sam Lai
Sent: Thursday, August 05, 2010 7:58 AM
To: django-users@googlegroups.com
Subject: Re: overriding model.save()

On 5 August 2010 03:05, Sells, Fred  wrote:
> I would like to prevent saving a new value if the database contains a
> specific value.  This is on a per field, per record basis.
>
> If I override the save() method; is there a way to find the existing (in
> the DB) values and the new (to be stored) values?

Just perform database queries as per normal inside the save() method.

You have access to the object to be stored as well, see
http://docs.djangoproject.com/en/dev/topics/db/models/#overriding-model-methods

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

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


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



error: 'get format is not defined' in DateTimeShortcuts.js

2010-08-05 Thread Ogi Vranesic
Hi dear django users

After I updated Django to version 1.2.1
and in myproject/media/js replaced
the old javascripts with the new from 
site-packages/django/contrib/admin/media/js
and site-packages/django/contrib/admin/media/js/admin
I become in DateTimeShortcuts.js the error 'get format is not defined'
Can somebody tell me what I'm missing?

Thanks in advance and best regards
Ogi

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



portable apps problem

2010-08-05 Thread bax...@gretschpages.com
I try to make my apps portable between the various sites/projects that
use them, but I'm running into some problems doing so. I'm hoping
there's some good way to handle this I just don't understand or know
about.

In a nutshell, I've got multiple sites/projects, and I'd like them to
all use the same articles app. Problem is, the articles app was
originally written for site A,and has at least one M2M relationship
with another app that site B does not have, need, or really want. So,
how do I give site A what it needs without cluttering up Site B with a
bunch of unwanted extras, while using the same app?

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



Re: intermediate table in manytomany relationship not created

2010-08-05 Thread bksfu
When Django created the above tables, they were created with the
MyISAM engine.  If the intermediate table has to have foreign keys
back to the Phone and Room tables, this would be illegal from MySQL's
perspective, which can apparently only form foreign key constraints
between InnoDB tables.  If this is the reason that the intermediate
table wasn't created, how do I force Django to create tables in MySQL
with the InnoDB engine?  - Brian

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



Re: intermediate table in manytomany relationship not created

2010-08-05 Thread Carlos Daniel Ruvalcaba Valenzuela
There is an option to default to InnoDB tables on the configuration:

http://docs.djangoproject.com/en/dev/ref/databases/#creating-your-tables

Regards,
Carlos Daniel Ruvalcaba Valenzuela

On Thu, Aug 5, 2010 at 12:48 PM, bksfu  wrote:
> When Django created the above tables, they were created with the
> MyISAM engine.  If the intermediate table has to have foreign keys
> back to the Phone and Room tables, this would be illegal from MySQL's
> perspective, which can apparently only form foreign key constraints
> between InnoDB tables.  If this is the reason that the intermediate
> table wasn't created, how do I force Django to create tables in MySQL
> with the InnoDB engine?  - Brian
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: portable apps problem

2010-08-05 Thread bax...@gretschpages.com
I came up with a solution using if 'foo' in settings.INSTALLED_APPS:
but it feels pretty hackish. If there's a better way, I'd love to hear
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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: django.views.static.serve issue

2010-08-05 Thread bagheera
Dnia 05-08-2010 o 14:57:04 Reinout van Rees   
napisał(a):



On 08/05/2010 01:36 PM, bagheera wrote:

Hi, i set up static files for development purposes in following way:

urls.py:


if settings.DEBUG:
urlpatterns += patterns('',(r'^site_media/(?P.*)$',
'django.views.static.serve', {'document_root': settings.MEDIA_ROOT}),)

settings.py:

MEDIA_ROOT = '/home/bagheera/NetBeansProjects/nml-src/storage'
MEDIA_URL = 'http://localhost:8000/site_media/'

index.html template:



WHY i had to add "site_media" string, when it IS already included in
MEDIA_URL ?
If i use

dev server gives output:
/images/clock.gif/ HTTP/1.1" 404 2155

Full path to this file is:
'/home/bagheera/NetBeansProjects/nml-src/storage/images/clock.gif'


Probably MEDIA_URL isn't set at all in that template.  If even the  
"localhost:8000" isn't showing up...


I saw that problem once, too.  The reason was that the template is  
rendered without the proper context.  You'll need to pass along a  
RequestContext:



from django.template import RequestContext

def your_view(request):
 ...
 return render_to_response(
 your_template,
 {'some': 'parameter'},
 context_instance=RequestContext(request))


Reinout


context_instance=RequestContext(request) solves the problem, i had also  
fall back to ,  
witch now is working fine. Thanks



--
Linux user

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



Re: overriding model.save()

2010-08-05 Thread Alec Shaner
The "new" values are what you just set: in your example, self.a=3 and
self.b=4 if you're inside your custom save method. Then you can get the
current values from the database from inside your custom save with something
like:

current = Foo.objects.get(pk=self.pk)

and inspect current.b for special values.

On Thu, Aug 5, 2010 at 2:54 PM, Sells, Fred wrote:

> That part makes sense, but where would I find the "new" values that have
> been set but not saved when my custom save() method is called? Like
>
> X.a=3
> X.b=4
> X.save()
>
> I want to see if b is a special value before saving.
>
> -Original Message-
> From: django-users@googlegroups.com [mailto:django-us...@googlegroups.com]
> On Behalf Of Sam Lai
> Sent: Thursday, August 05, 2010 7:58 AM
> To: django-users@googlegroups.com
> Subject: Re: overriding model.save()
>
> On 5 August 2010 03:05, Sells, Fred  wrote:
> > I would like to prevent saving a new value if the database contains a
> > specific value.  This is on a per field, per record basis.
> >
> > If I override the save() method; is there a way to find the existing (in
> > the DB) values and the new (to be stored) values?
>
> Just perform database queries as per normal inside the save() method.
>
> You have access to the object to be stored as well, see
>
> http://docs.djangoproject.com/en/dev/topics/db/models/#overriding-model-methods
>
> > --
> > You received this message because you are subscribed to the Google Groups
> "Django users" group.
> > To post to this group, send email to django-us...@googlegroups.com.
> > To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> > For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
> >
> >
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Custom management command using sql_delete fails

2010-08-05 Thread Mathias De Maré
Hi,

I've created a custom management command for django-admin.py, but the
sql execution (using statements created by sql_delete) keeps failing
on django.db.utils.DatabaseError: unrecognized token: " "
I'm afraid I'm not sure what's wrong. I'm currently thinking it's some
kind of encoding problem, but I can't seem to pinpoint the cause.

The custom command code is as follows:

from optparse import make_option
from django.db import connection, transaction, connections,
DEFAULT_DB_ALIAS
from django.core.management.sql import sql_delete
from django.core.management.base import AppCommand

class Command(AppCommand):
option_list = AppCommand.option_list + (
make_option('--database', action='store', dest='database',
default=DEFAULT_DB_ALIAS, help='Nominates a database to
print the '
'SQL for.  Defaults to the "default" database.'),
)

def handle_app(self, app, **options):
drop_statements = sql_delete(app, self.style,
connections[options.get('database', DEFAULT_DB_ALIAS)])
for statement in drop_statements:
statement = statement
cursor = connection.cursor()
cursor.execute(statement)
transaction.commit_unless_managed()

The error is:

python manage.py drop_some_tables blog
Traceback (most recent call last):
  File "manage.py", line 11, in 
execute_manager(settings)
  File "/usr/local/lib/python2.6/dist-packages/django/core/management/
__init__.py", line 438, in execute_manager
utility.execute()
  File "/usr/local/lib/python2.6/dist-packages/django/core/management/
__init__.py", line 379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python2.6/dist-packages/django/core/management/
base.py", line 191, in run_from_argv
self.execute(*args, **options.__dict__)
  File "/usr/local/lib/python2.6/dist-packages/django/core/management/
base.py", line 218, in execute
output = self.handle(*args, **options)
  File "/usr/local/lib/python2.6/dist-packages/django/core/management/
base.py", line 282, in handle
app_output = self.handle_app(app, **options)
  File "/home/mathias/Documents/I2P/i2p.www.jinja2/www_django/../
www_django/i2p_magic/management/commands/drop_some_tables.py", line
18, in handle_app
cursor.execute(statement)
  File "/usr/local/lib/python2.6/dist-packages/django/db/backends/
util.py", line 15, in execute
return self.cursor.execute(sql, params)
  File "/usr/local/lib/python2.6/dist-packages/django/db/backends/
sqlite3/base.py", line 200, in execute
return Database.Cursor.execute(self, query, params)
django.db.utils.DatabaseError: unrecognized token: " "

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



Dango-tagging incompatibilities?

2010-08-05 Thread adelein
Has anyone used django-tagging lately with Django 1.1 and above? I am
starting to use it but saw some comments in stackoverflow about
incompatibilities. Dont want to go down a dead end.

Appreciate your tips!


Thanks,

Adelein

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



TemplateDoesNotExist: 500.html error when trying to run server

2010-08-05 Thread meenakshi

  I am a beginner working through the Django tutorial.  When I try to
run the development server at http://127.0.0.1:8000/,  I get a
TemplateDoesNotExist: 500.html error.
   I have no problems linking to http://127.0.0.1:8000/admin,
however.  Whats going on?

Here is what I get when I try to run the server :

^CMacintosh:mysite mroy$ python2.6 manage.py runserver
Validating models...
0 errors found

Django version 1.1.1, using settings 'mysite.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

Traceback (most recent call last):

  File "/sw/lib/python2.6/site-packages/django/core/servers/
basehttp.py", line 279, in run
self.result = application(self.environ, self.start_response)

  File "/sw/lib/python2.6/site-packages/django/core/servers/
basehttp.py", line 651, in __call__
return self.application(environ, start_response)

  File "/sw/lib/python2.6/site-packages/django/core/handlers/wsgi.py",
line 241, in __call__
response = self.get_response(request)

  File "/sw/lib/python2.6/site-packages/django/core/handlers/base.py",
line 122, in get_response
return self.handle_uncaught_exception(request, resolver,
sys.exc_info())

  File "/sw/lib/python2.6/site-packages/django/core/handlers/base.py",
line 166, in handle_uncaught_exception
return callback(request, **param_dict)

  File "/sw/lib/python2.6/site-packages/django/views/defaults.py",
line 23, in server_error
t = loader.get_template(template_name) # You need to create a
500.html template.

  File "/sw/lib/python2.6/site-packages/django/template/loader.py",
line 81, in get_template
source, origin = find_template_source(template_name)

  File "/sw/lib/python2.6/site-packages/django/template/loader.py",
line 74, in find_template_source
raise TemplateDoesNotExist, name

TemplateDoesNotExist: 500.html



I am using python2.6 and Django version 1.1.  What's wrong?  I
apologize for this newbie question.  Would really appreciate some
help.

Thanks,
Meenakshi

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



Re: TemplateDoesNotExist: 500.html error when trying to run server

2010-08-05 Thread Steve Holden
On 8/5/2010 6:27 PM, meenakshi wrote:
> 
>   I am a beginner working through the Django tutorial.  When I try to
> run the development server at http://127.0.0.1:8000/,  I get a
> TemplateDoesNotExist: 500.html error.
>I have no problems linking to http://127.0.0.1:8000/admin,
> however.  Whats going on?
> 
> Here is what I get when I try to run the server :
> 
> ^CMacintosh:mysite mroy$ python2.6 manage.py runserver
> Validating models...
> 0 errors found
> 
> Django version 1.1.1, using settings 'mysite.settings'
> Development server is running at http://127.0.0.1:8000/
> Quit the server with CONTROL-C.
> 
> Traceback (most recent call last):
> 
>   File "/sw/lib/python2.6/site-packages/django/core/servers/
> basehttp.py", line 279, in run
> self.result = application(self.environ, self.start_response)
> 
>   File "/sw/lib/python2.6/site-packages/django/core/servers/
> basehttp.py", line 651, in __call__
> return self.application(environ, start_response)
> 
>   File "/sw/lib/python2.6/site-packages/django/core/handlers/wsgi.py",
> line 241, in __call__
> response = self.get_response(request)
> 
>   File "/sw/lib/python2.6/site-packages/django/core/handlers/base.py",
> line 122, in get_response
> return self.handle_uncaught_exception(request, resolver,
> sys.exc_info())
> 
>   File "/sw/lib/python2.6/site-packages/django/core/handlers/base.py",
> line 166, in handle_uncaught_exception
> return callback(request, **param_dict)
> 
>   File "/sw/lib/python2.6/site-packages/django/views/defaults.py",
> line 23, in server_error
> t = loader.get_template(template_name) # You need to create a
> 500.html template.
> 
>   File "/sw/lib/python2.6/site-packages/django/template/loader.py",
> line 81, in get_template
> source, origin = find_template_source(template_name)
> 
>   File "/sw/lib/python2.6/site-packages/django/template/loader.py",
> line 74, in find_template_source
> raise TemplateDoesNotExist, name
> 
> TemplateDoesNotExist: 500.html
> 
> 
> 
> I am using python2.6 and Django version 1.1.  What's wrong?  I
> apologize for this newbie question.  Would really appreciate some
> help.
> 
Do you have the DEBUG setting at False? I thought 500 errors would give
a traceback rather than print a 500 response when DEBUG was true.

You appear to be getting the error because some part of your logic is
raising an uncaught exception. In order to return the necessary HTTP
response (with status code 500) Django looks for a specific template.
Defining it will be useful for production, but for testing you want to
see the traceback from the error so you know what is going wrong in your
logic.

regards
 Steve
-- 
I'm no expert.
"ex" == "has-been"; "spurt" == "drip under pressure"
"expert" == "has-been drip under pressure".

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



Re: Python question about subprocess.Popen() and stdout

2010-08-05 Thread Joshua Russo
On Aug 4, 6:49 pm, Hassan  wrote:
> > Ok, so it appears that (in Python 2.5 at least) there is no way to capture
> > the stdout of subprocess.Popen()
>
> just do this
>
> from subprocess import Popen, PIPE
> p = Popen([cmd], stdout=PIPE)
> p.stdout.readlines()
>
> thats it!

The problem is that it waits for the process to end to output
anything. Unless I was doing something wrong, but I think I was doing
just what you describe here.

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



Re: Dango-tagging incompatibilities?

2010-08-05 Thread creecode
Hello Adelein,

I used a version of django-tagging with Django v1.1 without any
noticeable problems.  Which revision it was I can't say off the top of
my head.  A look at the django-tagging website may provide the
answers.

Toodle-looo...
creecode

On Aug 5, 3:18 pm, adelein  wrote:
> Has anyone used django-tagging lately with Django 1.1 and above? I am
> starting to use it but saw some comments in stackoverflow about
> incompatibilities. Dont want to go down a dead end.
>
> Appreciate your tips!

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



Re: Python question about subprocess.Popen() and stdout

2010-08-05 Thread Steve Holden
On 8/5/2010 7:16 PM, Joshua Russo wrote:
> On Aug 4, 6:49 pm, Hassan  wrote:
>>> Ok, so it appears that (in Python 2.5 at least) there is no way to capture
>>> the stdout of subprocess.Popen()
>>
>> just do this
>>
>> from subprocess import Popen, PIPE
>> p = Popen([cmd], stdout=PIPE)
>> p.stdout.readlines()
>>
>> thats it!
> 
> The problem is that it waits for the process to end to output
> anything. Unless I was doing something wrong, but I think I was doing
> just what you describe here.
> 
Well, readlines() inherently has to see the end of the data stream
before it can return a list of all the lines that the data stream
contains, so that's hardly surprising is it?

Try using readline() in a loop and see if that gives you better results.
I don't guarantee it will, but at least you will have some chance if
subprocess.open() *isn't* buffering the whole stream.

regards
 Steve
-- 
I'm no expert.
"ex" == "has-been"; "spurt" == "drip under pressure"
"expert" == "has-been drip under pressure".

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



Re: Interpolation and comparation between 2 dates: easy and difficult at the same time

2010-08-05 Thread Paulo Almeida
In the third case, I didn't understand why you didn't divide (his_to -
his_from) / (my_to - my_from). Bearing that in mind, this made sense in my
head, but analyze it carefully:

def match(mf,mt,hf,ht):
mydiff = diff_in_seconds(mf,mt)
if (mf >= hf and mt <= ht) or (mf < hf and mt > ht):
mydiff = diff_in_seconds(mf,mt)
hisdiff = diff_in_seconds(hf,ht)
return min(1, hisdiff / mydiff)
else:
case1 = max(0, diff_in_seconds(hf, mt))
case2 = max(0, diff_in_seconds(mf, ht))
diff = min(case1, case2)
return (diff / mydiff)

def diff_in_seconds(d1,d2):
timedelta = d2 - d1
return float(timedelta)

print match(0,100,40,90)


2010/8/5 Alexandre González 

> I've develope a "simple" function to calculate the difference between 2
> dates, and the time that they are interpolated.
>
> I need it to: I arrive to a site at a hour (my_from), I go out from the
> site at a hour (my_to). Some friend arrive at the site at a hour (his_from)
> and let it at a hour (his_to)
>
> If I stay in the site after he arrives and before he goes out, the
> "probability" of match is 1, if I let the site after he arrives, the
> probability of match is 0... You can see the samples in the documentation.
>
> I need to know if this is a good way to do, and if compare all the kinds of
> matching (I've found 6). This is the code:
>
> def time_match(self, my_from, my_to, his_from, his_to):
> """
> I've found 6 general kinds of time matching. It's better to
> explain it with graphics:
>
>   (my_from)--A--(my_to)
> -
>  (his_from)--B--(his_to)
> """
>
> #|-A-|   |-A-|
> #  or 
> #   |--B--||--B--|
> if my_to < his_from or his_to < my_from:
> return 0
>
> #  |--A--|
> # 
> #  |--B---|
> elif my_from >= his_from and my_to <= his_to:
> return 1
>
> #|-A---|
> # 
> #|-B-|
> elif my_from < his_from and my_to > his_to:
> my_diff_to_reuse = diff_in_seconds(my_from, my_to)
> diff = my_diff_to_reuse - self.diff_in_seconds(his_from,
> his_to)
>
> return (diff / my_diff_to_reuse)
>
> #   |---A---|
> # 
> #   |---B---|
> elif my_from <= his_from and my_to <= his_to:
> diff = self.diff_in_seconds(his_from, my_to)
>
> return (diff / self.diff_in_seconds(my_from, my_to))
>
> # |---A---|
> # 
> #|---B---|
> elif my_from >= his_from and my_to >= his_to:
> diff  = self.diff_in_seconds(my_from, his_to)
>
> return (diff / self.diff_in_seconds(my_from, my_to))
>
> # If I'm here I have a problem
> return 0
>
>
> def diff_in_seconds(date1, date2):
> # Initial from: http://www.bytemycode.com/snippets/snippet/304/
> timedelta = date2 - date1
> diff = timedelta.days*24*3600 + timedelta.seconds
>
> return abs(float(diff))
>
> Thanks!
> --
> Please, don't send me files with extensions: .doc, .docx, .xls, .xlsx, .ppt
> and/or .pptx
> http://mirblu.com
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

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



django comments problem

2010-08-05 Thread ignacio.arriaga

Hello,

I have a problem with django.contrib comments application. I have
installed the applicacion and made the synchronization with the
database. I create a comment form in this way:

{% render_comment_form for project %}

When I push either preview or submit I get a 403 error related with
csrf protection. I have the Csrf middleware activated.

I am using django 1.2 with python 2.6.

Greetings and thanks.

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



Finding Duration: Creating a context variable from two DateField model fields

2010-08-05 Thread flowpoke
I have a simple model that includes two DateField fields. I have
everything passing to the template, as I would like but i'd like to
add one more variable, duration. I want {{ duration }} to be that of
the delta between the two DateField fields, in years. It's simple
arithmetic but im not sure where to implement this logic. This is on a
per object basis but it seems to me that I'd want to apply this logic
at the model level, since it's a constant (i'll reference it anytime i
call on this object(s)).

Any pointers on where to begin? I suppose I can break this down in a
view but im not sure how to unpack the QuertSet, add the new context
variable to each object and then wrap it back up into a QuerySet. If
thats even the right way to do 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-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



debugging template inheritance

2010-08-05 Thread msoulier
Hi,

I have a framework on a product that allows new django projects to
make use of
an existing project's code, so new projects can reduce duplication. It
does
this in templates by some trickery with the TEMPLATE_DIRS.

For example, I have a base project here

/var/www/django/base/templates/base.html
  /500.html
  /404.html

And then a project making use of it like so

/var/www/django/project1/templates/index.html

{% extends "base/templates/base.html" %}

And a TEMPLATE_DIRS of
(
"/var/www/django",
"/var/www/django/project1/templates"
)

In my main project, this works well. And, when there's a fatal error
and my
servererror view function says to render "base/templates/500.html",
everything
works.

500.html extends base.html, which is a key point. That has always
worked in
the past even though the /var/www/django/base/templates directory is
not in
the path. I always thought that it was a feature that 500.html could
extend
base.html and it worked because they were in the same directory
together.

And, it does work in project1. But, I just added a project2,
configured
identically AFAICT, and it's not working. When I try to render
500.html I get

  File "/var/tmp/Django-1.1.1-root/usr/lib/python2.4/site-packages/
django/shortc
uts/__init__.py", line 20, in render_to_response
  File "/var/tmp/Django-1.1.1-root/usr/lib/python2.4/site-packages/
django/templa
te/loader.py", line 108, in render_to_string
  File "/var/tmp/Django-1.1.1-root/usr/lib/python2.4/site-packages/
django/templa
te/__init__.py", line 178, in render
  File "/var/tmp/Django-1.1.1-root/usr/lib/python2.4/site-packages/
django/templa
te/__init__.py", line 779, in render
  File "/var/tmp/Django-1.1.1-root/usr/lib/python2.4/site-packages/
django/templa
te/__init__.py", line 792, in render_node
  File "/var/tmp/Django-1.1.1-root/usr/lib/python2.4/site-packages/
django/templa
te/loader_tags.py", line 71, in render
  File "/var/tmp/Django-1.1.1-root/usr/lib/python2.4/site-packages/
django/templa
te/loader_tags.py", line 66, in get_parent
TemplateSyntaxError: Template u'base.html' cannot be extended, because
it doesn'
t exist

So, should this work? Is it a fluke that it works in one project and
not the
other? If it should work, then some clues for helping figure out why
it's not
working would be appreciated.

Thanks,
Mike
--
Michael P. Soulier 
"Any intelligent fool can make things bigger and more complex... It
takes a
touch of genius - and a lot of courage to move in the opposite
direction."
--Albert Einstein

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



Re: Finding Duration: Creating a context variable from two DateField model fields

2010-08-05 Thread Paulo Almeida
A function or property in the model would do nicely. You can check this page
for more information:

http://www.b-list.org/weblog/2006/aug/18/django-tips-using-properties-models-and-managers/

-
Paulo

On Fri, Aug 6, 2010 at 12:24 AM, flowpoke  wrote:

> I have a simple model that includes two DateField fields. I have
> everything passing to the template, as I would like but i'd like to
> add one more variable, duration. I want {{ duration }} to be that of
> the delta between the two DateField fields, in years. It's simple
> arithmetic but im not sure where to implement this logic. This is on a
> per object basis but it seems to me that I'd want to apply this logic
> at the model level, since it's a constant (i'll reference it anytime i
> call on this object(s)).
>
> Any pointers on where to begin? I suppose I can break this down in a
> view but im not sure how to unpack the QuertSet, add the new context
> variable to each object and then wrap it back up into a QuerySet. If
> thats even the right way to do 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-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com
> .
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Dango-tagging incompatibilities?

2010-08-05 Thread adelein
Hi,

Thanks, I will continue with it then.

On Aug 5, 4:40 pm, creecode  wrote:
> Hello Adelein,
>
> I used a version of django-tagging with Django v1.1 without any
> noticeable problems.  Which revision it was I can't say off the top of
> my head.  A look at the django-tagging website may provide the
> answers.
>
> Toodle-looo...
> creecode
>
> On Aug 5, 3:18 pm, adelein  wrote:
>
>
>
> > Has anyone used django-tagging lately with Django 1.1 and above? I am
> > starting to use it but saw some comments in stackoverflow about
> > incompatibilities. Dont want to go down a dead end.
>
> > Appreciate your tips!

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



Re: Dango-tagging incompatibilities?

2010-08-05 Thread Lachlan Musicman
I am using django-tagging with trunk and am not experiencing any real
problems. Admittedly, I'm not under massive load, but it's working
fine...

cheers
L.

On Fri, Aug 6, 2010 at 08:18, adelein  wrote:
> Has anyone used django-tagging lately with Django 1.1 and above? I am
> starting to use it but saw some comments in stackoverflow about
> incompatibilities. Dont want to go down a dead end.
>
> Appreciate your tips!
>
>
> Thanks,
>
> Adelein
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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