summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJayaram Pai2013-12-05 21:25:35 +0530
committerJayaram Pai2013-12-05 21:25:35 +0530
commit41e5496301cd02bff34dad877d20b2dd30349866 (patch)
tree587de041ff2c6820c7b2a9fc0c4ab87a6c2eb63a
parente0bbd9f308e03d1d4e5b2f1e668b8958c81c039e (diff)
downloadspoken-tutorial-forums-41e5496301cd02bff34dad877d20b2dd30349866.tar.gz
spoken-tutorial-forums-41e5496301cd02bff34dad877d20b2dd30349866.tar.bz2
spoken-tutorial-forums-41e5496301cd02bff34dad877d20b2dd30349866.zip
something works :)
-rw-r--r--drupal_auth/backends.py23
-rw-r--r--drupal_auth/managers.py26
-rw-r--r--drupal_auth/models.py28
-rw-r--r--drupal_auth/routers.py18
-rw-r--r--forums/settings.py6
-rw-r--r--static/website/templates/index.html1
-rw-r--r--website/models.py13
-rw-r--r--website/views.py3
8 files changed, 103 insertions, 15 deletions
diff --git a/drupal_auth/backends.py b/drupal_auth/backends.py
new file mode 100644
index 0000000..1caa1f0
--- /dev/null
+++ b/drupal_auth/backends.py
@@ -0,0 +1,23 @@
+from django.contrib.auth.models import User
+from django.contrib.auth import get_user_model
+from django.shortcuts import render_to_response, get_object_or_404
+
+User = get_user_model()
+
+class DrupalAuthBackend(object):
+ def authenticate(self, username=None, password=None):
+ try:
+ user = User(name='cheese')
+ user.is_active = True
+ user.is_authenticated = True
+ return user
+ except Exception, e:
+ print e.message
+ print "blaj"*1000
+
+ def get_user(self, user_id):
+ try:
+ print "Hello"*1000
+ return User.objects.get(pk=user_id)
+ except User.DoesNotExist:
+ return None
diff --git a/drupal_auth/managers.py b/drupal_auth/managers.py
new file mode 100644
index 0000000..d1dc662
--- /dev/null
+++ b/drupal_auth/managers.py
@@ -0,0 +1,26 @@
+import md5
+
+from django.db import models
+from django.contrib.auth.models import (
+ BaseUserManager, AbstractBaseUser
+)
+
+class DrupalUserManager(BaseUserManager):
+ def create_user(self, password=None):
+ user = self.model()
+ if not email:
+ raise ValueError('Users must have an email address')
+
+ user.set_password(password)
+ user.save(using=self._db)
+ return user
+
+ def create_superuser(self, name, password):
+ user = self.model()
+ user.name= name
+ p = md5.new()
+ p.update(password)
+ user.pass_field= p.hexdigest()
+ user.is_admin = True
+ user.save(using=self._db)
+ return user
diff --git a/drupal_auth/models.py b/drupal_auth/models.py
new file mode 100644
index 0000000..e3fab6b
--- /dev/null
+++ b/drupal_auth/models.py
@@ -0,0 +1,28 @@
+from django.db import models
+from django.contrib.auth.models import User
+from django.contrib.auth.models import (
+ BaseUserManager, AbstractBaseUser
+)
+
+from drupal_auth.managers import DrupalUserManager
+
+class Users(models.Model):
+ name = models.CharField(max_length=60L, unique=True, primary_key=True)
+ pass_field = models.CharField(max_length=32L, db_column='pass') # Field renamed because it was a Python reserved word.
+ last_login = models.DateTimeField(auto_now_add=True)
+
+ USERNAME_FIELD = 'name'
+ REQUIRED_FIELDS = []
+ objects = DrupalUserManager()
+
+ class Meta:
+ db_table = 'users'
+
+ def is_authenticated(self):
+ return True
+#class Test(AbstractBaseUser):
+# username = models.CharField(max_length=40, unique=True, db_index=True)
+# USERNAME_FIELD = 'username'
+# REQUIRED_FIELDS = []
+#
+# objects = DrupalUserManager()
diff --git a/drupal_auth/routers.py b/drupal_auth/routers.py
new file mode 100644
index 0000000..c125f73
--- /dev/null
+++ b/drupal_auth/routers.py
@@ -0,0 +1,18 @@
+class DrupalAuthRouter(object):
+ def db_for_read(self, model, **hints):
+ if model._meta.app_label == 'drupal_auth':
+ print '######################################### read_spoken'
+ return 'spoken'
+ return 'default'
+
+ def db_for_write(self, model, **hints):
+ if model._meta.app_label == 'drupal_auth':
+ print '######################################### write_spoken'
+ return 'spoken'
+ return 'default'
+
+ def allow_relation(self, **hints):
+ return True
+
+ def allow_syncdb(self, db, model):
+ return True
diff --git a/forums/settings.py b/forums/settings.py
index 6a82a19..dc2bb08 100644
--- a/forums/settings.py
+++ b/forums/settings.py
@@ -144,6 +144,7 @@ INSTALLED_APPS = (
# 'django.contrib.admindocs',
'website',
'widget_tweaks',
+ 'drupal_auth',
)
# A sample logging configuration. The only tangible logging
@@ -175,5 +176,6 @@ LOGGING = {
}
}
-AUTHENTICATION_BACKENDS = ( 'drupal_auth.backend.DrupalAuthBackend', )
-AUTH_USER_MODEL = 'website.Test'
+AUTH_USER_MODEL = 'drupal_auth.Users'
+AUTHENTICATION_BACKENDS = ( 'drupal_auth.backends.DrupalAuthBackend', )
+DATABASE_ROUTERS = ['drupal_auth.routers.DrupalAuthRouter']
diff --git a/static/website/templates/index.html b/static/website/templates/index.html
index ddc9078..5fcfec8 100644
--- a/static/website/templates/index.html
+++ b/static/website/templates/index.html
@@ -1,6 +1,7 @@
{% extends 'website/templates/base.html' %}
{% block content %}
<h4>Recent Questions</h4>
+{{ user.name }}
{% for question in questions %}
<div class="question">
<div class="title">
diff --git a/website/models.py b/website/models.py
index e47fb00..b38c118 100644
--- a/website/models.py
+++ b/website/models.py
@@ -1,11 +1,6 @@
from django.conf import settings
from django.db import models
from django.contrib.auth.models import User
-from django.contrib.auth.models import (
- BaseUserManager, AbstractBaseUser
-)
-
-from website.managers import DrupalUserManager
class Question(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL)
@@ -26,6 +21,7 @@ class Reply(models.Model):
date_modified = models.DateTimeField(auto_now=True)
# CDEEP database created using inspectdb arg of manage.py
+
class TutorialDetails(models.Model):
id = models.IntegerField(primary_key=True)
foss_category = models.CharField(max_length=255L)
@@ -59,10 +55,3 @@ class TutorialResources(models.Model):
request_exception = models.TextField()
class Meta:
db_table = 'tutorial_resources'
-
-class Test(AbstractBaseUser):
- username = models.CharField(max_length=40, unique=True, db_index=True)
- USERNAME_FIELD = 'username'
- REQUIRED_FIELDS = []
-
- objects = DrupalUserManager()
diff --git a/website/views.py b/website/views.py
index d8c4012..29c6a76 100644
--- a/website/views.py
+++ b/website/views.py
@@ -29,7 +29,8 @@ categories = [
def home(request):
questions = Question.objects.all().order_by('date_created').reverse()[:10]
context = {
- 'questions': questions
+ 'questions': questions,
+ 'user': request.user
}
return render_to_response('website/templates/index.html', context)