Exemplo n.º 1
0
def create_dummy_member(status, type='P', mid=None):
    if status not in ['N', 'P', 'A']:
        raise Exception("Unknown membership status")  # pragma: no cover
    if type not in ['P', 'S', 'O', 'H']:
        raise Exception("Unknown membership type")  # pragma: no cover
    i = random.randint(1, 300)
    fname = random_first_name()
    d = {
        'street_address': 'Testikatu %d' % i,
        'postal_code': '%d' % (i + 1000),
        'post_office': 'Paska kaupunni',
        'country': 'Finland',
        'phone': "%09d" % (40123000 + i),
        'sms': "%09d" % (40123000 + i),
        'email': '*****@*****.**' % i,
        'homepage': 'http://www.example.com/%d' % i,
        'first_name': fname,
        'given_names': '%s %s' % (fname, "Kapsi"),
        'last_name': random_last_name(),
    }
    contact = Contact(**d)
    contact.save()
    if type == 'O':
        contact.organization_name = contact.name()
        contact.first_name = u''
        contact.last_name = u''
        contact.save()
        membership = Membership(
            id=mid,
            type=type,
            status=status,
            organization=contact,
            nationality='Finnish',
            municipality='Paska kaupunni',
            extra_info='Hintsunlaisesti semmoisia tietoja.')
    else:
        membership = Membership(
            id=mid,
            type=type,
            status=status,
            person=contact,
            nationality='Finnish',
            municipality='Paska kaupunni',
            extra_info='Hintsunlaisesti semmoisia tietoja.')
    logger.info("New application %s from %s:." % (str(contact), '::1'))
    membership.save()
    return membership
Exemplo n.º 2
0
def create_dummy_member(status, type='P', mid=None):
    if status not in ['N', 'P', 'A']:
        raise Exception("Unknown membership status")  # pragma: no cover
    if type not in ['P', 'S', 'O', 'H']:
        raise Exception("Unknown membership type")  # pragma: no cover
    i = random.randint(1, 300)
    fname = random_first_name()
    d = {
        'street_address' : 'Testikatu %d'%i,
        'postal_code' : '%d' % (i+1000),
        'post_office' : 'Paska kaupunni',
        'country' : 'Finland',
        'phone' : "%09d" % (40123000 + i),
        'sms' : "%09d" % (40123000 + i),
        'email' : '*****@*****.**' % i,
        'homepage' : 'http://www.example.com/%d'%i,
        'first_name' : fname,
        'given_names' : '%s %s' % (fname, "Kapsi"),
        'last_name' : random_last_name(),
    }
    contact = Contact(**d)
    contact.save()
    if type == 'O':
        contact.organization_name = contact.name()
        contact.first_name = u''
        contact.last_name = u''
        contact.save()
        membership = Membership(id=mid, type=type, status=status,
                                organization=contact,
                                nationality='Finnish',
                                municipality='Paska kaupunni',
                                extra_info='Hintsunlaisesti semmoisia tietoja.')
    else:
        membership = Membership(id=mid, type=type, status=status,
                                person=contact,
                                nationality='Finnish',
                                municipality='Paska kaupunni',
                                extra_info='Hintsunlaisesti semmoisia tietoja.')
    logger.info("New application %s from %s:." % (str(contact), '::1'))
    membership.save()
    return membership
Exemplo n.º 3
0
    def create_dummy_member(self, i, duplicate_of=None):
        fname = random_first_name()
        d = {
            'street_address' : 'Testikatu %d'%i,
            'postal_code' : '%d' % (i+1000),
            'post_office' : 'Paska kaupunni',
            'country' : 'Finland',
            'phone' : "%09d" % (40123000 + i),
            'sms' : "%09d" % (40123000 + i),
            'email' : '*****@*****.**' % i,
            'homepage' : 'http://www.example.com/%d'%i,
            'first_name' : fname,
            'given_names' : '%s %s' % (fname, "Kapsi"),
            'last_name' : random_last_name(),
        }

        if duplicate_of is not None:
            d['first_name'] = duplicate_of.person.first_name
            d['last_name'] = duplicate_of.person.last_name

        person = Contact(**d)
        person.save()
        membership = Membership(type='P', status='N',
                                person=person,
                                nationality='Finnish',
                                municipality='Paska kaupunni',
                                extra_info='Hintsunlaisesti semmoisia tietoja.')

        self.stdout.write(unicode(person))
        membership.save()

        forward_alias = Alias(owner=membership,
                              name=Alias.email_forwards(membership)[0])
        forward_alias.save()


        login_alias = Alias(owner=membership, account=True,
                            name=choice(Alias.unix_logins(membership)))
        login_alias.save()

        # Services
        forward_alias_service = Service(servicetype=ServiceType.objects.get(servicetype='Email alias'),
                                        alias=forward_alias, owner=membership, data=forward_alias.name)
        forward_alias_service.save()

        unix_account_service = Service(servicetype=ServiceType.objects.get(servicetype='UNIX account'),
                                       alias=login_alias, owner=membership, data=login_alias.name)
        unix_account_service.save()

        if random() < 0.6:
            mysql_service = Service(servicetype=ServiceType.objects.get(servicetype='MySQL database'),
                                    alias=login_alias, owner=membership, data=login_alias.name.replace('-', '_'))
            mysql_service.save()
        if random() < 0.6:
            postgresql_service = Service(servicetype=ServiceType.objects.get(servicetype='PostgreSQL database'),
                                         alias=login_alias, owner=membership, data=login_alias.name)
            postgresql_service.save()
        # End of services

        logger.info("New application %s from %s:." % (str(person), '::1'))
        return membership
Exemplo n.º 4
0
def create_member(mdata, logins):
    # 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'].replace(" ", "").replace("-", ""),
        'sms' : mdata['sms'].replace(" ", "").replace("-", ""),
        'email' : mdata['email'].strip(" "),
        'homepage' : mdata['website'].strip(" "),
        'first_name' : mdata['name'].strip(" "),
        'given_names' : mdata['firstnames'].strip(" "),
        'last_name' : mdata['lastname'].strip(" "),
        # mdata['application_id'],
        # mdata['sendinfo'],
    }

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

    if not mdata['memberclass']:
        mtype = 'P'
        print >> sys.stderr, "# Member type missing for member %d" % mdata['id']
    elif mdata['memberclass'] == 'member':
        mtype = 'P'
    elif mdata['memberclass'] == 'supporting':
        mtype = 'S'
    elif mdata['memberclass'] == 'organization':
        mtype = 'O'
    elif mdata['memberclass'] == 'honorary':
        mtype = 'H'
    else:
        print >> sys.stderr, "! Not importing, member class unknown for member %d" % mdata['id']
        return False

    contact = Contact(**d)
    contact.save()
    if mtype == 'O':
        membership = Membership(id=mdata['id'], type=mtype, status='A',
                                created=datetime.utcfromtimestamp(mdata['time']),
                                approved=datetime.utcfromtimestamp(mdata['time']),
                                organization=contact,
                                nationality=mdata['nationality'],
                                municipality=mdata['residence'],
                                extra_info='Imported from legacy',
                                public_memberlist=bool(mdata['publicname']))
    else:
        membership = Membership(id=mdata['id'], type=mtype, status='A',
                                created=datetime.utcfromtimestamp(mdata['time']),
                                approved=datetime.utcfromtimestamp(mdata['time']),
                                person=contact,
                                nationality=mdata['nationality'],
                                municipality=mdata['residence'],
                                extra_info='Imported from legacy',
                                public_memberlist=bool(mdata['publicname']))
    logger.info("Member %s imported from legacy database." % (unicode(contact)))
    membership.save()

    # Create a period only if there already is one previously. Else let
    # makebills create one.
    if mdata.has_key('period_start'):
        billing_cycle = BillingCycle(membership=membership, is_paid=False,
                                     start=datetime.strptime(mdata['period_start'], "%Y-%m-%d %H:%M:%S"),
                                     end=datetime.strptime(mdata['period_end'], "%Y-%m-%d %H:%M:%S")+timedelta(days=1))
        billing_cycle.save()
        bill = Bill(billingcycle=billing_cycle)
        bill.save()
        # Due to auto_now_add, need to save first before changing
        bill.created=datetime.strptime(mdata['bill_creation'], "%Y-%m-%d %H:%M:%S")
        bill.due_date=datetime.strptime(mdata['bill_dueday'], "%Y-%m-%d %H:%M:%S")
        bill.save()
    for alias in mdata['aliases']:
        if alias in logins:
            a = Alias(owner=membership, name=alias, account=True,
                      created=membership.created)
        else:
            a = Alias(owner=membership, name=alias, account=False,
                      created=membership.created)
        a.save()

        account_alias_count = Alias.objects.filter(owner=a.owner, account=True).count()
        if account_alias_count > 1:
            logger.warning("%i account aliases for %s" % (account_alias_count, a.owner))

    log_change(membership, user, change_message="Imported into system")
    return True
Exemplo n.º 5
0
    def create_dummy_member(self, i, duplicate_of=None):
        fname = random_first_name()
        d = {
            'street_address': 'Testikatu %d' % i,
            'postal_code': '%d' % (i + 1000),
            'post_office': 'Paska kaupunni',
            'country': 'Finland',
            'phone': "%09d" % (40123000 + i),
            'sms': "%09d" % (40123000 + i),
            'email': '*****@*****.**' % i,
            'homepage': 'http://www.example.com/%d' % i,
            'first_name': fname,
            'given_names': '%s %s' % (fname, "Kapsi"),
            'last_name': random_last_name(),
        }

        if duplicate_of is not None:
            d['first_name'] = duplicate_of.person.first_name
            d['last_name'] = duplicate_of.person.last_name

        person = Contact(**d)
        person.save()
        if random() < 0.2:
            public_memberlist = True
        else:
            public_memberlist = False
        membership = Membership(
            type='P',
            status='N',
            person=person,
            nationality='Finnish',
            municipality='Paska kaupunni',
            public_memberlist=public_memberlist,
            extra_info='Hintsunlaisesti semmoisia tietoja.')

        self.stdout.write(unicode(person))
        membership.save()

        forward_alias = Alias(owner=membership,
                              name=Alias.email_forwards(membership)[0])
        forward_alias.save()

        login_alias = Alias(owner=membership,
                            account=True,
                            name=choice(Alias.unix_logins(membership)))
        login_alias.save()

        # Services
        forward_alias_service = Service(
            servicetype=ServiceType.objects.get(servicetype='Email alias'),
            alias=forward_alias,
            owner=membership,
            data=forward_alias.name)
        forward_alias_service.save()

        unix_account_service = Service(
            servicetype=ServiceType.objects.get(servicetype='UNIX account'),
            alias=login_alias,
            owner=membership,
            data=login_alias.name)
        unix_account_service.save()

        if random() < 0.6:
            mysql_service = Service(servicetype=ServiceType.objects.get(
                servicetype='MySQL database'),
                                    alias=login_alias,
                                    owner=membership,
                                    data=login_alias.name.replace('-', '_'))
            mysql_service.save()
        if random() < 0.6:
            postgresql_service = Service(servicetype=ServiceType.objects.get(
                servicetype='PostgreSQL database'),
                                         alias=login_alias,
                                         owner=membership,
                                         data=login_alias.name)
            postgresql_service.save()
        # End of services

        logger.info("New application %s from %s:." % (str(person), '::1'))
        return membership
Exemplo n.º 6
0
    def create_dummy_member(self, i, duplicate_of=None):
        fname = random_first_name()
        d = {
            "street_address": "Testikatu %d" % i,
            "postal_code": "%d" % (i + 1000),
            "post_office": "Paska kaupunni",
            "country": "Finland",
            "phone": "%09d" % (40123000 + i),
            "sms": "%09d" % (40123000 + i),
            "email": "*****@*****.**" % i,
            "homepage": "http://www.example.com/%d" % i,
            "first_name": fname,
            "given_names": "%s %s" % (fname, "Kapsi"),
            "last_name": random_last_name(),
        }

        if duplicate_of is not None:
            d["first_name"] = duplicate_of.person.first_name
            d["last_name"] = duplicate_of.person.last_name

        person = Contact(**d)
        person.save()
        if random() < 0.2:
            public_memberlist = True
        else:
            public_memberlist = False
        membership = Membership(
            type="P",
            status="N",
            person=person,
            nationality="Finnish",
            municipality="Paska kaupunni",
            public_memberlist=public_memberlist,
            extra_info="Hintsunlaisesti semmoisia tietoja.",
        )

        self.stdout.write(unicode(person))
        membership.save()

        forward_alias = Alias(owner=membership, name=Alias.email_forwards(membership)[0])
        forward_alias.save()

        login_alias = Alias(owner=membership, account=True, name=choice(Alias.unix_logins(membership)))
        login_alias.save()

        # Services
        forward_alias_service = Service(
            servicetype=ServiceType.objects.get(servicetype="Email alias"),
            alias=forward_alias,
            owner=membership,
            data=forward_alias.name,
        )
        forward_alias_service.save()

        unix_account_service = Service(
            servicetype=ServiceType.objects.get(servicetype="UNIX account"),
            alias=login_alias,
            owner=membership,
            data=login_alias.name,
        )
        unix_account_service.save()

        if random() < 0.6:
            mysql_service = Service(
                servicetype=ServiceType.objects.get(servicetype="MySQL database"),
                alias=login_alias,
                owner=membership,
                data=login_alias.name.replace("-", "_"),
            )
            mysql_service.save()
        if random() < 0.6:
            postgresql_service = Service(
                servicetype=ServiceType.objects.get(servicetype="PostgreSQL database"),
                alias=login_alias,
                owner=membership,
                data=login_alias.name,
            )
            postgresql_service.save()
        # End of services

        logger.info("New application %s from %s:." % (str(person), "::1"))
        return membership