filteredselectmultiple widget breaks when in dialog box

2011-05-12 Thread carrier24sg
hi folks,

I am using the FilteredSelectMultiple widget for my manytomanyfield,
as seen on the admin site.

At the moment, everything is fine. However, if I place this widget
within a jquery dialog, the script breaks. I cannot move my items from
the first list to the second.



{{ form.students.errors }}
{{ form.students }}



My script:

$(document).ready(function(){

$('#students_input').dialog({
autoOpen:false,
modal:true,
height:300,
width:350,
});


$(":submit").click( function(){
$("form").data("submit-button", this.name);
});

$("form").submit(function() {
   $('#students_input').dialog('open');

//other stuffs
});

Error message:

SelectBox.cache[id] is undefined
http://foobar.com/media/admin/js/SelectBox.js
Line 58

Can anyone shed some light to this?

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



Re: customizing admin - third party db esp. MongoDB?

2011-05-12 Thread Shamail Tayyab

On 12/05/11 12:13 PM, λq wrote:

Hi guys,

I have a legacy Django project to maintain, and now my job is to port some part
of the admin view from MySQL backend to MongoDB.

AFAIK the mongodb as Model backend for django isn't exactly mature
yet, I am thinking of writing customized admin views while using
PyMongo as mongodb driver.

So my question is: Is it possible to write complete overhaul of
django's admin with data provision from a third party? These includes wrap
around mongodb CURD operations, generate HTML forms and validating
data.

What's tbe best practice of doing this? Or am I just doing it wrong?

Use pymongo as DB Driver and mongoengine for Django ORM like wrapper for 
mongo..


Tx

--
Shamail Tayyab

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



Re: customizing admin - third party db esp. MongoDB?

2011-05-12 Thread λq
http://mongoengine.org/docs/v0.4/django.html

It doesn't work with django admin's.

On Thu, May 12, 2011 at 3:16 PM, Shamail Tayyab  wrote:
> On 12/05/11 12:13 PM, λq wrote:
>>
>> Hi guys,
>>
>> I have a legacy Django project to maintain, and now my job is to port some
>> part
>> of the admin view from MySQL backend to MongoDB.
>>
>> AFAIK the mongodb as Model backend for django isn't exactly mature
>> yet, I am thinking of writing customized admin views while using
>> PyMongo as mongodb driver.
>>
>> So my question is: Is it possible to write complete overhaul of
>> django's admin with data provision from a third party? These includes wrap
>> around mongodb CURD operations, generate HTML forms and validating
>> data.
>>
>> What's tbe best practice of doing this? Or am I just doing it wrong?
>>
> Use pymongo as DB Driver and mongoengine for Django ORM like wrapper for
> mongo..
>
> Tx
>
> --
> Shamail Tayyab
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Encrpting urls to hide PKs

2011-05-12 Thread Wesley Childs
Why cant you do something like this to avoid exposing data if people are
guessing primary keys

if request.user == Users.objects.get(id=pk-url):
Show data
Else:
raise 404 or redirect to home page

The above requires a logged in a user but you get the idea of not allowing
people to start guessing to expose data.

Wes
On 10 May 2011 22:09, "Sean Brant"  wrote:
>
>
>
>
> On May 10, 2011, at 4:02 PM, "Cal Leeming [Simplicity Media Ltd]"<
cal.leem...@simplicitymedialtd.co.uk> wrote:
>
>> Sean, are you suggesting that the OP rely on base36 encoding for
security? Please tell me you are joking.
>
> No not at all, I thought he stated this does not have to be secure.
>
> If it does, then yeah my code is a bad idea. If security is a issue this
should be behind a password.
>
>> On 10/05/2011 15:32, Sean Brant wrote:
>>> Sorry I think I only responded to the original poster.
>>>
>>> >>> from django.utils.http import int_to_base36, base36_to_int
>>> >>> int_to_base36(123)
>>> '3f'
>>> >>> base36_to_int('3f')
>>> 123
>>>
>>> Sean
>>>
>>
>
> --
> You received this message because you are subscribed to the Google Groups
"Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.
>

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



Re: haystack

2011-05-12 Thread pankaj sharma

can u tell me which one is better in sphinx and haystack

On May 11, 10:01 pm, Tarkeshwar Thakur  wrote:
> In your settings filehttp://docs.djangoproject.com/en/dev/topics/settings/
>
> On Thu, May 12, 2011 at 10:20 AM, pankaj sharma
> wrote:
>
>
>
>
>
>
>
>
>
> > hello friends, i want to use haystack for my website,
> > but i am having too many problems to install it.
> > in the dowumentation it is telling to add haystack to ur installed
> > apps. now it it telling to do "HAYSTACK_SITECONF =
> > 'myproject.search_sites'"
> > now where should i type this i dont have any idea about so please help
> > me
>
> >http://docs.haystacksearch.org/dev/tutorial.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-users@googlegroups.com.
> > To unsubscribe from this group, send email to
> > django-users+unsubscr...@googlegroups.com.
> > For more options, visit this group at
> >http://groups.google.com/group/django-users?hl=en.
>
> --
> - Tarkeshwar
> Blog: tarkeshwar.com 
> Pet project: operty.com 

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



CharField with choices gets no ... choices

2011-05-12 Thread Thomas Weholt
I got a model looking something like this

class SomeModel(models.Model):
somefield = models.CharField(max_length=100, choices=somemethod())

The problem is that somemethod, which produces the choices to give in
the form in the admin, is called when the module is imported, not when
the form instance is created. The result from the somemethod call is
dynamic based on custom user defined code and not some static tuple or
list.

So my question is: how can I get the choices to be set at the time of
form creation? Tried overriding the __init__, but then somefield was
only available as a string and I could not set any choice-property.

-- 
Mvh/Best regards,
Thomas Weholt
http://www.weholt.org

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



Re: class based views

2011-05-12 Thread Oleg Lomaka
http://docs.djangoproject.com/en/1.3/topics/generic-views-migration/

On Thu, May 12, 2011 at 9:56 AM, km  wrote:

> I do not find any help page on migrating existing function based views
> (defined in views.py of django app) to class based views in django.1.3
> pointers and help  appreciated.
>
>

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



Re: class based views

2011-05-12 Thread Michal Petrucha
On Thu, May 12, 2011 at 12:26:13PM +0530, km wrote:
> Hi all,
> 
> I do not find any help page on migrating existing function based views
> (defined in views.py of django app) to class based views in django.1.3
> pointers and help  appreciated.

There is a migration guide, you can find it for example via the 1.3
release notes:

http://docs.djangoproject.com/en/dev/topics/generic-views-migration/

Michal Petrucha


signature.asc
Description: Digital signature


Re: class based views

2011-05-12 Thread km
ah! thanks - thisis what i require.
regards,
KM

On Thu, May 12, 2011 at 1:31 PM, Michal Petrucha wrote:

> On Thu, May 12, 2011 at 12:26:13PM +0530, km wrote:
> > Hi all,
> >
> > I do not find any help page on migrating existing function based views
> > (defined in views.py of django app) to class based views in django.1.3
> > pointers and help  appreciated.
>
> There is a migration guide, you can find it for example via the 1.3
> release notes:
>
> http://docs.djangoproject.com/en/dev/topics/generic-views-migration/
>
> Michal Petrucha
>
> -BEGIN PGP SIGNATURE-
> Version: GnuPG v1.4.10 (GNU/Linux)
>
> iEYEARECAAYFAk3Lk+8ACgkQ11l9uIBrcFT1ZwCgneOWREnW5A7QaIrawgTbteIz
> F6AAn26HARNPgQ3nkGan0fmiiunAPyfD
> =49Ia
> -END PGP SIGNATURE-
>
>

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



Re: CharField with choices gets no ... choices

2011-05-12 Thread Jani Tiainen
On Thu, 2011-05-12 at 09:59 +0200, Thomas Weholt wrote:
> I got a model looking something like this
> 
> class SomeModel(models.Model):
> somefield = models.CharField(max_length=100, choices=somemethod())
> 
> The problem is that somemethod, which produces the choices to give in
> the form in the admin, is called when the module is imported, not when
> the form instance is created. The result from the somemethod call is
> dynamic based on custom user defined code and not some static tuple or
> list.
> 
> So my question is: how can I get the choices to be set at the time of
> form creation? Tried overriding the __init__, but then somefield was
> only available as a string and I could not set any choice-property.

You hit common "problem". You do assignment of function/method call
result not the callable itself. Small but significant difference.

So whenever somefield = models.Charfield(choices=somemethod()) is
evaluated it uses result of method call. And due the way objects are
called value is put there when class itself is constructed (imported).
This is just how it works with Python.

To be able to do dynamic chocies (which also is documented that
something might be wrong if choices are dynamic)) you have to pass
callable - which in python means that leave out parenthesis:

somefield = models.CharField(choices=somemethod)

-- 

Jani Tiainen


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



Re: CharField with choices gets no ... choices

2011-05-12 Thread Oleg Lomaka
You don't need to override choices for Model, because it is global to
validate "what values accepted to store into database". It's not depends on
current request scope or session.

If you need to provide user with subset of choices to choose from
dynamically, then you should use a Form for this.

class SomeModel(models.Model):
somefield = models.CharField(max_length=100, choices=all_posible_values)
# or you can omit choices completely here

class SomeModelForm(forms.ModelForm)
class Meta:
model = SomeModel
widgets = {'somefield': forms.Select}

def __init__(self, *args, **kwargs):
super(SomeModelForm, self).__init__(*args, **kwargs)
self.fields['somefield'].widget.choices = somemethod()

Also you can write clean_somefield method to check that user didn't try to
mislead you.

On Thu, May 12, 2011 at 10:59 AM, Thomas Weholt wrote:

> I got a model looking something like this
>
> class SomeModel(models.Model):
>somefield = models.CharField(max_length=100, choices=somemethod())
>
> The problem is that somemethod, which produces the choices to give in
> the form in the admin, is called when the module is imported, not when
> the form instance is created. The result from the somemethod call is
> dynamic based on custom user defined code and not some static tuple or
> list.
>
> So my question is: how can I get the choices to be set at the time of
> form creation? Tried overriding the __init__, but then somefield was
> only available as a string and I could not set any choice-property.
>
> --
> Mvh/Best regards,
> Thomas Weholt
> http://www.weholt.org
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: CharField with choices gets no ... choices

2011-05-12 Thread Thomas Weholt
On Thu, May 12, 2011 at 10:09 AM, Jani Tiainen  wrote:
> On Thu, 2011-05-12 at 09:59 +0200, Thomas Weholt wrote:
>> I got a model looking something like this
>>
>> class SomeModel(models.Model):
>>     somefield = models.CharField(max_length=100, choices=somemethod())
>>
>> The problem is that somemethod, which produces the choices to give in
>> the form in the admin, is called when the module is imported, not when
>> the form instance is created. The result from the somemethod call is
>> dynamic based on custom user defined code and not some static tuple or
>> list.
>>
>> So my question is: how can I get the choices to be set at the time of
>> form creation? Tried overriding the __init__, but then somefield was
>> only available as a string and I could not set any choice-property.
>
> You hit common "problem". You do assignment of function/method call
> result not the callable itself. Small but significant difference.
>
> So whenever somefield = models.Charfield(choices=somemethod()) is
> evaluated it uses result of method call. And due the way objects are
> called value is put there when class itself is constructed (imported).
> This is just how it works with Python.
>
> To be able to do dynamic chocies (which also is documented that
> something might be wrong if choices are dynamic)) you have to pass
> callable - which in python means that leave out parenthesis:
>
> somefield = models.CharField(choices=somemethod)

Ah crap!! Of course. Thanks alot Jani :-)

Thomas

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



Re: Django Admin site and password field

2011-05-12 Thread Oleg Lomaka
Sorry, it's unclear you use django's auth.User model or you have custom
model for your users?

If you have your custom model, then show an admin.py file from your app
directory.

On Thu, May 12, 2011 at 7:58 AM, Gabe  wrote:

> I am using built-in Django admin. In my models.py file password field
> is defined:
>
>password = models.CharField(max_length=64)
>
> I just can`t see password type field for models.
>
>
> On 11 Maj, 20:26, Shawn Milochik  wrote:
> > It sounds like you're not using the built-in Django admin, which would
> > make your life easier.
> >
> > Assuming you want to do it the hard way, you can just use a
> > PasswordInput widget.
> http://docs.djangoproject.com/en/1.3/ref/forms/widgets/
>
>

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



Re: haystack

2011-05-12 Thread Tim Sawyer
Here's the instructions I wrote when I added search with Haystack and
Whoosh to my site.

http://drumcoder.co.uk/blog/2010/may/19/django-text-search-haystack-and-whoosh/

Hope that helps point you in the right direction.

Tim.

> hello friends, i want to use haystack for my website,
> but i am having too many problems to install it.
> in the dowumentation it is telling to add haystack to ur installed
> apps. now it it telling to do "HAYSTACK_SITECONF =
> 'myproject.search_sites'"
> now where should i type this i dont have any idea about so please help
> me
>
> http://docs.haystacksearch.org/dev/tutorial.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-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


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



Re: haystack

2011-05-12 Thread Sam Lai
On 12 May 2011 17:31, pankaj sharma  wrote:
>
> can u tell me which one is better in sphinx and haystack

Haystack provides only the glue between Django and a search
engine/indexer. With Haystack, you still need to pick a search engine
to use, e.g. Solr, Whoosh, Xapian. It doesn't support Sphinx yet
though.

As for comparisons between Solr (Lucene), Xapian or Sphinx - it'll
depend on your situation, but they're fairly similar. Whoosh is
intended for smaller deployments. Best thing is to try them out. If
you decide on Sphinx, there's a django-sphinx to help you.

> On May 11, 10:01 pm, Tarkeshwar Thakur  wrote:
>> In your settings filehttp://docs.djangoproject.com/en/dev/topics/settings/
>>
>> On Thu, May 12, 2011 at 10:20 AM, pankaj sharma
>> wrote:
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> > hello friends, i want to use haystack for my website,
>> > but i am having too many problems to install it.
>> > in the dowumentation it is telling to add haystack to ur installed
>> > apps. now it it telling to do "HAYSTACK_SITECONF =
>> > 'myproject.search_sites'"
>> > now where should i type this i dont have any idea about so please help
>> > me
>>
>> >http://docs.haystacksearch.org/dev/tutorial.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-users@googlegroups.com.
>> > To unsubscribe from this group, send email to
>> > django-users+unsubscr...@googlegroups.com.
>> > For more options, visit this group at
>> >http://groups.google.com/group/django-users?hl=en.
>>
>> --
>> - Tarkeshwar
>> Blog: tarkeshwar.com 
>> Pet project: operty.com 
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Django Admin site and password field

2011-05-12 Thread Jirka Vejrazka
I have not done it myself, but you might need to specify custom widget
for your field. Take a look at PasswordInput widget here:
http://docs.djangoproject.com/en/1.3/ref/forms/widgets/

  HTH

   Jirka

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



Re: Django Admin site and password field

2011-05-12 Thread Michal Petrucha
On Wed, May 11, 2011 at 09:58:14PM -0700, Gabe wrote:
> I am using built-in Django admin. In my models.py file password field
> is defined:
> 
> password = models.CharField(max_length=64)
> 
> I just can`t see password type field for models.

It is hard for us to guess what you're actually trying to achieve.
Here are my guesses:

1) You created your own model which has nothing to do with the admin
   infrastructure (i. e. the auth infrastructure used by the admin is
   the default one bundled with Django). This model includes a
   CharField that you want to represent in the admin using a
   PasswordWidget.

   In this case you'll just want to override the widget for this
   specific field. (I don't know the specifics, you can look it up in
   the tutorial or reference.)

2) You created a model replacing the default User model bundled in the
   auth framework and are having issues with the admin login screen
   using a regular TextInput for the password. This would be possible
   if you specified a custom login_form to the AdminSite.

   In this case you'll also want to override the widget used for this
   form field to a PasswordInput.

I don't know if I guessed right but I hope it was at least a little
bit useful.

Michal Petrucha


signature.asc
Description: Digital signature


Interpreting html tags within a unicode string rather than simply writing them

2011-05-12 Thread Jason
Hi there,

I have a letter stored in my database which I would like to write to a html 
page preserving the formatting. The letter is standard text, however has 
some non ascii characters e.g. £ $ and so on which means the letter takes a 
unicode type. In the letter I have replaced line breaks with  etc. 
However when I write this to a variable {{ letter }} within my html document 
the html mark up shows as text rather than formatting the document e.g.

Hello John  This letter is to  confirm 

etc.

Is there a way I can have the contents of this variable interpreted as html?

Cheers,
J

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



Re: Interpreting html tags within a unicode string rather than simply writing them

2011-05-12 Thread Tom Evans
On Thu, May 12, 2011 at 1:13 PM, Jason <1jason.whatf...@gmail.com> wrote:
> Hi there,
> I have a letter stored in my database which I would like to write to a html
> page preserving the formatting. The letter is standard text, however has
> some non ascii characters e.g. £ $ and so on which means the letter takes a
> unicode type. In the letter I have replaced line breaks with  etc.
> However when I write this to a variable {{ letter }} within my html document
> the html mark up shows as text rather than formatting the document e.g.
> Hello John  This letter is to  confirm 
> etc.
> Is there a way I can have the contents of this variable interpreted as html?
> Cheers,
> J
>

Unicode/not unicode is an irrelevant issue here.

Many ways to get the desired output:

1) Use the 'safe' template filter to mark the string as safe to output raw
2) Use django.utils.safestring.mark_safe to mark the string as safe in your view
3) Use the autoescape template tag to disable output escaping when you
output the string
4) Don't convert newlines to , use the 'linebreaksbr' template
filter to do it in when you output the string

Cheers

Tom

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



Re: Development server: cookies not working

2011-05-12 Thread Frederik Vogelsang
Hi,

2011/5/5 Tom Evans :
> If you can see the Set-Cookie header in the responses, but your
> browser is not accepting them, verify that the path and domain are
> correct in that response. Browsers will ignore cookies for domains
> other than the domain serving the page, and for paths other than the
> current path and substrings of the current path (as the browser sees
> it).
The domain definitely is correct. I am not sure about the path because
the cookie is being set for the root (/) path. This is the request and
reply:

POST /search/advanced/ HTTP/1.1
Host: 127.0.0.1:8000
Connection: keep-alive
Referer: http://127.0.0.1:8000/search/advanced/
Content-Length: 149
Cache-Control: max-age=0
Origin: http://127.0.0.1:8000
User-Agent: Mozilla/5.0 (X11; Linux i686) AppleWebKit/534.24 (KHTML,
like Gecko) Chrome/11.0.696.65 Safari/534.24
Content-Type: application/x-www-form-urlencoded
Accept: 
application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Encoding: gzip,deflate,sdch
Accept-Language: de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Cookie: sessionid=xxx; csrftoken=xxx

csrfmiddlewaretoken=xxx&givenName=foo&surname=
HTTP/1.0 302 FOUND
Date: Thu, 12 May 2011 12:22:50 GMT
Server: WSGIServer/0.1 Python/2.6.5
Vary: Cookie
Content-Type: text/html; charset=utf-8
Location: http://127.0.0.1:8000/search/result/
Set-Cookie:  sessionid=xxx; expires=Thu, 26-May-2011 12:22:50 GMT;
Max-Age=1209600; Path=/; secure


Any ideas?


Regards,
Frederik

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



Re: Development server: cookies not working

2011-05-12 Thread Frederik Vogelsang
Hi,

one quick update: the problem was the Set-Cookie line. I did set
SESSION_COOKIE_SECURE = True in my settings.py, this is why it did not
work with the localserver.

Thanks everyone!


Frederik

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



Re: Readonly on subset of forms in Admin inlines

2011-05-12 Thread Vinicius Massuchetto
Hi! Did you find any solution for this? I'm trying to achieve a
similar behavior for inlines, as posted in another recent thread.

Thanks.
--
Vinicius Massuchetto

On Jan 23, 8:07 am, Peter Phillips  wrote:
> Thanks for the reply!
>
> I probably didn't explain the problem properly. I have been using the
> ModelAdmin.readonly_fields option, however it hasn't been doing quite
> what I need for inline formsets. In the case of my inline form, when I
> set some of the fields toreadonly, they end up read only for all
> forms in the formset. That is, every new row that's added to the
> inline formset and all existing ones end up with read only fields.
> What I was hoping to do was override a method to dynamically set some
> fields as read only, but only for some of the forms in the inline
> formset, not all of them.
>
> The following code means that once a row/form in the inline was not
> created by the request.user, all rows/forms becomereadonly. What I'd
> like is to have fields only in the rows they did not create bereadonly, 
> leaving the ones that they did create editable.
>
> I wasn't sure whether there was perhaps an easy way to loop through
> the forms in the inline formset and set options in the admin for each
> of them separately.
>
> class IssuesInline(admin.TabularInline):
>     model = Issues
>     extra = 0
>     can_delete = False
>     fields = ('risk', 'issue', 'priority', 'l1', 'c1', 'notes')
>     exclude = ('added_by', 'modified_by')
>     readonly_fields = ('lbyc')
>
>     def get_readonly_fields(self,request,obj=None):
>         if request.user.username!=obj.added_by:
>              return ('risk', 'issue', 'priority', 'l1', 'c1',
> 'notes',) + self.readonly_fields
>         return self.readonly_fields
>
> Thanks again!
>
> On Jan 20, 8:24 pm, Thomas  wrote:
>
>
>
>
>
>
>
> > Am 20.01.2011 um 03:27 schrieb Peter Phillips:
>
> > > Hello,
>
> > > Is there a straightforward way to set fields to read only for a subset
> > > of the forms in an inline formset in the Admin? I'd like to set some
> > > fields to read only on my inline form for rows that were not created
> > > by the user. However, when I set the fields to read only, it of course
> > > affects all rows/forms in the inline, preventing the user from editing
> > > their own rows. Do I need to do a custom formset for
> > > InlineModelAdmin.formset?
>
> > hi,
>
> > maybe this provides a proper solution for 
> > you:http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contri...
>
> > good luck,
> > TR
>
> > 
>
> >http://thoreg.org

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



Help with django translation for django-sorting

2011-05-12 Thread Oleg Oltar
Hi need help,

I am using django soring application:

https://github.com/directeur/django-sorting

I just wonder if there is a way to make local names for sorting filters...
E.g. I am trying to localize following:

{% anchor total Rating %}

And using standard django trick

{% anchor total _("Rating") %}

is not helping... Don't know what to do...
See:
http://stackoverflow.com/questions/5978927/django-sorting-localization-is-not-working

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



RESTful web service unit tests

2011-05-12 Thread Bruno Ripa
Hi all,


  i am writing some tests to test a RESTful api i have written
(Django 1.3, using piston, python 2.6.5).

The url is basically: /api/products and you need to be logged to
access it.

We can use such api, via curl PUT query (the client code uses pycurl
to access the ws).

It works in production / development, but not the tests.

So far i've tried:

1. send credentials to the web service when doing the PUT request
2. successfully login, and consequentely contact the ws

in both cases, the response is an Authorization Required and status
code is 401.

Btw, i am using follow = True (and so i have a redirect chain with a
301 status).

I am pretty sure i am doing something wrong, but can't spot it.

Any help ?

Thanks in advance,
  B.
N.b.: here is the code i'm using to test:


class CommunicationTests(TestCase):
   """
   """

   def setUp(self):
   """
   """

   admin = User.objects.create_user('admin',
'admin@some','admin')
   admin.is_staff = True
   admin.save()


   self._client = client.Client()

   self._connected = self._client.login(username="admin",
password="admin")

   def test_contactWS(self):
   """
   """

   self.assertTrue(self._connected)

   credentials = {
   "username":"admin",
   "password":"admin"
   }

   response = self._client.put(path="/api/products",follow=True,
**credentials)

Ofc, i am changing very often this code to make tests, not all the
scenarios are reported here.

P.s.: sorry to the people reading again this mail, sent before to the
wrong list.

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



Re: Django Admin site and password field

2011-05-12 Thread Gabe
First of all thx for all replies.

For now I don`t use auth.User model I would like to create my own. So
I have written model class Users:

class Users(models.Model):
login =
models.CharField(max_length=64,error_messages={'required':'Podanie
loginu jest obowiązkowe','unique':'Podany login już istnieje. Wybierz
inny.'},help_text='Wybierz login do pracy w systemie.',unique=True)
password =
models.CharField(max_length=64,error_messages={'min_length':'Hasło
musi zawierać od 8 do 64 znaków','required':'Podanie hasła jest
wymagane'},help_text='Wprowadź hasło.')
email = models.EmailField(help_text='Podaj adres e-mail. Będzie on
używany do kontaktu z Tobą przez
administratora.',error_messages={'required':'Podanie e-maila jest
wymagane','invalid':'Format adresu jest niepoprawny'})
isActive = models.BooleanField(default=False)
priviledge = models.OneToOneField(Priviledges,blank=True)
activation_code = models.CharField(max_length=64,blank=True)

def __unicode__(self):
return self.login

Then I have registered it in admin panel by editing admin.py among
with another models:

from django.contrib import admin
from dgcmsUser.models import Users
from dgcmsUser.models import Priviledges
from dgcmsUser.models import UsersProfiles

admin.site.register(Users)
admin.site.register(UsersProfiles)
admin.site.register(Priviledges)


Then when I add user using autogenerated admin panel the password
field is  not  which I
would like it to be.

I haven`t done any other file editions.


Gabe

On 12 Maj, 13:52, Michal Petrucha  wrote:
> On Wed, May 11, 2011 at 09:58:14PM -0700, Gabe wrote:
> > I am using built-in Django admin. In my models.py file password field
> > is defined:
>
> >     password = models.CharField(max_length=64)
>
> > I just can`t see password type field for models.
>
> It is hard for us to guess what you're actually trying to achieve.
> Here are my guesses:
>
> 1) You created your own model which has nothing to do with the admin
>    infrastructure (i. e. the auth infrastructure used by the admin is
>    the default one bundled with Django). This model includes a
>    CharField that you want to represent in the admin using a
>    PasswordWidget.
>
>    In this case you'll just want to override the widget for this
>    specific field. (I don't know the specifics, you can look it up in
>    the tutorial or reference.)
>
> 2) You created a model replacing the default User model bundled in the
>    auth framework and are having issues with the admin login screen
>    using a regular TextInput for the password. This would be possible
>    if you specified a custom login_form to the AdminSite.
>
>    In this case you'll also want to override the widget used for this
>    form field to a PasswordInput.
>
> I don't know if I guessed right but I hope it was at least a little
> bit useful.
>
> Michal Petrucha
>
>  signature.asc
> < 1KWyświetlPobierz

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



Re: Encrpting urls to hide PKs

2011-05-12 Thread Ian Clelland
On Thu, May 12, 2011 at 12:29 AM, Wesley Childs wrote:

> Why cant you do something like this to avoid exposing data if people are
> guessing primary keys
>
> if request.user == Users.objects.get(id=pk-url):
> Show data
> Else:
> raise 404 or redirect to home page
>
> The above requires a logged in a user but you get the idea of not allowing
> people to start guessing to expose data.
>

You can't do this, in this case, *because* it requires a logged-in user.
Specifically, the OP is looking for a way to authenticate a user based on
their knowledge of a 'secret' URL, but if the URLs are predictable, then
discovering the secrets is trivial. Your solution is fine once the user has
been logged in, although some people would say that it can still give away
too much information*

Honestly, I can think of exactly two ways for the original poster to achieve
his goal (and I've deployed systems using each of these):

1. Sign** the ID with a secret known only to the web server. Put the ID and
the signature in the URL somewhere, and, when the user hits the view, sign
the ID again, and verify that the signatures match. This doesn't hide the ID
at all, but it ensures that nobody can forge a url with a different ID than
the server gave them.

2. Generate a unique token for each record, randomly. Use a UUID, they're
great for that. Then use the token in the URL, and look for the token in the
database when the user comes back to the confirmation view. If your tokens
are actually random, and large enough (say, 64 bits), then anybody trying to
guess them will be wasting their time.


-- 
Regards,
Ian Clelland



* By looking at the database IDs, people can gauge how heavily the system is
being used, or if they see a key for someone else's record, they can
estimate when that record was created, by comparing it to their own data.

** And by sign, I mean HMAC.

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



django.db.utils.DatabaseError: relation "django_content_type" does not exist

2011-05-12 Thread javatina
I have just come accross this error:

django.db.utils.DatabaseError: relation "django_content_type" does not
exist
LINE 1: ..."."app_label", "django_content_type"."model" FROM
"django_co...
(see whole traceback below)

Some very quick investigation showed that I am not the only one - see
for example this thread (Jan 2010)
http://groups.google.com/group/django-developers/browse_thread/thread/3a40a72b4e419ad6

I also checked this ticket - it does not seem to be close ("Patch
needs improvement:  yes")
http://code.djangoproject.com/ticket/12767

What is clear is that I have similar setup - two databases and I use
User (from auth) in my own models (meaning crossing applications), but
models where I use User are in the same database with User. As soon as
I got rid of two database setup, the error disappeared.

BTW, my attempt to use the hack offered in the thread I mentioned
above resulted in another error (also reported in similar cases):
django.db.utils.DatabaseError: relation "auth_permission" does not
exist
LINE 1: ...ntent_type_id", "auth_permission"."codename" FROM
"auth_perm...

I am totally new to Python/Django (what do I know?), but it seem that
it's still a bug and a multi-database feature is not really ready, is
it?

Serge
== Traceback =
Creating tables ...
Traceback (most recent call last):
  File "/Users/serge/PycharmProjects/NaviquanPost/manage.py", line 11,
in 
execute_manager(settings)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/
lib/python2.7/site-packages/django/core/management/__init__.py", line
438, in execute_manager
utility.execute()
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/
lib/python2.7/site-packages/django/core/management/__init__.py", line
379, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/
lib/python2.7/site-packages/django/core/management/base.py", line 191,
in run_from_argv
self.execute(*args, **options.__dict__)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/
lib/python2.7/site-packages/django/core/management/base.py", line 220,
in execute
output = self.handle(*args, **options)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/
lib/python2.7/site-packages/django/core/management/base.py", line 351,
in handle
return self.handle_noargs(**options)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/
lib/python2.7/site-packages/django/core/management/commands/
syncdb.py", line 109, in handle_noargs
emit_post_sync_signal(created_models, verbosity, interactive, db)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/
lib/python2.7/site-packages/django/core/management/sql.py", line 190,
in emit_post_sync_signal
interactive=interactive, db=db)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/
lib/python2.7/site-packages/django/dispatch/dispatcher.py", line 172,
in send
response = receiver(signal=self, sender=sender, **named)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/
lib/python2.7/site-packages/django/contrib/auth/management/
__init__.py", line 30, in create_permissions
ctype = ContentType.objects.get_for_model(klass)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/
lib/python2.7/site-packages/django/contrib/contenttypes/models.py",
line 38, in get_for_model
defaults = {'name': smart_unicode(opts.verbose_name_raw)},
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/
lib/python2.7/site-packages/django/db/models/manager.py", line 135, in
get_or_create
return self.get_query_set().get_or_create(**kwargs)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/
lib/python2.7/site-packages/django/db/models/query.py", line 378, in
get_or_create
return self.get(**lookup), False
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/
lib/python2.7/site-packages/django/db/models/query.py", line 344, in
get
num = len(clone)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/
lib/python2.7/site-packages/django/db/models/query.py", line 82, in
__len__
self._result_cache = list(self.iterator())
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/
lib/python2.7/site-packages/django/db/models/query.py", line 273, in
iterator
for row in compiler.results_iter():
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/
lib/python2.7/site-packages/django/db/models/sql/compiler.py", line
680, in results_iter
for rows in self.execute_sql(MULTI):
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/
lib/python2.7/site-packages/django/db/models/sql/compiler.py", line
735, in execute_sql
cursor.execute(sql, params)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/
lib/python2.7/site-packages/django/db/backends/util.py", line 34, in

Where does SessionMiddleware load the session object from the SessionStore backend?

2011-05-12 Thread Andy
I was looking at the source code of SessionMiddleware:

  class SessionMiddleware(object):
def process_request(self, request):
engine = import_module(settings.SESSION_ENGINE)
session_key =
request.COOKIES.get(settings.SESSION_COOKIE_NAME, None)
request.session = engine.SessionStore(session_key)

If I understand it correctly, for every request
SessionMiddleware.process_request() will get the sessionid from the
cookie and then create a new SessionStore instance using that
sessionid.

And when I looked at the source for __init__() of SessionStore and
SessionBase:


  class SessionStore(SessionBase):
def __init__(self, session_key=None):
super(SessionStore, self).__init__(session_key)


  class SessionBase(object):
def __init__(self, session_key=None):
self._session_key = session_key
self.accessed = False
self.modified = False

So basically SessionStore just creates a new instance without trying
to look up in the database to see whether that session already exists
or not. But shouldn't that be the whole point of session -- for every
request Django needs to look up in the session database to see if the
session is already there? I'm guess at someplace this database lookup
takes place but I can't find it.

Can you tell me where can i find it? Or did I misunderstand how
session work in Django?

Thanks

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



Re: Django Admin site and password field

2011-05-12 Thread Michal Petrucha
On Thu, May 12, 2011 at 09:51:24AM -0700, Gabe wrote:
> First of all thx for all replies.
> 
> For now I don`t use auth.User model I would like to create my own. So
> I have written model class Users:
> 
> [...]
> 
> Then I have registered it in admin panel by editing admin.py among
> with another models:
> 
> from django.contrib import admin
> from dgcmsUser.models import Users
> from dgcmsUser.models import Priviledges
> from dgcmsUser.models import UsersProfiles
> 
> admin.site.register(Users)
> admin.site.register(UsersProfiles)
> admin.site.register(Priviledges)
> 
> 
> Then when I add user using autogenerated admin panel the password
> field is  not  which I
> would like it to be.

You have to create a custom ModelForm for your Users model. This form
will only have to override the widget of the password field. Then
you'll have to create a custom ModelAdmin specifying your ModelForm
instead of the default one.

It may look something like this (note that I'm typing off the top of
my head):

class UserForm(forms.ModelForm):
class Meta:
widgets = {
'password': PasswordInput,
}

class UserAdmin(admin.ModelAdmin):
form = UserForm

admin.site.register(User, UserAdmin)


OT: Note that each time someone saves a plaintext password in a
database, a kitten dies. Please, think of the kittens. (-; (Also
applies to base64-encoded passwords and such. Yeah, you wouldn't
believe it but the academic information system our university forces
us to use does exactly that. Probably because of unicode encoding
issues.)

Michal


signature.asc
Description: Digital signature


Overriding save() + site framework = nothing changed when clicking save in the admin

2011-05-12 Thread ksamuel
I overrided the save method of one of my model to it sync its sites
with its parent sites:

def save(self, *args, **kwargs):

ret = models.Model.save(self, *args, **kwargs)

if self.id:

for site in self.parent.sites.all():
self.sites.add(site.id)

This code work, except when you save the object in the admin. Using
PDB, I can see that self.parent.sites.all() return something at the
end of send. But right after, the relations disapears. I'm not
(willingly at least) using transactions.

More details here:
http://stackoverflow.com/questions/5982347/why-is-adding-site-to-an-object-doesnt-seem-to-work-in-a-save-override-in-the

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



Re: Where does SessionMiddleware load the session object from the SessionStore backend?

2011-05-12 Thread Kirill Spitsin
On Thu, May 12, 2011 at 01:58:07PM -0700, Andy wrote:
...
> So basically SessionStore just creates a new instance without trying
> to look up in the database to see whether that session already exists
> or not. But shouldn't that be the whole point of session -- for every
> request Django needs to look up in the session database to see if the
> session is already there? I'm guess at someplace this database lookup
> takes place but I can't find it.
> 
> Can you tell me where can i find it? Or did I misunderstand how
> session work in Django?

Django loads session from store lazily, after first access to session,
in `SessionStore.load()` method.  For example:

https://code.djangoproject.com/browser/django/trunk/django/contrib/sessions/backends/db.py#L16

-- 
Kirill Spitsin

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



Re: Overriding save() + site framework = nothing changed when clicking save in the admin

2011-05-12 Thread ksamuel
I got some help on the Django IRC channel:

The anwser is that django save m2m relationship in the admin by
calling 'clear' on it, then setting it. I means that the form destroy
any attached data to the object then add the ones in you entered in
the admin.

It works outside the admin because we don't use the admin form that
clear the m2m relationship.

The reason it works for tags in the admin is that the tagging
application doesn't use m2m but emulate it by placing a TaggedItem
object with a foreign key to a tag and to your model with a generic
relation. Plus it's an inline field inclusion.

I think a possible solution is to create a custom admin form and add
the site from here.


On 13 mai, 00:03, ksamuel  wrote:
> I overrided the save method of one of my model to it sync its sites
> with its parent sites:
>
> def save(self, *args, **kwargs):
>
>     ret = models.Model.save(self, *args, **kwargs)
>
>     if self.id:
>
>         for site in self.parent.sites.all():
>             self.sites.add(site.id)
>
> This code work, except when you save the object in the admin. Using
> PDB, I can see that self.parent.sites.all() return something at the
> end of send. But right after, the relations disapears. I'm not
> (willingly at least) using transactions.
>
> More details 
> here:http://stackoverflow.com/questions/5982347/why-is-adding-site-to-an-o...

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



Re: Where does SessionMiddleware load the session object from the SessionStore backend?

2011-05-12 Thread Andy
Thanks. I did notice the load() method.

But can you tell me where is that method called?

On May 12, 5:39 pm, Kirill Spitsin  wrote:
> On Thu, May 12, 2011 at 01:58:07PM -0700, Andy wrote:
>
> ...
>
> > So basically SessionStore just creates a new instance without trying
> > to look up in the database to see whether that session already exists
> > or not. But shouldn't that be the whole point of session -- for every
> > request Django needs to look up in the session database to see if the
> > session is already there? I'm guess at someplace this database lookup
> > takes place but I can't find it.
>
> > Can you tell me where can i find it? Or did I misunderstand how
> > session work in Django?
>
> Django loads session from store lazily, after first access to session,
> in `SessionStore.load()` method.  For example:
>
> https://code.djangoproject.com/browser/django/trunk/django/contrib/se...
>
> --
> Kirill Spitsin

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



Re: Where does SessionMiddleware load the session object from the SessionStore backend?

2011-05-12 Thread Kirill Spitsin
On Thu, May 12, 2011 at 03:39:39PM -0700, Andy wrote:
> Thanks. I did notice the load() method.
> 
> But can you tell me where is that method called?

session[key]:

SessionBase.__getitem__(key):
return self._session[key]
http://code.djangoproject.com/browser/django/trunk/django/contrib/sessions/backends/base.py#L46

SessionBase._session is a property, with getter SessionBase._get_session():
http://code.djangoproject.com/browser/django/trunk/django/contrib/sessions/backends/base.py#L168

and in _get_session() SessionBase.load() is called.

-- 
Kirill Spitsin

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



Re: Where does SessionMiddleware load the session object from the SessionStore backend?

2011-05-12 Thread Andy
Thank you.

On May 12, 6:54 pm, Kirill Spitsin  wrote:
> On Thu, May 12, 2011 at 03:39:39PM -0700, Andy wrote:
> > Thanks. I did notice the load() method.
>
> > But can you tell me where is that method called?
>
> session[key]:
>
> SessionBase.__getitem__(key):
>     return 
> self._session[key]http://code.djangoproject.com/browser/django/trunk/django/contrib/ses...
>
> SessionBase._session is a property, with getter 
> SessionBase._get_session():http://code.djangoproject.com/browser/django/trunk/django/contrib/ses...
>
> and in _get_session() SessionBase.load() is called.
>
> --
> Kirill Spitsin

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



File Field

2011-05-12 Thread pankaj sharma
Hello friends,.
i want to upload some files to my database and show it to user ..
how to add an filefield option to models.py and how to show them in
admin.py.
and how to let the users download the files...

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



Overriding templates for the inclusion_tag

2011-05-12 Thread Stodge
Is there any interest in changing the inclusion template functionality
to let the function return the template name in the dictionary to the
inclusion_tag  decorator? This would let the developer override the
template filename:

{{{
@register.inclusion_tag('block/render_region.html')
def render_region(slug):

# Some random code that does nothing.
if len(slug) == 0:
return {'template': 'block/empty_region.html'}

return {'region': region, 'blocks': blocks}
}}}

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



Re: Overide error messages in models

2011-05-12 Thread Daniel França
no way? I'll need to create new model forms?

2011/5/12 Daniel França 

> Hi all,
> I need to override error messages (like for required fields) directly in
> Models, I don't wanna duplicate code declaring some fields again in forms,
> and in some cases I don't even create the forms, just using generic views
> for model...
>
> I was looking for a solution to change the default error messages (without
> write this in all fields), but I didn't find anything, so I look for a
> solution to write the error messages right in Models, I found this:
> http://docs.djangoproject.com/en/dev/ref/models/fields/#error-messages
> I'm running django 1.2.5
>
> I did that for some fields in my model, and the error message still is the
> default message "This field is required".
>
> Anyone know how can I solve that without need to duplicate code?
>
>

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



Re: Overide error messages in models

2011-05-12 Thread k4ml
On May 13, 8:08 am, Daniel França  wrote:
> no way? I'll need to create new model forms?
>
> 2011/5/12 Daniel França 
> > I did that for some fields in my model, and the error message still is the
> > default message "This field is required".

I can't see any string 'error_messages' in django/db/models/' files so
the error message must be from django.forms. Maybe the documentation
is incorrect ? There's also no reference regarding error_messages for
models's field in the linked release page.

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



Der Prozess kann nicht auf die Datei zugreifen, da sie von einem anderen Prozess verwendet wird: PDF Upload

2011-05-12 Thread doniyor
Hallo,

i have got small problem. i try to upload a pdf but i get this error
all the time.
The process can not access the file because it is being used by
another process: 'file location...'

my code is here:

pdf_file = self.cleaned_data.get('pdf_file')
  if (pdf_file.name[-3:] == u'pdf' or pdf_file.content_type in
['application/pdf', 'application/x-pdf'])):
  return self.cleaned_data
  else:
  raise forms.ValidationError(u"Die hochgeladene Datei ist
keine gültige PDF Datei.")

can someone tell me why that is and where my problem is?

huge thanks

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



Re: Overide error messages in models

2011-05-12 Thread Shawn Milochik

On 05/12/2011 08:08 PM, Daniel França wrote:

no way? I'll need to create new model forms?

2011/5/12 Daniel França


Hi all,
I need to override error messages (like for required fields) directly in
Models, I don't wanna duplicate code declaring some fields again in forms,
and in some cases I don't even create the forms, just using generic views
for model...

I was looking for a solution to change the default error messages (without
write this in all fields), but I didn't find anything, so I look for a
solution to write the error messages right in Models, I found this:
http://docs.djangoproject.com/en/dev/ref/models/fields/#error-messages
I'm running django 1.2.5

I did that for some fields in my model, and the error message still is the
default message "This field is required".

Anyone know how can I solve that without need to duplicate code?




What exactly did you change to attempt to override the error messages?


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



Re: Overide error messages in models

2011-05-12 Thread Daniel França
I wanna change the error messages without to need to rewrite fields code, to
be more specific I want to translate them...


On Thu, May 12, 2011 at 10:25 PM, Shawn Milochik  wrote:

> On 05/12/2011 08:08 PM, Daniel França wrote:
>
>> no way? I'll need to create new model forms?
>>
>> 2011/5/12 Daniel França
>>
>>  Hi all,
>>> I need to override error messages (like for required fields) directly in
>>> Models, I don't wanna duplicate code declaring some fields again in
>>> forms,
>>> and in some cases I don't even create the forms, just using generic views
>>> for model...
>>>
>>> I was looking for a solution to change the default error messages
>>> (without
>>> write this in all fields), but I didn't find anything, so I look for a
>>> solution to write the error messages right in Models, I found this:
>>> http://docs.djangoproject.com/en/dev/ref/models/fields/#error-messages
>>> I'm running django 1.2.5
>>>
>>> I did that for some fields in my model, and the error message still is
>>> the
>>> default message "This field is required".
>>>
>>> Anyone know how can I solve that without need to duplicate code?
>>>
>>>
>>>
> What exactly did you change to attempt to override the error messages?
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>

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



Re: Overide error messages in models

2011-05-12 Thread Shawn Milochik

On 05/12/2011 09:35 PM, Daniel França wrote:

I wanna change the error messages without to need to rewrite fields code, to
be more specific I want to translate them...



Did you try setting the error_messages value?

http://docs.djangoproject.com/en/1.3/ref/forms/validation/#using-validators

There's a full example in this document, using e-mail field as an 
example. It's also translation-friendly, if you follow the convention of 
importing ugettext_lazy as _ (underscore) and using it in your model.






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



Template inheritance, how to render dynamic content in base templates

2011-05-12 Thread robinne
How can I render dynamic content in a base template if I only call a
view on my child template?

What I am trying to do is setup a base template that will include
"Profile" information for the user who is logged in, for example:
"Welcome John", instead of "login here", on every page. But if I call
my child page "/Home" (for example) and it extends "base.html", how do
I render the dynamic content within base.html? Thanks.

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



Re: Der Prozess kann nicht auf die Datei zugreifen, da sie von einem anderen Prozess verwendet wird: PDF Upload

2011-05-12 Thread Amanjeev Sethi
I am still learning systems, programming and Django myself but doesn't that
error look like you have not closed a previous opened File?

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