Giter VIP home page Giter VIP logo

mango's Introduction

Installation

To install mango:

sudo python setup.py install

Usage

To use mango with your Django project, just add these lines to your settings.py file:

SESSION_ENGINE = 'mango.session'
AUTHENTICATION_BACKENDS = ('mango.auth.Backend',)
MONGODB_HOST = 'localhost'  # enter your MongoDB hostname here
MONGODB_PORT = None         # enter your MongoDB port here (None for default port)
MONGODB_NAME = 'mydb'       # enter your MongoDB database name here

Also, make sure 'MIDDLEWARE_CLASSES' contains the session and authentication middleware classes:

MIDDLEWARE_CLASSES = (
   ...
   'django.contrib.sessions.middleware.SessionMiddleware',
   'django.contrib.auth.middleware.AuthenticationMiddleware',
   ...
)

Django sessions should now work exactly as described in the Django sessions documentation.

For the most part, Django authentication should also work as described in the Django authentication documentation. However, since many of the administrative functions rely on Django's ORM model (which we no longer have with mongodb), you can't use the User model described in the Django documentation to directly manipulate User objects. Instead, mango provides its own User class that you should use instead. All of Django's original User class instance methods are available in mango's User class (is_authenticated(), set_password(), check_password(), etc...). However, there is longer a User.objects attribute. Instead, many of the administrative function such as create_user() are now class methods of User.

For instance, to create a user:

>>> from mango.auth import User
>>> user = User.create_user('john', '[email protected]', 'johnpassword')

To find a user:

>>> from mango.auth import User
>>> user = User.get({'username': 'john'})

To modify a user's attributes:

>>> from mango.auth import User
>>> user = User.get({'username': 'john'})
>>> user.first_name = 'John'
>>> user.last_name = 'Lennon'
>>> user.save()

To delete a user:

>>> from mango.auth import User
>>> user = User.get({'username': 'john'})
>>> user.delete()

If you want direct access to the database connection from anywhere in your Django app:

>>> from mango import database as db
>>> db.users.find()
>>> db.sessions.find()

Limitations

Support for permissions and groups is not available yet, but is coming soon.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.