magic-removal: Fixed various breakage due to removal of magic modules. Several bits of calling code still use magic modules.

git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@1642 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2005-12-14 07:02:42 +00:00
parent a5489c964e
commit 9027ed6ea6
6 changed files with 20 additions and 21 deletions

View File

@ -1,6 +1,6 @@
from django.core.extensions import DjangoContext, render_to_response
from django.conf.settings import SECRET_KEY
from django.models.auth import users
from django.models.auth import User, SESSION_KEY
from django.utils import httpwrappers
import base64, md5
import cPickle as pickle
@ -66,14 +66,14 @@ def staff_member_required(view_func):
# Check the password.
username = request.POST.get('username', '')
try:
user = users.get_object(username__exact=username, is_staff__exact=True)
except users.UserDoesNotExist:
user = User.objects.get_object(username__exact=username, is_staff__exact=True)
except User.DoesNotExist:
message = ERROR_MESSAGE
if '@' in username:
# Mistakenly entered e-mail address instead of username? Look it up.
try:
user = users.get_object(email__exact=username)
except users.UserDoesNotExist:
user = User.objects.get_object(email__exact=username)
except User.DoesNotExist:
message = _("Usernames cannot contain the '@' character.")
else:
message = _("Your e-mail address is not your username. Try '%s' instead.") % user.username
@ -82,7 +82,7 @@ def staff_member_required(view_func):
# The user data is correct; log in the user in and continue.
else:
if user.check_password(request.POST.get('password', '')):
request.session[users.SESSION_KEY] = user.id
request.session[SESSION_KEY] = user.id
if request.POST.has_key('post_data'):
post_data = _decode_post_data(request.POST['post_data'])
if post_data and not post_data.has_key(LOGIN_FORM_KEY):

View File

@ -2,7 +2,7 @@ from django.core import formfields, validators
from django.core.mail import mail_admins, mail_managers
from django.core.exceptions import Http404, ObjectDoesNotExist
from django.core.extensions import DjangoContext, render_to_response
from django.models.auth import users
from django.models.auth import SESSION_KEY
from django.models.comments import comments, freecomments
from django.models.core import contenttypes
from django.parts.auth.formfields import AuthenticationForm
@ -216,7 +216,7 @@ def post_comment(request):
# If user gave correct username/password and wasn't already logged in, log them in
# so they don't have to enter a username/password again.
if manipulator.get_user() and new_data.has_key('password') and manipulator.get_user().check_password(new_data['password']):
request.session[users.SESSION_KEY] = manipulator.get_user_id()
request.session[SESSION_KEY] = manipulator.get_user_id()
if errors or request.POST.has_key('preview'):
class CommentFormWrapper(formfields.FormWrapper):
def __init__(self, manipulator, new_data, errors, rating_choices):

View File

@ -1,6 +1,6 @@
from django.core.exceptions import ImproperlyConfigured, ObjectDoesNotExist
from django.core.template import Context, loader, Template, TemplateDoesNotExist
from django.models.core import sites
from django.models.core import Site
from django.utils import feedgenerator
from django.conf.settings import LANGUAGE_CODE, SETTINGS_MODULE
@ -52,7 +52,7 @@ class Feed:
else:
obj = None
current_site = sites.get_current()
current_site = Site.objects.get_current()
link = self.__get_dynamic_attr('link', obj)
link = add_domain(current_site.domain, link)

View File

@ -97,13 +97,13 @@ class ModPythonRequest(httpwrappers.HttpRequest):
def _get_user(self):
if not hasattr(self, '_user'):
from django.models.auth import users
from django.models.auth import User, SESSION_KEY
try:
user_id = self.session[users.SESSION_KEY]
user_id = self.session[SESSION_KEY]
if not user_id:
raise ValueError
self._user = users.get_object(pk=user_id)
except (AttributeError, KeyError, ValueError, users.UserDoesNotExist):
self._user = User.objects.get_object(pk=user_id)
except (AttributeError, KeyError, ValueError, user.DoesNotExist):
from django.parts.auth import anonymoususers
self._user = anonymoususers.AnonymousUser()
return self._user

View File

@ -118,13 +118,13 @@ class WSGIRequest(httpwrappers.HttpRequest):
def _get_user(self):
if not hasattr(self, '_user'):
from django.models.auth import users
from django.models.auth import User, SESSION_KEY
try:
user_id = self.session[users.SESSION_KEY]
user_id = self.session[SESSION_KEY]
if not user_id:
raise ValueError
self._user = users.get_object(pk=user_id)
except (AttributeError, KeyError, ValueError, users.UserDoesNotExist):
self._user = User.objects.get_object(pk=user_id)
except (AttributeError, KeyError, ValueError, user.DoesNotExist):
from django.parts.auth import anonymoususers
self._user = anonymoususers.AnonymousUser()
return self._user

View File

@ -3,6 +3,8 @@ from django.db import models
from django.models import core
from django.utils.translation import gettext_lazy as _
SESSION_KEY = '_auth_user_id'
class Permission(models.Model):
name = models.CharField(_('name'), maxlength=50)
package = models.ForeignKey(core.Package, db_column='package')
@ -47,9 +49,6 @@ class User(models.Model):
class META:
verbose_name = _('User')
verbose_name_plural = _('Users')
module_constants = {
'SESSION_KEY': '_auth_user_id',
}
ordering = ('username',)
exceptions = ('SiteProfileNotAvailable',)
admin = models.Admin(