switch from deprecated get_model a app registry

pull/1/head
eric 2016-07-24 18:39:36 -04:00
parent da7b3171ce
commit 09fe1a5d32
10 changed files with 57 additions and 41 deletions

View File

@ -1,4 +1,4 @@
from django.db.models import get_model
from django.apps import apps
from regluit.core import cc
@ -8,7 +8,7 @@ class BaseFacet(object):
def __init__(self, outer_facet):
self.outer_facet = outer_facet if outer_facet else None
self.model = get_model('core', 'Work')
self.model = apps.get_model('core', 'Work')
def _get_query_set(self):
if self.outer_facet:
@ -221,7 +221,7 @@ class PublisherFacetGroup(FacetGroup):
self.facet_name=facet_name
# facet_names of the form 'pub.PUB_ID' and PUB_ID is therefore the 5th character on
self.pub_id=self.facet_name[4:]
pubmodel = get_model('core', 'Publisher')
pubmodel = apps.get_model('core', 'Publisher')
try:
self.publisher = pubmodel.objects.get(id=self.pub_id)
except pubmodel.DoesNotExist:

View File

@ -25,6 +25,7 @@ from tempfile import SpooledTemporaryFile
'''
django imports
'''
from django.apps import apps
from django.conf import settings
from django.contrib.auth.models import User
from django.contrib.sites.models import Site
@ -32,7 +33,7 @@ from django.contrib.contenttypes.generic import GenericRelation
from django.core.urlresolvers import reverse
from django.core.files.base import ContentFile
from django.db import models
from django.db.models import F, Q, get_model
from django.db.models import F, Q
from django.db.models.signals import post_save, pre_delete
from django.utils.translation import ugettext_lazy as _
'''
@ -206,11 +207,11 @@ class Premium(models.Model):
@property
def premium_count(self):
t_model=get_model('payment','Transaction')
t_model=apps.get_model('payment','Transaction')
return t_model.objects.filter(premium=self).count()
@property
def premium_remaining(self):
t_model=get_model('payment','Transaction')
t_model=apps.get_model('payment','Transaction')
return self.limit - t_model.objects.filter(premium=self).count()
def __unicode__(self):
return (self.campaign.work.title if self.campaign else '') + ' $' + str(self.amount)

View File

@ -12,10 +12,11 @@ django imports
"""
import django.dispatch
from django.apps import apps
from django.conf import settings
from django.contrib.auth.models import User
from django.contrib.sites.models import Site
from django.db.models import get_model, signals
from django.db.models import signals
from django.db.models.signals import post_save
from django.db.utils import DatabaseError
from django.dispatch import Signal
@ -41,8 +42,8 @@ def create_user_objects(sender, created, instance, **kwargs):
# don't create Wishlist or UserProfile if we are loading fixtures http://stackoverflow.com/a/3500009/7782
if not kwargs.get('raw', False):
try:
Wishlist = get_model('core', 'Wishlist')
UserProfile = get_model('core', 'UserProfile')
Wishlist = apps.get_model('core', 'Wishlist')
UserProfile = apps.get_model('core', 'UserProfile')
if created:
Wishlist.objects.create(user=instance)
profile = UserProfile.objects.create(user=instance)
@ -164,7 +165,7 @@ def handle_transaction_charged(sender,transaction=None, **kwargs):
notification.send([transaction.user], "pledge_charged", context, True)
elif transaction.campaign.type is BUY2UNGLUE:
# provision the book
Acq = get_model('core', 'Acq')
Acq = apps.get_model('core', 'Acq')
if transaction.offer.license == LIBRARY:
library = Library.objects.get(id=transaction.extra['library_id'])
new_acq = Acq.objects.create(user=library.user,work=transaction.campaign.work,license= LIBRARY)
@ -178,7 +179,7 @@ def handle_transaction_charged(sender,transaction=None, **kwargs):
else:
if transaction.extra.get('give_to', False):
# it's a gift!
Gift = get_model('core', 'Gift')
Gift = apps.get_model('core', 'Gift')
giftee = Gift.giftee(transaction.extra['give_to'], str(transaction.id))
new_acq = Acq.objects.create(user=giftee, work=transaction.campaign.work, license= transaction.offer.license)
gift = Gift.objects.create(acq=new_acq, message=transaction.extra.get('give_message',''), giver=transaction.user , to = transaction.extra['give_to'])
@ -194,7 +195,7 @@ def handle_transaction_charged(sender,transaction=None, **kwargs):
transaction.campaign.update_status(send_notice=True)
elif transaction.campaign.type is THANKS:
if transaction.user:
Acq = get_model('core', 'Acq')
Acq = apps.get_model('core', 'Acq')
new_acq = Acq.objects.create(user=transaction.user, work=transaction.campaign.work, license=THANKED)
notification.send([transaction.user], "purchase_complete", context, True)
elif transaction.receipt:

View File

@ -23,6 +23,7 @@ from tastypie.models import ApiKey
django imports
'''
from django import forms
from django.apps import apps
from django.conf import settings
from django.contrib import messages
from django.contrib.admin.views.decorators import staff_member_required
@ -38,7 +39,7 @@ from django.core.files.temp import NamedTemporaryFile
from django.core.mail import EmailMessage
from django.core.urlresolvers import reverse, reverse_lazy
from django.core.validators import validate_email
from django.db.models import Q, Count, Sum, get_model
from django.db.models import Q, Count, Sum
from django.forms import Select
from django.forms.models import modelformset_factory, inlineformset_factory
from django.http import (
@ -2379,7 +2380,7 @@ class InfoPageView(TemplateView):
transactions.month.sum = transactions.month.aggregate(Sum('amount'))['amount__sum']
transactions.yesterday = transactions.filter(date_created__range = (date_today()-timedelta(days=1), date_today()))
transactions.yesterday.sum = transactions.yesterday.aggregate(Sum('amount'))['amount__sum']
marc = get_model('marc','MARCRecord').objects
marc = apps.get_model('marc','MARCRecord').objects
marc.today = marc.filter(created__range = (date_today(), now()))
marc.days7 = marc.filter(created__range = (date_today()-timedelta(days=7), now()))
marc.year = marc.filter(created__year = date_today().year)

View File

@ -3,6 +3,7 @@ import logging
from datetime import datetime
from StringIO import StringIO
from django.apps import apps
from django.conf import settings
from django.db import models
@ -205,7 +206,7 @@ class MARCRecord(models.Model):
def import_records(marcfile):
class RecordLoader(pymarc.XmlHandler):
Edition = models.get_model(*EDITION_MODEL.split('.'))
Edition = apps.get_model(*EDITION_MODEL.split('.'))
num_loaded=0
def process_record(self, record):
try:

View File

@ -3,7 +3,7 @@ django imports
"""
from django.test import TestCase
from django.test.client import Client
from django.db.models import get_model
from django.apps import apps
"""
regluit imports
@ -102,9 +102,9 @@ class MarcTests(TestCase):
work_id=None
def test_records(self):
w = get_model('core','Work').objects.create(title="Work 1")
e = get_model('core','Edition').objects.create(title=w.title,work=w)
eb = get_model('core','Ebook').objects.create(url = "http://example.org",edition = e,format = 'epub', rights='CC BY')
w = apps.get_model('core','Work').objects.create(title="Work 1")
e = apps.get_model('core','Edition').objects.create(title=w.title,work=w)
eb = apps.get_model('core','Ebook').objects.create(url = "http://example.org",edition = e,format = 'epub', rights='CC BY')
mr = models.MARCRecord.objects.create(guts=a_marc_record, edition=e )
@ -119,8 +119,8 @@ class MarcTests(TestCase):
e.set_publisher('test pub')
e.publication_date = '2000'
e.add_author('joe writer')
id = get_model('core','Identifier').objects.create(work=w,edition=e, type='isbn', value='0030839939')
id = get_model('core','Identifier').objects.create(work=w,edition=e, type='oclc', value='0074009772')
id = apps.get_model('core','Identifier').objects.create(work=w,edition=e, type='isbn', value='0030839939')
id = apps.get_model('core','Identifier').objects.create(work=w,edition=e, type='oclc', value='0074009772')
load.stub(e)

View File

@ -1,9 +1,9 @@
from datetime import datetime
from xml.sax import SAXParseException
from django.apps import apps
from django.contrib import messages
from django.core.urlresolvers import reverse, reverse_lazy
from django.db.models import get_model
from django.http import HttpResponseRedirect, HttpResponse, HttpResponseNotFound
from django.views.generic.edit import FormView
@ -18,7 +18,7 @@ PREAMBLE = ('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>'
'http://www.loc.gov/standards/marcxml/schema/'
'MARC21slim.xsd">')
Edition = get_model(*models.EDITION_MODEL.split('.'))
Edition = apps.get_model(*models.EDITION_MODEL.split('.'))
def marc_records(request, selected_records=None):

View File

@ -11,9 +11,9 @@ pledge_created = Signal(providing_args=["transaction"]) # should really be calle
pledge_modified = Signal(providing_args=["transaction", "up_or_down"])
credit_balance_added = Signal(providing_args=["amount"])
from django.apps import apps
from django.db.models.signals import post_save
from django.db.utils import DatabaseError
from django.db.models import get_model
from django.contrib.auth.models import User
# create Credit to associate with User
@ -22,7 +22,7 @@ def create_user_objects(sender, created, instance, **kwargs):
# don't create Credit if we are loading fixtures http://stackoverflow.com/a/3500009/7782
if not kwargs.get('raw', False):
try:
Credit = get_model('payment', 'Credit')
Credit = apps.get_model('payment', 'Credit')
if created:
Credit.objects.create(user=instance)
except DatabaseError:

View File

@ -106,7 +106,7 @@ class EpubTests(unittest.TestCase):
epub.close()
epub=EPUB(f,mode='r')
self.assertEqual(len(epub.opf),4)
self.assertEqual(len(epub.opf[0]),5) #metadata items
self.assertEqual(len(epub.opf[0]),6) #metadata items
self.assertEqual(len(epub.opf[1]),2) #manifest items
self.assertEqual(len(epub.opf[2]),1) #spine items
self.assertEqual(len(epub.opf[3]),0) #guide items

View File

@ -1,8 +1,8 @@
Django==1.8.14
Fabric==1.6.0
MySQL-python==1.2.3
MySQL-python==1.2.5
Pillow==2.5.3
PyJWT==1.1.0
PyJWT==1.4.1
PyPDF2==1.23
PyGithub==1.15.0
PyYAML==3.11
@ -14,10 +14,10 @@ amqp==1.4.9
anyjson==0.3.3
billiard==3.3.0.23
awscli==1.10.26
boto==2.8.0
boto==2.42.0
#git+ssh://git@github.com/Gluejar/boto.git@2.3.0
celery==3.1.23
certifi==2015.04.28
certifi==2016.2.28
# pip installing pillow seems to delete distribute
# but having distribute in requirements starting to cause problems
# distribute==0.6.28
@ -29,18 +29,18 @@ django-compat==1.0.10
django-contrib-comments==1.7.1
django-endless-pagination==2.0
django-extensions==1.6.1
django-jsonfield==0.9.10
django-jsonfield==1.0.0
#django-kombu==0.9.4
django-maintenancemode==0.10
django-mptt==0.7.4
django-mptt==0.8.5
django-nose-selenium==0.7.3
#django-notification==0.2
git+git://github.com/eshellman/django-notification.git@412c7a03a327195a1017c2be92c8e2caabc880b6
django-registration==2.1.1
django-selectable==0.9.0
django-smtp-ssl==1.0
django-storages==1.1.6
django-tastypie==0.12.2
django-storages==1.4.1
django-tastypie==0.13.3
django-transmeta==0.7.3
feedparser==5.1.2
freebase==1.0.8
@ -57,24 +57,24 @@ mechanize==0.2.5
mimeparse==0.1.3
nose==1.1.2
oauth2==1.5.211
oauthlib==0.7.2
oauthlib==1.1.2
paramiko==1.14.1
postmonkey==1.0b
pyasn1==0.1.4
pycrypto==2.6
pymarc==3.0.2
pyparsing==2.0.3
python-dateutil==2.1
python-dateutil==2.5.3
python-mimeparse==0.1.4
python-openid==2.2.5
python-social-auth==0.2.6
pytz==2012d
python-social-auth==0.2.19
pytz==2016.6.1
rdflib==4.2.0
rdflib-jsonld==0.3
redis==2.10.3
reportlab==3.1.8
requests==2.7.0
requests-oauthlib==0.4.2
requests==2.10.0
requests-oauthlib==0.6.2
selenium==2.53.1
six==1.9.0
sorl-thumbnail==12.3
@ -85,4 +85,16 @@ virtualenv==1.4.9
# virtualenv-clone==0.2.4 not sure why I have this in my env
#virtualenvwrapper==3.6
wsgiref==0.1.2
xhtml2pdf==0.0.6
xhtml2pdf==0.0.6
#for urllib3 secure
cffi==1.7.0
cryptography==1.4
enum34==1.1.6
idna==2.1
ipaddress==1.0.16
ndg-httpsclient==0.4.2
pyOpenSSL==16.0.0
pyasn1==0.1.9
pycparser==2.14
setuptools==25.0.0
urllib3==1.16