[bug 616535] Remove last bits of Tiki-related code.

This commit is contained in:
Paul Craciunoiu 2010-12-22 14:50:29 -08:00
Родитель c60cbdb39e
Коммит 973acf18c7
4 изменённых файлов: 0 добавлений и 154 удалений

Просмотреть файл

Просмотреть файл

Просмотреть файл

@ -1,119 +0,0 @@
from datetime import datetime
from optparse import make_option
import os
from django.conf import settings
from django.core.management.base import BaseCommand
from PIL import Image
from sumo.models import TikiUser
from sumo.utils import chunked
from upload.tasks import _scale_dimensions
from users.models import User, Profile
AVATAR_ROOT = os.path.join(settings.MEDIA_ROOT, settings.USER_AVATAR_PATH)
AVATAR_PATH = os.path.join(AVATAR_ROOT, 'avatar-%s.png')
AVATAR_URL = os.path.join(settings.USER_AVATAR_PATH, 'avatar-%s.png')
class Command(BaseCommand): #pragma: no cover
help = 'Migrate user avatars out of the database.'
option_list = BaseCommand.option_list + (
make_option('--start',
action='store',
type=int,
dest='start',
default=0,
help='Where to start.'),
make_option('--end',
action='store',
type=int,
dest='end',
default=None,
help='Where to end.'),
)
def handle(self, *args, **options):
print 'Writing avatars to %s' % AVATAR_PATH
start = options['start']
end = options['end']
print 'Starting at %s, going until %s' % (start, end)
# Grab all the known Tiki users.
users = TikiUser.objects.all().values_list('pk',
flat=True)[start:end]
# In case it doesn't exist.
if not os.path.exists(AVATAR_ROOT):
os.makedirs(AVATAR_ROOT)
total = 0
for chunk in chunked(users, 1000):
total += len(chunk)
print 'Processing %s users (%s total)' % (len(chunk),
total + start)
for pk in chunk:
# Load or create a Django user.
tu = TikiUser.objects.get(pk=pk)
try:
du = User.objects.get(username=tu.login)
except User.DoesNotExist:
du = User(username=tu.login,
email=tu.email,
password=tu.hash,
is_active=True,
date_joined=datetime.fromtimestamp(
tu.registrationDate))
du.save()
# Load or (usually) create a profile.
try:
profile = du.get_profile()
if profile.avatar: # Already has an avatar, skip it.
continue
except Profile.DoesNotExist:
profile = Profile.objects.create(user=du)
# Set livechat_id
profile.livechat_id = tu.livechat_id
# If the avatar already exists because we generated it ahead
# of time, just use it.
if os.path.exists(AVATAR_PATH % du.pk):
profile.avatar = AVATAR_PATH % du.pk
elif tu.avatarFileType and tu.avatarFileType.startswith('image'):
# What format is it currently in?
format = 'png'
if tu.avatarFileType == 'image/gif':
format = 'gif'
elif tu.avatarFileType == 'image/jpeg':
format = 'jpg'
# Write the avatar data to a file.
fname = '/tmp/avatar-%s.%s' % (pk, format)
with open(fname, 'wb') as fp:
fp.write(tu.avatarData)
try:
# Maybe resize, convert to PNG.
image = Image.open(fname)
# 48x48 is the size of all the avatars we've created.
size = _scale_dimensions(*image.size, longest_side=48)
avatar = image.resize(size, resample=1)
avatar.save(AVATAR_PATH % du.pk)
profile.avatar = AVATAR_URL % du.pk
except IOError:
pass # Couldn't read or write the image.
# Clean up.
os.unlink(fname)
profile.save()

Просмотреть файл

@ -19,38 +19,3 @@ class ModelBase(caching.base.CachingMixin, models.Model):
class Meta:
abstract = True
class TikiUser(ModelBase):
# TODO: Delete me!
class Meta:
db_table = 'users_users'
userId = models.AutoField(primary_key=True)
email = models.CharField(max_length=200, null=True)
login = models.CharField(max_length=200, unique=True)
password = models.CharField(max_length=30)
provpass = models.CharField(max_length=30)
default_group = models.CharField(max_length=30, null=True)
lastLogin = models.IntegerField(null=True)
currentLogin = models.IntegerField(null=True)
registrationDate = models.IntegerField(null=True)
challenge = models.CharField(max_length=32, null=True)
pass_confirm = models.IntegerField(null=True)
email_confirm = models.IntegerField(null=True)
hash = models.CharField(max_length=34, null=True)
created = models.IntegerField(null=True)
avatarName = models.CharField(max_length=80, null=True)
avatarSize = models.IntegerField(null=True)
avatarFileType = models.CharField(max_length=250, null=True)
avatarData = models.TextField(null=True)
avatarLibName = models.CharField(max_length=200, null=True)
avatarType = models.CharField(max_length=1, null=True)
score = models.IntegerField(default=0)
unsuccessful_logins = models.IntegerField(default=0)
valid = models.CharField(max_length=32, null=True)
openid_url = models.CharField(max_length=255, null=True)
livechat_id = models.CharField(max_length=255, null=True, unique=True)
def __unicode__(self):
return '%s: %s' % (self.userId, self.login)