diff --git a/django/contrib/admin/templatetags/admin_list.py b/django/contrib/admin/templatetags/admin_list.py index 8bc956154c..8d8d9f91e4 100644 --- a/django/contrib/admin/templatetags/admin_list.py +++ b/django/contrib/admin/templatetags/admin_list.py @@ -8,7 +8,7 @@ from django.utils import dateformat from django.utils.html import escape from django.utils.text import capfirst from django.utils.translation import get_date_formats -from django.conf.settings import ADMIN_MEDIA_PREFIX +from django.conf import settings from django.template import Library register = Library() @@ -148,7 +148,7 @@ def items_for_result(cl, result): # Booleans are special: We use images. elif isinstance(f, models.BooleanField) or isinstance(f, models.NullBooleanField): BOOLEAN_MAPPING = {True: 'yes', False: 'no', None: 'unknown'} - result_repr = '%s' % (ADMIN_MEDIA_PREFIX, BOOLEAN_MAPPING[field_val], field_val) + result_repr = '%s' % (settings.ADMIN_MEDIA_PREFIX, BOOLEAN_MAPPING[field_val], field_val) # ImageFields are special: Use a thumbnail. elif isinstance(f, models.ImageField): from django.parts.media.photos import get_thumbnail_url diff --git a/django/contrib/admin/templatetags/admin_modify.py b/django/contrib/admin/templatetags/admin_modify.py index fc8ce5d8a9..3b3d1d803c 100644 --- a/django/contrib/admin/templatetags/admin_modify.py +++ b/django/contrib/admin/templatetags/admin_modify.py @@ -8,7 +8,7 @@ from django.db.models.fields import BoundField, Field from django.db.models.related import BoundRelatedObject from django.db.models import TABULAR, STACKED from django.db import models -from django.conf.settings import ADMIN_MEDIA_PREFIX +from django.conf import settings import re register = template.Library() @@ -20,7 +20,7 @@ def class_name_to_underscored(name): #@register.simple_tag def include_admin_script(script_path): - return '' % (ADMIN_MEDIA_PREFIX, script_path) + return '' % (settings.ADMIN_MEDIA_PREFIX, script_path) include_admin_script = register.simple_tag(include_admin_script) #@register.inclusion_tag('admin/submit_line', takes_context=True) @@ -205,7 +205,7 @@ def filter_interface_script_maybe(bound_field): if f.rel and isinstance(f.rel, models.ManyToMany) and f.rel.filter_interface: return '\n' % ( - f.name, f.verbose_name, f.rel.filter_interface-1, ADMIN_MEDIA_PREFIX) + f.name, f.verbose_name, f.rel.filter_interface-1, settings.ADMIN_MEDIA_PREFIX) else: return '' filter_interface_script_maybe = register.simple_tag(filter_interface_script_maybe) diff --git a/django/contrib/admin/templatetags/adminmedia.py b/django/contrib/admin/templatetags/adminmedia.py index bebed4a84f..e786c9d953 100644 --- a/django/contrib/admin/templatetags/adminmedia.py +++ b/django/contrib/admin/templatetags/adminmedia.py @@ -3,8 +3,8 @@ register = Library() def admin_media_prefix(): try: - from django.conf.settings import ADMIN_MEDIA_PREFIX + from django.conf import settings except ImportError: return '' - return ADMIN_MEDIA_PREFIX -admin_media_prefix = register.simple_tag(admin_media_prefix) \ No newline at end of file + return settings.ADMIN_MEDIA_PREFIX +admin_media_prefix = register.simple_tag(admin_media_prefix) diff --git a/django/contrib/admin/views/decorators.py b/django/contrib/admin/views/decorators.py index 57ac6cd5a9..5eb9028a8e 100644 --- a/django/contrib/admin/views/decorators.py +++ b/django/contrib/admin/views/decorators.py @@ -1,6 +1,6 @@ from django.core.extensions import render_to_response from django.template import RequestContext -from django.conf.settings import SECRET_KEY +from django.conf import settings from django.contrib.auth.models import User, SESSION_KEY from django import http from django.utils.translation import gettext_lazy @@ -29,13 +29,13 @@ def _display_login_form(request, error_message=''): def _encode_post_data(post_data): pickled = pickle.dumps(post_data) - pickled_md5 = md5.new(pickled + SECRET_KEY).hexdigest() + pickled_md5 = md5.new(pickled + settings.SECRET_KEY).hexdigest() return base64.encodestring(pickled + pickled_md5) def _decode_post_data(encoded_data): encoded_data = base64.decodestring(encoded_data) pickled, tamper_check = encoded_data[:-32], encoded_data[-32:] - if md5.new(pickled + SECRET_KEY).hexdigest() != tamper_check: + if md5.new(pickled + settings.SECRET_KEY).hexdigest() != tamper_check: from django.core.exceptions import SuspiciousOperation raise SuspiciousOperation, "User may have tampered with session cookie." return pickle.loads(pickled) diff --git a/django/contrib/comments/models.py b/django/contrib/comments/models.py index f812d89ce8..22a4858241 100644 --- a/django/contrib/comments/models.py +++ b/django/contrib/comments/models.py @@ -3,6 +3,7 @@ from django.contrib.contenttypes.models import ContentType from django.contrib.sites.models import Site from django.contrib.auth.models import User from django.utils.translation import gettext_lazy as _ +from django.conf import settings import datetime MIN_PHOTO_DIMENSION = 5 @@ -26,9 +27,8 @@ class CommentManager(models.Manager): 'pa,ra') and target (something like 'lcom.eventtimes:5157'). Used to validate that submitted form options have not been tampered-with. """ - from django.conf.settings import SECRET_KEY import md5 - return md5.new(options + photo_options + rating_options + target + SECRET_KEY).hexdigest() + return md5.new(options + photo_options + rating_options + target + settings.SECRET_KEY).hexdigest() def get_rating_options(self, rating_string): """ @@ -53,11 +53,10 @@ class CommentManager(models.Manager): return self.get_list(**kwargs) def user_is_moderator(self, user): - from django.conf.settings import COMMENTS_MODERATORS_GROUP if user.is_superuser: return True for g in user.get_group_list(): - if g.id == COMMENTS_MODERATORS_GROUP: + if g.id == settings.COMMENTS_MODERATORS_GROUP: return True return False diff --git a/django/contrib/comments/templatetags/comments.py b/django/contrib/comments/templatetags/comments.py index 5c2b1dfae0..6fb3d2ee97 100644 --- a/django/contrib/comments/templatetags/comments.py +++ b/django/contrib/comments/templatetags/comments.py @@ -123,13 +123,13 @@ class CommentCountNode(template.Node): self.var_name, self.free = var_name, free def render(self, context): - from django.conf.settings import SITE_ID + from django.conf import settings get_count_function = self.free and FreeComment.objects.get_count or Comment.objects.get_count if self.context_var_name is not None: self.obj_id = template.resolve_variable(self.context_var_name, context) comment_count = get_count_function(object_id__exact=self.obj_id, content_type__package__label__exact=self.package, - content_type__python_module_name__exact=self.module, site__id__exact=SITE_ID) + content_type__python_module_name__exact=self.module, site__id__exact=settings.SITE_ID) context[self.var_name] = comment_count return '' @@ -142,7 +142,7 @@ class CommentListNode(template.Node): self.extra_kwargs = extra_kwargs or {} def render(self, context): - from django.conf.settings import COMMENTS_BANNED_USERS_GROUP, SITE_ID + from django.conf import settings get_list_function = self.free and FreeComment.objects.get_list or Comment.objects.get_list_with_karma if self.context_var_name is not None: try: @@ -153,13 +153,13 @@ class CommentListNode(template.Node): 'object_id__exact': self.obj_id, 'content_type__package__label__exact': self.package, 'content_type__python_module_name__exact': self.module, - 'site__id__exact': SITE_ID, + 'site__id__exact': settings.SITE_ID, 'select_related': True, 'order_by': (self.ordering + 'submit_date',), } kwargs.update(self.extra_kwargs) - if not self.free and COMMENTS_BANNED_USERS_GROUP: - kwargs['select'] = {'is_hidden': 'user_id IN (SELECT user_id FROM auth_users_groups WHERE group_id = %s)' % COMMENTS_BANNED_USERS_GROUP} + if not self.free and settings.COMMENTS_BANNED_USERS_GROUP: + kwargs['select'] = {'is_hidden': 'user_id IN (SELECT user_id FROM auth_users_groups WHERE group_id = %s)' % settings.COMMENTS_BANNED_USERS_GROUP} comment_list = get_list_function(**kwargs) if not self.free: @@ -170,7 +170,7 @@ class CommentListNode(template.Node): user_id = None context['user_can_moderate_comments'] = False # Only display comments by banned users to those users themselves. - if COMMENTS_BANNED_USERS_GROUP: + if settings.COMMENTS_BANNED_USERS_GROUP: comment_list = [c for c in comment_list if not c.is_hidden or (user_id == c.user_id)] context[self.var_name] = comment_list diff --git a/django/contrib/comments/views/comments.py b/django/contrib/comments/views/comments.py index 9cd2c0e83a..daa2a0ec7d 100644 --- a/django/contrib/comments/views/comments.py +++ b/django/contrib/comments/views/comments.py @@ -11,7 +11,7 @@ from django.contrib.contenttypes.models import ContentType from django.parts.auth.formfields import AuthenticationForm from django.http import HttpResponseRedirect from django.utils.text import normalize_newlines -from django.conf.settings import BANNED_IPS, COMMENTS_ALLOW_PROFANITIES, COMMENTS_SKETCHY_USERS_GROUP, COMMENTS_FIRST_FEW, SITE_ID +from django.conf import settings from django.utils.translation import ngettext import base64, datetime @@ -72,7 +72,7 @@ class PublicCommentManipulator(AuthenticationForm): self.user_cache = user def hasNoProfanities(self, field_data, all_data): - if COMMENTS_ALLOW_PROFANITIES: + if settings.COMMENTS_ALLOW_PROFANITIES: return return validators.hasNoProfanities(field_data, all_data) @@ -85,7 +85,7 @@ class PublicCommentManipulator(AuthenticationForm): new_data.get("rating4", None), new_data.get("rating5", None), new_data.get("rating6", None), new_data.get("rating7", None), new_data.get("rating8", None), new_data.get("rating1", None) is not None, - datetime.datetime.now(), new_data["is_public"], new_data["ip_address"], False, SITE_ID) + datetime.datetime.now(), new_data["is_public"], new_data["ip_address"], False, settings.SITE_ID) def save(self, new_data): today = datetime.date.today() @@ -108,12 +108,12 @@ class PublicCommentManipulator(AuthenticationForm): c.save() # If the commentor has posted fewer than COMMENTS_FIRST_FEW comments, # send the comment to the managers. - if self.user_cache.get_comments_comment_count() <= COMMENTS_FIRST_FEW: + if self.user_cache.get_comments_comment_count() <= settings.COMMENTS_FIRST_FEW: message = ngettext('This comment was posted by a user who has posted fewer than %(count)s comment:\n\n%(text)s', 'This comment was posted by a user who has posted fewer than %(count)s comments:\n\n%(text)s') % \ - {'count': COMMENTS_FIRST_FEW, 'text': c.get_as_text()} + {'count': settings.COMMENTS_FIRST_FEW, 'text': c.get_as_text()} mail_managers("Comment posted by rookie user", message) - if COMMENTS_SKETCHY_USERS_GROUP and COMMENTS_SKETCHY_USERS_GROUP in [g.id for g in self.user_cache.get_group_list()]: + if settings.COMMENTS_SKETCHY_USERS_GROUP and settings.COMMENTS_SKETCHY_USERS_GROUP in [g.id for g in self.user_cache.get_group_list()]: message = _('This comment was posted by a sketchy user:\n\n%(text)s') % {'text': c.get_as_text()} mail_managers("Comment posted by sketchy user (%s)" % self.user_cache.username, c.get_as_text()) return c @@ -129,7 +129,7 @@ class PublicFreeCommentManipulator(forms.Manipulator): ) def hasNoProfanities(self, field_data, all_data): - if COMMENTS_ALLOW_PROFANITIES: + if settings.COMMENTS_ALLOW_PROFANITIES: return return validators.hasNoProfanities(field_data, all_data) @@ -138,7 +138,7 @@ class PublicFreeCommentManipulator(forms.Manipulator): return FreeComment(None, new_data["content_type_id"], new_data["object_id"], new_data["comment"].strip(), new_data["person_name"].strip(), datetime.datetime.now(), new_data["is_public"], - new_data["ip_address"], False, SITE_ID) + new_data["ip_address"], False, settings.SITE_ID) def save(self, new_data): today = datetime.date.today() @@ -247,7 +247,7 @@ def post_comment(request): elif request.POST.has_key('post'): # If the IP is banned, mail the admins, do NOT save the comment, and # serve up the "Thanks for posting" page as if the comment WAS posted. - if request.META['REMOTE_ADDR'] in BANNED_IPS: + if request.META['REMOTE_ADDR'] in settings.BANNED_IPS: mail_admins("Banned IP attempted to post comment", str(request.POST) + "\n\n" + str(request.META)) else: manipulator.do_html2python(new_data) @@ -310,7 +310,7 @@ def post_free_comment(request): elif request.POST.has_key('post'): # If the IP is banned, mail the admins, do NOT save the comment, and # serve up the "Thanks for posting" page as if the comment WAS posted. - if request.META['REMOTE_ADDR'] in BANNED_IPS: + if request.META['REMOTE_ADDR'] in settings.BANNED_IPS: from django.core.mail import mail_admins mail_admins("Practical joker", str(request.POST) + "\n\n" + str(request.META)) else: diff --git a/django/contrib/comments/views/userflags.py b/django/contrib/comments/views/userflags.py index cc58fc3327..3132926898 100644 --- a/django/contrib/comments/views/userflags.py +++ b/django/contrib/comments/views/userflags.py @@ -4,7 +4,7 @@ from django.http import Http404 from django.models.comments import comments, moderatordeletions, userflags from django.views.decorators.auth import login_required from django.http import HttpResponseRedirect -from django.conf.settings import SITE_ID +from django.conf import settings def flag(request, comment_id): """ @@ -16,7 +16,7 @@ def flag(request, comment_id): the flagged `comments.comments` object """ try: - comment = comments.get_object(pk=comment_id, site__id__exact=SITE_ID) + comment = comments.get_object(pk=comment_id, site__id__exact=settings.SITE_ID) except comments.CommentDoesNotExist: raise Http404 if request.POST: @@ -27,7 +27,7 @@ flag = login_required(flag) def flag_done(request, comment_id): try: - comment = comments.get_object(pk=comment_id, site__id__exact=SITE_ID) + comment = comments.get_object(pk=comment_id, site__id__exact=settings.SITE_ID) except comments.CommentDoesNotExist: raise Http404 return render_to_response('comments/flag_done', {'comment': comment}, context_instance=RequestContext(request)) @@ -42,7 +42,7 @@ def delete(request, comment_id): the flagged `comments.comments` object """ try: - comment = comments.get_object(pk=comment_id, site__id__exact=SITE_ID) + comment = comments.get_object(pk=comment_id, site__id__exact=settings.SITE_ID) except comments.CommentDoesNotExist: raise Http404 if not comments.user_is_moderator(request.user): @@ -60,7 +60,7 @@ delete = login_required(delete) def delete_done(request, comment_id): try: - comment = comments.get_object(pk=comment_id, site__id__exact=SITE_ID) + comment = comments.get_object(pk=comment_id, site__id__exact=settings.SITE_ID) except comments.CommentDoesNotExist: raise Http404 return render_to_response('comments/delete_done', {'comment': comment}, context_instance=RequestContext(request))