using my own User object instead of django.contrib.auth.models.User ?

103 views
Skip to first unread message

Alex Lovell-Troy

unread,
Jul 20, 2011, 7:48:10 AM7/20/11
to django-paypal
I'm integrating the django-paypal stuff into an existing website that
uses it's own object for users rather than the User object. It's
compatible with most other things, but I see that paypal/pro/models
assumes that my logged-in user will be present in the User table and
then works with that assumption in the __init__(). Does anyone with
more experience have a suggestion for how I can link the user
attribute on the PayPalNVP class to my own user object without making
drastically brittle changes to the source?

Class PayPalNVP(Model):
...
user = models.ForeignKey(User, blank=True, null=True)
...
def init(self, request, paypal_request, paypal_response)
...
if hasattr(request, "user") and request.user.is_authenticated():
self.user = request.user
...


-alex

John Lockwood

unread,
Jul 20, 2011, 4:54:40 PM7/20/11
to django...@googlegroups.com
write your own auth.ModelBackend interface to your  and set it in AUTHENTICATION_BACKENDS and write your one AuthenticationMiddleware


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


Lior Sion

unread,
Jul 21, 2011, 4:46:06 AM7/21/11
to django...@googlegroups.com
I would guess that this already exists if the system works properly with the new user type. 

Two simple options to consider:

change the django-paypal code to support different models, and contribute back to github. I played with the package , it's not very complicated.

create duplicate data with the users table. I would highly recommend against this approach, very error prone.
--
thanks,
Lior Sion

Skype: sionlior | GTalk: lior.sion

Alex Lovell-Troy

unread,
Jul 21, 2011, 12:02:51 PM7/21/11
to django...@googlegroups.com
I ended up changing the way django-paypal interacts with the auth system in a non-wonderful way, but it does the job and is fairly general.  I just set the Model that looks like a User in settings.py and use that instead if it is specified.

Good point about offering the changes back through github.  Until I get that set up, here's an inline diff of my changes for your consideration:

-- a/paypal/pro/models.py                                                                                                                                                                                
+++ b/paypal/pro/models.py                                                                                                                                                                                
@@ -2,9 +2,13 @@                                                                                                                                                                                          
 # -*- coding: utf-8 -*-                                                                                                                                                                                  
 from string import split as L                                                                                                                                                                            
 from django.db import models                                                                                                                                                                             
+from django.conf import settings                                                                                                                                                                         
 from django.utils.http import urlencode                                                                                                                                                                  
 from django.forms.models import model_to_dict                                                                                                                                                            
-from django.contrib.auth.models import User                                                                                                                                                              
+if getattr(settings, 'PAYPAL_USER_MODEL', None):                                                                                                                                                         
+    User = models.get_model(*settings.PAYPAL_USER_MODEL.rsplit('.', 1))                                                                                                                                  
+else:                                                                                                                                                                                                    
+    from django.contrib.auth.models import User        
Alex Lovell-Troy
Lead Engineer | OneLeap
Twitter: @alexlovelltroy @oneleap
http://oneleap.to/alt
Reply all
Reply to author
Forward
0 new messages