Premi?re version : mise en route du suivi.
authorCyril Robert <Cyril Robert cyrilrbt@gmail.com>
Fri, 9 Apr 2010 13:44:51 +0000 (09:44 -0400)
committerCyril Robert <Cyril Robert cyrilrbt@gmail.com>
Fri, 9 Apr 2010 13:44:51 +0000 (09:44 -0400)
12 files changed:
.gitignore [new file with mode: 0644]
auf_references_client/__init__.py [new file with mode: 0644]
auf_references_client/backends.py [new file with mode: 0644]
auf_references_client/manage.py [new file with mode: 0644]
auf_references_client/models.py [new file with mode: 0644]
auf_references_client/serializers.py [new file with mode: 0644]
auf_references_client/settings.py [new file with mode: 0644]
auf_references_client/tests.py [new file with mode: 0644]
auf_references_client/urls.py [new file with mode: 0644]
auf_references_client/views.py [new file with mode: 0644]
setup.cfg [new file with mode: 0644]
setup.py [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..45dd433
--- /dev/null
@@ -0,0 +1,33 @@
+# binaires
+*.pyc
+*.pyo
+
+# setuptools
+*.egg-info
+dist
+
+# Fichier temporaires:
+.*.swp
+*~
+\#*#
+
+# DB de dev
+*.db
+
+# restants de merge
+*.orig
+*.rej
+
+# Configuration du projet - par environnement
+conf.py
+django.wsgi
+
+# buildout
+.installed.cfg
+bin
+develop-eggs
+downloads
+eggs
+log
+parts
+tmp
diff --git a/auf_references_client/__init__.py b/auf_references_client/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/auf_references_client/backends.py b/auf_references_client/backends.py
new file mode 100644 (file)
index 0000000..cd56d26
--- /dev/null
@@ -0,0 +1,71 @@
+# -*- encoding: utf-8 -*-
+import hashlib, sys
+
+from django.conf import settings
+from django.contrib.auth.backends import ModelBackend
+from django.contrib.auth.models import User as DjangoUser, check_password
+
+from models import AufUser as RemoteUser
+
+class CascadeBackend(ModelBackend):
+    def authenticate(self, username=None, password=None):
+        user = None
+
+        # Prep des données
+        if username.endswith ("@auf.org"):
+            username = username.replace ("@auf.org", "")
+
+        email = "%s@auf.org" % username
+        md5pass = hashlib.md5(password).hexdigest ()
+
+        # Cherche les comptes roa+locaux
+        remoteUser = localUser = None
+        try:
+            if settings.AUTH_PASSWORD_REQUIRED:
+                remoteUser = RemoteUser.objects.get (email=email, password=md5pass)
+            else:
+                remoteUser = RemoteUser.objects.get (email=email)
+        except:
+            pass
+        try:
+            localUser = DjangoUser.objects.get (username=username)
+        except: pass
+
+        # Si on a pas besoin du mdp, on doit copier qd meme,
+        # il ne faut jamais retourner un "RemoteUser" ici
+        if not settings.AUTH_PASSWORD_REQUIRED:
+            if remoteUser and not localUser:
+                localUser = DjangoUser (username = username,
+                        email = email, 
+                        first_name = remoteUser.first_name,
+                        last_name = remoteUser.last_name,
+                        is_staff = False,
+                        is_active = True,
+                        is_superuser = False)
+                localUser.set_password (password)
+                localUser.save ()
+            user = localUser
+        # Gestion des comptes roa vs. local
+        else:
+            # Local existe pas, on doit de tte facon le creer
+            if not localUser:
+                localUser = DjangoUser (username = username,
+                        email = email, 
+                        is_staff = False,
+                        is_active = True,
+                        is_superuser = False)
+            # Cas du compte local seul, on verifie le mot de passe
+            elif not remoteUser:
+                if localUser.check_password (password):
+                    user = localUser
+            # Compte roa, on valide le mot de passe distant et on
+            # met a jour la copie locale
+            if remoteUser:
+                localUser.first_name = remoteUser.first_name
+                localUser.last_name = remoteUser.last_name
+                # pass distant en md5
+                localUser.set_password (password)
+                localUser.save ()
+                user = localUser
+
+        return user
diff --git a/auf_references_client/manage.py b/auf_references_client/manage.py
new file mode 100644 (file)
index 0000000..5e78ea9
--- /dev/null
@@ -0,0 +1,11 @@
+#!/usr/bin/env python
+from django.core.management import execute_manager
+try:
+    import settings # Assumed to be in the same directory.
+except ImportError:
+    import sys
+    sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__)
+    sys.exit(1)
+
+if __name__ == "__main__":
+    execute_manager(settings)
diff --git a/auf_references_client/models.py b/auf_references_client/models.py
new file mode 100644 (file)
index 0000000..797eba6
--- /dev/null
@@ -0,0 +1 @@
+from auf_references_modeles import *
diff --git a/auf_references_client/serializers.py b/auf_references_client/serializers.py
new file mode 100644 (file)
index 0000000..c5b6550
--- /dev/null
@@ -0,0 +1,31 @@
+from django.conf import settings
+from django.utils.xmlutils import SimplerXMLGenerator
+
+from django.core.serializers.xml_serializer import Serializer as XMLSerializer, \
+                                                   Deserializer as XMLDeserializer
+
+class Serializer(XMLSerializer):
+    """
+    A test serializer which removes ``django-objects`` xml tag from default
+    Django's xml serializer, adapt it to your own usage.
+    """
+    
+    def start_serialization(self):
+        """
+        Start serialization -- open the XML document and the root element.
+        """
+        self.xml = SimplerXMLGenerator(self.stream, self.options.get("encoding", settings.DEFAULT_CHARSET))
+        self.xml.startDocument()
+        self.xml.startElement("django-test", {"version" : "1.0"})
+
+    def end_serialization(self):
+        """
+        End serialization -- end the document.
+        """
+        self.indent(0)
+        self.xml.endElement("django-test")
+        self.xml.endDocument()
+
+
+class Deserializer(XMLDeserializer):
+    pass
diff --git a/auf_references_client/settings.py b/auf_references_client/settings.py
new file mode 100644 (file)
index 0000000..c9e505b
--- /dev/null
@@ -0,0 +1,28 @@
+# Django settings for app project.
+ROA_MODELS = True   # set to False if you'd like to develop/test locally
+
+ROA_FORMAT = 'django'
+SERIALIZATION_MODULES = {
+    'django' : 'auf_references_client.serializers',
+}
+ROA_HEADERS = {
+    'Content-Type': 'application/x-www-form-urlencoded',
+}
+ROA_DJANGO_ERRORS = True # useful to ease debugging if you use test server
+
+
+# URLs
+#ROA_URL_OVERRIDES_LIST = {
+#    'auf_references_modeles.pays': 'http://localhost:8001/roa/pays/',
+#    'auf_references_modeles.region': 'http://localhost:8001/roa/region/',
+#}
+ROA_BASE_URL = "https://references.auf.org/roa/"
+
+## Pour la nouvelle app d'auth
+#AUTHENTICATION_BACKENDS = (
+#    'auf_references_client.backends.CascadeBackend',
+#)
+#AUTH_PASSWORD_REQUIRED=True
+
+## ?
+#ROA_CUSTOM_ARGS = {'api-key': ROA_API_KEY}
diff --git a/auf_references_client/tests.py b/auf_references_client/tests.py
new file mode 100644 (file)
index 0000000..2247054
--- /dev/null
@@ -0,0 +1,23 @@
+"""
+This file demonstrates two different styles of tests (one doctest and one
+unittest). These will both pass when you run "manage.py test".
+
+Replace these with more appropriate tests for your application.
+"""
+
+from django.test import TestCase
+
+class SimpleTest(TestCase):
+    def test_basic_addition(self):
+        """
+        Tests that 1 + 1 always equals 2.
+        """
+        self.failUnlessEqual(1 + 1, 2)
+
+__test__ = {"doctest": """
+Another way to test that 1 + 1 is equal to 2.
+
+>>> 1 + 1 == 2
+True
+"""}
+
diff --git a/auf_references_client/urls.py b/auf_references_client/urls.py
new file mode 100644 (file)
index 0000000..f240223
--- /dev/null
@@ -0,0 +1,17 @@
+from django.conf.urls.defaults import *
+
+# Uncomment the next two lines to enable the admin:
+# from django.contrib import admin
+# admin.autodiscover()
+
+urlpatterns = patterns('',
+    # Example:
+    # (r'^app/', include('app.foo.urls')),
+
+    # Uncomment the admin/doc line below and add 'django.contrib.admindocs' 
+    # to INSTALLED_APPS to enable admin documentation:
+    # (r'^admin/doc/', include('django.contrib.admindocs.urls')),
+
+    # Uncomment the next line to enable the admin:
+    # (r'^admin/', include(admin.site.urls)),
+)
diff --git a/auf_references_client/views.py b/auf_references_client/views.py
new file mode 100644 (file)
index 0000000..60f00ef
--- /dev/null
@@ -0,0 +1 @@
+# Create your views here.
diff --git a/setup.cfg b/setup.cfg
new file mode 100644 (file)
index 0000000..f4c8d25
--- /dev/null
+++ b/setup.cfg
@@ -0,0 +1,7 @@
+[egg_info]
+tag_build = dev
+
+#[build_sphinx]
+#source-dir = doc/
+#build-dir = doc/_build
+#all_files = 1
diff --git a/setup.py b/setup.py
new file mode 100644 (file)
index 0000000..f05a5d1
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,22 @@
+# -*- encoding: utf-8 -*-
+from setuptools import setup, find_packages
+import sys, os
+
+version = '0.1.6'
+
+if __name__ == '__main__':
+    setup(
+        name='auf_references_client',
+        version=version,
+        description="TEMPORAIRE - App django sachant parler à auf_references",
+        classifiers=[],
+        keywords='',
+        author='Cyril Robert',
+        author_email='cyril.robert@auf.org',
+        url='',
+        license='GPL',
+        packages = find_packages (),
+        include_package_data=True,
+        zip_safe=False,
+        install_requires=['django', 'django-roa', 'auf_references_modeles'],
+        )