コード例 #1
0
ファイル: test_models.py プロジェクト: khayford/mzalendo
    def test_missing_contacts(self):
        person = models.Person(legal_name="Test Person", slug='test-person')
        person.save()

        self.assertItemsEqual(
            [i.category.slug for i in Task.objects_for(person)],
            [
                'find-missing-phone', 'find-missing-email',
                'find-missing-address'
            ],
        )

        # add a phone number and check that the tasks get updated
        phone = models.ContactKind(
            slug='phone',
            name='Phone',
        )
        phone.save()

        contact = models.Contact(
            content_type=ContentType.objects.get_for_model(person),
            object_id=person.id,
            kind=phone,
            value='07891 234 567',
        )
        contact.save()

        self.assertItemsEqual(
            [i.category.slug for i in Task.objects_for(person)],
            ['find-missing-email', 'find-missing-address'],
        )
コード例 #2
0
def process(filename):
    data = json.loads(open(filename, 'r').read())
    # pprint.pprint( data )
    print "%s (%s) - %s" % (data['name'], data['slug'], filename)

    slug = data['slug']

    try:
        person = models.Person.objects.get(slug=slug)
        return  # don't try to update the person
    except models.Person.DoesNotExist:
        person = models.Person(slug=slug)

    person.legal_name = data['name']
    person.summary = data['summary']
    person.date_of_birth = data['date_of_birth']

    person.save()

    content_type = ContentType.objects.get_for_model(person)

    if data.get('profile_url'):
        models.Contact.objects.get_or_create(
            content_type=content_type,
            object_id=person.id,
            value=re.sub('\s', '%20', data['profile_url']),
            kind=profile_url_kind,
        )

    if data.get('email'):
        models.Contact.objects.get_or_create(
            content_type=content_type,
            object_id=person.id,
            value=data['email'],
            kind=email_kind,
        )

    # import image
    if data.get('image') and 'img_not_found' not in data['image']:

        image_url = re.sub('\s', '%20', data['image'])

        photo, created = Image.objects.get_or_create(
            content_type=content_type,
            object_id=person.id,
            source=image_url,
        )

        if created:

            print "  Fetching " + image_url
            try:
                img_temp = NamedTemporaryFile(delete=True)
                img_temp.write(urllib2.urlopen(image_url).read())
                img_temp.flush()

                photo.image.save(person.slug, File(img_temp))
                photo.save()
            except urllib2.HTTPError:
                print "  ...failed!"
コード例 #3
0
ファイル: test_positions.py プロジェクト: khayford/mzalendo
    def setUp(self):
        self.person = models.Person(
            legal_name='Test Person',
            slug='test-person',
        )
        self.person.save()

        self.organisation_kind = models.OrganisationKind(
            name='Foo',
            slug='foo',
        )
        self.organisation_kind.save()

        self.organisation = models.Organisation(
            name='Test Org',
            slug='test-org',
            kind=self.organisation_kind,
        )
        self.organisation.save()

        self.title = models.PositionTitle.objects.create(
            name='Test title',
            slug='test-title',
        )
コード例 #4
0
ファイル: test_persons.py プロジェクト: khayford/mzalendo
    def test_naming(self):
        # create a test person
        person = models.Person(legal_name="Alfred Smith")
        person.clean()  # would normally be called by 'save()'
        self.assertEqual(person.name, "Alfred Smith")
        self.assertEqual(person.additional_names(), [])

        # Add an alternative name
        person.other_names = "Freddy Smith"
        person.clean()  # would normally be called by 'save()'
        self.assertEqual(person.name, "Freddy Smith")
        self.assertEqual(person.additional_names(), [])

        # Add yet another alternative name
        person.other_names = "Fred Smith\nFreddy Smith"
        person.clean()  # would normally be called by 'save()'
        self.assertEqual(person.name, "Fred Smith")
        self.assertEqual(person.additional_names(), ['Freddy Smith'])

        # Add yet another alternative name
        person.other_names = "\n\nFred Smith\n\nFreddy Smith\n\n\n"
        person.clean()  # would normally be called by 'save()'
        self.assertEqual(person.name, "Fred Smith")
        self.assertEqual(person.additional_names(), ['Freddy Smith'])
コード例 #5
0
ファイル: ods.py プロジェクト: twothreenine/kerndlware
def import_accounts(create_users=True):
    with open('import_scripts/accounts.csv',
              newline='',
              encoding='utf-8',
              errors='ignore') as csvfile:
        reader = csv.reader(csvfile, delimiter='\t')
        for index, row in enumerate(reader):
            if not row[0] == '':
                original_id = int(row[0])
                name = row[2]
                if row[4] == '':
                    active = True
                else:
                    active = False
                a = models.Account(name=name,
                                   original_id=original_id,
                                   active=active)
                a.save()
                comment = row[7]
                if not row[3] == '':
                    rate = int(row[3])
                    if row[5]:
                        start_date = datetime.datetime.strptime(
                            row[5], '%d.%m.%y'
                        )  # must begin at first day of the month!
                        if start_date.day == 1:
                            orig_start_date = ""
                        else:
                            orig_start_date = "Urspr. Eintrittsdatum: " + start_date.strftime(
                                '%d.%m.%y; ')
                            if start_date.month == 12:
                                start_date = start_date.replace(
                                    day=1, month=1, year=start_date.year + 1)
                            else:
                                start_date = start_date.replace(
                                    day=1, month=start_date.month + 1)
                    else:
                        start_date = None
                        orig_start_date = ""
                    if row[6]:
                        end_date = datetime.datetime.strptime(
                            row[6], '%d.%m.%y'
                        )  # must end at last day of the month, unless the date is on the 1st, then on the last day of the previous month
                        orig_end_date = end_date
                        if end_date.day == 1:
                            end_date.replace(month=end_date.month - 1)
                        end_date = last_day_of_month(end_date)
                        if orig_end_date == end_date:
                            orig_end_date = ""
                        else:
                            orig_end_date = "Urspr. Austrittsdatum: " + orig_end_date.strftime(
                                '%d.%m.%y; ')
                    else:
                        end_date = None
                        orig_end_date = ""
                    ap = models.MembershipFee(account=a,
                                              start=start_date,
                                              end=end_date,
                                              rate=rate,
                                              comment=orig_start_date +
                                              orig_end_date + comment)
                    ap.save()
                elif not row[5] == '':
                    a.comment = "Eintritt am " + str(
                        row[5]) + ", nicht zahlend; " + comment
                if create_users == True:
                    if original_id == 1 or original_id == 52:  # specifically for our database with Spontankäufer and Spendenkonto
                        u = models.VirtualUser(name=name,
                                               active=active,
                                               comment=comment)
                        u.save()
                    else:
                        u = models.Person(name=name,
                                          active=active,
                                          comment=comment)
                        u.save()
                        n = re.search(
                            '(.+ ?.+) (.+)', name
                        )  # improve regex code: if there is only one word, group 2 shall be empty (first name only)
                        if n:
                            u.first_name = n.group(1)
                            u.last_name = n.group(2)
                    u.accounts.add(a)
                    u.save()
                    a.users.add(u)
                a.save()
コード例 #6
0
ファイル: test_age.py プロジェクト: migonzalvar/alpha
def test_age_eighteen_year():
    birthday = dt.date.today()
    birthday = birthday.replace(year=birthday.year - 18)
    person = models.Person(birthday=birthday)
    assert person.age == '18 años'
コード例 #7
0
    #  'StatusID': '2',
    #  'UniversityEducation': 'Economics and Political Science Amhrest College,USA '}

    try:
        (last, first,
         middle) = name_to_first_last.conversions[obj['Fullnames']]
    except:
        print obj['Fullnames']
        continue

    slug = slugify(first + ' ' + last)

    try:
        db_obj = models.Person.objects.get(slug=slug)
    except models.Person.DoesNotExist:
        db_obj = models.Person(slug=slug)

    dob = obj.get('DateOfBirth')
    if dob:
        dob = re.sub(
            '-01-01', '-00-00', dob
        )  # 1 Jan happens too often - assume it means that month and day unknown
        # print dob
        (year, month, day) = re.split('-', dob)
        if int(year):
            db_obj.date_of_birth = ApproximateDate(year=int(year),
                                                   month=int(month),
                                                   day=int(day))

    db_obj.original_id = obj['MemberID']