Use get_user_profile_by_email more consistently.

The previous situation was bad for two reasons:

(1) It had a lot of copies of the code, some of them missing pieces:
  UserProfile.objects.get(user__email__iexact=foo)

This was in particular going to be inconvenient since we are dropping
the __user part of that.

(2) It didn't take advantage of our memcached caching.

(imported from commit 2325795f288a7cf306cdae191f5d3080aac0651a)
This commit is contained in:
Tim Abbott
2013-03-28 15:20:31 -04:00
parent 203e5e17ee
commit 198480ef99
21 changed files with 77 additions and 71 deletions

View File

@@ -1,6 +1,7 @@
from optparse import make_option
from django.core.management.base import BaseCommand
from zephyr.models import Realm, UserProfile, Message, UserMessage
from zephyr.models import Realm, UserProfile, Message, UserMessage, \
get_user_profile_by_email
from zephyr.lib.timestamp import datetime_to_timestamp, timestamp_to_datetime
import simplejson
@@ -18,7 +19,7 @@ def dump():
def restore(change):
for (email, timestamp) in simplejson.loads(file("dumped-pointers").read()):
try:
u = UserProfile.objects.get(user__email__iexact=email)
u = get_user_profile_by_email(email)
except UserProfile.DoesNotExist:
print "Skipping...", email
continue