Re: Django throws ImproperlyConfigured error when loading URLconf on startup

2013-06-23 Thread Pratik Mandrekar
Has anyone been able to resolve this?

I am facing the same issue.

On Sunday, March 24, 2013 8:46:26 PM UTC+5:30, Dan Gentry wrote:
>
> Andrei, I once received this error when the problem was actually in 
> another python module being imported - in my case views.py.  Hope this 
> helps, Dan

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Deployment problem with google bots

2013-06-23 Thread Mike Dewhirst

On 22/06/2013 11:54pm, frocco wrote:

Hello

I get error messages from time to time because a google bot try's to view a 
product that no longer exists. How do I prevent this?



Are you responding with the correct error message (probably 404) when 
someone looks for a non-existent page?


--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Have Jcrop in Django Admin for thumbnails?

2013-06-23 Thread thomaaaas
Hello,

I'm new in the Django world, and I need some advice.

Basically what I want:
1) In m model I have an origianl_image and a thumbnail_image 
2) In the admin, a user upload an image 
3) Then, we show him the Jcrop pluging to crop the image as a thubnail 

I already do 1) and 2), but have no idea how to do 3)
Any advice on how to do this?
Thanks!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Why is there no view for sign up in django.contrib.auth.views?

2013-06-23 Thread Raúl Pedro Santos
Russell,

I disagree. You say that logging in has constant requirements but it 
doesn't. Some applications will require a username and a password, others 
will require an email address and a password, others will have some sort of 
captcha, others will have 2-factor authentication...

So logging in has as much constant requirements as registration does.

I believe it would be good to have a simple registration view and form just 
to get people started, like the login and logout ones. Just like you made 
some assumptions to provide a view and a form for logging in (which, again, 
doesn't necessarily suite every project), it would be simple to provide a 
view and a form for registration.


Cheers,
Raúl


On Saturday, 6 April 2013 02:18:18 UTC+1, Russell Keith-Magee wrote:
>
>
> On Sat, Apr 6, 2013 at 8:40 AM, Cody Scott 
> > wrote:
>
>> If I want users to sign up for my site, I need to make a register view, 
>> register form and a register template.
>>
>> Why is there a view and form for every other user account action (login, 
>> logout, etc.)
>>
>> Logging in has constant requirements - a username and a password. You 
> must provide both, or you can't log in. The forms and views to support this 
> are simple. Logging out doesn't require any user data at all - you just log 
> out the currently logged in user.
>
> What would you propose we put on a "register" view? Every project is going 
> to have different registration requirements. For that matter, there's also 
> different registration processes - are you going to enforce verification of 
> email addresses? Do you want to gather profile information before or after 
> the email address has been verified? 
>
> *That* is why there isn't a baked in Django "register" view, form and 
> template.
>
> There are, however, third party apps that can help. django-registration 
> and django-profiles for example provide generic implementations of specific 
> registration procedures. djangopackages.com is a good indication of the 
> sorts of third-party tools that are available.
>
> This also points out an important philosophical approach with Django - 
> Django is much more that just the core. Django is a wide ecosystem of 
> packages and tools. The wider ecosystem provides a lot more functionality 
> that the core can ever provide, and it helps to distribute the load of 
> maintaining these tools over a much wider group of individuals.
>
> Yours,
> Russ Magee %-)
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: How to divide my apps? Good practices?

2013-06-23 Thread galgal





I've made a quick schema of couple of main tables. As you can see, there 
are many relations, so I think putting it all in one app. There will be a 
couple of additional models. There will be 1 more thing: a play systems. 
Some seasons can have simple table games but others - of example 2 rounds 
of regular matches etc... That will be a special, separated class for that, 
in the same app as rest I think.

What do you think?


-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Background pattern files on S3 not being found while hosted on Heroku

2013-06-23 Thread Vincent Fulco
Verified S3 files are there and app on Heroku finds custom.css as other 
bits come thru correctly.

Within body{} of custom.css have tried the following based on scouring the 
Net help sites (assume same for background:url and background-image:url):


1) url(img/backgrounds/foo.png)

ref'ed to STATIC_URL in settings.py ("https://s3.amazonaws.com/foo_media/";) 
both with and w/o the quotes

2) url("{{STATIC_URL}}img/backgrounds/foo.png")

hard coded both with and w/o the quotes
3) url("https://s3.amazonaws.com/foo_media/img/backgrounds/foo.png";)

TIA, V.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




'FormSet' object has no attribute 'save'

2013-06-23 Thread Mário Idival
Hi guys,

I need of little help with formsets. I want save 3 instances of an form in 
databases.
E.G : 
name
lastname
-
name
lastname
-
name
lastname
-
I try use formset but I'm not getting save, expected this error for me :' 
ClassNameForSet' object has no attribute 'save'
Somebody know how i can pass for this?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Background pattern files on S3 not being found while hosted on Heroku

2013-06-23 Thread Vincent Fulco
Should add running the normal django-storages, boto setup for serving 
static from S3.

On Sunday, June 23, 2013 9:45:40 AM UTC-5, Vincent Fulco wrote:
>
> Verified S3 files are there and app on Heroku finds custom.css as other 
> bits come thru correctly.
>
> Within body{} of custom.css have tried the following based on scouring the 
> Net help sites (assume same for background:url and background-image:url):
>
>
> 1) url(img/backgrounds/foo.png)
>
> ref'ed to STATIC_URL in settings.py ("https://s3.amazonaws.com/foo_media/";) 
> both with and w/o the quotes
>
> 2) url("{{STATIC_URL}}img/backgrounds/foo.png")
>
> hard coded both with and w/o the quotes
> 3) url("https://s3.amazonaws.com/foo_media/img/backgrounds/foo.png";)
>
> TIA, V.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Custom manytomany widget in admin site: How to get the objects instead of their keys?

2013-06-23 Thread Serge G. Spaolonzi
I have a custom m2m widget for the admin site. I need to display the names
of the related objects but for the moment I only get the ids of the objects.

Is it possible to get the related objects instead the keys?
How is it implemented in the default widget and the horizontal_filter?
(I took a look to the  code but I got lost)

This is the code for the render method, values only contain a list with the
keys and I need to access the name attribute of the objects.

> def render(self, name, value, attrs=None):
> if value is None:
> value = 'n'
> final_attrs = self.build_attrs(attrs, type=self.input_type,
name=name)
> if value != '':
> final_attrs['value'] = ', '.join(v for v in value])
> return format_html('', flatatt(final_attrs))


Thanks

-- 
Serge G. Spaolonzi
Cobalys Systems
http://www.cobalys.com

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: How to access request/session information from model.clean?

2013-06-23 Thread Richard E. Cooke
Thanks Jason!

I hunted through your links, and while I was setting up a test I stumbled 
upon this in the Django 1.5 Admin docs:

 - 
https://docs.djangoproject.com/en/1.5/ref/contrib/admin/#django.contrib.admin.ModelAdmin.save_model

and this:

 - 
https://docs.djangoproject.com/en/1.5/ref/contrib/admin/#django.contrib.admin.ModelAdmin.save_formset

Changing my "ThreadLocal" middle ware to store the "company site" in the 
session information, I am testing this:

def save_model(self, request, obj, form, change):
if change:
if obj.site.id != request.session['site'].id:
logger.debug("Contacts.Company.save_model: replacing site 
(%s) with (%s) " % (repr(obj.site), repr(request.session['site'])) )
else:
logger.debug("Contacts.Company.save_model: setting site (%s)" % 
(repr(request.session['site'])) )
obj.site = request.session['site']
obj.user = request.user

def save_formset(self, request, form, formset, change):
  instances = formset.save(commit=False)
  for instance in instances:
if change:
if instance.site.id != request.session['site'].id:
logger.debug("Contacts.Company.save_model: replacing site 
(%s) with (%s) " % (repr(instance.site), repr(request.session['site'])) )
else:
logger.debug("Contacts.Company.save_model: setting site (%s)" % 
(repr(request.session['site'])) )
instance.site = request.session['site']
instance.user = request.user
instance.save()
  formset.save_m2m()


This is added to your admin.py as part of your ModelAdmin class.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




How do I change a global setting from inside middleware?

2013-06-23 Thread Richard E. Cooke
I'm using Grappelli to spruce up my Admin interface.

I would like to customize the site name (and web page tittle).

I have this in my project settings.py file:

# http://django-grappelli.readthedocs.org/en/latest/customization.html
GRAPPELLI_ADMIN_TITLE = "The Default Company"


And in my middle ware I try to change it to match the company name of the 
connecting user:
(This code snipped is abbreviated, don't try and copy and paste it into a 
file and run it!)

from django.conf import settings
def process_request(self, request):
settings.GRAPPELLI_ADMIN_TITLE = request.user.myuser.site.name

But it seems to be a crap shoot if the title gets changed to the right 
value, or changed at all!

More shared memory consequences?

I could not find a "best practice" for this.  So, I suspect there is a 
"better way" I'm hoping somebody can enlighten me.

Thanks in advance,
Rich.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: 'FormSet' object has no attribute 'save'

2013-06-23 Thread Xavier Ordoquy
Hi,

Looks like you've missed something in your code. Unfortunately without the 
formset creation / instance creation code, there isn't much we can do.

Regards,
Xavier.

Le 23 juin 2013 à 17:05, Mário Idival  a écrit :

> Hi guys,
> 
> I need of little help with formsets. I want save 3 instances of an form in 
> databases.
> E.G : 
> name
> lastname
> -
> name
> lastname
> -
> name
> lastname
> -
> I try use formset but I'm not getting save, expected this error for me :' 
> ClassNameForSet' object has no attribute 'save'
> Somebody know how i can pass for this?
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>  
>  

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: How do I change a global setting from inside middleware?

2013-06-23 Thread Serge G. Spaolonzi
Django settings cant be changed on the fly.
>From the official documentation:
> You shouldn’t alter settings in your applications at runtime. For
example, don’t do this in a view:

I think the solution for your problem is to set or update
 'grappelli_admin_title'  context variable from the middleware or from a
custom context processor.

Looking at Grappellis code it seems this is the relevant code for your
problem:
grappelli/templates/admin/base.html
{% if grappelli_admin_title %}{{
grappelli_admin_title }}{% else %}{% get_admin_title %}{% endif %}


Using context processors is the best practice for this kind of problems.
For example:

def admin_title(request):
"""
Adds media-related context variables to the context.
"""
user_company_name = request.user.company_name
return {'grappelli_admin_title': user_company_name, }


Regards



On Sun, Jun 23, 2013 at 3:47 PM, Richard E. Cooke wrote:

> I'm using Grappelli to spruce up my Admin interface.
>
> I would like to customize the site name (and web page tittle).
>
> I have this in my project settings.py file:
>
> # http://django-grappelli.readthedocs.org/en/latest/customization.html
> GRAPPELLI_ADMIN_TITLE = "The Default Company"
>
>
> And in my middle ware I try to change it to match the company name of the
> connecting user:
> (This code snipped is abbreviated, don't try and copy and paste it into a
> file and run it!)
>
> from django.conf import settings
> def process_request(self, request):
> settings.GRAPPELLI_ADMIN_TITLE = request.user.myuser.site.name
>
> But it seems to be a crap shoot if the title gets changed to the right
> value, or changed at all!
>
> More shared memory consequences?
>
> I could not find a "best practice" for this.  So, I suspect there is a
> "better way" I'm hoping somebody can enlighten me.
>
> Thanks in advance,
> Rich.
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>



-- 
Serge G. Spaolonzi
Cobalys Systems
http://www.cobalys.com

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Custom context_processors

2013-06-23 Thread Floor Tile
Hello everyone,

I'm puzzling for some time now to get a solution for my following problem.
I hope someone can help me.

I need some context to be filtered before it's rendered in a template. To
do this I got the following piece of code saved in
catalog_context_processors.py :

from catalog.models import Category



def filter_active_category(request):


return {


 'active_categories': Category.objects.filter(is_active=True),


 'request': request


 }

To make use of this context processor I need to get the file into
TEMPLATE_CONTEXT_PROCESSORS. (right?)

When I search the internet almost every hit I get, tells me I have to
re-define TEMPLATE_CONTEXT_PROCESSORS in my settings file, copy the
contents of this variable from the global settings to my settings and add
my file ( catalog_context_processors ).

I have a feeling that it is a much better (cleaner) solution if I add the
following to my settings.py:

TEMPLATE_CONTEXT_PROCESSORS = global_settings.TEMPLATE_CONTEXT_PROCESSORS +
(

  'context_processors',


 )

I have the following questions which I hope somebody can answer:

1. Am I right too use this construction at all? Or is there a better
solution to get this done in Django?
2. Are there best practices for this construction? With this I mean; if
this is the way too go...Where should the "context_processors.py" live?
(Which directory?)

OhI'm using Django 1.5.1.

Many thanks in advance for any pointers in the right direction!!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




How to use context_processors?

2013-06-23 Thread Mark van Deursen
Hello everyone,

I'm puzzling for some time now to get a solution for my following problem. 
I hope someone can help me.

I need some context to be filtered before it's rendered in a template. To 
do this I got the following piece of code saved in 
catalog_context_processors.py :

from catalog.models import Category


  
def filter_active_category(request):   

   
return {   

  
 'active_categories': Category.objects.filter(is_active=True), 

   
 'request': request 

  
 }   

To make use of this context processor I need to get the file into 
TEMPLATE_CONTEXT_PROCESSORS. (right?)

When I search the internet almost every hit I get, tells me I have to 
over-write TEMPLATE_CONTEXT_PROCESSORS in my settings file by copying this 
variable-declaration from the global settings to my settings and add my 
file ( catalog_context_processors ).

I have a feeling that it is a much better (cleaner) solution if I add the 
following to my settings.py:

TEMPLATE_CONTEXT_PROCESSORS = global_settings.TEMPLATE_CONTEXT_PROCESSORS + 
(   
   
  'context_processors', 

 
 ) 

I have the following questions which I hope somebody can answer:

1. Am I right too use this construction at all? Or is there a better 
solution to get this done in Django? 
2. Are there best practices for this construction? With this I mean; if 
this is the way too go...Where should the "context_processors.py" live? 
(Which directory?)

OhI'm using Django 1.5.1.

Many thanks in advance for any pointers in the right direction!!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




How to use context_processors (part X)?

2013-06-23 Thread Floor Tile
*Sorry for multiple posts for the same subject!! I had some difficulties 
getting it right due to some stupidity on my side!*

Hello everyone,

I'm puzzling for some time now to get a solution for my following problem. 
I hope someone can help me.

I need some context to be filtered before it's rendered in a template. To 
do this I got the following piece of code saved in 
catalog_context_processors.py :

from catalog.models import Category


  
def filter_active_category(**request): 

 
return {   

  
 'active_categories': Category.objects.filter(is_**active=True), 

   
 'request': request 

  
 }   

To make use of this context processor I need to get the file into 
TEMPLATE_CONTEXT_PROCESSORS. (right?)

When I search the internet almost every hit I get, tells me I have to 
over-write TEMPLATE_CONTEXT_PROCESSORS in my settings file by copying this 
variable-declaration from the global settings to my settings and add my 
file ( catalog_context_processors ).

I have a feeling that it is a much better (cleaner) solution if I add the 
following to my settings.py:

TEMPLATE_CONTEXT_PROCESSORS = global_settings.TEMPLATE_**CONTEXT_PROCESSORS 
+ ( 
 
  'context_processors', 

 
 ) 

I have the following questions which I hope somebody can answer:

1. Am I right too use this construction at all? Or is there a better 
solution to get this done in Django? 
2. Are there best practices for this construction? With this I mean; if 
this is the way too go...Where should the "context_processors.py" live? 
(Which directory?)

OhI'm using Django 1.5.1.

Many thanks in advance for any pointers in the right direction!!

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




apps referencing username field in custom user classes

2013-06-23 Thread Victor Rajewski
I have a custom minimal user model subclassing AbstractBaseUser, containing 
little more than an email address, for use with django-social-auth. 
However, I'm using an externally-developed app which queries the user model 
using the username field, which in my case does not exist, resulting in a 
FieldError. Rather than modifying the external app, it would be nicer to 
handle this within the User model. While the AbstractBaseUser model does 
call for specifying which field is the username with the USERNAME_FIELD 
property, it doesn't actual allow referencing that field as 'username' in a 
query. 

I've managed to work around this by using a custom queryset as per 
http://stackoverflow.com/questions/17250776/using-an-alias-or-property-in-place-of-a-field-in-django
 
but this seems quite a long-winded way around this.

I'm guessing this case is not unique in apps assuming the presence of a 
field 'username' which the app can use as a unique way of identifying the 
user. Is there a new way (in django 1.5+) that apps should be trying to 
access users? Could django be modified to include so that AbstractBaseUsers 
include a 'virtual' field 'username' which is an alias to whatever 
USERNAME_FIELD references?

Cheers,

Victor

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: Have Jcrop in Django Admin for thumbnails?

2013-06-23 Thread Arkadiusz Tymieniecki
Hi Thomas,

You can learn something from satchmo developers, they've implemented
image_with_thumbnail field here:

https://bitbucket.org/krizma/satchmo/src/7945ef742c82/satchmo/apps/satchmo_utils/thumbnail/field.py

Cheers,
Arkadiusz



On 23/06/13 12:06, thoms wrote:
> Hello,
>
> I'm new in the Django world, and I need some advice.
>
> Basically what I want:
> 1) In m model I have an origianl_image and a thumbnail_image 
> 2) In the admin, a user upload an image 
> 3) Then, we show him the Jcrop pluging to crop the image as a thubnail 
>
> I already do 1) and 2), but have no idea how to do 3)
> Any advice on how to do this?
> Thanks!
>
> -- 
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at http://groups.google.com/group/django-users.
> For more options, visit https://groups.google.com/groups/opt_out.
>  
>  

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: apps referencing username field in custom user classes

2013-06-23 Thread Russell Keith-Magee
On Mon, Jun 24, 2013 at 5:43 AM, Victor Rajewski wrote:

> I have a custom minimal user model subclassing AbstractBaseUser,
> containing little more than an email address, for use with
> django-social-auth. However, I'm using an externally-developed app which
> queries the user model using the username field, which in my case does not
> exist, resulting in a FieldError. Rather than modifying the external app,
> it would be nicer to handle this within the User model. While the
> AbstractBaseUser model does call for specifying which field is the username
> with the USERNAME_FIELD property, it doesn't actual allow referencing that
> field as 'username' in a query.
>

It actually does - you just need to be a little clever about it.

There are two ways -- the hard way (using raw queries), and the easy way.

The hard way:

user = UserModel.objects.get(**{UserModel.USERNAME_FIELD: desired_username})

This exploits the fact that you can pass kwargs to any function, and that
Django's query language is really just a syntax associated with kwarg keys.
You create a dictionary that describes the query you want, and you unroll
it in your User queries.

This is a common enough pattern that it's wrapped up in an easier way:

UserModel.objects.get_by_natural_key(desired_username)

This uses the serialisation infrastructure to do exactly the same query
(you can check the source code if you want :-)

Yours,
Russ Magee %-)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Question about python for web

2013-06-23 Thread Dat Huynh
Dear all,

I have a very simple question about running a simple web application with
apache on MacOS.

Step 1: Copy the file mod_wsgi.so from the link
http://code.google.com/p/modwsgi/downloads/detail?name=mod_wsgi-macosx106-ap22py26-3.3.so
into the folder "/usr/libexec/apache2"


Step 2: Add the following line:

  LoadModule wsgi_module libexec/apache2/mod_wsgi.so
into the file "/etc/apache/httpd.conf"


Step 3: Edit a file "test.py" as below and copy the file to the folder
"/Library/WebServer/".

#!usr/bin/python
print "Content-type: text/html"
print
print ""
print ""
print ""
print "Test Page"
print ""

When I type the following url "http://localhost/test.py"; on my browser, I
see exactly the content of the file, NOT the text "Test Page" only.

I think I miss something in the procedure.
What should I do to make my browser process the received HTML data?

Thank you very much.

Sincerely,
Dat.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: How do I change a global setting from inside middleware?

2013-06-23 Thread Richard E. Cooke
Thanks Mr. Spaolonzi!

I guess its time to read some template docs.  I'll post back what I come up 
with so others can use it.


Rich.


On Sunday, June 23, 2013 3:20:24 PM UTC-4, Serge G. Spaolonzi wrote:
>
> Django settings cant be changed on the fly. 
> From the official documentation:
> > You shouldn’t alter settings in your applications at runtime. For 
> example, don’t do this in a view:
>
> I think the solution for your problem is to set or update 
>  'grappelli_admin_title'  context variable from the middleware or from a 
> custom context processor.
>
> Looking at Grappellis code it seems this is the relevant code for your 
> problem:
> grappelli/templates/admin/base.html
> {% if grappelli_admin_title %}{{ 
> grappelli_admin_title }}{% else %}{% get_admin_title %}{% endif %}
>
>
> Using context processors is the best practice for this kind of problems. 
> For example:
>
> def admin_title(request):
> """
> Adds media-related context variables to the context.
> """
> user_company_name = request.user.company_name
> return {'grappelli_admin_title': user_company_name, }
>
>
> Regards
>
>
>
> On Sun, Jun 23, 2013 at 3:47 PM, Richard E. Cooke 
> 
> > wrote:
>
>> I'm using Grappelli to spruce up my Admin interface.
>>
>> I would like to customize the site name (and web page tittle).
>>
>> I have this in my project settings.py file:
>>
>> # http://django-grappelli.readthedocs.org/en/latest/customization.html
>> GRAPPELLI_ADMIN_TITLE = "The Default Company"
>>
>>
>> And in my middle ware I try to change it to match the company name of the 
>> connecting user:
>> (This code snipped is abbreviated, don't try and copy and paste it into a 
>> file and run it!)
>>
>> from django.conf import settings
>> def process_request(self, request):
>> settings.GRAPPELLI_ADMIN_TITLE = request.user.myuser.site.name
>>
>> But it seems to be a crap shoot if the title gets changed to the right 
>> value, or changed at all!
>>
>> More shared memory consequences?
>>
>> I could not find a "best practice" for this.  So, I suspect there is a 
>> "better way" I'm hoping somebody can enlighten me.
>>
>> Thanks in advance,
>> Rich.
>>
>>  -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users...@googlegroups.com .
>> To post to this group, send email to django...@googlegroups.com
>> .
>> Visit this group at http://groups.google.com/group/django-users.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>  
>>  
>>
>
>
>
> -- 
> Serge G. Spaolonzi
> Cobalys Systems
> http://www.cobalys.com
>  

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.




Re: apps referencing username field in custom user classes

2013-06-23 Thread Victor Rajewski
Thanks Russ, 

This solves the problem from one end, however in my case the wrong end, as 
it would require the app I'm using (and presumably many 
other apps relying on the username field) to be re-written; besides which, 
USERNAME_FIELD is not present in the User model of django <= 1.4 so every 
query for a username would now need a try/except (at least for the first 
way you mention)

And the second way doesn't work for get_object_or_404 or other convenience 
functions or more complex queries.

Cheers,

On Monday, 24 June 2013 10:36:29 UTC+10, Russell Keith-Magee wrote:
>
>
> On Mon, Jun 24, 2013 at 5:43 AM, Victor Rajewski 
> 
> > wrote:
>
>> I have a custom minimal user model subclassing AbstractBaseUser, 
>> containing little more than an email address, for use with 
>> django-social-auth. However, I'm using an externally-developed app which 
>> queries the user model using the username field, which in my case does not 
>> exist, resulting in a FieldError. Rather than modifying the external app, 
>> it would be nicer to handle this within the User model. While the 
>> AbstractBaseUser model does call for specifying which field is the username 
>> with the USERNAME_FIELD property, it doesn't actual allow referencing that 
>> field as 'username' in a query. 
>>
>
> It actually does - you just need to be a little clever about it.
>
> There are two ways -- the hard way (using raw queries), and the easy way.
>
> The hard way: 
>
> user = UserModel.objects.get(**{UserModel.USERNAME_FIELD: 
> desired_username})
>
> This exploits the fact that you can pass kwargs to any function, and that 
> Django's query language is really just a syntax associated with kwarg keys. 
> You create a dictionary that describes the query you want, and you unroll 
> it in your User queries.
>
> This is a common enough pattern that it's wrapped up in an easier way:
>
> UserModel.objects.get_by_natural_key(desired_username)
>
> This uses the serialisation infrastructure to do exactly the same query 
> (you can check the source code if you want :-)
>
> Yours,
> Russ Magee %-)
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
For more options, visit https://groups.google.com/groups/opt_out.