X-Git-Url: https://git.openstreetmap.org./osqa.git/blobdiff_plain/7f4982393567a5f6827c12a089363d91338f9f13..99d077e46d0eb3efd5e96a65f120e6e4b6197db0:/forum/views/meta.py diff --git a/forum/views/meta.py b/forum/views/meta.py index a0c5ced..513fd39 100644 --- a/forum/views/meta.py +++ b/forum/views/meta.py @@ -1,33 +1,34 @@ import os from itertools import groupby -from django.shortcuts import render_to_response, get_object_or_404 -from django.core.urlresolvers import reverse -from django.template import RequestContext, loader -from django.http import HttpResponseRedirect, HttpResponse, Http404 + +from django.shortcuts import render_to_response +from django.template import RequestContext +from django.http import HttpResponseRedirect, HttpResponse from django.views.static import serve +from django.views.decorators.cache import cache_page +from django.utils.translation import ugettext as _ +from django.utils.safestring import mark_safe + +from django.contrib import messages + from forum import settings -from forum.modules import decorate from forum.views.decorators import login_required from forum.forms import FeedbackForm -from django.core.urlresolvers import reverse -from django.utils.translation import ugettext as _ -from django.db.models import Count +from forum.modules import decorate from forum.forms import get_next_url from forum.models import Badge, Award, User, Page -from forum.badges.base import BadgesMeta from forum.http_responses import HttpResponseNotFound, HttpResponseIntServerError -from forum import settings from forum.utils.mail import send_template_email -from django.utils.safestring import mark_safe from forum.templatetags.extra_filters import or_preview + import decorators -import re, sys, logging, traceback +import logging, traceback def favicon(request): return HttpResponseRedirect(str(settings.APP_FAVICON)) def custom_css(request): - return HttpResponse(or_preview(settings.CUSTOM_CSS, request), mimetype="text/css") + return HttpResponse(or_preview(settings.CUSTOM_CSS, request), content_type="text/css") def static(request, title, content): return render_to_response('static.html', {'content' : content, 'title': title}, @@ -36,7 +37,7 @@ def static(request, title, content): def media(request, skin, path): response = serve(request, "%s/media/%s" % (skin, path), document_root=os.path.join(os.path.dirname(os.path.dirname(__file__)), 'skins').replace('\\', '/')) - content_type = response['Content-Type'] + content_type = response.get('Content-Type', '') if ('charset=' not in content_type): if (content_type.startswith('text') or content_type=='application/x-javascript'): content_type += '; charset=utf-8' @@ -47,7 +48,7 @@ def media(request, skin, path): def markdown_help(request): return render_to_response('markdown_help.html', context_instance=RequestContext(request)) - +@cache_page(60 * 60 * 24 * 30) #30 days def opensearch(request): return render_to_response('opensearch.html', {'settings' : settings}, context_instance=RequestContext(request)) @@ -68,7 +69,7 @@ def feedback(request): send_template_email(recipients, "notifications/feedback.html", context) msg = _('Thanks for the feedback!') - request.user.message_set.create(message=msg) + messages.info(request, msg) return HttpResponseRedirect(get_next_url(request)) else: form = FeedbackForm(request.user, initial={'next':get_next_url(request)}) @@ -88,10 +89,11 @@ def logout(request): @decorators.render('badges.html', 'badges', _('badges'), weight=300) def badges(request): - badges = [b.ondb for b in sorted(BadgesMeta.by_id.values(), lambda b1, b2: cmp(b1.name, b2.name))] + from forum.badges.base import BadgesMeta + badges = sorted([Badge.objects.get(id=id) for id in BadgesMeta.by_id.keys()], lambda b1, b2: cmp(b1.name, b2.name)) if request.user.is_authenticated(): - my_badges = Award.objects.filter(user=request.user).values('badge_id').distinct() + my_badges = Award.objects.filter(user=request.user).values_list('badge_id', flat=True).distinct() else: my_badges = [] @@ -144,7 +146,7 @@ def page(request): sidebar = mark_safe(sidebar) else: - return HttpResponse(page.body, mimetype=page.extra.get('mimetype', 'text/html')) + return HttpResponse(page.body, content_type=page.extra.get('mimetype', 'text/html')) render = page.extra.get('render', 'markdown')