Mercurial > public > sg101
comparison comments/views.py @ 1206:02181fa5ac9d modernize tip
Update to Django 1.9.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Wed, 22 Jan 2025 17:58:16 -0600 |
parents | 110bbc78a482 |
children |
comparison
equal
deleted
inserted
replaced
1205:510ef3cbf3e6 | 1206:02181fa5ac9d |
---|---|
1 """ | 1 """ |
2 Views for the comments application. | 2 Views for the comments application. |
3 | 3 |
4 """ | 4 """ |
5 from django.apps import apps | |
5 from django.contrib.auth.decorators import login_required | 6 from django.contrib.auth.decorators import login_required |
6 from django.core.exceptions import ObjectDoesNotExist | 7 from django.core.exceptions import ObjectDoesNotExist |
7 from django.http import HttpResponse | 8 from django.http import HttpResponse |
8 from django.http import HttpResponseBadRequest | 9 from django.http import HttpResponseBadRequest |
9 from django.http import HttpResponseForbidden | 10 from django.http import HttpResponseForbidden |
10 from django.db.models import get_model | |
11 from django.shortcuts import render | 11 from django.shortcuts import render |
12 from django.utils.html import escape | 12 from django.utils.html import escape |
13 from django.views.decorators.http import require_POST | 13 from django.views.decorators.http import require_POST |
14 | 14 |
15 from core.functions import email_admins | 15 from core.functions import email_admins |
49 object_pk = request.POST.get('object_pk', None) | 49 object_pk = request.POST.get('object_pk', None) |
50 if ctype is None or object_pk is None: | 50 if ctype is None or object_pk is None: |
51 return HttpResponseBadRequest('Missing content_type or object_pk field.') | 51 return HttpResponseBadRequest('Missing content_type or object_pk field.') |
52 | 52 |
53 try: | 53 try: |
54 model = get_model(*ctype.split('.', 1)) | 54 model = apps.get_model(*ctype.split('.', 1)) |
55 target = model.objects.get(pk=object_pk) | 55 target = model.objects.get(pk=object_pk) |
56 except TypeError: | 56 except TypeError: |
57 return HttpResponseBadRequest( | 57 return HttpResponseBadRequest( |
58 "Invalid content_type value: %r" % escape(ctype)) | 58 "Invalid content_type value: %r" % escape(ctype)) |
59 except AttributeError: | 59 except AttributeError: |