def create_admin(self): # Create admin user. user = User.objects.create_user('admin', password='******') user.is_superuser = True user.is_staff = True user.first_name = 'admin' user.last_name = 'istrator' user.email = '*****@*****.**' user.save() profile = models.UserProfile(user=user) profile.save() user.userprofile.bio = 'This is a bio for the admin user, whose first name is admin and ' \ 'last name is istrator, who has no email address, and lives off campus.' user.userprofile.on_off_campus = 'off' # get the debug image to use as the profile photo print(self.debug_profile_pic_path) print(self.debug_item_pic_path) filename = self.debug_profile_pic_path + 'debug.jpeg' print(os.listdir()) extension = '.' + filename.split('.')[len(filename.split('.')) - 1] image = Image.open(filename) image_bytes = BytesIO() image.save(image_bytes, image.format) user.userprofile.profile_picture.save( user.first_name + extension, ContentFile(image_bytes.getvalue())) user.userprofile.save() return
def create_user(self): # Create debug user information. name = 'Test User' bio = 'This is a bio for Test User, whose first name is Test and ' \ 'last name is User, who has email address [email protected], and lives on campus.' location = 'on' username = name.replace(' ', '') email = (username + '@somewhere.com').lower() user = User.objects.create_user(username=email, password='******') user.is_superuser = False user.is_staff = False user.first_name = name.split(' ')[0] user.last_name = name.split(' ')[1] user.email = email user.save() profile = models.UserProfile(user=user) profile.save() user.userprofile.bio = bio user.userprofile.on_off_campus = location # get the debug image to use as the profile photo filename = self.debug_profile_pic_path + 'debug.jpeg' extension = '.' + filename.split('.')[len(filename.split('.')) - 1] image = Image.open(filename) image_bytes = BytesIO() image.save(image_bytes, image.format) user.userprofile.profile_picture.save( user.first_name + extension, ContentFile(image_bytes.getvalue())) user.userprofile.save() return
def create_random_users(self): image_list = glob.glob(self.debug_profile_pic_path + 'images-*.jpeg') # profile data contains all of the fake information profile_data = [(fake.name(), fake.text(), random.choice(['on', 'off' ]), counter) for counter in range(self.num_users)] for name, bio, location, counter in profile_data: username = name.replace(' ', '') email = (username + '@somewhere.com').lower() user = User.objects.create_user(username=email, password='******') user.is_superuser = False user.is_staff = False user.first_name = name.split(' ')[0] user.last_name = name.split(' ')[1] user.email = email user.save() profile = models.UserProfile(user=user) profile.save() user.userprofile.bio = bio user.userprofile.on_off_campus = location # get an image to use as the profile photo filename = image_list[counter % len(image_list)] extension = '.' + filename.split('.')[len(filename.split('.')) - 1] image = Image.open(filename) image_bytes = BytesIO() image.save(image_bytes, image.format) user.userprofile.profile_picture.save( user.first_name + extension, ContentFile(image_bytes.getvalue())) user.userprofile.save() return