<commit_before>#!/usr/bin/env python
# encoding: utf-8
"""
import_member_data.py

Created by <NAME> on 2010-06-18.
Copyright (c) 2010 Kapsi Internet-käyttäjät ry. All rights reserved.
"""

import sys
import os
from datetime import datetime, timedelta
from optparse import OptionParser

os.environ['DJANGO_SETTINGS_MODULE'] = 'sikteeri.settings'
sys.path.insert(0, '..')

from django.conf import settings
import logging
from membership.utils import log_change
from django.contrib.auth.models import User
from django.contrib.comments.models import Comment
from membership.views import contact_from_dict
from membership.models import Membership, Bill, BillingCycle, Fee, MEMBER_TYPES

user = User.objects.get(id=1)

# MEMBER_TYPES = (('P', _('Person')),
#                 ('S', _('Supporting')),
#                 ('O', _('Organization')))

def create_member(mdata):
    # legacy fields
    # ['application_id', 'sendinfo', 'memberclass', 'applicationtime', 'sms',
    # 'id', 'email', 'website', 'publicwebsite', 'lastname', 'phone',
    # 'firstnames', 'address', 'nationality', 'post', 'removed', 'publicname',
    # 'name', 'mobile', 'residence', 'time', 'publicemail', 'period_start',
    # 'period_end']
    # TODO: latest billing period start date?
    post_index = mdata['post'].find(' ')
    postcode = mdata['post'][:post_index]
    postoffice = mdata['post'][post_index+1:]
    d = {
        'street_address' : mdata['address'],
        'postal_code' : postcode,
        'post_office' : postoffice,
        'country' : mdata['nationality'],
        'phone' : mdata['phone'],
        'sms' : mdata['sms'],
        'email' : mdata['email'],
        'homepage' : mdata['website'],
        'first_name' : mdata['name'],
        'given_names' : mdata['firstnames'],
        'last_name' : mdata['lastname'],
        # mdata['application_id'],
        # mdata['sendinfo'],
    }

    # Hide non-public websites
    if not mdata['publicwebsite']:
        d['homepage'] = ""

    if not mdata['memberclass']:
        mtype = 'P'
        print "Member type missing for member %d" % mdata['id']
    elif mdata['memberclass'] == 'member':
        mtype = 'P'
    elif mdata['memberclass'] == 'supporting':
        mtype = 'S'
    else:
        print "Not importing, member class unknown for member %d" % mdata['id']
        return False
    person = contact_from_dict(d)
    person.save()
    membership = Membership(id=mdata['id'], type=mtype, status='A',
                            created=datetime.utcfromtimestamp(mdata['time']),<commit_msg>Fixed import_member_data after refactoring.<commit_after>#!/usr/bin/env python
# encoding: utf-8
"""
import_member_data.py

Created by <NAME> on 2010-06-18.
Copyright (c) 2010 Kapsi Internet-käyttäjät ry. All rights reserved.
"""

import sys
import os
from datetime import datetime, timedelta
from optparse import OptionParser

os.environ['DJANGO_SETTINGS_MODULE'] = 'sikteeri.settings'
sys.path.insert(0, '..')

from django.conf import settings
import logging
from membership.utils import log_change
from django.contrib.auth.models import User
from django.contrib.comments.models import Comment
from membership.models import Contact, Membership, Bill, BillingCycle
from membership.models import Fee, MEMBER_TYPES

user = User.objects.get(id=1)

# MEMBER_TYPES = (('P', _('Person')),
#                 ('S', _('Supporting')),
#                 ('O', _('Organization')))

def create_member(mdata):
    # legacy fields
    # ['application_id', 'sendinfo', 'memberclass', 'applicationtime', 'sms',
    # 'id', 'email', 'website', 'publicwebsite', 'lastname', 'phone',
    # 'firstnames', 'address', 'nationality', 'post', 'removed', 'publicname',
    # 'name', 'mobile', 'residence', 'time', 'publicemail', 'period_start',
    # 'period_end']
    # TODO: latest billing period start date?
    post_index = mdata['post'].find(' ')
    postcode = mdata['post'][:post_index]
    postoffice = mdata['post'][post_index+1:]
    d = {
        'street_address' : mdata['address'],
        'postal_code' : postcode,
        'post_office' : postoffice,
        'country' : mdata['nationality'],
        'phone' : mdata['phone'],
        'sms' : mdata['sms'],
        'email' : mdata['email'],
        'homepage' : mdata['website'],
        'first_name' : mdata['name'],
        'given_names' : mdata['firstnames'],
        'last_name' : mdata['lastname'],
        # mdata['application_id'],
        # mdata['sendinfo'],
    }

    # Hide non-public websites
    if not mdata['publicwebsite']:
        d['homepage'] = ""

    if not mdata['memberclass']:
        mtype = 'P'
        print "Member type missing for member %d" % mdata['id']
    elif mdata['memberclass'] == 'member':
        mtype = 'P'
    elif mdata['memberclass'] == 'supporting':
        mtype = 'S'
    else:
        print "Not importing, member class unknown for member %d" % mdata['id']
        return False
    person = Contact(**d)
    person.save()
    membership = Membership(id=mdata['id'], type=mtype, status='A',
                            created=datetime.utcfromtimestamp(mdata['time']),
{'fraction_non_alphanumeric': 0.1583284284873455, 'fraction_numerical': 0.006278202864430057, 'mean_word_length': 3.3461210571184994, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7125342', 'n_tokens_mistral': 1659, 'n_tokens_neox': 1605, 'n_words': 382}