Bitbucket is a code hosting site with unlimited public and private repositories. We're also free for small teams!

Close
Use mode:

1. Enter into to the django-globalrequest directory and execute the following command:
$ python setup.py install

2. Inside your django project, add the line:
    'jaa.django.globalrequest.middleware.GlobalRequestMiddleware',
to your MIDDLEWARE_CLASSES tuple in settings.py.

Example:
        MIDDLEWARE_CLASSES = (
            'django.middleware.common.CommonMiddleware',
            ...
            'jaa.django.globalrequest.middleware.GlobalRequestMiddleware',
        }

3. Then, in your python code you can do the following:
    
from jaa.globalrequest import get_request
...
request = get_request()
user = request.user

Example:

-----models.py----
from django.db import models
from django.contrib.auth.models import User
from jaa.django.globalrequest import get_request

class Comment(models.Model):
    comment = models.TextField()
    user = models.ForeignKey(User)
    def __init__(self, *args, **kwargs):
        super(Comment, self).__init__(*args, **kwargs)
        self.user = get_request().user

-----models.py----

Recent activity

Jonatan Alexis Anauati

Commits by Jonatan Alexis Anauati were pushed to janauati/django-globalrequest

482f519 - Version 0.2.0. Adds `get_current_user_model` method. it verifies that current user is an instance of django.contrib.auth.models.User and returns it, otherwise returns None.
Jonatan Alexis Anauati

Commits by Jonatan Alexis Anauati were pushed to janauati/django-globalrequest

e4fe13e - Adds the `get_current_site` method. By examining the current request, this method returns the related Site object (`django.contrib.sites.models.Site`).
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.