|
List Info
Thread: django-drupal combo
|
|
| django-drupal combo |

|
2006-11-19 21:16:47 |
I'm thinking about adding a Django admin utility to an
existing Drupal
website. Before I dig into experimentation, I'd like to see
if anyone
can see any likely problems (other than it just sounds
hairbrained).
I'm not really mixing Drupal/Django functionality. I want to
run
reports in Django against data kept in Drupal's user table.
Actually,
I want to keep some additional data in a Django model which
contributes
to the reports. My idea is just to put the Django and Drupal
tables
into the same mysql database. I don't see any name
collisions. Offhand,
it seems doable.
But what about hidden gotchas, like what happens if I run a
syncdb,
will Django do something to mysql tables that don't
correspond to
Django models? Does anyone know of any other lurking
surprises?
Thanks,
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-unsubscribe googlegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---
|
|
| django-drupal combo |

|
2006-11-20 16:35:55 |
On 11/19/06, doubtintom <doubtintom gmail.com> wrote:
> But what about hidden gotchas, like what happens if I
run a syncdb,
> will Django do something to mysql tables that don't
correspond to
> Django models? Does anyone know of any other lurking
surprises?
The "syncdb" command does not alter or delete
existing tables. It only
adds new ones. So it won't touch the Drupal tables.
Adrian
--
Adrian Holovaty
holovaty.com | djangoproject.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-unsubscribe googlegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---
|
|
| django-drupal combo |

|
2006-11-22 01:53:28 |
Hey, another Drupal/Django user!
I don't know if this is something you need to do, but here
is some code
that gets a user dictionary for the currently logged in
Drupal user.
I'm using this to give my existing Drupal users the ability
to edit
Django records without having to do a separate Django login.
--jefurii
My Drupal install uses a totally separate database, so I
added these
settings to my settings.py:
> DRUPAL_DATABASE_HOST = 'localhost'
> DRUPAL_DATABASE_NAME = 'drupaldatabase'
> DRUPAL_DATABASE_USER = 'drupaldbuser'
> DRUPAL_DATABASE_PASSWORD = '**********'
The following code is in a views.py, but it really should be
in a
separate file:
> from django.conf import settings
> import MySQLdb
>
> def get_drupal_user(request):
> """Look at the PHP Session ID and
get the logged-in Drupal user and their user
roles."""
> phpsessionid =
request.COOKIES.get('PHPSESSID',None)
> # get user
> user = { }
> user_query = "SELECT s.sid, s.uid, u.name
FROM sessions s, users u
> WHERE (u.uid = s.uid) AND (s.sid =
%s)"
> user_results = get_drupal_stuff(user_query,
phpsessionid)
> if (user_results) and (type(user_results) ==
'string') and (user_results.find('rror')):
> user = user_results
> elif user_results:
> user = {'uid': user_results[0]['uid'], 'name':
user_results[0]['name']}
> # get user roles
> roles = [ ]
> roles_query = "SELECT r.rid, r.name FROM
users_roles ur, role r
> WHERE (ur.rid = r.rid) AND
(ur.uid = %s)"
> role_results = get_drupal_stuff(roles_query,
user['uid'])
> if role_results:
> for row in role_results:
> roles.append(row['name'])
> user['roles'] = roles
> return user
>
> def get_drupal_stuff(query, arg):
> """Wrapper function for executing a
query on the Drupal database."""
> results = { }
> try:
> c =
MySQLdb.connect(host=settings.DRUPAL_DATABASE_HOST,
>
db=settings.DRUPAL_DATABASE_NAME,
>
user=settings.DRUPAL_DATABASE_USER,
>
passwd=settings.DRUPAL_DATABASE_PASSWORD)
> cursor = c.cursor(MySQLdb.cursors.DictCursor)
> cursor.execute(query, arg)
> except MySQLdb.OperationalError, message:
> results = "Error %d:n%s" %
(message[0], message[1])
> else:
> results = cursor.fetchall()
> cursor.close()
> c.close()
> return results
And finally, this code gets a dictionary containing the user
info:
> def index(request):
> user = get_drupal_user(request)
--~--~---------~--~----~------------~-------~--~----~
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-unsubscribe googlegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---
|
|
| django-drupal combo |

|
2006-11-22 08:59:16 |
Well done. Maybe one day I'll need to use a combo of Django
and Drupal too.
Good luck!
Aidas Bendoraitis [aka Archatas]
On 11/22/06, jefurii <jefurii gmail.com> wrote:
>
> Hey, another Drupal/Django user!
> I don't know if this is something you need to do, but
here is some code
> that gets a user dictionary for the currently logged in
Drupal user.
> I'm using this to give my existing Drupal users the
ability to edit
> Django records without having to do a separate Django
login.
> --jefurii
>
>
> My Drupal install uses a totally separate database, so
I added these
> settings to my settings.py:
>
> > DRUPAL_DATABASE_HOST = 'localhost'
> > DRUPAL_DATABASE_NAME = 'drupaldatabase'
> > DRUPAL_DATABASE_USER = 'drupaldbuser'
> > DRUPAL_DATABASE_PASSWORD = '**********'
>
>
> The following code is in a views.py, but it really
should be in a
> separate file:
>
> > from django.conf import settings
> > import MySQLdb
> >
> > def get_drupal_user(request):
> > """Look at the PHP Session ID
and get the logged-in Drupal user and their user
roles."""
> > phpsessionid =
request.COOKIES.get('PHPSESSID',None)
> > # get user
> > user = { }
> > user_query = "SELECT s.sid, s.uid,
u.name FROM sessions s, users u
> > WHERE (u.uid = s.uid) AND
(s.sid = %s)"
> > user_results = get_drupal_stuff(user_query,
phpsessionid)
> > if (user_results) and (type(user_results) ==
'string') and (user_results.find('rror')):
> > user = user_results
> > elif user_results:
> > user = {'uid': user_results[0]['uid'],
'name': user_results[0]['name']}
> > # get user roles
> > roles = [ ]
> > roles_query = "SELECT r.rid, r.name
FROM users_roles ur, role r
> > WHERE (ur.rid = r.rid) AND
(ur.uid = %s)"
> > role_results =
get_drupal_stuff(roles_query, user['uid'])
> > if role_results:
> > for row in role_results:
> > roles.append(row['name'])
> > user['roles'] = roles
> > return user
> >
> > def get_drupal_stuff(query, arg):
> > """Wrapper function for
executing a query on the Drupal database."""
> > results = { }
> > try:
> > c =
MySQLdb.connect(host=settings.DRUPAL_DATABASE_HOST,
> >
db=settings.DRUPAL_DATABASE_NAME,
> >
user=settings.DRUPAL_DATABASE_USER,
> >
passwd=settings.DRUPAL_DATABASE_PASSWORD)
> > cursor =
c.cursor(MySQLdb.cursors.DictCursor)
> > cursor.execute(query, arg)
> > except MySQLdb.OperationalError, message:
> > results = "Error %d:n%s" %
(message[0], message[1])
> > else:
> > results = cursor.fetchall()
> > cursor.close()
> > c.close()
> > return results
>
>
> And finally, this code gets a dictionary containing the
user info:
>
> > def index(request):
> > user = get_drupal_user(request)
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
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-unsubscribe googlegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---
|
|
[1-4]
|
|