Allow importing the old portal to be optional

This commit is contained in:
Tanner Collin 2020-01-23 06:54:34 +00:00
parent 6dcdeffa9e
commit c6182c8984
4 changed files with 15 additions and 7 deletions

View File

@ -3,8 +3,6 @@ from django.db import models
from django.contrib.auth.models import User
from django.utils.timezone import now
from . import old_models
IGNORE = '+'
class Member(models.Model):

View File

@ -6,10 +6,9 @@ from rest_framework.validators import UniqueValidator
from rest_auth.registration.serializers import RegisterSerializer
from rest_auth.serializers import UserDetailsSerializer
from . import models, old_models, fields, utils
from . import models, fields, utils
from .. import settings
class TransactionSerializer(serializers.ModelSerializer):
# fields directly from old portal. replace with slugs we want
account_type = serializers.ChoiceField([

View File

@ -7,7 +7,11 @@ from bleach.sanitizer import Cleaner
from django.db.models import Sum
from . import models, old_models
from . import models
try:
import old_models
except ModuleNotFoundError:
old_models = None
def num_months_spanned(d1, d2):
'''
@ -192,7 +196,14 @@ def link_old_member(data, user):
If a member claims they have an account on the old protospace portal,
go through and link their objects to their new user using the member_id
found with their email as a hint
Since this runs AFTER registration, we need to delete the user on any
failures or else the username will be taken when they try again
'''
if not old_models:
user.delete()
raise ValidationError(dict(email='Unable to link, old DB wasn\'t imported.'))
old_members = old_models.Members.objects.using('old_portal')
try:
@ -204,6 +215,7 @@ def link_old_member(data, user):
member = models.Member.objects.get(id=old_member.id)
if member.user:
user.delete()
raise ValidationError(dict(email='Old member already claimed.'))
member.user = user

View File

@ -4,7 +4,6 @@ django.setup()
import datetime
from apiserver.api import models, old_models, utils
from apiserver.api.serializers import process_image
MEMBER_FIELDS = [
'id',
@ -101,7 +100,7 @@ for o in old:
if str(o.id) in photo_folders:
folder = 'old_photos/' + str(o.id)
if 'photo.jpg' in os.listdir(folder):
small, medium, large = process_image(folder + '/photo.jpg')
small, medium, large = utils.process_image(folder + '/photo.jpg')
print('Found a photo')
models.Member.objects.create(photo_small=small, photo_medium=medium, photo_large=large, **new)