コード例 #1
0
    def create_user(self):
        """Create a new random user"""
        self.stdout.write("Creating a user")

        fakeprofile = _faker.profile()
        fakeprofile["password"] = "".join(
            random.choice(string.ascii_uppercase + string.digits)
            for _ in range(16))
        user = get_user_model().objects.create_user(fakeprofile["username"],
                                                    fakeprofile["mail"],
                                                    fakeprofile["password"])
        user.first_name = fakeprofile["name"].split()[0]
        user.last_name = " ".join(fakeprofile["name"].split()[1:])

        profile = _ProfileFactory()
        profile.user_id = user.id
        profile.birthday = fakeprofile["birthdate"]
        profile.website = fakeprofile["website"][0]

        igen = IconGenerator(5, 5)  # 5x5 blocks
        icon = igen.generate(
            user.username,
            480,
            480,
            padding=(10, 10, 10, 10),
            output_format="jpeg",
        )  # 620x620 pixels, with 10 pixels padding on each side
        profile.photo.save(fakeprofile["username"] + ".jpeg",
                           ContentFile(icon))

        membership = Membership()
        membership.user_id = user.id
        membership.since = _faker.date_time_between(start_date="-4y",
                                                    end_date="now",
                                                    tzinfo=None)
        membership.until = random.choice([
            _faker.date_time_between(start_date=membership.since,
                                     end_date="+2y",
                                     tzinfo=None),
            None,
        ])
        membership.type = random.choice(
            [t[0] for t in Membership.MEMBERSHIP_TYPES])

        user.save()
        profile.save()
        membership.save()
コード例 #2
0
                       emergency_contact = row['Emergency Contact'],
                       emergency_phone_number = row['Emergency Phone'],
                       stripe_customer_code = row['Stripe cus_ code'])
            if len(m.birth_date) == 0:
                m.birth_date = datetime.date.today()
            try:
                m.save()
            except django.core.exceptions.ValidationError:
                print('error: skipping', fname, lname)
                raise

            #attempt to make a membership
            try:
                #for empty strings on expire date
                if not row['Last day of Membership']:
                    last_day = datetime.date.today()
                else:

                    last_day = datetime.datetime.strptime(row['Last day of Membership'], '%Y-%m-%d').date()
                    if last_day > datetime.date.today():
                        ms = Membership(member = m,
                                        start_date = datetime.date.today(),
                                        expire_date = last_day,
                                        stripe_subscription_code = row['Stripe Membership sub_ code'])
                        ms.save()
            except ValueError:
                print('\t could not parse date: [', row['Last day of Membership'], ']')
                pass
            #end for loop