GithubHelp home page GithubHelp logo

alir3z4 / django-cuser Goto Github PK

View Code? Open in Web Editor NEW

This project forked from seveas/django-echelon

39.0 39.0 11.0 91 KB

Middleware to make authentication data easily available to all parts of a django project

Home Page: http://pypi.python.org/pypi/django-cuser

License: BSD 3-Clause "New" or "Revised" License

Python 100.00%
authentication django

django-cuser's People

Contributors

alir3z4 avatar daniell avatar daniellawrence avatar joetric avatar luzfcb avatar martinburchell avatar muhuk avatar seveas avatar vst avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

django-cuser's Issues

Returns None

Although I login, it returns None, Do you have any idea for this?

cuser import fails in Django 1.7

Hi,
the following vanilla installation works with Django 1.6 but not with Django 1.7:
#1# settings.py

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'cuser',
    'test_dj17',
)
MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'cuser.middleware.CuserMiddleware',
)

#2# test_dj17/models.py

from django.db import models
from cuser.middleware import CuserMiddleware
from cuser.fields import CurrentUserField
# Create your models here.

In Django 1.6 everything works fine, in Django 1.7 I get:

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/srv/vhost73/virtual/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
    utility.execute()
  File "/srv/vhost73/virtual/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute
    django.setup()
  File "/srv/vhost73/virtual/local/lib/python2.7/site-packages/django/__init__.py", line 21, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/srv/vhost73/virtual/local/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
    app_config.import_models(all_models)
  File "/srv/vhost73/virtual/local/lib/python2.7/site-packages/django/apps/config.py", line 197, in import_models
    self.models_module = import_module(models_module_name)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/srv/vhost73/project/test_dj17/models.py", line 3, in <module>
    from cuser.middleware import CuserMiddleware
  File "/srv/vhost73/virtual/local/lib/python2.7/site-packages/cuser/middleware.py", line 5, in <module>
    User = get_user_model()
  File "/srv/vhost73/virtual/local/lib/python2.7/site-packages/django/contrib/auth/__init__.py", line 136, in get_user_model
    return django_apps.get_model(settings.AUTH_USER_MODEL)
  File "/srv/vhost73/virtual/local/lib/python2.7/site-packages/django/apps/registry.py", line 199, in get_model
    self.check_models_ready()
  File "/srv/vhost73/virtual/local/lib/python2.7/site-packages/django/apps/registry.py", line 131, in check_models_ready
    raise AppRegistryNotReady("Models aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Models aren't loaded yet.

Am I missing something in my configuration or is the problem due to changes in 1.7? The 1.7 documentation says: " get_user_model() only works once Django has imported all models." (https://docs.djangoproject.com/en/1.7/topics/auth/customizing/).

Best wishes,
Volker

Django 1.9

Hello, I have a project in Django 1.9 and I am trying to use your application but gives me an error when importing the CurrentUserField.

from __future__ import unicode_literals

from django.utils.translation import ugettext_lazy as _
from django.contrib.auth.models import User
from django.db import models

from cuser.fields import CurrentUserField

from myapps.utils.models import Audit


class Project(models.Model):
    name = models.CharField(max_length=150, verbose_name=_(u'Nombre del proyecto'), unique=True)
    creator = CurrentUserField(add_only=True, related_name='created_projects')

    class Meta:
      verbose_name = _(u'Proyecto')
      verbose_name_plural = _(u'Proyectos')
      ordering = ['name', ]

    def __unicode__(self):
      return "%s" % self.name`

The error is as follows:

File "/virtualenv/baenet/local/lib/python2.7/site-packages/django/apps/config.py", line 202, in import_models
    self.models_module = import_module(models_module_name)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/webapps/baenet/baenet/myapps/projects/models.py", line 14, in <module>
    class Project(models.Model):
  File "/webapps/baenet/baenet/myapps/projects/models.py", line 16, in Project
    creator = CurrentUserField(add_only=True, related_name='created_projects')
  File "/virtualenv/baenet/local/lib/python2.7/site-packages/cuser/fields.py", line 27, in __init__
    super(CurrentUserField, self).__init__(**kwargs)
  File "/virtualenv/baenet/local/lib/python2.7/site-packages/django/db/models/fields/related.py", line 799, in __init__
    to, on_delete, from_fields=['self'], to_fields=[to_field], **kwargs)
  File "/virtualenv/baenet/local/lib/python2.7/site-packages/django/db/models/fields/related.py", line 456, in __init__
    super(ForeignObject, self).__init__(rel=rel, **kwargs)
TypeError: __init__() got an unexpected keyword argument 'rel_class'`

Not work in Django 1.10

Unhandled exception in thread started by <function check_errors..wrapper at 0x7f9ba3fea378>

Traceback (most recent call last):

File "/home/shaman/Work/envs/ufanet_ru/lib/python3.4/site-packages/django/utils/autoreload.py", line 226, in wrapper
fn(_args, *_kwargs)
File "/home/shaman/Work/envs/ufanet_ru/lib/python3.4/site-packages/django/core/management/commands/runserver.py", line 142, in inner_run
handler = self.get_handler(_args, *_options)
File "/home/shaman/Work/envs/ufanet_ru/lib/python3.4/site-packages/django/contrib/staticfiles/management/commands/runserver.py", line 27, in get_handler
handler = super(Command, self).get_handler(_args, *_options)
File "/home/shaman/Work/envs/ufanet_ru/lib/python3.4/site-packages/django/core/management/commands/runserver.py", line 64, in get_handler
return get_internal_wsgi_application()
File "/home/shaman/Work/envs/ufanet_ru/lib/python3.4/site-packages/django/core/servers/basehttp.py", line 49, in get_internal_wsgi_application
return import_string(app_path)
File "/home/shaman/Work/envs/ufanet_ru/lib/python3.4/site-packages/django/utils/module_loading.py", line 20, in import_string
module = import_module(module_path)
File "/home/shaman/Work/envs/ufanet_ru/lib/python3.4/importlib/init.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 2254, in _gcd_import
File "", line 2237, in _find_and_load
File "", line 2226, in _find_and_load_unlocked
File "", line 1200, in _load_unlocked
File "", line 1129, in _exec
File "", line 1471, in exec_module
File "", line 321, in _call_with_frames_removed
File "/home/shaman/Work/Projects/ufanet_ru/configs/wsgi.py", line 16, in
application = get_wsgi_application()
File "/home/shaman/Work/envs/ufanet_ru/lib/python3.4/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application
return WSGIHandler()
File "/home/shaman/Work/envs/ufanet_ru/lib/python3.4/site-packages/django/core/handlers/wsgi.py", line 153, in init
self.load_middleware()
File "/home/shaman/Work/envs/ufanet_ru/lib/python3.4/site-packages/django/core/handlers/base.py", line 82, in load_middleware
mw_instance = middleware(handler)
TypeError: object() takes no parameters

For fix:

from django.utils.deprecation import MiddlewareMixin
from cuser.middleware import CuserMiddleware


class CuserCustomMiddleware(MiddlewareMixin, CuserMiddleware):
    pass

It's work!

Allow overwriting CurrentUserField value

This was a gotcha for me in switching to the library, the value is set on pre_save and does not allow manually setting a different value if needed. One could implement the option to read the current user on model initialization (see: https://github.com/PaesslerAG/django-currentuser/blob/master/django_currentuser/db/models/fields.py#L20).

Alternatively raise a warning if there is already a value set on a unsaved instance that gets overwritten to make the user aware of their value getting overwritten.

rename project

rename the project
echelon => cuser

And also it's not about just renaming the project
There are some couple of thing should be remove from the old fork, such as templates and template tags and couple of variable naming

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.