def handle(self, *args, **options):
        #create users
        default_boards = DefaultBoard.objects.all()
        image_dir = os.path.join(os.path.dirname(settings.MEDIA_ROOT), 'default_images')
        image_files = [os.path.join(image_dir, f) for f in os.listdir(image_dir)]
        self.stdout.write("Generating %d users, %d pins with 0-%d comments per pin.\n" % (options['num_users'], options['num_pins'], options['max_comments'] ))

        for i in xrange(options['num_users']):
            u = User.objects.create(username="******" % i, first_name="User No %d" % i, email="*****@*****.**" % i)
            for b in default_boards:
                Board.objects.create(user=u, name=b.name, category=b.category)

        users = list(User.objects.all())
        boards = list(Board.objects.all())
        ct = ContentType.objects.get_for_model(Pin)
        site = Site.objects.get_current()

        #generate default users to follow for each category
        for c in Category.objects.get_list_for_welcome_screen():
            users = random.sample(users, 4)
            for u in users:
                c.recommended_users_to_follow.add(u)

        for i in xrange(options['num_pins']):
            is_repin = bool((random.randint(0,100) > 80) and Pin.objects.count()>0)
            p = Pin.objects.create(description = make_comment(), board=random.choice(boards))
            if not is_repin:
                f_name = random.choice(image_files)
                p.image.save(os.path.basename(f_name),  ContentFile(open(f_name, 'rb').read()))
            else:
                p.is_repin = True
                p.source_pin = random.choice(list(Pin.objects.filter(is_repin=False)))
                p.save()
            for ic in xrange(random.randint(0, options['max_comments'])):
                Comment.objects.create(comment=make_comment(), user=random.choice(users), 
                    content_type_id = ct.pk, object_pk=p.pk, site=site)

            for il in xrange(random.randint(0, options['num_likes'])):
                Like.objects.like_pin(p, random.choice(users))

        source_json = os.path.join(settings.PROJECT_ROOT, 'apps', 'pins','management',
            'commands','video_sources.json')
        videos = json.loads(open(source_json,'rb').read())

        for i in xrange(options['num_videos']):
            b = random.choice(boards)
            form_class = get_pin_url_form(b.user)
            v = random.choice(videos)
            data = {'description': make_comment(), 'board': b.pk, 'url':'http://youtube.com/', 
                'parser':v['parser'], 'video_id': v['video_id']}
            form = form_class(data)
            form.is_valid()
            form.save()

        self.stdout.write("Data generated successfully!")
Example #2
0
	def test_pin_from_url(self):
		form_class = get_pin_url_form(self.user)
		data = {'board': self.board.pk, 'description': 'Some test description', 
		'url':'http://wot.lv/', 
		'image_url': 'https://lh5.googleusercontent.com/-uqDGD8tYhOg/Tx8FK52WrsI/AAAAAAAABP8/gylZJOCX6V4/w859-h572-k/Picture%2B001.jpg'}
		form = form_class(data)
		self.assertTrue(form.is_valid())
		pin = form.save()
		self.assertIsInstance(pin.get_image(), models.FileField.attr_class)
		self.assertEqual(pin.url, 'http://wot.lv/')
		self.assertEqual(pin.board, self.board)
Example #3
0
def finish_web_pin(request, success_urlname="single_pin", pin_source="url"):
    """
	This view receives form's data from pin bookmarklet and "Pin from URL" feature.
	"""
    form = get_pin_url_form(request.user)(request.POST)
    if form.is_valid():
        pin = form.save(commit=False)
        pin.is_active = True
        pin.pin_source = pin_source
        pin.save()
        pins.signals.pin_finished.send_robust(finish_web_pin, instance=pin)
        messages.success(request, _('Pin created successfully!'))
        return redirect(success_urlname, pin.pk)
    else:
        messages.error(request, _('Could not upload pin!'))
        return redirect("pin_it")
def finish_web_pin(request, success_urlname = "single_pin", pin_source="url"):
	"""
	This view receives form's data from pin bookmarklet and "Pin from URL" feature.
	"""
	form = get_pin_url_form(request.user)(request.POST)
	if form.is_valid():
		pin = form.save(commit=False)
		pin.is_active = True
		pin.pin_source = pin_source
		pin.save()
		pins.signals.pin_finished.send_robust(finish_web_pin, instance=pin)
		messages.success(request, _('Pin created successfully!'))
		return redirect(success_urlname, pin.pk)
	else:
		messages.error(request, _('Could not upload pin!'))
		return redirect("pin_it")
Example #5
0
 def test_pin_from_url(self):
     form_class = get_pin_url_form(self.user)
     data = {
         'board':
         self.board.pk,
         'description':
         'Some test description',
         'url':
         'http://wot.lv/',
         'image_url':
         'https://lh5.googleusercontent.com/-uqDGD8tYhOg/Tx8FK52WrsI/AAAAAAAABP8/gylZJOCX6V4/w859-h572-k/Picture%2B001.jpg'
     }
     form = form_class(data)
     self.assertTrue(form.is_valid())
     pin = form.save()
     self.assertIsInstance(pin.get_image(), models.FileField.attr_class)
     self.assertEqual(pin.url, 'http://wot.lv/')
     self.assertEqual(pin.board, self.board)
    def handle(self, *args, **options):
        #create users
        default_boards = DefaultBoard.objects.all()
        image_dir = os.path.join(os.path.dirname(settings.MEDIA_ROOT),
                                 'default_images')
        image_files = [
            os.path.join(image_dir, f) for f in os.listdir(image_dir)
        ]
        self.stdout.write(
            "Generating %d users, %d pins with 0-%d comments per pin.\n" %
            (options['num_users'], options['num_pins'],
             options['max_comments']))

        for i in xrange(options['num_users']):
            u = User.objects.create(username="******" % i,
                                    first_name="User No %d" % i,
                                    email="*****@*****.**" % i)
            for b in default_boards:
                Board.objects.create(user=u, name=b.name, category=b.category)

        users = list(User.objects.all())
        boards = list(Board.objects.all())
        ct = ContentType.objects.get_for_model(Pin)
        site = Site.objects.get_current()

        #generate default users to follow for each category
        for c in Category.objects.get_list_for_welcome_screen():
            users = random.sample(users, 4)
            for u in users:
                c.recommended_users_to_follow.add(u)

        for i in xrange(options['num_pins']):
            is_repin = bool((random.randint(0, 100) > 80)
                            and Pin.objects.count() > 0)
            p = Pin.objects.create(description=make_comment(),
                                   board=random.choice(boards))
            if not is_repin:
                f_name = random.choice(image_files)
                p.image.save(os.path.basename(f_name),
                             ContentFile(open(f_name, 'rb').read()))
            else:
                p.is_repin = True
                p.source_pin = random.choice(
                    list(Pin.objects.filter(is_repin=False)))
                p.save()
            for ic in xrange(random.randint(0, options['max_comments'])):
                Comment.objects.create(comment=make_comment(),
                                       user=random.choice(users),
                                       content_type_id=ct.pk,
                                       object_pk=p.pk,
                                       site=site)

            for il in xrange(random.randint(0, options['num_likes'])):
                Like.objects.like_pin(p, random.choice(users))

        source_json = os.path.join(settings.PROJECT_ROOT, 'apps', 'pins',
                                   'management', 'commands',
                                   'video_sources.json')
        videos = json.loads(open(source_json, 'rb').read())

        for i in xrange(options['num_videos']):
            b = random.choice(boards)
            form_class = get_pin_url_form(b.user)
            v = random.choice(videos)
            data = {
                'description': make_comment(),
                'board': b.pk,
                'url': 'http://youtube.com/',
                'parser': v['parser'],
                'video_id': v['video_id']
            }
            form = form_class(data)
            form.is_valid()
            form.save()

        self.stdout.write("Data generated successfully!")